diff mbox series

[RFC,-next,v2,04/41] md/md-bitmap: add 'events_cleared' into struct md_bitmap_stats

Message ID 20240814071113.346781-5-yukuai1@huaweicloud.com (mailing list archive)
State Superseded
Headers show
Series md/md-bitmap: introduce bitmap_operations and make structure internel | expand

Commit Message

Yu Kuai Aug. 14, 2024, 7:10 a.m. UTC
From: Yu Kuai <yukuai3@huawei.com>

Also add a new helper to get events_cleared to avoid dereferencing
bitmap directly to prepare inventing a new bitmap.

Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
 drivers/md/md-bitmap.c |  1 +
 drivers/md/md-bitmap.h | 12 ++++++++++++
 drivers/md/md.c        |  4 ++--
 3 files changed, 15 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
index 8866c7122f79..8a2411040d2f 100644
--- a/drivers/md/md-bitmap.c
+++ b/drivers/md/md-bitmap.c
@@ -2105,6 +2105,7 @@  int md_bitmap_get_stats(struct bitmap *bitmap, struct md_bitmap_stats *stats)
 	stats->pages = counts->pages;
 	stats->missing_pages = counts->missing_pages;
 	stats->file = bitmap->storage.file;
+	stats->events_cleared = bitmap->events_cleared;
 
 	return 0;
 }
diff --git a/drivers/md/md-bitmap.h b/drivers/md/md-bitmap.h
index 8fb52aacd5a1..c8527ba38dfc 100644
--- a/drivers/md/md-bitmap.h
+++ b/drivers/md/md-bitmap.h
@@ -238,6 +238,7 @@  struct md_bitmap_stats {
 	unsigned long pages;
 	unsigned long missing_pages;
 	struct file *file;
+	u64 events_cleared;
 };
 
 /* the bitmap API */
@@ -282,6 +283,17 @@  int md_bitmap_copy_from_slot(struct mddev *mddev, int slot,
 void md_bitmap_free(struct bitmap *bitmap);
 void md_bitmap_wait_behind_writes(struct mddev *mddev);
 
+static inline u64 md_bitmap_events_cleared(struct mddev *mddev)
+{
+	struct md_bitmap_stats stats;
+	int err = md_bitmap_get_stats(mddev->bitmap, &stats);
+
+	if (err)
+		return 0;
+
+	return stats.events_cleared;
+}
+
 static inline bool md_bitmap_enabled(struct bitmap *bitmap)
 {
 	return bitmap && bitmap->storage.filemap &&
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 27013059baa2..29ec6fe80ae8 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -1464,7 +1464,7 @@  static int super_90_validate(struct mddev *mddev, struct md_rdev *freshest, stru
 		/* if adding to array with a bitmap, then we can accept an
 		 * older device ... but not too old.
 		 */
-		if (ev1 < mddev->bitmap->events_cleared)
+		if (ev1 < md_bitmap_events_cleared(mddev))
 			return 0;
 		if (ev1 < mddev->events)
 			set_bit(Bitmap_sync, &rdev->flags);
@@ -1991,7 +1991,7 @@  static int super_1_validate(struct mddev *mddev, struct md_rdev *freshest, struc
 		/* If adding to array with a bitmap, then we can accept an
 		 * older device, but not too old.
 		 */
-		if (ev1 < mddev->bitmap->events_cleared)
+		if (ev1 < md_bitmap_events_cleared(mddev))
 			return 0;
 		if (ev1 < mddev->events)
 			set_bit(Bitmap_sync, &rdev->flags);