linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 01/11] md: add infra for active_aligned_reads changes
@ 2024-04-18  5:43 tada keisuke
  0 siblings, 0 replies; only message in thread
From: tada keisuke @ 2024-04-18  5:43 UTC (permalink / raw)
  To: song@kernel.org, yukuai3@huawei.com
  Cc: linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org

Prepare to smoothly change the type of active_aligned_reads from atomic_t to percpu_ref.

Signed-off-by: Keisuke TADA <keisuke1.tada@kioxia.com>
Signed-off-by: Toshifumi OHTAKE <toshifumi.ootake@kioxia.com>
---
 drivers/md/raid5.c | 12 ++++++------
 drivers/md/raid5.h | 20 ++++++++++++++++++++
 2 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index 2bd1ce9b3922..3b04d8b526b1 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -5435,7 +5435,7 @@ static void raid5_align_endio(struct bio *bi)
 
 	if (!error) {
 		bio_endio(raid_bi);
-		if (atomic_dec_and_test(&conf->active_aligned_reads))
+		if (active_aligned_reads_dec_and_test(conf))
 			wake_up(&conf->wait_for_quiescent);
 		return;
 	}
@@ -5499,7 +5499,7 @@ static int raid5_read_one_chunk(struct mddev *mddev, struct bio *raid_bio)
 
 	did_inc = false;
 	if (conf->quiesce == 0) {
-		atomic_inc(&conf->active_aligned_reads);
+		active_aligned_reads_inc(conf);
 		did_inc = true;
 	}
 	/* need a memory barrier to detect the race with raid5_quiesce() */
@@ -5507,12 +5507,12 @@ static int raid5_read_one_chunk(struct mddev *mddev, struct bio *raid_bio)
 		/* quiesce is in progress, so we need to undo io activation and wait
 		 * for it to finish
 		 */
-		if (did_inc && atomic_dec_and_test(&conf->active_aligned_reads))
+		if (did_inc && active_aligned_reads_dec_and_test(conf))
 			wake_up(&conf->wait_for_quiescent);
 		spin_lock_irq(&conf->device_lock);
 		wait_event_lock_irq(conf->wait_for_quiescent, conf->quiesce == 0,
 				    conf->device_lock);
-		atomic_inc(&conf->active_aligned_reads);
+		active_aligned_reads_inc(conf);
 		spin_unlock_irq(&conf->device_lock);
 	}
 
@@ -6608,7 +6608,7 @@ static int  retry_aligned_read(struct r5conf *conf, struct bio *raid_bio,
 
 	bio_endio(raid_bio);
 
-	if (atomic_dec_and_test(&conf->active_aligned_reads))
+	if (active_aligned_reads_dec_and_test(conf))
 		wake_up(&conf->wait_for_quiescent);
 	return handled;
 }
@@ -8586,7 +8586,7 @@ static void raid5_quiesce(struct mddev *mddev, int quiesce)
 		smp_store_release(&conf->quiesce, 2);
 		wait_event_cmd(conf->wait_for_quiescent,
 				    atomic_read(&conf->active_stripes) == 0 &&
-				    atomic_read(&conf->active_aligned_reads) == 0,
+				    active_aligned_reads_is_zero(conf),
 				    unlock_all_device_hash_locks_irq(conf),
 				    lock_all_device_hash_locks_irq(conf));
 		conf->quiesce = 1;
diff --git a/drivers/md/raid5.h b/drivers/md/raid5.h
index 9b5a7dc3f2a0..5bd6bb3540c5 100644
--- a/drivers/md/raid5.h
+++ b/drivers/md/raid5.h
@@ -696,6 +696,26 @@ struct r5conf {
 	struct r5pending_data	*next_pending_data;
 };
 
+static inline void active_aligned_reads_inc(struct r5conf *conf)
+{
+	atomic_inc(&conf->active_aligned_reads);
+}
+
+static inline void active_aligned_reads_dec(struct r5conf *conf)
+{
+	atomic_dec(&conf->active_aligned_reads);
+}
+
+static inline bool active_aligned_reads_is_zero(struct r5conf *conf)
+{
+	return atomic_read(&conf->active_aligned_reads) == 0;
+}
+
+static inline bool active_aligned_reads_dec_and_test(struct r5conf *conf)
+{
+	return atomic_dec_and_test(&conf->active_aligned_reads);
+}
+
 #if PAGE_SIZE == DEFAULT_STRIPE_SIZE
 #define RAID5_STRIPE_SIZE(conf)	STRIPE_SIZE
 #define RAID5_STRIPE_SHIFT(conf)	STRIPE_SHIFT
-- 
2.34.1



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2024-04-18  6:19 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-18  5:43 [PATCH v2 01/11] md: add infra for active_aligned_reads changes tada keisuke

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).