aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2008-08-29 03:01:47 -0400
committerJens Axboe <jens.axboe@oracle.com>2008-10-09 02:56:07 -0400
commit548b10eb2959c96cef6fc29fc96e0931eeb53bc5 (patch)
tree7166bc04336b80a69f87a9add097919b418f4f43
parent80795aefb76d10c5d698e60c7e7750b5330787da (diff)
block: move __dev from disk to part0
Move disk->__dev to part0->__dev. This simplifies bdget_disk() and lookup_devt() and allows common sysfs attributes to be unified. part_to_disk() is updated to handle part0 -> disk. Updated to include a fix from Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>, he writes: "part0 is a "special" partition and doesn't need to have capacity set - this fixes regression caused by "block: move __dev from disk to part0" commit." Signed-off-by: Tejun Heo <tj@kernel.org> Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
-rw-r--r--block/genhd.c40
-rw-r--r--include/linux/genhd.h13
2 files changed, 20 insertions, 33 deletions
diff --git a/block/genhd.c b/block/genhd.c
index 65b7386c26d8..36b9f1bdd91f 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -537,22 +537,15 @@ struct gendisk *get_gendisk(dev_t devt, int *partno)
537 */ 537 */
538extern struct block_device *bdget_disk(struct gendisk *disk, int partno) 538extern struct block_device *bdget_disk(struct gendisk *disk, int partno)
539{ 539{
540 dev_t devt = MKDEV(0, 0); 540 struct hd_struct *part;
541 struct block_device *bdev = NULL;
541 542
542 if (partno == 0) 543 part = disk_get_part(disk, partno);
543 devt = disk_devt(disk); 544 if (part && (part->nr_sects || partno == 0))
544 else { 545 bdev = bdget(part_devt(part));
545 struct hd_struct *part; 546 disk_put_part(part);
546 547
547 part = disk_get_part(disk, partno); 548 return bdev;
548 if (part && part->nr_sects)
549 devt = part_devt(part);
550 disk_put_part(part);
551 }
552
553 if (likely(devt != MKDEV(0, 0)))
554 return bdget(devt);
555 return NULL;
556} 549}
557EXPORT_SYMBOL(bdget_disk); 550EXPORT_SYMBOL(bdget_disk);
558 551
@@ -1000,27 +993,18 @@ dev_t blk_lookup_devt(const char *name, int partno)
1000 class_dev_iter_init(&iter, &block_class, NULL, &disk_type); 993 class_dev_iter_init(&iter, &block_class, NULL, &disk_type);
1001 while ((dev = class_dev_iter_next(&iter))) { 994 while ((dev = class_dev_iter_next(&iter))) {
1002 struct gendisk *disk = dev_to_disk(dev); 995 struct gendisk *disk = dev_to_disk(dev);
996 struct hd_struct *part;
1003 997
1004 if (strcmp(dev->bus_id, name)) 998 if (strcmp(dev->bus_id, name))
1005 continue; 999 continue;
1006 if (partno < 0 || partno >= disk_max_parts(disk))
1007 continue;
1008
1009 if (partno == 0)
1010 devt = disk_devt(disk);
1011 else {
1012 struct hd_struct *part;
1013
1014 part = disk_get_part(disk, partno);
1015 if (!part || !part->nr_sects) {
1016 disk_put_part(part);
1017 continue;
1018 }
1019 1000
1001 part = disk_get_part(disk, partno);
1002 if (part && (part->nr_sects || partno == 0)) {
1020 devt = part_devt(part); 1003 devt = part_devt(part);
1021 disk_put_part(part); 1004 disk_put_part(part);
1005 break;
1022 } 1006 }
1023 break; 1007 disk_put_part(part);
1024 } 1008 }
1025 class_dev_iter_exit(&iter); 1009 class_dev_iter_exit(&iter);
1026 return devt; 1010 return devt;
diff --git a/include/linux/genhd.h b/include/linux/genhd.h
index 1cf828148ec6..ff293ec8b3f7 100644
--- a/include/linux/genhd.h
+++ b/include/linux/genhd.h
@@ -16,9 +16,9 @@
16#ifdef CONFIG_BLOCK 16#ifdef CONFIG_BLOCK
17 17
18#define kobj_to_dev(k) container_of((k), struct device, kobj) 18#define kobj_to_dev(k) container_of((k), struct device, kobj)
19#define dev_to_disk(device) container_of((device), struct gendisk, __dev) 19#define dev_to_disk(device) container_of((device), struct gendisk, part0.__dev)
20#define dev_to_part(device) container_of((device), struct hd_struct, __dev) 20#define dev_to_part(device) container_of((device), struct hd_struct, __dev)
21#define disk_to_dev(disk) (&((disk)->__dev)) 21#define disk_to_dev(disk) (&(disk)->part0.__dev)
22#define part_to_dev(part) (&((part)->__dev)) 22#define part_to_dev(part) (&((part)->__dev))
23 23
24extern struct device_type part_type; 24extern struct device_type part_type;
@@ -141,7 +141,6 @@ struct gendisk {
141 141
142 int flags; 142 int flags;
143 struct device *driverfs_dev; // FIXME: remove 143 struct device *driverfs_dev; // FIXME: remove
144 struct device __dev;
145 struct kobject *holder_dir; 144 struct kobject *holder_dir;
146 struct kobject *slave_dir; 145 struct kobject *slave_dir;
147 146
@@ -164,8 +163,12 @@ struct gendisk {
164 163
165static inline struct gendisk *part_to_disk(struct hd_struct *part) 164static inline struct gendisk *part_to_disk(struct hd_struct *part)
166{ 165{
167 if (likely(part)) 166 if (likely(part)) {
168 return dev_to_disk(part_to_dev(part)->parent); 167 if (part->partno)
168 return dev_to_disk(part_to_dev(part)->parent);
169 else
170 return dev_to_disk(part_to_dev(part));
171 }
169 return NULL; 172 return NULL;
170} 173}
171 174