Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp2518634lqo; Tue, 14 May 2024 00:39:39 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVDznd2oyu94IxDkTpOG3vC1CnwPVdg41JwRUVZzyB1IekKtkYV/NZ9ApdtSN0+i6Oex65l6NTquXYfKENVNWVOMDINq1tur7d7tnhsRQ== X-Google-Smtp-Source: AGHT+IFzPqMIzia0JByP6O3k+32ciJTG14yR/90QuyyY3oJMtfV4MwiBRSZ6ypLf+3ZsRUiI4ICA X-Received: by 2002:a05:6a21:995:b0:1af:d206:e57c with SMTP id adf61e73a8af0-1afde1fc287mr10172760637.58.1715672379493; Tue, 14 May 2024 00:39:39 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715672379; cv=pass; d=google.com; s=arc-20160816; b=hTgTchN4Dry3hRmt6bVd5eMSN3V3S80sNhwd54m37OvYeubDWB0WSI17KFlYEBpZmS Q/rgDRsEl9hIoGVYhehOiPL1RkqUvEa518TyxQRqDZMO33YD6rHRGQiubgiFd9ZotWLm SlITtwWGKy6rNUZz1kaEm3ayHAqzJPtvP+uAVdIoH/clndpV8QuWxJL3tOpdMCjFByjK E03Q9DoxVC5vclao1qHsiygew6bq4ZlnJ2bK8dlZ6mixIPIbqbv+GazeSPGZRWyVQN2g zDq+AGtzQPYZv9M91+yzUlxEGxoQmUuyFFi/MBk2d3xDSRV6bm5+WpPggABubh8AUOJ2 SPTw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:user-agent:date:message-id:from :references:cc:to:subject; bh=DvcsNhg1vKi866f2/PF3LrAVUlJt1rUbqehuXhJjk3E=; fh=7XeR3ua4fuc2ZoR6dl+kgTmgqTMQ8MgPFYYydJ9V4E8=; b=hxoNG5c6+xnZ6+xuO2bbZmRaQg1FLf8DVFyQQPgJx0uiYXWoP4S0dNvYxCF8YJADmf UnP0dd1GWpFge4cOrbxmZAJieesex2rfKaPIBRbpG/g3OIXXznfdprXxzyw913+1DMJu SztKy2l+haqXQxD8uwtTy3fIRsd1y/gaslPk3NiftolkwIeHpUS539IL79iZ2cAK1qEL 1bWRS7dxGwcEtoR0gU/KM06SGIdVLjzSpqNjQNVLBPXKfMLqFdW76ndNbkIUOw3ScYui W74USA+DM9rO8C4QGO0GmozLmApkkqSpbauV8pu3BjGrMj23dkpEvXm47DUNxJx1obic /ABg==; 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-178406-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-178406-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d9443c01a7336-1ef0c038684si105681005ad.373.2024.05.14.00.39.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 May 2024 00:39:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-178406-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-178406-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-178406-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 1AF63283B09 for ; Tue, 14 May 2024 07:39:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0D44F1CD2B; Tue, 14 May 2024 07:39:22 +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 3E45917BA6; Tue, 14 May 2024 07:39:18 +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=1715672361; cv=none; b=o6YALNu7y1vVlvL+tvGrFeQTlgYpVUt/zx4D5MLI0Kql9lhxoW4JLBCZq2fZxlQb87XqgkxG4PhB3Hoi7a9EZYJtyPc+nadRjRStcbRe56B0ccclTTtutEqbWKdmcX49oG+quu4A7iGNtdU3I9dQYmpw3/IdsxKPt+GJhPsqrSs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715672361; c=relaxed/simple; bh=MnSQzHoxtxIl3IOV7lyQzamLUBc4nGorf90eqgyKJ5Q=; h=Subject:To:Cc:References:From:Message-ID:Date:MIME-Version: In-Reply-To:Content-Type; b=YmpWWJk7PtT4iLpFnghWdXvviZXggik5IFb/9qDA5KgmvYsTSZBtINUCiSAEWVjKQax1BOsCCEbRYgOmiI9yEEQmp8HJiNwUDTNuuOXtJOWZyW2RpM9Tp+5Rn9dtD8+EeH2aMmMj94l/5e+ee6JFWj+uZbjrJBRYx1tCuY1xB4Y= 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 4VdpBw2Q0Yz4f3lW3; Tue, 14 May 2024 15:39:04 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 739691A0846; Tue, 14 May 2024 15:39:14 +0800 (CST) Received: from [10.174.176.73] (unknown [10.174.176.73]) by APP1 (Coremail) with SMTP id cCh0CgBnOBEgFUNmecN+Mg--.24478S3; Tue, 14 May 2024 15:39:14 +0800 (CST) Subject: Re: [PATCH md-6.10 3/9] md: add new helpers for sync_action To: Xiao Ni , Yu Kuai Cc: agk@redhat.com, snitzer@kernel.org, mpatocka@redhat.com, song@kernel.org, dm-devel@lists.linux.dev, linux-kernel@vger.kernel.org, linux-raid@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com, "yukuai (C)" References: <20240509011900.2694291-1-yukuai1@huaweicloud.com> <20240509011900.2694291-4-yukuai1@huaweicloud.com> From: Yu Kuai Message-ID: <06211ae2-9b5f-10c7-7953-9d79d2eacc67@huaweicloud.com> Date: Tue, 14 May 2024 15:39:12 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-CM-TRANSID:cCh0CgBnOBEgFUNmecN+Mg--.24478S3 X-Coremail-Antispam: 1UD129KBjvJXoWxZFW3Wr13tw4fCFW8tw1rCrg_yoWruF18pF W0yas8ZrW7ZFy7Xry2qa4DAayF9r1Iq3y7AFyfGa4fJ3ZIkwnaka4DK3W7Ca4vka43ur1Y va4DGFy3uF4FyrJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUU9F14x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4U JVWxJr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Gc CE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E 2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJV W8JwACjcxG0xvEwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lFIxGxcIEc7CjxVA2Y2ka 0xkIwI1lc7I2V7IY0VAS07AlzVAYIcxG8wCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7x kEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E 67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCw CI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6rW3Jr0E 3s1lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcS sGvfC2KfnxnUUI43ZEXa7VUbXdbUUUUUU== X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ Hi, 在 2024/05/14 14:52, Xiao Ni 写道: > On Mon, May 13, 2024 at 5:31 PM Yu Kuai wrote: >> >> From: Yu Kuai >> >> 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 | 64 +++++++++++++++++++++++++++++++++++++++++++++++++ >> drivers/md/md.h | 3 +++ >> 2 files changed, 67 insertions(+) >> >> diff --git a/drivers/md/md.c b/drivers/md/md.c >> index 00bbafcd27bb..48ec35342d1b 100644 >> --- a/drivers/md/md.c >> +++ b/drivers/md/md.c >> @@ -69,6 +69,16 @@ >> #include "md-bitmap.h" >> #include "md-cluster.h" >> >> +static 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,60 @@ 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; >> + >> + /* >> + * idle means no sync_thread is running, and no new sync_thread is >> + * requested. >> + */ >> + if (!test_bit(MD_RECOVERY_RUNNING, &recovery) && >> + (!md_is_rdwr(mddev) || !test_bit(MD_RECOVERY_NEEDED, &recovery))) >> + return ACTION_IDLE; > > Hi Kuai > > Can I think the above judgement cover these two situations: > 1. The array is readonly / readauto and it doesn't have > MD_RECOVERY_RUNNING. Now maybe it has MD_RECOVERY_NEEDED, it means one > array may want to do some sync action, but the array state is not > readwrite and it can't start. > 2. The array doesn't have MD_RECOVERY_RUNNING and MD_RECOVERY_NEEDED > >> + >> + 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)) { >> + if (test_bit(MD_RECOVERY_CHECK, &recovery)) >> + return ACTION_CHECK; >> + if (test_bit(MD_RECOVERY_REQUESTED, &recovery)) >> + return ACTION_REPAIR; >> + return ACTION_RESYNC; >> + } >> + >> + return ACTION_IDLE; > > Does it need this? I guess it's the reason in case there are other > situations, right? Yes, we need this, because they are many places to set MD_RECOVERY_NEEDED, while there are no sync action actually, this case is 'idle'. Thanks, Kuai > > Regards > Xiao > >> +} >> + >> +enum sync_action md_sync_action_by_name(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; >> +} >> + >> +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 2edad966f90a..72ca7a796df5 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(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); >> extern void md_write_end(struct mddev *mddev); >> -- >> 2.39.2 >> > > . >