Received: by 2002:a05:7412:bc1a:b0:d7:7d3a:4fe2 with SMTP id ki26csp719090rdb; Sat, 19 Aug 2023 22:59:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFhIZuaizDqaCFpGSQVcNhgcyJ6LO8nCn7ac3ZnW0KnGjYBvpgnyl3l6fs+3YbxOoWRy0VG X-Received: by 2002:a05:6a20:1453:b0:131:5b6f:ccb6 with SMTP id a19-20020a056a20145300b001315b6fccb6mr5496489pzi.19.1692511163993; Sat, 19 Aug 2023 22:59:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692511163; cv=none; d=google.com; s=arc-20160816; b=uaZ+d2Z6DEwWbbC5ZinZfQPRc1nBjxeSMdf83BEAhLh3xxkp6Ai4+8FdhciD6GF6yw /uPblr/+O4Ek2IAx32KNuYJZIjPd4M6ro9S5Xg5B3dvIWKjWAjJsvrFEaLdQHVthQ36E CCkT1XWbPQ4a+Leic4pqbL7lZZ5i0O9yOO71bB91zGhSxFr28dJZcOruzjcKsNoPBNXe LOmX3MH1TyVdHev78JDJiTgqTXLgQxsM/StnZok4Wbn6iBrK/T0hGOc9W88vj+5CxNZn FKXA2dplmrom0dh0iGUMf83fubRs6ZKFdvn3AApev6e/A0PYGX7r2Vc4lJkVCAbKCd2Y wsUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:references:cc:to :subject; bh=3eJzerD5hntNnppnT8igUh6uxw2fYFETqGMhpZNChM4=; fh=hnbNByNE88FqKwogCfJk1qi+meUNWTNOKA7EZjg8CA8=; b=lQ5V3WZBr+bICOzoPV3qjG24/vgm3b/Dky/J+5IzTRLCE8e/Z5Iimg/k3uinpTwOdO loAi7AstVcmraK/Hx96JnRvEvpHwgcRKLKdP6fktE67z82v5PSERf9cPLz1tUNgGCHZ1 W0mnuTdsH9r2SotXIXmnWoTjsew43HoRdKphy4wMiQ9YYoq647j+AXOAQ2dtraj8Br9a hJxpQpcyhJcjSpoYU/xnLTNh5AQ+hRpBm7yDVpsPLFVy65gHsPuCAC7UPjdeeuEjKChW V7nl0loD6K6wCb1OH8dXLEfK66mIJyGxMpw8yYcpzCTKOxMgByaA+Ya68pzyWY41WRNk Lawg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n2-20020a056a00212200b0068a3ff442c2si654632pfj.2.2023.08.19.22.59.11; Sat, 19 Aug 2023 22:59:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229726AbjHTCrG (ORCPT + 99 others); Sat, 19 Aug 2023 22:47:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229971AbjHTCqx (ORCPT ); Sat, 19 Aug 2023 22:46:53 -0400 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D4E349320; Sat, 19 Aug 2023 19:20:00 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.169]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4RSzpK405Qz4f3mJ0; Sun, 20 Aug 2023 10:19:53 +0800 (CST) Received: from [10.174.176.73] (unknown [10.174.176.73]) by APP4 (Coremail) with SMTP id gCh0CgBH1qhJeOFkadqDBA--.18182S3; Sun, 20 Aug 2023 10:19:54 +0800 (CST) Subject: Re: [PATCH -next v2 7/7] md: delay remove_and_add_spares() for read only array to md_start_sync() To: Xiao Ni , Yu Kuai Cc: song@kernel.org, linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com, "yukuai (C)" References: <20230815030957.509535-1-yukuai1@huaweicloud.com> <20230815030957.509535-8-yukuai1@huaweicloud.com> From: Yu Kuai Message-ID: Date: Sun, 20 Aug 2023 10:19:52 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-CM-TRANSID: gCh0CgBH1qhJeOFkadqDBA--.18182S3 X-Coremail-Antispam: 1UD129KBjvJXoWxJF4fuF4kuF4UJr1UXry5urg_yoWrXrWDpr WxAFn0krWUX34xXr12gF1DWa4rtr10qrZFkry3ua4xZwnIyrn7G34rWayUWry5Aa4S9a10 va18tFZxuF1rCFJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUkE14x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26F1j6w1UM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4U JVWxJr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Gc CE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E 2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJV W8JwACjcxG0xvEwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lc7I2V7IY0VAS07AlzVAY IcxG8wCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14 v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkG c2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI 0_Jr0_Gr1lIxAIcVCF04k26cxKx2IYs7xG6rWUJVWrZr1UMIIF0xvEx4A2jsIE14v26r1j 6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUdHU DUUUUU= X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-3.8 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, 在 2023/08/16 15:18, Xiao Ni 写道: > On Tue, Aug 15, 2023 at 11:13 AM Yu Kuai wrote: >> >> From: Yu Kuai >> >> Before this patch, for read-only array: >> >> md_check_recovery() check that 'MD_RECOVERY_NEEDED' is set, then it will >> call remove_and_add_spares() directly to try to remove and add rdevs >> from array. >> >> After this patch: >> >> 1) md_check_recovery() check that 'MD_RECOVERY_NEEDED' is set, and the >> worker 'sync_work' is not pending, and there are rdevs can be added >> or removed, then it will queue new work md_start_sync(); >> 2) md_start_sync() will call remove_and_add_spares() and exist; > > Hi Kuai > > If md_check_recovery returns and md_starts_sync doesn't start, during > the window the raid changes to read-write, the sync thread can be run > but MD_RECOVERY_RUNNING isn't set. Is there such a problem? That's a good question, looks like this is possible. Read-only array doesn't test or set MD_RECOVERY_RUNNING at all in md_check_recovery(). I'll use MD_RECOVERY_RUNNING to prevent such concurrent scenario in the new version. Thanks, Kuai > > Regards > Xiao > >> >> This change make sure that array reconfiguration is independent from >> daemon, and it'll be much easier to synchronize it with io, consier >> that io may rely on daemon thread to be done. >> >> Signed-off-by: Yu Kuai >> --- >> drivers/md/md.c | 37 +++++++++++++++++++++++++++---------- >> 1 file changed, 27 insertions(+), 10 deletions(-) >> >> diff --git a/drivers/md/md.c b/drivers/md/md.c >> index d26d2c35f9af..74d529479fcf 100644 >> --- a/drivers/md/md.c >> +++ b/drivers/md/md.c >> @@ -9191,6 +9191,16 @@ static bool rdev_addable(struct md_rdev *rdev) >> return true; >> } >> >> +static bool md_spares_need_change(struct mddev *mddev) >> +{ >> + struct md_rdev *rdev; >> + >> + rdev_for_each(rdev, mddev) >> + if (rdev_removeable(rdev) || rdev_addable(rdev)) >> + return true; >> + return false; >> +} >> + >> static int remove_and_add_spares(struct mddev *mddev, >> struct md_rdev *this) >> { >> @@ -9309,6 +9319,12 @@ static void md_start_sync(struct work_struct *ws) >> >> mddev_lock_nointr(mddev); >> >> + if (!md_is_rdwr(mddev)) { >> + remove_and_add_spares(mddev, NULL); >> + mddev_unlock(mddev); >> + return; >> + } >> + >> if (!md_choose_sync_direction(mddev, &spares)) >> goto not_running; >> >> @@ -9403,7 +9419,8 @@ void md_check_recovery(struct mddev *mddev) >> } >> >> if (!md_is_rdwr(mddev) && >> - !test_bit(MD_RECOVERY_NEEDED, &mddev->recovery)) >> + (!test_bit(MD_RECOVERY_NEEDED, &mddev->recovery) || >> + work_pending(&mddev->sync_work))) >> return; >> if ( ! ( >> (mddev->sb_flags & ~ (1<> @@ -9431,15 +9448,8 @@ void md_check_recovery(struct mddev *mddev) >> */ >> rdev_for_each(rdev, mddev) >> clear_bit(Blocked, &rdev->flags); >> - /* On a read-only array we can: >> - * - remove failed devices >> - * - add already-in_sync devices if the array itself >> - * is in-sync. >> - * As we only add devices that are already in-sync, >> - * we can activate the spares immediately. >> - */ >> - remove_and_add_spares(mddev, NULL); >> - /* There is no thread, but we need to call >> + /* >> + * There is no thread, but we need to call >> * ->spare_active and clear saved_raid_disk >> */ >> set_bit(MD_RECOVERY_INTR, &mddev->recovery); >> @@ -9447,6 +9457,13 @@ void md_check_recovery(struct mddev *mddev) >> clear_bit(MD_RECOVERY_RECOVER, &mddev->recovery); >> clear_bit(MD_RECOVERY_NEEDED, &mddev->recovery); >> clear_bit(MD_SB_CHANGE_PENDING, &mddev->sb_flags); >> + >> + /* >> + * Let md_start_sync() to remove and add rdevs to the >> + * array. >> + */ >> + if (md_spares_need_change(mddev)) >> + queue_work(md_misc_wq, &mddev->sync_work); >> goto unlock; >> } >> >> -- >> 2.39.2 >> > > . >