Skip to content

Commit

Permalink
md: use new apis to suspend array for adding/removing rdev from state…
Browse files Browse the repository at this point in the history
…_store()

User can write 'remove' and 're-add' to trigger array reconfiguration
through sysfs, suspend array in this case so that io won't concurrent
with array reconfiguration.

And now that all the caller of add_bound_rdev() alread suspend the
array, remove mddev_suspend/resume() from add_bound_rdev() as well.

Signed-off-by: Yu Kuai <yukuai3@huawei.com>
Signed-off-by: Song Liu <song@kernel.org>
Link: https://lore.kernel.org/r/20231010151958.145896-12-yukuai1@huaweicloud.com
  • Loading branch information
Yu Kuai authored and Song Liu committed Oct 11, 2023
1 parent 205669f commit cfa078c
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions drivers/md/md.c
Original file line number Diff line number Diff line change
Expand Up @@ -2940,11 +2940,7 @@ static int add_bound_rdev(struct md_rdev *rdev)
*/
super_types[mddev->major_version].
validate_super(mddev, rdev);
if (add_journal)
mddev_suspend(mddev);
err = mddev->pers->hot_add_disk(mddev, rdev);
if (add_journal)
mddev_resume(mddev);
if (err) {
md_kick_rdev_from_array(rdev);
return err;
Expand Down Expand Up @@ -3697,24 +3693,31 @@ rdev_attr_store(struct kobject *kobj, struct attribute *attr,
struct rdev_sysfs_entry *entry = container_of(attr, struct rdev_sysfs_entry, attr);
struct md_rdev *rdev = container_of(kobj, struct md_rdev, kobj);
struct kernfs_node *kn = NULL;
bool suspend = false;
ssize_t rv;
struct mddev *mddev = rdev->mddev;

if (!entry->store)
return -EIO;
if (!capable(CAP_SYS_ADMIN))
return -EACCES;
if (!mddev)
return -ENODEV;

if (entry->store == state_store && cmd_match(page, "remove"))
kn = sysfs_break_active_protection(kobj, attr);
if (entry->store == state_store) {
if (cmd_match(page, "remove"))
kn = sysfs_break_active_protection(kobj, attr);
if (cmd_match(page, "remove") || cmd_match(page, "re-add"))
suspend = true;
}

rv = mddev ? mddev_lock(mddev) : -ENODEV;
rv = suspend ? mddev_suspend_and_lock(mddev) : mddev_lock(mddev);
if (!rv) {
if (rdev->mddev == NULL)
rv = -ENODEV;
else
rv = entry->store(rdev, page, length);
mddev_unlock(mddev);
suspend ? mddev_unlock_and_resume(mddev) : mddev_unlock(mddev);
}

if (kn)
Expand Down

0 comments on commit cfa078c

Please sign in to comment.