Received: by 2002:ab2:7903:0:b0:1fb:b500:807b with SMTP id a3csp944353lqj; Mon, 3 Jun 2024 06:00:47 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW9xrgnuxLhJWAmXCWsKrYTARODaSW3x4rYX6lHyHYG6jiuN2+0l+G2sIPEB8VMMFbD2L6tEKDuWkAumA2mG/oCcYjT8PkzYcLCyj/GEw== X-Google-Smtp-Source: AGHT+IESRHLbasrE+ty8QhgHfzNrqGCAMPODPOGev7cLekhdu1a1RwM8HuJCi6+8i32PXseRZjTT X-Received: by 2002:ac2:4194:0:b0:52b:913d:1c62 with SMTP id 2adb3069b0e04-52b913d1d7cmr4550512e87.69.1717419647094; Mon, 03 Jun 2024 06:00:47 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717419647; cv=pass; d=google.com; s=arc-20160816; b=uLd8LJRF8h+orWjlwV2gH28avwmObTYM9aAzzlappyKkpdM83c6fOeZn7RFcwJgZnj ZK/yAJN/J2wyuO+vqVTC0U0ueBLEfLYpWs8NzEvD/n6WRY3xLS/dvxtAd85i1UaVIb4e UhRZ6k3qbF2ipn7PzYSCB0UefYVhUs7sFX1Y9nUH2/YYbvlf4jcx2mCScHTQ5iu/bn2J R58BurutvnwkGWzCxczaqp7zr+hJqwA068Cfx3gHK5r6IU0oOm/7TUrpae5agnJbPVwC JE561FGzgOJ4whK27m6+66EiCVoPc1rJPhMZDJ1VMTwzKIguOZoScp+7/Of9EmYs63Ce ZGyA== 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=+TuXsWGhFRqaB4jjDHY+y4SpFc3V7WLeN4k8I9Uim6k=; fh=1LhuwRtrwnHwkJ8SSfr9g2yPev2+fxl/FqZerKdeGVc=; b=c2x9smUBJy5w3ufvt24BK4qb2ipBoEg95INFaTwJ0TPsgOAB3kKPvkqIgJpRRueEzy BUkgKVT8qMdS2Y+0EAtImQ5wTvFEpbxxFZWrDAs4hQudWKDc2sL6sOhE++JJWTI1GRNe uTegQPeQcKt8a64arAk2lV8cKCNYfFoM/w284rORBoSKLNi+5bKenZODB/vbf5jMpS+Z ZKbawvXZnFp38Nt7Jow15qwxlja6uGZZ6v7JaGq20rkTetcezQMi3bwpy8uuCsI78aNJ YEbGPiDVaubeQAnk7FeGj92WXdAxkxgeHdWXPQU48Uuc4scSADE/G54pWEAaTwLvNN0W 2JdA==; 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-199151-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-199151-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. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a6916b86816si75072966b.574.2024.06.03.06.00.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jun 2024 06:00:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-199151-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=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-199151-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-199151-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 4F2D51F27087 for ; Mon, 3 Jun 2024 12:59:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5DE1612D748; Mon, 3 Jun 2024 12:58:47 +0000 (UTC) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) (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 60F7612CD98; Mon, 3 Jun 2024 12:58:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.188 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717419526; cv=none; b=r/hRzRWwhWJAkaSuO9iaiCUkmTkDO8vtGIFwPdTD6bqTO3deyKoHXewniD6Wv6xY//k/wG/wW9jSIAt4zLKgu/tNpL/OBsKmfNO5Ipof3c+IAMW380J8au+gqe6w7R/1wG/lhiFBTR+GFgPIwSuDnyNaSezbmzUe6nAR769/0DU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717419526; c=relaxed/simple; bh=RYgIXlpfHFpa7fuAjbAWJANhvY0CxwerTgR7X6hLYaw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=PCMhzqrQstPKz84rAUYbnrTrxJdVjpB0CNGlKRV3AX/SACNI/yTfiuQT7psCJX8OpzPMwsNvxncZvSK2hFA8l7qg8F7zzmK+rIDxg5uUKdFGhw9LB0ZzTMK8zK7sKi2De5CMpSFHk97fGs0Q4nCelEgitn/qpi2GnNsvBYpiZ3k= 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.188 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 szxga02-in.huawei.com (SkyGuard) with ESMTP id 4VtDFJ0BR1zmXZx; Mon, 3 Jun 2024 20:54:12 +0800 (CST) Received: from kwepemm600009.china.huawei.com (unknown [7.193.23.164]) by mail.maildlp.com (Postfix) with ESMTPS id 54347140123; Mon, 3 Jun 2024 20:58:27 +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:12 +0800 From: Yu Kuai To: , , , , , , CC: , , , , , , Subject: [PATCH 03/12] md: add new helpers for sync_action Date: Mon, 3 Jun 2024 20:58:06 +0800 Message-ID: <20240603125815.2199072-4-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) The new helpers will get current sync_action of the array, will be used in later patches to make code cleaner. Signed-off-by: Yu Kuai --- drivers/md/md.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++ drivers/md/md.h | 3 ++ 2 files changed, 82 insertions(+) diff --git a/drivers/md/md.c b/drivers/md/md.c index aff9118ff697..e5487008f66e 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -69,6 +69,16 @@ #include "md-bitmap.h" #include "md-cluster.h" +static const char *action_name[NR_SYNC_ACTIONS] = { + [ACTION_RESYNC] = "resync", + [ACTION_RECOVER] = "recover", + [ACTION_CHECK] = "check", + [ACTION_REPAIR] = "repair", + [ACTION_RESHAPE] = "reshape", + [ACTION_FROZEN] = "frozen", + [ACTION_IDLE] = "idle", +}; + /* pers_list is a list of registered personalities protected by pers_lock. */ static LIST_HEAD(pers_list); static DEFINE_SPINLOCK(pers_lock); @@ -4867,6 +4877,75 @@ metadata_store(struct mddev *mddev, const char *buf, size_t len) static struct md_sysfs_entry md_metadata = __ATTR_PREALLOC(metadata_version, S_IRUGO|S_IWUSR, metadata_show, metadata_store); +enum sync_action md_sync_action(struct mddev *mddev) +{ + unsigned long recovery = mddev->recovery; + + /* + * frozen has the highest priority, means running sync_thread will be + * stopped immediately, and no new sync_thread can start. + */ + if (test_bit(MD_RECOVERY_FROZEN, &recovery)) + return ACTION_FROZEN; + + /* + * read-only array can't register sync_thread, and it can only + * add/remove spares. + */ + if (!md_is_rdwr(mddev)) + return ACTION_IDLE; + + /* + * idle means no sync_thread is running, and no new sync_thread is + * requested. + */ + if (!test_bit(MD_RECOVERY_RUNNING, &recovery) && + !test_bit(MD_RECOVERY_NEEDED, &recovery)) + return ACTION_IDLE; + + if (test_bit(MD_RECOVERY_RESHAPE, &recovery) || + mddev->reshape_position != MaxSector) + return ACTION_RESHAPE; + + if (test_bit(MD_RECOVERY_RECOVER, &recovery)) + return ACTION_RECOVER; + + if (test_bit(MD_RECOVERY_SYNC, &recovery)) { + /* + * MD_RECOVERY_CHECK must be paired with + * MD_RECOVERY_REQUESTED. + */ + if (test_bit(MD_RECOVERY_CHECK, &recovery)) + return ACTION_CHECK; + if (test_bit(MD_RECOVERY_REQUESTED, &recovery)) + return ACTION_REPAIR; + return ACTION_RESYNC; + } + + /* + * MD_RECOVERY_NEEDED or MD_RECOVERY_RUNNING is set, however, no + * sync_action is specified. + */ + return ACTION_IDLE; +} + +enum sync_action md_sync_action_by_name(const char *page) +{ + enum sync_action action; + + for (action = 0; action < NR_SYNC_ACTIONS; ++action) { + if (cmd_match(page, action_name[action])) + return action; + } + + return NR_SYNC_ACTIONS; +} + +const char *md_sync_action_name(enum sync_action action) +{ + return action_name[action]; +} + static ssize_t action_show(struct mddev *mddev, char *page) { diff --git a/drivers/md/md.h b/drivers/md/md.h index 6b9d9246f260..018f3292a25c 100644 --- a/drivers/md/md.h +++ b/drivers/md/md.h @@ -864,6 +864,9 @@ extern void md_unregister_thread(struct mddev *mddev, struct md_thread __rcu **t 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(const char *page); +extern const 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); extern void md_write_end(struct mddev *mddev); -- 2.39.2