drbd: do not block when adjusting "disk-options" while IO is frozen
authorLars Ellenberg <lars.ellenberg@linbit.com>
Thu, 20 Dec 2018 16:23:37 +0000 (17:23 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 5 Dec 2019 14:37:45 +0000 (15:37 +0100)
[ Upstream commit f708bd08ecbdc23d03aaedf5b3311ebe44cfdb50 ]

"suspending" IO is overloaded.
It can mean "do not allow new requests" (obviously),
but it also may mean "must not complete pending IO",
for example while the fencing handlers do their arbitration.

When adjusting disk options, we suspend io (disallow new requests), then
wait for the activity-log to become unused (drain all IO completions),
and possibly replace it with a new activity log of different size.

If the other "suspend IO" aspect is active, pending IO completions won't
happen, and we would block forever (unkillable drbdsetup process).

Fix this by skipping the activity log adjustment if the "al-extents"
setting did not change. Also, in case it did change, fail early without
blocking if it looks like we would block forever.

Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/block/drbd/drbd_nl.c

index a675a0f61f9c0947f369c2b8ebe6f5d0bf65916a..31d7fe4480afdd4f9cbe0deab47d5c412d4d2558 100644 (file)
@@ -1515,6 +1515,30 @@ static void sanitize_disk_conf(struct drbd_device *device, struct disk_conf *dis
        }
 }
 
+static int disk_opts_check_al_size(struct drbd_device *device, struct disk_conf *dc)
+{
+       int err = -EBUSY;
+
+       if (device->act_log &&
+           device->act_log->nr_elements == dc->al_extents)
+               return 0;
+
+       drbd_suspend_io(device);
+       /* If IO completion is currently blocked, we would likely wait
+        * "forever" for the activity log to become unused. So we don't. */
+       if (atomic_read(&device->ap_bio_cnt))
+               goto out;
+
+       wait_event(device->al_wait, lc_try_lock(device->act_log));
+       drbd_al_shrink(device);
+       err = drbd_check_al_size(device, dc);
+       lc_unlock(device->act_log);
+       wake_up(&device->al_wait);
+out:
+       drbd_resume_io(device);
+       return err;
+}
+
 int drbd_adm_disk_opts(struct sk_buff *skb, struct genl_info *info)
 {
        struct drbd_config_context adm_ctx;
@@ -1577,15 +1601,12 @@ int drbd_adm_disk_opts(struct sk_buff *skb, struct genl_info *info)
                }
        }
 
-       drbd_suspend_io(device);
-       wait_event(device->al_wait, lc_try_lock(device->act_log));
-       drbd_al_shrink(device);
-       err = drbd_check_al_size(device, new_disk_conf);
-       lc_unlock(device->act_log);
-       wake_up(&device->al_wait);
-       drbd_resume_io(device);
-
+       err = disk_opts_check_al_size(device, new_disk_conf);
        if (err) {
+               /* Could be just "busy". Ignore?
+                * Introduce dedicated error code? */
+               drbd_msg_put_info(adm_ctx.reply_skb,
+                       "Try again without changing current al-extents setting");
                retcode = ERR_NOMEM;
                goto fail_unlock;
        }