Message ID | 20240201063404.772797-8-linan666@huaweicloud.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-47705-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:106:209c:c626 with SMTP id mn5csp251410dyc; Wed, 31 Jan 2024 22:41:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IHOknyXWJHkbV6NgeYuP32iAcL9Ywmk3yFWN9CvvIbSfqdle8nePxveYygkfNRU7zx3wAq+ X-Received: by 2002:a17:90b:1c10:b0:296:18a2:6043 with SMTP id oc16-20020a17090b1c1000b0029618a26043mr593866pjb.42.1706769685779; Wed, 31 Jan 2024 22:41:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706769685; cv=pass; d=google.com; s=arc-20160816; b=CKA+DIh433hdFlpLQd/jxqu53qDe9be8WynUGHz37bPDV2uQxiqE7jWKtjLlvdznks r/YcWNXbbSBt4smRfig6aVYDDAHv6SSpmCDnsfLFamOVc+O8PnKjvrUTcxUqhdmAKXIL FxC9iWODTN8gbkwII9sOegAxrlFJOVj2rTfqfLciAjLigyqMPWXv1gzFRHV9SwGD2zqO BEoSKjasl2eMSwBHBfOWd9DND2g6Hubxzam7x1dxirtHrHw7ErvW7cokkjpj/s2JC2fF YFBpuLG2EWlSXt9PhYNp7IVGLdCIcSCZh53ydx4B/yAGwsGkmagO+1fMln5wQkmE9puO qMBA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=JWjn8A2do3Srjrs0AgdK/81AwkQLgg04gCCp8ZJONbA=; fh=TLjL7/q9gEblMbJiqoRUJyt+TQtkrdtBuSKyyg4z+tU=; b=ZyURJP2jBrRfy4ZWp/YudOS6Iehx+k9928X0AI7udHAR/PbVPdh8qHck66JXMdUoBL oDKd5+R4VGt0eDie1RPSHbroJDGV0fC2efw1LOXufjnHKn8kKWCHerOiNHHbQ9PfwTFO Rn5wJrROymZNPUr/HqK+t1RGjDO/hxVavqeqmzbtwLRD7g/PKevfmjjfZcfpKUlGQjjp mjFiQeGpJn5yZsgIe+9zLWLpZK4z50I0rJxgJ4u5z2MsGkHYHfckzSKY76e5ZoGeG4z6 cH9IYLYc/0Z+exFqRpAgEk4IKscksyxRpAUgpJQuQjh6TiIZfceFprKKY8c6e1whnEPK aTgw==; 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-47705-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47705-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCW/vvM0RmunkDvmQe0ETxhem7OytYifGggiUeoDjfSL8mRigqafapmsw0PDxi7bie0BK5WV+i2EWxIaKNmv3f7KlrOyKQ== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id s24-20020a17090ad49800b00295dda7f384si2865461pju.152.2024.01.31.22.41.25 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 22:41:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-47705-ouuuleilei=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-47705-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47705-ouuuleilei=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 8C47B29542D for <ouuuleilei@gmail.com>; Thu, 1 Feb 2024 06:41:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 25A2815B976; Thu, 1 Feb 2024 06:38:39 +0000 (UTC) Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [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 C9D3E157E9B; Thu, 1 Feb 2024 06:38:34 +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=1706769517; cv=none; b=AYTTiw4cXD4wySj15HsJ+nlLSHBEjLSpE4O+vEVckv8HS+uviMp2EYivk8t1Qq7wIQjZikwmBJNibRbmvlq76nfuQC9SlNQRnlR0ExGxBHYMj3/iI4M5+0OCjd5yOyHR2i/RW6rlnJQnvzzhMb4s44/MXJb8Ti16ln5oDzDiOtg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706769517; c=relaxed/simple; bh=e7/3sAqCiWfWbLUF4DKh+PfCZwNYbxKy0sq+yrPrUxg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Ym0qLdyRko8gVj4wiDs5pjKOWvYwwpOL7xXzMNorkLXk124OeDjTrhhWQ6aWCbBSujeSmw31aRHJT2Iu964ulQuPbJZQ8lAXfJi7KyF1kwQkJZMvm+krFHsXdLNbbhXnCRTvRUuvX6//h/JpWgIKh5UL1/4kh3LrObDCAj98AGg= 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.216]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4TQTkT0B3Gz4f3m76; Thu, 1 Feb 2024 14:38:25 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 8B1521A0199; Thu, 1 Feb 2024 14:38:31 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX5g5iPLtllCl+Cg--.15155S11; Thu, 01 Feb 2024 14:38:31 +0800 (CST) From: linan666@huaweicloud.com To: song@kernel.org, neilb@suse.com, mariusz.tkaczyk@linux.intel.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 v5 7/8] md: sync blockdev before stopping raid or setting readonly Date: Thu, 1 Feb 2024 14:34:03 +0800 Message-Id: <20240201063404.772797-8-linan666@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240201063404.772797-1-linan666@huaweicloud.com> References: <20240201063404.772797-1-linan666@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: cCh0CgAX5g5iPLtllCl+Cg--.15155S11 X-Coremail-Antispam: 1UD129KBjvJXoW7Cw4UuryxXry8Xw43tFW5KFg_yoW8WF13pF s2yry5Wr1Ut34ftw47ua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-CM-SenderInfo: polqt0awwwqx5xdzvxpfor3voofrz/ X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789677729780958920 X-GMAIL-MSGID: 1789677729780958920 |
Series |
bugfix of MD_CLOSING and clean up md_ioctl()
|
|
Commit Message
Li Nan
Feb. 1, 2024, 6:34 a.m. UTC
From: Li Nan <linan122@huawei.com> Commit a05b7ea03d72 ("md: avoid crash when stopping md array races with closing other open fds.") added sync_block before stopping raid and setting readonly. Later in commit 260fa034ef7a ("md: avoid deadlock when dirty buffers during md_stop.") it is moved to ioctl. array_state_store() was ignored. Add sync blockdev to array_state_store() now. Signed-off-by: Li Nan <linan122@huawei.com> --- drivers/md/md.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
Comments
Hi, 在 2024/02/01 14:34, linan666@huaweicloud.com 写道: > From: Li Nan <linan122@huawei.com> > > Commit a05b7ea03d72 ("md: avoid crash when stopping md array races > with closing other open fds.") added sync_block before stopping raid and > setting readonly. Later in commit 260fa034ef7a ("md: avoid deadlock when > dirty buffers during md_stop.") it is moved to ioctl. array_state_store() > was ignored. Add sync blockdev to array_state_store() now. You're not just adding sync_blockdev() here. Please rewrite the tittle and commit message. > > Signed-off-by: Li Nan <linan122@huawei.com> > --- > drivers/md/md.c | 16 ++++++++++++++++ > 1 file changed, 16 insertions(+) > > diff --git a/drivers/md/md.c b/drivers/md/md.c > index 4c7a0225f77d..86becf0015f5 100644 > --- a/drivers/md/md.c > +++ b/drivers/md/md.c > @@ -4493,6 +4493,16 @@ array_state_store(struct mddev *mddev, const char *buf, size_t len) > case broken: /* cannot be set */ > case bad_word: > return -EINVAL; > + case clear: > + case readonly: > + case inactive: > + case read_auto: > + if (!mddev->pers || !md_is_rdwr(mddev)) > + break; > + err = mddev_set_closing_and_sync_blockdev(mddev); In this context, mddev->openers should be zero, and such check is in do_md_stop() and md_set_readonly(): if (atomic_read(&mddev->openers) > !!bdev). Thanks, Kuai > + if (err) > + return err; > + break; > default: > break; > } > @@ -4518,6 +4528,7 @@ array_state_store(struct mddev *mddev, const char *buf, size_t len) > spin_unlock(&mddev->lock); > return err ?: len; > } > + > err = mddev_lock(mddev); > if (err) > return err; > @@ -4592,6 +4603,11 @@ array_state_store(struct mddev *mddev, const char *buf, size_t len) > sysfs_notify_dirent_safe(mddev->sysfs_state); > } > mddev_unlock(mddev); > + > + if (st == readonly || st == read_auto || st == inactive || > + (err && st == clear)) > + clear_bit(MD_CLOSING, &mddev->flags); > + > return err ?: len; > } > static struct md_sysfs_entry md_array_state = >
在 2024/2/2 10:12, Yu Kuai 写道: > Hi, > > 在 2024/02/01 14:34, linan666@huaweicloud.com 写道: >> From: Li Nan <linan122@huawei.com> >> >> Commit a05b7ea03d72 ("md: avoid crash when stopping md array races >> with closing other open fds.") added sync_block before stopping raid and >> setting readonly. Later in commit 260fa034ef7a ("md: avoid deadlock when >> dirty buffers during md_stop.") it is moved to ioctl. array_state_store() >> was ignored. Add sync blockdev to array_state_store() now. > > You're not just adding sync_blockdev() here. Please rewrite the tittle > and commit message. > >> >> Signed-off-by: Li Nan <linan122@huawei.com> >> --- >> drivers/md/md.c | 16 ++++++++++++++++ >> 1 file changed, 16 insertions(+) >> >> diff --git a/drivers/md/md.c b/drivers/md/md.c >> index 4c7a0225f77d..86becf0015f5 100644 >> --- a/drivers/md/md.c >> +++ b/drivers/md/md.c >> @@ -4493,6 +4493,16 @@ array_state_store(struct mddev *mddev, const char >> *buf, size_t len) >> case broken: /* cannot be set */ >> case bad_word: >> return -EINVAL; >> + case clear: >> + case readonly: >> + case inactive: >> + case read_auto: >> + if (!mddev->pers || !md_is_rdwr(mddev)) >> + break; >> + err = mddev_set_closing_and_sync_blockdev(mddev); > > In this context, mddev->openers should be zero, and such check is in > do_md_stop() and md_set_readonly(): > Yeah, the checks in do_md_stop() and md_set_readonly() can be removed after this patch. However, 'mddev->open_metux' is used to protect MD_CLOSING and 'mddev->openers', it can be removed in these functions, too. I will fix it later. Thanks for your review. > if (atomic_read(&mddev->openers) > !!bdev). > > Thanks, > Kuai >
diff --git a/drivers/md/md.c b/drivers/md/md.c index 4c7a0225f77d..86becf0015f5 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -4493,6 +4493,16 @@ array_state_store(struct mddev *mddev, const char *buf, size_t len) case broken: /* cannot be set */ case bad_word: return -EINVAL; + case clear: + case readonly: + case inactive: + case read_auto: + if (!mddev->pers || !md_is_rdwr(mddev)) + break; + err = mddev_set_closing_and_sync_blockdev(mddev); + if (err) + return err; + break; default: break; } @@ -4518,6 +4528,7 @@ array_state_store(struct mddev *mddev, const char *buf, size_t len) spin_unlock(&mddev->lock); return err ?: len; } + err = mddev_lock(mddev); if (err) return err; @@ -4592,6 +4603,11 @@ array_state_store(struct mddev *mddev, const char *buf, size_t len) sysfs_notify_dirent_safe(mddev->sysfs_state); } mddev_unlock(mddev); + + if (st == readonly || st == read_auto || st == inactive || + (err && st == clear)) + clear_bit(MD_CLOSING, &mddev->flags); + return err ?: len; } static struct md_sysfs_entry md_array_state =