aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/genhd.h
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2008-09-03 03:01:48 -0400
committerJens Axboe <jens.axboe@oracle.com>2008-10-09 02:56:05 -0400
commitf331c0296f2a9fee0d396a70598b954062603015 (patch)
treef74c467d58940131d97d90c4ea549843185e6ef0 /include/linux/genhd.h
parentcf771cb5a7b716f3f9e532fd42a1e3a0a75adec5 (diff)
block: don't depend on consecutive minor space
* Implement disk_devt() and part_devt() and use them to directly access devt instead of computing it from ->major and ->first_minor. Note that all references to ->major and ->first_minor outside of block layer is used to determine devt of the disk (the part0) and as ->major and ->first_minor will continue to represent devt for the disk, converting these users aren't strictly necessary. However, convert them for consistency. * Implement disk_max_parts() to avoid directly deferencing genhd->minors. * Update bdget_disk() such that it doesn't assume consecutive minor space. * Move devt computation from register_disk() to add_disk() and make it the only one (all other usages use the initially determined value). These changes clean up the code and will help disk->part dereference fix and extended block device numbers. Signed-off-by: Tejun Heo <tj@kernel.org> Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
Diffstat (limited to 'include/linux/genhd.h')
-rw-r--r--include/linux/genhd.h27
1 files changed, 21 insertions, 6 deletions
diff --git a/include/linux/genhd.h b/include/linux/genhd.h
index d1723c0a8600..0ff75329199c 100644
--- a/include/linux/genhd.h
+++ b/include/linux/genhd.h
@@ -111,10 +111,14 @@ struct hd_struct {
111#define GENHD_FL_FAIL 64 111#define GENHD_FL_FAIL 64
112 112
113struct gendisk { 113struct gendisk {
114 /* major, first_minor and minors are input parameters only,
115 * don't use directly. Use disk_devt() and disk_max_parts().
116 */
114 int major; /* major number of driver */ 117 int major; /* major number of driver */
115 int first_minor; 118 int first_minor;
116 int minors; /* maximum number of minors, =1 for 119 int minors; /* maximum number of minors, =1 for
117 * disks that can't be partitioned. */ 120 * disks that can't be partitioned. */
121
118 char disk_name[32]; /* name of major driver */ 122 char disk_name[32]; /* name of major driver */
119 struct hd_struct **part; /* [indexed by minor - 1] */ 123 struct hd_struct **part; /* [indexed by minor - 1] */
120 struct block_device_operations *fops; 124 struct block_device_operations *fops;
@@ -152,6 +156,21 @@ static inline struct gendisk *part_to_disk(struct hd_struct *part)
152 return NULL; 156 return NULL;
153} 157}
154 158
159static inline int disk_max_parts(struct gendisk *disk)
160{
161 return disk->minors - 1;
162}
163
164static inline dev_t disk_devt(struct gendisk *disk)
165{
166 return disk->dev.devt;
167}
168
169static inline dev_t part_devt(struct hd_struct *part)
170{
171 return part->dev.devt;
172}
173
155/* 174/*
156 * Macros to operate on percpu disk statistics: 175 * Macros to operate on percpu disk statistics:
157 * 176 *
@@ -163,7 +182,7 @@ static inline struct hd_struct *disk_map_sector(struct gendisk *gendiskp,
163{ 182{
164 struct hd_struct *part; 183 struct hd_struct *part;
165 int i; 184 int i;
166 for (i = 0; i < gendiskp->minors - 1; i++) { 185 for (i = 0; i < disk_max_parts(gendiskp); i++) {
167 part = gendiskp->part[i]; 186 part = gendiskp->part[i];
168 if (part && part->start_sect <= sector 187 if (part && part->start_sect <= sector
169 && sector < part->start_sect + part->nr_sects) 188 && sector < part->start_sect + part->nr_sects)
@@ -366,6 +385,7 @@ extern void add_disk(struct gendisk *disk);
366extern void del_gendisk(struct gendisk *gp); 385extern void del_gendisk(struct gendisk *gp);
367extern void unlink_gendisk(struct gendisk *gp); 386extern void unlink_gendisk(struct gendisk *gp);
368extern struct gendisk *get_gendisk(dev_t dev, int *partno); 387extern struct gendisk *get_gendisk(dev_t dev, int *partno);
388extern struct block_device *bdget_disk(struct gendisk *disk, int partno);
369 389
370extern void set_device_ro(struct block_device *bdev, int flag); 390extern void set_device_ro(struct block_device *bdev, int flag);
371extern void set_disk_ro(struct gendisk *disk, int flag); 391extern void set_disk_ro(struct gendisk *disk, int flag);
@@ -553,11 +573,6 @@ extern void blk_register_region(dev_t devt, unsigned long range,
553 void *data); 573 void *data);
554extern void blk_unregister_region(dev_t devt, unsigned long range); 574extern void blk_unregister_region(dev_t devt, unsigned long range);
555 575
556static inline struct block_device *bdget_disk(struct gendisk *disk, int partno)
557{
558 return bdget(MKDEV(disk->major, disk->first_minor) + partno);
559}
560
561#else /* CONFIG_BLOCK */ 576#else /* CONFIG_BLOCK */
562 577
563static inline void printk_all_partitions(void) { } 578static inline void printk_all_partitions(void) { }