Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Christoph Hellwig and committed by
Jens Axboe
2ebcabf3 dcbddf54

+3 -12
+3 -12
drivers/block/nbd.c
··· 299 299 static int nbd_set_size(struct nbd_device *nbd, loff_t bytesize, 300 300 loff_t blksize) 301 301 { 302 - struct block_device *bdev; 303 - 304 302 if (!blksize) 305 303 blksize = NBD_DEF_BLKSIZE; 306 304 if (blksize < 512 || blksize > PAGE_SIZE || !is_power_of_2(blksize)) ··· 318 320 blk_queue_logical_block_size(nbd->disk->queue, blksize); 319 321 blk_queue_physical_block_size(nbd->disk->queue, blksize); 320 322 321 - set_capacity(nbd->disk, bytesize >> 9); 322 - bdev = bdget_disk(nbd->disk, 0); 323 - if (bdev) { 324 - if (bdev->bd_disk) 325 - bd_set_nr_sectors(bdev, bytesize >> 9); 326 - else 327 - set_bit(GD_NEED_PART_SCAN, &nbd->disk->state); 328 - bdput(bdev); 329 - } 330 - kobject_uevent(&nbd_to_dev(nbd)->kobj, KOBJ_CHANGE); 323 + set_bit(GD_NEED_PART_SCAN, &nbd->disk->state); 324 + if (!set_capacity_and_notify(nbd->disk, bytesize >> 9)) 325 + kobject_uevent(&nbd_to_dev(nbd)->kobj, KOBJ_CHANGE); 331 326 return 0; 332 327 } 333 328