From patchwork Tue Feb 6 08:55: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: 197264 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1409531dyb; Tue, 6 Feb 2024 01:02:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IH59M+mQt6vodCORpVtddB38J6+tjHRJBMfjl/aB65SHJHPB/ozQU8LhnS39ldZ+5C2T0vE X-Received: by 2002:a17:902:6845:b0:1d9:259b:5708 with SMTP id f5-20020a170902684500b001d9259b5708mr1027921pln.13.1707210122909; Tue, 06 Feb 2024 01:02:02 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707210122; cv=pass; d=google.com; s=arc-20160816; b=OTHOR21D83iQBmm7HeyQ/cxX+0JJ4lEUiDF2XcBvVmGiidUztHkXNUh0WY9SIsYXaL uhQnt0Ab+lbMz5xNO6zWmzdqZKVd1ccrZzLROKcCPxxeZ7EdsVeSiVOKMjtRaRRDlxp9 SjfyHpNWWEQJ2hR/xkZYlHfrWCFEEJOMidQopUKeHdJ53WyV6tvccb8Ngtmfva92KFj5 zYXC0Bex2uT1zrb9qM00O61M7q8jmO1QFr2O2w3UnojJbkqmrpZ3P+hkzfItwT3SKKdY e/+jvwMigXUOdYvk2G8UEMBLJUGYXOXIRJlPJag4iN4xNj+vW90k45DEEef+TwVy9MB5 kqSg== 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=hAJEQBh1UAdSAXxmugIPhu4WHImxGeK4g+3GCVLSUQI=; fh=hTKEQOkhwW9hSIkmCasZkEPto4aEiZdTaCDbUf/Sujk=; b=g3S/NmRnqU0rcQcYpdoz3PNB4B9RAusEr0sPbYRdq/YfKySQzmKviiJLZqZ95vcKVs w2xbRMAuoVDfGNx5QjmCjw9dfkennHoETEAo+8A5m+3BLYKT3zkjT9/QG27A56VlRgjN 09csK9xZ1oE2O8UH+kQ+mcFbvy6qfLemdE4aYxgzXpfp7h7A2mXQksmC0Di8XZvUCmEh DqanmBuVVx/5X/L/oN83M9DIzJ9vccmoyXeqlacIYo4fJWzx50pPnZRw2385rbuGdAqY 1miWE4SMM48fUjbu1IiVohIYzliaTP0LkTmjb44CrG/ZbKeBv5nbHijsslf3Apytub+u JBaA==; 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-54545-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54545-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCU4XMo8+zL1eLeDpeRYwXKHwYpvdTPnUNf+XQreg3EhQV3d/+TGR/NRWbGYZzkJ8cJgtExz4iHdo2pChPDH88WPjvM63A== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id u16-20020a170902e81000b001d9c367205esi1364048plg.73.2024.02.06.01.02.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 01:02:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54545-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-54545-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54545-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 F3B11288B11 for ; Tue, 6 Feb 2024 09:01:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 90A0312E1F7; Tue, 6 Feb 2024 09:00:00 +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 66B7A12D151; Tue, 6 Feb 2024 08:59:56 +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=1707209998; cv=none; b=MbG6wg8hZNwA/4l4gkP3A+pUYQiHDY7f2icdUdutX0mVBBoQKSNhRkocQvY0Oe13u0wmxOfltzBlvw/lFIiTSEdBqspxS3RpCpU1FAHGR9Sx9bgN3XyfltpxOIegZsqSqGUdBolx1Fo6N3OtCaPdeqwP4SOVSIRJuvXIwPtkb7k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707209998; c=relaxed/simple; bh=fabXSuSbPNoZKn2OMKk7PLCdkCHW8zqLdDk1CeYEfW8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=uphC93rb+DOJuuoo48RTccwm7+GEl6tdVyahzNpZp5qJad6ToscYoYPfcazme3nhSLkm44lGdPNHpYtp8IsqnYQLyz1zTEx8oN2deOV4dOqlAC/0J4nDgLXQCBsMjhAj4e0rWTDStH8t5PeWrS+5IiLfEQJArDoY4cORMTMCaWI= 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 4TTcdL1q9Nz4f3kKX; Tue, 6 Feb 2024 16:59:50 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 069D11A0C47; Tue, 6 Feb 2024 16:59:53 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgCXaBEG9cFldA+QDA--.34552S5; Tue, 06 Feb 2024 16:59:52 +0800 (CST) From: linan666@huaweicloud.com To: song@kernel.org, mariusz.tkaczyk@linux.intel.com, shli@fb.com, neilb@suse.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 v6 1/9] md: merge the check of capabilities into md_ioctl_valid() Date: Tue, 6 Feb 2024 16:55:03 +0800 Message-Id: <20240206085511.2841555-2-linan666@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240206085511.2841555-1-linan666@huaweicloud.com> References: <20240206085511.2841555-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: cCh0CgCXaBEG9cFldA+QDA--.34552S5 X-Coremail-Antispam: 1UD129KBjvJXoW7tFW7Kw1kWFyfJFy7GFy3Arb_yoW8AF15pF 4fGFWay3y5try7GF45t3ykCa4rZwn2q3yfJrWaka4vg3WUArWUGryrKw4Fvasakr929F4f Ga1UKFy8Ca18JFUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUmC14x267AKxVW5JVWrJwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_Jr4l82xGYIkIc2 x26xkF7I0E14v26r4j6ryUM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Cr0_Gr1UM2 8EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0DM2vY z4IE04k24VAvwVAKI4IrM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c 02F40Ex7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE 4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7M4 IIrI8v6xkF7I0E8cxan2IY04v7M4kE6xkIj40Ew7xC0wCF04k20xvY0x0EwIxGrwCFx2Iq xVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r 106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AK xVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7 xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_ Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUrpndUUUUU= X-CM-SenderInfo: polqt0awwwqx5xdzvxpfor3voofrz/ X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790139561826511329 X-GMAIL-MSGID: 1790139561826511329 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 Tue Feb 6 08:55: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: 197261 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1408934dyb; Tue, 6 Feb 2024 01:01:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IGzztPH0Ajx6i4DNrdY7QmGa3AfaIiD0xG0lMg0eqyCJNtsJVeR8BUSV0PrdNUuCbZ6Ona+ X-Received: by 2002:a05:6808:3020:b0:3bf:e5be:316 with SMTP id ay32-20020a056808302000b003bfe5be0316mr511229oib.25.1707210066561; Tue, 06 Feb 2024 01:01:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707210066; cv=pass; d=google.com; s=arc-20160816; b=gaPgLtvuq+0seKprOnh2lpcTnciZ6Ux2Odz8hJzHx+rpiaN7suR952P7EAi/ZKqb0o jKdb6zhofMcnLlL040muy7kONne3N2d0kj2l1QWnJTdlA4xm5oKH1tK5Qc/MeUNQwV1a lTTxE0PHQIFVg2KPVEvtveOA/HTq9SjAJ4o1Iyi3g7R4tTiFuPVxefpAB28MEK93QInL lZgY//RtE05JGSpff85ZWtDzG7UScwhvOGr3giUVGUTq1LTzrAcdQR0DJZcpJVyEkt1P AZzVE/yuTuwdBFJW8Wmos3kc5D5oYNCoNeECbcJwGaW6dyXkMOwDEuYPWVx2VhF0FKOu 5C2Q== 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=LoW0pKOy5oPGST/bz32kJSg1pxGE1sQqgMnhxmzeUoY=; fh=yP8QqlTqpUXPbvYZpOoM+CMP6McTqzwqtbv1S4GLdC0=; b=CJQ6qEFIsdFRzX1TAWo1IoQv/QKWYPyCtaRzURYtzjV05CDUGl4NRHDhvlyC97K1j4 h8V0kM1YEqLj0LNc7648YTtx3Xm/qvCWyLwRgRcB6EtSBennknVGQ6cP6RjIEhIQRdCY fwGFqbA1aUcv9MbbJWZ9dKL+DcNKSdoCUr506DCiKC2rw5FzqXCuWhXJWChkUG4DsfD+ Ats8y6Ihd5gvkdIhlxf9mDdYssoo44GmogZtk6zwWfVzlxG9U2hsEZXctz1hbeB0odWB BFD/AEV3QoLcC43sLUdNzgdvasCC31jetBSeZcx3UCMxaxsuqhCvAsI2bkffYtXldUwG OdQQ==; 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-54544-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54544-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCWOtQL0N8NlgOE/gA+agV+8Zhvb8mN86OM5VZAC9VpaF6xNK8SE5KuhNwS26w8ApEYam90VnPAycYBN0BZWKhxtxrYWOw== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id g4-20020a37e204000000b00783ff7daffcsi1832427qki.439.2024.02.06.01.01.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 01:01:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54544-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-54544-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54544-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 55A641C21B58 for ; Tue, 6 Feb 2024 09:01:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4698212E1DC; Tue, 6 Feb 2024 09:00:00 +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 66BCA12D152; Tue, 6 Feb 2024 08:59:56 +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=1707209998; cv=none; b=TmpQKQzHO8aV19VvrEv4w+P3q5HHv3M6bOMxhwWf5MyxoUymdkG5uYiYsX8TPd8q1cw/hUuurpIq1apESDDusd2aMd+RAnQ5RHPlH3tIvj0r/9TdW2HspBkDM7rQpUemuQBqqHNBdP5kF+UfzgMDiMjuWJ+JylSCNQVK7Xpnp/Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707209998; c=relaxed/simple; bh=oTJkRyyWHPEDWjIBAjPNXcElGoLqKERTnxTkUCe0WUY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Ml4K9snl5Fc6Fxltr7azXn7y9BRAYA5JwSMprepAdrf/X4w2m6EFplg66Rghm2isQlMq386Cm3daASpq0zpsQtRkZhFjng/Co5pAfLzkjVmJYwXJw8FZs0UlxZe8OcHM+Da6qqWmQcAnvaW4iI5N+h+dydR8UzgVgRhhKg2zUp0= 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 4TTcdL56Fpz4f3kKg; Tue, 6 Feb 2024 16:59:50 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 777CA1A016E; Tue, 6 Feb 2024 16:59:53 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgCXaBEG9cFldA+QDA--.34552S6; Tue, 06 Feb 2024 16:59:53 +0800 (CST) From: linan666@huaweicloud.com To: song@kernel.org, mariusz.tkaczyk@linux.intel.com, shli@fb.com, neilb@suse.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 v6 2/9] md: changed the switch of RAID_VERSION to if Date: Tue, 6 Feb 2024 16:55:04 +0800 Message-Id: <20240206085511.2841555-3-linan666@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240206085511.2841555-1-linan666@huaweicloud.com> References: <20240206085511.2841555-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: cCh0CgCXaBEG9cFldA+QDA--.34552S6 X-Coremail-Antispam: 1UD129KBjvdXoW7GFyfWr1kJryDWr4fXFyxKrg_yoW3GrX_ua ySqas7JrW7CF1Skr1Fvr43ZryYyFs7Wr4xuFnrKr98Z3W3Zr1fWr1kGrZ8Xw4rWa4UGF98 ZrnxtrWFvr4qkjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbBkFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k26cxKx2IYs7xG 6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUXwA2048vs2IY02 0Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xv wVC0I7IYx2IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr1UM2 8EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0DM2vY z4IE04k24VAvwVAKI4IrM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c 02F40Ex7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE 4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7M4 IIrI8v6xkF7I0E8cxan2IY04v7M4kE6xkIj40Ew7xC0wCF04k20xvY0x0EwIxGrwCFx2Iq xVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r 106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AK xVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7 xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_ Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUvAp5UUUUU= X-CM-SenderInfo: polqt0awwwqx5xdzvxpfor3voofrz/ X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790139502893270278 X-GMAIL-MSGID: 1790139502893270278 From: Li Nan There is only one case of this 'switch'. Change it to 'if'. Signed-off-by: Li Nan --- drivers/md/md.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/md/md.c b/drivers/md/md.c index 1b509fb82040..ea147348bd24 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -7636,12 +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: */ - switch (cmd) { - case RAID_VERSION: - err = get_version(argp); - goto out; - default:; - } + if (cmd == RAID_VERSION) + return get_version(argp); /* * Commands creating/starting a new array: From patchwork Tue Feb 6 08:55:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Nan X-Patchwork-Id: 197266 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1410018dyb; Tue, 6 Feb 2024 01:02:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IERREv7b3w0XN45t4WYk+SlxtFTyi9geUVx4Wyr11CKGG9T0Rk6aBVaqniLuPymJxJ6iM8Z X-Received: by 2002:a05:6a21:4982:b0:19a:ef21:60a0 with SMTP id ax2-20020a056a21498200b0019aef2160a0mr933129pzc.25.1707210175031; Tue, 06 Feb 2024 01:02:55 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707210175; cv=pass; d=google.com; s=arc-20160816; b=bU8PCvCCgBXBHXkDnOs5O7BjAaYX5uVilbWjeAcg6kTFhItB1QtMFewgjwqdMJBseP SocQWnYkUfZFUKN7dGGWaoTCMmcp+Cu1iyKh09dsgHjnlmD+fh91/8NImimfi9ok5Epl SX+neNksOV7wlAr/Tzk7niD86KdXyb1UTl+HWAY56PcYfJ3TtYfmt8VN/S08GvIQ3U6y XJXxULnkOHKyhqpi2NciKMkOFrav+2FKJqU+CfZvk60UOrSltM+reHM0RO9fP4v3IF7p cY1E1Q7ohdj15bzEEw2N1kpVvJv7/Lvlemf3mbSxA7uMxBlP+Gv5GHIekopviCU8o/Zy OjBg== 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=LNRKlaOn8e9jKeUiYfnBvG4mGWjnY1TMonZlah2UBfY=; fh=KDZT1HwhZl+Hax4UGSkUcbO79wxT6WkWcgxCp1vhjFU=; b=hYcL2Sdevdws4rRsNqCdI57agGYUJU61W4ExfRhgde0Ahq2ykM5OCGgTYGh1xkJ0Fd pInng0mbT4Hn3q4fgvwNjDGDC1FXBfywtxqiaLjAc+n3pn1Fy/HwAqRMvgomVnLXt9Wh 42U4QVpR/Fzu0E1hORcyPdcWe2CSIH05JaZq6l4NKFvofdQbWwIDJL1GU1lh2INij9tI xTrAVyFLqxG+aIY1QJpcucMl65kCWMu/0ROOkNbeHc6LgMDN+PFcwiWshobMXOmB80kT SMVA9jH/1YYWM4P4QC6YlT3pKBEMxUqhnVZ+4sSVDzsDpsbwNVKZjqx8FaYfONTqgdhx ILzA==; 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-54547-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54547-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCUGe7akyVDCc3EA+2FWglJ+ms1sSkD9DqoszMvjYM1TTJ4DKiBvGRAI/SBQRbi8aXOyOxMY4Uo3F21BaS8f73YBbFaSpw== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id ei2-20020a056a0080c200b006dd8a272463si1284552pfb.246.2024.02.06.01.02.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 01:02:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54547-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-54547-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54547-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 4FAABB22C91 for ; Tue, 6 Feb 2024 09:02:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0AB4E12F380; Tue, 6 Feb 2024 09:00:02 +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 06C7C12D161; Tue, 6 Feb 2024 08:59:56 +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=1707209999; cv=none; b=fencTMNi6vaTFb5KFKLmeccDDYpwF4rfBSE52xAOtAWDCcpraeWhp/ouM3XuwIGvz5IRBIcDDLLXlRdiMJ8YJ7gNdrEYQmcNpklo6PCfk1ruAQm52o/tk2tCQuKGtKfOctHD2evWo2pxsQnVyecAGviYLU1d8hdfsKreYtuSsPM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707209999; c=relaxed/simple; bh=0eM9a+BLPyshHZ+cYhbvhP0NmcRRNc1MK5/f4P8xSn8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=DqjVpUNGb/ev2Fe4kmrG7wiLck1p/5FkTHpKnjUMlqCohy+MIWaCTAiZLNzxWkkgTvK1zgztkaw5x3rYj8nVNqNVyVlKgJuvH1dcoI4nlRS7SSLCxNYmasQSYcxE5Sd9NjpkKQp/9JIyhnY3F7KNNlT/gVTHL90djhq7JwUJAhQ= 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.216]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4TTcdK3PXJz4f3kj3; Tue, 6 Feb 2024 16:59:49 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id DE3A71A0C59; Tue, 6 Feb 2024 16:59:53 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgCXaBEG9cFldA+QDA--.34552S7; Tue, 06 Feb 2024 16:59:53 +0800 (CST) From: linan666@huaweicloud.com To: song@kernel.org, mariusz.tkaczyk@linux.intel.com, shli@fb.com, neilb@suse.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 v6 3/9] md: clean up invalid BUG_ON in md_ioctl Date: Tue, 6 Feb 2024 16:55:05 +0800 Message-Id: <20240206085511.2841555-4-linan666@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240206085511.2841555-1-linan666@huaweicloud.com> References: <20240206085511.2841555-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: cCh0CgCXaBEG9cFldA+QDA--.34552S7 X-Coremail-Antispam: 1UD129KBjvdXoWrKry5WFy5tFykWw43Kr4UJwb_yoW3tFc_ua yrZF9rXryxZFyIkr15tr13ZFy0yFn7Wrn7ZF1a9ry5ZFy7XryrGFZYgws8Xan5WFW7uryq yr4ayrsYyrsrKjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbBkFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k26cxKx2IYs7xG 6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUWwA2048vs2IY02 0Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xv wVC0I7IYx2IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr1UM2 8EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0DM2vY z4IE04k24VAvwVAKI4IrM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c 02F40Ex7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE 4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7M4 IIrI8v6xkF7I0E8cxan2IY04v7M4kE6xkIj40Ew7xC0wCF04k20xvY0x0EwIxGrwCFx2Iq xVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r 106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AK xVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7 xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_ Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0JU9Z23UUUUU= X-CM-SenderInfo: polqt0awwwqx5xdzvxpfor3voofrz/ X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790139616900808404 X-GMAIL-MSGID: 1790139616900808404 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 ea147348bd24..fb4e80a0aa9a 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -7645,11 +7645,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 Tue Feb 6 08:55:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Nan X-Patchwork-Id: 197263 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1409412dyb; Tue, 6 Feb 2024 01:01:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IGClmevw3w6/58p3TvbPITg5ZGAcIYwvBNg565qbKgPQ9Jl9p5Yl8i3ZeD1Bi/IZjBbVtEV X-Received: by 2002:a05:6808:144c:b0:3bf:e050:9128 with SMTP id x12-20020a056808144c00b003bfe0509128mr2805706oiv.22.1707210109321; Tue, 06 Feb 2024 01:01:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707210109; cv=pass; d=google.com; s=arc-20160816; b=ysWH126GRKDIimyzI1tQj24sSiX1xIBNa/ITV7aRaS7EswzBf6DP2xMHxnvoxb2nBR L42sw86NFYycYNy4bhu9eZEUn24Y6T/27nzQ0DuCUeh8G8e1aZDCHI84zeQZ6q0THrlv GOn/EtOkThqcKorgVMSgCDeIEhilIx8IhV5hWI0dgxWVOWKF3C71LwMH5jqd7BMDDibw IfldMjYUt4TGGGVggd9pu/5u9Wrgos4gvDIlgHS5vIebhcM1Xd3tHV2OH6WYjvRtT0lS op5CQxrsqhXxBF4hAhVzsTZo/XRZXG+SKBkPyqcK9jAim4gkGe5WrixuYF+YoVD5BsZ7 jfXA== 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=FNtSE/8Jjg4eHnJ92rNT31P7JUMPLDuJW29qOXfSoIc=; fh=HbqOBVr5CDIociCtcposdRR9F5CFJa2jAcPtImCw8B4=; b=Ix2V0ZgskzHDw3wQUGnhqt61mqfjbnxUvn4Wjk3AIg2Di9R9bokPdJO2uAqLQyL0Oy hsl3/LGNqYZ2va8nBr0/yr7n/89dyt7LAYEe4K05nofONKgC80xMShpkpd2T4b6LO2LL U3KQIXEOMCQ8h6FAL1I5g/zTX5KtdKqFZRULnvz1kk9mIMMggbS+Plz455UOwUZyFHu8 0sfXyzgqmt2qYb6awS7k+mXDOnmu5XmKSne4GRZMLgKQslBLyKQp6/GwOgoXy595eE1F fFAwhMG9JYbqp5RjdATJk1TD/vxiEynjtMGBxZcG0Ofnm17MtZdhFG19Exr68Z7DWFis aM7A==; 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-54546-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54546-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCVwXj5MEqsn64zgFJSU4ZGO0OEgWOjxVhPvaLPHwgJBOraNPLaj66IHdT0NIi2RUEwABCbwzR//uQM2v06EMBqPcSYJJw== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id q7-20020a05620a038700b00783e3d3fae8si1762301qkm.545.2024.02.06.01.01.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 01:01:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54546-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-54546-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54546-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 140E11C21F98 for ; Tue, 6 Feb 2024 09:01:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B401612EBFA; Tue, 6 Feb 2024 09:00:01 +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 7098412C81F; Tue, 6 Feb 2024 08:59:57 +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=1707209999; cv=none; b=dgh+hpiPfrPzaBZvMod0PoRU3sdzWUXDLeYt6C7QAbdrbVV060MxCkMuvfSfkydBTYhsyXm8j0XgPZqFapJH0KIT1ekHZ7LlFonck5mT9ejrT3N57Qrbx9NkdJGN2W9mD5fCtk+EMb6gourZhzWulTQSFj8ERT/PAFNOt9mtOao= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707209999; c=relaxed/simple; bh=W+PbX/stc28z0ut0CCXrOC9+tCdv7a9eAngFWE8eMhk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=BkPesucWVZ8ADLYeh1zIUhUp09GE4NyOoVPSGoAQkcDZpMUAL9wiNJ/Kao+h9dtqHjX7ZNh83ihHQ537Na3bUdpWSmXT81qkycZlVfnqEmrQNM1mdoDMQYnhuXE6y27gB4LvKwl/GJCWAmdmDhRCEls+wYWmIPt3vNJxbXfaJNU= 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 4TTcdK6h9Sz4f3kj6; Tue, 6 Feb 2024 16:59:49 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 5B4AF1A0175; Tue, 6 Feb 2024 16:59:54 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgCXaBEG9cFldA+QDA--.34552S8; Tue, 06 Feb 2024 16:59:54 +0800 (CST) From: linan666@huaweicloud.com To: song@kernel.org, mariusz.tkaczyk@linux.intel.com, shli@fb.com, neilb@suse.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 v6 4/9] md: return directly before setting did_set_md_closing Date: Tue, 6 Feb 2024 16:55:06 +0800 Message-Id: <20240206085511.2841555-5-linan666@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240206085511.2841555-1-linan666@huaweicloud.com> References: <20240206085511.2841555-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: cCh0CgCXaBEG9cFldA+QDA--.34552S8 X-Coremail-Antispam: 1UD129KBjvJXoW7tFWfXw43AF4xGw15Xw4fZrb_yoW8Aw4Upa 9agF9xtrWUJr95Kr1UJasY9FyYqw12kFZ2kryxCF1UZFyUArsxZr1Fg3yFqr95urykA3y5 t3W7JayrWayxGrUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUQY14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAac4AC62xK8xCEY4vEwIxC4wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0V AKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1l Ox8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErc IFxwACI402YVCY1x02628vn2kIc2xKxwAKzVCY07xG64k0F24l42xK82IYc2Ij64vIr41l 4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67 AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8I cVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26F4j6r4UJwCI42IY6xAIw20EY4 v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AK xVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7VUbxR67UUUUU== X-CM-SenderInfo: polqt0awwwqx5xdzvxpfor3voofrz/ X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790139547249621579 X-GMAIL-MSGID: 1790139547249621579 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 | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/drivers/md/md.c b/drivers/md/md.c index fb4e80a0aa9a..02d6197dc944 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -7649,26 +7649,19 @@ static int md_ioctl(struct block_device *bdev, blk_mode_t mode, switch (cmd) { case GET_ARRAY_INFO: if (!mddev->raid_disks && !mddev->external) - err = -ENODEV; - else - err = get_array_info(mddev, argp); - goto out; + return -ENODEV; + return get_array_info(mddev, argp); case GET_DISK_INFO: if (!mddev->raid_disks && !mddev->external) - err = -ENODEV; - else - err = get_disk_info(mddev, argp); - goto out; + return -ENODEV; + return get_disk_info(mddev, argp); 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) @@ -7684,13 +7677,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 Tue Feb 6 08:55:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Nan X-Patchwork-Id: 197267 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1410064dyb; Tue, 6 Feb 2024 01:02:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IFfKi5xwhq/SSG9xhnlL3E7kZ+dSiH1S1TDcLkF0XfUXkhATs7ffNWO6ICA38hzERmAmnTa X-Received: by 2002:a92:d44a:0:b0:363:abde:3b70 with SMTP id r10-20020a92d44a000000b00363abde3b70mr2270985ilm.12.1707210178073; Tue, 06 Feb 2024 01:02:58 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707210178; cv=pass; d=google.com; s=arc-20160816; b=ndOe/TUKeYe9dAVtLWbkLbI6OhNPIDz/ox8Mxvs4WzeMG03EOZDcpkOdew/f4xI9yF gAXjqQ6G5JO9aeXnKoxVYq4pyPZu/4x6gUyXpU+RWWmR1XnIJQqMN/Wg+vgLqYHilums AFdiRmFs2pdJaxS+5PpIOtXbz5TdJs97apKKfNAhj5KHUxmS+Byy9pPAVcDrpTopFlcX teZz6UhZ2j82SU7jBq9udjE27m/Xs7x989qVEgbdj6Sv0/kvKxE+BmYSPXVK50SvRDjD mSdJftfQgd4F79s9z1pvBF4I0/acV2umqUTPsojfc6I5piOj6cvvCe4YiuFruN9eHmki hVzg== 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=RXg3Ppcvq+Bb3hj6RdTsco9vbekBo7y2UqPplK/Rc2g=; fh=C6bCFzzp+RCI/ttLRzoiiygYdA3udm7wS5jnPmMKxjE=; b=Sb2CZZdobSudrO3AXOa+Pi+w779B0Lctm2A8odnoufcyZR0PVLmIwPZmOB0e9uXmYK gPl/fE9BX6lncIPnMa1vy5nsGFfXTRrSCxWa0QOuSEWo3KLqz3KvcuD9e2VfSvE/B3cT s5n8cX61tC3AbLpzlwHjHQhqaGe3oYLWg0/us3zsDCM3+JtOUhSJWCfyVFQpV6oCAJVz 9WIUg1x1NpB74UR+i0VRxefGLgGXzAq8dIsLYloBikdiyCsBje4nlpifszIemZlvTlqr 3WMFda9Xj3eB/JIX6kC+8tJysqlzCNYIXWR1x4EXRy+H+4QPhkg6fZTNijHus+npwBWi ORmA==; 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-54548-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54548-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCWDyXJE07fCePcnGALp2lbDRHTpiGClAWjZjT7shokFbe64b+l/a9ZU/LYOkPS1Fke+GeydFekoHYsgTAOlMfQF4YRoNQ== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id i12-20020a6551cc000000b005cdf3787c1fsi1406503pgq.67.2024.02.06.01.02.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 01:02:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54548-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-54548-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54548-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 0BB4D282F86 for ; Tue, 6 Feb 2024 09:02:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B42F212F5AC; Tue, 6 Feb 2024 09:00:02 +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 06C3212D15F; Tue, 6 Feb 2024 08:59:57 +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=1707210000; cv=none; b=OQ3IsrmUkh54cCzAiYDXcm2KsCagk5fAM00iDdRHC2JDa8lAkcAEiPPtMIgWsTpLDnyXH4JAYEJpIkUVbLJo1fKgsaZKg5zTWXohveVVTZeEb/U4CFgwRoytCj/qXcXidq3DkSGRDve24pgwd6LFPm+NPMRVTw+FBAEKb+AT0Rk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707210000; c=relaxed/simple; bh=MqM+wcbxq9vaxTluNjoJmJiRysA3/+CUnbH5KNM18FA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ThV2PzrGrmNG27egCthhlOlajIz7kX9LcDsLunO8h4deJWy9jd1cGULE+gdrBsJFFssYO9cb1YokTrZ6rC6hjukwA46DSVlo6W7W4v4Du3+mI1+rX61QrtUL/D6VIj3mqrUMDZc6ej4uGdAbRibNonOlpwFUXpTi5R8VA3yJXPI= 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 4TTcdL2jGFz4f3kj7; Tue, 6 Feb 2024 16:59:50 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id C60F21A027B; Tue, 6 Feb 2024 16:59:54 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgCXaBEG9cFldA+QDA--.34552S9; Tue, 06 Feb 2024 16:59:54 +0800 (CST) From: linan666@huaweicloud.com To: song@kernel.org, mariusz.tkaczyk@linux.intel.com, shli@fb.com, neilb@suse.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 v6 5/9] md: Don't clear MD_CLOSING when the raid is about to stop Date: Tue, 6 Feb 2024 16:55:07 +0800 Message-Id: <20240206085511.2841555-6-linan666@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240206085511.2841555-1-linan666@huaweicloud.com> References: <20240206085511.2841555-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: cCh0CgCXaBEG9cFldA+QDA--.34552S9 X-Coremail-Antispam: 1UD129KBjvJXoW7Cw13Zr18XryUAw4DCFy5CFg_yoW8Zry7pa 1IgFy5KryUGr9I9w4Utw1kWa4FqrySqrWvyry2va4rWa4UAry7Jr9Yg3yDCr1kGFZ5AFs8 X3WUXayUWw18W3JanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUQY14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAac4AC62xK8xCEY4vEwIxC4wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0V AKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1l Ox8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErc IFxwACI402YVCY1x02628vn2kIc2xKxwAKzVCY07xG64k0F24l42xK82IYc2Ij64vIr41l 4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67 AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8I cVAFwI0_JFI_Gr1lIxAIcVC0I7IYx2IY6xkF7I0E14v26F4j6r4UJwCI42IY6xAIw20EY4 v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AK xVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7VUbxR67UUUUU== X-CM-SenderInfo: polqt0awwwqx5xdzvxpfor3voofrz/ X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790139619210102965 X-GMAIL-MSGID: 1790139619210102965 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 02d6197dc944..c72af9fa3d7f 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) @@ -7683,7 +7690,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); } @@ -7825,7 +7831,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 Tue Feb 6 08:55:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Nan X-Patchwork-Id: 197265 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1409735dyb; Tue, 6 Feb 2024 01:02:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IHGy3QoRAv7YB7rXiOaDK1xZkWuvnoylxvL90dHbCGygQWcyvk1GsDgOYOEUuxIiuIUm8e6 X-Received: by 2002:a05:620a:3914:b0:783:de24:f315 with SMTP id qr20-20020a05620a391400b00783de24f315mr1771168qkn.58.1707210145625; Tue, 06 Feb 2024 01:02:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707210145; cv=pass; d=google.com; s=arc-20160816; b=ekM/0LaytQ16HH2VZECP93EBl2//IoMpWDcxjaieBC2RqIV7OSN04+7pcCGtxXpmTY TQhprl1b4A9AZmBxZCeVkq0z8ZCAEMWohoSd+yVEIu0ZbSfvH5Efc4ReWCK2dC8LNAzd 6AJoNs/yuW9uIa0rYEvbcmiHOAdjhR5UEUZs+CDQaPVyYM78SYwpOl04butE1Yy+wgx3 SjgHDR3WaRkSwvq+jauJ0r6hapQrkGcur3KajjcyFIZKHxwW+cosF9rwnbU/xhqdHMhe NASWU8yLfBomdz7opKQBiegIExJIxBbytQ5mBBk6X8+VIWMBiN8QJGPVbYzD7sDtcM3u 0wVw== 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=SI6W9cRhpTH0g0/pcBWt5RwtkVoO8bX7k8EwO6m/+9g=; fh=2LHg8rSNERDy7y+4NCgy6TY5TWpVqT2chiQ8qlXACwU=; b=oc5UC7VrkiaumSktpqcZbz6JUH/g3yq7TNJmeP1wSGKKh4c5bi/VQ1FrxmkFv3+vH2 u9O5TSuALMimb5qj86CTmLEm6CsEqxZgCTdB8KFYepdyLfdZiXwwLhWIfyCI/hb26PXS 1nk3YgjKjb1wd25ZcFo/nrxhC/dcxb+GJtzg+pRteeeTApRAaM7WqciIbLQM+XDHxAYb cL2jUBB0sXH6qpYeBjsWOirTYajqQnnDgJ7+byydGsmbnUz+XXEgNZF9tq2ilh6uzyFR ghBeYWpQ3q0YuszSEag8YakZXhUSyCki+p1HW1g7Ctwdrlz0CZE5gOnYnW7/wJPa1Wav QnYA==; 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-54549-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54549-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCWVpkHuQ6cB7Jz10GXr/RTgcq2RufHUKY0kJYUybL37LA9I37ArFeD+h+mFIK+T4tE5y8sYValXP9amLnZxZQf23rTeyg== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id q7-20020a05620a038700b00783e3d3fae8si1762301qkm.545.2024.02.06.01.02.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 01:02:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54549-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-54549-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54549-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 684441C20F2F for ; Tue, 6 Feb 2024 09:02:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BC98912F5AF; Tue, 6 Feb 2024 09:00:02 +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 06B9112D15E; Tue, 6 Feb 2024 08:59:57 +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=1707209999; cv=none; b=SWO3wB6xYtuMI4zMxqnwpcHZf7O0h/ktZzTBA7sTsbWaDvSgIg97ktWZW8k/7ClVPNk3c7ZEKZyoaeYob0aFbXPcpV/Jo1e77m6F5R10jQOZl8gmgGPrvhMgsTbFMMp/E6Nq54KlzTCoEGXRun49PIc6wZfQxGaKntZfxmsUEvs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707209999; c=relaxed/simple; bh=hv3B4WH+x62QgtFTnkDV8okKj1oRCL21b+lA7hVsg6E=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=l5Hiv/lMBSmLMIv5I5tGp2jt045mpynCls1Uw91sUYYQYTxdHQzMw4ErqzDkpVRRLWKzk0Hq9bvxGdAjiYi5EWpHlHJw/0mk42Fuk+fhZKUi+pb4yUOW+6NzOQnQrGOOvNmdfnuFjgdDQljorr6bP1vS+DTetxWw4kM3G5Z5LrA= 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.216]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4TTcdL5v4bz4f3kj8; Tue, 6 Feb 2024 16:59:50 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 3FEEE1A0C61; Tue, 6 Feb 2024 16:59:55 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgCXaBEG9cFldA+QDA--.34552S10; Tue, 06 Feb 2024 16:59:55 +0800 (CST) From: linan666@huaweicloud.com To: song@kernel.org, mariusz.tkaczyk@linux.intel.com, shli@fb.com, neilb@suse.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 v6 6/9] md: factor out a helper to sync mddev Date: Tue, 6 Feb 2024 16:55:08 +0800 Message-Id: <20240206085511.2841555-7-linan666@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240206085511.2841555-1-linan666@huaweicloud.com> References: <20240206085511.2841555-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: cCh0CgCXaBEG9cFldA+QDA--.34552S10 X-Coremail-Antispam: 1UD129KBjvJXoW7tFWrGw4DZw4rXFW7Xry5Jwb_yoW8AF1Dpa yftF9xKr1UGrZIyr47Jr9rZ3WYgw1Ikayvyry7Aa4xZF97ArsFgryFgFyUKrykK34xAF4U tw18Xa15Wa47Wr7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUQY14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAac4AC62xK8xCEY4vEwIxC4wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0V AKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1l Ox8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErc IFxwACI402YVCY1x02628vn2kIc2xKxwAKzVCY07xG64k0F24l42xK82IYc2Ij64vIr41l 4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67 AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8I cVAFwI0_JFI_Gr1lIxAIcVC0I7IYx2IY6xkF7I0E14v26F4j6r4UJwCI42IY6xAIw20EY4 v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AK xVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7VUbxR67UUUUU== X-CM-SenderInfo: polqt0awwwqx5xdzvxpfor3voofrz/ X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790139585393435243 X-GMAIL-MSGID: 1790139585393435243 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 c72af9fa3d7f..04826431d3c6 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, int opener_num) +{ + mutex_lock(&mddev->open_mutex); + if (mddev->pers && atomic_read(&mddev->openers) > opener_num) { + 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 */ @@ -7681,17 +7699,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, 1); + if (err) + return err; } if (!md_is_rdwr(mddev)) From patchwork Tue Feb 6 08:55:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Nan X-Patchwork-Id: 197269 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1410417dyb; Tue, 6 Feb 2024 01:03:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IF5TvMPbNwq8f/I9Erk2qM6ohb75by1b92ea5QdAUGC8IEoCUOY8Py2D+URTE+n/BAoUIJi X-Received: by 2002:a05:6a20:a19a:b0:19e:488f:6933 with SMTP id r26-20020a056a20a19a00b0019e488f6933mr792444pzk.21.1707210220612; Tue, 06 Feb 2024 01:03:40 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707210220; cv=pass; d=google.com; s=arc-20160816; b=ba12Bi6RitTdiIdCfpkMAXRBYR/Kp07Mjm2pLQm0b9fyj4YKu8iNE72w2XvLOme+zh 0nqmibGMtvkAo5zyvpZGiB2BKQP29LE1X5WHbbVhqwv5DwTxK6W4AaYis6lBSn37Dqv4 711Zq8/cnG2qVlW8WjWHfFb3jp+vUBi2VOg+wM8BLT8DA9yy5JwezvMj6eNSAlbeRUtv DDofP7eeHt/f1rKrVk/JdqlvaRg2c3k1fICZJ7n+vItIaDoPmjTyHxlyI8vWjqxKFEVe KBrhhq+7wFo1r5KcKSGe18wbwBwjFe72jhoL96FIkBUQvD00+PuPm7X1ns7HBPc0KqKx Nf8g== 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=0Junj8Gb/aY+6BFHDhX/UNIcXhSdVIfB7mS0Kdf3vL4=; fh=aT4RmgeK4yE7PKXGuYDSGHFs5Qgb/2HhwHIUvHKq9QY=; b=GqjbTH7Quqb+QqTQQNuff9vkHAU0Qxg1a07ObBTUGXMVTuGycLVJVsZHTu+GaSmam9 IcfBRHXgzbLv/t8uIdoUYkL+MDjZVe6UJ5XAAHb5UUx53ycsxfKiLdI3/MV5W0+FYbZm GgmiZ66fXOKxVYQVZq+FlFcxW/iwmLOb3NQ7tcnJz/bCO17pLO8Yx2WwHPxaVFdsf6eb 2Up2uqkbf9kGXK+DI/Cn5yoaUDUTA7TP/u0Iu9aO5AcKkwif5r/E8gvmkI9M3QNSbZMx cZ8rrP2TCsHm/ZeL1UyRcjDWp1YO7qMYKxEzvn7md7czrljiNJLSrGbaOaP2cO7PnsGR dCzA==; 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-54552-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54552-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCUEMNHTnSu1Ky6HR0PcNSjErabHXKhEiqrBE7WQxd/rTrvYv3Aj1U4omxnfoYmEvfdDxeYf2G2L+LShJaW3ITbMkNt3/A== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id w1-20020a056a0014c100b006e05de14bd2si283816pfu.318.2024.02.06.01.03.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 01:03:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54552-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-54552-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54552-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 F390FB2119F for ; Tue, 6 Feb 2024 09:02:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4CAC312F386; Tue, 6 Feb 2024 09:00:04 +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 B8ECE12DDB4; Tue, 6 Feb 2024 08:59:59 +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=1707210001; cv=none; b=A1nk8TnDqB2OnbjvCNwuwOqSigSV886cZGPgETIDgV7oqaLZN3yuzl3MFNhlTfAqdKHVH01ixNqCWjY8Wydqm2XKRqho+18rJfiJgWpHBcdPRLcnPiILTw9NHDB2NrNsq73E+EfevFb5PeWIncIrkGY484pIzg8etFwsAqldebA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707210001; c=relaxed/simple; bh=0nXUeGguJuzk+QCYWlm2HVHhWdjhdiMjANKTPaOvan4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Hgtfh9FBcsHZ65PvjrPGsM8orprE4zZhFyMfW6bZUH9ihoUSgIqh58NYBrdASWx0VpzA2DVcaFhV56qT+IkEWdrIxWxjOexa6gFUaKEmtRm9V7h0NI1c8tOIL6pMe66N6ca6p+of67iwX1h4rZv929pb4vXou9Ii3XiaFmXOjb8= 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 4TTcdM53Znz4f3knd; Tue, 6 Feb 2024 16:59:51 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 236AA1A027B; Tue, 6 Feb 2024 16:59:56 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgCXaBEG9cFldA+QDA--.34552S12; Tue, 06 Feb 2024 16:59:55 +0800 (CST) From: linan666@huaweicloud.com To: song@kernel.org, mariusz.tkaczyk@linux.intel.com, shli@fb.com, neilb@suse.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 v6 8/9] md: clean up openers check in do_md_stop() and md_set_readonly() Date: Tue, 6 Feb 2024 16:55:10 +0800 Message-Id: <20240206085511.2841555-9-linan666@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240206085511.2841555-1-linan666@huaweicloud.com> References: <20240206085511.2841555-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: cCh0CgCXaBEG9cFldA+QDA--.34552S12 X-Coremail-Antispam: 1UD129KBjvJXoWxCw1UWw1xuF1DCr1xJrW3trb_yoWrtw47p3 yIqas8Gr4UX3sIqF4UGFWku3WYvw18KFyktry3C3yruF1ftrnrWFyFgF18Ary8Kas7Awn8 Xa1YyFyUuFy7GrUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUQY14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAac4AC62xK8xCEY4vEwIxC4wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0V AKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1l Ox8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErc IFxwACI402YVCY1x02628vn2kIc2xKxwAKzVCY07xG64k0F24l42xK82IYc2Ij64vIr41l 4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67 AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8I cVAFwI0_JFI_Gr1lIxAIcVC0I7IYx2IY6xkF7I0E14v26F4j6r4UJwCI42IY6xAIw20EY4 v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AK xVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7VUbxR67UUUUU== X-CM-SenderInfo: polqt0awwwqx5xdzvxpfor3voofrz/ X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790139664388240037 X-GMAIL-MSGID: 1790139664388240037 From: Li Nan Before stopping or setting readonly, mddev_set_closing_and_sync_blockdev() is always called to check the openers. So no longer need to check it again in do_md_stop() and md_set_readonly(). Clean it up. Signed-off-by: Li Nan --- drivers/md/md.c | 38 ++++++++++++++------------------------ 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/drivers/md/md.c b/drivers/md/md.c index 200410a8adf3..adb821626d66 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -4475,8 +4475,8 @@ array_state_show(struct mddev *mddev, char *page) return sprintf(page, "%s\n", array_states[st]); } -static int do_md_stop(struct mddev *mddev, int ro, struct block_device *bdev); -static int md_set_readonly(struct mddev *mddev, struct block_device *bdev); +static int do_md_stop(struct mddev *mddev, int ro); +static int md_set_readonly(struct mddev *mddev); static int restart_array(struct mddev *mddev); static ssize_t @@ -4537,14 +4537,14 @@ array_state_store(struct mddev *mddev, const char *buf, size_t len) case inactive: /* stop an active array, return 0 otherwise */ if (mddev->pers) - err = do_md_stop(mddev, 2, NULL); + err = do_md_stop(mddev, 2); break; case clear: - err = do_md_stop(mddev, 0, NULL); + err = do_md_stop(mddev, 0); break; case readonly: if (mddev->pers) - err = md_set_readonly(mddev, NULL); + err = md_set_readonly(mddev); else { mddev->ro = MD_RDONLY; set_disk_ro(mddev->gendisk, 1); @@ -4554,7 +4554,7 @@ array_state_store(struct mddev *mddev, const char *buf, size_t len) case read_auto: if (mddev->pers) { if (md_is_rdwr(mddev)) - err = md_set_readonly(mddev, NULL); + err = md_set_readonly(mddev); else if (mddev->ro == MD_RDONLY) err = restart_array(mddev); if (err == 0) { @@ -6412,7 +6412,7 @@ void md_stop(struct mddev *mddev) EXPORT_SYMBOL_GPL(md_stop); -static int md_set_readonly(struct mddev *mddev, struct block_device *bdev) +static int md_set_readonly(struct mddev *mddev) { int err = 0; int did_freeze = 0; @@ -6440,9 +6440,7 @@ static int md_set_readonly(struct mddev *mddev, struct block_device *bdev) !test_bit(MD_SB_CHANGE_PENDING, &mddev->sb_flags)); mddev_lock_nointr(mddev); - mutex_lock(&mddev->open_mutex); - if ((mddev->pers && atomic_read(&mddev->openers) > !!bdev) || - mddev->sync_thread || + if (mddev->sync_thread || test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)) { pr_warn("md: %s still in use.\n",mdname(mddev)); if (did_freeze) { @@ -6468,7 +6466,6 @@ static int md_set_readonly(struct mddev *mddev, struct block_device *bdev) err = 0; } out: - mutex_unlock(&mddev->open_mutex); return err; } @@ -6476,8 +6473,7 @@ static int md_set_readonly(struct mddev *mddev, struct block_device *bdev) * 0 - completely stop and dis-assemble array * 2 - stop but do not disassemble array */ -static int do_md_stop(struct mddev *mddev, int mode, - struct block_device *bdev) +static int do_md_stop(struct mddev *mddev, int mode) { struct gendisk *disk = mddev->gendisk; struct md_rdev *rdev; @@ -6503,13 +6499,9 @@ static int do_md_stop(struct mddev *mddev, int mode, &mddev->recovery))); mddev_lock_nointr(mddev); - mutex_lock(&mddev->open_mutex); - if ((mddev->pers && atomic_read(&mddev->openers) > !!bdev) || - mddev->sysfs_active || - mddev->sync_thread || + if (mddev->sysfs_active || mddev->sync_thread || test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)) { pr_warn("md: %s still in use.\n",mdname(mddev)); - mutex_unlock(&mddev->open_mutex); if (did_freeze) { clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery); set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); @@ -6532,13 +6524,11 @@ static int do_md_stop(struct mddev *mddev, int mode, sysfs_unlink_rdev(mddev, rdev); set_capacity_and_notify(disk, 0); - mutex_unlock(&mddev->open_mutex); mddev->changed = 1; if (!md_is_rdwr(mddev)) mddev->ro = MD_RDWR; - } else - mutex_unlock(&mddev->open_mutex); + } /* * Free resources if final stop */ @@ -6584,7 +6574,7 @@ static void autorun_array(struct mddev *mddev) err = do_md_run(mddev); if (err) { pr_warn("md: do_md_run() returned %d\n", err); - do_md_stop(mddev, 0, NULL); + do_md_stop(mddev, 0); } } @@ -7758,11 +7748,11 @@ static int md_ioctl(struct block_device *bdev, blk_mode_t mode, goto unlock; case STOP_ARRAY: - err = do_md_stop(mddev, 0, bdev); + err = do_md_stop(mddev, 0); goto unlock; case STOP_ARRAY_RO: - err = md_set_readonly(mddev, bdev); + err = md_set_readonly(mddev); goto unlock; case HOT_REMOVE_DISK: From patchwork Tue Feb 6 08:55:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Nan X-Patchwork-Id: 197268 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1410367dyb; Tue, 6 Feb 2024 01:03:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IGcpGvKanbf4ywO7SAWG9Q5bApxh3PPOruw3u3UyBJPaVelxj1kTac9n8f2M2Z8exttCHtU X-Received: by 2002:a17:903:186:b0:1d9:66de:ea0b with SMTP id z6-20020a170903018600b001d966deea0bmr1089419plg.37.1707210215048; Tue, 06 Feb 2024 01:03:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707210215; cv=pass; d=google.com; s=arc-20160816; b=wxj1Xii+Yi64D6m+RaE9wy5kM+rjhN9nUn2/PXY5Fa4Qm934q3aU3GNGvyYhLF2fC4 cDC2A7jkZBtX2cTRiQekZ+MB4tyDrUg4LrhsC1n1ce/VXCbqEGGqIv3CvvsQwHQUJc3L GgHLwGzn3FjXAPVuCrT5Oogziay1aM7mAb9ypZrvvMycdFhHkD/HYTakoF1dg2J1lTAz 9hFzK2PktqV0YVS1GTkOFAK4qf/2sK2dAXz0onJUnGkeA/3psbY/ISA6I6WmyO+ZLAsE GwmCgk5ot0O9Lf138AwOrZCDW9FcWMD6YhjzkcWbEyyvaeJMF1qrMiieiwsTVah42PPj Gh3g== 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=0PpJnCJCReeVbyI9wmNozZ0E4jS5XFMeIaTHn6wguuU=; fh=fWZdqCmLeAZtbBTK308bTwzRA3d+gnf2aQC7e27iIZk=; b=MFsUL/iO4To0C/O3heGuCjqzh4fPyDhGAZXzMbgObKbZ5UHgmCcdIfw++w3Z8dIgUr rPv+4ngdvCd+Vjh2BaXjZ3s0SQ5OJFvVFRLy3mDtU1vL7vLOG3Gtryto/K3QLBGZnLCA ei16JNzl00XATFYpbimQQDKzRsbulCS3dbmWSYhuU5w89i07TZlTuZ+pnAWTg9rV2HPj lDWoO0SDYeyyUf417PJYlaYCTkirJTmCq5d7bivdMdvEh/CMvLINpkii7XVMTXyZOefF qBR3Up+bvMvoC5HGo3rQCqQFNPL7yE5TG1WfiqVF7YAxZ8gOCreon0+G+uSZVhMGfGUr gxhA==; 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-54551-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54551-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCUB+z9BMf6Q8CBIBtzmvsuXIKSh7supUlrptUEK0ihSdMkp+JvBZrXvpKniH8lyP0OhpUsxMtM9O0AP3aRzu9Puogf7/Q== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id x17-20020a170902e05100b001d99ab3b516si1323370plx.40.2024.02.06.01.03.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 01:03:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54551-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-54551-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54551-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 A993CB21E83 for ; Tue, 6 Feb 2024 09:02:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C33F512FF91; Tue, 6 Feb 2024 09:00:03 +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 88A8612DD8B; Tue, 6 Feb 2024 08:59:59 +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=1707210001; cv=none; b=AhIL5eMUE8k1UF7ld9RP8i5br10WPtQr2C9ERxTfDeduKsgEPCoW6YACaxtcPZ7k0+dWbWDjDo8A7a7dN5vsPjyxZWyOdznvdjhrnG3LQuhV8gz34a6+DYTKNJGmPXwiedUJE5rCgsg09kXtrX2O+Ue+4h92w9tXXkYIe2d3z6c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707210001; c=relaxed/simple; bh=H/alJ/3zoRLTUvvj4DHF2RFOl5ysgpYtLrzw+xmVOMw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=RYWUPzegPxHGZpzGWhgc3mFqNPj4SB0VHUV8SYxDvZBXkSytml8qpCsmi6TQb/lE7L8mn5xGxQ27gvw9JEa4PvkQ31VfPc+xTTJz85E3sGFVB+7Zd4uKudGzbW6uqaZ2lovMgC5w3neCX1pwU98rBaTcNUNeS5e2OM9du77vpJA= 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 4TTcdK6Jylz4f3mHr; Tue, 6 Feb 2024 16:59:49 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 926CD1A027B; Tue, 6 Feb 2024 16:59:56 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgCXaBEG9cFldA+QDA--.34552S13; Tue, 06 Feb 2024 16:59:56 +0800 (CST) From: linan666@huaweicloud.com To: song@kernel.org, mariusz.tkaczyk@linux.intel.com, shli@fb.com, neilb@suse.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 v6 9/9] md: check mddev->pers before calling md_set_readonly() Date: Tue, 6 Feb 2024 16:55:11 +0800 Message-Id: <20240206085511.2841555-10-linan666@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240206085511.2841555-1-linan666@huaweicloud.com> References: <20240206085511.2841555-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: cCh0CgCXaBEG9cFldA+QDA--.34552S13 X-Coremail-Antispam: 1UD129KBjvJXoW7tF15Xw47uF15tw1DZFWDArb_yoW8Zr47p3 9aqF98Gr18Xryayr4Dt3WkuFy5Zw17tryDtrWxu3yrua4Fywn8Gryag3WxJrWDKas7Aay5 Xa1UJFW7ua4Ig3JanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUQ214x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAac4AC62xK8xCEY4vEwIxC4wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0V AKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1l Ox8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErc IFxwACI402YVCY1x02628vn2kIc2xKxwAKzVCY07xG64k0F24l42xK82IYc2Ij64vIr41l 4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67 AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8I cVAFwI0_JFI_Gr1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4UJVWxJr1lIxAIcVCF04k26c xKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAF wI0_Gr1j6F4UJbIYCTnIWIevJa73UjIFyTuYvjfUY4EEUUUUU X-CM-SenderInfo: polqt0awwwqx5xdzvxpfor3voofrz/ X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790139658419805955 X-GMAIL-MSGID: 1790139658419805955 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 | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/drivers/md/md.c b/drivers/md/md.c index adb821626d66..987851db98c1 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) { int err = 0; @@ -6451,20 +6452,18 @@ static int md_set_readonly(struct mddev *mddev) 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: return err; } @@ -7752,7 +7751,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: