]> www.infradead.org Git - users/hch/block.git/commitdiff
block: move bdev_disk_changed
authorChristoph Hellwig <hch@lst.de>
Fri, 26 Mar 2021 13:17:52 +0000 (14:17 +0100)
committerChristoph Hellwig <hch@lst.de>
Tue, 30 Mar 2021 05:44:39 +0000 (07:44 +0200)
Move bdev_disk_changed to fs/partitions/core.c.  This keeps the partition
scan logic in one place, and allows to mark blk_add_partitions and
blk_drop_partitions static.

Signed-off-by: Christoph Hellwig <hch@lst.de>
block/partitions/core.c
fs/block_dev.c
include/linux/genhd.h

index 22a0dab17ed34362f204d4b5e4fe2a858f0481db..90e3bd2804c4fad9f417bea9dac86a11489d6cc9 100644 (file)
@@ -526,7 +526,7 @@ static bool disk_unlock_native_capacity(struct gendisk *disk)
        }
 }
 
-int blk_drop_partitions(struct block_device *bdev)
+static int blk_drop_partitions(struct block_device *bdev)
 {
        struct disk_part_iter piter;
        struct block_device *part;
@@ -595,7 +595,7 @@ static bool blk_add_partition(struct gendisk *disk, struct block_device *bdev,
        return true;
 }
 
-int blk_add_partitions(struct gendisk *disk, struct block_device *bdev)
+static int blk_add_partitions(struct gendisk *disk, struct block_device *bdev)
 {
        struct parsed_partitions *state;
        int ret = -EAGAIN, p;
@@ -656,6 +656,54 @@ out_free_state:
        return ret;
 }
 
+int bdev_disk_changed(struct block_device *bdev, bool invalidate)
+{
+       struct gendisk *disk = bdev->bd_disk;
+       int ret;
+
+       lockdep_assert_held(&bdev->bd_mutex);
+
+       clear_bit(GD_NEED_PART_SCAN, &bdev->bd_disk->state);
+
+rescan:
+       ret = blk_drop_partitions(bdev);
+       if (ret)
+               return ret;
+
+       /*
+        * Historically we only set the capacity to zero for devices that
+        * support partitions (independ of actually having partitions created).
+        * Doing that is rather inconsistent, but changing it broke legacy
+        * udisks polling for legacy ide-cdrom devices.  Use the crude check
+        * below to get the sane behavior for most device while not breaking
+        * userspace for this particular setup.
+        */
+       if (invalidate) {
+               if (disk_part_scan_enabled(disk) ||
+                   !(disk->flags & GENHD_FL_REMOVABLE))
+                       set_capacity(disk, 0);
+       }
+
+       if (get_capacity(disk)) {
+               ret = blk_add_partitions(disk, bdev);
+               if (ret == -EAGAIN)
+                       goto rescan;
+       } else if (invalidate) {
+               /*
+                * Tell userspace that the media / partition table may have
+                * changed.
+                */
+               kobject_uevent(&disk_to_dev(disk)->kobj, KOBJ_CHANGE);
+       }
+
+       return ret;
+}
+/*
+ * Only exported for loop and dasd for historic reasons.  Don't use in new
+ * code!
+ */
+EXPORT_SYMBOL_GPL(bdev_disk_changed);
+
 void *read_part_sector(struct parsed_partitions *state, sector_t n, Sector *p)
 {
        struct address_space *mapping = state->bdev->bd_inode->i_mapping;
index 535d29fa06fa479d63f3cf47df022656ffe8c4e2..4b39477bf89c2b68f6107b8a5a1b1f8bef0e9e4c 100644 (file)
@@ -1233,54 +1233,6 @@ EXPORT_SYMBOL_GPL(bd_unlink_disk_holder);
 
 static void __blkdev_put(struct block_device *bdev, fmode_t mode, int for_part);
 
-int bdev_disk_changed(struct block_device *bdev, bool invalidate)
-{
-       struct gendisk *disk = bdev->bd_disk;
-       int ret;
-
-       lockdep_assert_held(&bdev->bd_mutex);
-
-       clear_bit(GD_NEED_PART_SCAN, &bdev->bd_disk->state);
-
-rescan:
-       ret = blk_drop_partitions(bdev);
-       if (ret)
-               return ret;
-
-       /*
-        * Historically we only set the capacity to zero for devices that
-        * support partitions (independ of actually having partitions created).
-        * Doing that is rather inconsistent, but changing it broke legacy
-        * udisks polling for legacy ide-cdrom devices.  Use the crude check
-        * below to get the sane behavior for most device while not breaking
-        * userspace for this particular setup.
-        */
-       if (invalidate) {
-               if (disk_part_scan_enabled(disk) ||
-                   !(disk->flags & GENHD_FL_REMOVABLE))
-                       set_capacity(disk, 0);
-       }
-
-       if (get_capacity(disk)) {
-               ret = blk_add_partitions(disk, bdev);
-               if (ret == -EAGAIN)
-                       goto rescan;
-       } else if (invalidate) {
-               /*
-                * Tell userspace that the media / partition table may have
-                * changed.
-                */
-               kobject_uevent(&disk_to_dev(disk)->kobj, KOBJ_CHANGE);
-       }
-
-       return ret;
-}
-/*
- * Only exported for loop and dasd for historic reasons.  Don't use in new
- * code!
- */
-EXPORT_SYMBOL_GPL(bdev_disk_changed);
-
 /*
  * bd_mutex locking:
  *
index f364619092cca0dfeddfebc4bbdde97b37c34674..de6390fab74535a3fae09e972e4a7c981df328af 100644 (file)
@@ -272,8 +272,6 @@ static inline sector_t get_capacity(struct gendisk *disk)
 }
 
 int bdev_disk_changed(struct block_device *bdev, bool invalidate);
-int blk_add_partitions(struct gendisk *disk, struct block_device *bdev);
-int blk_drop_partitions(struct block_device *bdev);
 
 extern struct gendisk *__alloc_disk_node(int minors, int node_id);
 extern void put_disk(struct gendisk *disk);