From patchwork Thu Feb 1 09:25:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Kuai X-Patchwork-Id: 195222 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2719:b0:106:209c:c626 with SMTP id hl25csp30535dyb; Thu, 1 Feb 2024 01:33:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IEppRaMOi0GZSywjVBWSbqBlO/D8fI2p6ojUj5iqnsQhRdewhr8WwnhMS5DPUIWm9ezWIYV X-Received: by 2002:a05:620a:450f:b0:783:915c:1fc4 with SMTP id t15-20020a05620a450f00b00783915c1fc4mr2200359qkp.20.1706780020667; Thu, 01 Feb 2024 01:33:40 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706780020; cv=pass; d=google.com; s=arc-20160816; b=A8Tjqeecp6Bb0GGri2US3MgE9P1pKqeKzZve5vCRAB0s+DcV5uNDMA4kuViMdLV/8d M/GyG2LVmz128jVGzy6NsBog0KsJhfgydOcVuItNQPCOHaSnS/Zsh8q4Zed0yIII1r0M 8so1ZKPmuJCZ7n29qiGWxTnJSqz2Pol9eU/olkGFRCn3xmIzA2sC+2La4Nnl6QKZ3w37 ko0q0bCZVaoAVN4WngNmb2EEsns7Nq09QZsqvoxFWRQqXUCLET1utlGQpz0e49+BP6sD s9nUUn9SYg65sPZbWsgx8k7SqkZLFFCMGDlf31iPhTbWwyG8BG3c9wdUDMJAbZz32V7L 8Odg== 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=b3eJ83DrviuTqQQ68RGTsQGR0o7HCSRQU/aKwxPS4Cw=; fh=DTliBXooeebxRJ74TDpr0yJW1IdUrMVl4+4KQuEojLQ=; b=GIuYS18EO0TokSI06gbtWFRwIcIWNqJBqhX+ewcwbt/+WflkVBtYO0LguELppfK2A8 V8/dtAI67Fgfr/y1ve6GF33e9MzhpdzwwjvgGGPhntirCjv09wQj4IT0W48WURJbKljX rrrihk4/aUydvw31eKGLkXLcvGJkgq000TBCgC5HhY6g/1CrOO3DppZ3Oq8kne0U0fOW NLfspqauwJLaOfRpRncU8bzOJe0mmUP2kFXoGOYEZBYUL0IvTM20/i17WL954rOcU54t Vqt81ah6heW4LLyorwuoXGxXZh/Te1RiiENT+aKLlCxa5Pz8aORxgGUCSxPojZqO1hyA qLkA==; 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-47871-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47871-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCXGWxvbLwRFqUwFFFactyMEYibpM4BUb6tPDt/8YkmZu1ChKt4BSQ2lu6VEGn9kJ7w8YV6BDALD5YWRpzo6UrlPcrkbHA== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id vr15-20020a05620a55af00b00783e118ed11si12015191qkn.482.2024.02.01.01.33.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 01:33:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-47871-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-47871-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47871-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 710CD1C27D08 for ; Thu, 1 Feb 2024 09:33:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 524E4161B46; Thu, 1 Feb 2024 09:30:38 +0000 (UTC) Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 55D6115B965; Thu, 1 Feb 2024 09:30:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706779835; cv=none; b=Fcne0xVoYDYygn5n1eS8uMH+5/6U3+qnZPY/XYXzF60XSDBmPFTb8dPb/8FFhuxnTf4CzLvvuPdu/yzt9KueKV/uV9vSUfGkUkrHckl0eJxlCCcmrcA+VFgGyWYrTc7iQjaX1ZOpe+Svmeq+OJV0xCB++jb+S0lJ49Bqte3Twf8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706779835; c=relaxed/simple; bh=NZ1TzNGo0Z0m3MqtenTynFlNQ6IJhqAzTBTv1Jw/zxo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=R0c3ai94OwiLxCbTzAwdC30R6LnCbNloBy/YqfSgsboc3BDaCJE0XyWFdskKJL115fx1IdcfnwvsevC49eafOkb0CIKHhwgWXuoz+xAwQRGg4QT9FUbLyiMfAEQYqdMow03iH9vXUA+xL+2UF5I9pBeu+0W1wilCji4vVAB3BAw= 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 4TQYXy1qNxz4f3l7V; Thu, 1 Feb 2024 17:30:26 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 731E01A038B; Thu, 1 Feb 2024 17:30:30 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgCXaBGtZLtl8V6KCg--.33515S11; Thu, 01 Feb 2024 17:30:30 +0800 (CST) From: Yu Kuai To: mpatocka@redhat.com, heinzm@redhat.com, xni@redhat.com, blazej.kucman@linux.intel.com, agk@redhat.com, snitzer@kernel.org, dm-devel@lists.linux.dev, song@kernel.org, yukuai3@huawei.com, jbrassow@f14.redhat.com, neilb@suse.de, shli@fb.com, akpm@osdl.org Cc: linux-kernel@vger.kernel.org, linux-raid@vger.kernel.org, yukuai1@huaweicloud.com, yi.zhang@huawei.com, yangerkun@huawei.com Subject: [PATCH v5 07/14] md: export helpers to stop sync_thread Date: Thu, 1 Feb 2024 17:25:52 +0800 Message-Id: <20240201092559.910982-8-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240201092559.910982-1-yukuai1@huaweicloud.com> References: <20240201092559.910982-1-yukuai1@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: cCh0CgCXaBGtZLtl8V6KCg--.33515S11 X-Coremail-Antispam: 1UD129KBjvJXoWxZryrJF1rCF1fuFyDGF1Utrb_yoW5CFWrpr WIq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trlr6x35dzhxuhorxvhhfrp/ X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789688566970417638 X-GMAIL-MSGID: 1789688566970417638 From: Yu Kuai 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 | 33 +++++++++++++++++++++++++++++++-- drivers/md/md.h | 3 +++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/drivers/md/md.c b/drivers/md/md.c index 9e41a9aaba8b..19f16a77cf9c 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -4919,16 +4919,45 @@ static void stop_sync_thread(struct mddev *mddev, bool locked, bool check_seq) mddev_lock_nointr(mddev); } +void md_idle_sync_thread(struct mddev *mddev) +{ + lockdep_assert_held(&mddev->reconfig_mutex); + + clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery); + stop_sync_thread(mddev, true, true); +} +EXPORT_SYMBOL_GPL(md_idle_sync_thread); + +void md_frozen_sync_thread(struct mddev *mddev) +{ + lockdep_assert_held(&mddev->reconfig_mutex); + + set_bit(MD_RECOVERY_FROZEN, &mddev->recovery); + stop_sync_thread(mddev, true, false); +} +EXPORT_SYMBOL_GPL(md_frozen_sync_thread); + +void md_unfrozen_sync_thread(struct mddev *mddev) +{ + lockdep_assert_held(&mddev->reconfig_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); +} +EXPORT_SYMBOL_GPL(md_unfrozen_sync_thread); + static void idle_sync_thread(struct mddev *mddev) { mutex_lock(&mddev->sync_mutex); - clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery); if (mddev_lock(mddev)) { mutex_unlock(&mddev->sync_mutex); return; } + clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery); stop_sync_thread(mddev, false, true); mutex_unlock(&mddev->sync_mutex); } @@ -4936,13 +4965,13 @@ static void idle_sync_thread(struct mddev *mddev) 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; } + 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);