Commit 58226942 authored by Yu Kuai's avatar Yu Kuai Committed by Song Liu

md: use new apis to suspend array before mddev_create/destroy_serial_pool

mddev_create/destroy_serial_pool() will be called from several places
where mddev_suspend() will be called later.

Prepare to remove the mddev_suspend() from
mddev_create/destroy_serial_pool().
Signed-off-by: default avatarYu Kuai <yukuai3@huawei.com>
Signed-off-by: default avatarSong Liu <song@kernel.org>
Link: https://lore.kernel.org/r/20231010151958.145896-14-yukuai1@huaweicloud.com
parent 1b0a2d95
...@@ -175,7 +175,7 @@ static void __init md_setup_drive(struct md_setup_args *args) ...@@ -175,7 +175,7 @@ static void __init md_setup_drive(struct md_setup_args *args)
return; return;
} }
err = mddev_lock(mddev); err = mddev_suspend_and_lock(mddev);
if (err) { if (err) {
pr_err("md: failed to lock array %s\n", name); pr_err("md: failed to lock array %s\n", name);
goto out_mddev_put; goto out_mddev_put;
...@@ -221,7 +221,7 @@ static void __init md_setup_drive(struct md_setup_args *args) ...@@ -221,7 +221,7 @@ static void __init md_setup_drive(struct md_setup_args *args)
if (err) if (err)
pr_warn("md: starting %s failed\n", name); pr_warn("md: starting %s failed\n", name);
out_unlock: out_unlock:
mddev_unlock(mddev); mddev_unlock_and_resume(mddev);
out_mddev_put: out_mddev_put:
mddev_put(mddev); mddev_put(mddev);
} }
......
...@@ -2537,7 +2537,7 @@ backlog_store(struct mddev *mddev, const char *buf, size_t len) ...@@ -2537,7 +2537,7 @@ backlog_store(struct mddev *mddev, const char *buf, size_t len)
if (backlog > COUNTER_MAX) if (backlog > COUNTER_MAX)
return -EINVAL; return -EINVAL;
rv = mddev_lock(mddev); rv = mddev_suspend_and_lock(mddev);
if (rv) if (rv)
return rv; return rv;
...@@ -2562,16 +2562,16 @@ backlog_store(struct mddev *mddev, const char *buf, size_t len) ...@@ -2562,16 +2562,16 @@ backlog_store(struct mddev *mddev, const char *buf, size_t len)
if (!backlog && mddev->serial_info_pool) { if (!backlog && mddev->serial_info_pool) {
/* serial_info_pool is not needed if backlog is zero */ /* serial_info_pool is not needed if backlog is zero */
if (!mddev->serialize_policy) if (!mddev->serialize_policy)
mddev_destroy_serial_pool(mddev, NULL, false); mddev_destroy_serial_pool(mddev, NULL, true);
} else if (backlog && !mddev->serial_info_pool) { } else if (backlog && !mddev->serial_info_pool) {
/* serial_info_pool is needed since backlog is not zero */ /* serial_info_pool is needed since backlog is not zero */
rdev_for_each(rdev, mddev) rdev_for_each(rdev, mddev)
mddev_create_serial_pool(mddev, rdev, false); mddev_create_serial_pool(mddev, rdev, true);
} }
if (old_mwb != backlog) if (old_mwb != backlog)
md_bitmap_update_sb(mddev->bitmap); md_bitmap_update_sb(mddev->bitmap);
mddev_unlock(mddev); mddev_unlock_and_resume(mddev);
return len; return len;
} }
......
...@@ -2557,7 +2557,7 @@ static int bind_rdev_to_array(struct md_rdev *rdev, struct mddev *mddev) ...@@ -2557,7 +2557,7 @@ static int bind_rdev_to_array(struct md_rdev *rdev, struct mddev *mddev)
pr_debug("md: bind<%s>\n", b); pr_debug("md: bind<%s>\n", b);
if (mddev->raid_disks) if (mddev->raid_disks)
mddev_create_serial_pool(mddev, rdev, false); mddev_create_serial_pool(mddev, rdev, true);
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;
...@@ -3077,11 +3077,11 @@ state_store(struct md_rdev *rdev, const char *buf, size_t len) ...@@ -3077,11 +3077,11 @@ state_store(struct md_rdev *rdev, const char *buf, size_t len)
} }
} else if (cmd_match(buf, "writemostly")) { } else if (cmd_match(buf, "writemostly")) {
set_bit(WriteMostly, &rdev->flags); set_bit(WriteMostly, &rdev->flags);
mddev_create_serial_pool(rdev->mddev, rdev, false); mddev_create_serial_pool(rdev->mddev, rdev, true);
need_update_sb = true; need_update_sb = true;
err = 0; err = 0;
} else if (cmd_match(buf, "-writemostly")) { } else if (cmd_match(buf, "-writemostly")) {
mddev_destroy_serial_pool(rdev->mddev, rdev, false); mddev_destroy_serial_pool(rdev->mddev, rdev, true);
clear_bit(WriteMostly, &rdev->flags); clear_bit(WriteMostly, &rdev->flags);
need_update_sb = true; need_update_sb = true;
err = 0; err = 0;
...@@ -3707,7 +3707,9 @@ rdev_attr_store(struct kobject *kobj, struct attribute *attr, ...@@ -3707,7 +3707,9 @@ rdev_attr_store(struct kobject *kobj, struct attribute *attr,
if (entry->store == state_store) { if (entry->store == state_store) {
if (cmd_match(page, "remove")) if (cmd_match(page, "remove"))
kn = sysfs_break_active_protection(kobj, attr); kn = sysfs_break_active_protection(kobj, attr);
if (cmd_match(page, "remove") || cmd_match(page, "re-add")) if (cmd_match(page, "remove") || cmd_match(page, "re-add") ||
cmd_match(page, "writemostly") ||
cmd_match(page, "-writemostly"))
suspend = true; suspend = true;
} }
...@@ -4684,7 +4686,7 @@ new_dev_store(struct mddev *mddev, const char *buf, size_t len) ...@@ -4684,7 +4686,7 @@ new_dev_store(struct mddev *mddev, const char *buf, size_t len)
minor != MINOR(dev)) minor != MINOR(dev))
return -EOVERFLOW; return -EOVERFLOW;
err = mddev_lock(mddev); err = mddev_suspend_and_lock(mddev);
if (err) if (err)
return err; return err;
if (mddev->persistent) { if (mddev->persistent) {
...@@ -4705,14 +4707,14 @@ new_dev_store(struct mddev *mddev, const char *buf, size_t len) ...@@ -4705,14 +4707,14 @@ new_dev_store(struct mddev *mddev, const char *buf, size_t len)
rdev = md_import_device(dev, -1, -1); rdev = md_import_device(dev, -1, -1);
if (IS_ERR(rdev)) { if (IS_ERR(rdev)) {
mddev_unlock(mddev); mddev_unlock_and_resume(mddev);
return PTR_ERR(rdev); return PTR_ERR(rdev);
} }
err = bind_rdev_to_array(rdev, mddev); err = bind_rdev_to_array(rdev, mddev);
out: out:
if (err) if (err)
export_rdev(rdev, mddev); export_rdev(rdev, mddev);
mddev_unlock(mddev); mddev_unlock_and_resume(mddev);
if (!err) if (!err)
md_new_event(); md_new_event();
return err ? err : len; return err ? err : len;
...@@ -6649,13 +6651,13 @@ static void autorun_devices(int part) ...@@ -6649,13 +6651,13 @@ static void autorun_devices(int part)
if (IS_ERR(mddev)) if (IS_ERR(mddev))
break; break;
if (mddev_lock(mddev)) if (mddev_suspend_and_lock(mddev))
pr_warn("md: %s locked, cannot run\n", mdname(mddev)); pr_warn("md: %s locked, cannot run\n", mdname(mddev));
else if (mddev->raid_disks || mddev->major_version else if (mddev->raid_disks || mddev->major_version
|| !list_empty(&mddev->disks)) { || !list_empty(&mddev->disks)) {
pr_warn("md: %s already running, cannot run %pg\n", pr_warn("md: %s already running, cannot run %pg\n",
mdname(mddev), rdev0->bdev); mdname(mddev), rdev0->bdev);
mddev_unlock(mddev); mddev_unlock_and_resume(mddev);
} else { } else {
pr_debug("md: created %s\n", mdname(mddev)); pr_debug("md: created %s\n", mdname(mddev));
mddev->persistent = 1; mddev->persistent = 1;
...@@ -6665,7 +6667,7 @@ static void autorun_devices(int part) ...@@ -6665,7 +6667,7 @@ static void autorun_devices(int part)
export_rdev(rdev, mddev); export_rdev(rdev, mddev);
} }
autorun_array(mddev); autorun_array(mddev);
mddev_unlock(mddev); mddev_unlock_and_resume(mddev);
} }
/* on success, candidates will be empty, on error /* on success, candidates will be empty, on error
* it won't... * it won't...
......
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