Received: by 2002:ab2:7903:0:b0:1fb:b500:807b with SMTP id a3csp944523lqj; Mon, 3 Jun 2024 06:00:59 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVtScEMe7/P60pO3ASKMjsM1JAcFL7ZD2vh3kJT/q0EHRYFODtky3MjC8M+aX3BL3G8lKO9gRc41Dg41bK+DqeFoLjK9iUTlahN+LDbNg== X-Google-Smtp-Source: AGHT+IFo5uEZljc3afuAPqIugkm0Y2RarM0pK3xYcTdYm1VkUpCKQ/wozgf8XZ7k4SvXW4uSpL8E X-Received: by 2002:a17:906:bcd8:b0:a68:f493:4b58 with SMTP id a640c23a62f3a-a68f4934d07mr259462366b.40.1717419659106; Mon, 03 Jun 2024 06:00:59 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717419659; cv=pass; d=google.com; s=arc-20160816; b=YrF+yKAb/y+g5QvRNcxXTNHG8yYsHkFkBgRiAPexUzfFHIzE326ePkqRnMhkg5EmoT nu+Ekt5aWcWgXWL8wnrVxkuVomFR5GPgvPHF7PcUUmcOUQ/3V9vO2oOd6I8rSpohEn5T F2rxNq/GMfWEe8ZB8+zPFMMMG7ZL8kjquP3Bv6famgZnrpq6Ztmhd+JeiJv+S/UViqEr 1QwxbAt6GB8CLOOy5j68+gbz2Xadf66NFgslU9X9zE5C9NQolKGEzCa9p91tcW4ORBUg IShdgTqpQxiEip/yUghwUxE2WBK6rCRyoRckUBPzAO4xV/WoK02xbyCqXxcstBPODQrf 5kew== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=INo87kdcf1LdEck05mv4ZbIoF/yrN/WwFv0OeCB7e6U=; fh=1LhuwRtrwnHwkJ8SSfr9g2yPev2+fxl/FqZerKdeGVc=; b=mVPTwlh9WNgUQDLM9/Zi8RTaA5XJ2kWssNeftk0pN5dAn8uax5C4baZpltrv/ng3GV i9il1BT86bI4t7lAEMCRaLvilrm6EwXWc0zbVU4LJzdSK11X3Ktx6aSjP8qg8d53zBb9 P8hdht4uzXnuKsb6d8R30MUelmeat11yAxkoopW82y+pMW5ZD4q101VxuUYJBdkWgoQ1 +dgh37KZmF0wdXlCmfrA6Aq14Vp60Hi+86E903+QyjdpQVTZjHxtNLP2JZ+NmHb2WQB9 xOAxCHtnV6JgbyR3NKZShksC/U0iPu1vRW5YACT35s0xVhd9K0DJJO0Avdg312XiHZCu Tjaw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-199152-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-199152-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a690133656fsi129037366b.706.2024.06.03.06.00.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jun 2024 06:00:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-199152-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-199152-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-199152-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 6DCD51F2735B for ; Mon, 3 Jun 2024 12:59:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8021F12CDAE; Mon, 3 Jun 2024 12:59:01 +0000 (UTC) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 314CD12C54B; Mon, 3 Jun 2024 12:58:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.187 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717419541; cv=none; b=pETGgah+/CdAI4o9A1F7BKsC01OYJgsHRi/Ebsk5Ebo8S+E67gYJtUz8seykDHPVYXnfa/AYcRZUtppsqRwjqxklPXBDgbmO/8So5WmWf/AIAt/xoy5fEdughSd/S1ZpafzHNzvysWCywtsG5axA0YNLXBpgQN5KZqD01teWqAU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717419541; c=relaxed/simple; bh=BMr1T6POjrtTgMDCctLWY9qwW/mvv6c4OE0VAANQlq4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=JbbqpEavc5wiIiXD0Cegyq9MCqkAfxcwmOMnX6wnVjycv7pnU6HX3A74NAS1/wG6OODIA1WsD7W4hXQQlMUUWmnPXbPhNw0FUHmDhUUx/VmN1HuWMK9GwyWs+VJtdhEZvlAq1CFWknzoHZHNJabKbxpOhAp2WU6qYShZVaoxPM0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.105]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4VtDGH1nrwzwRLn; Mon, 3 Jun 2024 20:55:03 +0800 (CST) Received: from kwepemm600009.china.huawei.com (unknown [7.193.23.164]) by mail.maildlp.com (Postfix) with ESMTPS id 5F2FB14037B; Mon, 3 Jun 2024 20:58:42 +0800 (CST) Received: from huawei.com (10.175.104.67) by kwepemm600009.china.huawei.com (7.193.23.164) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Mon, 3 Jun 2024 20:58:13 +0800 From: Yu Kuai To: , , , , , , CC: , , , , , , Subject: [PATCH 04/12] md: factor out helper to start reshape from action_store() Date: Mon, 3 Jun 2024 20:58:07 +0800 Message-ID: <20240603125815.2199072-5-yukuai3@huawei.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240603125815.2199072-1-yukuai3@huawei.com> References: <20240603125815.2199072-1-yukuai3@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemm600009.china.huawei.com (7.193.23.164) There are no functional changes, just to make code cleaner and prepare for following refactor. Signed-off-by: Yu Kuai --- drivers/md/md.c | 65 +++++++++++++++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 24 deletions(-) diff --git a/drivers/md/md.c b/drivers/md/md.c index e5487008f66e..28f50a106566 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -5070,6 +5070,45 @@ static void frozen_sync_thread(struct mddev *mddev) 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 action_store(struct mddev *mddev, const char *page, size_t len) { @@ -5089,32 +5128,10 @@ action_store(struct mddev *mddev, const char *page, size_t len) clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery); set_bit(MD_RECOVERY_RECOVER, &mddev->recovery); } else if (cmd_match(page, "reshape")) { - int err; - 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); - } + int err = mddev_start_reshape(mddev); + if (err) return err; - sysfs_notify_dirent_safe(mddev->sysfs_degraded); } else { if (cmd_match(page, "check")) set_bit(MD_RECOVERY_CHECK, &mddev->recovery); -- 2.39.2