diff options
author | Tejun Heo <tj@kernel.org> | 2008-09-03 03:01:48 -0400 |
---|---|---|
committer | Jens Axboe <jens.axboe@oracle.com> | 2008-10-09 02:56:05 -0400 |
commit | f331c0296f2a9fee0d396a70598b954062603015 (patch) | |
tree | f74c467d58940131d97d90c4ea549843185e6ef0 /fs | |
parent | cf771cb5a7b716f3f9e532fd42a1e3a0a75adec5 (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 'fs')
-rw-r--r-- | fs/block_dev.c | 2 | ||||
-rw-r--r-- | fs/partitions/check.c | 19 |
2 files changed, 12 insertions, 9 deletions
diff --git a/fs/block_dev.c b/fs/block_dev.c index de0776cd721..72e0a2887cb 100644 --- a/fs/block_dev.c +++ b/fs/block_dev.c | |||
@@ -892,7 +892,7 @@ int check_disk_change(struct block_device *bdev) | |||
892 | 892 | ||
893 | if (bdops->revalidate_disk) | 893 | if (bdops->revalidate_disk) |
894 | bdops->revalidate_disk(bdev->bd_disk); | 894 | bdops->revalidate_disk(bdev->bd_disk); |
895 | if (bdev->bd_disk->minors > 1) | 895 | if (disk_max_parts(bdev->bd_disk)) |
896 | bdev->bd_invalidated = 1; | 896 | bdev->bd_invalidated = 1; |
897 | return 1; | 897 | return 1; |
898 | } | 898 | } |
diff --git a/fs/partitions/check.c b/fs/partitions/check.c index b86aab1b0df..e77fa144a07 100644 --- a/fs/partitions/check.c +++ b/fs/partitions/check.c | |||
@@ -134,7 +134,11 @@ char *disk_name(struct gendisk *hd, int partno, char *buf) | |||
134 | 134 | ||
135 | const char *bdevname(struct block_device *bdev, char *buf) | 135 | const char *bdevname(struct block_device *bdev, char *buf) |
136 | { | 136 | { |
137 | int partno = MINOR(bdev->bd_dev) - bdev->bd_disk->first_minor; | 137 | int partno = 0; |
138 | |||
139 | if (bdev->bd_part) | ||
140 | partno = bdev->bd_part->partno; | ||
141 | |||
138 | return disk_name(bdev->bd_disk, partno, buf); | 142 | return disk_name(bdev->bd_disk, partno, buf); |
139 | } | 143 | } |
140 | 144 | ||
@@ -169,7 +173,7 @@ check_partition(struct gendisk *hd, struct block_device *bdev) | |||
169 | if (isdigit(state->name[strlen(state->name)-1])) | 173 | if (isdigit(state->name[strlen(state->name)-1])) |
170 | sprintf(state->name, "p"); | 174 | sprintf(state->name, "p"); |
171 | 175 | ||
172 | state->limit = hd->minors; | 176 | state->limit = disk_max_parts(hd) + 1; |
173 | i = res = err = 0; | 177 | i = res = err = 0; |
174 | while (!res && check_part[i]) { | 178 | while (!res && check_part[i]) { |
175 | memset(&state->parts, 0, sizeof(state->parts)); | 179 | memset(&state->parts, 0, sizeof(state->parts)); |
@@ -416,7 +420,6 @@ void register_disk(struct gendisk *disk) | |||
416 | int err; | 420 | int err; |
417 | 421 | ||
418 | disk->dev.parent = disk->driverfs_dev; | 422 | disk->dev.parent = disk->driverfs_dev; |
419 | disk->dev.devt = MKDEV(disk->major, disk->first_minor); | ||
420 | 423 | ||
421 | strlcpy(disk->dev.bus_id, disk->disk_name, BUS_ID_SIZE); | 424 | strlcpy(disk->dev.bus_id, disk->disk_name, BUS_ID_SIZE); |
422 | /* ewww... some of these buggers have / in the name... */ | 425 | /* ewww... some of these buggers have / in the name... */ |
@@ -440,7 +443,7 @@ void register_disk(struct gendisk *disk) | |||
440 | disk_sysfs_add_subdirs(disk); | 443 | disk_sysfs_add_subdirs(disk); |
441 | 444 | ||
442 | /* No minors to use for partitions */ | 445 | /* No minors to use for partitions */ |
443 | if (disk->minors == 1) | 446 | if (!disk_max_parts(disk)) |
444 | goto exit; | 447 | goto exit; |
445 | 448 | ||
446 | /* No such device (e.g., media were just removed) */ | 449 | /* No such device (e.g., media were just removed) */ |
@@ -463,8 +466,8 @@ exit: | |||
463 | kobject_uevent(&disk->dev.kobj, KOBJ_ADD); | 466 | kobject_uevent(&disk->dev.kobj, KOBJ_ADD); |
464 | 467 | ||
465 | /* announce possible partitions */ | 468 | /* announce possible partitions */ |
466 | for (i = 1; i < disk->minors; i++) { | 469 | for (i = 0; i < disk_max_parts(disk); i++) { |
467 | p = disk->part[i-1]; | 470 | p = disk->part[i]; |
468 | if (!p || !p->nr_sects) | 471 | if (!p || !p->nr_sects) |
469 | continue; | 472 | continue; |
470 | kobject_uevent(&p->dev.kobj, KOBJ_ADD); | 473 | kobject_uevent(&p->dev.kobj, KOBJ_ADD); |
@@ -482,7 +485,7 @@ int rescan_partitions(struct gendisk *disk, struct block_device *bdev) | |||
482 | if (res) | 485 | if (res) |
483 | return res; | 486 | return res; |
484 | bdev->bd_invalidated = 0; | 487 | bdev->bd_invalidated = 0; |
485 | for (p = 1; p < disk->minors; p++) | 488 | for (p = 1; p <= disk_max_parts(disk); p++) |
486 | delete_partition(disk, p); | 489 | delete_partition(disk, p); |
487 | if (disk->fops->revalidate_disk) | 490 | if (disk->fops->revalidate_disk) |
488 | disk->fops->revalidate_disk(disk); | 491 | disk->fops->revalidate_disk(disk); |
@@ -545,7 +548,7 @@ void del_gendisk(struct gendisk *disk) | |||
545 | int p; | 548 | int p; |
546 | 549 | ||
547 | /* invalidate stuff */ | 550 | /* invalidate stuff */ |
548 | for (p = disk->minors - 1; p > 0; p--) { | 551 | for (p = disk_max_parts(disk); p > 0; p--) { |
549 | invalidate_partition(disk, p); | 552 | invalidate_partition(disk, p); |
550 | delete_partition(disk, p); | 553 | delete_partition(disk, p); |
551 | } | 554 | } |