summaryrefslogtreecommitdiff
path: root/fs/block_dev.c
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2019-11-14 15:34:34 +0100
committerJens Axboe <axboe@kernel.dk>2019-11-14 07:43:21 -0700
commita1548b674403c0de70cc29a1575689917ba60157 (patch)
treebe1dcf032146bd80dde2c4fe8f380a6c76a31a0b /fs/block_dev.c
parent6917d0689993f46d97d40dd66c601d0fd5b1dbdd (diff)
downloadlinux-next-a1548b674403c0de70cc29a1575689917ba60157.tar.gz
block: move rescan_partitions to fs/block_dev.c
Large parts of rescan_partitions aren't about partitions, and moving it to block_dev.c will allow for some further cleanups by merging it into its only caller. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Jan Kara <jack@suse.cz> Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'fs/block_dev.c')
-rw-r--r--fs/block_dev.c38
1 files changed, 36 insertions, 2 deletions
diff --git a/fs/block_dev.c b/fs/block_dev.c
index 0af62b76d031..ec10dacd18d0 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -1416,8 +1416,8 @@ static void flush_disk(struct block_device *bdev, bool kill_dirty)
* and adjusts it if it differs. When shrinking the bdev size, its all caches
* are freed.
*/
-void check_disk_size_change(struct gendisk *disk, struct block_device *bdev,
- bool verbose)
+static void check_disk_size_change(struct gendisk *disk,
+ struct block_device *bdev, bool verbose)
{
loff_t disk_size, bdev_size;
@@ -1508,6 +1508,40 @@ EXPORT_SYMBOL(bd_set_size);
static void __blkdev_put(struct block_device *bdev, fmode_t mode, int for_part);
+static int rescan_partitions(struct gendisk *disk, struct block_device *bdev,
+ bool invalidate)
+{
+ int ret;
+
+rescan:
+ ret = blk_drop_partitions(disk, bdev);
+ if (ret)
+ return ret;
+
+ if (invalidate)
+ set_capacity(disk, 0);
+ else if (disk->fops->revalidate_disk)
+ disk->fops->revalidate_disk(disk);
+
+ check_disk_size_change(disk, bdev, !invalidate);
+ bdev->bd_invalidated = 0;
+
+ if (!get_capacity(disk)) {
+ /*
+ * Tell userspace that the media / partition table may have
+ * changed.
+ */
+ kobject_uevent(&disk_to_dev(disk)->kobj, KOBJ_CHANGE);
+ return 0;
+ }
+
+ ret = blk_add_partitions(disk, bdev);
+ if (ret == -EAGAIN)
+ goto rescan;
+ return ret;
+}
+
+
static void bdev_disk_changed(struct block_device *bdev, bool invalidate)
{
if (disk_part_scan_enabled(bdev->bd_disk)) {