Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp2286425rdh; Tue, 26 Sep 2023 20:03:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFmOwlbtkLNDqKfjjH7fXnIKOqHpcugfix9/UMxLPa03m0Uyd7sFsQognlaNbSnnlqjjW9t X-Received: by 2002:a17:902:d4d1:b0:1bd:d6b5:a54f with SMTP id o17-20020a170902d4d100b001bdd6b5a54fmr723961plg.55.1695783827288; Tue, 26 Sep 2023 20:03:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695783827; cv=none; d=google.com; s=arc-20160816; b=Mem3VllBlc+iNUR1I0x3H7CIJmKupbdEMhvklpvtSC6wZhXkXpy85JAGwpDjRwQttS W/kO7JAmp+LZGwTANx2HODe70Qh5KP7DCEvwM2U1a/yRrAfY2lc/wdOE2P0MbzWS6Pzg exPG4TO1K+yEM4Y8dgo5VknqrnK0bTKAcVy3K+2oVSk6TVmHnzZ8U8LPy+/hREmnJLmP +O25QNnJHuprjTctilKGGzJzCHCUUnLb0uHDUrsKx9X2qgN5Efqc41g/LHy4y0ksoyfh BbJlajNXAAgdKosHlHX0zSmcPaWkI6IbANHUSEzvdBuWpXGt4KmrDZVDybshHupKEy5a jaBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=YaANvwV5bCzi2VSNHmJt9nzKG2Ybs51UBIuMWWY/uko=; fh=1ZQzoRqTVujMrMQvqbS60Jjo8Alq+FzhfX8iaxIMWGI=; b=aD4JAy9NSiJGr+ir8mVk1SqIuyiMZbr/weAsO6FZINBHaINcolMWggm0Xb1WRaZQJO Nc2hi47nEh+F+JhoNoaWmT20GEqehNnNLvB4I/qlQPISFfKkhitylUEUW0hAcdY4Pgvy E/Dbpr4/2dHexZosDlDegDs1DPHhdyBY7jI6tBJyGG470s8b33k5SJc3gIiVWvHW75Hp M7m953zvNaPIBN7++zaPzCwH49e7Nwp98L384cw+4NALQVe8We8v8XeOgVdoZ8B/c0Zt wAiVqJDLd1OqYKeCWa3cZfJk7UI2zfsL4ZwNIZ+baoJL64k8aNhaMUNJwsA7oMNiTIuV NXYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=sRu55kdV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id kq11-20020a170903284b00b001c34abf9f2esi13669852plb.110.2023.09.26.20.03.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 20:03:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=sRu55kdV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id A4D4280CFD67; Tue, 26 Sep 2023 20:01:21 -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 S230488AbjI0DAr (ORCPT + 99 others); Tue, 26 Sep 2023 23:00:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234137AbjI0C6p (ORCPT ); Tue, 26 Sep 2023 22:58:45 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79DD019781; Tue, 26 Sep 2023 17:15:28 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4F719C433CA; Wed, 27 Sep 2023 00:15:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695773727; bh=Fsvg0F3lnuo5kK+BZq/zqgC2Z48DcX4ehDUq6zNzreo=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=sRu55kdVDEzBlTb4zAOUbXj0BTlPCL0Rrj94Us9wJKFyPwgdaEm3FixpHOuXhWqNo Fe+6mvKFcoNV+lDqqucRFOKmX3QYu42VTMaQtXCIbSKJPSY3/IWo80W2m1r9FQNcvi Jo00owrcTF2zURSaY459/yYcAmOUbPztZn1xFpiFFn9fESnSfqFUd/t57GyPKvUBmM p298XY8liHGtdKRFXBpcFwH9gZA+DKfKEDVR7PUHodtK9jMtdgiRa9x3trWV6ea1Bn utS/yV3glld7xMh4GKbWKi7sc87SV7uHZI8fN4lRyNlcuCi9gsAa5XZs8Bv4u7GIFP M747ozhHrvJGQ== Received: by mail-lf1-f53.google.com with SMTP id 2adb3069b0e04-5046bf37ec1so6606642e87.1; Tue, 26 Sep 2023 17:15:27 -0700 (PDT) X-Gm-Message-State: AOJu0YwJHxK4i2TIAKBf9rBUpWSWwFo4WCnmyu+Pk97BfCKZY7VBcJZF 4cvC9gpJlRsr0cl7n+5pe/Frt+R+iFoZsaO8/DY= X-Received: by 2002:a05:6512:ac5:b0:503:3707:66ed with SMTP id n5-20020a0565120ac500b00503370766edmr340401lfu.34.1695773725474; Tue, 26 Sep 2023 17:15:25 -0700 (PDT) MIME-Version: 1.0 References: <20230926025827.671407-1-yukuai1@huaweicloud.com> <20230926025827.671407-2-yukuai1@huaweicloud.com> In-Reply-To: <20230926025827.671407-2-yukuai1@huaweicloud.com> From: Song Liu Date: Tue, 26 Sep 2023 17:15:13 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 1/2] md: factor out a new helper to put mddev To: Yu Kuai Cc: mariusz.tkaczyk@linux.intel.com, xni@redhat.com, linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org, yukuai3@huawei.com, yi.zhang@huawei.com, yangerkun@huawei.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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]); Tue, 26 Sep 2023 20:01:21 -0700 (PDT) On Mon, Sep 25, 2023 at 8:04=E2=80=AFPM Yu Kuai w= rote: > > 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; > + This condition is indeed very confusing. No matter whether we call the flag "locked" or "do_lock", it is not really accurate. How about we factor out a helper with the following logic: if (!mddev->raid_disks && list_empty(&mddev->disks) && mddev->ctime =3D=3D 0 && !mddev->hold_active) { /* Array is not configured at all, and not held active, * so destroy it */ set_bit(MD_DELETED, &mddev->flags); /* * Call queue_work inside the spinlock so that * flush_workqueue() after mddev_find will succeed in waiti= ng * for the work to be done. */ queue_work(md_misc_wq, &mddev->del_work); } and then use it at the two callers? Does this make sense? Thanks, Song