Message ID | 20231211081714.1923567-1-linan666@huaweicloud.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp6898972vqy; Mon, 11 Dec 2023 00:18:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IF9z6d+pZ13RvJqGRwgzRgjIyfUpaZfm+Fqd6WC0+lWllTZ/SH+PaVCIZd0UlbnbcoWDDOx X-Received: by 2002:a05:6e02:15c5:b0:35d:5995:1d62 with SMTP id q5-20020a056e0215c500b0035d59951d62mr7706859ilu.39.1702282729431; Mon, 11 Dec 2023 00:18:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702282729; cv=none; d=google.com; s=arc-20160816; b=Wf1pGTbYPGcPtcopK1Ft77/itEHYeELuTdCg/UG65croan+MjFEhlfnO/OFZp1Mz5v i1/SxIdrdETh8zwGSvuTOiXZNqe80hd373URHHxy3HO/1Cv1mmCwKdxSG8Nb8DKnGBA+ 4lzyvlWqmYK/JA6o+fzna5zArJQFRMxg/1GW+nx54gQDQmWakT2ZIQrXx9JoWHDf2JIl G0eQr+BGw2Q+JFB8gwGEFeifpanpIwGCrvPuIyxE7uIc+DV0tSe25z4GTkaA01evPfwe 9mo49SD4/OU6WfsKZu4/dn7ByEz/ZXSj4QdpKOVm09uXLA04ufUJkOG4L1SniuEBrX4A 3uHg== 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 :message-id:date:subject:cc:to:from; bh=JDHTT8f359VXD8DPbgxtEZa5YMGc+eF+vP9OsrQM690=; fh=CSkUREzWa3dtwa18CaTyeaY19v1mFTX69eBmV7HiS1o=; b=t42LUaCqIgNy5gZAMJP0+TeQEPt7fKHNhtbUeHqnuZuD5e1uYOFKAGnEVmec0N/85e j2MRWIdz5gcrz2iUmSAUMRjRanAEAR6/45TLJEfm8T3RI9aF1F4xyl9dY90WpH02Y9Gs wy0RqT6ENzMv8hQKeoKqnqEjubCDzf0Y3bWKPRjjeGjEyKOkNTWtFd+C9clUD4gAoEUd ywgSG6J4Y7wenRJTKwLdHtaamL0gho64s8qsgS2UbZQlRgI2HiW+syEpzl5fmVh5n1R6 oD1UhJgLCSdBIu2drBCjg2/0kBJuAF1zneoswiFlBfRbLYEB3o1QubaiS17o6tC5E7kH TbBw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id j12-20020a65428c000000b005be1ee5b9dfsi5488641pgp.454.2023.12.11.00.18.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 00:18:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 8B169809589D; Mon, 11 Dec 2023 00:18:45 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233767AbjLKISh (ORCPT <rfc822;dexuan.linux@gmail.com> + 99 others); Mon, 11 Dec 2023 03:18:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229463AbjLKISf (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 11 Dec 2023 03:18:35 -0500 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9BAEED; Mon, 11 Dec 2023 00:18:41 -0800 (PST) Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4SpZQ40fQzz4f3kjD; Mon, 11 Dec 2023 16:18:36 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 7F7321A0837; Mon, 11 Dec 2023 16:18:38 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgDHyhDcxXZlKwVbDQ--.7085S4; Mon, 11 Dec 2023 16:18:38 +0800 (CST) From: linan666@huaweicloud.com To: song@kernel.org, zlliu@suse.com, neilb@suse.com, shli@fb.com Cc: linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org, linan666@huaweicloud.com, yukuai3@huawei.com, yi.zhang@huawei.com, houtao1@huawei.com, yangerkun@huawei.com Subject: [PATCH] md: Don't clear MD_CLOSING when the raid is about to stop Date: Mon, 11 Dec 2023 16:17:14 +0800 Message-Id: <20231211081714.1923567-1-linan666@huaweicloud.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: cCh0CgDHyhDcxXZlKwVbDQ--.7085S4 X-Coremail-Antispam: 1UD129KBjvJXoW7Cw13Zr18XryUAw4DCFy5CFg_yoW8Zr45pF 4xWF98KrWUGr9I9w4Utw4kXFyYq34aqrWvyry29a4rWa4Yyr9rJryFg398tryxGrZ5JFs8 Xa1UCa1Uu3WxW3JanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBY14x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26F1j6w1UM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4U JVWxJr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Gc CE3s1lnxkEFVAIw20F6cxK64vIFxWle2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xv F2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r1j6r 4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I 648v4I1lFIxGxcIEc7CjxVA2Y2ka0xkIwI1lw4CEc2x0rVAKj4xxMxAIw28IcxkI7VAKI4 8JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xv wVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjx v20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20E Y4v20xvaj40_Wr1j6rW3Jr1lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x 0267AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7VUbSApUUUUUU== X-CM-SenderInfo: polqt0awwwqx5xdzvxpfor3voofrz/ X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 11 Dec 2023 00:18:45 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784972815005993054 X-GMAIL-MSGID: 1784972815005993054 |
Series |
md: Don't clear MD_CLOSING when the raid is about to stop
|
|
Commit Message
Li Nan
Dec. 11, 2023, 8:17 a.m. UTC
From: Li Nan <linan122@huawei.com> The raid should not be opened anymore when it is about to be stopped. However, other processes can open it again if the flag MD_CLOSING is cleared before exiting. From now on, this flag will not be cleared when the raid will be stopped. Fixes: 065e519e71b2 ("md: MD_CLOSING needs to be cleared after called md_set_readonly or do_md_stop") Signed-off-by: Li Nan <linan122@huawei.com> --- drivers/md/md.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
Comments
On Mon, 11 Dec 2023 16:17:14 +0800 linan666@huaweicloud.com wrote: > From: Li Nan <linan122@huawei.com> > > The raid should not be opened anymore when it is about to be stopped. > However, other processes can open it again if the flag MD_CLOSING is > cleared before exiting. From now on, this flag will not be cleared when > the raid will be stopped. > > Fixes: 065e519e71b2 ("md: MD_CLOSING needs to be cleared after called > md_set_readonly or do_md_stop") Signed-off-by: Li Nan <linan122@huawei.com> Hello Li Nan, I was there when I needed to fix this: https://git.kernel.org/pub/scm/linux/kernel/git/song/md.git/commit/?h=md-next&id=c8870379a21fbd9ad14ca36204ccfbe9d25def43 For sure, you have to consider applying same solution for array_store "clear". Minor nit below. Thanks, Mariusz > --- > drivers/md/md.c | 8 +++----- > 1 file changed, 3 insertions(+), 5 deletions(-) > > diff --git a/drivers/md/md.c b/drivers/md/md.c > index 4e9fe5cbeedc..ebdfc9068a60 100644 > --- a/drivers/md/md.c > +++ b/drivers/md/md.c > @@ -6238,7 +6238,6 @@ static void md_clean(struct mddev *mddev) > mddev->persistent = 0; > mddev->level = LEVEL_NONE; > mddev->clevel[0] = 0; > - mddev->flags = 0; I recommend (safety recommendation): mddev->flags = MD_CLOSING; Unless you can prove that other flags cannot race. > mddev->sb_flags = 0; > mddev->ro = MD_RDWR; > mddev->metadata_type[0] = 0;
Hi, 在 2023/12/11 17:56, Mariusz Tkaczyk 写道: > On Mon, 11 Dec 2023 16:17:14 +0800 > linan666@huaweicloud.com wrote: > >> From: Li Nan <linan122@huawei.com> >> >> The raid should not be opened anymore when it is about to be stopped. >> However, other processes can open it again if the flag MD_CLOSING is >> cleared before exiting. From now on, this flag will not be cleared when >> the raid will be stopped. >> >> Fixes: 065e519e71b2 ("md: MD_CLOSING needs to be cleared after called >> md_set_readonly or do_md_stop") Signed-off-by: Li Nan <linan122@huawei.com> > > Hello Li Nan, > I was there when I needed to fix this: > https://git.kernel.org/pub/scm/linux/kernel/git/song/md.git/commit/?h=md-next&id=c8870379a21fbd9ad14ca36204ccfbe9d25def43 > > For sure, you have to consider applying same solution for array_store "clear". > Minor nit below. > > Thanks, > Mariusz > >> --- >> drivers/md/md.c | 8 +++----- >> 1 file changed, 3 insertions(+), 5 deletions(-) >> >> diff --git a/drivers/md/md.c b/drivers/md/md.c >> index 4e9fe5cbeedc..ebdfc9068a60 100644 >> --- a/drivers/md/md.c >> +++ b/drivers/md/md.c >> @@ -6238,7 +6238,6 @@ static void md_clean(struct mddev *mddev) >> mddev->persistent = 0; >> mddev->level = LEVEL_NONE; >> mddev->clevel[0] = 0; >> - mddev->flags = 0; > > I recommend (safety recommendation): > mddev->flags = MD_CLOSING; Taking a look I think both MD_CLOSING and MD_DELETED should not be cleared, however, there is no guarantee that MD_CLOSING will be set before md_clean, because mdadm can be removed without running. Hence I think just set MD_CLOSING is werid. I think the proper way is to keep MD_CLOSING and MD_DELETED if they are set. However, there is no such api to clear other bits at once. Since we're not expecting anyone else to write flags, following maybe acceptable: mddev->flags &= BIT_ULL_MASK(MD_CLOSING) | BIT_ULL_MASK(MD_DELETED); Or after making sure other flags cannot race, this patch is ok. Thanks, Kuai > > Unless you can prove that other flags cannot race. > >> mddev->sb_flags = 0; >> mddev->ro = MD_RDWR; >> mddev->metadata_type[0] = 0; > > . >
On Tue, 12 Dec 2023 11:21:28 +0800 Yu Kuai <yukuai1@huaweicloud.com> wrote: > Hi, > > 在 2023/12/11 17:56, Mariusz Tkaczyk 写道: > > On Mon, 11 Dec 2023 16:17:14 +0800 > > linan666@huaweicloud.com wrote: > > > >> From: Li Nan <linan122@huawei.com> > >> > >> The raid should not be opened anymore when it is about to be stopped. > >> However, other processes can open it again if the flag MD_CLOSING is > >> cleared before exiting. From now on, this flag will not be cleared when > >> the raid will be stopped. > >> > >> Fixes: 065e519e71b2 ("md: MD_CLOSING needs to be cleared after called > >> md_set_readonly or do_md_stop") Signed-off-by: Li Nan > >> <linan122@huawei.com> > > > > Hello Li Nan, > > I was there when I needed to fix this: > > https://git.kernel.org/pub/scm/linux/kernel/git/song/md.git/commit/?h=md-next&id=c8870379a21fbd9ad14ca36204ccfbe9d25def43 > > > > For sure, you have to consider applying same solution for array_store > > "clear". Minor nit below. > > > > Thanks, > > Mariusz > > > >> --- > >> drivers/md/md.c | 8 +++----- > >> 1 file changed, 3 insertions(+), 5 deletions(-) > >> > >> diff --git a/drivers/md/md.c b/drivers/md/md.c > >> index 4e9fe5cbeedc..ebdfc9068a60 100644 > >> --- a/drivers/md/md.c > >> +++ b/drivers/md/md.c > >> @@ -6238,7 +6238,6 @@ static void md_clean(struct mddev *mddev) > >> mddev->persistent = 0; > >> mddev->level = LEVEL_NONE; > >> mddev->clevel[0] = 0; > >> - mddev->flags = 0; > > > > I recommend (safety recommendation): > > mddev->flags = MD_CLOSING; > > Taking a look I think both MD_CLOSING and MD_DELETED should not be > cleared, however, there is no guarantee that MD_CLOSING will be set > before md_clean, because mdadm can be removed without running. Hence I > think just set MD_CLOSING is werid. > > I think the proper way is to keep MD_CLOSING and MD_DELETED if they are > set. However, there is no such api to clear other bits at once. Since > we're not expecting anyone else to write flags, following maybe > acceptable: > > mddev->flags &= BIT_ULL_MASK(MD_CLOSING) | BIT_ULL_MASK(MD_DELETED); Yes, MD_CLOSING is a bit number to not a bit value I can assign directly. Thanks for clarifying! Mariusz > > Or after making sure other flags cannot race, this patch is ok. > > Thanks, > Kuai > > > > > Unless you can prove that other flags cannot race. > > > >> mddev->sb_flags = 0; > >> mddev->ro = MD_RDWR; > >> mddev->metadata_type[0] = 0; > > > > . > > >
Hello, kernel test robot noticed "mdadm-selftests.06name.fail" on: commit: 4d060913335fad6f1d1f0816859c20aae823851c ("[PATCH] md: Don't clear MD_CLOSING when the raid is about to stop") url: https://github.com/intel-lab-lkp/linux/commits/linan666-huaweicloud-com/md-Don-t-clear-MD_CLOSING-when-the-raid-is-about-to-stop/20231211-162010 base: git://git.kernel.org/cgit/linux/kernel/git/song/md.git md-next patch link: https://lore.kernel.org/all/20231211081714.1923567-1-linan666@huaweicloud.com/ patch subject: [PATCH] md: Don't clear MD_CLOSING when the raid is about to stop in testcase: mdadm-selftests version: mdadm-selftests-x86_64-5f41845-1_20220826 with following parameters: disk: 1HDD test_prefix: 06name compiler: gcc-12 test machine: 8 threads 1 sockets Intel(R) Core(TM) i7-4790T CPU @ 2.70GHz (Haswell) with 16G memory (please refer to attached dmesg/kmsg for entire log/backtrace) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <oliver.sang@intel.com> | Closes: https://lore.kernel.org/oe-lkp/202312261217.c5597bdf-oliver.sang@intel.com 2023-12-24 10:19:28 mkdir -p /var/tmp 2023-12-24 10:19:28 mke2fs -t ext3 -b 4096 -J size=4 -q /dev/sdb1 2023-12-24 10:19:59 mount -t ext3 /dev/sdb1 /var/tmp sed -e 's/{DEFAULT_METADATA}/1.2/g' \ -e 's,{MAP_PATH},/run/mdadm/map,g' mdadm.8.in > mdadm.8 /usr/bin/install -D -m 644 mdadm.8 /usr/share/man/man8/mdadm.8 /usr/bin/install -D -m 644 mdmon.8 /usr/share/man/man8/mdmon.8 /usr/bin/install -D -m 644 md.4 /usr/share/man/man4/md.4 /usr/bin/install -D -m 644 mdadm.conf.5 /usr/share/man/man5/mdadm.conf.5 /usr/bin/install -D -m 644 udev-md-raid-creating.rules /lib/udev/rules.d/01-md-raid-creating.rules /usr/bin/install -D -m 644 udev-md-raid-arrays.rules /lib/udev/rules.d/63-md-raid-arrays.rules /usr/bin/install -D -m 644 udev-md-raid-assembly.rules /lib/udev/rules.d/64-md-raid-assembly.rules /usr/bin/install -D -m 644 udev-md-clustered-confirm-device.rules /lib/udev/rules.d/69-md-clustered-confirm-device.rules /usr/bin/install -D -m 755 mdadm /sbin/mdadm /usr/bin/install -D -m 755 mdmon /sbin/mdmon Testing on linux-6.7.0-rc3-00014-g4d060913335f kernel /lkp/benchmarks/mdadm-selftests/tests/06name... FAILED - see /var/tmp/06name.log and /var/tmp/fail06name.log for details The kernel config and materials to reproduce are available at: https://download.01.org/0day-ci/archive/20231226/202312261217.c5597bdf-oliver.sang@intel.com
在 2023/12/26 14:24, kernel test robot 写道: > > > Hello, > > kernel test robot noticed "mdadm-selftests.06name.fail" on: > > commit: 4d060913335fad6f1d1f0816859c20aae823851c ("[PATCH] md: Don't clear MD_CLOSING when the raid is about to stop") > url: https://github.com/intel-lab-lkp/linux/commits/linan666-huaweicloud-com/md-Don-t-clear-MD_CLOSING-when-the-raid-is-about-to-stop/20231211-162010 > base: git://git.kernel.org/cgit/linux/kernel/git/song/md.git md-next > patch link: https://lore.kernel.org/all/20231211081714.1923567-1-linan666@huaweicloud.com/ > patch subject: [PATCH] md: Don't clear MD_CLOSING when the raid is about to stop > > in testcase: mdadm-selftests > version: mdadm-selftests-x86_64-5f41845-1_20220826 > with following parameters: > > disk: 1HDD > test_prefix: 06name > > > > compiler: gcc-12 > test machine: 8 threads 1 sockets Intel(R) Core(TM) i7-4790T CPU @ 2.70GHz (Haswell) with 16G memory > > (please refer to attached dmesg/kmsg for entire log/backtrace) > > > > > If you fix the issue in a separate patch/commit (i.e. not just a new version of > the same patch/commit), kindly add following tags > | Reported-by: kernel test robot <oliver.sang@intel.com> > | Closes: https://lore.kernel.org/oe-lkp/202312261217.c5597bdf-oliver.sang@intel.com > > 2023-12-24 10:19:28 mkdir -p /var/tmp > 2023-12-24 10:19:28 mke2fs -t ext3 -b 4096 -J size=4 -q /dev/sdb1 > 2023-12-24 10:19:59 mount -t ext3 /dev/sdb1 /var/tmp > sed -e 's/{DEFAULT_METADATA}/1.2/g' \ > -e 's,{MAP_PATH},/run/mdadm/map,g' mdadm.8.in > mdadm.8 > /usr/bin/install -D -m 644 mdadm.8 /usr/share/man/man8/mdadm.8 > /usr/bin/install -D -m 644 mdmon.8 /usr/share/man/man8/mdmon.8 > /usr/bin/install -D -m 644 md.4 /usr/share/man/man4/md.4 > /usr/bin/install -D -m 644 mdadm.conf.5 /usr/share/man/man5/mdadm.conf.5 > /usr/bin/install -D -m 644 udev-md-raid-creating.rules /lib/udev/rules.d/01-md-raid-creating.rules > /usr/bin/install -D -m 644 udev-md-raid-arrays.rules /lib/udev/rules.d/63-md-raid-arrays.rules > /usr/bin/install -D -m 644 udev-md-raid-assembly.rules /lib/udev/rules.d/64-md-raid-assembly.rules > /usr/bin/install -D -m 644 udev-md-clustered-confirm-device.rules /lib/udev/rules.d/69-md-clustered-confirm-device.rules > /usr/bin/install -D -m 755 mdadm /sbin/mdadm > /usr/bin/install -D -m 755 mdmon /sbin/mdmon > Testing on linux-6.7.0-rc3-00014-g4d060913335f kernel > /lkp/benchmarks/mdadm-selftests/tests/06name... FAILED - see /var/tmp/06name.log and /var/tmp/fail06name.log for details > > If MD_CLOSING is not cleared when stopping, it will still exist when assembling and mddev can't be opened anymore. We need to clear it when starting. I will fix it in next version. > > The kernel config and materials to reproduce are available at: > https://download.01.org/0day-ci/archive/20231226/202312261217.c5597bdf-oliver.sang@intel.com > > >
在 2023/12/12 11:21, Yu Kuai 写道: > Hi, > > 在 2023/12/11 17:56, Mariusz Tkaczyk 写道: >> On Mon, 11 Dec 2023 16:17:14 +0800 >> linan666@huaweicloud.com wrote: >> >>> From: Li Nan <linan122@huawei.com> >>> >>> The raid should not be opened anymore when it is about to be stopped. >>> However, other processes can open it again if the flag MD_CLOSING is >>> cleared before exiting. From now on, this flag will not be cleared when >>> the raid will be stopped. >>> >>> Fixes: 065e519e71b2 ("md: MD_CLOSING needs to be cleared after called >>> md_set_readonly or do_md_stop") Signed-off-by: Li Nan >>> <linan122@huawei.com> >> >> Hello Li Nan, >> I was there when I needed to fix this: >> https://git.kernel.org/pub/scm/linux/kernel/git/song/md.git/commit/?h=md-next&id=c8870379a21fbd9ad14ca36204ccfbe9d25def43 >> >> >> For sure, you have to consider applying same solution for array_store >> "clear". >> Minor nit below. >> >> Thanks, >> Mariusz >> >>> --- >>> drivers/md/md.c | 8 +++----- >>> 1 file changed, 3 insertions(+), 5 deletions(-) >>> >>> diff --git a/drivers/md/md.c b/drivers/md/md.c >>> index 4e9fe5cbeedc..ebdfc9068a60 100644 >>> --- a/drivers/md/md.c >>> +++ b/drivers/md/md.c >>> @@ -6238,7 +6238,6 @@ static void md_clean(struct mddev *mddev) >>> mddev->persistent = 0; >>> mddev->level = LEVEL_NONE; >>> mddev->clevel[0] = 0; >>> - mddev->flags = 0; >> >> I recommend (safety recommendation): >> mddev->flags = MD_CLOSING; > > Taking a look I think both MD_CLOSING and MD_DELETED should not be > cleared, however, there is no guarantee that MD_CLOSING will be set > before md_clean, because mdadm can be removed without running. Hence I > think just set MD_CLOSING is werid. > > I think the proper way is to keep MD_CLOSING and MD_DELETED if they are > set. However, there is no such api to clear other bits at once. Since > we're not expecting anyone else to write flags, following maybe > acceptable: > > mddev->flags &= BIT_ULL_MASK(MD_CLOSING) | BIT_ULL_MASK(MD_DELETED); > MD_DELETED is only set after mddev->active is put to 0. We need to open mddev and get it before stropping raid, so the active must not be 0 and MD_DELETED will not be set in md_clean. > Or after making sure other flags cannot race, this patch is ok. > > Thanks, > Kuai > >> >> Unless you can prove that other flags cannot race. >> >>> mddev->sb_flags = 0; >>> mddev->ro = MD_RDWR; >>> mddev->metadata_type[0] = 0; >> >> . >> > > > .
diff --git a/drivers/md/md.c b/drivers/md/md.c index 4e9fe5cbeedc..ebdfc9068a60 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -6238,7 +6238,6 @@ static void md_clean(struct mddev *mddev) mddev->persistent = 0; mddev->level = LEVEL_NONE; mddev->clevel[0] = 0; - mddev->flags = 0; mddev->sb_flags = 0; mddev->ro = MD_RDWR; mddev->metadata_type[0] = 0; @@ -7614,7 +7613,6 @@ static int md_ioctl(struct block_device *bdev, blk_mode_t mode, int err = 0; void __user *argp = (void __user *)arg; struct mddev *mddev = NULL; - bool did_set_md_closing = false; if (!md_ioctl_valid(cmd)) return -ENOTTY; @@ -7698,7 +7696,6 @@ static int md_ioctl(struct block_device *bdev, blk_mode_t mode, err = -EBUSY; goto out; } - did_set_md_closing = true; mutex_unlock(&mddev->open_mutex); sync_blockdev(bdev); } @@ -7742,10 +7739,13 @@ static int md_ioctl(struct block_device *bdev, blk_mode_t mode, case STOP_ARRAY: err = do_md_stop(mddev, 0, bdev); + if (err) + clear_bit(MD_CLOSING, &mddev->flags); goto unlock; case STOP_ARRAY_RO: err = md_set_readonly(mddev, bdev); + clear_bit(MD_CLOSING, &mddev->flags); goto unlock; case HOT_REMOVE_DISK: @@ -7840,8 +7840,6 @@ static int md_ioctl(struct block_device *bdev, blk_mode_t mode, mddev_unlock(mddev); out: - if(did_set_md_closing) - clear_bit(MD_CLOSING, &mddev->flags); return err; } #ifdef CONFIG_COMPAT