All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Song Liu <song@kernel.org>
Cc: Logan Gunthorpe <logang@deltatee.com>,
	linux-raid@vger.kernel.org, linux-block@vger.kernel.org,
	Hannes Reinecke <hare@suse.de>
Subject: [PATCH 08/10] md: stop using for_each_mddev in md_exit
Date: Tue, 19 Jul 2022 11:18:22 +0200	[thread overview]
Message-ID: <20220719091824.1064989-9-hch@lst.de> (raw)
In-Reply-To: <20220719091824.1064989-1-hch@lst.de>

Just do a simple list_for_each_entry_safe on all_mddevs, and only grab a
reference when we drop the lock and delete the now unused for_each_mddev
macro.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Logan Gunthorpe <logang@deltatee.com>
Reviewed-by: Hannes Reinecke <hare@suse.de>
---
 drivers/md/md.c | 39 +++++++++++----------------------------
 1 file changed, 11 insertions(+), 28 deletions(-)

diff --git a/drivers/md/md.c b/drivers/md/md.c
index ede817286cacd..ee3e9ba03fd25 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -368,28 +368,6 @@ EXPORT_SYMBOL_GPL(md_new_event);
 static LIST_HEAD(all_mddevs);
 static DEFINE_SPINLOCK(all_mddevs_lock);
 
-/*
- * iterates through all used mddevs in the system.
- * We take care to grab the all_mddevs_lock whenever navigating
- * the list, and to always hold a refcount when unlocked.
- * Any code which breaks out of this loop while own
- * a reference to the current mddev and must mddev_put it.
- */
-#define for_each_mddev(_mddev,_tmp)					\
-									\
-	for (({ spin_lock(&all_mddevs_lock);				\
-		_tmp = all_mddevs.next;					\
-		_mddev = NULL;});					\
-	     ({ if (_tmp != &all_mddevs)				\
-			mddev_get(list_entry(_tmp, struct mddev, all_mddevs));\
-		spin_unlock(&all_mddevs_lock);				\
-		if (_mddev) mddev_put(_mddev);				\
-		_mddev = list_entry(_tmp, struct mddev, all_mddevs);	\
-		_tmp != &all_mddevs;});					\
-	     ({ spin_lock(&all_mddevs_lock);				\
-		_tmp = _tmp->next;})					\
-		)
-
 /* Rather than calling directly into the personality make_request function,
  * IO requests come here first so that we can check if the device is
  * being suspended pending a reconfiguration.
@@ -9923,8 +9901,7 @@ void md_autostart_arrays(int part)
 
 static __exit void md_exit(void)
 {
-	struct mddev *mddev;
-	struct list_head *tmp;
+	struct mddev *mddev, *n;
 	int delay = 1;
 
 	unregister_blkdev(MD_MAJOR,"md");
@@ -9944,17 +9921,23 @@ static __exit void md_exit(void)
 	}
 	remove_proc_entry("mdstat", NULL);
 
-	for_each_mddev(mddev, tmp) {
+	spin_lock(&all_mddevs_lock);
+	list_for_each_entry_safe(mddev, n, &all_mddevs, all_mddevs) {
+		mddev_get(mddev);
+		spin_unlock(&all_mddevs_lock);
 		export_array(mddev);
 		mddev->ctime = 0;
 		mddev->hold_active = 0;
 		/*
-		 * for_each_mddev() will call mddev_put() at the end of each
-		 * iteration.  As the mddev is now fully clear, this will
-		 * schedule the mddev for destruction by a workqueue, and the
+		 * As the mddev is now fully clear, mddev_put will schedule
+		 * the mddev for destruction by a workqueue, and the
 		 * destroy_workqueue() below will wait for that to complete.
 		 */
+		mddev_put(mddev);
+		spin_lock(&all_mddevs_lock);
 	}
+	spin_unlock(&all_mddevs_lock);
+
 	destroy_workqueue(md_rdev_misc_wq);
 	destroy_workqueue(md_misc_wq);
 	destroy_workqueue(md_wq);
-- 
2.30.2


  parent reply	other threads:[~2022-07-19  9:19 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-19  9:18 fix md disk_name lifetime problems v4 Christoph Hellwig
2022-07-19  9:18 ` [PATCH 01/10] md: fix mddev->kobj lifetime Christoph Hellwig
2022-07-19  9:18 ` [PATCH 02/10] md: fix error handling in md_alloc Christoph Hellwig
2022-07-19  9:18 ` [PATCH 03/10] md: implement ->free_disk Christoph Hellwig
2022-07-19  9:18 ` [PATCH 04/10] md: rename md_free to md_kobj_release Christoph Hellwig
2022-07-19  9:18 ` [PATCH 05/10] md: factor out the rdev overlaps check from rdev_size_store Christoph Hellwig
2022-07-19  9:18 ` [PATCH 06/10] md: stop using for_each_mddev in md_do_sync Christoph Hellwig
2022-07-19  9:18 ` [PATCH 07/10] md: stop using for_each_mddev in md_notify_reboot Christoph Hellwig
2022-07-19  9:18 ` Christoph Hellwig [this message]
2022-07-19  9:18 ` [PATCH 09/10] md: only delete entries from all_mddevs when the disk is freed Christoph Hellwig
2022-07-19  9:25   ` Hannes Reinecke
2022-07-19  9:18 ` [PATCH 10/10] md: simplify md_open Christoph Hellwig
2022-07-19 18:42 ` fix md disk_name lifetime problems v4 Song Liu
2022-07-19 18:44   ` Logan Gunthorpe
2022-07-20  6:05     ` Song Liu
  -- strict thread matches above, loose matches on Subject: below --
2022-07-18  6:34 fix md disk_name lifetime problems v3 Christoph Hellwig
2022-07-18  6:34 ` [PATCH 08/10] md: stop using for_each_mddev in md_exit Christoph Hellwig
2022-07-18  7:10   ` Hannes Reinecke
2022-07-19  7:03     ` Christoph Hellwig
2022-07-19  7:06       ` Hannes Reinecke
2022-07-18 20:03   ` Logan Gunthorpe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220719091824.1064989-9-hch@lst.de \
    --to=hch@lst.de \
    --cc=hare@suse.de \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-raid@vger.kernel.org \
    --cc=logang@deltatee.com \
    --cc=song@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.