[Devel] [PATCH RHEL7 COMMIT] ms/nbd: use bd_set_size when updating disk size

Konstantin Khorenko khorenko at virtuozzo.com
Tue Nov 5 11:06:19 MSK 2019


The commit is pushed to "branch-rh7-3.10.0-1062.4.1.vz7.115.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-1062.4.1.vz7.115.7
------>
commit 1f3d9cac2e584e40d5e52395c4a4a6d19aea759f
Author: Josef Bacik <jbacik at fb.com>
Date:   Tue Nov 5 11:06:17 2019 +0300

    ms/nbd: use bd_set_size when updating disk size
    
    When we stopped relying on the bdev everywhere I broke updating the
    block device size on the fly, which ceph relies on.  We can't just do
    set_capacity, we also have to do bd_set_size so things like parted will
    notice the device size change.
    
    Fixes: 29eaadc ("nbd: stop using the bdev everywhere")
    cc: stable at vger.kernel.org
    Signed-off-by: Josef Bacik <jbacik at fb.com>
    Signed-off-by: Jens Axboe <axboe at kernel.dk>
    
    https://jira.sw.ru/browse/PSBM-99102
    (cherry picked from commit 9e2b19675d1338d2a38e99194756f2db44a081df)
    Signed-off-by: Andrey Ryabinin <aryabinin at virtuozzo.com>
---
 drivers/block/nbd.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index a0ebd61c19d8..0eedb74183dc 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -196,9 +196,18 @@ static void nbd_size_clear(struct nbd_device *nbd)
 static void nbd_size_update(struct nbd_device *nbd)
 {
 	struct nbd_config *config = nbd->config;
+	struct block_device *bdev = bdget_disk(nbd->disk, 0);
+
 	blk_queue_logical_block_size(nbd->disk->queue, config->blksize);
 	blk_queue_physical_block_size(nbd->disk->queue, config->blksize);
 	set_capacity(nbd->disk, config->bytesize >> 9);
+	if (bdev) {
+		if (bdev->bd_disk)
+			bd_set_size(bdev, config->bytesize);
+		else
+			bdev->bd_invalidated = 1;
+		bdput(bdev);
+	}
 	kobject_uevent(&nbd_to_dev(nbd)->kobj, KOBJ_CHANGE);
 }
 
@@ -952,7 +961,6 @@ static int nbd_start_device(struct nbd_device *nbd, struct block_device *bdev)
 	set_bit(NBD_HAS_PID_FILE, &config->runtime_flags);
 	if (max_part)
 		bdev->bd_invalidated = 1;
-	bd_set_size(bdev, config->bytesize);
 
 	nbd_dev_dbg_init(nbd);
 	for (i = 0; i < num_connections; i++) {



More information about the Devel mailing list