Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp3930074rdb; Thu, 28 Dec 2023 05:02:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IHc9n35u54+8S8M80la0jD2r2iR9fLXsyYB1AFCj+vxUVvnTAqem2C3ndN/cJO/PM9Vbh+J X-Received: by 2002:a17:902:74c7:b0:1cc:449b:689e with SMTP id f7-20020a17090274c700b001cc449b689emr10973752plt.20.1703768562961; Thu, 28 Dec 2023 05:02:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703768562; cv=none; d=google.com; s=arc-20160816; b=aW5MEhPa1OugsbZ1YZK9cCzkiAj46KbPqHjxGjpvntzlOeUgM5dtHQqwt6gNbXI+MV xogFrRmdp2AUrg8XLWxECKK05j9anomTHvEzlc5W8EAt5CR6z7OIHGCQnm+6Y6zP2vF9 aoL9gLEAPFkPBhg69ay+5EVo48+9St/tUQ6rvKE0zPiaIDhwEdULl8Gm4aHXg5pDuCOI ZjiNR8q1jWjtRZT7f0M6yTCCEUDBHA+qZUUNsGQzyA9ocqDBBW/Uz8ANiGNx8PcbC+/E lgftvGVQow11wPG37JER4U+hagu0zwDhZGRQdod9Zkw5yxUQXs4qha2s7zddB/hPkV0Y n/kg== ARC-Message-Signature: i=1; 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=PTXkHpvo36cfN81uAjIp3VvTUbEHvHpx14vS/MaXcPM=; fh=inucGFr1xsz6a94DIfUTXxw97Je/3Nu0zw5/V4Qmqiw=; b=g2b9mKW9xMMvE9i/2iVkqAfuYrRemkqkr2sz6egActY+yHAQi1LIFpXXwKe5oYqabE CMkX+Ox8Bhvx6KMHgpbAWm6hvzEQ1D/MX3zrpvH+GP4JmEi4RJAC/LwrKoFXNOZksSvA 6UO+prJYVBotRjgnHx0kXNyfqgku70ekDx9Lvwajjz6HEjeO4xynTF4p/f6kiHMyG6Vz crYQZf3GNd8EnVYv8YTZHWFiYM1UDKiEgEEadeyXHafWKG11tESOYJDW+CA3hVwO/6Vo WTwGcGex1z/y+Y2RE+KYLH+0U7UqLypi7cklgDhMVXrn6kbNwzE9ALg+qrDz5Rt5zUDM G5IQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-12657-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12657-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id q18-20020a170902dad200b001d36c48d5f5si6762512plx.364.2023.12.28.05.02.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Dec 2023 05:02:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-12657-linux.lists.archive=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; spf=pass (google.com: domain of linux-kernel+bounces-12657-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12657-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 83696B23E5B for ; Thu, 28 Dec 2023 13:01:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ECE0C11C9D; Thu, 28 Dec 2023 12:58:25 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org 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 6E0C5107AD; Thu, 28 Dec 2023 12:58:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4T17pv4F0vz4f3k5f; Thu, 28 Dec 2023 20:58:15 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 267D91A017F; Thu, 28 Dec 2023 20:58:17 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgBHlQvmcI1lvcx3Ew--.36075S5; Thu, 28 Dec 2023 20:58:16 +0800 (CST) From: Yu Kuai To: song@kernel.org, yukuai3@huawei.com, neilb@suse.de Cc: linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org, yukuai1@huaweicloud.com, yi.zhang@huawei.com, yangerkun@huawei.com Subject: [PATCH -next 1/3] md: remove redundant check of 'mddev->sync_thread' Date: Thu, 28 Dec 2023 20:55:51 +0800 Message-Id: <20231228125553.2697765-2-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231228125553.2697765-1-yukuai1@huaweicloud.com> References: <20231228125553.2697765-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:cCh0CgBHlQvmcI1lvcx3Ew--.36075S5 X-Coremail-Antispam: 1UD129KBjvJXoWxXw1DCw4xAF1UCw4rKrWUXFb_yoWrAr18pa yIyF98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sync_thread: 1) Set MD_RECOVERY_NEEDED and wake up daemon thread (by ioctl/sysfs or other events); 2) Daemon thread woke up, md_check_recovery() found that MD_RECOVERY_NEEDED is set: a) try to grab reconfig_mutex; b) set MD_RECOVERY_RUNNING; c) clear MD_RECOVERY_NEEDED, and then queue sync_work; 3) md_start_sync() choose sync_action, then register sync_thread; 4) md_do_sync() is done, set MD_RECOVERY_DONE and wake up daemon thread; 5) Daemon thread woke up, md_check_recovery() found that MD_RECOVERY_DONE is set: a) try to grab reconfig_mutex; b) unregister sync_thread; c) clear MD_RECOVERY_RUNNING and MD_RECOVERY_DONE; Hence there is no such case that MD_RECOVERY_RUNNING is not set, while sync_thread is registered. Signed-off-by: Yu Kuai --- drivers/md/md.c | 14 ++++---------- drivers/md/raid5.c | 6 ++---- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/drivers/md/md.c b/drivers/md/md.c index 9bdd57324c37..2208eed3baac 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -3314,8 +3314,7 @@ static ssize_t new_offset_store(struct md_rdev *rdev, if (kstrtoull(buf, 10, &new_offset) < 0) return -EINVAL; - if (mddev->sync_thread || - test_bit(MD_RECOVERY_RUNNING,&mddev->recovery)) + if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)) return -EBUSY; if (new_offset == rdev->data_offset) /* reset is always permitted */ @@ -3993,8 +3992,7 @@ level_store(struct mddev *mddev, const char *buf, size_t len) */ rv = -EBUSY; - if (mddev->sync_thread || - test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) || + if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) || mddev->reshape_position != MaxSector || mddev->sysfs_active) goto out_unlock; @@ -6388,7 +6386,6 @@ static int md_set_readonly(struct mddev *mddev, struct block_device *bdev) mutex_lock(&mddev->open_mutex); if ((mddev->pers && 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; @@ -6441,7 +6438,6 @@ static int do_md_stop(struct mddev *mddev, int mode, mutex_lock(&mddev->open_mutex); if ((mddev->pers && atomic_read(&mddev->openers) > !!bdev) || 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); @@ -7287,8 +7283,7 @@ static int update_size(struct mddev *mddev, sector_t num_sectors) * of each device. If num_sectors is zero, we find the largest size * that fits. */ - if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) || - mddev->sync_thread) + if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)) return -EBUSY; if (!md_is_rdwr(mddev)) return -EROFS; @@ -7325,8 +7320,7 @@ static int update_raid_disks(struct mddev *mddev, int raid_disks) if (raid_disks <= 0 || (mddev->max_disks && raid_disks >= mddev->max_disks)) return -EINVAL; - if (mddev->sync_thread || - test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) || + if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) || test_bit(MD_RESYNCING_REMOTE, &mddev->recovery) || mddev->reshape_position != MaxSector) return -EBUSY; diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c index 26e1e8a5e941..e3a216e51e3f 100644 --- a/drivers/md/raid5.c +++ b/drivers/md/raid5.c @@ -7025,10 +7025,8 @@ raid5_store_stripe_size(struct mddev *mddev, const char *page, size_t len) pr_debug("md/raid: change stripe_size from %lu to %lu\n", conf->stripe_size, new); - if (mddev->sync_thread || - test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) || - mddev->reshape_position != MaxSector || - mddev->sysfs_active) { + if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) || + mddev->reshape_position != MaxSector || mddev->sysfs_active) { err = -EBUSY; goto out_unlock; } -- 2.39.2