Received: by 2002:ab2:6991:0:b0:1f7:f6c3:9cb1 with SMTP id v17csp860633lqo; Wed, 8 May 2024 18:37:11 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUwmzcWgRK/Zi6aH3MWPZkQpepgDph3FuwW22ffIC9xdcUGAFtMQmPgtRyOy9zgmvBRnfGh4I21eeL6+GOZMbvBlLhTZc6XYXlEMFzUdA== X-Google-Smtp-Source: AGHT+IH/J1tahXfpBsoU6KWggnnn8TXNe6UHCxXka4eD1oMr6zAKOUD3IZgghaufgfD/pr/OKjJr X-Received: by 2002:ac2:42c8:0:b0:513:e63c:cfe7 with SMTP id 2adb3069b0e04-5217cd4b2cfmr2341518e87.66.1715218630818; Wed, 08 May 2024 18:37:10 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715218630; cv=pass; d=google.com; s=arc-20160816; b=VehW3P2ZzM2s3WyvN5uemlRsJdHsMxLEbzxsUriMY8BftvkTDu1g9s7imyd1DwS3Hp APuRfvb83Sf672/HCmH5C1+AQE644ATlbufHmFtqSA9FaGm6uAcRqPg8+7NK/8D3ysUf 1S/zBiva2XsynpH5xpNfR0awmZSjhp7aFBKEs0IYr3lxsZ4V8+2re5gDcTqfcHuKDHsV tGtilZOnsQXiqX2jrRR7Q30mx6ftFVTB2CVvNHz5TQItzu6aXxEttptBqL388QHMYRBF ayxqY0ucMhi8MMlCcMu4zhgIlx7AKPNHy51fyBNZgGZMpF/VAMWPlaN3Q44Q/KqlfFJl iobw== 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=fxgCcjKVcv/tQI7eRM5sm4oUaOOkgyz/95ltBttmhYI=; fh=vFj2LZCfsSjQyBW6TnUaUIAX9ceL72Bl/t9ngqXepOM=; b=S9lt/R5HfaxZexNaJ7zwtdRz9mGOs7/PaANray12p/kKxomyjxWlcFJnZRSrlTmTfh 0PQPVh6WL6onut/uREkgq1AmCx6xHaibHjN9z5HN6h4E2eI76cWp9aBoqumX+dsblFo4 woDxnGj0J4hWb//Nv5jti9aH07TExQHlaoMVLYyDWsrmXFn3jLDKlmMvqGC+SbF0i2kj 6+YnwsXMPEolrKCu056E5CFGgsFZ+tCBO0GR5MmwH3pMYD1/GBycZjNHVDdawK/nQsEJ lM346daUBRk9Bn3RG6y2Zbndy9T3JUI68G68Lb3vDOqG7pBCyfLo+NiRqYMle1dBmacl 19bw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-174007-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-174007-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a5a1794648dsi22363766b.189.2024.05.08.18.37.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 18:37:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-174007-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-174007-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-174007-linux.lists.archive=gmail.com@vger.kernel.org" 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 D2CDA1F235B6 for ; Thu, 9 May 2024 01:29:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8449513C9C9; Thu, 9 May 2024 01:29:11 +0000 (UTC) Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) (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 A08C613C66D; Thu, 9 May 2024 01:29:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715218150; cv=none; b=cAX00J+lJ96KS0e601cK8Iw9F6bvZMBjmPyTykVOyq3B6g73hGNob3eanrvxGRseT4fY6YowXCDDb7p7LKjoy5AQi/BgkoxlqCcgYPSefAzdnGoxutMzEbpUW9WLhe599VNYOvwKROYvlwYX8Au2Dk6AF5hkdgPjup/dLD0O3Jw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715218150; c=relaxed/simple; bh=dZUWovCd9fNOy2fyKYX2nZD0pt4n2TnyvzaT97C5lno=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=I1usAZvZwHQf3WN6uKpoC8fZj8P1a6aO09LCs2RnF7EajwEsbKFn9uuebMzVunGT6aeInwi73yKSDlM/8sOD6JIlkd7rZngKcrjMSziWFNPmIxuuD84LaNmXTaWZLYLjnohLNv099n5yD2LI9dfn5VixjlkHrx5T10YldFbqkfQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VZZDD3239z4f3kkF; Thu, 9 May 2024 09:29:00 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id BD4281A058D; Thu, 9 May 2024 09:29:05 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgDHlxDeJjxm5MuXMA--.59814S8; Thu, 09 May 2024 09:29:05 +0800 (CST) From: Yu Kuai To: agk@redhat.com, snitzer@kernel.org, mpatocka@redhat.com, song@kernel.org, xni@redhat.com Cc: dm-devel@lists.linux.dev, linux-kernel@vger.kernel.org, linux-raid@vger.kernel.org, yukuai3@huawei.com, yukuai1@huaweicloud.com, yi.zhang@huawei.com, yangerkun@huawei.com Subject: [PATCH md-6.10 4/9] md: factor out helper to start reshape from action_store() Date: Thu, 9 May 2024 09:18:55 +0800 Message-Id: <20240509011900.2694291-5-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240509011900.2694291-1-yukuai1@huaweicloud.com> References: <20240509011900.2694291-1-yukuai1@huaweicloud.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 X-CM-TRANSID:cCh0CgDHlxDeJjxm5MuXMA--.59814S8 X-Coremail-Antispam: 1UD129KBjvJXoWxur1UJF1kJF1UtrW7tw4xWFg_yoWrGF17pa yftFn5ArW5JrW3Xw4UJF1DuayFgr1xtrZrtrW7W34fJF1fKrn7G3WYga1UJr98ta4rAr4Y qa1DtFW5CFWj9aUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPF14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUGVWUXwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUCVW8JwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Cr0_Gr1UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJV W8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjfUF18B UUUUU X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ From: Yu Kuai There are no functional changes, just to make code cleaner and prepare for following refactor. Signed-off-by: Yu Kuai --- drivers/md/md.c | 67 +++++++++++++++++++++++++++++++------------------ drivers/md/md.h | 2 +- 2 files changed, 43 insertions(+), 26 deletions(-) diff --git a/drivers/md/md.c b/drivers/md/md.c index 48ec35342d1b..7600da89d909 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -4914,7 +4914,7 @@ enum sync_action md_sync_action(struct mddev *mddev) return ACTION_IDLE; } -enum sync_action md_sync_action_by_name(char *page) +enum sync_action md_sync_action_by_name(const char *page) { enum sync_action action; @@ -5055,6 +5055,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) { @@ -5074,32 +5113,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); diff --git a/drivers/md/md.h b/drivers/md/md.h index 72ca7a796df5..cf54870e89db 100644 --- a/drivers/md/md.h +++ b/drivers/md/md.h @@ -865,7 +865,7 @@ extern void md_wakeup_thread(struct md_thread __rcu *thread); extern void md_check_recovery(struct mddev *mddev); extern void md_reap_sync_thread(struct mddev *mddev); extern enum sync_action md_sync_action(struct mddev *mddev); -extern enum sync_action md_sync_action_by_name(char *page); +extern enum sync_action md_sync_action_by_name(const char *page); extern char *md_sync_action_name(enum sync_action action); extern bool md_write_start(struct mddev *mddev, struct bio *bi); extern void md_write_inc(struct mddev *mddev, struct bio *bi); -- 2.39.2