Skip to content

Commit 2ebcabf

Browse files
Christoph Hellwigaxboe
authored andcommitted
nbd: use set_capacity_and_notify
Use set_capacity_and_notify to update the disk and block device sizes and send a RESIZE uevent to userspace. Note that blktests relies on uevents being sent also for updates that did not change the device size, so the explicit kobject_uevent remains for that case. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent dcbddf5 commit 2ebcabf

File tree

1 file changed

+3
-12
lines changed

1 file changed

+3
-12
lines changed

drivers/block/nbd.c

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,6 @@ static void nbd_size_clear(struct nbd_device *nbd)
299299
static int nbd_set_size(struct nbd_device *nbd, loff_t bytesize,
300300
loff_t blksize)
301301
{
302-
struct block_device *bdev;
303-
304302
if (!blksize)
305303
blksize = NBD_DEF_BLKSIZE;
306304
if (blksize < 512 || blksize > PAGE_SIZE || !is_power_of_2(blksize))
@@ -320,16 +318,9 @@ static int nbd_set_size(struct nbd_device *nbd, loff_t bytesize,
320318
blk_queue_logical_block_size(nbd->disk->queue, blksize);
321319
blk_queue_physical_block_size(nbd->disk->queue, blksize);
322320

323-
set_capacity(nbd->disk, bytesize >> 9);
324-
bdev = bdget_disk(nbd->disk, 0);
325-
if (bdev) {
326-
if (bdev->bd_disk)
327-
bd_set_nr_sectors(bdev, bytesize >> 9);
328-
else
329-
set_bit(GD_NEED_PART_SCAN, &nbd->disk->state);
330-
bdput(bdev);
331-
}
332-
kobject_uevent(&nbd_to_dev(nbd)->kobj, KOBJ_CHANGE);
321+
set_bit(GD_NEED_PART_SCAN, &nbd->disk->state);
322+
if (!set_capacity_and_notify(nbd->disk, bytesize >> 9))
323+
kobject_uevent(&nbd_to_dev(nbd)->kobj, KOBJ_CHANGE);
333324
return 0;
334325
}
335326

0 commit comments

Comments
 (0)