diff mbox series

[RFC,-next,23/26] md/md-bitmap: merge md_bitmap_wait_behind_writes() into bitmap_operations

Message ID 20240810020854.797814-24-yukuai1@huaweicloud.com (mailing list archive)
State Superseded
Headers show
Series md/md-bitmap: introduce bitmap_operations | expand

Commit Message

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

So that the implementation won't be exposed, and it'll be possible
to invent a new bitmap by replacing bitmap_operations.

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

Patch

diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
index 99c496a32e94..87e192d172fb 100644
--- a/drivers/md/md-bitmap.c
+++ b/drivers/md/md-bitmap.c
@@ -1825,14 +1825,12 @@  static void __bitmap_free(struct bitmap *bitmap)
 	kfree(bitmap);
 }
 
-void md_bitmap_wait_behind_writes(struct mddev *mddev)
+static void bitmap_wait_behind_writes(struct bitmap *bitmap)
 {
-	struct bitmap *bitmap = mddev->bitmap;
-
 	/* wait for behind writes to complete */
-	if (bitmap && atomic_read(&bitmap->behind_writes) > 0) {
+	if (atomic_read(&bitmap->behind_writes) > 0) {
 		pr_debug("md:%s: behind writes in progress - waiting to stop.\n",
-			 mdname(mddev));
+			 mdname(bitmap->mddev));
 		/* need to kick something here to make sure I/O goes? */
 		wait_event(bitmap->behind_wait,
 			   atomic_read(&bitmap->behind_writes) == 0);
@@ -1846,7 +1844,7 @@  static void bitmap_destroy(struct mddev *mddev)
 	if (!bitmap) /* there was no bitmap */
 		return;
 
-	md_bitmap_wait_behind_writes(mddev);
+	bitmap_wait_behind_writes(bitmap);
 	if (!mddev->serialize_policy)
 		mddev_destroy_serial_pool(mddev, NULL);
 
@@ -2705,6 +2703,7 @@  static struct bitmap_operations bitmap_ops = {
 	.end_sync		= bitmap_end_sync,
 	.close_sync		= bitmap_close_sync,
 	.cond_end_sync		= bitmap_cond_end_sync,
+	.wait_behind_writes	= bitmap_wait_behind_writes,
 
 	.update_sb		= bitmap_update_sb,
 	.resize			= bitmap_resize,
diff --git a/drivers/md/md-bitmap.h b/drivers/md/md-bitmap.h
index b5836e5ff1e3..090d4f11f3cd 100644
--- a/drivers/md/md-bitmap.h
+++ b/drivers/md/md-bitmap.h
@@ -253,6 +253,7 @@  struct bitmap_operations {
 			 sector_t *blocks, int aborted);
 	void (*close_sync)(struct bitmap *bitmap);
 	void (*cond_end_sync)(struct bitmap *bitmap, sector_t sector, bool force);
+	void (*wait_behind_writes)(struct bitmap *bitmap);
 
 	void (*update_sb)(struct bitmap *bitmap);
 	int (*resize)(struct bitmap *bitmap, sector_t blocks, int chunksize,
@@ -395,6 +396,14 @@  static inline void md_bitmap_cond_end_sync(struct mddev *mddev, sector_t sector,
 	mddev->bitmap_ops->cond_end_sync(mddev->bitmap, sector, force);
 }
 
+static inline void md_bitmap_wait_behind_writes(struct mddev *mddev)
+{
+	if (!mddev->bitmap || !mddev->bitmap_ops->wait_behind_writes)
+		return;
+
+	mddev->bitmap_ops->wait_behind_writes(mddev->bitmap);
+}
+
 static inline int md_bitmap_resize(struct mddev *mddev, sector_t blocks,
 				   int chunksize, int init)
 {
@@ -446,8 +455,6 @@  void md_bitmap_unplug(struct bitmap *bitmap);
 void md_bitmap_unplug_async(struct bitmap *bitmap);
 void md_bitmap_daemon_work(struct mddev *mddev);
 
-void md_bitmap_wait_behind_writes(struct mddev *mddev);
-
 static inline bool md_bitmap_enabled(struct bitmap *bitmap)
 {
 	return bitmap && bitmap->storage.filemap &&