Commit fb541ca4 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Song Liu

md: remove lock_bdev / unlock_bdev

These wrappers for blkdev_get / blkdev_put just horribly confuse the
code with their odd naming.  Remove them and improve the error unwinding
in md_import_device with the now folded code.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarSong Liu <song@kernel.org>
parent 1d6df9d3
...@@ -2493,34 +2493,6 @@ static void unbind_rdev_from_array(struct md_rdev *rdev) ...@@ -2493,34 +2493,6 @@ static void unbind_rdev_from_array(struct md_rdev *rdev)
queue_work(md_rdev_misc_wq, &rdev->del_work); queue_work(md_rdev_misc_wq, &rdev->del_work);
} }
/*
* prevent the device from being mounted, repartitioned or
* otherwise reused by a RAID array (or any other kernel
* subsystem), by bd_claiming the device.
*/
static int lock_rdev(struct md_rdev *rdev, dev_t dev, int shared)
{
int err = 0;
struct block_device *bdev;
bdev = blkdev_get_by_dev(dev, FMODE_READ|FMODE_WRITE|FMODE_EXCL,
shared ? (struct md_rdev *)lock_rdev : rdev);
if (IS_ERR(bdev)) {
pr_warn("md: could not open device unknown-block(%u,%u).\n",
MAJOR(dev), MINOR(dev));
return PTR_ERR(bdev);
}
rdev->bdev = bdev;
return err;
}
static void unlock_rdev(struct md_rdev *rdev)
{
struct block_device *bdev = rdev->bdev;
rdev->bdev = NULL;
blkdev_put(bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL);
}
void md_autodetect_dev(dev_t dev); void md_autodetect_dev(dev_t dev);
static void export_rdev(struct md_rdev *rdev) static void export_rdev(struct md_rdev *rdev)
...@@ -2531,7 +2503,8 @@ static void export_rdev(struct md_rdev *rdev) ...@@ -2531,7 +2503,8 @@ static void export_rdev(struct md_rdev *rdev)
if (test_bit(AutoDetected, &rdev->flags)) if (test_bit(AutoDetected, &rdev->flags))
md_autodetect_dev(rdev->bdev->bd_dev); md_autodetect_dev(rdev->bdev->bd_dev);
#endif #endif
unlock_rdev(rdev); blkdev_put(rdev->bdev, FMODE_READ | FMODE_WRITE | FMODE_EXCL);
rdev->bdev = NULL;
kobject_put(&rdev->kobj); kobject_put(&rdev->kobj);
} }
...@@ -3675,9 +3648,10 @@ EXPORT_SYMBOL_GPL(md_rdev_init); ...@@ -3675,9 +3648,10 @@ EXPORT_SYMBOL_GPL(md_rdev_init);
*/ */
static struct md_rdev *md_import_device(dev_t newdev, int super_format, int super_minor) static struct md_rdev *md_import_device(dev_t newdev, int super_format, int super_minor)
{ {
int err; static struct md_rdev *claim_rdev; /* just for claiming the bdev */
struct md_rdev *rdev; struct md_rdev *rdev;
sector_t size; sector_t size;
int err;
rdev = kzalloc(sizeof(*rdev), GFP_KERNEL); rdev = kzalloc(sizeof(*rdev), GFP_KERNEL);
if (!rdev) if (!rdev)
...@@ -3685,14 +3659,20 @@ static struct md_rdev *md_import_device(dev_t newdev, int super_format, int supe ...@@ -3685,14 +3659,20 @@ static struct md_rdev *md_import_device(dev_t newdev, int super_format, int supe
err = md_rdev_init(rdev); err = md_rdev_init(rdev);
if (err) if (err)
goto abort_free; goto out_free_rdev;
err = alloc_disk_sb(rdev); err = alloc_disk_sb(rdev);
if (err) if (err)
goto abort_free; goto out_clear_rdev;
err = lock_rdev(rdev, newdev, super_format == -2); rdev->bdev = blkdev_get_by_dev(newdev,
if (err) FMODE_READ | FMODE_WRITE | FMODE_EXCL,
goto abort_free; super_format == -2 ? claim_rdev : rdev);
if (IS_ERR(rdev->bdev)) {
pr_warn("md: could not open device unknown-block(%u,%u).\n",
MAJOR(newdev), MINOR(newdev));
err = PTR_ERR(rdev->bdev);
goto out_clear_rdev;
}
kobject_init(&rdev->kobj, &rdev_ktype); kobject_init(&rdev->kobj, &rdev_ktype);
...@@ -3701,7 +3681,7 @@ static struct md_rdev *md_import_device(dev_t newdev, int super_format, int supe ...@@ -3701,7 +3681,7 @@ static struct md_rdev *md_import_device(dev_t newdev, int super_format, int supe
pr_warn("md: %pg has zero or unknown size, marking faulty!\n", pr_warn("md: %pg has zero or unknown size, marking faulty!\n",
rdev->bdev); rdev->bdev);
err = -EINVAL; err = -EINVAL;
goto abort_free; goto out_blkdev_put;
} }
if (super_format >= 0) { if (super_format >= 0) {
...@@ -3711,21 +3691,22 @@ static struct md_rdev *md_import_device(dev_t newdev, int super_format, int supe ...@@ -3711,21 +3691,22 @@ static struct md_rdev *md_import_device(dev_t newdev, int super_format, int supe
pr_warn("md: %pg does not have a valid v%d.%d superblock, not importing!\n", pr_warn("md: %pg does not have a valid v%d.%d superblock, not importing!\n",
rdev->bdev, rdev->bdev,
super_format, super_minor); super_format, super_minor);
goto abort_free; goto out_blkdev_put;
} }
if (err < 0) { if (err < 0) {
pr_warn("md: could not read %pg's sb, not importing!\n", pr_warn("md: could not read %pg's sb, not importing!\n",
rdev->bdev); rdev->bdev);
goto abort_free; goto out_blkdev_put;
} }
} }
return rdev; return rdev;
abort_free: out_blkdev_put:
if (rdev->bdev) blkdev_put(rdev->bdev, FMODE_READ | FMODE_WRITE | FMODE_EXCL);
unlock_rdev(rdev); out_clear_rdev:
md_rdev_clear(rdev); md_rdev_clear(rdev);
out_free_rdev:
kfree(rdev); kfree(rdev);
return ERR_PTR(err); return ERR_PTR(err);
} }
......
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