Commit 368c7f1f authored by Jens Axboe's avatar Jens Axboe

Merge branch 'md-next' of...

Merge branch 'md-next' of https://git.kernel.org/pub/scm/linux/kernel/git/song/md into for-6.2/block

Pull MD fixes from Song:

"This contains code cleanup by Christoph."

* 'md-next' of https://git.kernel.org/pub/scm/linux/kernel/git/song/md:
  md: fold unbind_rdev_from_array into md_kick_rdev_from_array
  md: mark md_kick_rdev_from_array static
  md: remove lock_bdev / unlock_bdev
parents f40eb998 b5c1acf0
...@@ -2468,7 +2468,22 @@ static void rdev_delayed_delete(struct work_struct *ws) ...@@ -2468,7 +2468,22 @@ static void rdev_delayed_delete(struct work_struct *ws)
kobject_put(&rdev->kobj); kobject_put(&rdev->kobj);
} }
static void unbind_rdev_from_array(struct md_rdev *rdev) void md_autodetect_dev(dev_t dev);
static void export_rdev(struct md_rdev *rdev)
{
pr_debug("md: export_rdev(%pg)\n", rdev->bdev);
md_rdev_clear(rdev);
#ifndef MODULE
if (test_bit(AutoDetected, &rdev->flags))
md_autodetect_dev(rdev->bdev->bd_dev);
#endif
blkdev_put(rdev->bdev, FMODE_READ | FMODE_WRITE | FMODE_EXCL);
rdev->bdev = NULL;
kobject_put(&rdev->kobj);
}
static void md_kick_rdev_from_array(struct md_rdev *rdev)
{ {
bd_unlink_disk_holder(rdev->bdev, rdev->mddev->gendisk); bd_unlink_disk_holder(rdev->bdev, rdev->mddev->gendisk);
list_del_rcu(&rdev->same_set); list_del_rcu(&rdev->same_set);
...@@ -2491,56 +2506,8 @@ static void unbind_rdev_from_array(struct md_rdev *rdev) ...@@ -2491,56 +2506,8 @@ static void unbind_rdev_from_array(struct md_rdev *rdev)
INIT_WORK(&rdev->del_work, rdev_delayed_delete); INIT_WORK(&rdev->del_work, rdev_delayed_delete);
kobject_get(&rdev->kobj); kobject_get(&rdev->kobj);
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);
static void export_rdev(struct md_rdev *rdev)
{
pr_debug("md: export_rdev(%pg)\n", rdev->bdev);
md_rdev_clear(rdev);
#ifndef MODULE
if (test_bit(AutoDetected, &rdev->flags))
md_autodetect_dev(rdev->bdev->bd_dev);
#endif
unlock_rdev(rdev);
kobject_put(&rdev->kobj);
}
void md_kick_rdev_from_array(struct md_rdev *rdev)
{
unbind_rdev_from_array(rdev);
export_rdev(rdev); export_rdev(rdev);
} }
EXPORT_SYMBOL_GPL(md_kick_rdev_from_array);
static void export_array(struct mddev *mddev) static void export_array(struct mddev *mddev)
{ {
...@@ -3675,9 +3642,10 @@ EXPORT_SYMBOL_GPL(md_rdev_init); ...@@ -3675,9 +3642,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 +3653,20 @@ static struct md_rdev *md_import_device(dev_t newdev, int super_format, int supe ...@@ -3685,14 +3653,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 +3675,7 @@ static struct md_rdev *md_import_device(dev_t newdev, int super_format, int supe ...@@ -3701,7 +3675,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 +3685,22 @@ static struct md_rdev *md_import_device(dev_t newdev, int super_format, int supe ...@@ -3711,21 +3685,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);
} }
......
...@@ -782,7 +782,6 @@ extern void mddev_resume(struct mddev *mddev); ...@@ -782,7 +782,6 @@ extern void mddev_resume(struct mddev *mddev);
extern void md_reload_sb(struct mddev *mddev, int raid_disk); extern void md_reload_sb(struct mddev *mddev, int raid_disk);
extern void md_update_sb(struct mddev *mddev, int force); extern void md_update_sb(struct mddev *mddev, int force);
extern void md_kick_rdev_from_array(struct md_rdev * rdev);
extern void mddev_create_serial_pool(struct mddev *mddev, struct md_rdev *rdev, extern void mddev_create_serial_pool(struct mddev *mddev, struct md_rdev *rdev,
bool is_suspend); bool is_suspend);
extern void mddev_destroy_serial_pool(struct mddev *mddev, struct md_rdev *rdev, extern void mddev_destroy_serial_pool(struct mddev *mddev, struct md_rdev *rdev,
......
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