Skip to content

Commit

Permalink
nbd: don't update block size after device is started
Browse files Browse the repository at this point in the history
[ Upstream commit b40813d ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Ming Lei authored and gregkh committed Nov 18, 2020
1 parent d71c591 commit 97bfb92
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions drivers/block/nbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ static void nbd_size_clear(struct nbd_device *nbd)
}
}

static void nbd_size_update(struct nbd_device *nbd)
static void nbd_size_update(struct nbd_device *nbd, bool start)
{
struct nbd_config *config = nbd->config;
struct block_device *bdev = bdget_disk(nbd->disk, 0);
Expand All @@ -312,7 +312,8 @@ static void nbd_size_update(struct nbd_device *nbd)
if (bdev) {
if (bdev->bd_disk) {
bd_set_size(bdev, config->bytesize);
set_blocksize(bdev, config->blksize);
if (start)
set_blocksize(bdev, config->blksize);
} else
bdev->bd_invalidated = 1;
bdput(bdev);
Expand All @@ -327,7 +328,7 @@ static void nbd_size_set(struct nbd_device *nbd, loff_t blocksize,
config->blksize = blocksize;
config->bytesize = blocksize * nr_blocks;
if (nbd->task_recv != NULL)
nbd_size_update(nbd);
nbd_size_update(nbd, false);
}

static void nbd_complete_rq(struct request *req)
Expand Down Expand Up @@ -1307,7 +1308,7 @@ static int nbd_start_device(struct nbd_device *nbd)
args->index = i;
queue_work(nbd->recv_workq, &args->work);
}
nbd_size_update(nbd);
nbd_size_update(nbd, true);
return error;
}

Expand Down

0 comments on commit 97bfb92

Please sign in to comment.