From patchwork Thu Feb 1 06:34:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Nan X-Patchwork-Id: 195177 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:106:209c:c626 with SMTP id mn5csp251696dyc; Wed, 31 Jan 2024 22:42:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IHYs0fjErdFvI5ouBCc7F80z8m3bndGLWsPRdFMzbhUP88ZWd4wTaQSkp9ZnPj+KhxNSbNj X-Received: by 2002:a2e:860b:0:b0:2d0:770d:774 with SMTP id a11-20020a2e860b000000b002d0770d0774mr599837lji.41.1706769732245; Wed, 31 Jan 2024 22:42:12 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706769732; cv=pass; d=google.com; s=arc-20160816; b=cRT91FqYwvxv9wYoV0FdG9961FkOmNMiY51N3u9IRsKrBiZ2LId6lk861/TfY/idkH UNewe9uky6s86GYSK0MZO0leG3k3zs0qbdrPD9alDAI0OspeObpc+GGVHlWWB7A7Jehn la3SGACao6oanAHqrEXySJ2BD08Ec9o549DLwLsWB9LtuwAjTdFaq9CIrLogCE2piVzZ sgZ73mhO6Lf4HPRCqePp6BCm5UsEyqNGU0ouIuGe8EIgTRJLyhtLZVKnzbqN/yGUUdBu 2obrkuOMCKv4vEX9VGNthQqJc91nv+URA58vDTBiHhIRX89PU2D/4AuBursX9JiKht/U 79mg== 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=nbvF74DvWT63t8juonCjX58209USjPtA4LkFTCH2aZE=; fh=Dk39nkcInzCYzW1VeBdsqTac7yYaKXf7dkegIEgvqVM=; b=dNkQ3WRVppMo48kk5VWmgFZ3zkwBRMwYgIcFvlGnUUWcYYRja83KI6rwX09A4kFYxn 69Ptmwrql31+N6OG2FzHXVDv83ADS0ZnpplFP/b2oMCa25KYNScnQTrX9cL2eqq4in1j Si4rBgmMAjQ7hlJlt0G/BSUztjpLdmdJvk+aBXR4d9l7Ly6uKxK7I9tSzt7y4Z8GCE8o XYfU7SdpFOuNfYNHR13MDYw56wSOYTcTZb0GhsV27GDCF2mrMTolJzt2JN/qRzjUybuo 1wsL0VCeCb7hSJXARGRUPEf2ZCoEiZGGhjX710heLjZdAGYvQlyoqspgJxg9PfjJPIHR jrtA==; 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-47704-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47704-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCUMKu+//XxgEus5SQoiwpFvUonTnyUos9l//5f7n/47KtzxeJ2TzgkoiGfAqT8QpNEvHXZC6B4Ri2icUyr7g1X9pTHMsg== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id p6-20020a05640243c600b0055ee21d6135si4797218edc.352.2024.01.31.22.42.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 22:42:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-47704-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-47704-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47704-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 am.mirrors.kernel.org (Postfix) with ESMTPS id DED041F21FA5 for ; Thu, 1 Feb 2024 06:41:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A77DC15B11C; Thu, 1 Feb 2024 06:38:38 +0000 (UTC) Received: from dggsgout11.his.huawei.com (unknown [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 9490D157E6B; Thu, 1 Feb 2024 06:38:33 +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=1706769516; cv=none; b=ox2Gh8/t1lu9b5el9jF50arXaWOXmDHXfoSANaQD4tDoX3kXSNIZKSq9c27xsSoh7Yo3fbfPRMG256tmxSQqu/hv8WBIljnaeHJdODI56Xfxk2OgwtjU+NTkXVuXHvH3UT1dIBuAUjye3m4cZfpcG6g9qIHZNVbtA+Cfkwe6TGs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706769516; c=relaxed/simple; bh=2ui+26hVUMX6PdqicUPRi8cSQN5CIv5m/cqEznh7b6g=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=fxX5aOeF8fWwJsZuYvMjnOymuHmeGcLV5EPB/L9muAWTpdkfFVQwQGXOMtf/Tq3WPOupaRSVaI3akeYytUrdXbXn5bOm92ZqHnRTnUaigBr7y3xl5Ra4FllFQBfg/ir0mDZqTo8dKcGIk9WhYq+9Oq8aMY8qdB06uBopJGJhLRs= 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 4TQTkS0ggXz4f3lW2; Thu, 1 Feb 2024 14:38:24 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 9C4781A0199; Thu, 1 Feb 2024 14:38:30 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX5g5iPLtllCl+Cg--.15155S9; Thu, 01 Feb 2024 14:38:30 +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 5/8] md: Don't clear MD_CLOSING when the raid is about to stop Date: Thu, 1 Feb 2024 14:34:01 +0800 Message-Id: <20240201063404.772797-6-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: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX5g5iPLtllCl+Cg--.15155S9 X-Coremail-Antispam: 1UD129KBjvJXoW7Cw13Zr18XryUAw4DCFy5CFg_yoW8Cw13pa 1xKFy5KrWUJ3sI9w4Utw1kW3WFq34SgrWvyry2va4rZa4UAry7Jr9Yg3yDCr95WFZ5ZFs8 X3WUXayUWw1xW3JanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUQY14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAac4AC62xK8xCEY4vEwIxC4wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0V AKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUGVWUXwAv7VC2z280aVAFwI0_Jr0_Gr1l Ox8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErc IFxwACI402YVCY1x02628vn2kIc2xKxwAKzVCY07xG64k0F24l42xK82IYc2Ij64vIr41l 4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67 AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8I cVAFwI0_JFI_Gr1lIxAIcVC0I7IYx2IY6xkF7I0E14v26F4j6r4UJwCI42IY6xAIw20EY4 v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AK xVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7VUbMKZtUUUUU== X-CM-SenderInfo: polqt0awwwqx5xdzvxpfor3voofrz/ X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789677779122340862 X-GMAIL-MSGID: 1789677779122340862 From: Li Nan 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 Reviewed-by: Yu Kuai --- drivers/md/md.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/md/md.c b/drivers/md/md.c index 5442e8e3c161..deee004b8f22 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -6247,7 +6247,15 @@ static void md_clean(struct mddev *mddev) mddev->persistent = 0; mddev->level = LEVEL_NONE; mddev->clevel[0] = 0; - mddev->flags = 0; + /* + * Don't clear MD_CLOSING, or mddev can be opened again. + * 'hold_active != 0' means mddev is still in the creation + * process and will be used later. + */ + if (mddev->hold_active) + mddev->flags = 0; + else + mddev->flags &= BIT_ULL_MASK(MD_CLOSING); mddev->sb_flags = 0; mddev->ro = MD_RDWR; mddev->metadata_type[0] = 0; @@ -7626,7 +7634,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; err = md_ioctl_valid(cmd); if (err) @@ -7687,7 +7694,6 @@ static int md_ioctl(struct block_device *bdev, blk_mode_t mode, mutex_unlock(&mddev->open_mutex); return -EBUSY; } - did_set_md_closing = true; mutex_unlock(&mddev->open_mutex); sync_blockdev(bdev); } @@ -7829,7 +7835,7 @@ static int md_ioctl(struct block_device *bdev, blk_mode_t mode, mddev_unlock(mddev); out: - if(did_set_md_closing) + if (cmd == STOP_ARRAY_RO || (err && cmd == STOP_ARRAY)) clear_bit(MD_CLOSING, &mddev->flags); return err; }