summaryrefslogtreecommitdiffstats
path: root/include/linux/genhd.h
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2008-09-03 09:01:48 +0200
committerJens Axboe <jens.axboe@oracle.com>2008-10-09 08:56:05 +0200
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 d1723c0a860..0ff75329199 100644
--- a/include/linux/genhd.h
+++ b/include/linux/genhd.h
@@ -111,10 +111,14 @@ struct hd_struct {
#define GENHD_FL_FAIL 64
struct gendisk {
+ /* major, first_minor and minors are input parameters only,
+ * don't use directly. Use disk_devt() and disk_max_parts().
+ */
int major; /* major number of driver */
int first_minor;
int minors; /* maximum number of minors, =1 for
* disks that can't be partitioned. */
+
char disk_name[32]; /* name of major driver */
struct hd_struct **part; /* [indexed by minor - 1] */
struct block_device_operations *fops;
@@ -152,6 +156,21 @@ static inline struct gendisk *part_to_disk(struct hd_struct *part)
return NULL;
}
+static inline int disk_max_parts(struct gendisk *disk)
+{
+ return disk->minors - 1;
+}
+
+static inline dev_t disk_devt(struct gendisk *disk)
+{
+ return disk->dev.devt;
+}
+
+static inline dev_t part_devt(struct hd_struct *part)
+{
+ return part->dev.devt;
+}
+
/*
* Macros to operate on percpu disk statistics:
*
@@ -163,7 +182,7 @@ static inline struct hd_struct *disk_map_sector(struct gendisk *gendiskp,
{
struct hd_struct *part;
int i;
- for (i = 0; i < gendiskp->minors - 1; i++) {
+ for (i = 0; i < disk_max_parts(gendiskp); i++) {
part = gendiskp->part[i];
if (part && part->start_sect <= sector
&& sector < part->start_sect + part->nr_sects)
@@ -366,6 +385,7 @@ extern void add_disk(struct gendisk *disk);
extern void del_gendisk(struct gendisk *gp);
extern void unlink_gendisk(struct gendisk *gp);
extern struct gendisk *get_gendisk(dev_t dev, int *partno);
+extern struct block_device *bdget_disk(struct gendisk *disk, int partno);
extern void set_device_ro(struct block_device *bdev, int flag);
extern void set_disk_ro(struct gendisk *disk, int flag);
@@ -553,11 +573,6 @@ extern void blk_register_region(dev_t devt, unsigned long range,
void *data);
extern void blk_unregister_region(dev_t devt, unsigned long range);
-static inline struct block_device *bdget_disk(struct gendisk *disk, int partno)
-{
- return bdget(MKDEV(disk->major, disk->first_minor) + partno);
-}
-
#else /* CONFIG_BLOCK */
static inline void printk_all_partitions(void) { }