Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp997602rdb; Wed, 24 Jan 2024 01:20:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IHNQTPosMz+Q/g3reNR40Z6gfpzSNG8x217GgavGdqOaeCLp2ARv17y/3jN6Rjx+t5qVsJP X-Received: by 2002:a05:6512:3e21:b0:50e:c82b:3637 with SMTP id i33-20020a0565123e2100b0050ec82b3637mr1701723lfv.74.1706088051632; Wed, 24 Jan 2024 01:20:51 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706088051; cv=pass; d=google.com; s=arc-20160816; b=qYt/DjnIj5yH8ClaeSLIwnX1BmSOgOAxhvr0WGLpVP66ffFSbwBPTwPsc7opYLe65x GYDin/ZqNhFwvWoMwftXmkNzK38NUKAcrjfAjy0aSH4PNvvFejIrB4Fs4oF4pLuutBGA /9SkvyhMQqH3e2KXZ5J40UkHO3k//++/pQZHM9Dm4kpe6oiOcg7RyMzMfB5RWlIEMFfp c/0URzFYsQOrTxrUrho9nTx4nmYgVDnhF/G+TwlAx/qjdlLC0EJOk06QcngT0qfJO6h6 PlhFNme4bC8tW6d4RBfGevinkZx6iFCn002EtUsKv5UrinNh4J/n2jSywaK4bBlaDpgs BHiQ== 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=BCg4cERelT8HEkZAmRmXqxbt+PHDp55KsPlH0NBvFxI=; fh=SaJ9rWjnsGFI+7ibUS2Ywr9D7BSRvW01ZC90UJpOFqs=; b=feB1GUaNa9wZljoiapRfSpFkd0tp0ZuG81I/ovXtJkyNt68Y8Jrd/6dFaDH+C0WtUt HvoaPFKohhnheTepC4fKt0HuAIMJUvHgaElSBAuo45YD7YNhkGejzcqQkI3v9Om7+oO4 04RZRIPZQXcbikL7m8tcLeSExKnH19PN2ZSMn6mrgpMSqAG442S12GpoZiOjYcj7n248 6xwihuuXRM7SOx06bDcDs8cVv9Cr4GNLpzlnTSb7l8g/8ADYtOlpVE5LtbC0+tNyW4CZ FfAH22ZaC2h9nm5OEPqeTZB8VOBRIttUQKnIq4VqBe+mhubNEE+XHVmZHYOMdGHIfTEL 2STg== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-36696-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-36696-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id b2-20020a1709062b4200b00a2a6fa4457dsi12737725ejg.397.2024.01.24.01.20.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 01:20:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-36696-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-36696-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-36696-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 59B301F2633B for ; Wed, 24 Jan 2024 09:20:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EF1AD18027; Wed, 24 Jan 2024 09:19:51 +0000 (UTC) Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) (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 974C217C67; Wed, 24 Jan 2024 09:19:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.190 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706087991; cv=none; b=ah6oEY/yEnM+qfb2YRw7xCPEch7Cyr1/TivsBEcjDRbCq6FpxF8cICFya6Fyeli+qBH1C6RMujeAPoMr4ti+Gs4MYWxLtVtKm/2MXr9TO+vPrqrAc6QGnndj9QkGXTeu4KXWZ1u3mUjheujGffe8/5LqXGS+7Ls6Z1GcGSBPnlM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706087991; c=relaxed/simple; bh=zbq5mTq1vwpbLsA7BkaKJDAM1FT2S8s+HUXg+ohYWY4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=GQ45zWEkvCefaJfzeceRqJ6T1HOHwfb1iGiBhv5DFLW/x1Judj6pHT1QvNcyTmATdB9v0lvHoVBaL3vG1CXtE+MGMxLoQ68Gfpw5aYC8rmJuJrTHnDXr9Hle2r6viNW7H+8he4ckSSZJ7sxFhzGrCpt4e5Qmb9wTDdf+ZSL9yRs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.190 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.214]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4TKdgM0wsNz1xmWl; Wed, 24 Jan 2024 17:18:55 +0800 (CST) Received: from kwepemm600009.china.huawei.com (unknown [7.193.23.164]) by mail.maildlp.com (Postfix) with ESMTPS id 7D0591A017B; Wed, 24 Jan 2024 17:19:32 +0800 (CST) Received: from huawei.com (10.175.104.67) by kwepemm600009.china.huawei.com (7.193.23.164) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Wed, 24 Jan 2024 17:18:21 +0800 From: Yu Kuai To: , , , , , , , , , , , CC: , , , , Subject: [PATCH v2 05/11] md: export helpers to stop sync_thread Date: Wed, 24 Jan 2024 17:14:15 +0800 Message-ID: <20240124091421.1261579-6-yukuai3@huawei.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240124091421.1261579-1-yukuai3@huawei.com> References: <20240124091421.1261579-1-yukuai3@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemm600009.china.huawei.com (7.193.23.164) The new heleprs will be used in dm-raid in later patches to fix regressions and prevent calling md_reap_sync_thread() directly. Signed-off-by: Yu Kuai --- drivers/md/md.c | 41 +++++++++++++++++++++++++++++++++++++---- drivers/md/md.h | 3 +++ 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/drivers/md/md.c b/drivers/md/md.c index 6c5d0a372927..90cf31b53804 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -4915,30 +4915,63 @@ static void stop_sync_thread(struct mddev *mddev, bool locked, bool check_seq) mddev_lock_nointr(mddev); } -static void idle_sync_thread(struct mddev *mddev) +void md_idle_sync_thread(struct mddev *mddev) { + lockdep_assert_held(mddev->reconfig_mutex); + mutex_lock(&mddev->sync_mutex); clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery); + stop_sync_thread(mddev, true, true); + mutex_unlock(&mddev->sync_mutex); +} +EXPORT_SYMBOL_GPL(md_idle_sync_thread); + +void md_frozen_sync_thread(struct mddev *mddev) +{ + lockdep_assert_held(mddev->reconfig_mutex); + + mutex_lock(&mddev->sync_mutex); + set_bit(MD_RECOVERY_FROZEN, &mddev->recovery); + stop_sync_thread(mddev, true, false); + mutex_unlock(&mddev->sync_mutex); +} +EXPORT_SYMBOL_GPL(md_frozen_sync_thread); +void md_unfrozen_sync_thread(struct mddev *mddev) +{ + lockdep_assert_held(mddev->reconfig_mutex); + + mutex_lock(&mddev->sync_mutex); + 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_action); + mutex_unlock(&mddev->sync_mutex); +} +EXPORT_SYMBOL_GPL(md_unfrozen_sync_thread); + +static void idle_sync_thread(struct mddev *mddev) +{ if (mddev_lock(mddev)) { mutex_unlock(&mddev->sync_mutex); return; } + mutex_lock(&mddev->sync_mutex); + clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery); stop_sync_thread(mddev, false, true); mutex_unlock(&mddev->sync_mutex); } static void frozen_sync_thread(struct mddev *mddev) { - mutex_lock(&mddev->sync_mutex); - set_bit(MD_RECOVERY_FROZEN, &mddev->recovery); - if (mddev_lock(mddev)) { mutex_unlock(&mddev->sync_mutex); return; } + mutex_lock(&mddev->sync_mutex); + set_bit(MD_RECOVERY_FROZEN, &mddev->recovery); stop_sync_thread(mddev, false, false); mutex_unlock(&mddev->sync_mutex); } diff --git a/drivers/md/md.h b/drivers/md/md.h index 8d881cc59799..437ab70ce79b 100644 --- a/drivers/md/md.h +++ b/drivers/md/md.h @@ -781,6 +781,9 @@ extern void md_rdev_clear(struct md_rdev *rdev); extern void md_handle_request(struct mddev *mddev, struct bio *bio); extern int mddev_suspend(struct mddev *mddev, bool interruptible); extern void mddev_resume(struct mddev *mddev); +extern void md_idle_sync_thread(struct mddev *mddev); +extern void md_frozen_sync_thread(struct mddev *mddev); +extern void md_unfrozen_sync_thread(struct mddev *mddev); extern void md_reload_sb(struct mddev *mddev, int raid_disk); extern void md_update_sb(struct mddev *mddev, int force); -- 2.39.2