Skip to content

Commit 9e2b196

Browse files
Josef Bacikaxboe
authored andcommitted
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: [email protected] Signed-off-by: Josef Bacik <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent c3f7c93 commit 9e2b196

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

drivers/block/nbd.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,18 @@ static void nbd_size_clear(struct nbd_device *nbd)
234234
static void nbd_size_update(struct nbd_device *nbd)
235235
{
236236
struct nbd_config *config = nbd->config;
237+
struct block_device *bdev = bdget_disk(nbd->disk, 0);
238+
237239
blk_queue_logical_block_size(nbd->disk->queue, config->blksize);
238240
blk_queue_physical_block_size(nbd->disk->queue, config->blksize);
239241
set_capacity(nbd->disk, config->bytesize >> 9);
242+
if (bdev) {
243+
if (bdev->bd_disk)
244+
bd_set_size(bdev, config->bytesize);
245+
else
246+
bdev->bd_invalidated = 1;
247+
bdput(bdev);
248+
}
240249
kobject_uevent(&nbd_to_dev(nbd)->kobj, KOBJ_CHANGE);
241250
}
242251

@@ -1114,7 +1123,6 @@ static int nbd_start_device_ioctl(struct nbd_device *nbd, struct block_device *b
11141123
if (ret)
11151124
return ret;
11161125

1117-
bd_set_size(bdev, config->bytesize);
11181126
if (max_part)
11191127
bdev->bd_invalidated = 1;
11201128
mutex_unlock(&nbd->config_lock);

0 commit comments

Comments
 (0)