[PATCH RFC -next 24/26] md/md-bitmap: merge md_bitmap_daemon_work() into bitmap_operations

From: Yu Kuai
Date: Fri Aug 09 2024 - 22:18:26 EST


From: Yu Kuai <yukuai3@xxxxxxxxxx>

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@xxxxxxxxxx>
---
drivers/md/md-bitmap.c | 19 +++++++------------
drivers/md/md-bitmap.h | 10 +++++++++-
2 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
index 87e192d172fb..4f3ea6e51572 100644
--- a/drivers/md/md-bitmap.c
+++ b/drivers/md/md-bitmap.c
@@ -1292,9 +1292,9 @@ static void mddev_set_timeout(struct mddev *mddev, unsigned long timeout,
* bitmap daemon -- periodically wakes up to clean bits and flush pages
* out to disk
*/
-void md_bitmap_daemon_work(struct mddev *mddev)
+static void bitmap_daemon_work(struct bitmap *bitmap)
{
- struct bitmap *bitmap;
+ struct mddev *mddev = bitmap->mddev;
unsigned long j;
unsigned long nextpage;
sector_t blocks;
@@ -1304,13 +1304,8 @@ void md_bitmap_daemon_work(struct mddev *mddev)
* bitmap_destroy.
*/
mutex_lock(&mddev->bitmap_info.mutex);
- bitmap = mddev->bitmap;
- if (bitmap == NULL) {
- mutex_unlock(&mddev->bitmap_info.mutex);
- return;
- }
- if (time_before(jiffies, bitmap->daemon_lastrun
- + mddev->bitmap_info.daemon_sleep))
+ if (time_before(jiffies, bitmap->daemon_lastrun +
+ mddev->bitmap_info.daemon_sleep))
goto done;

bitmap->daemon_lastrun = jiffies;
@@ -1780,11 +1775,11 @@ static void bitmap_flush(struct mddev *mddev)
*/
sleep = mddev->bitmap_info.daemon_sleep * 2;
bitmap->daemon_lastrun -= sleep;
- md_bitmap_daemon_work(mddev);
+ bitmap_daemon_work(bitmap);
bitmap->daemon_lastrun -= sleep;
- md_bitmap_daemon_work(mddev);
+ bitmap_daemon_work(bitmap);
bitmap->daemon_lastrun -= sleep;
- md_bitmap_daemon_work(mddev);
+ bitmap_daemon_work(bitmap);
if (mddev->bitmap_info.external)
md_super_wait(mddev);
bitmap_update_sb(bitmap);
diff --git a/drivers/md/md-bitmap.h b/drivers/md/md-bitmap.h
index 090d4f11f3cd..f67e030139cd 100644
--- a/drivers/md/md-bitmap.h
+++ b/drivers/md/md-bitmap.h
@@ -254,6 +254,7 @@ struct bitmap_operations {
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 (*daemon_work)(struct bitmap *bitmap);

void (*update_sb)(struct bitmap *bitmap);
int (*resize)(struct bitmap *bitmap, sector_t blocks, int chunksize,
@@ -404,6 +405,14 @@ static inline void md_bitmap_wait_behind_writes(struct mddev *mddev)
mddev->bitmap_ops->wait_behind_writes(mddev->bitmap);
}

+static inline void md_bitmap_daemon_work(struct mddev *mddev)
+{
+ if (!mddev->bitmap || !mddev->bitmap_ops->daemon_work)
+ return;
+
+ mddev->bitmap_ops->daemon_work(mddev->bitmap);
+}
+
static inline int md_bitmap_resize(struct mddev *mddev, sector_t blocks,
int chunksize, int init)
{
@@ -453,7 +462,6 @@ static inline void md_bitmap_free(struct mddev *mddev, struct bitmap *bitmap)

void md_bitmap_unplug(struct bitmap *bitmap);
void md_bitmap_unplug_async(struct bitmap *bitmap);
-void md_bitmap_daemon_work(struct mddev *mddev);

static inline bool md_bitmap_enabled(struct bitmap *bitmap)
{
--
2.39.2