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 | 7 ++++--- drivers/md/md-bitmap.h | 10 +++++++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c index d9838fbcc9d7..d731f7d4bbbb 100644 --- a/drivers/md/md-bitmap.c +++ b/drivers/md/md-bitmap.c @@ -1878,7 +1878,7 @@ void md_bitmap_destroy(struct mddev *mddev) * if this returns an error, bitmap_destroy must be called to do clean up * once mddev->bitmap is set */ -struct bitmap *md_bitmap_create(struct mddev *mddev, int slot) +static struct bitmap *bitmap_create(struct mddev *mddev, int slot) { struct bitmap *bitmap; sector_t blocks = mddev->resync_max_sectors; @@ -2029,7 +2029,7 @@ struct bitmap *get_bitmap_from_slot(struct mddev *mddev, int slot) int rv = 0; struct bitmap *bitmap; - bitmap = md_bitmap_create(mddev, slot); + bitmap = bitmap_create(mddev, slot); if (IS_ERR(bitmap)) { rv = PTR_ERR(bitmap); return ERR_PTR(rv); @@ -2404,7 +2404,7 @@ location_store(struct mddev *mddev, const char *buf, size_t len) } mddev->bitmap_info.offset = offset; - bitmap = md_bitmap_create(mddev, -1); + bitmap = bitmap_create(mddev, -1); if (IS_ERR(bitmap)) { rv = PTR_ERR(bitmap); goto out; @@ -2709,6 +2709,7 @@ const struct attribute_group md_bitmap_group = { }; static struct bitmap_operations bitmap_ops = { + .create = bitmap_create, }; void mddev_set_bitmap_ops(struct mddev *mddev) diff --git a/drivers/md/md-bitmap.h b/drivers/md/md-bitmap.h index 992feaf66d47..a7cbf0c692fc 100644 --- a/drivers/md/md-bitmap.h +++ b/drivers/md/md-bitmap.h @@ -235,13 +235,21 @@ struct bitmap { }; struct bitmap_operations { + struct bitmap* (*create)(struct mddev *mddev, int slot); }; /* the bitmap API */ void mddev_set_bitmap_ops(struct mddev *mddev); /* these are used only by md/bitmap */ -struct bitmap *md_bitmap_create(struct mddev *mddev, int slot); +static inline struct bitmap *md_bitmap_create(struct mddev *mddev, int slot) +{ + if (!mddev->bitmap_ops->create) + return ERR_PTR(-EOPNOTSUPP); + + return mddev->bitmap_ops->create(mddev, slot); +} + int md_bitmap_load(struct mddev *mddev); void md_bitmap_flush(struct mddev *mddev); void md_bitmap_destroy(struct mddev *mddev); -- 2.39.2