提交 d1f54d6f 编写于 作者: M Ming Lei 提交者: Yang Yingliang

nbd: don't update block size after device is started

mainline inclusion
from mainline-v5.10-rc2
commit b40813dd
category: bugfix
bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1891363
CVE: NA
backport: openEuler-20.09

Here is the testcase:
1. rbd create --size 2G rbdpool/foo
2. rbd-nbd map rbdpool/foo
3. mkfs.ext4 /dev/nbd0
4. mount /dev/nbd0 /mnt
5. rbd resize --size 4G rbdpool/foo
6. ls /mnt
ls will stuck here forever.

--------------------------------

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: c8a83a6b ("nbd: Use set_blocksize() to set device blocksize")
Reported-by: Nlining <lining2020x@163.com>
Signed-off-by: NMing Lei <ming.lei@redhat.com>
Cc: Josef Bacik <josef@toxicpanda.com>
Cc: Jan Kara <jack@suse.cz>
Tested-by: Nlining <lining2020x@163.com>
Signed-off-by: NJens Axboe <axboe@kernel.dk>
Signed-off-by: NSasha Levin <sashal@kernel.org>
Signed-off-by: Nlining <lining_yewu@cmss.chinamobile.com>
Reviewed-by: NXie XiuQi <xiexiuqi@huawei.com>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
上级 8887018b
......@@ -293,7 +293,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);
......@@ -309,7 +309,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);
......@@ -324,7 +325,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)
......@@ -1263,7 +1264,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;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册