Message ID | 20231129043127.2245901-3-yukuai1@huaweicloud.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a5a7:0:b0:403:3b70:6f57 with SMTP id d7csp116427vqn; Tue, 28 Nov 2023 20:32:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IGCPUHUR9JgXU8/+mNewSk0Di4cd6ILFNPhSyAAnKnxWaH4FCFbExbarTrzoAzPHaHmryii X-Received: by 2002:a05:6a20:3d13:b0:18c:b081:4c32 with SMTP id y19-20020a056a203d1300b0018cb0814c32mr7688899pzi.4.1701232355544; Tue, 28 Nov 2023 20:32:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701232355; cv=none; d=google.com; s=arc-20160816; b=g+cvEH0bnSoTkTblwQjewtU95eB+akpgc09Gw8n2H0sbN0LhskZOFWA7VVC7LuxdND oL9Uh6DpZULqRvIuz5W6tGga2oa3p7Ac5fdGnQ8pPjcLI2Aud/c094Fo3oaUtguGmqHY H4KzBciNvUp6Ha5onJkdNLak1JfL7C1ig1Gr/aggk8Kvde82I/i9MPPhfSM3fZj2hWjr UTqJBpwZcT6tx5avgzZDWLvSMv/64LUZw+zAMsbStb0nLeylOwwiBCs69UccZd8Fpf5o 7Giv3PtfChXFDopqg/UG0bPhrAB3Wb0VCkpxfnKQ13OcLSVp2swnc0tKO9eLfsFBNPGt nriQ== 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=+bCK5/jiB172XuZ5dbmZwfSZOdZQqyZdx+d7VRHvc00=; fh=zVIHjnfjYXjU+hYbxPUw8z+QX7mV2ayyrBgf4ZvrzN8=; b=SQbogRpaT/dkV0SX1LCon03PXNzr1P8rgPcsKvozpZ8sAmjMnKv6OmhbO7dwbvwnK/ vxDs1tEDdclv7pC/tAymkcro8HNlcNtKDfF7QzMRpb8W7ZvS6Nq2CezRtpvaHDrl3amV 3kJx7R8M/AWFUQYs5eOLPyePRFlZESnCGmRA9SqAZWIuZ+H5L5bqr5vdI38tG8NJJ3E/ 01h/71I1BaC7im3iLHozHzmsNhNlM3/mm+Dvev2jmKV9kxe7FtPrWpYg8MqTOjvHirYL DOYBbG11TWaWGbGI9BKJ7a1+zVyrrbAUhss0arcTEJvEuWXeXbE438FK931zFC3NMsv/ W+Pw== 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:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id z8-20020a1709027e8800b001cfdd2fe63csi4503858pla.312.2023.11.28.20.32.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 20:32:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (Postfix) with ESMTP id 0C725804AD36; Tue, 28 Nov 2023 20:32:30 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376904AbjK2EcL (ORCPT <rfc822;kernel.ruili@gmail.com> + 99 others); Tue, 28 Nov 2023 23:32:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230198AbjK2EcI (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 28 Nov 2023 23:32:08 -0500 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A934B19B1; Tue, 28 Nov 2023 20:32:13 -0800 (PST) Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4Sg5yH3wkYz4f3kk1; Wed, 29 Nov 2023 12:32:07 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 689AA1A0B64; Wed, 29 Nov 2023 12:32:10 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgDn6xHHvmZldxHwCA--.18598S6; Wed, 29 Nov 2023 12:32:10 +0800 (CST) From: Yu Kuai <yukuai1@huaweicloud.com> To: xni@redhat.com, song@kernel.org, yukuai3@huawei.com Cc: linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org, yukuai1@huaweicloud.com, yi.zhang@huawei.com, yangerkun@huawei.com Subject: [PATCH v3 2/3] md: don't leave 'MD_RECOVERY_FROZEN' in error path of md_set_readonly() Date: Wed, 29 Nov 2023 12:31:26 +0800 Message-Id: <20231129043127.2245901-3-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231129043127.2245901-1-yukuai1@huaweicloud.com> References: <20231129043127.2245901-1-yukuai1@huaweicloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: cCh0CgDn6xHHvmZldxHwCA--.18598S6 X-Coremail-Antispam: 1UD129KBjvJXoW7uFWfGr48uw4ktF45Cr1rJFb_yoW8KFWxp3 yxtF98Cry8JFy3Zr4Dta4DZa45Zw1jqrWqyFy3u34rJF1ftrsxCFyY9348JrWvkas2v3y5 Xw4rGrW7ua4IgaUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUU9m14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_Jryl82xGYIkIc2 x26xkF7I0E14v26r4j6ryUM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJw A2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq3wAS 0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2 IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0 Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCF04k20xvY0x0EwIxGrwCFx2 IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v2 6r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67 AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IY s7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr 0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUc6pPUUUUU= X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ 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 agentk.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 (agentk.vger.email [0.0.0.0]); Tue, 28 Nov 2023 20:32:30 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783871418748256183 X-GMAIL-MSGID: 1783871418748256183 |
Series |
md: fix stopping sync thread
|
|
Commit Message
Yu Kuai
Nov. 29, 2023, 4:31 a.m. UTC
From: Yu Kuai <yukuai3@huawei.com> If md_set_readonly() failed, the array could still be read-write, however 'MD_RECOVERY_FROZEN' could still be set, which leave the array in an abnormal state that sync or recovery can't continue anymore. Hence make sure the flag is cleared after md_set_readonly() returns. Signed-off-by: Yu Kuai <yukuai3@huawei.com> Acked-by: Xiao Ni <xni@redhat.com> --- drivers/md/md.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-)
Comments
On Tue, Nov 28, 2023 at 8:32 PM Yu Kuai <yukuai1@huaweicloud.com> wrote: > > From: Yu Kuai <yukuai3@huawei.com> > > If md_set_readonly() failed, the array could still be read-write, however > 'MD_RECOVERY_FROZEN' could still be set, which leave the array in an > abnormal state that sync or recovery can't continue anymore. > Hence make sure the flag is cleared after md_set_readonly() returns. > > Signed-off-by: Yu Kuai <yukuai3@huawei.com> > Acked-by: Xiao Ni <xni@redhat.com> Since we are shipping this via the md-fixes branch, we need a Fixes tag. > --- > drivers/md/md.c | 24 +++++++++++++----------- > 1 file changed, 13 insertions(+), 11 deletions(-) > > diff --git a/drivers/md/md.c b/drivers/md/md.c > index 5640a948086b..2d8e45a1af23 100644 > --- a/drivers/md/md.c > +++ b/drivers/md/md.c > @@ -6355,6 +6355,9 @@ static int md_set_readonly(struct mddev *mddev, struct block_device *bdev) > int err = 0; > int did_freeze = 0; > > + if (mddev->external && test_bit(MD_SB_CHANGE_PENDING, &mddev->sb_flags)) > + return -EBUSY; > + > if (!test_bit(MD_RECOVERY_FROZEN, &mddev->recovery)) { > did_freeze = 1; > set_bit(MD_RECOVERY_FROZEN, &mddev->recovery); > @@ -6369,8 +6372,6 @@ static int md_set_readonly(struct mddev *mddev, struct block_device *bdev) > */ > md_wakeup_thread_directly(mddev->sync_thread); > > - if (mddev->external && test_bit(MD_SB_CHANGE_PENDING, &mddev->sb_flags)) > - return -EBUSY; > mddev_unlock(mddev); > wait_event(resync_wait, !test_bit(MD_RECOVERY_RUNNING, > &mddev->recovery)); > @@ -6383,29 +6384,30 @@ static int md_set_readonly(struct mddev *mddev, struct block_device *bdev) > mddev->sync_thread || > test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)) { > pr_warn("md: %s still in use.\n",mdname(mddev)); > - if (did_freeze) { > - clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery); > - set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); > - md_wakeup_thread(mddev->thread); > - } This change (move did_freeze, etc.) is not explained in the commit log. Is it just refactor? Thanks, Song > err = -EBUSY; > goto out; > } > + > if (mddev->pers) { > __md_stop_writes(mddev); > > - err = -ENXIO; > - if (mddev->ro == MD_RDONLY) > + if (mddev->ro == MD_RDONLY) { > + err = -ENXIO; > goto out; > + } > + > mddev->ro = MD_RDONLY; > set_disk_ro(mddev->gendisk, 1); > + } > + > +out: > + if ((mddev->pers && !err) || did_freeze) { > clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery); > set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); > md_wakeup_thread(mddev->thread); > sysfs_notify_dirent_safe(mddev->sysfs_state); > - err = 0; > } > -out: > + > mutex_unlock(&mddev->open_mutex); > return err; > } > -- > 2.39.2 >
Hi, 在 2023/12/02 4:53, Song Liu 写道: > On Tue, Nov 28, 2023 at 8:32 PM Yu Kuai <yukuai1@huaweicloud.com> wrote: >> >> From: Yu Kuai <yukuai3@huawei.com> >> >> If md_set_readonly() failed, the array could still be read-write, however >> 'MD_RECOVERY_FROZEN' could still be set, which leave the array in an >> abnormal state that sync or recovery can't continue anymore. >> Hence make sure the flag is cleared after md_set_readonly() returns. >> >> Signed-off-by: Yu Kuai <yukuai3@huawei.com> >> Acked-by: Xiao Ni <xni@redhat.com> > > Since we are shipping this via the md-fixes branch, we need a Fixes tag. Okay, I'll add following fix tag: Fixes: 88724bfa68be ("md: wait for pending superblock updates before switching to read-only") > >> --- >> drivers/md/md.c | 24 +++++++++++++----------- >> 1 file changed, 13 insertions(+), 11 deletions(-) >> >> diff --git a/drivers/md/md.c b/drivers/md/md.c >> index 5640a948086b..2d8e45a1af23 100644 >> --- a/drivers/md/md.c >> +++ b/drivers/md/md.c >> @@ -6355,6 +6355,9 @@ static int md_set_readonly(struct mddev *mddev, struct block_device *bdev) >> int err = 0; >> int did_freeze = 0; >> >> + if (mddev->external && test_bit(MD_SB_CHANGE_PENDING, &mddev->sb_flags)) >> + return -EBUSY; >> + >> if (!test_bit(MD_RECOVERY_FROZEN, &mddev->recovery)) { >> did_freeze = 1; >> set_bit(MD_RECOVERY_FROZEN, &mddev->recovery); >> @@ -6369,8 +6372,6 @@ static int md_set_readonly(struct mddev *mddev, struct block_device *bdev) >> */ >> md_wakeup_thread_directly(mddev->sync_thread); >> >> - if (mddev->external && test_bit(MD_SB_CHANGE_PENDING, &mddev->sb_flags)) >> - return -EBUSY; >> mddev_unlock(mddev); >> wait_event(resync_wait, !test_bit(MD_RECOVERY_RUNNING, >> &mddev->recovery)); >> @@ -6383,29 +6384,30 @@ static int md_set_readonly(struct mddev *mddev, struct block_device *bdev) >> mddev->sync_thread || >> test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)) { >> pr_warn("md: %s still in use.\n",mdname(mddev)); >> - if (did_freeze) { >> - clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery); >> - set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); >> - md_wakeup_thread(mddev->thread); >> - } > > This change (move did_freeze, etc.) is not explained in the commit log. > Is it just refactor? It is refactor, but it is also part of "make sure the flag is cleared after md_set_readonly() returns", because now that MD_RECOVERY_FROZEN will be cleared: if ((mddev->pers && !err) || did_freeze) Which means, - If set readonly succeed, or; - if something is wrong and did_freeze is set, exactly what this patch tries to do; Thanks, Kuai > > Thanks, > Song > > >> err = -EBUSY; >> goto out; >> } >> + >> if (mddev->pers) { >> __md_stop_writes(mddev); >> >> - err = -ENXIO; >> - if (mddev->ro == MD_RDONLY) >> + if (mddev->ro == MD_RDONLY) { >> + err = -ENXIO; >> goto out; >> + } >> + >> mddev->ro = MD_RDONLY; >> set_disk_ro(mddev->gendisk, 1); >> + } >> + >> +out: >> + if ((mddev->pers && !err) || did_freeze) { >> clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery); >> set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); >> md_wakeup_thread(mddev->thread); >> sysfs_notify_dirent_safe(mddev->sysfs_state); >> - err = 0; >> } >> -out: >> + >> mutex_unlock(&mddev->open_mutex); >> return err; >> } >> -- >> 2.39.2 >> > . >
diff --git a/drivers/md/md.c b/drivers/md/md.c index 5640a948086b..2d8e45a1af23 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -6355,6 +6355,9 @@ static int md_set_readonly(struct mddev *mddev, struct block_device *bdev) int err = 0; int did_freeze = 0; + if (mddev->external && test_bit(MD_SB_CHANGE_PENDING, &mddev->sb_flags)) + return -EBUSY; + if (!test_bit(MD_RECOVERY_FROZEN, &mddev->recovery)) { did_freeze = 1; set_bit(MD_RECOVERY_FROZEN, &mddev->recovery); @@ -6369,8 +6372,6 @@ static int md_set_readonly(struct mddev *mddev, struct block_device *bdev) */ md_wakeup_thread_directly(mddev->sync_thread); - if (mddev->external && test_bit(MD_SB_CHANGE_PENDING, &mddev->sb_flags)) - return -EBUSY; mddev_unlock(mddev); wait_event(resync_wait, !test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)); @@ -6383,29 +6384,30 @@ static int md_set_readonly(struct mddev *mddev, struct block_device *bdev) mddev->sync_thread || test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)) { pr_warn("md: %s still in use.\n",mdname(mddev)); - if (did_freeze) { - clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery); - set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); - md_wakeup_thread(mddev->thread); - } err = -EBUSY; goto out; } + if (mddev->pers) { __md_stop_writes(mddev); - err = -ENXIO; - if (mddev->ro == MD_RDONLY) + if (mddev->ro == MD_RDONLY) { + err = -ENXIO; goto out; + } + mddev->ro = MD_RDONLY; set_disk_ro(mddev->gendisk, 1); + } + +out: + if ((mddev->pers && !err) || did_freeze) { clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery); set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); md_wakeup_thread(mddev->thread); sysfs_notify_dirent_safe(mddev->sysfs_state); - err = 0; } -out: + mutex_unlock(&mddev->open_mutex); return err; }