[PATCH 1/4] ublk: don't cancel commands in QUIESCE_DEV on a device that isn't live
From: Josef Bacik
Date: Tue Oct 06 2026 - 13:19:20 EST
QUIESCE_DEV on a device which is not LIVE returns 0 as "already in
expected state", but ublk_cancel_dev() still runs after ub->mutex is
dropped. A device which is QUIESCED because its server died may have a
new server fetching its commands for recovery at that point, and the
cancel completes them without marking anything:
new server QUIESCE_DEV
START_USER_RECOVERY
FETCH part of the queue
device is QUIESCED, ret = 0
ublk_cancel_dev()
io->cmd = NULL, command done
FETCH the rest of the queue
END_USER_RECOVERY
device goes LIVE
ublk_queue_rq()
NULL io->cmd
Skip the cancel when the device was not LIVE. Its server is gone, so
there is nothing of the server QUIESCE_DEV is meant for left to cancel.
Fixes: b465ae7b2524 ("ublk: add feature UBLK_F_QUIESCE")
Assisted-by: LLM
Signed-off-by: Josef Bacik <josef@xxxxxxxxxxxxxx>
---
drivers/block/ublk_drv.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
index 39eb7775a351..0bd0b95b3217 100644
--- a/drivers/block/ublk_drv.c
+++ b/drivers/block/ublk_drv.c
@@ -5413,6 +5413,7 @@ static int ublk_ctrl_quiesce_dev(struct ublk_device *ub,
/* zero means wait forever */
u64 timeout_ms = header->data[0];
struct gendisk *disk;
+ bool live = true;
int ret = -ENODEV;
if (!(ub->dev_info.flags & UBLK_F_QUIESCE))
@@ -5427,8 +5428,15 @@ static int ublk_ctrl_quiesce_dev(struct ublk_device *ub,
ret = 0;
/* already in expected state */
- if (ub->dev_info.state != UBLK_S_DEV_LIVE)
+ if (ub->dev_info.state != UBLK_S_DEV_LIVE) {
+ /*
+ * Nothing to cancel either: the server this was meant for is
+ * gone, and the commands of the next one, which may be fetching
+ * them for recovery right now, are not ours to cancel.
+ */
+ live = false;
goto put_disk;
+ }
/* Mark the device as canceling */
mutex_lock(&ub->cancel_mutex);
@@ -5447,7 +5455,7 @@ static int ublk_ctrl_quiesce_dev(struct ublk_device *ub,
mutex_unlock(&ub->mutex);
/* Cancel pending uring_cmd */
- if (!ret)
+ if (!ret && live)
ublk_cancel_dev(ub);
return ret;
}
--
2.55.0