diff mbox series

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

Message ID 20240814071113.346781-7-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>

There are no functional changes, 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 |  1 +
 drivers/md/md.c        | 12 ++++++++----
 3 files changed, 10 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
index 9ff5ed250ba5..cd304240aaa6 100644
--- a/drivers/md/md-bitmap.c
+++ b/drivers/md/md-bitmap.c
@@ -2109,6 +2109,7 @@  int md_bitmap_get_stats(struct bitmap *bitmap, struct md_bitmap_stats *stats)
 	counts = &bitmap->counts;
 	stats->pages = counts->pages;
 	stats->missing_pages = counts->missing_pages;
+	stats->file_pages = bitmap->storage.file_pages;
 	stats->file = bitmap->storage.file;
 	stats->events_cleared = bitmap->events_cleared;
 
diff --git a/drivers/md/md-bitmap.h b/drivers/md/md-bitmap.h
index 1a7ad2cf9f75..52ef4dae8f3e 100644
--- a/drivers/md/md-bitmap.h
+++ b/drivers/md/md-bitmap.h
@@ -237,6 +237,7 @@  struct bitmap {
 struct md_bitmap_stats {
 	unsigned long pages;
 	unsigned long missing_pages;
+	unsigned long file_pages;
 	unsigned long sync_size;
 	struct file *file;
 	u64 events_cleared;
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 29ec6fe80ae8..628fa49170e1 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -2323,7 +2323,10 @@  super_1_allow_new_offset(struct md_rdev *rdev,
 			 unsigned long long new_offset)
 {
 	/* All necessary checks on new >= old have been done */
-	struct bitmap *bitmap;
+	struct bitmap *bitmap = rdev->mddev->bitmap;
+	struct md_bitmap_stats stats;
+	int err;
+
 	if (new_offset >= rdev->data_offset)
 		return 1;
 
@@ -2340,10 +2343,11 @@  super_1_allow_new_offset(struct md_rdev *rdev,
 	 */
 	if (rdev->sb_start + (32+4)*2 > new_offset)
 		return 0;
-	bitmap = rdev->mddev->bitmap;
-	if (bitmap && !rdev->mddev->bitmap_info.file &&
+
+	err = md_bitmap_get_stats(bitmap, &stats);
+	if (!err && !rdev->mddev->bitmap_info.file &&
 	    rdev->sb_start + rdev->mddev->bitmap_info.offset +
-	    bitmap->storage.file_pages * (PAGE_SIZE>>9) > new_offset)
+	    stats.file_pages * (PAGE_SIZE>>9) > new_offset)
 		return 0;
 	if (rdev->badblocks.sector + rdev->badblocks.size > new_offset)
 		return 0;