Commit 0762b8bd authored by Tejun Heo's avatar Tejun Heo Committed by Jens Axboe

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: default avatarTejun Heo <tj@kernel.org>
Signed-off-by: default avatarJens Axboe <jens.axboe@oracle.com>
parent 4c46501d
...@@ -1274,7 +1274,7 @@ __setup("fail_make_request=", setup_fail_make_request); ...@@ -1274,7 +1274,7 @@ __setup("fail_make_request=", setup_fail_make_request);
static int should_fail_request(struct bio *bio) static int should_fail_request(struct bio *bio)
{ {
if ((bio->bi_bdev->bd_disk->flags & GENHD_FL_FAIL) || if ((bio->bi_bdev->bd_disk->flags & GENHD_FL_FAIL) ||
(bio->bi_bdev->bd_part && bio->bi_bdev->bd_part->make_it_fail)) bio->bi_bdev->bd_part->make_it_fail)
return should_fail(&fail_make_request, bio->bi_size); return should_fail(&fail_make_request, bio->bi_size);
return 0; return 0;
......
...@@ -1464,10 +1464,7 @@ static int bind_rdev_to_array(mdk_rdev_t * rdev, mddev_t * mddev) ...@@ -1464,10 +1464,7 @@ static int bind_rdev_to_array(mdk_rdev_t * rdev, mddev_t * mddev)
if ((err = kobject_add(&rdev->kobj, &mddev->kobj, "dev-%s", b))) if ((err = kobject_add(&rdev->kobj, &mddev->kobj, "dev-%s", b)))
goto fail; goto fail;
if (rdev->bdev->bd_part)
ko = &part_to_dev(rdev->bdev->bd_part)->kobj; ko = &part_to_dev(rdev->bdev->bd_part)->kobj;
else
ko = &disk_to_dev(rdev->bdev->bd_disk)->kobj;
if ((err = sysfs_create_link(&rdev->kobj, ko, "block"))) { if ((err = sysfs_create_link(&rdev->kobj, ko, "block"))) {
kobject_del(&rdev->kobj); kobject_del(&rdev->kobj);
goto fail; goto fail;
......
...@@ -540,14 +540,6 @@ EXPORT_SYMBOL(bd_release); ...@@ -540,14 +540,6 @@ EXPORT_SYMBOL(bd_release);
* /sys/block/sda/holders/dm-0 --> /sys/block/dm-0 * /sys/block/sda/holders/dm-0 --> /sys/block/dm-0
*/ */
static struct kobject *bdev_get_kobj(struct block_device *bdev)
{
if (bdev->bd_contains != bdev)
return kobject_get(&part_to_dev(bdev->bd_part)->kobj);
else
return kobject_get(&disk_to_dev(bdev->bd_disk)->kobj);
}
static int add_symlink(struct kobject *from, struct kobject *to) static int add_symlink(struct kobject *from, struct kobject *to)
{ {
if (!from || !to) if (!from || !to)
...@@ -596,7 +588,7 @@ static int bd_holder_grab_dirs(struct block_device *bdev, ...@@ -596,7 +588,7 @@ static int bd_holder_grab_dirs(struct block_device *bdev,
if (!bo->hdev) if (!bo->hdev)
goto fail_put_sdir; goto fail_put_sdir;
bo->sdev = bdev_get_kobj(bdev); bo->sdev = kobject_get(&part_to_dev(bdev->bd_part)->kobj);
if (!bo->sdev) if (!bo->sdev)
goto fail_put_hdev; goto fail_put_hdev;
...@@ -919,7 +911,6 @@ static int __blkdev_put(struct block_device *bdev, int for_part); ...@@ -919,7 +911,6 @@ static int __blkdev_put(struct block_device *bdev, int for_part);
static int do_open(struct block_device *bdev, struct file *file, int for_part) static int do_open(struct block_device *bdev, struct file *file, int for_part)
{ {
struct module *owner = NULL;
struct gendisk *disk; struct gendisk *disk;
struct hd_struct *part = NULL; struct hd_struct *part = NULL;
int ret; int ret;
...@@ -941,25 +932,27 @@ static int do_open(struct block_device *bdev, struct file *file, int for_part) ...@@ -941,25 +932,27 @@ static int do_open(struct block_device *bdev, struct file *file, int for_part)
ret = -ENXIO; ret = -ENXIO;
file->f_mapping = bdev->bd_inode->i_mapping; file->f_mapping = bdev->bd_inode->i_mapping;
lock_kernel(); lock_kernel();
disk = get_gendisk(bdev->bd_dev, &partno); disk = get_gendisk(bdev->bd_dev, &partno);
if (!disk) { if (!disk)
unlock_kernel(); goto out_unlock_kernel;
bdput(bdev); part = disk_get_part(disk, partno);
return ret; if (!part)
} goto out_unlock_kernel;
owner = disk->fops->owner;
mutex_lock_nested(&bdev->bd_mutex, for_part); mutex_lock_nested(&bdev->bd_mutex, for_part);
if (!bdev->bd_openers) { if (!bdev->bd_openers) {
bdev->bd_disk = disk; bdev->bd_disk = disk;
bdev->bd_part = part;
bdev->bd_contains = bdev; bdev->bd_contains = bdev;
if (!partno) { if (!partno) {
struct backing_dev_info *bdi; struct backing_dev_info *bdi;
if (disk->fops->open) { if (disk->fops->open) {
ret = disk->fops->open(bdev->bd_inode, file); ret = disk->fops->open(bdev->bd_inode, file);
if (ret) if (ret)
goto out_first; goto out_clear;
} }
if (!bdev->bd_openers) { if (!bdev->bd_openers) {
bd_set_size(bdev,(loff_t)get_capacity(disk)<<9); 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,31 +968,32 @@ static int do_open(struct block_device *bdev, struct file *file, int for_part)
whole = bdget_disk(disk, 0); whole = bdget_disk(disk, 0);
ret = -ENOMEM; ret = -ENOMEM;
if (!whole) if (!whole)
goto out_first; goto out_clear;
BUG_ON(for_part); BUG_ON(for_part);
ret = __blkdev_get(whole, file->f_mode, file->f_flags, 1); ret = __blkdev_get(whole, file->f_mode, file->f_flags, 1);
if (ret) if (ret)
goto out_first; goto out_clear;
bdev->bd_contains = whole; bdev->bd_contains = whole;
part = disk_get_part(disk, partno);
bdev->bd_inode->i_data.backing_dev_info = bdev->bd_inode->i_data.backing_dev_info =
whole->bd_inode->i_data.backing_dev_info; whole->bd_inode->i_data.backing_dev_info;
if (!(disk->flags & GENHD_FL_UP) || if (!(disk->flags & GENHD_FL_UP) ||
!part || !part->nr_sects) { !part || !part->nr_sects) {
ret = -ENXIO; ret = -ENXIO;
goto out_first; goto out_clear;
} }
bdev->bd_part = part;
bd_set_size(bdev, (loff_t)part->nr_sects << 9); bd_set_size(bdev, (loff_t)part->nr_sects << 9);
} }
} else { } else {
disk_put_part(part);
put_disk(disk); put_disk(disk);
module_put(owner); module_put(disk->fops->owner);
part = NULL;
disk = NULL;
if (bdev->bd_contains == bdev) { if (bdev->bd_contains == bdev) {
if (bdev->bd_disk->fops->open) { if (bdev->bd_disk->fops->open) {
ret = bdev->bd_disk->fops->open(bdev->bd_inode, file); ret = bdev->bd_disk->fops->open(bdev->bd_inode, file);
if (ret) if (ret)
goto out; goto out_unlock_bdev;
} }
if (bdev->bd_invalidated) if (bdev->bd_invalidated)
rescan_partitions(bdev->bd_disk, bdev); 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,20 +1006,24 @@ static int do_open(struct block_device *bdev, struct file *file, int for_part)
unlock_kernel(); unlock_kernel();
return 0; return 0;
out_first: out_clear:
bdev->bd_disk = NULL; bdev->bd_disk = NULL;
bdev->bd_part = NULL;
bdev->bd_inode->i_data.backing_dev_info = &default_backing_dev_info; bdev->bd_inode->i_data.backing_dev_info = &default_backing_dev_info;
if (bdev != bdev->bd_contains) if (bdev != bdev->bd_contains)
__blkdev_put(bdev->bd_contains, 1); __blkdev_put(bdev->bd_contains, 1);
bdev->bd_contains = NULL; bdev->bd_contains = NULL;
put_disk(disk); out_unlock_bdev:
disk_put_part(part);
module_put(owner);
out:
mutex_unlock(&bdev->bd_mutex); mutex_unlock(&bdev->bd_mutex);
out_unlock_kernel:
unlock_kernel(); unlock_kernel();
if (ret)
disk_put_part(part);
if (disk)
module_put(disk->fops->owner);
put_disk(disk);
bdput(bdev); bdput(bdev);
return ret; return ret;
} }
...@@ -1110,11 +1108,8 @@ static int __blkdev_put(struct block_device *bdev, int for_part) ...@@ -1110,11 +1108,8 @@ static int __blkdev_put(struct block_device *bdev, int for_part)
put_disk(disk); put_disk(disk);
module_put(owner); module_put(owner);
if (bdev->bd_contains != bdev) {
disk_put_part(bdev->bd_part); disk_put_part(bdev->bd_part);
bdev->bd_part = NULL; bdev->bd_part = NULL;
}
bdev->bd_disk = NULL; bdev->bd_disk = NULL;
bdev->bd_inode->i_data.backing_dev_info = &default_backing_dev_info; bdev->bd_inode->i_data.backing_dev_info = &default_backing_dev_info;
if (bdev != bdev->bd_contains) if (bdev != bdev->bd_contains)
......
...@@ -134,12 +134,7 @@ char *disk_name(struct gendisk *hd, int partno, char *buf) ...@@ -134,12 +134,7 @@ char *disk_name(struct gendisk *hd, int partno, char *buf)
const char *bdevname(struct block_device *bdev, char *buf) const char *bdevname(struct block_device *bdev, char *buf)
{ {
int partno = 0; return disk_name(bdev->bd_disk, bdev->bd_part->partno, buf);
if (bdev->bd_part)
partno = bdev->bd_part->partno;
return disk_name(bdev->bd_disk, partno, buf);
} }
EXPORT_SYMBOL(bdevname); EXPORT_SYMBOL(bdevname);
......
...@@ -412,7 +412,7 @@ extern void rand_initialize_disk(struct gendisk *disk); ...@@ -412,7 +412,7 @@ extern void rand_initialize_disk(struct gendisk *disk);
static inline sector_t get_start_sect(struct block_device *bdev) static inline sector_t get_start_sect(struct block_device *bdev)
{ {
return bdev->bd_contains == bdev ? 0 : bdev->bd_part->start_sect; return bdev->bd_part->start_sect;
} }
static inline sector_t get_capacity(struct gendisk *disk) static inline sector_t get_capacity(struct gendisk *disk)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment