[PATCH RFC -next v2 13/41] md/md-bitmap: merge md_bitmap_load() into bitmap_operations

Yu Kuai
2024-08-14T07:15:33Z

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/dm-raid.c | 4 +++-
drivers/md/md-bitmap.c | 6 +++---
drivers/md/md-bitmap.h | 2 +-
drivers/md/md.c | 7 ++++---
4 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/drivers/md/dm-raid.c b/drivers/md/dm-raid.c
index 0c3323e0adb2..c3e201fde4c5 100644
--- a/drivers/md/dm-raid.c
+++ b/drivers/md/dm-raid.c
@@ -3949,7 +3949,9 @@ static int __load_dirty_region_bitmap(struct raid_set *rs)
/* Try loading the bitmap unless "raid0", which does not have one */
if (!rs_is_raid0(rs) &&
!test_and_set_bit(RT_FLAG_RS_BITMAP_LOADED, &rs->runtime_flags)) {
- r = md_bitmap_load(&rs->md);
+ struct mddev *mddev = &rs->md;
+
+ r = mddev->bitmap_ops->load(mddev);
if (r)
DMERR("Failed to load bitmap");
}
diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
index 9606bcafb834..0113a972e42d 100644
--- a/drivers/md/md-bitmap.c
+++ b/drivers/md/md-bitmap.c
@@ -1977,7 +1977,7 @@ static int bitmap_create(struct mddev *mddev, int slot)
return 0;
}

-int md_bitmap_load(struct mddev *mddev)
+static int bitmap_load(struct mddev *mddev)
{
int err = 0;
sector_t start = 0;
@@ -2033,7 +2033,6 @@ int md_bitmap_load(struct mddev *mddev)
out:
return err;
}
-EXPORT_SYMBOL_GPL(md_bitmap_load);

/* caller need to free returned bitmap with md_bitmap_free() */
struct bitmap *get_bitmap_from_slot(struct mddev *mddev, int slot)
@@ -2422,7 +2421,7 @@ location_store(struct mddev *mddev, const char *buf, size_t len)
if (rv)
goto out;

- rv = md_bitmap_load(mddev);
+ rv = bitmap_load(mddev);
if (rv) {
mddev->bitmap_info.offset = 0;
md_bitmap_destroy(mddev);
@@ -2721,6 +2720,7 @@ const struct attribute_group md_bitmap_group = {

static struct bitmap_operations bitmap_ops = {
.create = bitmap_create,
+ .load = bitmap_load,
};

void mddev_set_bitmap_ops(struct mddev *mddev)
diff --git a/drivers/md/md-bitmap.h b/drivers/md/md-bitmap.h
index 4b9c22b66e65..ba912f5f3450 100644
--- a/drivers/md/md-bitmap.h
+++ b/drivers/md/md-bitmap.h
@@ -247,13 +247,13 @@ struct md_bitmap_stats {

struct bitmap_operations {
int (*create)(struct mddev *mddev, int slot);
+ int (*load)(struct mddev *mddev);
};

/* the bitmap API */
void mddev_set_bitmap_ops(struct mddev *mddev);

/* these are used only by md/bitmap */
-int md_bitmap_load(struct mddev *mddev);
void md_bitmap_flush(struct mddev *mddev);
void md_bitmap_destroy(struct mddev *mddev);

diff --git a/drivers/md/md.c b/drivers/md/md.c
index b32ab7ca7640..2fe25a6257e6 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -6303,7 +6303,8 @@ int do_md_run(struct mddev *mddev)
err = md_run(mddev);
if (err)
goto out;
- err = md_bitmap_load(mddev);
+
+ err = mddev->bitmap_ops->load(mddev);
if (err) {
md_bitmap_destroy(mddev);
goto out;
@@ -7271,7 +7272,7 @@ static int set_bitmap_file(struct mddev *mddev, int fd)
if (fd >= 0) {
err = mddev->bitmap_ops->create(mddev, -1);
if (!err)
- err = md_bitmap_load(mddev);
+ err = mddev->bitmap_ops->load(mddev);

if (err) {
md_bitmap_destroy(mddev);
@@ -7565,7 +7566,7 @@ static int update_array_info(struct mddev *mddev, mdu_array_info_t *info)
mddev->bitmap_info.default_space;
rv = mddev->bitmap_ops->create(mddev, -1);
if (!rv)
- rv = md_bitmap_load(mddev);
+ rv = mddev->bitmap_ops->load(mddev);

if (rv)
md_bitmap_destroy(mddev);
--
2.39.2