Skip to content

Commit b40813d

Browse files
Ming Leiaxboe
authored andcommitted
nbd: don't update block size after device is started
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: c8a83a6 ("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>
1 parent 4977d12 commit b40813d

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
@@ -296,7 +296,7 @@ static void nbd_size_clear(struct nbd_device *nbd)
296296
}
297297
}
298298

299-
static void nbd_size_update(struct nbd_device *nbd)
299+
static void nbd_size_update(struct nbd_device *nbd, bool start)
300300
{
301301
struct nbd_config *config = nbd->config;
302302
struct block_device *bdev = bdget_disk(nbd->disk, 0);
@@ -313,7 +313,8 @@ static void nbd_size_update(struct nbd_device *nbd)
313313
if (bdev) {
314314
if (bdev->bd_disk) {
315315
bd_set_nr_sectors(bdev, nr_sectors);
316-
set_blocksize(bdev, config->blksize);
316+
if (start)
317+
set_blocksize(bdev, config->blksize);
317318
} else
318319
set_bit(GD_NEED_PART_SCAN, &nbd->disk->state);
319320
bdput(bdev);
@@ -328,7 +329,7 @@ static void nbd_size_set(struct nbd_device *nbd, loff_t blocksize,
328329
config->blksize = blocksize;
329330
config->bytesize = blocksize * nr_blocks;
330331
if (nbd->task_recv != NULL)
331-
nbd_size_update(nbd);
332+
nbd_size_update(nbd, false);
332333
}
333334

334335
static void nbd_complete_rq(struct request *req)
@@ -1308,7 +1309,7 @@ static int nbd_start_device(struct nbd_device *nbd)
13081309
args->index = i;
13091310
queue_work(nbd->recv_workq, &args->work);
13101311
}
1311-
nbd_size_update(nbd);
1312+
nbd_size_update(nbd, true);
13121313
return error;
13131314
}
13141315

0 commit comments

Comments
 (0)