1 From d514650b78a6196ce3e6f622f049b7955b8b751c Mon Sep 17 00:00:00 2001
2 From: Sasha Levin <sashal@kernel.org>
3 Date: Wed, 28 Oct 2020 15:24:34 +0800
4 Subject: nbd: don't update block size after device is started
6 From: Ming Lei <ming.lei@redhat.com>
8 [ Upstream commit b40813ddcd6bf9f01d020804e4cb8febc480b9e4 ]
10 Mounted NBD device can be resized, one use case is rbd-nbd.
12 Fix the issue by setting up default block size, then not touch it
13 in nbd_size_update() any more. This kind of usage is aligned with loop
14 which has same use case too.
16 Cc: stable@vger.kernel.org
17 Fixes: c8a83a6b54d0 ("nbd: Use set_blocksize() to set device blocksize")
18 Reported-by: lining <lining2020x@163.com>
19 Signed-off-by: Ming Lei <ming.lei@redhat.com>
20 Cc: Josef Bacik <josef@toxicpanda.com>
21 Cc: Jan Kara <jack@suse.cz>
22 Tested-by: lining <lining2020x@163.com>
23 Signed-off-by: Jens Axboe <axboe@kernel.dk>
24 Signed-off-by: Sasha Levin <sashal@kernel.org>
26 drivers/block/nbd.c | 9 +++++----
27 1 file changed, 5 insertions(+), 4 deletions(-)
29 diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
30 index cdf62fb94fb15..9a0fb2d52a76c 100644
31 --- a/drivers/block/nbd.c
32 +++ b/drivers/block/nbd.c
33 @@ -268,7 +268,7 @@ static void nbd_size_clear(struct nbd_device *nbd)
37 -static void nbd_size_update(struct nbd_device *nbd)
38 +static void nbd_size_update(struct nbd_device *nbd, bool start)
40 struct nbd_config *config = nbd->config;
41 struct block_device *bdev = bdget_disk(nbd->disk, 0);
42 @@ -279,7 +279,8 @@ static void nbd_size_update(struct nbd_device *nbd)
45 bd_set_size(bdev, config->bytesize);
46 - set_blocksize(bdev, config->blksize);
48 + set_blocksize(bdev, config->blksize);
50 bdev->bd_invalidated = 1;
52 @@ -294,7 +295,7 @@ static void nbd_size_set(struct nbd_device *nbd, loff_t blocksize,
53 config->blksize = blocksize;
54 config->bytesize = blocksize * nr_blocks;
55 if (nbd->task_recv != NULL)
56 - nbd_size_update(nbd);
57 + nbd_size_update(nbd, false);
60 static void nbd_complete_rq(struct request *req)
61 @@ -1231,7 +1232,7 @@ static int nbd_start_device(struct nbd_device *nbd)
63 queue_work(nbd->recv_workq, &args->work);
65 - nbd_size_update(nbd);
66 + nbd_size_update(nbd, true);