diff options
author | Tejun Heo <tj@kernel.org> | 2008-08-25 06:47:23 -0400 |
---|---|---|
committer | Jens Axboe <jens.axboe@oracle.com> | 2008-10-09 02:56:06 -0400 |
commit | 1f0142905d4812966831613847db38a66da29eb8 (patch) | |
tree | 0db3c802fccfa7b2b8b74bfd0078258e8fb8e22d | |
parent | bcce3de1be61e424deef35d1e86e86a35c4b6e65 (diff) |
block: adjust formatting for large minors and add ext_range sysfs attr
With extended minors and the soon-to-follow debug feature, large minor
numbers for block devices will be common. This patch does the
followings to make printouts pretty.
* Adapt print formats such that large minors don't break the
formatting.
* For extended MAJ:MIN, %02x%02x for MAJ:MIN used in
printk_all_partitions() doesn't cut it anymore. Update it such that
%03x:%05x is used if either MAJ or MIN doesn't fit in %02x.
* Implement ext_range sysfs attribute which shows total minors the
device can use including both conventional minor space and the
extended one.
Signed-off-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
-rw-r--r-- | block/genhd.c | 45 | ||||
-rw-r--r-- | include/linux/fs.h | 1 |
2 files changed, 35 insertions, 11 deletions
diff --git a/block/genhd.c b/block/genhd.c index 7bbfed05cecb..ee4b13520e59 100644 --- a/block/genhd.c +++ b/block/genhd.c | |||
@@ -366,6 +366,18 @@ void blk_free_devt(dev_t devt) | |||
366 | } | 366 | } |
367 | } | 367 | } |
368 | 368 | ||
369 | static char *bdevt_str(dev_t devt, char *buf) | ||
370 | { | ||
371 | if (MAJOR(devt) <= 0xff && MINOR(devt) <= 0xff) { | ||
372 | char tbuf[BDEVT_SIZE]; | ||
373 | snprintf(tbuf, BDEVT_SIZE, "%02x%02x", MAJOR(devt), MINOR(devt)); | ||
374 | snprintf(buf, BDEVT_SIZE, "%-9s", tbuf); | ||
375 | } else | ||
376 | snprintf(buf, BDEVT_SIZE, "%03x:%05x", MAJOR(devt), MINOR(devt)); | ||
377 | |||
378 | return buf; | ||
379 | } | ||
380 | |||
369 | /* | 381 | /* |
370 | * Register device numbers dev..(dev+range-1) | 382 | * Register device numbers dev..(dev+range-1) |
371 | * range must be nonzero | 383 | * range must be nonzero |
@@ -521,7 +533,8 @@ void __init printk_all_partitions(void) | |||
521 | struct gendisk *disk = dev_to_disk(dev); | 533 | struct gendisk *disk = dev_to_disk(dev); |
522 | struct disk_part_iter piter; | 534 | struct disk_part_iter piter; |
523 | struct hd_struct *part; | 535 | struct hd_struct *part; |
524 | char buf[BDEVNAME_SIZE]; | 536 | char name_buf[BDEVNAME_SIZE]; |
537 | char devt_buf[BDEVT_SIZE]; | ||
525 | 538 | ||
526 | /* | 539 | /* |
527 | * Don't show empty devices or things that have been | 540 | * Don't show empty devices or things that have been |
@@ -536,10 +549,10 @@ void __init printk_all_partitions(void) | |||
536 | * numbers in hex - the same format as the root= | 549 | * numbers in hex - the same format as the root= |
537 | * option takes. | 550 | * option takes. |
538 | */ | 551 | */ |
539 | printk("%02x%02x %10llu %s", | 552 | printk("%s %10llu %s", |
540 | MAJOR(disk_devt(disk)), MINOR(disk_devt(disk)), | 553 | bdevt_str(disk_devt(disk), devt_buf), |
541 | (unsigned long long)get_capacity(disk) >> 1, | 554 | (unsigned long long)get_capacity(disk) >> 1, |
542 | disk_name(disk, 0, buf)); | 555 | disk_name(disk, 0, name_buf)); |
543 | if (disk->driverfs_dev != NULL && | 556 | if (disk->driverfs_dev != NULL && |
544 | disk->driverfs_dev->driver != NULL) | 557 | disk->driverfs_dev->driver != NULL) |
545 | printk(" driver: %s\n", | 558 | printk(" driver: %s\n", |
@@ -550,10 +563,10 @@ void __init printk_all_partitions(void) | |||
550 | /* now show the partitions */ | 563 | /* now show the partitions */ |
551 | disk_part_iter_init(&piter, disk, 0); | 564 | disk_part_iter_init(&piter, disk, 0); |
552 | while ((part = disk_part_iter_next(&piter))) | 565 | while ((part = disk_part_iter_next(&piter))) |
553 | printk(" %02x%02x %10llu %s\n", | 566 | printk(" %s %10llu %s\n", |
554 | MAJOR(part_devt(part)), MINOR(part_devt(part)), | 567 | bdevt_str(part_devt(part), devt_buf), |
555 | (unsigned long long)part->nr_sects >> 1, | 568 | (unsigned long long)part->nr_sects >> 1, |
556 | disk_name(disk, part->partno, buf)); | 569 | disk_name(disk, part->partno, name_buf)); |
557 | disk_part_iter_exit(&piter); | 570 | disk_part_iter_exit(&piter); |
558 | } | 571 | } |
559 | class_dev_iter_exit(&iter); | 572 | class_dev_iter_exit(&iter); |
@@ -630,14 +643,14 @@ static int show_partition(struct seq_file *seqf, void *v) | |||
630 | return 0; | 643 | return 0; |
631 | 644 | ||
632 | /* show the full disk and all non-0 size partitions of it */ | 645 | /* show the full disk and all non-0 size partitions of it */ |
633 | seq_printf(seqf, "%4d %4d %10llu %s\n", | 646 | seq_printf(seqf, "%4d %7d %10llu %s\n", |
634 | MAJOR(disk_devt(sgp)), MINOR(disk_devt(sgp)), | 647 | MAJOR(disk_devt(sgp)), MINOR(disk_devt(sgp)), |
635 | (unsigned long long)get_capacity(sgp) >> 1, | 648 | (unsigned long long)get_capacity(sgp) >> 1, |
636 | disk_name(sgp, 0, buf)); | 649 | disk_name(sgp, 0, buf)); |
637 | 650 | ||
638 | disk_part_iter_init(&piter, sgp, 0); | 651 | disk_part_iter_init(&piter, sgp, 0); |
639 | while ((part = disk_part_iter_next(&piter))) | 652 | while ((part = disk_part_iter_next(&piter))) |
640 | seq_printf(seqf, "%4d %4d %10llu %s\n", | 653 | seq_printf(seqf, "%4d %7d %10llu %s\n", |
641 | MAJOR(part_devt(part)), MINOR(part_devt(part)), | 654 | MAJOR(part_devt(part)), MINOR(part_devt(part)), |
642 | (unsigned long long)part->nr_sects >> 1, | 655 | (unsigned long long)part->nr_sects >> 1, |
643 | disk_name(sgp, part->partno, buf)); | 656 | disk_name(sgp, part->partno, buf)); |
@@ -691,6 +704,14 @@ static ssize_t disk_range_show(struct device *dev, | |||
691 | return sprintf(buf, "%d\n", disk->minors); | 704 | return sprintf(buf, "%d\n", disk->minors); |
692 | } | 705 | } |
693 | 706 | ||
707 | static ssize_t disk_ext_range_show(struct device *dev, | ||
708 | struct device_attribute *attr, char *buf) | ||
709 | { | ||
710 | struct gendisk *disk = dev_to_disk(dev); | ||
711 | |||
712 | return sprintf(buf, "%d\n", disk_max_parts(disk) + 1); | ||
713 | } | ||
714 | |||
694 | static ssize_t disk_removable_show(struct device *dev, | 715 | static ssize_t disk_removable_show(struct device *dev, |
695 | struct device_attribute *attr, char *buf) | 716 | struct device_attribute *attr, char *buf) |
696 | { | 717 | { |
@@ -780,6 +801,7 @@ static ssize_t disk_fail_store(struct device *dev, | |||
780 | #endif | 801 | #endif |
781 | 802 | ||
782 | static DEVICE_ATTR(range, S_IRUGO, disk_range_show, NULL); | 803 | static DEVICE_ATTR(range, S_IRUGO, disk_range_show, NULL); |
804 | static DEVICE_ATTR(ext_range, S_IRUGO, disk_ext_range_show, NULL); | ||
783 | static DEVICE_ATTR(removable, S_IRUGO, disk_removable_show, NULL); | 805 | static DEVICE_ATTR(removable, S_IRUGO, disk_removable_show, NULL); |
784 | static DEVICE_ATTR(ro, S_IRUGO, disk_ro_show, NULL); | 806 | static DEVICE_ATTR(ro, S_IRUGO, disk_ro_show, NULL); |
785 | static DEVICE_ATTR(size, S_IRUGO, disk_size_show, NULL); | 807 | static DEVICE_ATTR(size, S_IRUGO, disk_size_show, NULL); |
@@ -792,6 +814,7 @@ static struct device_attribute dev_attr_fail = | |||
792 | 814 | ||
793 | static struct attribute *disk_attrs[] = { | 815 | static struct attribute *disk_attrs[] = { |
794 | &dev_attr_range.attr, | 816 | &dev_attr_range.attr, |
817 | &dev_attr_ext_range.attr, | ||
795 | &dev_attr_removable.attr, | 818 | &dev_attr_removable.attr, |
796 | &dev_attr_ro.attr, | 819 | &dev_attr_ro.attr, |
797 | &dev_attr_size.attr, | 820 | &dev_attr_size.attr, |
@@ -858,7 +881,7 @@ static int diskstats_show(struct seq_file *seqf, void *v) | |||
858 | cpu = disk_stat_lock(); | 881 | cpu = disk_stat_lock(); |
859 | disk_round_stats(cpu, gp); | 882 | disk_round_stats(cpu, gp); |
860 | disk_stat_unlock(); | 883 | disk_stat_unlock(); |
861 | seq_printf(seqf, "%4d %4d %s %lu %lu %llu %u %lu %lu %llu %u %u %u %u\n", | 884 | seq_printf(seqf, "%4d %7d %s %lu %lu %llu %u %lu %lu %llu %u %u %u %u\n", |
862 | MAJOR(disk_devt(gp)), MINOR(disk_devt(gp)), | 885 | MAJOR(disk_devt(gp)), MINOR(disk_devt(gp)), |
863 | disk_name(gp, 0, buf), | 886 | disk_name(gp, 0, buf), |
864 | disk_stat_read(gp, ios[0]), disk_stat_read(gp, merges[0]), | 887 | disk_stat_read(gp, ios[0]), disk_stat_read(gp, merges[0]), |
@@ -877,7 +900,7 @@ static int diskstats_show(struct seq_file *seqf, void *v) | |||
877 | cpu = disk_stat_lock(); | 900 | cpu = disk_stat_lock(); |
878 | part_round_stats(cpu, hd); | 901 | part_round_stats(cpu, hd); |
879 | disk_stat_unlock(); | 902 | disk_stat_unlock(); |
880 | seq_printf(seqf, "%4d %4d %s %lu %lu %llu " | 903 | seq_printf(seqf, "%4d %7d %s %lu %lu %llu " |
881 | "%u %lu %lu %llu %u %u %u %u\n", | 904 | "%u %lu %lu %llu %u %u %u %u\n", |
882 | MAJOR(part_devt(hd)), MINOR(part_devt(hd)), | 905 | MAJOR(part_devt(hd)), MINOR(part_devt(hd)), |
883 | disk_name(gp, hd->partno, buf), | 906 | disk_name(gp, hd->partno, buf), |
diff --git a/include/linux/fs.h b/include/linux/fs.h index 860689f541b1..02a9fb5a830c 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h | |||
@@ -1685,6 +1685,7 @@ extern void chrdev_show(struct seq_file *,off_t); | |||
1685 | 1685 | ||
1686 | /* fs/block_dev.c */ | 1686 | /* fs/block_dev.c */ |
1687 | #define BDEVNAME_SIZE 32 /* Largest string for a blockdev identifier */ | 1687 | #define BDEVNAME_SIZE 32 /* Largest string for a blockdev identifier */ |
1688 | #define BDEVT_SIZE 10 /* Largest string for MAJ:MIN for blkdev */ | ||
1688 | 1689 | ||
1689 | #ifdef CONFIG_BLOCK | 1690 | #ifdef CONFIG_BLOCK |
1690 | #define BLKDEV_MAJOR_HASH_SIZE 255 | 1691 | #define BLKDEV_MAJOR_HASH_SIZE 255 |