diff options
author | Tejun Heo <tj@kernel.org> | 2010-12-08 14:57:36 -0500 |
---|---|---|
committer | Jens Axboe <jaxboe@fusionio.com> | 2010-12-16 11:53:38 -0500 |
commit | d2bf1b6723ed0eab378363649d15b7893bf14e91 (patch) | |
tree | 4a4144b09ab747ad661605aa761753d9a805e77f /block/genhd.c | |
parent | dddd9dc340ae1a41d90e084529ca979c77c4ecfe (diff) |
block: move register_disk() and del_gendisk() to block/genhd.c
There's no reason for register_disk() and del_gendisk() to be in
fs/partitions/check.c. Move both to genhd.c. While at it, collapse
unlink_gendisk(), which was artificially in a separate function due to
genhd.c / check.c split, into del_gendisk().
Signed-off-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
Diffstat (limited to 'block/genhd.c')
-rw-r--r-- | block/genhd.c | 90 |
1 files changed, 87 insertions, 3 deletions
diff --git a/block/genhd.c b/block/genhd.c index 0905ab22c8cf..2e5e4c0a1133 100644 --- a/block/genhd.c +++ b/block/genhd.c | |||
@@ -502,6 +502,64 @@ static int exact_lock(dev_t devt, void *data) | |||
502 | return 0; | 502 | return 0; |
503 | } | 503 | } |
504 | 504 | ||
505 | void register_disk(struct gendisk *disk) | ||
506 | { | ||
507 | struct device *ddev = disk_to_dev(disk); | ||
508 | struct block_device *bdev; | ||
509 | struct disk_part_iter piter; | ||
510 | struct hd_struct *part; | ||
511 | int err; | ||
512 | |||
513 | ddev->parent = disk->driverfs_dev; | ||
514 | |||
515 | dev_set_name(ddev, disk->disk_name); | ||
516 | |||
517 | /* delay uevents, until we scanned partition table */ | ||
518 | dev_set_uevent_suppress(ddev, 1); | ||
519 | |||
520 | if (device_add(ddev)) | ||
521 | return; | ||
522 | if (!sysfs_deprecated) { | ||
523 | err = sysfs_create_link(block_depr, &ddev->kobj, | ||
524 | kobject_name(&ddev->kobj)); | ||
525 | if (err) { | ||
526 | device_del(ddev); | ||
527 | return; | ||
528 | } | ||
529 | } | ||
530 | disk->part0.holder_dir = kobject_create_and_add("holders", &ddev->kobj); | ||
531 | disk->slave_dir = kobject_create_and_add("slaves", &ddev->kobj); | ||
532 | |||
533 | /* No minors to use for partitions */ | ||
534 | if (!disk_partitionable(disk)) | ||
535 | goto exit; | ||
536 | |||
537 | /* No such device (e.g., media were just removed) */ | ||
538 | if (!get_capacity(disk)) | ||
539 | goto exit; | ||
540 | |||
541 | bdev = bdget_disk(disk, 0); | ||
542 | if (!bdev) | ||
543 | goto exit; | ||
544 | |||
545 | bdev->bd_invalidated = 1; | ||
546 | err = blkdev_get(bdev, FMODE_READ, NULL); | ||
547 | if (err < 0) | ||
548 | goto exit; | ||
549 | blkdev_put(bdev, FMODE_READ); | ||
550 | |||
551 | exit: | ||
552 | /* announce disk after possible partitions are created */ | ||
553 | dev_set_uevent_suppress(ddev, 0); | ||
554 | kobject_uevent(&ddev->kobj, KOBJ_ADD); | ||
555 | |||
556 | /* announce possible partitions */ | ||
557 | disk_part_iter_init(&piter, disk, 0); | ||
558 | while ((part = disk_part_iter_next(&piter))) | ||
559 | kobject_uevent(&part_to_dev(part)->kobj, KOBJ_ADD); | ||
560 | disk_part_iter_exit(&piter); | ||
561 | } | ||
562 | |||
505 | /** | 563 | /** |
506 | * add_disk - add partitioning information to kernel list | 564 | * add_disk - add partitioning information to kernel list |
507 | * @disk: per-device partitioning information | 565 | * @disk: per-device partitioning information |
@@ -552,17 +610,43 @@ void add_disk(struct gendisk *disk) | |||
552 | "bdi"); | 610 | "bdi"); |
553 | WARN_ON(retval); | 611 | WARN_ON(retval); |
554 | } | 612 | } |
555 | |||
556 | EXPORT_SYMBOL(add_disk); | 613 | EXPORT_SYMBOL(add_disk); |
557 | EXPORT_SYMBOL(del_gendisk); /* in partitions/check.c */ | ||
558 | 614 | ||
559 | void unlink_gendisk(struct gendisk *disk) | 615 | void del_gendisk(struct gendisk *disk) |
560 | { | 616 | { |
617 | struct disk_part_iter piter; | ||
618 | struct hd_struct *part; | ||
619 | |||
620 | /* invalidate stuff */ | ||
621 | disk_part_iter_init(&piter, disk, | ||
622 | DISK_PITER_INCL_EMPTY | DISK_PITER_REVERSE); | ||
623 | while ((part = disk_part_iter_next(&piter))) { | ||
624 | invalidate_partition(disk, part->partno); | ||
625 | delete_partition(disk, part->partno); | ||
626 | } | ||
627 | disk_part_iter_exit(&piter); | ||
628 | |||
629 | invalidate_partition(disk, 0); | ||
630 | blk_free_devt(disk_to_dev(disk)->devt); | ||
631 | set_capacity(disk, 0); | ||
632 | disk->flags &= ~GENHD_FL_UP; | ||
633 | |||
561 | sysfs_remove_link(&disk_to_dev(disk)->kobj, "bdi"); | 634 | sysfs_remove_link(&disk_to_dev(disk)->kobj, "bdi"); |
562 | bdi_unregister(&disk->queue->backing_dev_info); | 635 | bdi_unregister(&disk->queue->backing_dev_info); |
563 | blk_unregister_queue(disk); | 636 | blk_unregister_queue(disk); |
564 | blk_unregister_region(disk_devt(disk), disk->minors); | 637 | blk_unregister_region(disk_devt(disk), disk->minors); |
638 | |||
639 | part_stat_set_all(&disk->part0, 0); | ||
640 | disk->part0.stamp = 0; | ||
641 | |||
642 | kobject_put(disk->part0.holder_dir); | ||
643 | kobject_put(disk->slave_dir); | ||
644 | disk->driverfs_dev = NULL; | ||
645 | if (!sysfs_deprecated) | ||
646 | sysfs_remove_link(block_depr, dev_name(disk_to_dev(disk))); | ||
647 | device_del(disk_to_dev(disk)); | ||
565 | } | 648 | } |
649 | EXPORT_SYMBOL(del_gendisk); | ||
566 | 650 | ||
567 | /** | 651 | /** |
568 | * get_gendisk - get partitioning information for a given device | 652 | * get_gendisk - get partitioning information for a given device |