From patchwork Fri Jan 26 09:22:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Nan X-Patchwork-Id: 192523 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:e09d:b0:103:945f:af90 with SMTP id gm29csp579401dyb; Fri, 26 Jan 2024 03:01:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IFKfCXvtSYJYdpSOnjebW333s5XnFwGaT4E4e6XlCKK+gRStCcgIg+BD8Hd4kBwdoVk6hNd X-Received: by 2002:a05:6358:98a8:b0:176:ae9c:34bc with SMTP id q40-20020a05635898a800b00176ae9c34bcmr1421238rwa.61.1706266864497; Fri, 26 Jan 2024 03:01:04 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706266864; cv=pass; d=google.com; s=arc-20160816; b=JIc43W3we9HoLGn3FVGkn9In6UAiaJ3wGD30/cBGsJK3PMrHyGKc/vzVr4nXk61JT5 EtnsxUhXuELu+ZhCTYYwLU7ya2Keyb6ZKcmKZqEU7zIVfJ7UIIpJ6BQSgHLpAkXn69nz DCQ8EtScMF/B3ViSjW1nDqs1OWEGrNgr1OIG7jjjV+Lu3C1NafNl82oRZREMPs2HNYG3 DF3HMcU/1+rzPnIIcVyo0+sFyUaGyy4sU+E2R02zN2Fi6a0ZfKPNamuU+SHB+pGV4n1H RuRAJi1at6DMgKCTGzdbRgr1DZSLPoihFUhus+vM77vchxiTXDRhQPI3oYBXkNPKwQEe ShAQ== 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=FPjgUSiZ4K80Iy2Jb518yBPBIzvXpjMlgXUqzTTumls=; fh=u3xs68RapeYgyf8J+6FO06hVnIcx/tsubPM81p4b4hk=; b=aiEPhrdOtOwogkdjcCWHzWGzx6qMKZpSZ3WqB/tF3t7FrRikaNURVx0bsvC0WySayA ti91zIuD7A/l4oj59fyowalKnHkr0FE/ZlWaHToPgVAD2KFEe5ij9Le/4e9dThJWlaoB Rt+9qjKvWkWwma5XYh9fndqQSNz5kELsp4YxUnaMKT2aKA+9oq1yjU5IeI57StiF0fhO 2zDLoE3cnMesls4BEoZz8lLrPMZqoqLlgvtUg/7cThPZij/CYSXs3Wk6NUmHvNjGN+ot yzmMTHDIw2FGFc+lxkYP5onZSdzsHaLRn/eo09kPOq3aF2uvY+PuInTvap6+ATa8hhKU CV3Q== 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-39918-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-39918-ouuuleilei=gmail.com@vger.kernel.org" Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id j186-20020a638bc3000000b005d24ebc7f36si960530pge.406.2024.01.26.03.01.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jan 2024 03:01:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-39918-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-39918-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-39918-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 DE666B2C907 for ; Fri, 26 Jan 2024 10:09:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4EDBB1EA8F; Fri, 26 Jan 2024 09:27:05 +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 BC2261946B; Fri, 26 Jan 2024 09:27:01 +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=1706261223; cv=none; b=Jijr8/JReEtyixPbHVa999Lux4m1vJxEhjBZPKvfVEWbvubqt3iMPaTl6AuLPOzcCMknfcPALiQdXSKpE4W+CKBGSvYrRDHcjGi6GKUu3fAE3ahnVQfj1f09mr8pIt8r80MM4cXFLfxSYU1Sv51ctFFkgXuOpeKkOD4RVAKqohg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706261223; c=relaxed/simple; bh=4V/bQdag0va6YAtWVymcSG+PLIDu/Aa9xOdzv2GP9qg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=hyBgEUAVlaTj7f6f7nnH0a5PvPpIe6OqJymM8ebocaKpDHmfuUMX620RwONcDsl60MWBbj0tPdvwrbxmc0Sr8CpkhQmYdbzEKzgPqv5bXu6faFIjxcFudpJXicWHBYWZ13wX/95mR7qlCdT+IeSc8dB4zb9cTqTRJTO6PRq2cZs= 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 4TLslc2vvpz4f3mHM; Fri, 26 Jan 2024 17:26:52 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id B9E021A0272; Fri, 26 Jan 2024 17:26:58 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgCXaBHferNlLsUdCA--.25360S6; Fri, 26 Jan 2024 17:26:58 +0800 (CST) From: linan666@huaweicloud.com To: song@kernel.org, neilb@suse.com, shli@fb.com, mariusz.tkaczyk@linux.intel.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 v4 2/4] md: factor out a helper to sync mddev Date: Fri, 26 Jan 2024 17:22:52 +0800 Message-Id: <20240126092254.1314908-3-linan666@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240126092254.1314908-1-linan666@huaweicloud.com> References: <20240126092254.1314908-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: cCh0CgCXaBHferNlLsUdCA--.25360S6 X-Coremail-Antispam: 1UD129KBjvJXoW7tFWrtFWfXFW5uw48Jw1DZFb_yoW8Cr17pa ySqF9xKr4UGrZxZr47JwnrZF1Ygw1Ikayvyry7CFyxZF97ArsF9ryFvFykGrykK34IyFZ8 t3W8Za15Way3WrUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUmK14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_Jryl82xGYIkIc2 x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJw A2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq3wAa c4AC62xK8xCEY4vEwIxC4wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzV Aqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S 6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxw ACI402YVCY1x02628vn2kIc2xKxwAKzVCY07xG64k0F24l42xK82IYc2Ij64vIr41l4I8I 3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxV WUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAF wI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcI k0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j 6r4UJbIYCTnIWIevJa73UjIFyTuYvjfUYSoXUUUUU X-CM-SenderInfo: polqt0awwwqx5xdzvxpfor3voofrz/ X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789150483645089420 X-GMAIL-MSGID: 1789150483645089420 From: Li Nan There are no functional changes, prepare to sync mddev in array_state_store(). Signed-off-by: Li Nan Acked-by: Mariusz Tkaczyk --- drivers/md/md.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/drivers/md/md.c b/drivers/md/md.c index 06550fe34aa1..40ab5c7ce394 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -529,6 +529,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 */ @@ -7681,20 +7699,10 @@ 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); - err = -EBUSY; - goto out; - } - if (test_and_set_bit(MD_CLOSING, &mddev->flags)) { - mutex_unlock(&mddev->open_mutex); - err = -EBUSY; + err = mddev_set_closing_and_sync_blockdev(mddev); + if (err) goto out; - } clear_md_closing = true; - mutex_unlock(&mddev->open_mutex); - sync_blockdev(bdev); } if (!md_is_rdwr(mddev)) From patchwork Fri Jan 26 09:22:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Nan X-Patchwork-Id: 192538 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:e09d:b0:103:945f:af90 with SMTP id gm29csp586647dyb; Fri, 26 Jan 2024 03:13:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IE5UxAiodqOTzDJNmugTiw2LLSrNNdYVLc+2Pm+qutXD6wChoOdZGc6RKIhmQR710u3Rri4 X-Received: by 2002:a17:902:f68e:b0:1d7:3f26:5368 with SMTP id l14-20020a170902f68e00b001d73f265368mr1593154plg.96.1706267636856; Fri, 26 Jan 2024 03:13:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706267636; cv=pass; d=google.com; s=arc-20160816; b=s8+vkiAKdFVSnKujackXs95k0IHvinsRdktqEbuVvT3hbbz3bQftz2dwLMTzWKO7be 93Uojlhv+C1Xi6G4BYSyI3OZznJgCKVviQJVa4+O75sW2ixaveuDUrk4gCsu/NJkdptS siaX+ggL2/f/uinqzo8CdPv3GccIb8ja8+PHmPOY5nDytKlH1wb5tTvuG5ep1lpRY0HW dZ6MKeI1N5KPvpkgczR4Q/0FDrZbGNaqywSkk0c3Tc4SHuN22cHFUTke/iu/t093ns9x 4xn7ycLngvi+WPiePpOcpErVfaQwa/YPuVPOIx97GSlqV1Zuc4JBeFE7oOLn3SYc25Hm dh4Q== 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=x1IBIrDQgYEiC7lQzUKUpAWSyqPLF36F67SAjcU8RT4=; fh=u3xs68RapeYgyf8J+6FO06hVnIcx/tsubPM81p4b4hk=; b=nVad+PZl4+rfejC1Eho1Xf7t4w2x3fKXEmFTAagkEMmvOpEYah4LZRJG5ZD/zvlaSQ QAhqJqW6QXMoPw3k7ZL70+rjiOelsxIR5jjjD2KYs2HSKYscJPVegWn9VoBnke1B0VTL he1hrmDnlI0OpZ5tL2+eeF2Y6+ldU6YmhxYFv5oszVabnsV/SpU7jfU0nPQ5kJ5pHKFY Mk9tliPmVJ7o8cqpIyDmzkhdnlgPipT/DipSubn306OGFg9yUAq0co5CaTdvUioDzoDa xzEqt2gpxuYQYFhBCa2bU3CziFCKUDwotViDjuLw6DkvVqpDPNHir2slGyIIAVLh/1u0 vahA== 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-39919-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-39919-ouuuleilei=gmail.com@vger.kernel.org" Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id t3-20020a170902e84300b001d67ee9872bsi965693plg.133.2024.01.26.03.13.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jan 2024 03:13:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-39919-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-39919-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-39919-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 35ACBB3746E for ; Fri, 26 Jan 2024 10:09:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C5D971EB46; Fri, 26 Jan 2024 09:27:05 +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 33E82134C7; Fri, 26 Jan 2024 09:27:01 +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=1706261224; cv=none; b=OWgZEbU9UX8rm3VR8EDApvM4lhoDZsG6NDvM/37z+qcjTsNGArSdnFBM9Scu8+eVCRoH88zwAayMYMPOnwqHJJQatl2QFU6dhAHUImQKBQKW01uah7c5++GWkYAwVgn1pttrh3P1/uF4/7wwFuciSxaPJNZICN+NGoYLCrIhN9s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706261224; c=relaxed/simple; bh=soKh8KoYlU+xGErZzdpdc6WEDajiSY4JByH8RDan27I=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=jxJLQUXF6tUYYGkmnDbqPGtTPlClq+tQ9c/B9QpBhF99Le3tfjZ4glMOSnBztFslgqvS1OHM+fbwQBtaKGQuOvtSYH9Zcq3ua1A5fb1RKOPY7FQrXljTqccTcw+kE9YdKKcf3NkiMrgolTtkI+KeOk9EIawVdvN3DSdue6P0uTk= 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 4TLslh5nLwz4f3kKK; Fri, 26 Jan 2024 17:26:56 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 376A41A0175; Fri, 26 Jan 2024 17:26:59 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgCXaBHferNlLsUdCA--.25360S7; Fri, 26 Jan 2024 17:26:59 +0800 (CST) From: linan666@huaweicloud.com To: song@kernel.org, neilb@suse.com, shli@fb.com, mariusz.tkaczyk@linux.intel.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 v4 3/4] md: sync blockdev before stopping raid or setting readonly Date: Fri, 26 Jan 2024 17:22:53 +0800 Message-Id: <20240126092254.1314908-4-linan666@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240126092254.1314908-1-linan666@huaweicloud.com> References: <20240126092254.1314908-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: cCh0CgCXaBHferNlLsUdCA--.25360S7 X-Coremail-Antispam: 1UD129KBjvJXoW7Cw4UuryxXry8Xw43tFW5KFg_yoW8ur4DpF s2yr15Wr1jv34fXr17Ga1DG3WYg34xKrWDtryfA3W8ZFy3A3sxuFZYgF4FvryDK3s3Ga4r tw1UAFn5Wa4xtF7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUmK14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JrWl82xGYIkIc2 x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJw A2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq3wAa c4AC62xK8xCEY4vEwIxC4wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzV Aqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S 6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxw ACI402YVCY1x02628vn2kIc2xKxwAKzVCY07xG64k0F24l42xK82IYc2Ij64vIr41l4I8I 3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxV WUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAF wI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcI k0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j 6r4UJbIYCTnIWIevJa73UjIFyTuYvjfUYlksUUUUU X-CM-SenderInfo: polqt0awwwqx5xdzvxpfor3voofrz/ X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789151293809347455 X-GMAIL-MSGID: 1789151293809347455 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 | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/drivers/md/md.c b/drivers/md/md.c index 40ab5c7ce394..24e33b65c6ff 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -4478,6 +4478,7 @@ array_state_store(struct mddev *mddev, const char *buf, size_t len) { int err = 0; enum array_state st = match_word(buf, array_states); + bool clear_md_closing = false; /* No lock dependent actions */ switch (st) { @@ -4487,6 +4488,17 @@ 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; + clear_md_closing = true; + break; default: break; } @@ -4512,6 +4524,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; @@ -4524,6 +4537,8 @@ array_state_store(struct mddev *mddev, const char *buf, size_t len) break; case clear: err = do_md_stop(mddev, 0, NULL); + if (!err) + clear_md_closing = false; break; case readonly: if (mddev->pers) @@ -4586,6 +4601,10 @@ array_state_store(struct mddev *mddev, const char *buf, size_t len) sysfs_notify_dirent_safe(mddev->sysfs_state); } mddev_unlock(mddev); + + if (clear_md_closing) + clear_bit(MD_CLOSING, &mddev->flags); + return err ?: len; } static struct md_sysfs_entry md_array_state = From patchwork Fri Jan 26 09:22:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Nan X-Patchwork-Id: 192496 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:e09d:b0:103:945f:af90 with SMTP id gm29csp562164dyb; Fri, 26 Jan 2024 02:17:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IHs8EgB3nQn64qcn50V8Lo3O1aN6hOBTd3VrVNBVurcMjHXrOEJ8/7h/zSwozKk6sgZb3hD X-Received: by 2002:ad4:5945:0:b0:685:7cce:6487 with SMTP id eo5-20020ad45945000000b006857cce6487mr965822qvb.118.1706264229144; Fri, 26 Jan 2024 02:17:09 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706264229; cv=pass; d=google.com; s=arc-20160816; b=lY5Z22VdE8F8z8OPu81awHbwZffA22T01RFcQl03Jr2L8d9la8YwT40Xxn5zPm4OlC f7/W/LrHp30yc9eF483gD7hK/Vj7ojY6alZVu1Wla5ejKXFu3jfRtZDOuhqbFMQX0xFH FqF6fHqy6vC5gwNSnUEwndBTVUufQNyycy+38mSJaZ/v4CLHRorhOZKhLCPBCa0QXNHd GFO6Y+YonIfyxp3YFGFQQp+EZqPufVRd0AW17cLIzGD6pzW3IPS/Xbh7nlnKsYM1xrR5 ydAPCF1v35bpeLzyHMh7WJEBKJyvMIHZ3ygMyvMiIKNYPbeYr2pu3oMxryqyILKMGA6N sbMg== 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=5Mi6aC6f4DAt5jme+GnEk5jC2Mx8p6Tt4S220ujETI8=; fh=u3xs68RapeYgyf8J+6FO06hVnIcx/tsubPM81p4b4hk=; b=qf//CY2KDivtCpexooBJrWcQnDP/mxQYHDzbZJEBO5PrukkO4nfliCozfGCIvq/ejo UvNFaA4EL2/jFoh8eGKuEenfJkSsKJj5QQpj5db1seUm7caoaT1qeZrOp1rb5m0hIMtA A0e/ikiSoBg9F7ZpprgsGnGzVU28cucGicp9jBslIlLq5Cn8m3XzoTv41aNUPMJxipQf d9xzqQrcpJFnfsvS8PFbNS70j71yHLtulbyPBFL2AtICFL6sYBkZeqrc/Kjs8XMkU/2F XG2K1FEHMvNCjUj132v8HRpv1OVdta4F7EvKpVS57QM9vtCXIijcAF59kioteqEnV+fF XO8g== 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-39920-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-39920-ouuuleilei=gmail.com@vger.kernel.org" Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id m5-20020ad45dc5000000b006819a28b0basi970794qvh.183.2024.01.26.02.17.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jan 2024 02:17:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-39920-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-39920-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-39920-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 DE3141C2E3BD for ; Fri, 26 Jan 2024 10:09:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 33F611EB5F; Fri, 26 Jan 2024 09:27:06 +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 83EC01A29C; Fri, 26 Jan 2024 09:27:02 +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=1706261224; cv=none; b=J+Ark5dg6Cmnp7f4ygfTWdlBKlot5WYTZMbxpwFvXUe1X13xregTGJo8tNZV7NtY0tx/HcBQ+7Yjr/FNbLJC2FzgL833F3QHWRb/7fbXN3hpmUMyT0U5vkYfHDsZwn2jqPXtq+GEUGGqmd/w/LPHaGn/lmuOaTxtcgr/kzffwNY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706261224; c=relaxed/simple; bh=kir+NFI9Hc5LZ5fsAA20JMPLyqKzJwdYV2OkBR2+Mi8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=tE1wm+mUCH0H+GEiiaCJDGPHjDBUqjJEj7kDWKgDr3mpfGzHCx1ntAD3gJqOW1YNAJoLwhS9tuzDh0ItpzgEsUuc5tg5q1bsOR6LWp/mwJisLE4yjq3tLle/oscs50JPrKTQBwUQVBWZIdMEMffq6POG5ryXEJEpfufL118JxY0= 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 4TLsld2NPvz4f3mHQ; Fri, 26 Jan 2024 17:26:53 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id A763D1A0232; Fri, 26 Jan 2024 17:26:59 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgCXaBHferNlLsUdCA--.25360S8; Fri, 26 Jan 2024 17:26:59 +0800 (CST) From: linan666@huaweicloud.com To: song@kernel.org, neilb@suse.com, shli@fb.com, mariusz.tkaczyk@linux.intel.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 v4 4/4] md: check mddev->pers before calling md_set_readonly() Date: Fri, 26 Jan 2024 17:22:54 +0800 Message-Id: <20240126092254.1314908-5-linan666@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240126092254.1314908-1-linan666@huaweicloud.com> References: <20240126092254.1314908-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: cCh0CgCXaBHferNlLsUdCA--.25360S8 X-Coremail-Antispam: 1UD129KBjvJXoW7tF15CFyUKryfXF4rZrWfGrg_yoW8ur15p3 ySqF98Gr1UXryavr4Ut3WkZa45Xw1xta4ktry7u3yrZF1fJrs8WrWSgF18ArWvgas7Aay5 Xa1UJrW7uFy2g3JanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUQY14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_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: 1789147720124524611 X-GMAIL-MSGID: 1789147720124524611 From: Li Nan If 'mddev->pers' is NULL, there is nothing to do in md_set_readonly(). To simplify the code, move the check of 'mddev->pers' to the caller of md_set_readonly(). Signed-off-by: Li Nan --- drivers/md/md.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/drivers/md/md.c b/drivers/md/md.c index 24e33b65c6ff..ece6eddb2748 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; @@ -6432,28 +6433,25 @@ 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)); err = -EBUSY; goto out; } - if (mddev->pers) { - __md_stop_writes(mddev); - - if (mddev->ro == MD_RDONLY) { - err = -ENXIO; - goto out; - } + __md_stop_writes(mddev); - mddev->ro = MD_RDONLY; - set_disk_ro(mddev->gendisk, 1); + if (mddev->ro == MD_RDONLY) { + err = -ENXIO; + goto out; } + mddev->ro = MD_RDONLY; + set_disk_ro(mddev->gendisk, 1); + out: - if ((mddev->pers && !err) || did_freeze) { + if (!err || did_freeze) { clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery); set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); md_wakeup_thread(mddev->thread); @@ -7772,7 +7770,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: