Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp898393rdh; Fri, 24 Nov 2023 00:05:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IFJyWYN+ar/noKkzhEVqRThctn/f06pMH3fBi66FCT3pJzbRnwPYxx3KC8zj2LZHv1WCysH X-Received: by 2002:a17:902:e844:b0:1cc:3c2d:128e with SMTP id t4-20020a170902e84400b001cc3c2d128emr2616176plg.7.1700813156834; Fri, 24 Nov 2023 00:05:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700813156; cv=none; d=google.com; s=arc-20160816; b=K9WlgHo9gzBMSvBzHeH3MX1dWiXKGMGYuS8pqithUmwkrbVYGNv4CIRkflMn5pSLZN wvHHImr/a+JRXXMfzc2cVFdRk313sKK5WHOrFriTmaV6f+k81kHx9nZvSqKJbbfWUHuC NVkr4bC9bgQ37EPnp27fIIozmG7JZI0jfn9tenifsPH4nxUVrokXLapnBR5u7ER3nhgt h1RQKGzAiIj1FVy/Hhv75roY5I1yPHfUUQkgijtrSxkNMUlpKTL3zaEskgY1wjblgiL3 8wG5cy9UZVxJiwZPQ+EBTiIPJV/I1uKZ695P0Lp0fpx9QDilO1AH+eGU7pVm542XVvzL fv8w== 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=DIAf62XR8V+UA0cAOGhJoQftNFb3bg4q9HZMDkwZOYA=; fh=1OsC7ljVhdTcf5FTl08sAtO9qsMpveq6AJn+JsIEEss=; b=fGuD4tqpENFJh4xSEVdh1ntvmY+JG5sd89K/P9qoqAZCw1fXsZvc+WaFmssJ6i95MT hO/FLFpT2Wnvp1sP/2i6XY7RTfrmSiGakwchSBCHmr25p8D9KSfi3VwJYjgQhXCIi6yu 8m93fbyFmRlvdqEEEBj4Bxsf6wqUk0CmymFKlf3ogi4R53uq+vAsVfe4DPX/07jYiJER PTKFE8wPF5iy98CxyAEdHYIkoBGow0oM3d6+acM7e9VSM7L29TeE2JyzIZrJCq+LK2XC gNAIzYf/vwppQPKJAdUolsMEhe69FvbfSp2nuEMHTTz7IPGHcUVBrTzZAxg+CHmLBB9m rZxA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id v3-20020a170902d68300b001cc2293b5e0si2827640ply.96.2023.11.24.00.05.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Nov 2023 00:05:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (Postfix) with ESMTP id 61C0E8083B49; Fri, 24 Nov 2023 00:05:29 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232903AbjKXIFF (ORCPT + 99 others); Fri, 24 Nov 2023 03:05:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46464 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235228AbjKXIEf (ORCPT ); Fri, 24 Nov 2023 03:04:35 -0500 Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 810CB423C; Fri, 24 Nov 2023 00:00:23 -0800 (PST) Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4Sc6pp6yxDz4f3mJM; Fri, 24 Nov 2023 16:00:18 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id B2C711A0352; Fri, 24 Nov 2023 16:00:20 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgDX2xERWGBlUnAqBw--.22901S8; Fri, 24 Nov 2023 16:00:20 +0800 (CST) From: Yu Kuai To: song@kernel.org, yukuai3@huawei.com, xni@redhat.com Cc: linux-kernel@vger.kernel.org, linux-raid@vger.kernel.org, yukuai1@huaweicloud.com, yi.zhang@huawei.com, yangerkun@huawei.com Subject: [PATCH v2 4/6] md: don't leave 'MD_RECOVERY_FROZEN' in error path of md_set_readonly() Date: Fri, 24 Nov 2023 15:59:51 +0800 Message-Id: <20231124075953.1932764-5-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231124075953.1932764-1-yukuai1@huaweicloud.com> References: <20231124075953.1932764-1-yukuai1@huaweicloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: cCh0CgDX2xERWGBlUnAqBw--.22901S8 X-Coremail-Antispam: 1UD129KBjvJXoW7uFWfWF17Jry8CF13Xr1kXwb_yoW8Kr4rp3 yftF98CryUJry3Zr4Dta4DXa45Zw12q3yqyFy3u3s5JF1ftrsxCFyrW34xJrWkKas2v3W5 Xw48JrW7u342g3JanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUU9C14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCF04k20xvY0x0EwIxGrw CFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE 14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2 IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxK x2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI 0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUQSdkUUUUU= 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 howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Fri, 24 Nov 2023 00:05:29 -0800 (PST) From: Yu Kuai 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 --- drivers/md/md.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/drivers/md/md.c b/drivers/md/md.c index b4e21db71454..5af67748e53e 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -6360,6 +6360,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); @@ -6373,8 +6376,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)); @@ -6386,27 +6387,29 @@ static int md_set_readonly(struct mddev *mddev, struct block_device *bdev) if ((mddev->pers && atomic_read(&mddev->openers) > !!bdev) || 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); - } 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); sysfs_notify_dirent_safe(mddev->sysfs_state); - err = 0; } -out: + mutex_unlock(&mddev->open_mutex); return err; } -- 2.39.2