Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp1614178rdh; Mon, 25 Sep 2023 20:05:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGYMUj/zlT2xDJsFaKiurDB+LKJnzW1bKcuTbIXoix+ySyvaWPIO2DpWGEZmKbV5AuFn9vx X-Received: by 2002:a05:6a20:9147:b0:13e:debc:3657 with SMTP id x7-20020a056a20914700b0013edebc3657mr1682204pzc.30.1695697509335; Mon, 25 Sep 2023 20:05:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695697509; cv=none; d=google.com; s=arc-20160816; b=FMRqJiJl/egkXt9YzszFzQ5x69xsZ8icvYCKgEXvacbE+A5zs4wHPEhDSW82wqOGua HDQ3MywY4byC7KV6eY3AcqP0d+2UgbRbmiQjjWlglejSFUzG5HvHQbnTHj4t7Pd4e40W 3ZinSrMPjh71/yItXF4YkYRPvdZshiXDizJIreZV86mTqjdxt3utrYQiuLVVNfydvh3W FkW+3KexzxqC2Kq45uneWVefZI0LZyHmPD2Kis2NGywlbAZdk3TlmlSue6EyPZ6lfDf4 O64JmjL5LduQ7o+juh4iMfz0jWt7/hgH1aebQ3gXeXm+2WaQj9zEGvkRu5Q6e1QhA+On PesA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=eDYrqx+BnMnA2duQnYL9S02i66lJYEuvbS0dc4uP4H0=; fh=j7ithBTyrb3RTLNZbal/inTEAY4pmW0TjhZv3VF+64M=; b=PBPxrqqGkE/6FW+wj78Zzv+Pj0H1+lIn3Lu45d7BebCAdOUJC5YHMBSXk/nS2guyjD zd8sJBxey77Wh+sW3U/GeH2LC2MAu3S/HSc+Z3vDw6E59lbN3/RSfNFjB3jbfy7D5+Xs tar5kjC2HAUB+OXKa/xvQ4t8PqIxp+mAwf/Ex4/O3OiSPYPygq0kqBb7gsDOE+GeTwQA TqYIHHa3uUPULc9TfNwH3rxNO/3q4xShe83vWRb9wgW8ewLBZjWJCUccN46N3bj27uUf wnXU8acsQxV/87c27UhC0j3MlbtgLp1C0evLqE2i1RbpzmEg6OS+N4/OlGcdzG2+ero6 uHNw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id cm22-20020a056a00339600b00690c951d2cesi11231135pfb.191.2023.09.25.20.05.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 20:05:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 4B402811ED85; Mon, 25 Sep 2023 20:05:07 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231513AbjIZDFD (ORCPT + 99 others); Mon, 25 Sep 2023 23:05:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229882AbjIZDFA (ORCPT ); Mon, 25 Sep 2023 23:05:00 -0400 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42315F3; Mon, 25 Sep 2023 20:04:54 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4Rvl2k3G1dz4f3n6N; Tue, 26 Sep 2023 11:04:30 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP4 (Coremail) with SMTP id gCh0CgDnfd0+ShJlShWjBQ--.31625S5; Tue, 26 Sep 2023 11:04:32 +0800 (CST) From: Yu Kuai To: mariusz.tkaczyk@linux.intel.com, xni@redhat.com, song@kernel.org Cc: linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org, yukuai3@huawei.com, yukuai1@huaweicloud.com, yi.zhang@huawei.com, yangerkun@huawei.com Subject: [PATCH v2 1/2] md: factor out a new helper to put mddev Date: Tue, 26 Sep 2023 10:58:26 +0800 Message-Id: <20230926025827.671407-2-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230926025827.671407-1-yukuai1@huaweicloud.com> References: <20230926025827.671407-1-yukuai1@huaweicloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: gCh0CgDnfd0+ShJlShWjBQ--.31625S5 X-Coremail-Antispam: 1UD129KBjvJXoW7Kr47Kr4xtrykurWUWr1kGrg_yoW8XF1fpa 1Sga98CrWUXFZaq3yUCa9ru3W5J3WvkrWDtryxG393ZFy3Kr1DWw1Fqa1UXr15Ga4fZFsI va1jqF1Uur18XrUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUU9v14x267AKxVW5JVWrJwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_Jr4l82xGYIkIc2 x26xkF7I0E14v26r1I6r4UM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Cr1j6rxdM2 8EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0DM2AI xVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20x vE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xv r2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7MxAIw28IcxkI7VAKI48JMxC20s 026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_ JrI_JrWlx4CE17CEb7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14 v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xva j40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8JV W8JrUvcSsGvfC2KfnxnUUI43ZEXa7VUbec_DUUUUU== X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Mon, 25 Sep 2023 20:05:07 -0700 (PDT) From: Yu Kuai There are no functional changes, the new helper will still hold 'all_mddevs_lock' after putting mddev, and it will be used to simplify md_seq_ops. Signed-off-by: Yu Kuai --- drivers/md/md.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/drivers/md/md.c b/drivers/md/md.c index 10cb4dfbf4ae..a5ef6f7da8ec 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -616,10 +616,15 @@ static inline struct mddev *mddev_get(struct mddev *mddev) static void mddev_delayed_delete(struct work_struct *ws); -void mddev_put(struct mddev *mddev) +static void __mddev_put(struct mddev *mddev, bool locked) { - if (!atomic_dec_and_lock(&mddev->active, &all_mddevs_lock)) + if (locked) { + spin_lock(&all_mddevs_lock); + if (!atomic_dec_and_test(&mddev->active)) + return; + } else if (!atomic_dec_and_lock(&mddev->active, &all_mddevs_lock)) return; + if (!mddev->raid_disks && list_empty(&mddev->disks) && mddev->ctime == 0 && !mddev->hold_active) { /* Array is not configured at all, and not held active, @@ -633,7 +638,14 @@ void mddev_put(struct mddev *mddev) */ queue_work(md_misc_wq, &mddev->del_work); } - spin_unlock(&all_mddevs_lock); + + if (!locked) + spin_unlock(&all_mddevs_lock); +} + +void mddev_put(struct mddev *mddev) +{ + __mddev_put(mddev, false); } static void md_safemode_timeout(struct timer_list *t); -- 2.39.2