]> www.infradead.org Git - users/hch/misc.git/commitdiff
md/md-bitmap: add a new parameter 'flush' to bitmap_ops->enabled
authorYu Kuai <yukuai3@huawei.com>
Mon, 7 Jul 2025 01:27:01 +0000 (09:27 +0800)
committerYu Kuai <yukuai3@huawei.com>
Sat, 6 Sep 2025 09:11:42 +0000 (17:11 +0800)
The method is only used from raid1/raid10 IO path, to check if write
bio should be pluged, the parameter is always set to true for now,
following patch will use this helper in other context like updating
superblock.

Link: https://lore.kernel.org/linux-raid/20250707012711.376844-6-yukuai1@huaweicloud.com
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
Reviewed-by: Xiao Ni <xni@redhat.com>
drivers/md/md-bitmap.c
drivers/md/md-bitmap.h
drivers/md/raid1-10.c

index 30b6b42b9a4842012e09558a488a4a4f899a5845..69e4a43c38b46a877e16809b1cdee69a77113a08 100644 (file)
@@ -232,20 +232,27 @@ static inline char *bmname(struct bitmap *bitmap)
        return bitmap->mddev ? mdname(bitmap->mddev) : "mdX";
 }
 
-static bool __bitmap_enabled(struct bitmap *bitmap)
+static bool __bitmap_enabled(struct bitmap *bitmap, bool flush)
 {
-       return bitmap->storage.filemap &&
-              !test_bit(BITMAP_STALE, &bitmap->flags);
+       if (!flush)
+               return true;
+
+       /*
+        * If caller want to flush bitmap pages to underlying disks, check if
+        * there are cached pages in filemap.
+        */
+       return !test_bit(BITMAP_STALE, &bitmap->flags) &&
+              bitmap->storage.filemap != NULL;
 }
 
-static bool bitmap_enabled(struct mddev *mddev)
+static bool bitmap_enabled(struct mddev *mddev, bool flush)
 {
        struct bitmap *bitmap = mddev->bitmap;
 
        if (!bitmap)
                return false;
 
-       return __bitmap_enabled(bitmap);
+       return __bitmap_enabled(bitmap, flush);
 }
 
 /*
@@ -1244,7 +1251,7 @@ static void __bitmap_unplug(struct bitmap *bitmap)
        int dirty, need_write;
        int writing = 0;
 
-       if (!__bitmap_enabled(bitmap))
+       if (!__bitmap_enabled(bitmap, true))
                return;
 
        /* look at each page to see if there are any set bits that need to be
index 0ceb9e97d21f6902da259f4db9487d95aadf918c..63d91831655fbce265e6ece86fcf4136201cba08 100644 (file)
@@ -62,7 +62,7 @@ struct md_bitmap_stats {
 };
 
 struct bitmap_operations {
-       bool (*enabled)(struct mddev *mddev);
+       bool (*enabled)(struct mddev *mddev, bool flush);
        int (*create)(struct mddev *mddev);
        int (*resize)(struct mddev *mddev, sector_t blocks, int chunksize);
 
index 52881e6032daeebffe15dbc911b60487d205356f..f3c3376cdd06a9c6c23c3106a7fd9695dd60f845 100644 (file)
@@ -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)) {
+       if (!mddev->bitmap_ops->enabled(mddev, true)) {
                raid1_submit_write(bio);
                return true;
        }