[PATCH v6 5/8] nbd: skip queue freeze when setting size at device startup
Yang Erkun <[email protected]> Tue, 4 Aug 2026 16:39:19 +0800
| Newsgroups | org.kernel.vger.linux-block |
|---|---|
| Message-ID | <[email protected]> |
Commit 242a49e5c878 ("nbd: freeze the queue for queue limits updates")
added the freeze to keep in-flight commands from seeing
torn queue_limits. But at startup the capacity is still 0
(invalidate_disk cleared it) and the write cache is off (the previous
patch cleared it on disconnect, and nbd_set_size sets it back only after
the commit), so submit_bio_noacct() rejects any bio before it reaches
the driver and no I/O is in flight. Drop the freeze by checking
capacity and write cache state in nbd_set_size.
Signed-off-by: Yang Erkun <[email protected]>
---
drivers/block/nbd.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index 8aeffc0eaaa1..66f1b3263b94 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -375,7 +375,11 @@ static int nbd_set_size(struct nbd_device *nbd, loff_t bytesize, loff_t blksize)
nbd_apply_limits(&lim, nbd->config->flags);
lim.logical_block_size = blksize;
lim.physical_block_size = blksize;
- error = queue_limits_commit_update_frozen(nbd->disk->queue, &lim);
+ /* No need freeze with 0 capacity and write cache disabled */
+ if (!get_capacity(nbd->disk) && !blk_queue_write_cache(nbd->disk->queue))
+ error = queue_limits_commit_update(nbd->disk->queue, &lim);
+ else
+ error = queue_limits_commit_update_frozen(nbd->disk->queue, &lim);
if (error)
return error;
--
2.52.0