block: simplify printk_all_partitions

Just use xa_for_each to iterate over the partitions as there is no need
to grab a reference to each partition.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20210406062303.811835-9-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
Christoph Hellwig 2021-04-06 08:22:59 +02:00 committed by Jens Axboe
parent e30691237b
commit e559f58d20
1 changed files with 16 additions and 17 deletions

View File

@ -806,10 +806,10 @@ void __init printk_all_partitions(void)
class_dev_iter_init(&iter, &block_class, NULL, &disk_type); class_dev_iter_init(&iter, &block_class, NULL, &disk_type);
while ((dev = class_dev_iter_next(&iter))) { while ((dev = class_dev_iter_next(&iter))) {
struct gendisk *disk = dev_to_disk(dev); struct gendisk *disk = dev_to_disk(dev);
struct disk_part_iter piter;
struct block_device *part; struct block_device *part;
char name_buf[BDEVNAME_SIZE]; char name_buf[BDEVNAME_SIZE];
char devt_buf[BDEVT_SIZE]; char devt_buf[BDEVT_SIZE];
unsigned long idx;
/* /*
* Don't show empty devices or things that have been * Don't show empty devices or things that have been
@ -820,30 +820,29 @@ void __init printk_all_partitions(void)
continue; continue;
/* /*
* Note, unlike /proc/partitions, I am showing the * Note, unlike /proc/partitions, I am showing the numbers in
* numbers in hex - the same format as the root= * hex - the same format as the root= option takes.
* option takes.
*/ */
disk_part_iter_init(&piter, disk, DISK_PITER_INCL_PART0); rcu_read_lock();
while ((part = disk_part_iter_next(&piter))) { xa_for_each(&disk->part_tbl, idx, part) {
bool is_part0 = part == disk->part0; if (!bdev_nr_sectors(part))
continue;
printk("%s%s %10llu %s %s", is_part0 ? "" : " ", printk("%s%s %10llu %s %s",
bdev_is_partition(part) ? " " : "",
bdevt_str(part->bd_dev, devt_buf), bdevt_str(part->bd_dev, devt_buf),
bdev_nr_sectors(part) >> 1, bdev_nr_sectors(part) >> 1,
disk_name(disk, part->bd_partno, name_buf), disk_name(disk, part->bd_partno, name_buf),
part->bd_meta_info ? part->bd_meta_info ?
part->bd_meta_info->uuid : ""); part->bd_meta_info->uuid : "");
if (is_part0) { if (bdev_is_partition(part))
if (dev->parent && dev->parent->driver)
printk(" driver: %s\n",
dev->parent->driver->name);
else
printk(" (driver?)\n");
} else
printk("\n"); printk("\n");
else if (dev->parent && dev->parent->driver)
printk(" driver: %s\n",
dev->parent->driver->name);
else
printk(" (driver?)\n");
} }
disk_part_iter_exit(&piter); rcu_read_unlock();
} }
class_dev_iter_exit(&iter); class_dev_iter_exit(&iter);
} }