aboutsummaryrefslogtreecommitdiffstats
path: root/block/genhd.c
diff options
context:
space:
mode:
Diffstat (limited to 'block/genhd.c')
-rw-r--r--block/genhd.c97
1 files changed, 24 insertions, 73 deletions
diff --git a/block/genhd.c b/block/genhd.c
index 06a252f2b967..e1cb96fb883e 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -176,7 +176,7 @@ EXPORT_SYMBOL_GPL(disk_part_iter_exit);
176 * while preemption is disabled. 176 * while preemption is disabled.
177 * 177 *
178 * RETURNS: 178 * RETURNS:
179 * Found partition on success, NULL if there's no matching partition. 179 * Found partition on success, part0 is returned if no partition matches
180 */ 180 */
181struct hd_struct *disk_map_sector_rcu(struct gendisk *disk, sector_t sector) 181struct hd_struct *disk_map_sector_rcu(struct gendisk *disk, sector_t sector)
182{ 182{
@@ -189,7 +189,7 @@ struct hd_struct *disk_map_sector_rcu(struct gendisk *disk, sector_t sector)
189 sector < part->start_sect + part->nr_sects) 189 sector < part->start_sect + part->nr_sects)
190 return part; 190 return part;
191 } 191 }
192 return NULL; 192 return &disk->part0;
193} 193}
194EXPORT_SYMBOL_GPL(disk_map_sector_rcu); 194EXPORT_SYMBOL_GPL(disk_map_sector_rcu);
195 195
@@ -580,24 +580,24 @@ void __init printk_all_partitions(void)
580 * numbers in hex - the same format as the root= 580 * numbers in hex - the same format as the root=
581 * option takes. 581 * option takes.
582 */ 582 */
583 printk("%s %10llu %s", 583 disk_part_iter_init(&piter, disk, DISK_PITER_INCL_PART0);
584 bdevt_str(disk_devt(disk), devt_buf), 584 while ((part = disk_part_iter_next(&piter))) {
585 (unsigned long long)get_capacity(disk) >> 1, 585 bool is_part0 = part == &disk->part0;
586 disk_name(disk, 0, name_buf));
587 if (disk->driverfs_dev != NULL &&
588 disk->driverfs_dev->driver != NULL)
589 printk(" driver: %s\n",
590 disk->driverfs_dev->driver->name);
591 else
592 printk(" (driver?)\n");
593 586
594 /* now show the partitions */ 587 printk("%s%s %10llu %s", is_part0 ? "" : " ",
595 disk_part_iter_init(&piter, disk, 0);
596 while ((part = disk_part_iter_next(&piter)))
597 printk(" %s %10llu %s\n",
598 bdevt_str(part_devt(part), devt_buf), 588 bdevt_str(part_devt(part), devt_buf),
599 (unsigned long long)part->nr_sects >> 1, 589 (unsigned long long)part->nr_sects >> 1,
600 disk_name(disk, part->partno, name_buf)); 590 disk_name(disk, part->partno, name_buf));
591 if (is_part0) {
592 if (disk->driverfs_dev != NULL &&
593 disk->driverfs_dev->driver != NULL)
594 printk(" driver: %s\n",
595 disk->driverfs_dev->driver->name);
596 else
597 printk(" (driver?)\n");
598 } else
599 printk("\n");
600 }
601 disk_part_iter_exit(&piter); 601 disk_part_iter_exit(&piter);
602 } 602 }
603 class_dev_iter_exit(&iter); 603 class_dev_iter_exit(&iter);
@@ -674,12 +674,7 @@ static int show_partition(struct seq_file *seqf, void *v)
674 return 0; 674 return 0;
675 675
676 /* show the full disk and all non-0 size partitions of it */ 676 /* show the full disk and all non-0 size partitions of it */
677 seq_printf(seqf, "%4d %7d %10llu %s\n", 677 disk_part_iter_init(&piter, sgp, DISK_PITER_INCL_PART0);
678 MAJOR(disk_devt(sgp)), MINOR(disk_devt(sgp)),
679 (unsigned long long)get_capacity(sgp) >> 1,
680 disk_name(sgp, 0, buf));
681
682 disk_part_iter_init(&piter, sgp, 0);
683 while ((part = disk_part_iter_next(&piter))) 678 while ((part = disk_part_iter_next(&piter)))
684 seq_printf(seqf, "%4d %7d %10llu %s\n", 679 seq_printf(seqf, "%4d %7d %10llu %s\n",
685 MAJOR(part_devt(part)), MINOR(part_devt(part)), 680 MAJOR(part_devt(part)), MINOR(part_devt(part)),
@@ -768,40 +763,13 @@ static ssize_t disk_capability_show(struct device *dev,
768 return sprintf(buf, "%x\n", disk->flags); 763 return sprintf(buf, "%x\n", disk->flags);
769} 764}
770 765
771static ssize_t disk_stat_show(struct device *dev,
772 struct device_attribute *attr, char *buf)
773{
774 struct gendisk *disk = dev_to_disk(dev);
775 int cpu;
776
777 cpu = disk_stat_lock();
778 disk_round_stats(cpu, disk);
779 disk_stat_unlock();
780 return sprintf(buf,
781 "%8lu %8lu %8llu %8u "
782 "%8lu %8lu %8llu %8u "
783 "%8u %8u %8u"
784 "\n",
785 disk_stat_read(disk, ios[READ]),
786 disk_stat_read(disk, merges[READ]),
787 (unsigned long long)disk_stat_read(disk, sectors[READ]),
788 jiffies_to_msecs(disk_stat_read(disk, ticks[READ])),
789 disk_stat_read(disk, ios[WRITE]),
790 disk_stat_read(disk, merges[WRITE]),
791 (unsigned long long)disk_stat_read(disk, sectors[WRITE]),
792 jiffies_to_msecs(disk_stat_read(disk, ticks[WRITE])),
793 disk->in_flight,
794 jiffies_to_msecs(disk_stat_read(disk, io_ticks)),
795 jiffies_to_msecs(disk_stat_read(disk, time_in_queue)));
796}
797
798static DEVICE_ATTR(range, S_IRUGO, disk_range_show, NULL); 766static DEVICE_ATTR(range, S_IRUGO, disk_range_show, NULL);
799static DEVICE_ATTR(ext_range, S_IRUGO, disk_ext_range_show, NULL); 767static DEVICE_ATTR(ext_range, S_IRUGO, disk_ext_range_show, NULL);
800static DEVICE_ATTR(removable, S_IRUGO, disk_removable_show, NULL); 768static DEVICE_ATTR(removable, S_IRUGO, disk_removable_show, NULL);
801static DEVICE_ATTR(ro, S_IRUGO, disk_ro_show, NULL); 769static DEVICE_ATTR(ro, S_IRUGO, disk_ro_show, NULL);
802static DEVICE_ATTR(size, S_IRUGO, part_size_show, NULL); 770static DEVICE_ATTR(size, S_IRUGO, part_size_show, NULL);
803static DEVICE_ATTR(capability, S_IRUGO, disk_capability_show, NULL); 771static DEVICE_ATTR(capability, S_IRUGO, disk_capability_show, NULL);
804static DEVICE_ATTR(stat, S_IRUGO, disk_stat_show, NULL); 772static DEVICE_ATTR(stat, S_IRUGO, part_stat_show, NULL);
805#ifdef CONFIG_FAIL_MAKE_REQUEST 773#ifdef CONFIG_FAIL_MAKE_REQUEST
806static struct device_attribute dev_attr_fail = 774static struct device_attribute dev_attr_fail =
807 __ATTR(make-it-fail, S_IRUGO|S_IWUSR, part_fail_show, part_fail_store); 775 __ATTR(make-it-fail, S_IRUGO|S_IWUSR, part_fail_show, part_fail_store);
@@ -836,7 +804,7 @@ static void disk_release(struct device *dev)
836 804
837 kfree(disk->random); 805 kfree(disk->random);
838 kfree(disk->__part); 806 kfree(disk->__part);
839 free_disk_stats(disk); 807 free_part_stats(&disk->part0);
840 kfree(disk); 808 kfree(disk);
841} 809}
842struct class block_class = { 810struct class block_class = {
@@ -873,28 +841,11 @@ static int diskstats_show(struct seq_file *seqf, void *v)
873 "\n\n"); 841 "\n\n");
874 */ 842 */
875 843
876 cpu = disk_stat_lock(); 844 disk_part_iter_init(&piter, gp, DISK_PITER_INCL_PART0);
877 disk_round_stats(cpu, gp);
878 disk_stat_unlock();
879 seq_printf(seqf, "%4d %7d %s %lu %lu %llu %u %lu %lu %llu %u %u %u %u\n",
880 MAJOR(disk_devt(gp)), MINOR(disk_devt(gp)),
881 disk_name(gp, 0, buf),
882 disk_stat_read(gp, ios[0]), disk_stat_read(gp, merges[0]),
883 (unsigned long long)disk_stat_read(gp, sectors[0]),
884 jiffies_to_msecs(disk_stat_read(gp, ticks[0])),
885 disk_stat_read(gp, ios[1]), disk_stat_read(gp, merges[1]),
886 (unsigned long long)disk_stat_read(gp, sectors[1]),
887 jiffies_to_msecs(disk_stat_read(gp, ticks[1])),
888 gp->in_flight,
889 jiffies_to_msecs(disk_stat_read(gp, io_ticks)),
890 jiffies_to_msecs(disk_stat_read(gp, time_in_queue)));
891
892 /* now show all non-0 size partitions of it */
893 disk_part_iter_init(&piter, gp, 0);
894 while ((hd = disk_part_iter_next(&piter))) { 845 while ((hd = disk_part_iter_next(&piter))) {
895 cpu = disk_stat_lock(); 846 cpu = part_stat_lock();
896 part_round_stats(cpu, hd); 847 part_round_stats(cpu, hd);
897 disk_stat_unlock(); 848 part_stat_unlock();
898 seq_printf(seqf, "%4d %7d %s %lu %lu %llu " 849 seq_printf(seqf, "%4d %7d %s %lu %lu %llu "
899 "%u %lu %lu %llu %u %u %u %u\n", 850 "%u %lu %lu %llu %u %u %u %u\n",
900 MAJOR(part_devt(hd)), MINOR(part_devt(hd)), 851 MAJOR(part_devt(hd)), MINOR(part_devt(hd)),
@@ -1000,7 +951,7 @@ struct gendisk *alloc_disk_ext_node(int minors, int ext_minors, int node_id)
1000 int tot_minors = minors + ext_minors; 951 int tot_minors = minors + ext_minors;
1001 int size = tot_minors * sizeof(struct hd_struct *); 952 int size = tot_minors * sizeof(struct hd_struct *);
1002 953
1003 if (!init_disk_stats(disk)) { 954 if (!init_part_stats(&disk->part0)) {
1004 kfree(disk); 955 kfree(disk);
1005 return NULL; 956 return NULL;
1006 } 957 }
@@ -1008,7 +959,7 @@ struct gendisk *alloc_disk_ext_node(int minors, int ext_minors, int node_id)
1008 disk->__part = kmalloc_node(size, GFP_KERNEL | __GFP_ZERO, 959 disk->__part = kmalloc_node(size, GFP_KERNEL | __GFP_ZERO,
1009 node_id); 960 node_id);
1010 if (!disk->__part) { 961 if (!disk->__part) {
1011 free_disk_stats(disk); 962 free_part_stats(&disk->part0);
1012 kfree(disk); 963 kfree(disk);
1013 return NULL; 964 return NULL;
1014 } 965 }