From patchwork Thu Feb 1 06:33:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Nan X-Patchwork-Id: 195180 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:106:209c:c626 with SMTP id mn5csp259599dyc; Wed, 31 Jan 2024 23:04:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IHSp+TumkXEX2qN9QbLC8/GF7j5HWnJHjOn1/A+Xf9by/NTMBwdvOL9ELEjIoEU2vYAJ6eh X-Received: by 2002:a17:903:110f:b0:1d5:8aa5:d782 with SMTP id n15-20020a170903110f00b001d58aa5d782mr1791759plh.6.1706771050656; Wed, 31 Jan 2024 23:04:10 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706771050; cv=pass; d=google.com; s=arc-20160816; b=E0ZMhG+/YoUwHYGh+Pog4oEd1+45K4TYiASFXpy7CqqOFBVDcNQERn+7RcfWMGV+UE PWlPgUodsd2iaXh35HRcV2wC8cwlFD1NkqbsYnu63ddTHXv1FbdnMPnGw5ejbyOFDNRW DjLT47c8pyF6jiKP6XBjCQg93K8QsRk7MHx6k/98matNmz6lVT2i8ma5+MWaXWyTSISD gMIIJuuZ66UZxTNCrwdg21dF9Q6twHBu4hF6uxbqwqZE0sIvg7fRHpiuQHJmSM+XojOK X/NZlRXU7HAd8rkWbRG5Q/Aw94Vq7fksBU7WScdHoxmCdlDqTy4OqW3w5xY0A8Mp+YdF eAsw== 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=Dd/JcFp/S54D+5boQgS24d54LHi/+bb8+FacovUwvQ8=; fh=gIb9WGafyoxTts5bkAxxQ+mw5HzC/YEBs1Hu0uf0bCE=; b=U81jbInyKT0/5aIWGZGxwXIp+VU2+IEo6fDJYlesm99Q+NsffCIjOvjLMnNQ+ba0Ws XA5vhTBJLEX/mmSj9hdor1jFOyEam+fh9qV0Zk6O9AGFJ2Qhy+bXtIuTRq9TV/PT78RA 6NPeJYs8ZYevX1OD7RnFDqCYFhK4BNEdttPGXg2dZ6orssYPcJDPj2WomMltKOX2A3iH Rj7v+rXw72iYPx1OXgpftntKlMa77DuPTpGcse84sXYF0Xv/1j7cNWnEULTs3mtSFaL3 vO/aLFSw+78+OC/sJ+DnKvRHUskGY0ps1zZw6NnBXOlnrKzWuBZF2hyO0tbWObCsP9Vk 41+A==; 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-47701-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47701-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCX4hvwA5nNCGVVBfUl33Q1dOpf9MT/0lxmlaSTDRQZKhJ7q3NGgoo8AXIdf1g+kPt+2REH0ZQSGoXMbJIxToOgD4BpDpg== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id y1-20020a17090322c100b001d44769173fsi11811407plg.245.2024.01.31.23.04.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 23:04:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-47701-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-47701-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47701-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 69100B2A0CD for ; Thu, 1 Feb 2024 06:40:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9331715AAC5; Thu, 1 Feb 2024 06:38:37 +0000 (UTC) Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) (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 4289E14C5A2; Thu, 1 Feb 2024 06:38:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706769515; cv=none; b=U1V9cUGlMGH86SoDErcyfYaTyX9syGz0xVSw+oXj/Rg/3lc1ReqT0z3qBYSZNRXXLcAcQaUDpl7WQOsxD2fBPlEuDESwHEm8o4H02/bS+lwOEdcJT1B75FNyx4M4Ylm/+i/FJ2eStS9Xs37SHyv02U/LdCvZTq8SUxhIwFBoxww= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706769515; c=relaxed/simple; bh=jP4m22rQj6WvFme4jcbJ2GC1m3E6QRznh9H3QFX0PjE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=W9k7xrNN7tpPKYcRZLLlig5NTHz1ySUioHIocC0djGRBpNagZ0u/wln5B1J7SAEgTJkuJyxgpkRNO2kY2a8Ln+fhux7OskdS/fvYzd/m1g3KbppDOSZ0tH/kzaMRxzgPjshgA0yRDtBICem31aJuMRUBEo0tmJE3gxuJKfQDr3s= 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.56 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.235]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4TQTkS3zN7z4f3kns; 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 BC2711A027B; Thu, 1 Feb 2024 14:38:28 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX5g5iPLtllCl+Cg--.15155S5; Thu, 01 Feb 2024 14:38:28 +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 1/8] md: merge the check of capabilities into md_ioctl_valid() Date: Thu, 1 Feb 2024 14:33:57 +0800 Message-Id: <20240201063404.772797-2-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--.15155S5 X-Coremail-Antispam: 1UD129KBjvJXoW7tFW7Wr15Wry7tw15KF13CFg_yoW8Ar17pF 4fJFWay3y5try7GF45t3ykCa45Zwn2q3yrJrWaka4vq3WUA3yUGryrGw4Fvas3Kr97uF4f Ga1UGFy8ua18JFUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUmK14x267AKxVW5JVWrJwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_Jr4l82xGYIkIc2 x26xkF7I0E14v26r4j6ryUM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJw A2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq3wAa c4AC62xK8xCEY4vEwIxC4wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzV Aqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUGVWUXwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S 6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxw ACI402YVCY1x02628vn2kIc2xKxwAKzVCY07xG64k0F24l42xK82IYc2Ij64vIr41l4I8I 3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxV WUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAF wI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcI k0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j 6r4UJbIYCTnIWIevJa73UjIFyTuYvjfU0BTYUUUUU X-CM-SenderInfo: polqt0awwwqx5xdzvxpfor3voofrz/ X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789679161045500616 X-GMAIL-MSGID: 1789679161045500616 From: Li Nan There is no functional change. Just to make code cleaner. Signed-off-by: Li Nan Reviewed-by: Yu Kuai --- drivers/md/md.c | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/drivers/md/md.c b/drivers/md/md.c index e351e6c51cc7..1b509fb82040 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -7545,16 +7545,17 @@ static int md_getgeo(struct block_device *bdev, struct hd_geometry *geo) return 0; } -static inline bool md_ioctl_valid(unsigned int cmd) +static inline int md_ioctl_valid(unsigned int cmd) { switch (cmd) { - case ADD_NEW_DISK: case GET_ARRAY_INFO: - case GET_BITMAP_FILE: case GET_DISK_INFO: + case RAID_VERSION: + return 0; + case ADD_NEW_DISK: + case GET_BITMAP_FILE: case HOT_ADD_DISK: case HOT_REMOVE_DISK: - case RAID_VERSION: case RESTART_ARRAY_RW: case RUN_ARRAY: case SET_ARRAY_INFO: @@ -7563,9 +7564,11 @@ static inline bool md_ioctl_valid(unsigned int cmd) case STOP_ARRAY: case STOP_ARRAY_RO: case CLUSTERED_DISK_NACK: - return true; + if (!capable(CAP_SYS_ADMIN)) + return -EACCES; + return 0; default: - return false; + return -ENOTTY; } } @@ -7625,18 +7628,9 @@ static int md_ioctl(struct block_device *bdev, blk_mode_t mode, struct mddev *mddev = NULL; bool did_set_md_closing = false; - if (!md_ioctl_valid(cmd)) - return -ENOTTY; - - switch (cmd) { - case RAID_VERSION: - case GET_ARRAY_INFO: - case GET_DISK_INFO: - break; - default: - if (!capable(CAP_SYS_ADMIN)) - return -EACCES; - } + err = md_ioctl_valid(cmd); + if (err) + return err; /* * Commands dealing with the RAID driver but not any From patchwork Thu Feb 1 06:33:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Nan X-Patchwork-Id: 195171 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:106:209c:c626 with SMTP id mn5csp250991dyc; Wed, 31 Jan 2024 22:40:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IF7dnw7tuO+vo8G95756awFidrC6xnsAHgW8li+iL53qZzVzM5Avgwglk0Rk8AbBLI4HGzn X-Received: by 2002:a2e:8296:0:b0:2d0:7676:c1fb with SMTP id y22-20020a2e8296000000b002d07676c1fbmr480850ljg.51.1706769607087; Wed, 31 Jan 2024 22:40:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706769607; cv=pass; d=google.com; s=arc-20160816; b=ColxBAMtKtMuvUzTCiChY4tc5HDo63s4tSJOKCcUCLmn0Q+rSIWNYOSMCvDQwTh9BK ErVy9N7i4i0KI9dSWnzk3Hfvq36I/nvTmzrl77zEE49wC+GDB8R/SV++EsXzLmpuFUcd tUqth5vTw0Ei2vhvlo4cYc9Js6EkqXkS4+4jgyI9N2MPtzMrzL8Zdi05OH3dkO7T8HQK c6hJ96HokWk8zm+T5JoXDkSMvpldk8Xau8FekQlbYN3wrmyrx9819Akpp4C0m6XJtV/y fz2EEbRkgm4pb0/ZxBweMpHENg1UkMg7jZLOAp55/eJXkqc7S31/I7IEiWsXG998uffk UsSA== 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=mV5kHnSGeXTusfctLd1atF2pGf/5Tg7SQw3fAC/8rn8=; fh=7YAgKwDd6rEAMWXC9LzLhMbakmRYDHh+j24IND6TDBE=; b=yz/nWP/Q4IlCpaLKWqo3KbBt+a90vWA+M4St2X/h4LbQfVYgHFkIV9xu0bCKS9/BrY X+S/p2qUShIFDxEBtUEEtNIDTWYuDCbhK7pCXfz++65Kf4d9cJE1h2ZVnHpPCVhIOpGH IjzYmw4zpcK5Db8ok8s6En1/TWbPX2AbRheDciIMFqT07Mz3r1lm+l264MLuhZVXmT8r zZ9Oq52NvrUEHmoDJcD3KCmQkYp3HCIJ65fz8ue0rOFGNyXgs50srglRGwk5/81LAWEv FsxfOJPvZvwU4c5+FFGwy0c9q+8DalsexMDkEhu5Vj4QER4YVFTq0qQ5FSqSY4JnWxyR lnKA==; 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-47699-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47699-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCWsLGtgrdJpJ/f0oiEZZHwjmk/Qncg/DUIMSrfE+xuuWNu4kQc0JH40ScldATO2Q7AlKOD+LW/kJRs29/pLQB4LmFczOQ== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id n26-20020a50935a000000b0055f4df3536dsi2221889eda.170.2024.01.31.22.40.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 22:40:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-47699-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-47699-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47699-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 66A171F238A5 for ; Thu, 1 Feb 2024 06:40:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EFCC915A4A4; Thu, 1 Feb 2024 06:38:36 +0000 (UTC) Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) (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 32F0D634FF; Thu, 1 Feb 2024 06:38:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706769515; cv=none; b=ulVnwuiRnLmBAUaEa6SrHZyF/RAmWZfVIWEj/YXvgE6OiWx6Z/QgAdyaqNKoxnHgv94Or8t7MCXImzu0Z/5dDHnhx/irxHoAhwQ62JlA9K0AvYZB+drFAzRW2KW46qgXMu3018svMIgjHBkm3No7yvb3GFgtnIkvvosxxeg0nK0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706769515; c=relaxed/simple; bh=yUSpzBKNKCP4F8ui7+OgWicevcqCyLmefg0O0EI89H0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=OCj+XCWLiEFZYmD+LuLbiZeXvMybxOm2tyW8tEJ/0uP+MoHG82IQd6VT8pCf8v1s9Cps65Y+gXhyDZVukaxbq9I5LgfBjR6JUCK0bBRxsRRrRG7A9hkC5gVs99ih46UUWtcgLdcjI0IwQxt5eZ3kxSwXAXkiWj/lVtOyPhOyYvY= 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.56 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 dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4TQTkT0RQ6z4f3kp8; 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 42EAC1A0172; Thu, 1 Feb 2024 14:38:29 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX5g5iPLtllCl+Cg--.15155S6; Thu, 01 Feb 2024 14:38:29 +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 2/8] md: changed the switch of RAID_VERSION to if Date: Thu, 1 Feb 2024 14:33:58 +0800 Message-Id: <20240201063404.772797-3-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--.15155S6 X-Coremail-Antispam: 1UD129KBjvdXoW7GFyfWr1ftFW8Kw17JF4Dtwb_yoWxAFc_uF ZagF97JrZrCF1Ikr1Fvr4Svr90vFs3Wr4xuFnrKryFv3W3XF1xWa4v9wn8Xw4rJa4UuF98 ZFnxtrWFvr4qkjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbBkFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k26cxKx2IYs7xG 6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUXwA2048vs2IY02 0Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xv wVC0I7IYx2IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr1UM2 8EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0DM2vY z4IE04k24VAvwVAKI4IrM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c 02F40Ex7xfMcIj6xIIjxv20xvE14v26r106r15McIj6I8E87Iv67AKxVWUJVW8JwAm72CE 4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7M4 IIrI8v6xkF7I0E8cxan2IY04v7M4kE6xkIj40Ew7xC0wCF04k20xvY0x0EwIxGrwCFx2Iq xVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r 106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AK xVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7 xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_ Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUpyIUUUUUU= X-CM-SenderInfo: polqt0awwwqx5xdzvxpfor3voofrz/ X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789677647211996926 X-GMAIL-MSGID: 1789677647211996926 From: Li Nan There is only one case of this 'switch'. Change it to 'if'. Signed-off-by: Li Nan --- drivers/md/md.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/md/md.c b/drivers/md/md.c index 1b509fb82040..3b4e0ef49675 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -7636,11 +7636,9 @@ static int md_ioctl(struct block_device *bdev, blk_mode_t mode, * Commands dealing with the RAID driver but not any * particular array: */ - switch (cmd) { - case RAID_VERSION: + if (cmd == RAID_VERSION) { err = get_version(argp); goto out; - default:; } /* From patchwork Thu Feb 1 06:33:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Nan X-Patchwork-Id: 195172 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:106:209c:c626 with SMTP id mn5csp251054dyc; Wed, 31 Jan 2024 22:40:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IFidLo5Ww7Fte1cDQaZcwAs0nQQMzhHvezAo+sKw7UX5KWlpTM9wGW+jOuXNirAaMB1kyn4 X-Received: by 2002:a17:90b:2406:b0:295:cf9f:a1de with SMTP id nr6-20020a17090b240600b00295cf9fa1demr4082000pjb.12.1706769615274; Wed, 31 Jan 2024 22:40:15 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706769615; cv=pass; d=google.com; s=arc-20160816; b=MQh6oHMAR8p57LmP8G8OuX0KQ6hGg/yk75Sbj4Rnbj/u7SSQOqY93+vc2sqrwXV+1J WknKbFBHq7+T9dvEHRNcbQpU/DXqQK3dhzWP/Sc74ztW3S0+l7v1uWRLb/JqTxEHi4SU iVonwx9xPeloqU8KKOofVnSfnc3iekq/nhrLxIcILbwCic+mkGqY293/HuFda6p7qoV+ kSS7TKZKH1CsY8o/mVN8DU9y54WISHs1bUCp5i0xevgP5Ah89sHrWBLGhityqjSJy09s rMUeRSQhW8Ptm7v/JVWd436doWThRrl+kMwv5ByQwZ6WuGHv8vTNzA/1N5DZXuEl1rgQ ShKA== 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=Whml/PAOlxd/cENwjfSSTSdWHx1DxRJ4muI8MuoYA+4=; fh=BUEmfciNitkzR4Nw7N1H7bRcalBCxGmMBgYjxt7waiQ=; b=nRcD4ttcDtERJLbNdYbQxWz+UDbDhjpSFElGW7vdleiwxRa+iNSR2UpLhUfebFG47u QrIaiVVDIDxRwNSTNXx3d/bbGiYhh6svi1lPSR3MymM/Rhf7S6bI/HYKrhXg4btLe2BH /eHltmubZher+MLJCcmltTFPN0ZfHsX4oQwVvJkAFnASllCd401GUEZ8JJimBbo8oBgz G7MzL9cbA32DMZn1dMoHa75NnacWNIAkmPIdwxOJTxKc0GHlLA/iTLlcvmbRK4dHZ/RW LLhwORznKUlYFIK+wOKMamIAQVN2zv1aTvQ4Y5TE5v+8uN4LVwcD76wHdIryFpNvfKNF 3KOA==; 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-47700-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47700-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCUpvul+NFnTMNRqaihJXnZH55n78FNwW7l4jn2dcJowzuhE0GWWAucE/B957uAUZ0L17PNgi9lHiFrE62ayhUh20VvlIQ== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id x3-20020a17090aa38300b00290cd0b42fasi2962926pjp.146.2024.01.31.22.40.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 22:40:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-47700-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-47700-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47700-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 1600F29527F for ; Thu, 1 Feb 2024 06:40:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 382E715A4BE; Thu, 1 Feb 2024 06:38:37 +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 60F6D15703D; 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=1706769515; cv=none; b=prnX3Ox/VOnio8kpr+xwAjWQffpveHaG5N01oQLB46gIc9oFXMthLvqvhT8TyTkzES+e0EL5TG5bZEYApCzaaVAZN6P6LNVRiu26ISjXYVlR1d/7km1J4xvM6t6DpNypFpAg5booozGk0yt3RkMSXy1WYedVq3yTfMMPolNmpS4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706769515; c=relaxed/simple; bh=4UplcmqoWJJbQGP8ptq+EBVCRp0y/SiN1WKG7ZyYRV0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=tbBKxvybh2ZyWRK2RJIQRbH34FYqiIClrsljnAin0Vf7NjCQ2cwOJlgEYp4FPbo7Vggmw3SjWV0VCY/YxufQx4o9Qsmy46lgmLhgWUUPomWNa+As3k4VroBB2jdIXpkYCmSIPOY0bXdU+lY9/y3Bq0HI7oNE1lkcyfOVuerdK8Q= 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.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4TQTkR1GPWz4f3lfx; Thu, 1 Feb 2024 14:38:23 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id AE6C01A027B; Thu, 1 Feb 2024 14:38:29 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX5g5iPLtllCl+Cg--.15155S7; Thu, 01 Feb 2024 14:38:29 +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 3/8] md: clean up invalid BUG_ON in md_ioctl Date: Thu, 1 Feb 2024 14:33:59 +0800 Message-Id: <20240201063404.772797-4-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--.15155S7 X-Coremail-Antispam: 1UD129KBjvdXoWrKry5WFy5tFykWw43Kr4UJwb_yoW3AFX_ua yrZF9rXry7uF9Fkr17tw1fZFy8tF1kWrn7Z3Wa9ry5ZFy7X348GrZYgwn8Wa1rWFW7uryq vr4ayFnYyrsrKjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbBAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k26cxKx2IYs7xG 6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUWwA2048vs2IY02 0Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xv wVC0I7IYx2IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr1UM2 8EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0DM2vY z4IE04k24VAvwVAKI4IrM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c 02F40Ex7xfMcIj6xIIjxv20xvE14v26r106r15McIj6I8E87Iv67AKxVWUJVW8JwAm72CE 4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7M4 IIrI8v6xkF7I0E8cxan2IY04v7M4kE6xkIj40Ew7xC0wCF04k20xvY0x0EwIxGrwCFx2Iq xVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r 106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AK xVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Cr0_Gr1UMIIF0xvE42xK8VAvwI8IcI k0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j 6r4UJbIYCTnIWIevJa73UjIFyTuYvjfUrYFADUUUU X-CM-SenderInfo: polqt0awwwqx5xdzvxpfor3voofrz/ X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789677655791886418 X-GMAIL-MSGID: 1789677655791886418 From: Li Nan 'disk->private_data' is set to mddev in md_alloc() and never set to NULL, and users need to open mddev before submitting ioctl. So mddev must not have been freed during ioctl, and there is no need to check mddev here. Clean up it. Signed-off-by: Li Nan Reviewed-by: Yu Kuai --- drivers/md/md.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/drivers/md/md.c b/drivers/md/md.c index 3b4e0ef49675..656080086052 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -7647,11 +7647,6 @@ static int md_ioctl(struct block_device *bdev, blk_mode_t mode, mddev = bdev->bd_disk->private_data; - if (!mddev) { - BUG(); - goto out; - } - /* Some actions do not requires the mutex */ switch (cmd) { case GET_ARRAY_INFO: From patchwork Thu Feb 1 06:34:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Nan X-Patchwork-Id: 195173 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:106:209c:c626 with SMTP id mn5csp251142dyc; Wed, 31 Jan 2024 22:40:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IEkM4bKFkela53Nwny/A/XgydvXjZ7U11OFccNSDq5fwZjZ1LAaaGitOBGsdTCaVmI3ElUT X-Received: by 2002:a05:6a20:5182:b0:19a:4592:50d with SMTP id j2-20020a056a20518200b0019a4592050dmr3102432pzf.55.1706769634956; Wed, 31 Jan 2024 22:40:34 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706769634; cv=pass; d=google.com; s=arc-20160816; b=EmMOGxOUKuKTJS1jvIGWLMbJR6qozi13W6317fs5m2rNPVURgSv0aepE3RtDLTVxOj +F9bkyfwAWv1k8xyFVvs6nhnaQv3i+wuylFx6bmxdkZHZtxONRpuSaz4JHpRsMwUy4qz 6nOVOh0eeOdLthlI+wfXPsvxgElEbb8o4ABbBHCB7BKqeusBFY2NNFxA3GXDzyLdBuIA mD9YsTWjwR/d/CyGSX613pfa//6tY8xz96+7dZd8O7OfRKBtTmd+ET2marlgsgzkaCuO dNT54k7mKHIx0EyCSYsYjl76QfU6ROZsa+m16FAfVKYtuNCmOJN7aenjyv5kB7xRa+1M cI1Q== 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=XYihhXIhDVsD4kD/O+ynLlfkDdN6N035tC/5+gbcXl4=; fh=3GGZl4/S5nCIaaAyE2q1M5uW+gtqkspqUPHkg8aRFEA=; b=MCEdWT8ndUpakkmr7BBEywfO+zMkTUU1HUd7ewAj1USYHeEsQqFvwT0nrdUglaH6fi eU8QnDjZSgp8jhxwVeAAIbTZdghTC/i+dfeEMH8c8eV49j0R/jqOvUxDgVBPfMvEcMJj 1NFC4WxVFhrplu/1Y9ZKPNuuszsXxSnt2p3LJPT1hRB3TqhHn46sf3b6WjoolTcllPD6 lYDop3rlVvbCYU0ABX3n8iewDHt2XNVnCpcl/W4EEFw1BvZbbCnQPMlydBuXM+/7Ylpo xA7Ms4tBEOexS9vRImK4y58bTY+rpISMmU5/pNfD8GUdY1zi+1aAs5PB8gkwjyeO4oZt z1yg==; 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-47702-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47702-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCVeiQ4XAs2lkuVh6aOaUAcIH6ZNtEsh5uUklhTPx4CAiZjCfln30TcgA3HgWgsN74RFXqjGU0B251mhBA5xxO5DZ7+gyg== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id t13-20020a170902dccd00b001d939abde75si2131400pll.48.2024.01.31.22.40.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 22:40:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-47702-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-47702-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47702-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 B989F295394 for ; Thu, 1 Feb 2024 06:40:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9960315AACA; Thu, 1 Feb 2024 06:38:37 +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 8B971157050; 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=1706769515; cv=none; b=lc91wCJC5hTnCVEt6K2eDXis4eY2RcvAPUIBKTTr/ANjIwvOVilHaIUpkkwYtJkZaxBuLBssWpr8gxx+wRgIRPoCMhw3iPLmnP6B6AJjCV6NQGLu/04j7xqJBiFGs+VMPzOA7UAhLGiAaKm6EH9FPYAyKfj2wl2cHmbZVOwC76w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706769515; c=relaxed/simple; bh=ftZkeplxga5glU/a1AQpEFCjQrpl9nc9WPVPM/ByKWA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=uyAZb1doYm1r1nBdbNYawulY0phNMljDF1JF8S0mVz1P86v4QFGhBPpzvNxNenhn6kqc+wd1+DpbI6zH2TD2o9Q6eKAZf6B2Ba7Mvz0e129bp0BxGUVvbcKPmVrjZxMJ2S2rz3Ih0uAKkC/GdPp3LjXNuv32EkrdsFaIoA73lEg= 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 4TQTkR4dF1z4f3lWC; Thu, 1 Feb 2024 14:38:23 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 2DB2C1A0175; 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--.15155S8; Thu, 01 Feb 2024 14:38:29 +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 4/8] md: return directly before setting did_set_md_closing Date: Thu, 1 Feb 2024 14:34:00 +0800 Message-Id: <20240201063404.772797-5-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--.15155S8 X-Coremail-Antispam: 1UD129KBjvJXoW7tFWfXw4UKry7uw15CF48JFb_yoW8Zr4xpF ZagF9xtrWrJFWUKr1DJa4DZFyYqw13KFWvkryxCryjvF9FyrsxZryFg3yFqry0g34kA3y5 tF12qa15Wa4xJFUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 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: 1789677676980085990 X-GMAIL-MSGID: 1789677676980085990 From: Li Nan There is nothing to do at 'out' before setting 'did_set_md_closing' in md_ioctl(). Return directly, and it will help us to remove 'did_set_md_closing' later. Signed-off-by: Li Nan --- drivers/md/md.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/drivers/md/md.c b/drivers/md/md.c index 656080086052..5442e8e3c161 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -7636,10 +7636,8 @@ static int md_ioctl(struct block_device *bdev, blk_mode_t mode, * Commands dealing with the RAID driver but not any * particular array: */ - if (cmd == RAID_VERSION) { - err = get_version(argp); - goto out; - } + if (cmd == RAID_VERSION) + return get_version(argp); /* * Commands creating/starting a new array: @@ -7654,23 +7652,20 @@ static int md_ioctl(struct block_device *bdev, blk_mode_t mode, err = -ENODEV; else err = get_array_info(mddev, argp); - goto out; + return err; case GET_DISK_INFO: if (!mddev->raid_disks && !mddev->external) err = -ENODEV; else err = get_disk_info(mddev, argp); - goto out; + return err; case SET_DISK_FAULTY: - err = set_disk_faulty(mddev, new_decode_dev(arg)); - goto out; + return set_disk_faulty(mddev, new_decode_dev(arg)); case GET_BITMAP_FILE: - err = get_bitmap_file(mddev, argp); - goto out; - + return get_bitmap_file(mddev, argp); } if (cmd == HOT_REMOVE_DISK) @@ -7686,13 +7681,11 @@ static int md_ioctl(struct block_device *bdev, blk_mode_t mode, mutex_lock(&mddev->open_mutex); if (mddev->pers && atomic_read(&mddev->openers) > 1) { mutex_unlock(&mddev->open_mutex); - err = -EBUSY; - goto out; + return -EBUSY; } if (test_and_set_bit(MD_CLOSING, &mddev->flags)) { mutex_unlock(&mddev->open_mutex); - err = -EBUSY; - goto out; + return -EBUSY; } did_set_md_closing = true; mutex_unlock(&mddev->open_mutex); 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; } From patchwork Thu Feb 1 06:34:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Nan X-Patchwork-Id: 195176 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:106:209c:c626 with SMTP id mn5csp251683dyc; Wed, 31 Jan 2024 22:42:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IGfHL7Q0qWl8dOaTEbm7dNM3b/KvSA6z7Td4122tCPDPhH9149dlxqfppr1rAWbih9wV+XS X-Received: by 2002:a17:906:2b5a:b0:a36:6356:7ab with SMTP id b26-20020a1709062b5a00b00a36635607abmr3206667ejg.14.1706769730337; Wed, 31 Jan 2024 22:42:10 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706769730; cv=pass; d=google.com; s=arc-20160816; b=omKHjiKaf6QzSOUkb58sNp6H8UCdHURAopyWf5XoC00NQgqUHOaD5EzeIUwwlzYuSI Jlovor4obRbos6EY9Mze/VQRS0MQTiMmpUmceIO55gMkW+y+gKYXGaK7JBJPgO8Q8GCG yzp7WGfTs47NvnphCOqktJmJdyCplwYkApurqxQqr2e5beh9BD/9EDhgkEMCOouTTAjh /gf7TMcj1kDAToJTPE+MAUcenugNV0SVQw/xWksB/3IaIQRjhd/eOS1U2GKapWOb8X8Z zEw4K6FpGmEWKmX9TCCPSEykb3FzARxC64TzZGD1co5PKooni5QJvREwADu2yfpwgqt/ 30Vw== 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=B5TYYPoI1kzkGlk3xN9B9mbdrtFXPjQTKbf3XritLB0=; fh=VB+z0Z3LDUYoIm7EMEfJYNjNqehOTtrc/jeim7Nq4pM=; b=I9xX/1j2ALx87O3jOqY79PDBWOrMdp/lEgE1piLQaxyy9b2k3KpK6TBOT7uI12NTzr iCYEMV9mb2BTJTObFUscuf+rUpf97m5NIeB6ThoYdiP8hlQV2gffzRo6YsqtUSQ8+Osi z689EqTXXhC+Oe51xd6HmQb2pm/83B4IbvpDadAtkFk3ZM4wjkE1ovMCc9QpkfqJF5T1 /4Rsmoan/hOxpDSBXqYQmYaXL9nTd14x1aHzQ8wGDB1GAeGX8Otcy9RCOeMahy7lNI1S n7mr3b/LJnlJ3HsBgbq9QZKMsxP215rQaQ4/CqyH+Ja2JNQoLV1uqrOCj+MnYFN28r4A UDZg==; 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-47703-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47703-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCW1d0QO8Bvp3Qm2ieiOGR9KXQsAX2Kxt2mpN2s4hDafemdMj4RIKu1aIejnzOR+XrOlDNchTwPknvxcCWuUBysvt8WjsQ== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id cx10-20020a170906c80a00b00a30f3e88390si6294040ejb.623.2024.01.31.22.42.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 22:42:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-47703-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-47703-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47703-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 A6ACC1F2218D for ; Thu, 1 Feb 2024 06:41:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9C50A15B119; Thu, 1 Feb 2024 06:38:38 +0000 (UTC) Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) (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 E2F2B157E78; Thu, 1 Feb 2024 06:38:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706769516; cv=none; b=TDtLAiG03cMjluqUmbMEIL1irTIaeZ8kZLzYVrbODbtx2zZ7VKAuqqJKN5X4qrgLdSLLIwCSGjK7+lFSNVT372BiFfPs2XNJLgUW+8F16rlYh/+ccybcTzzl4WgVzQLCpStXW4hYc25u6I/qmMfozzz7yjB88TCpetOOBZWWI2w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706769516; c=relaxed/simple; bh=FgoOAkQGCz2LvCk0WpcgjLn7q9QSD5DfzKqFyR6V3E0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=X2tz7ubdaoYT2JvTOD/6+n3Wht6xJn3MhsGqts8U91fuKbQlAd4f7kSTquU9OOVO4xsmtnME51ereFXRD/t+oxNl0hpXiT3q0P4Znqm0NXGk08FGiuwXe8FZ3lLDHDzTuAnOya6T6UviRN7dGnJ86PU4q0DgQyrhQcIf6rr9WEk= 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.56 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.235]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4TQTkV6RGWz4f3kpX; Thu, 1 Feb 2024 14:38:26 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 1B7A81A0232; 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--.15155S10; 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 6/8] md: factor out a helper to sync mddev Date: Thu, 1 Feb 2024 14:34:02 +0800 Message-Id: <20240201063404.772797-7-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--.15155S10 X-Coremail-Antispam: 1UD129KBjvJXoW7tFWrJrWfurWDJr17JFW5KFg_yoW8Aryrp3 yftF9xKr1UGrZIyr47J34DZ3WYgw1Ikayvyry7Ca4xZF97ArsF9ryF9ry8GrykK34xAF4D tw18Xa15Wa4UWr7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 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: 1789677776838902360 X-GMAIL-MSGID: 1789677776838902360 From: Li Nan There are no functional changes, prepare to sync mddev in array_state_store(). Signed-off-by: Li Nan --- drivers/md/md.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/drivers/md/md.c b/drivers/md/md.c index deee004b8f22..4c7a0225f77d 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -515,6 +515,24 @@ void mddev_resume(struct mddev *mddev) } EXPORT_SYMBOL_GPL(mddev_resume); +/* sync bdev before setting device to readonly or stopping raid*/ +static int mddev_set_closing_and_sync_blockdev(struct mddev *mddev) +{ + mutex_lock(&mddev->open_mutex); + if (mddev->pers && atomic_read(&mddev->openers) > 1) { + mutex_unlock(&mddev->open_mutex); + return -EBUSY; + } + if (test_and_set_bit(MD_CLOSING, &mddev->flags)) { + mutex_unlock(&mddev->open_mutex); + return -EBUSY; + } + mutex_unlock(&mddev->open_mutex); + + sync_blockdev(mddev->gendisk->part0); + return 0; +} + /* * Generic flush handling for md */ @@ -7685,17 +7703,9 @@ static int md_ioctl(struct block_device *bdev, blk_mode_t mode, /* Need to flush page cache, and ensure no-one else opens * and writes */ - mutex_lock(&mddev->open_mutex); - if (mddev->pers && atomic_read(&mddev->openers) > 1) { - mutex_unlock(&mddev->open_mutex); - return -EBUSY; - } - if (test_and_set_bit(MD_CLOSING, &mddev->flags)) { - mutex_unlock(&mddev->open_mutex); - return -EBUSY; - } - mutex_unlock(&mddev->open_mutex); - sync_blockdev(bdev); + err = mddev_set_closing_and_sync_blockdev(mddev); + if (err) + return err; } if (!md_is_rdwr(mddev)) From patchwork Thu Feb 1 06:34:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Nan X-Patchwork-Id: 195174 Return-Path: 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 (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 ; 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: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX5g5iPLtllCl+Cg--.15155S11 X-Coremail-Antispam: 1UD129KBjvJXoW7Cw4UuryxXry8Xw43tFW5KFg_yoW8WF13pF s2yry5Wr1Ut34ftw47ua1kGa45W3WxKrWDKryfZwn7ZFy7A3sxWFZ0gF4YvrykK34fG34f Jw45AFnYgFyxtF7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 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: 1789677729780958920 X-GMAIL-MSGID: 1789677729780958920 From: Li Nan 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 --- 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); + 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 = From patchwork Thu Feb 1 06:34:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Nan X-Patchwork-Id: 195175 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:106:209c:c626 with SMTP id mn5csp251456dyc; Wed, 31 Jan 2024 22:41:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IFuhg0WQIc5geK9yRbvFdsC+xHcGn4SpvVAGxmcxE6rbYUnOct9q3LxHGM+/3mCfydtm1Te X-Received: by 2002:a05:622a:130c:b0:42b:ead0:8dae with SMTP id v12-20020a05622a130c00b0042bead08daemr4170250qtk.41.1706769692439; Wed, 31 Jan 2024 22:41:32 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706769692; cv=pass; d=google.com; s=arc-20160816; b=J+U6qpCF5Q2uuNNAZtlpbs2OJnVZerbq1ZV+aNtgkqUjL6QCaOKwywWQA+DRPTKnl8 kxOsro43lksc+briQUK94JDR/9y0oDoMlGiksQggjjPeSkzlAPo60wGm2RCHHNnn22pe kNgQ/yCZJlTzUnacggpOqwYWvKgx2mIh0iRJSYbAEj4VbZJDprCfKkqkkFdU0hoglyf3 pZUqkEnL8felxbQOMx5cqhf/xX+69Cm9OQeGaqJPn6JnNFbUb1wNo2bVFJiqlvceRHX6 otGc0KdBJ6dIfBjnZJrQu+CHf7gQ4hnCPicBzjhmkVMjLXgPGbwh3qWkZZOyWyhPte18 XX4A== 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=3SXxTnFBVTqCAXn5RllOsnrsiFgyyXlK9NLh5Si5qxk=; fh=BWG647qYghb0Un8kfkFd6t4XMis8pbcuhoLmiJQHVCA=; b=YxcCxlJC88OrFV1h30Z1jLVlX7qRaJgP2MxEImwYzGZD0JZ+SvlpexN0gF3jZIePee MkSM7LXf24AvzI110QvyWfsZ3uX14ze/G5u+YbUHTp/qNm+5BZ4fzlOWct7f6aOEX1Fw JrOeKjeqvkE1wRH/kBG/AfsWzkyOGnEAMfbV7oqsUrUEOKDZ6PsMK+Q3IXrkACUKFZLC A/3SSgVsH1e2If6iJGc6WAaILp3L/VjTW4csfkdsFDutPbxdLepRwevIjmeBL+Cc/S6l 0yZk18K7if6gqej3hVVVNm2GPJEUULqaCl8zt3P+WCWy7NCW4rJphU0n2YI5uMPVjZGY Ic2A==; 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-47706-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47706-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCW1Mdfp9Df2d9Y4/EGPFy2kur8/95pwtRKFWVhIDRsQHPUfixPxuHNMF1pHZo+aOSPbOyp/+Dxu0dF3nfXSkXsf7CsSpA== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id x15-20020ac85f0f000000b0042a68cb923esi14018012qta.602.2024.01.31.22.41.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 22:41:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-47706-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-47706-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47706-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id CADFC1C2386E for ; Thu, 1 Feb 2024 06:41:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5B57C15B97E; Thu, 1 Feb 2024 06:38:39 +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 3CDFC1586D5; 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=CzNyWltf24/5ZLVYoxHVJwzhC7EXnZQBA8oiMtnvoD6QoRIXIknu9xjWQU1RJjlbNnkaVW45xXW+KADeeefzeGdqctoyWndUon+OyVdcg2trH3WbBZ6pV4iGpMblWjFlLx4puo4Kk471A85+ABNEUOUl9J46KYv5BNWJQWU/Nw0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706769517; c=relaxed/simple; bh=PHJvhZQzij43APMcWRsyeSUFLWsPh9To9Ao12iS0SWE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=n2iNyUI8YJ/sVcB2wvqEjim/KKzl2Dv54kQGueLXbgPevpXCB3kmRvMtffaeS1jgXR8fBmGl6gBRtd7+DZqqzHgaTc2h7vIKnwFnifivV/80mUgVTy4goPrvsk8gEqc73fkmD4WbmYtKD/5w8b08g07FzhE0aUXlgrhwowoLPeM= 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.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4TQTkT3VnVz4f3m7J; 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 07BF81A027B; Thu, 1 Feb 2024 14:38:32 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX5g5iPLtllCl+Cg--.15155S12; 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 8/8] md: check mddev->pers before calling md_set_readonly() Date: Thu, 1 Feb 2024 14:34:04 +0800 Message-Id: <20240201063404.772797-9-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--.15155S12 X-Coremail-Antispam: 1UD129KBjvJXoWxWr1rAF43ZrWUCr17Jr1fZwb_yoW5Jw4rp3 9aqF98Gr48Xryavr4Dta4kuFy5Zw17ta4ktry7W34rW3Wftwn8uryFg3W8JrWkKas7AF45 Xa1UJFW7ua42gFUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUQ214x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAac4AC62xK8xCEY4vEwIxC4wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0V AKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUGVWUXwAv7VC2z280aVAFwI0_Jr0_Gr1l Ox8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErc IFxwACI402YVCY1x02628vn2kIc2xKxwAKzVCY07xG64k0F24l42xK82IYc2Ij64vIr41l 4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67 AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8I cVAFwI0_JFI_Gr1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4UJVWxJr1lIxAIcVCF04k26c xKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAF wI0_Gr1j6F4UJbIYCTnIWIevJa73UjIFyTuYvjfUopBTDUUUU X-CM-SenderInfo: polqt0awwwqx5xdzvxpfor3voofrz/ X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789677737211064236 X-GMAIL-MSGID: 1789677737211064236 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 | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/drivers/md/md.c b/drivers/md/md.c index 86becf0015f5..2976cf778df3 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -6412,6 +6412,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, struct block_device *bdev) { int err = 0; @@ -6441,8 +6442,7 @@ static int md_set_readonly(struct mddev *mddev, struct block_device *bdev) mddev_lock_nointr(mddev); mutex_lock(&mddev->open_mutex); - if ((mddev->pers && atomic_read(&mddev->openers) > !!bdev) || - mddev->sync_thread || + if (atomic_read(&mddev->openers) > !!bdev || mddev->sync_thread || test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)) { pr_warn("md: %s still in use.\n",mdname(mddev)); if (did_freeze) { @@ -6453,20 +6453,18 @@ static int md_set_readonly(struct mddev *mddev, struct block_device *bdev) err = -EBUSY; goto out; } - if (mddev->pers) { - __md_stop_writes(mddev); + __md_stop_writes(mddev); - err = -ENXIO; - if (mddev->ro == MD_RDONLY) - goto out; - mddev->ro = MD_RDONLY; - set_disk_ro(mddev->gendisk, 1); - 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; - } + err = -ENXIO; + if (mddev->ro == MD_RDONLY) + goto out; + mddev->ro = MD_RDONLY; + set_disk_ro(mddev->gendisk, 1); + 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; @@ -7766,7 +7764,8 @@ static int md_ioctl(struct block_device *bdev, blk_mode_t mode, goto unlock; case STOP_ARRAY_RO: - err = md_set_readonly(mddev, bdev); + if (mddev->pers) + err = md_set_readonly(mddev, bdev); goto unlock; case HOT_REMOVE_DISK: