block: remove disk_part_iter
authorChristoph Hellwig <hch@lst.de>
Tue, 6 Apr 2021 06:23:02 +0000 (08:23 +0200)
committerJens Axboe <axboe@kernel.dk>
Thu, 8 Apr 2021 16:24:36 +0000 (10:24 -0600)
Just open code the xa_for_each in the remaining user.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20210406062303.811835-12-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/genhd.c
include/linux/genhd.h

index cbfe1ff..39ca97b 100644 (file)
@@ -161,81 +161,6 @@ static void part_in_flight_rw(struct block_device *part,
                inflight[1] = 0;
 }
 
-/**
- * disk_part_iter_init - initialize partition iterator
- * @piter: iterator to initialize
- * @disk: disk to iterate over
- * @flags: DISK_PITER_* flags
- *
- * Initialize @piter so that it iterates over partitions of @disk.
- *
- * CONTEXT:
- * Don't care.
- */
-void disk_part_iter_init(struct disk_part_iter *piter, struct gendisk *disk,
-                         unsigned int flags)
-{
-       piter->disk = disk;
-       piter->part = NULL;
-       if (flags & (DISK_PITER_INCL_PART0 | DISK_PITER_INCL_EMPTY_PART0))
-               piter->idx = 0;
-       else
-               piter->idx = 1;
-       piter->flags = flags;
-}
-
-/**
- * disk_part_iter_next - proceed iterator to the next partition and return it
- * @piter: iterator of interest
- *
- * Proceed @piter to the next partition and return it.
- *
- * CONTEXT:
- * Don't care.
- */
-struct block_device *disk_part_iter_next(struct disk_part_iter *piter)
-{
-       struct block_device *part;
-       unsigned long idx;
-
-       /* put the last partition */
-       disk_part_iter_exit(piter);
-
-       rcu_read_lock();
-       xa_for_each_start(&piter->disk->part_tbl, idx, part, piter->idx) {
-               if (!bdev_nr_sectors(part) &&
-                   !(piter->flags & DISK_PITER_INCL_EMPTY) &&
-                   !(piter->flags & DISK_PITER_INCL_EMPTY_PART0 &&
-                     piter->idx == 0))
-                       continue;
-
-               piter->part = bdgrab(part);
-               if (!piter->part)
-                       continue;
-               piter->idx = idx + 1;
-               break;
-       }
-       rcu_read_unlock();
-
-       return piter->part;
-}
-
-/**
- * disk_part_iter_exit - finish up partition iteration
- * @piter: iter of interest
- *
- * Called when iteration is over.  Cleans up @piter.
- *
- * CONTEXT:
- * Don't care.
- */
-void disk_part_iter_exit(struct disk_part_iter *piter)
-{
-       if (piter->part)
-               bdput(piter->part);
-       piter->part = NULL;
-}
-
 /*
  * Can be deleted altogether. Later.
  *
@@ -472,13 +397,22 @@ static char *bdevt_str(dev_t devt, char *buf)
 
 void disk_uevent(struct gendisk *disk, enum kobject_action action)
 {
-       struct disk_part_iter piter;
        struct block_device *part;
+       unsigned long idx;
+
+       rcu_read_lock();
+       xa_for_each(&disk->part_tbl, idx, part) {
+               if (bdev_is_partition(part) && !bdev_nr_sectors(part))
+                       continue;
+               if (!bdgrab(part))
+                       continue;
 
-       disk_part_iter_init(&piter, disk, DISK_PITER_INCL_EMPTY_PART0);
-       while ((part = disk_part_iter_next(&piter)))
+               rcu_read_unlock();
                kobject_uevent(bdev_kobj(part), action);
-       disk_part_iter_exit(&piter);
+               bdput(part);
+               rcu_read_lock();
+       }
+       rcu_read_unlock();
 }
 EXPORT_SYMBOL_GPL(disk_uevent);
 
index 16178a9..7e9660e 100644 (file)
@@ -204,25 +204,6 @@ static inline dev_t disk_devt(struct gendisk *disk)
 
 void disk_uevent(struct gendisk *disk, enum kobject_action action);
 
-/*
- * Smarter partition iterator without context limits.
- */
-#define DISK_PITER_INCL_EMPTY  (1 << 1) /* include 0-sized parts */
-#define DISK_PITER_INCL_PART0  (1 << 2) /* include partition 0 */
-#define DISK_PITER_INCL_EMPTY_PART0 (1 << 3) /* include empty partition 0 */
-
-struct disk_part_iter {
-       struct gendisk          *disk;
-       struct block_device     *part;
-       unsigned long           idx;
-       unsigned int            flags;
-};
-
-extern void disk_part_iter_init(struct disk_part_iter *piter,
-                                struct gendisk *disk, unsigned int flags);
-struct block_device *disk_part_iter_next(struct disk_part_iter *piter);
-extern void disk_part_iter_exit(struct disk_part_iter *piter);
-
 /* block/genhd.c */
 extern void device_add_disk(struct device *parent, struct gendisk *disk,
                            const struct attribute_group **groups);