]> www.infradead.org Git - users/hch/block.git/commitdiff
block: simplify partition removal
authorChristoph Hellwig <hch@lst.de>
Fri, 26 Mar 2021 14:16:50 +0000 (15:16 +0100)
committerChristoph Hellwig <hch@lst.de>
Fri, 2 Apr 2021 17:48:04 +0000 (19:48 +0200)
Always look up the first available entry instead of the complicated
stateful traversal.

Signed-off-by: Christoph Hellwig <hch@lst.de>
block/partitions/core.c

index 9fbaec466b516deea1401bf73f6e340ba52383ef..927144d4e59d3950897420b87620a03a50d22808 100644 (file)
@@ -528,15 +528,17 @@ static bool disk_unlock_native_capacity(struct gendisk *disk)
 
 void blk_drop_partitions(struct gendisk *disk)
 {
-       struct disk_part_iter piter;
        struct block_device *part;
+       unsigned long idx;
 
        lockdep_assert_held(&disk->part0->bd_mutex);
 
-       disk_part_iter_init(&piter, disk, DISK_PITER_INCL_EMPTY);
-       while ((part = disk_part_iter_next(&piter)))
+       xa_for_each_start(&disk->part_tbl, idx, part, 1) {
+               if (!bdgrab(part))
+                       continue;
                delete_partition(part);
-       disk_part_iter_exit(&piter);
+               bdput(part);
+       }
 }
 
 static bool blk_add_partition(struct gendisk *disk, struct block_device *bdev,