Skip to content

Commit 4bb77af

Browse files
Ming LeiFyzet
authored andcommitted
nbd: don't update block size after device is started
[ Upstream commit b40813ddcd6bf9f01d020804e4cb8febc480b9e4 ] Mounted NBD device can be resized, one use case is rbd-nbd. Fix the issue by setting up default block size, then not touch it in nbd_size_update() any more. This kind of usage is aligned with loop which has same use case too. Cc: stable@vger.kernel.org Fixes: c8a83a6b54d0 ("nbd: Use set_blocksize() to set device blocksize") Reported-by: lining <lining2020x@163.com> Signed-off-by: Ming Lei <ming.lei@redhat.com> Cc: Josef Bacik <josef@toxicpanda.com> Cc: Jan Kara <jack@suse.cz> Tested-by: lining <lining2020x@163.com> Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 22e10cb commit 4bb77af

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

drivers/block/nbd.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ static void nbd_size_clear(struct nbd_device *nbd)
268268
}
269269
}
270270

271-
static void nbd_size_update(struct nbd_device *nbd)
271+
static void nbd_size_update(struct nbd_device *nbd, bool start)
272272
{
273273
struct nbd_config *config = nbd->config;
274274
struct block_device *bdev = bdget_disk(nbd->disk, 0);
@@ -279,7 +279,8 @@ static void nbd_size_update(struct nbd_device *nbd)
279279
if (bdev) {
280280
if (bdev->bd_disk) {
281281
bd_set_size(bdev, config->bytesize);
282-
set_blocksize(bdev, config->blksize);
282+
if (start)
283+
set_blocksize(bdev, config->blksize);
283284
} else
284285
bdev->bd_invalidated = 1;
285286
bdput(bdev);
@@ -294,7 +295,7 @@ static void nbd_size_set(struct nbd_device *nbd, loff_t blocksize,
294295
config->blksize = blocksize;
295296
config->bytesize = blocksize * nr_blocks;
296297
if (nbd->task_recv != NULL)
297-
nbd_size_update(nbd);
298+
nbd_size_update(nbd, false);
298299
}
299300

300301
static void nbd_complete_rq(struct request *req)
@@ -1231,7 +1232,7 @@ static int nbd_start_device(struct nbd_device *nbd)
12311232
args->index = i;
12321233
queue_work(nbd->recv_workq, &args->work);
12331234
}
1234-
nbd_size_update(nbd);
1235+
nbd_size_update(nbd, true);
12351236
return error;
12361237
}
12371238

0 commit comments

Comments
 (0)