Message ID | 20230820090949.2874537-7-yukuai1@huaweicloud.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b82d:0:b0:3f2:4152:657d with SMTP id z13csp2420755vqi; Sun, 20 Aug 2023 03:57:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGaf0dJOhpmwWj26K4XltLmICY2odquyc3eitwyjo5tpVK6GTOAGRn1fBZmplzWFwuJctQY X-Received: by 2002:a05:6a00:24d2:b0:687:5c3f:d834 with SMTP id d18-20020a056a0024d200b006875c3fd834mr5911114pfv.11.1692529065846; Sun, 20 Aug 2023 03:57:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692529065; cv=none; d=google.com; s=arc-20160816; b=lmKWFBNA+a6Trj65T2InKSOYPl0WT5UBGBDj9UimWjapAs8NfBfTHC8ev5N/99Wbjj rR0B40I9Dr4zrDlOYmaKki07TaakXmZ4PqRwbLzvikoKYO6ci5Z5eSIVpMDvFoOO6v5e Iuh3GKEUcYQ4ZIOswRoMYOUY5nXMHMbv45xh6ld38aAoF+1WYUzsP8xnOMAZ32vqEo5f gqFk53gzOJ0Tt6LhjP71sRmQtuVFHgZ1a9lmqdla0Yck114+RI33BF7SaXMniT/guEl2 94GcIDXKfIC5uB6kG3pEkWgr6I4SKFMiVMacHvgSmu8/BOjN4CaRswXBRj1fCHQoDdYF nYCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=bAQuND7JbNvBM9xnEYWkUwFjKtvhuu/GY+tGia9XJp4=; fh=wYpPkfz5NmnUk5+Qk0ITITcjVIikaKAb2203DIB6KT8=; b=VioKEqXBsnwz5qQ/MeEMlCznY3xk1DXpca4GiWvY2xvgnT4gVav4HR3jFHURV7yHMW gz7pM4tT9SACit5yUvdIgOQANJamlkBy+9yf4SNNTbJqvmNE0JR2smjAUTj8ULjhWGHU /oeR3hzWyX2pxgStX/91DSwNn0blzYon/atCNwZVdLoAcem0m/qETby5Vr10YwtMCbos mLWHRF2NmMVRb0ps8ELbe72oMM1tYgpjTLTeAlm+Ug7coRUDzWRHsWIdqnj3LzeZjpVi Z/96qlXXaAvyol3oHuX93fqEkGGrG11WslHPOZyoowrOPtJMXgoIwDaduMCuX4r17Ln/ hhIg== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t8-20020a056a00138800b006884632d5a0si5225221pfg.297.2023.08.20.03.57.32; Sun, 20 Aug 2023 03:57:45 -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 S230261AbjHTJRL (ORCPT <rfc822;274620705z@gmail.com> + 99 others); Sun, 20 Aug 2023 05:17:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230209AbjHTJRH (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sun, 20 Aug 2023 05:17:07 -0400 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC5F249FE; Sun, 20 Aug 2023 02:13:51 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.169]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4RT8zw27Mbz4f3jqB; Sun, 20 Aug 2023 17:13:48 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP4 (Coremail) with SMTP id gCh0CgAnBahH2eFkmXibBA--.44158S10; Sun, 20 Aug 2023 17:13:48 +0800 (CST) From: Yu Kuai <yukuai1@huaweicloud.com> To: song@kernel.org, xni@redhat.com, mariusz.tkaczyk@linux.intel.com Cc: linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org, yukuai3@huawei.com, yukuai1@huaweicloud.com, yi.zhang@huawei.com, yangerkun@huawei.com Subject: [PATCH -next v3 6/7] md: factor out a helper rdev_addable() from remove_and_add_spares() Date: Sun, 20 Aug 2023 17:09:48 +0800 Message-Id: <20230820090949.2874537-7-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230820090949.2874537-1-yukuai1@huaweicloud.com> References: <20230820090949.2874537-1-yukuai1@huaweicloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: gCh0CgAnBahH2eFkmXibBA--.44158S10 X-Coremail-Antispam: 1UD129KBjvJXoW7Kr47Kr4xtr13KF4ftr13Jwb_yoW8Ary8pa yrKFy3K3yUAF13W3WDKryUGa4Yqa10grWIkry2ka4rXas8Jrn8Kw4rCF90qF98JFZY9F45 ZF15tw48ur1agFUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUU9K14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCF04k20xvY0x0EwIxGrw CFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE 14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2 IY67AKxVWUCVW8JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Cr0_Gr1UMIIF0xvE42xK8VAv wI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8JVWxJwCI42IY6I8E87Iv6xkF7I0E14 v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjfUOBTYUUUUU X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1774745357460943497 X-GMAIL-MSGID: 1774745357460943497 |
Series |
md: make rdev addition and removal independent from daemon thread
|
|
Commit Message
Yu Kuai
Aug. 20, 2023, 9:09 a.m. UTC
From: Yu Kuai <yukuai3@huawei.com> There are no functional changes, just to make the code simpler and prepare to delay remove_and_add_spares() to md_start_sync(). Signed-off-by: Yu Kuai <yukuai3@huawei.com> --- drivers/md/md.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-)
Comments
On Sun, Aug 20, 2023 at 2:13 AM Yu Kuai <yukuai1@huaweicloud.com> wrote: > > From: Yu Kuai <yukuai3@huawei.com> > > There are no functional changes, just to make the code simpler and > prepare to delay remove_and_add_spares() to md_start_sync(). > > Signed-off-by: Yu Kuai <yukuai3@huawei.com> > --- > drivers/md/md.c | 28 ++++++++++++++++------------ > 1 file changed, 16 insertions(+), 12 deletions(-) > > diff --git a/drivers/md/md.c b/drivers/md/md.c > index 11d27c934fdd..cdc361c521d4 100644 > --- a/drivers/md/md.c > +++ b/drivers/md/md.c > @@ -9177,6 +9177,20 @@ static bool rdev_is_spare(struct md_rdev *rdev) > !test_bit(Faulty, &rdev->flags); > } > > +static bool rdev_addable(struct md_rdev *rdev) > +{ > + if (test_bit(Candidate, &rdev->flags) || rdev->raid_disk >= 0 || > + test_bit(Faulty, &rdev->flags)) > + return false; > + > + if (!test_bit(Journal, &rdev->flags) && !md_is_rdwr(rdev->mddev) && Instead of straightforward refactoring, I hope we can make these rdev_* helpers more meaningful, and hopefullly reusable. For example, let's define the meaning of "addable", and write the function to match that meaning. In this case, I think we shouldn't check md_is_rdwr() inside rdev_addable(). Does this make sense? Thanks, Song > + !(rdev->saved_raid_disk >= 0 && > + !test_bit(Bitmap_sync, &rdev->flags))) > + return false; > + > + return true; > +} > + > static int remove_and_add_spares(struct mddev *mddev, > struct md_rdev *this) > { > @@ -9227,20 +9241,10 @@ static int remove_and_add_spares(struct mddev *mddev, > continue; > if (rdev_is_spare(rdev)) > spares++; > - if (test_bit(Candidate, &rdev->flags)) > + if (!rdev_addable(rdev)) > continue; > - if (rdev->raid_disk >= 0) > - continue; > - if (test_bit(Faulty, &rdev->flags)) > - continue; > - if (!test_bit(Journal, &rdev->flags)) { > - if (!md_is_rdwr(mddev) && > - !(rdev->saved_raid_disk >= 0 && > - !test_bit(Bitmap_sync, &rdev->flags))) > - continue; > - > + if (!test_bit(Journal, &rdev->flags)) > rdev->recovery_offset = 0; > - } > if (mddev->pers->hot_add_disk(mddev, rdev) == 0) { > /* failure here is OK */ > sysfs_link_rdev(mddev, rdev); > -- > 2.39.2 >
Hi, 在 2023/08/22 7:22, Song Liu 写道: > On Sun, Aug 20, 2023 at 2:13 AM Yu Kuai <yukuai1@huaweicloud.com> wrote: >> >> From: Yu Kuai <yukuai3@huawei.com> >> >> There are no functional changes, just to make the code simpler and >> prepare to delay remove_and_add_spares() to md_start_sync(). >> >> Signed-off-by: Yu Kuai <yukuai3@huawei.com> >> --- >> drivers/md/md.c | 28 ++++++++++++++++------------ >> 1 file changed, 16 insertions(+), 12 deletions(-) >> >> diff --git a/drivers/md/md.c b/drivers/md/md.c >> index 11d27c934fdd..cdc361c521d4 100644 >> --- a/drivers/md/md.c >> +++ b/drivers/md/md.c >> @@ -9177,6 +9177,20 @@ static bool rdev_is_spare(struct md_rdev *rdev) >> !test_bit(Faulty, &rdev->flags); >> } >> >> +static bool rdev_addable(struct md_rdev *rdev) >> +{ >> + if (test_bit(Candidate, &rdev->flags) || rdev->raid_disk >= 0 || >> + test_bit(Faulty, &rdev->flags)) >> + return false; >> + >> + if (!test_bit(Journal, &rdev->flags) && !md_is_rdwr(rdev->mddev) && > > Instead of straightforward refactoring, I hope we can make these rdev_* > helpers more meaningful, and hopefullly reusable. For example, let's define > the meaning of "addable", and write the function to match that meaning. In > this case, I think we shouldn't check md_is_rdwr() inside rdev_addable(). > > Does this make sense? Yes, this make sense, rdev can be added to read-only array. There are total three callers of pers->hot_add_sisk, I'll try to find if they have common conditions. Thanks, Kuai > > Thanks, > Song > > >> + !(rdev->saved_raid_disk >= 0 && >> + !test_bit(Bitmap_sync, &rdev->flags))) >> + return false; >> + >> + return true; >> +} >> + >> static int remove_and_add_spares(struct mddev *mddev, >> struct md_rdev *this) >> { >> @@ -9227,20 +9241,10 @@ static int remove_and_add_spares(struct mddev *mddev, >> continue; >> if (rdev_is_spare(rdev)) >> spares++; >> - if (test_bit(Candidate, &rdev->flags)) >> + if (!rdev_addable(rdev)) >> continue; >> - if (rdev->raid_disk >= 0) >> - continue; >> - if (test_bit(Faulty, &rdev->flags)) >> - continue; >> - if (!test_bit(Journal, &rdev->flags)) { >> - if (!md_is_rdwr(mddev) && >> - !(rdev->saved_raid_disk >= 0 && >> - !test_bit(Bitmap_sync, &rdev->flags))) >> - continue; >> - >> + if (!test_bit(Journal, &rdev->flags)) >> rdev->recovery_offset = 0; >> - } >> if (mddev->pers->hot_add_disk(mddev, rdev) == 0) { >> /* failure here is OK */ >> sysfs_link_rdev(mddev, rdev); >> -- >> 2.39.2 >> > . >
Hi, 在 2023/08/22 10:17, Yu Kuai 写道: > Hi, > > 在 2023/08/22 7:22, Song Liu 写道: >> On Sun, Aug 20, 2023 at 2:13 AM Yu Kuai <yukuai1@huaweicloud.com> wrote: >>> >>> From: Yu Kuai <yukuai3@huawei.com> >>> >>> There are no functional changes, just to make the code simpler and >>> prepare to delay remove_and_add_spares() to md_start_sync(). >>> >>> Signed-off-by: Yu Kuai <yukuai3@huawei.com> >>> --- >>> drivers/md/md.c | 28 ++++++++++++++++------------ >>> 1 file changed, 16 insertions(+), 12 deletions(-) >>> >>> diff --git a/drivers/md/md.c b/drivers/md/md.c >>> index 11d27c934fdd..cdc361c521d4 100644 >>> --- a/drivers/md/md.c >>> +++ b/drivers/md/md.c >>> @@ -9177,6 +9177,20 @@ static bool rdev_is_spare(struct md_rdev *rdev) >>> !test_bit(Faulty, &rdev->flags); >>> } >>> >>> +static bool rdev_addable(struct md_rdev *rdev) >>> +{ >>> + if (test_bit(Candidate, &rdev->flags) || rdev->raid_disk >= 0 || >>> + test_bit(Faulty, &rdev->flags)) >>> + return false; >>> + >>> + if (!test_bit(Journal, &rdev->flags) && >>> !md_is_rdwr(rdev->mddev) && >> >> Instead of straightforward refactoring, I hope we can make these rdev_* >> helpers more meaningful, and hopefullly reusable. For example, let's >> define >> the meaning of "addable", and write the function to match that >> meaning. In >> this case, I think we shouldn't check md_is_rdwr() inside rdev_addable(). >> >> Does this make sense? > > Yes, this make sense, rdev can be added to read-only array. > > There are total three callers of pers->hot_add_sisk, I'll try to find if > they have common conditions. Unfortunately, the conditions is quite different, and It's difficult to factor out a common helper for them to use. In this case, !md_is_rdwr() is one of the four conditions, which means if the array is read-only, there is a special case that rdev can't be added to the configuration. Perhaps it's okay to keep this? Thanks, Kuai > > Thanks, > Kuai > >> >> Thanks, >> Song >> >> >>> + !(rdev->saved_raid_disk >= 0 && >>> + !test_bit(Bitmap_sync, &rdev->flags))) >>> + return false; >>> + >>> + return true; >>> +} >>> + >>> static int remove_and_add_spares(struct mddev *mddev, >>> struct md_rdev *this) >>> { >>> @@ -9227,20 +9241,10 @@ static int remove_and_add_spares(struct mddev >>> *mddev, >>> continue; >>> if (rdev_is_spare(rdev)) >>> spares++; >>> - if (test_bit(Candidate, &rdev->flags)) >>> + if (!rdev_addable(rdev)) >>> continue; >>> - if (rdev->raid_disk >= 0) >>> - continue; >>> - if (test_bit(Faulty, &rdev->flags)) >>> - continue; >>> - if (!test_bit(Journal, &rdev->flags)) { >>> - if (!md_is_rdwr(mddev) && >>> - !(rdev->saved_raid_disk >= 0 && >>> - !test_bit(Bitmap_sync, &rdev->flags))) >>> - continue; >>> - >>> + if (!test_bit(Journal, &rdev->flags)) >>> rdev->recovery_offset = 0; >>> - } >>> if (mddev->pers->hot_add_disk(mddev, rdev) == 0) { >>> /* failure here is OK */ >>> sysfs_link_rdev(mddev, rdev); >>> -- >>> 2.39.2 >>> >> . >> > > . >
On Tue, Aug 22, 2023 at 8:04 PM Yu Kuai <yukuai1@huaweicloud.com> wrote: > > Hi, > > 在 2023/08/22 10:17, Yu Kuai 写道: > > Hi, > > > > 在 2023/08/22 7:22, Song Liu 写道: > >> On Sun, Aug 20, 2023 at 2:13 AM Yu Kuai <yukuai1@huaweicloud.com> wrote: > >>> > >>> From: Yu Kuai <yukuai3@huawei.com> > >>> > >>> There are no functional changes, just to make the code simpler and > >>> prepare to delay remove_and_add_spares() to md_start_sync(). > >>> > >>> Signed-off-by: Yu Kuai <yukuai3@huawei.com> > >>> --- > >>> drivers/md/md.c | 28 ++++++++++++++++------------ > >>> 1 file changed, 16 insertions(+), 12 deletions(-) > >>> > >>> diff --git a/drivers/md/md.c b/drivers/md/md.c > >>> index 11d27c934fdd..cdc361c521d4 100644 > >>> --- a/drivers/md/md.c > >>> +++ b/drivers/md/md.c > >>> @@ -9177,6 +9177,20 @@ static bool rdev_is_spare(struct md_rdev *rdev) > >>> !test_bit(Faulty, &rdev->flags); > >>> } > >>> > >>> +static bool rdev_addable(struct md_rdev *rdev) > >>> +{ > >>> + if (test_bit(Candidate, &rdev->flags) || rdev->raid_disk >= 0 || > >>> + test_bit(Faulty, &rdev->flags)) > >>> + return false; > >>> + > >>> + if (!test_bit(Journal, &rdev->flags) && > >>> !md_is_rdwr(rdev->mddev) && > >> > >> Instead of straightforward refactoring, I hope we can make these rdev_* > >> helpers more meaningful, and hopefullly reusable. For example, let's > >> define > >> the meaning of "addable", and write the function to match that > >> meaning. In > >> this case, I think we shouldn't check md_is_rdwr() inside rdev_addable(). > >> > >> Does this make sense? > > > > Yes, this make sense, rdev can be added to read-only array. > > > > There are total three callers of pers->hot_add_sisk, I'll try to find if > > they have common conditions. > > Unfortunately, the conditions is quite different, and It's difficult to > factor out a common helper for them to use. > > In this case, !md_is_rdwr() is one of the four conditions, which means > if the array is read-only, there is a special case that rdev can't be > added to the configuration. Perhaps it's okay to keep this? My main concern is that rdev_addable() is not making the code easier to understand. We have a few different cases at this point: 1. rdev is not suitable for add (Faulty, raid_disk>=0, Candidate); 2. rdev is Journal; 3. Re-add rdev to RO array; 4. Non-re-add rdev to RO array; 5. Other cases. Current rdev_addable() handles more or less all of this, which is confusing. Maybe we can do something along similar to the following (not tested). Does this look more clear? Thanks, Song diff --git i/drivers/md/md.c w/drivers/md/md.c index 78be7811a89f..8cb855d03e0a 100644 --- i/drivers/md/md.c +++ w/drivers/md/md.c @@ -9117,6 +9117,20 @@ void md_do_sync(struct md_thread *thread) } EXPORT_SYMBOL_GPL(md_do_sync); +static bool rdev_addable(struct md_rdev *rdev) +{ + if (test_bit(Candidate, &rdev->flags) || rdev->raid_disk >= 0 || + test_bit(Faulty, &rdev->flags)) + return false; + return true; +} + +static bool rdev_is_readd(struct md_rdev *rdev) +{ + return rdev->saved_raid_disk >= 0 || + !test_bit(Bitmap_sync, &rdev->flags); +} + static int remove_and_add_spares(struct mddev *mddev, struct md_rdev *this) { @@ -9176,25 +9190,24 @@ static int remove_and_add_spares(struct mddev *mddev, rdev_for_each(rdev, mddev) { if (this && this != rdev) continue; - if (test_bit(Candidate, &rdev->flags)) - continue; if (rdev->raid_disk >= 0 && !test_bit(In_sync, &rdev->flags) && !test_bit(Journal, &rdev->flags) && !test_bit(Faulty, &rdev->flags)) spares++; - if (rdev->raid_disk >= 0) + + if (!rdev_addable(rdev)) continue; - if (test_bit(Faulty, &rdev->flags)) + + if (test_bit(Journal, &rdev->flags)) + goto hot_add_disk; + + if (!md_is_rdwr(mddev) && !rdev_is_readd(rdev)) continue; - if (!test_bit(Journal, &rdev->flags)) { - if (!md_is_rdwr(mddev) && - !(rdev->saved_raid_disk >= 0 && - !test_bit(Bitmap_sync, &rdev->flags))) - continue; - rdev->recovery_offset = 0; - } + rdev->recovery_offset = 0; + + hot_add_disk: if (mddev->pers->hot_add_disk(mddev, rdev) == 0) { /* failure here is OK */ sysfs_link_rdev(mddev, rdev);
Hi, 在 2023/08/23 13:26, Song Liu 写道: > On Tue, Aug 22, 2023 at 8:04 PM Yu Kuai <yukuai1@huaweicloud.com> wrote: >> >> Hi, >> >> 在 2023/08/22 10:17, Yu Kuai 写道: >>> Hi, >>> >>> 在 2023/08/22 7:22, Song Liu 写道: >>>> On Sun, Aug 20, 2023 at 2:13 AM Yu Kuai <yukuai1@huaweicloud.com> wrote: >>>>> >>>>> From: Yu Kuai <yukuai3@huawei.com> >>>>> >>>>> There are no functional changes, just to make the code simpler and >>>>> prepare to delay remove_and_add_spares() to md_start_sync(). >>>>> >>>>> Signed-off-by: Yu Kuai <yukuai3@huawei.com> >>>>> --- >>>>> drivers/md/md.c | 28 ++++++++++++++++------------ >>>>> 1 file changed, 16 insertions(+), 12 deletions(-) >>>>> >>>>> diff --git a/drivers/md/md.c b/drivers/md/md.c >>>>> index 11d27c934fdd..cdc361c521d4 100644 >>>>> --- a/drivers/md/md.c >>>>> +++ b/drivers/md/md.c >>>>> @@ -9177,6 +9177,20 @@ static bool rdev_is_spare(struct md_rdev *rdev) >>>>> !test_bit(Faulty, &rdev->flags); >>>>> } >>>>> >>>>> +static bool rdev_addable(struct md_rdev *rdev) >>>>> +{ >>>>> + if (test_bit(Candidate, &rdev->flags) || rdev->raid_disk >= 0 || >>>>> + test_bit(Faulty, &rdev->flags)) >>>>> + return false; >>>>> + >>>>> + if (!test_bit(Journal, &rdev->flags) && >>>>> !md_is_rdwr(rdev->mddev) && >>>> >>>> Instead of straightforward refactoring, I hope we can make these rdev_* >>>> helpers more meaningful, and hopefullly reusable. For example, let's >>>> define >>>> the meaning of "addable", and write the function to match that >>>> meaning. In >>>> this case, I think we shouldn't check md_is_rdwr() inside rdev_addable(). >>>> >>>> Does this make sense? >>> >>> Yes, this make sense, rdev can be added to read-only array. >>> >>> There are total three callers of pers->hot_add_sisk, I'll try to find if >>> they have common conditions. >> >> Unfortunately, the conditions is quite different, and It's difficult to >> factor out a common helper for them to use. >> >> In this case, !md_is_rdwr() is one of the four conditions, which means >> if the array is read-only, there is a special case that rdev can't be >> added to the configuration. Perhaps it's okay to keep this? > > My main concern is that rdev_addable() is not making the code easier to > understand. We have a few different cases at this point: > > 1. rdev is not suitable for add (Faulty, raid_disk>=0, Candidate); > 2. rdev is Journal; > 3. Re-add rdev to RO array; > 4. Non-re-add rdev to RO array; > 5. Other cases. > > Current rdev_addable() handles more or less all of this, which is > confusing. Maybe we can do something along similar to the > following (not tested). Does this look more clear? > > Thanks, > Song > > diff --git i/drivers/md/md.c w/drivers/md/md.c > index 78be7811a89f..8cb855d03e0a 100644 > --- i/drivers/md/md.c > +++ w/drivers/md/md.c > @@ -9117,6 +9117,20 @@ void md_do_sync(struct md_thread *thread) > } > EXPORT_SYMBOL_GPL(md_do_sync); > > +static bool rdev_addable(struct md_rdev *rdev) > +{ > + if (test_bit(Candidate, &rdev->flags) || rdev->raid_disk >= 0 || > + test_bit(Faulty, &rdev->flags)) > + return false; > + return true; > +} > + > +static bool rdev_is_readd(struct md_rdev *rdev) > +{ > + return rdev->saved_raid_disk >= 0 || > + !test_bit(Bitmap_sync, &rdev->flags); This should use '&&' instead of '||' ? > +} > + > static int remove_and_add_spares(struct mddev *mddev, > struct md_rdev *this) > { > @@ -9176,25 +9190,24 @@ static int remove_and_add_spares(struct mddev *mddev, > rdev_for_each(rdev, mddev) { > if (this && this != rdev) > continue; > - if (test_bit(Candidate, &rdev->flags)) > - continue; > if (rdev->raid_disk >= 0 && > !test_bit(In_sync, &rdev->flags) && > !test_bit(Journal, &rdev->flags) && > !test_bit(Faulty, &rdev->flags)) > spares++; > - if (rdev->raid_disk >= 0) > + > + if (!rdev_addable(rdev)) > continue; > - if (test_bit(Faulty, &rdev->flags)) > + > + if (test_bit(Journal, &rdev->flags)) > + goto hot_add_disk; > + I understand what you mean now, but I must use the exact same judgement in the new helper md_spares_need_change() in patch 7, there will be redundant code this way. How about this, rework rdev_addable(): static bool rdev_addable(struct md_rdev *rdev) { + /* rdev is already used, don't add it again. */ if (test_bit(Candidate, &rdev->flags) || rdev->raid_disk >= 0 || test_bit(Faulty, &rdev->flags)) return false; ~ /* Allow to add journal disk. */ ~ if (test_bit(Journal, &rdev->flags)) ~_ return true; ~ /* Allow to add if array is read-write. */ + if (md_is_rdwr(rdev->mddev)) + return true; + + /* + * For read-only array, only allow to readd a rdev. And if bitmap is + * used, don't allow to readd a rdev that is too old. + */ + if (rdev->saved_raid_disk >=0 && !test_bit(Bitmap_sync, &rdev->flags)) + return true; + + return false; } Thanks, Kuai > + if (!md_is_rdwr(mddev) && !rdev_is_readd(rdev)) > continue; > - if (!test_bit(Journal, &rdev->flags)) { > - if (!md_is_rdwr(mddev) && > - !(rdev->saved_raid_disk >= 0 && > - !test_bit(Bitmap_sync, &rdev->flags))) > - continue; > > - rdev->recovery_offset = 0; > - } > + rdev->recovery_offset = 0; > + > + hot_add_disk: > if (mddev->pers->hot_add_disk(mddev, rdev) == 0) { > /* failure here is OK */ > sysfs_link_rdev(mddev, rdev); > . >
On Wed, Aug 23, 2023 at 1:37 AM Yu Kuai <yukuai1@huaweicloud.com> wrote: > [...] > > diff --git i/drivers/md/md.c w/drivers/md/md.c > > index 78be7811a89f..8cb855d03e0a 100644 > > --- i/drivers/md/md.c > > +++ w/drivers/md/md.c > > @@ -9117,6 +9117,20 @@ void md_do_sync(struct md_thread *thread) > > } > > EXPORT_SYMBOL_GPL(md_do_sync); > > > > +static bool rdev_addable(struct md_rdev *rdev) > > +{ > > + if (test_bit(Candidate, &rdev->flags) || rdev->raid_disk >= 0 || > > + test_bit(Faulty, &rdev->flags)) > > + return false; > > + return true; > > +} > > + > > +static bool rdev_is_readd(struct md_rdev *rdev) > > +{ > > + return rdev->saved_raid_disk >= 0 || > > + !test_bit(Bitmap_sync, &rdev->flags); > This should use '&&' instead of '||' ? > > > +} > > + > > static int remove_and_add_spares(struct mddev *mddev, > > struct md_rdev *this) > > { > > @@ -9176,25 +9190,24 @@ static int remove_and_add_spares(struct mddev *mddev, > > rdev_for_each(rdev, mddev) { > > if (this && this != rdev) > > continue; > > - if (test_bit(Candidate, &rdev->flags)) > > - continue; > > if (rdev->raid_disk >= 0 && > > !test_bit(In_sync, &rdev->flags) && > > !test_bit(Journal, &rdev->flags) && > > !test_bit(Faulty, &rdev->flags)) > > spares++; > > - if (rdev->raid_disk >= 0) > > + > > + if (!rdev_addable(rdev)) > > continue; > > - if (test_bit(Faulty, &rdev->flags)) > > + > > + if (test_bit(Journal, &rdev->flags)) > > + goto hot_add_disk; > > + > > I understand what you mean now, but I must use the exact same judgement > in the new helper md_spares_need_change() in patch 7, there will be > redundant code this way. > > How about this, rework rdev_addable(): Yeah, this was another option that I was thinking about. Let's go with this version. Thanks, Song > > static bool rdev_addable(struct md_rdev *rdev) > { > + /* rdev is already used, don't add it again. */ > if (test_bit(Candidate, &rdev->flags) || rdev->raid_disk >= 0 || > test_bit(Faulty, &rdev->flags)) > return false; > > ~ /* Allow to add journal disk. */ > ~ if (test_bit(Journal, &rdev->flags)) > ~_ return true; > > ~ /* Allow to add if array is read-write. */ > + if (md_is_rdwr(rdev->mddev)) > + return true; > + > + /* > + * For read-only array, only allow to readd a rdev. And if > bitmap is > + * used, don't allow to readd a rdev that is too old. > + */ > + if (rdev->saved_raid_disk >=0 && !test_bit(Bitmap_sync, > &rdev->flags)) > + return true; > + > + return false; > }
diff --git a/drivers/md/md.c b/drivers/md/md.c index 11d27c934fdd..cdc361c521d4 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -9177,6 +9177,20 @@ static bool rdev_is_spare(struct md_rdev *rdev) !test_bit(Faulty, &rdev->flags); } +static bool rdev_addable(struct md_rdev *rdev) +{ + if (test_bit(Candidate, &rdev->flags) || rdev->raid_disk >= 0 || + test_bit(Faulty, &rdev->flags)) + return false; + + if (!test_bit(Journal, &rdev->flags) && !md_is_rdwr(rdev->mddev) && + !(rdev->saved_raid_disk >= 0 && + !test_bit(Bitmap_sync, &rdev->flags))) + return false; + + return true; +} + static int remove_and_add_spares(struct mddev *mddev, struct md_rdev *this) { @@ -9227,20 +9241,10 @@ static int remove_and_add_spares(struct mddev *mddev, continue; if (rdev_is_spare(rdev)) spares++; - if (test_bit(Candidate, &rdev->flags)) + if (!rdev_addable(rdev)) continue; - if (rdev->raid_disk >= 0) - continue; - if (test_bit(Faulty, &rdev->flags)) - continue; - if (!test_bit(Journal, &rdev->flags)) { - if (!md_is_rdwr(mddev) && - !(rdev->saved_raid_disk >= 0 && - !test_bit(Bitmap_sync, &rdev->flags))) - continue; - + if (!test_bit(Journal, &rdev->flags)) rdev->recovery_offset = 0; - } if (mddev->pers->hot_add_disk(mddev, rdev) == 0) { /* failure here is OK */ sysfs_link_rdev(mddev, rdev);