summaryrefslogtreecommitdiff
path: root/block/genhd.c
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2021-11-22 14:06:16 +0100
committerJens Axboe <axboe@kernel.dk>2021-11-29 06:35:21 -0700
commite16e506ccd673a3a888a34f8f694698305840044 (patch)
treeccf5b29c0132bf9a83e01ce253a311dffb42a15c /block/genhd.c
parente3b3bad3f29878d13fdbc96f9e59674bd9b06bae (diff)
downloadlinux-rpi-e16e506ccd673a3a888a34f8f694698305840044.tar.gz
linux-rpi-e16e506ccd673a3a888a34f8f694698305840044.tar.bz2
linux-rpi-e16e506ccd673a3a888a34f8f694698305840044.zip
block: merge disk_scan_partitions and blkdev_reread_part
Unify the functionality that implements a partition rescan for a gendisk. Signed-off-by: Christoph Hellwig <hch@lst.de> Link: https://lore.kernel.org/r/20211122130625.1136848-6-hch@lst.de Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'block/genhd.c')
-rw-r--r--block/genhd.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/block/genhd.c b/block/genhd.c
index 1c326d3b54b4..94f39c4333b8 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -372,17 +372,21 @@ void disk_uevent(struct gendisk *disk, enum kobject_action action)
}
EXPORT_SYMBOL_GPL(disk_uevent);
-static void disk_scan_partitions(struct gendisk *disk)
+int disk_scan_partitions(struct gendisk *disk, fmode_t mode)
{
struct block_device *bdev;
- if (!get_capacity(disk) || !disk_part_scan_enabled(disk))
- return;
+ if (!disk_part_scan_enabled(disk))
+ return -EINVAL;
+ if (disk->open_partitions)
+ return -EBUSY;
set_bit(GD_NEED_PART_SCAN, &disk->state);
- bdev = blkdev_get_by_dev(disk_devt(disk), FMODE_READ, NULL);
- if (!IS_ERR(bdev))
- blkdev_put(bdev, FMODE_READ);
+ bdev = blkdev_get_by_dev(disk_devt(disk), mode, NULL);
+ if (IS_ERR(bdev))
+ return PTR_ERR(bdev);
+ blkdev_put(bdev, mode);
+ return 0;
}
/**
@@ -509,7 +513,8 @@ int __must_check device_add_disk(struct device *parent, struct gendisk *disk,
goto out_unregister_bdi;
bdev_add(disk->part0, ddev->devt);
- disk_scan_partitions(disk);
+ if (get_capacity(disk))
+ disk_scan_partitions(disk, FMODE_READ);
/*
* Announce the disk and partitions after all partitions are