aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2008-08-25 06:56:12 -0400
committerJens Axboe <jens.axboe@oracle.com>2008-10-09 02:56:08 -0400
commit0762b8bde9729f10f8e6249809660ff2ec3ad735 (patch)
tree12aa94ef16b840f713f833c712d335646c816dc1
parent4c46501d1659475dc6c89554af6ce7fe6ecf615c (diff)
block: always set bdev->bd_part
Till now, bdev->bd_part is set only if the bdev was for parts other than part0. This patch makes bdev->bd_part always set so that code paths don't have to differenciate common handling. Signed-off-by: Tejun Heo <tj@kernel.org> Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
-rw-r--r--block/blk-core.c2
-rw-r--r--drivers/md/md.c5
-rw-r--r--fs/block_dev.c67
-rw-r--r--fs/partitions/check.c7
-rw-r--r--include/linux/genhd.h2
5 files changed, 35 insertions, 48 deletions
diff --git a/block/blk-core.c b/block/blk-core.c
index e0a5ee36849c..a4a7c08d2f20 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -1274,7 +1274,7 @@ __setup("fail_make_request=", setup_fail_make_request);
1274static int should_fail_request(struct bio *bio) 1274static int should_fail_request(struct bio *bio)
1275{ 1275{
1276 if ((bio->bi_bdev->bd_disk->flags & GENHD_FL_FAIL) || 1276 if ((bio->bi_bdev->bd_disk->flags & GENHD_FL_FAIL) ||
1277 (bio->bi_bdev->bd_part && bio->bi_bdev->bd_part->make_it_fail)) 1277 bio->bi_bdev->bd_part->make_it_fail)
1278 return should_fail(&fail_make_request, bio->bi_size); 1278 return should_fail(&fail_make_request, bio->bi_size);
1279 1279
1280 return 0; 1280 return 0;
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 96e9fccd2eab..2bd9cf416123 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -1464,10 +1464,7 @@ static int bind_rdev_to_array(mdk_rdev_t * rdev, mddev_t * mddev)
1464 if ((err = kobject_add(&rdev->kobj, &mddev->kobj, "dev-%s", b))) 1464 if ((err = kobject_add(&rdev->kobj, &mddev->kobj, "dev-%s", b)))
1465 goto fail; 1465 goto fail;
1466 1466
1467 if (rdev->bdev->bd_part) 1467 ko = &part_to_dev(rdev->bdev->bd_part)->kobj;
1468 ko = &part_to_dev(rdev->bdev->bd_part)->kobj;
1469 else
1470 ko = &disk_to_dev(rdev->bdev->bd_disk)->kobj;
1471 if ((err = sysfs_create_link(&rdev->kobj, ko, "block"))) { 1468 if ((err = sysfs_create_link(&rdev->kobj, ko, "block"))) {
1472 kobject_del(&rdev->kobj); 1469 kobject_del(&rdev->kobj);
1473 goto fail; 1470 goto fail;
diff --git a/fs/block_dev.c b/fs/block_dev.c
index 57d572642854..c3fa19bd64df 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -540,14 +540,6 @@ EXPORT_SYMBOL(bd_release);
540 * /sys/block/sda/holders/dm-0 --> /sys/block/dm-0 540 * /sys/block/sda/holders/dm-0 --> /sys/block/dm-0
541 */ 541 */
542 542
543static struct kobject *bdev_get_kobj(struct block_device *bdev)
544{
545 if (bdev->bd_contains != bdev)
546 return kobject_get(&part_to_dev(bdev->bd_part)->kobj);
547 else
548 return kobject_get(&disk_to_dev(bdev->bd_disk)->kobj);
549}
550
551static int add_symlink(struct kobject *from, struct kobject *to) 543static int add_symlink(struct kobject *from, struct kobject *to)
552{ 544{
553 if (!from || !to) 545 if (!from || !to)
@@ -596,7 +588,7 @@ static int bd_holder_grab_dirs(struct block_device *bdev,
596 if (!bo->hdev) 588 if (!bo->hdev)
597 goto fail_put_sdir; 589 goto fail_put_sdir;
598 590
599 bo->sdev = bdev_get_kobj(bdev); 591 bo->sdev = kobject_get(&part_to_dev(bdev->bd_part)->kobj);
600 if (!bo->sdev) 592 if (!bo->sdev)
601 goto fail_put_hdev; 593 goto fail_put_hdev;
602 594
@@ -919,7 +911,6 @@ static int __blkdev_put(struct block_device *bdev, int for_part);
919 911
920static int do_open(struct block_device *bdev, struct file *file, int for_part) 912static int do_open(struct block_device *bdev, struct file *file, int for_part)
921{ 913{
922 struct module *owner = NULL;
923 struct gendisk *disk; 914 struct gendisk *disk;
924 struct hd_struct *part = NULL; 915 struct hd_struct *part = NULL;
925 int ret; 916 int ret;
@@ -941,25 +932,27 @@ static int do_open(struct block_device *bdev, struct file *file, int for_part)
941 932
942 ret = -ENXIO; 933 ret = -ENXIO;
943 file->f_mapping = bdev->bd_inode->i_mapping; 934 file->f_mapping = bdev->bd_inode->i_mapping;
935
944 lock_kernel(); 936 lock_kernel();
937
945 disk = get_gendisk(bdev->bd_dev, &partno); 938 disk = get_gendisk(bdev->bd_dev, &partno);
946 if (!disk) { 939 if (!disk)
947 unlock_kernel(); 940 goto out_unlock_kernel;
948 bdput(bdev); 941 part = disk_get_part(disk, partno);
949 return ret; 942 if (!part)
950 } 943 goto out_unlock_kernel;
951 owner = disk->fops->owner;
952 944
953 mutex_lock_nested(&bdev->bd_mutex, for_part); 945 mutex_lock_nested(&bdev->bd_mutex, for_part);
954 if (!bdev->bd_openers) { 946 if (!bdev->bd_openers) {
955 bdev->bd_disk = disk; 947 bdev->bd_disk = disk;
948 bdev->bd_part = part;
956 bdev->bd_contains = bdev; 949 bdev->bd_contains = bdev;
957 if (!partno) { 950 if (!partno) {
958 struct backing_dev_info *bdi; 951 struct backing_dev_info *bdi;
959 if (disk->fops->open) { 952 if (disk->fops->open) {
960 ret = disk->fops->open(bdev->bd_inode, file); 953 ret = disk->fops->open(bdev->bd_inode, file);
961 if (ret) 954 if (ret)
962 goto out_first; 955 goto out_clear;
963 } 956 }
964 if (!bdev->bd_openers) { 957 if (!bdev->bd_openers) {
965 bd_set_size(bdev,(loff_t)get_capacity(disk)<<9); 958 bd_set_size(bdev,(loff_t)get_capacity(disk)<<9);
@@ -975,31 +968,32 @@ static int do_open(struct block_device *bdev, struct file *file, int for_part)
975 whole = bdget_disk(disk, 0); 968 whole = bdget_disk(disk, 0);
976 ret = -ENOMEM; 969 ret = -ENOMEM;
977 if (!whole) 970 if (!whole)
978 goto out_first; 971 goto out_clear;
979 BUG_ON(for_part); 972 BUG_ON(for_part);
980 ret = __blkdev_get(whole, file->f_mode, file->f_flags, 1); 973 ret = __blkdev_get(whole, file->f_mode, file->f_flags, 1);
981 if (ret) 974 if (ret)
982 goto out_first; 975 goto out_clear;
983 bdev->bd_contains = whole; 976 bdev->bd_contains = whole;
984 part = disk_get_part(disk, partno);
985 bdev->bd_inode->i_data.backing_dev_info = 977 bdev->bd_inode->i_data.backing_dev_info =
986 whole->bd_inode->i_data.backing_dev_info; 978 whole->bd_inode->i_data.backing_dev_info;
987 if (!(disk->flags & GENHD_FL_UP) || 979 if (!(disk->flags & GENHD_FL_UP) ||
988 !part || !part->nr_sects) { 980 !part || !part->nr_sects) {
989 ret = -ENXIO; 981 ret = -ENXIO;
990 goto out_first; 982 goto out_clear;
991 } 983 }
992 bdev->bd_part = part;
993 bd_set_size(bdev, (loff_t)part->nr_sects << 9); 984 bd_set_size(bdev, (loff_t)part->nr_sects << 9);
994 } 985 }
995 } else { 986 } else {
987 disk_put_part(part);
996 put_disk(disk); 988 put_disk(disk);
997 module_put(owner); 989 module_put(disk->fops->owner);
990 part = NULL;
991 disk = NULL;
998 if (bdev->bd_contains == bdev) { 992 if (bdev->bd_contains == bdev) {
999 if (bdev->bd_disk->fops->open) { 993 if (bdev->bd_disk->fops->open) {
1000 ret = bdev->bd_disk->fops->open(bdev->bd_inode, file); 994 ret = bdev->bd_disk->fops->open(bdev->bd_inode, file);
1001 if (ret) 995 if (ret)
1002 goto out; 996 goto out_unlock_bdev;
1003 } 997 }
1004 if (bdev->bd_invalidated) 998 if (bdev->bd_invalidated)
1005 rescan_partitions(bdev->bd_disk, bdev); 999 rescan_partitions(bdev->bd_disk, bdev);
@@ -1012,20 +1006,24 @@ static int do_open(struct block_device *bdev, struct file *file, int for_part)
1012 unlock_kernel(); 1006 unlock_kernel();
1013 return 0; 1007 return 0;
1014 1008
1015out_first: 1009 out_clear:
1016 bdev->bd_disk = NULL; 1010 bdev->bd_disk = NULL;
1011 bdev->bd_part = NULL;
1017 bdev->bd_inode->i_data.backing_dev_info = &default_backing_dev_info; 1012 bdev->bd_inode->i_data.backing_dev_info = &default_backing_dev_info;
1018 if (bdev != bdev->bd_contains) 1013 if (bdev != bdev->bd_contains)
1019 __blkdev_put(bdev->bd_contains, 1); 1014 __blkdev_put(bdev->bd_contains, 1);
1020 bdev->bd_contains = NULL; 1015 bdev->bd_contains = NULL;
1021 put_disk(disk); 1016 out_unlock_bdev:
1022 disk_put_part(part);
1023 module_put(owner);
1024out:
1025 mutex_unlock(&bdev->bd_mutex); 1017 mutex_unlock(&bdev->bd_mutex);
1018 out_unlock_kernel:
1026 unlock_kernel(); 1019 unlock_kernel();
1027 if (ret) 1020
1028 bdput(bdev); 1021 disk_put_part(part);
1022 if (disk)
1023 module_put(disk->fops->owner);
1024 put_disk(disk);
1025 bdput(bdev);
1026
1029 return ret; 1027 return ret;
1030} 1028}
1031 1029
@@ -1110,11 +1108,8 @@ static int __blkdev_put(struct block_device *bdev, int for_part)
1110 1108
1111 put_disk(disk); 1109 put_disk(disk);
1112 module_put(owner); 1110 module_put(owner);
1113 1111 disk_put_part(bdev->bd_part);
1114 if (bdev->bd_contains != bdev) { 1112 bdev->bd_part = NULL;
1115 disk_put_part(bdev->bd_part);
1116 bdev->bd_part = NULL;
1117 }
1118 bdev->bd_disk = NULL; 1113 bdev->bd_disk = NULL;
1119 bdev->bd_inode->i_data.backing_dev_info = &default_backing_dev_info; 1114 bdev->bd_inode->i_data.backing_dev_info = &default_backing_dev_info;
1120 if (bdev != bdev->bd_contains) 1115 if (bdev != bdev->bd_contains)
diff --git a/fs/partitions/check.c b/fs/partitions/check.c
index f0f604950ff4..87298c0fc8ce 100644
--- a/fs/partitions/check.c
+++ b/fs/partitions/check.c
@@ -134,12 +134,7 @@ char *disk_name(struct gendisk *hd, int partno, char *buf)
134 134
135const char *bdevname(struct block_device *bdev, char *buf) 135const char *bdevname(struct block_device *bdev, char *buf)
136{ 136{
137 int partno = 0; 137 return disk_name(bdev->bd_disk, bdev->bd_part->partno, buf);
138
139 if (bdev->bd_part)
140 partno = bdev->bd_part->partno;
141
142 return disk_name(bdev->bd_disk, partno, buf);
143} 138}
144 139
145EXPORT_SYMBOL(bdevname); 140EXPORT_SYMBOL(bdevname);
diff --git a/include/linux/genhd.h b/include/linux/genhd.h
index 2c0e1b597ab4..45a3682b5d87 100644
--- a/include/linux/genhd.h
+++ b/include/linux/genhd.h
@@ -412,7 +412,7 @@ extern void rand_initialize_disk(struct gendisk *disk);
412 412
413static inline sector_t get_start_sect(struct block_device *bdev) 413static inline sector_t get_start_sect(struct block_device *bdev)
414{ 414{
415 return bdev->bd_contains == bdev ? 0 : bdev->bd_part->start_sect; 415 return bdev->bd_part->start_sect;
416} 416}
417static inline sector_t get_capacity(struct gendisk *disk) 417static inline sector_t get_capacity(struct gendisk *disk)
418{ 418{