Received: by 2002:a05:7412:ba23:b0:fa:4c10:6cad with SMTP id jp35csp1524617rdb; Sat, 20 Jan 2024 02:41:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IHYlLtS2EfIH/NLdMz6MbQMInYj1zJhQCwsdsCa5pNtNhj7xbXba2Yu+oj+VRbJPOqVAR7/ X-Received: by 2002:a05:620a:240f:b0:781:581f:f48 with SMTP id d15-20020a05620a240f00b00781581f0f48mr1533185qkn.125.1705747298746; Sat, 20 Jan 2024 02:41:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705747298; cv=pass; d=google.com; s=arc-20160816; b=dmXFebHZUyuUAPDM+9JNm5EA2JMiHLQDWFHAMH/eOjerMQ5ki86XrUaFDZk/B5pBZM VutEBv42rGWdQbWwjIaeI7vY9a/tFB0ppIpz9tiHdLJYA8JEGe2M3uivWJ6BXZd2S+FV y5DwaHKtK7+CMoivFcvn4RUJi5s+zUzemnFx+qEoHMHlOdfiDDWBMM0wJ+2AJ3d+lL7j OcsWjdnL+j+4sX8SO7mzWvdBce9XVJc4xq+2H/Q2fyHfnoIjnA/QZ1PvCHCGBKNJeK/Y IXNyOt5sG+qoLnlebpqYpfMynDQDNdSqYZGBCPSNLwMWYczJ1FY9c1EEfkOuHYnDyjUc SIyA== 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=nrtSR/YAXze4kaPPkc4IMcl7Wj/hz8xCZK3LMn4eWKE=; fh=y2Ma2pP32dbTTwcFlrDJ//qG1pVVCx07l+xa/F5EZpc=; b=0F1xRMthGUsgWQs5po8FuiaX3Lt0kCwskfgNUt3WQNmhq0o3CkHRby90wkUT9ga/lr UdEeKLf1QYKTsgMJ4/pRG2XmQHkFQ1G+ansHj6TLMHAKFs4qRa4Kow75Dn6V+W6nOUnR k+qmIavXVdgTHqyO4EyMlfVKLYTf3e2mRhZLYzWGL1XZm2eFPZFKDfp3HTXJz9YFLHYD 1kbOx/CDqUgbs09ixZsMwoWgGUt+a1wDhIRfqtHCErq6ZOK4GMNEu85YdY+sAheM/WfT kUXLq+ThVugpJ5+wniE5lGTcS6BS/r1xnbybcP3YT3AAM9Dy63nwjWZEOZywCQ4FX7tv Ndqg== 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-31760-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-31760-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id n27-20020a05620a223b00b0078326674eabsi1182060qkh.409.2024.01.20.02.41.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Jan 2024 02:41:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-31760-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-31760-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-31760-linux.lists.archive=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 82F4D1C21165 for ; Sat, 20 Jan 2024 10:41:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ED97FDDCA; Sat, 20 Jan 2024 10:41:22 +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 C59DBD502; Sat, 20 Jan 2024 10:41:20 +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=1705747282; cv=none; b=O4bFDLIevcCHGDa7Kn0s/b9zk/Bb53JMixQbVzpYlvZnoEfAlnAEWeSYxmqtWdedgsyJjZPmUj2DySskLNJ1odue4qm5kt4HRtmhYQWfjYgb/vob3Du0z2A0dOylpq/dXRt/GMoSrCq/Ea7AqhlFCYs56rHGV2pEcVjuCGpz6rg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705747282; c=relaxed/simple; bh=7f5Ea4YOXZsVcffF1Kp4uocWgltKhjuUuA7JtCWrFY0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=BwR6oGid3Ec/6XM4Xtheoij7y78mzY/ShrmYP0+yA/rpBsf4OLbm0InE8LkxQJkrNqEGWYoQgStK5c15awTY8yQ65DJu90FCu+sh8wHaESnVF4cBFzETzOcfaEvYgtjLfR7NeWHCMzGLVEE2ObRpZjDhnzgiKUWchbt0eA/V7lY= 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 4THCh75rjtz4f3l1m; Sat, 20 Jan 2024 18:41:11 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 05CBA1A0B44; Sat, 20 Jan 2024 18:41:18 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+RFKo6tlY4mmBQ--.38494S7; Sat, 20 Jan 2024 18:41:17 +0800 (CST) From: Yu Kuai To: mpatocka@redhat.com, dm-devel@lists.linux.dev, msnitzer@redhat.com, heinzm@redhat.com, song@kernel.org, yukuai3@huawei.com Cc: linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org, yukuai1@huaweicloud.com, yi.zhang@huawei.com, yangerkun@huawei.com Subject: [PATCH 3/5] md: make sure md_do_sync() will set MD_RECOVERY_DONE Date: Sat, 20 Jan 2024 18:37:32 +0800 Message-Id: <20240120103734.4155446-4-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240120103734.4155446-1-yukuai1@huaweicloud.com> References: <20240120103734.4155446-1-yukuai1@huaweicloud.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 X-CM-TRANSID:cCh0CgAn+RFKo6tlY4mmBQ--.38494S7 X-Coremail-Antispam: 1UD129KBjvJXoW7WF48JF18KF45Gw4rCFy7GFg_yoW8Ar1kpa ykGF9IvrW8ArW3urW2qa4DXa45Aw1Ivry3CFyfuas8AF1fta1akFW5uF1UXaykta4fJayY va15JF9xZF95C3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBK14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JrWl82xGYIkIc2 x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Cr0_Gr1UM2 8EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0DM2AI xVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20x vE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xv r2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7M4IIrI8v6xkF7I0E8cxan2IY04 v7MxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_ Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUtVW8ZwCIc40Y0x 0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8 JVWxJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIx AIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7VUbJ73DUUUUU= = X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ From: Yu Kuai stop_sync_thread() will interrupt md_do_sync(), and md_do_sync() must set MD_RECOVERY_DONE, so that follow up md_check_recovery() will unregister sync_thread, clear MD_RECOVERY_RUNNING and wake up stop_sync_thread(). Before this patch, if MD_RECOVERY_WAIT is set or the array is read-only, md_do_sync() will return without setting MD_RECOVERY_DONE, hence use stop_sync_thread() directly will hang because md_check_recovery() can't clear MD_RECOVERY_RUNNING, which is possible for dm-raid. Signed-off-by: Yu Kuai --- drivers/md/md.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/md/md.c b/drivers/md/md.c index 6906d023f1d6..ba45c7be3dbe 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -8788,12 +8788,13 @@ void md_do_sync(struct md_thread *thread) int ret; /* just incase thread restarts... */ - if (test_bit(MD_RECOVERY_DONE, &mddev->recovery) || - test_bit(MD_RECOVERY_WAIT, &mddev->recovery)) + if (test_bit(MD_RECOVERY_DONE, &mddev->recovery)) return; - if (!md_is_rdwr(mddev)) {/* never try to sync a read-only array */ + + if (test_bit(MD_RECOVERY_WAIT, &mddev->recovery) || + !md_is_rdwr(mddev)) {/* never try to sync a read-only array */ set_bit(MD_RECOVERY_INTR, &mddev->recovery); - return; + goto out; } if (mddev_is_clustered(mddev)) { @@ -9171,6 +9172,7 @@ void md_do_sync(struct md_thread *thread) mddev->array_sectors); } +out: spin_lock(&mddev->lock); if (!test_bit(MD_RECOVERY_INTR, &mddev->recovery)) { /* We completed so min/max setting can be forgotten if used. */ -- 2.39.2