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: Christoph Hellwig <hch@lst.de> Signed-off-by: Song Liu <song@kernel.org>
This commit is contained in:
parent
1d6df9d352
commit
fb541ca4c3
@ -2493,34 +2493,6 @@ static void unbind_rdev_from_array(struct md_rdev *rdev)
|
||||
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);
|
||||
|
||||
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))
|
||||
md_autodetect_dev(rdev->bdev->bd_dev);
|
||||
#endif
|
||||
unlock_rdev(rdev);
|
||||
blkdev_put(rdev->bdev, FMODE_READ | FMODE_WRITE | FMODE_EXCL);
|
||||
rdev->bdev = NULL;
|
||||
kobject_put(&rdev->kobj);
|
||||
}
|
||||
|
||||
@ -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)
|
||||
{
|
||||
int err;
|
||||
static struct md_rdev *claim_rdev; /* just for claiming the bdev */
|
||||
struct md_rdev *rdev;
|
||||
sector_t size;
|
||||
int err;
|
||||
|
||||
rdev = kzalloc(sizeof(*rdev), GFP_KERNEL);
|
||||
if (!rdev)
|
||||
@ -3685,14 +3659,20 @@ static struct md_rdev *md_import_device(dev_t newdev, int super_format, int supe
|
||||
|
||||
err = md_rdev_init(rdev);
|
||||
if (err)
|
||||
goto abort_free;
|
||||
goto out_free_rdev;
|
||||
err = alloc_disk_sb(rdev);
|
||||
if (err)
|
||||
goto abort_free;
|
||||
goto out_clear_rdev;
|
||||
|
||||
err = lock_rdev(rdev, newdev, super_format == -2);
|
||||
if (err)
|
||||
goto abort_free;
|
||||
rdev->bdev = blkdev_get_by_dev(newdev,
|
||||
FMODE_READ | FMODE_WRITE | FMODE_EXCL,
|
||||
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);
|
||||
|
||||
@ -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",
|
||||
rdev->bdev);
|
||||
err = -EINVAL;
|
||||
goto abort_free;
|
||||
goto out_blkdev_put;
|
||||
}
|
||||
|
||||
if (super_format >= 0) {
|
||||
@ -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",
|
||||
rdev->bdev,
|
||||
super_format, super_minor);
|
||||
goto abort_free;
|
||||
goto out_blkdev_put;
|
||||
}
|
||||
if (err < 0) {
|
||||
pr_warn("md: could not read %pg's sb, not importing!\n",
|
||||
rdev->bdev);
|
||||
goto abort_free;
|
||||
goto out_blkdev_put;
|
||||
}
|
||||
}
|
||||
|
||||
return rdev;
|
||||
|
||||
abort_free:
|
||||
if (rdev->bdev)
|
||||
unlock_rdev(rdev);
|
||||
out_blkdev_put:
|
||||
blkdev_put(rdev->bdev, FMODE_READ | FMODE_WRITE | FMODE_EXCL);
|
||||
out_clear_rdev:
|
||||
md_rdev_clear(rdev);
|
||||
out_free_rdev:
|
||||
kfree(rdev);
|
||||
return ERR_PTR(err);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user