summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYu Kuai <yukuai3@huawei.com>2025-07-07 09:27:02 +0800
committerYu Kuai <yukuai3@huawei.com>2025-09-06 17:11:45 +0800
commit110332074dc6ad2f07a3cf9cc45b03adbce0e54f (patch)
tree26952a934676f9c8660ad81de97fad98efb07f79
parent9c41ead04ec0d3ee54505039879aee20cf495e0a (diff)
md/md-bitmap: add md_bitmap_registered/enabled() helper
There are no functional changes, prepare to handle the case that mddev->bitmap_ops can be NULL, which is possible after introducing CONFIG_MD_BITMAP. Link: https://lore.kernel.org/linux-raid/20250707012711.376844-7-yukuai1@huaweicloud.com Signed-off-by: Yu Kuai <yukuai3@huawei.com> Reviewed-by: Xiao Ni <xni@redhat.com>
-rw-r--r--drivers/md/md-bitmap.c16
-rw-r--r--drivers/md/md-bitmap.h19
-rw-r--r--drivers/md/raid1-10.c2
3 files changed, 23 insertions, 14 deletions
diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
index 69e4a43c38b4..613e767578aa 100644
--- a/drivers/md/md-bitmap.c
+++ b/drivers/md/md-bitmap.c
@@ -232,8 +232,10 @@ static inline char *bmname(struct bitmap *bitmap)
return bitmap->mddev ? mdname(bitmap->mddev) : "mdX";
}
-static bool __bitmap_enabled(struct bitmap *bitmap, bool flush)
+static bool bitmap_enabled(void *data, bool flush)
{
+ struct bitmap *bitmap = data;
+
if (!flush)
return true;
@@ -245,16 +247,6 @@ static bool __bitmap_enabled(struct bitmap *bitmap, bool flush)
bitmap->storage.filemap != NULL;
}
-static bool bitmap_enabled(struct mddev *mddev, bool flush)
-{
- struct bitmap *bitmap = mddev->bitmap;
-
- if (!bitmap)
- return false;
-
- return __bitmap_enabled(bitmap, flush);
-}
-
/*
* check a page and, if necessary, allocate it (or hijack it if the alloc fails)
*
@@ -1251,7 +1243,7 @@ static void __bitmap_unplug(struct bitmap *bitmap)
int dirty, need_write;
int writing = 0;
- if (!__bitmap_enabled(bitmap, true))
+ if (!bitmap_enabled(bitmap, true))
return;
/* look at each page to see if there are any set bits that need to be
diff --git a/drivers/md/md-bitmap.h b/drivers/md/md-bitmap.h
index 63d91831655f..a36ed32ec0d5 100644
--- a/drivers/md/md-bitmap.h
+++ b/drivers/md/md-bitmap.h
@@ -62,7 +62,7 @@ struct md_bitmap_stats {
};
struct bitmap_operations {
- bool (*enabled)(struct mddev *mddev, bool flush);
+ bool (*enabled)(void *data, bool flush);
int (*create)(struct mddev *mddev);
int (*resize)(struct mddev *mddev, sector_t blocks, int chunksize);
@@ -107,4 +107,21 @@ struct bitmap_operations {
/* the bitmap API */
void mddev_set_bitmap_ops(struct mddev *mddev);
+static inline bool md_bitmap_registered(struct mddev *mddev)
+{
+ return mddev->bitmap_ops != NULL;
+}
+
+static inline bool md_bitmap_enabled(struct mddev *mddev, bool flush)
+{
+ /* bitmap_ops must be registered before creating bitmap. */
+ if (!md_bitmap_registered(mddev))
+ return false;
+
+ if (!mddev->bitmap)
+ return false;
+
+ return mddev->bitmap_ops->enabled(mddev->bitmap, flush);
+}
+
#endif
diff --git a/drivers/md/raid1-10.c b/drivers/md/raid1-10.c
index f3c3376cdd06..521625756128 100644
--- a/drivers/md/raid1-10.c
+++ b/drivers/md/raid1-10.c
@@ -140,7 +140,7 @@ static inline bool raid1_add_bio_to_plug(struct mddev *mddev, struct bio *bio,
* If bitmap is not enabled, it's safe to submit the io directly, and
* this can get optimal performance.
*/
- if (!mddev->bitmap_ops->enabled(mddev, true)) {
+ if (!md_bitmap_enabled(mddev, true)) {
raid1_submit_write(bio);
return true;
}