From patchwork Mon Feb 26 03:14:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Nan X-Patchwork-Id: 206199 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp1846322dyb; Sun, 25 Feb 2024 19:22:19 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXacIRr62TItGfZKeyyaGe34LESxuqgmjr6u17N4VGdTWQq+M8SJl7D4ZAA7+YE63bxLHC0qBZr6D/V0sOQisEuhkQ7EQ== X-Google-Smtp-Source: AGHT+IGPMLzkmwepExfhUwdhXr4jdljOEsMJmCp6T21CbH2kVKo7TYj8814+mSAU3tZtBSOY0IJe X-Received: by 2002:a17:90b:23d5:b0:29a:ce1f:bec4 with SMTP id md21-20020a17090b23d500b0029ace1fbec4mr139080pjb.3.1708917738847; Sun, 25 Feb 2024 19:22:18 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708917738; cv=pass; d=google.com; s=arc-20160816; b=IaDlmcsyMxr/WZa65TpelLanZvcg9gDZxQktfkezNR1JJO9NOWCjtSr9kdtLvEf1F3 PxDjJxw7z8VoQ6b4GQivpxRUQVJxa6Vdb54+DG1Es/WxdlRevlDKHB2dU+C+RWQVrOIW Dq82yuLKGm0CnlCxrt9RMJ2P/3SjPEkuW6Msp+i7b9B+e/7OmZj2fApxc4oIEQFuWa+q U+KfWmnyZ36nACakrh6U7SgkhbOhjCXD6hhWKcpl0Ko7arPw/vS5D7+kHNU3srXvhikH Xu5yEhW191zqHL+dKa/LQztCScnJo2uI+Lq3yF1MPbg02rhFHipyV3PZrmHWVirY8K/v lx3g== 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=Je4SLj0x94G9N+K7PjLfWx5DEO/PMJrgqqR9mAIrpOE=; fh=0dNtsen0Y4Fayp56GvNYBSuoU/QTeuYBQcKGxWKzWhY=; b=DMTKq72j/p8ibMTUlubdDrJoLCUrEELmMahf3Ffj6DwmiHivhTIMV7+5k+IhtpGUFR hhbLIxZVWOFw5gWz+iEcXafddRNMJOR+tx45CoXS6leEVPhmZ4fasrTsxUWQdSVKreUa jI6HLk4Iw/q+2SAhyYmp7OpNVDBDgDFCOzDKK0WTXT1UZPl228xwmIETxsFXzs4MarZo mAOeVBKVqhwbkOLQktLWoiZ1I27jAZ35BOuuQkfiOY7RF7AkskS7mylu5aO2+6xkPKOy jb7enHdpi4M0aUf9aOZvTjl90jhdmnBwKI7QmeeFmXQ6fxyZSASxOjYF9/WmQ4cmmI39 p6Sw==; 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-80461-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80461-ouuuleilei=gmail.com@vger.kernel.org" Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id g7-20020a17090a578700b00299592a7d25si4808978pji.104.2024.02.25.19.22.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Feb 2024 19:22:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-80461-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-80461-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80461-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 A77F6281DD2 for ; Mon, 26 Feb 2024 03:22:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1F4C81C6B0; Mon, 26 Feb 2024 03:20:45 +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 5DA5018EA1; Mon, 26 Feb 2024 03:20:41 +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=1708917643; cv=none; b=m8kXdtsW3lRcqblmHedtXM1jpix3L1O37OCmql36zTZWS7ErTcdd6GzB/UUJOsWVdA3eJnW3Vw4fUngvhu7dO0KTJAS9CNob90tg2Z4EeXnpCCJ7GN1Z1/lDy6dK0wYbeq5wjOmOK7eLyk4tTBUF7QBl4i/+IVAjCLajaClFgk4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708917643; c=relaxed/simple; bh=pxkzW3x8CNPXo/PaItuAjkfqG+f8YqJQM2EENaYKhYo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=oQFocKs/aubwEhrbieZu2kHq30S4cwavV/NbxgeQpCFkfaw7qxGUhiDdYR+8LdZT0lVk9CI5RdxgzAbqf1zQplYC/nE1wCJsY8dmVbpo/z4trP5S8qm81p3kDznYhGhfbic4dsZixLfbdx364re0O3zFCcfkmX8CXs92m08ETww= 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.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4Tjm8f6FY9z4f3kKD; Mon, 26 Feb 2024 11:20:34 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 2F4971A016E; Mon, 26 Feb 2024 11:20:38 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX5g5_A9xl7gKzFA--.13921S13; Mon, 26 Feb 2024 11:20:37 +0800 (CST) From: linan666@huaweicloud.com To: song@kernel.org, shli@fb.com, neilb@suse.com Cc: mariusz.tkaczyk@linux.intel.com, 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 v7 9/9] md: check mddev->pers before calling md_set_readonly() Date: Mon, 26 Feb 2024 11:14:44 +0800 Message-Id: <20240226031444.3606764-10-linan666@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240226031444.3606764-1-linan666@huaweicloud.com> References: <20240226031444.3606764-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: cCh0CgAX5g5_A9xl7gKzFA--.13921S13 X-Coremail-Antispam: 1UD129KBjvJXoW7tF15Xw47uF15tw1Dtw1UZFb_yoW8Aryfp3 9aqF98Gr18X34avr4Uta1kWa45Xw1xt34qkryxu3yfXF15Awn8WrySga18XrWkKas7AFZx Xa15GFW7ua4Ig3JanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUQ214x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAac4AC62xK8xCEY4vEwIxC4wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0V AKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1l Ox8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErc IFxwACI402YVCY1x02628vn2kIc2xKxwAKzVCY07xG64k0F24l42xK82IYc2Ij64vIr41l 4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67 AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8I cVAFwI0_JFI_Gr1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4UJVWxJr1lIxAIcVCF04k26c xKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4j6F4UMIIF0xvEx4A2jsIEc7CjxVAF wI0_Gr1j6F4UJbIYCTnIWIevJa73UjIFyTuYvjfUY4EEUUUUU X-CM-SenderInfo: polqt0awwwqx5xdzvxpfor3voofrz/ X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791930126877972808 X-GMAIL-MSGID: 1791930126877972808 From: Li Nan If 'mddev->pers' is NULL, there is nothing to do in md_set_readonly(). Except for md_ioctl(), the other two callers of md_set_readonly() have already checked 'mddev->pers'. To simplify the code, move the check of 'mddev->pers' to the caller. Signed-off-by: Li Nan --- drivers/md/md.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/drivers/md/md.c b/drivers/md/md.c index 82c12ecf17a6..f227a7613003 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -6419,6 +6419,7 @@ void md_stop(struct mddev *mddev) EXPORT_SYMBOL_GPL(md_stop); +/* ensure 'mddev->pers' exist before calling md_set_readonly() */ static int md_set_readonly(struct mddev *mddev) { int err = 0; @@ -6443,20 +6444,18 @@ static int md_set_readonly(struct mddev *mddev) goto out; } - if (mddev->pers) { - __md_stop_writes(mddev); - - if (mddev->ro == MD_RDONLY) { - err = -ENXIO; - goto out; - } + __md_stop_writes(mddev); - mddev->ro = MD_RDONLY; - set_disk_ro(mddev->gendisk, 1); + 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) { + if (!err || did_freeze) { clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery); set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); sysfs_notify_dirent_safe(mddev->sysfs_state); @@ -7729,7 +7728,8 @@ static int md_ioctl(struct block_device *bdev, blk_mode_t mode, goto unlock; case STOP_ARRAY_RO: - err = md_set_readonly(mddev); + if (mddev->pers) + err = md_set_readonly(mddev); goto unlock; case HOT_REMOVE_DISK: