Commit 207c5656 authored by Yu Kuai's avatar Yu Kuai Committed by Song Liu

md: factor out helper to start reshape from action_store()

There are no functional changes, just to make code cleaner and prepare
for following refactor.
Signed-off-by: default avatarYu Kuai <yukuai3@huawei.com>
Signed-off-by: default avatarSong Liu <song@kernel.org>
Link: https://lore.kernel.org/r/20240611132251.1967786-5-yukuai1@huaweicloud.com
parent e792a4c2
...@@ -5071,6 +5071,45 @@ static void frozen_sync_thread(struct mddev *mddev) ...@@ -5071,6 +5071,45 @@ static void frozen_sync_thread(struct mddev *mddev)
mutex_unlock(&mddev->sync_mutex); mutex_unlock(&mddev->sync_mutex);
} }
static int mddev_start_reshape(struct mddev *mddev)
{
int ret;
if (mddev->pers->start_reshape == NULL)
return -EINVAL;
ret = mddev_lock(mddev);
if (ret)
return ret;
if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)) {
mddev_unlock(mddev);
return -EBUSY;
}
if (mddev->reshape_position == MaxSector ||
mddev->pers->check_reshape == NULL ||
mddev->pers->check_reshape(mddev)) {
clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery);
ret = mddev->pers->start_reshape(mddev);
if (ret) {
mddev_unlock(mddev);
return ret;
}
} else {
/*
* If reshape is still in progress, and md_check_recovery() can
* continue to reshape, don't restart reshape because data can
* be corrupted for raid456.
*/
clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery);
}
mddev_unlock(mddev);
sysfs_notify_dirent_safe(mddev->sysfs_degraded);
return 0;
}
static ssize_t static ssize_t
action_store(struct mddev *mddev, const char *page, size_t len) action_store(struct mddev *mddev, const char *page, size_t len)
{ {
...@@ -5090,32 +5129,10 @@ action_store(struct mddev *mddev, const char *page, size_t len) ...@@ -5090,32 +5129,10 @@ action_store(struct mddev *mddev, const char *page, size_t len)
clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery); clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery);
set_bit(MD_RECOVERY_RECOVER, &mddev->recovery); set_bit(MD_RECOVERY_RECOVER, &mddev->recovery);
} else if (cmd_match(page, "reshape")) { } else if (cmd_match(page, "reshape")) {
int err; int err = mddev_start_reshape(mddev);
if (mddev->pers->start_reshape == NULL)
return -EINVAL;
err = mddev_lock(mddev);
if (!err) {
if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)) {
err = -EBUSY;
} else if (mddev->reshape_position == MaxSector ||
mddev->pers->check_reshape == NULL ||
mddev->pers->check_reshape(mddev)) {
clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery);
err = mddev->pers->start_reshape(mddev);
} else {
/*
* If reshape is still in progress, and
* md_check_recovery() can continue to reshape,
* don't restart reshape because data can be
* corrupted for raid456.
*/
clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery);
}
mddev_unlock(mddev);
}
if (err) if (err)
return err; return err;
sysfs_notify_dirent_safe(mddev->sysfs_degraded);
} else { } else {
if (cmd_match(page, "check")) if (cmd_match(page, "check"))
set_bit(MD_RECOVERY_CHECK, &mddev->recovery); set_bit(MD_RECOVERY_CHECK, &mddev->recovery);
......
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