From: Yu Kuai <yuku...@huawei.com>

Include following APIs:
 - llbitmap_start_sync
 - llbitmap_end_sync
 - llbitmap_close_sync

Signed-off-by: Yu Kuai <yuku...@huawei.com>
---
 drivers/md/md-llbitmap.c | 43 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/drivers/md/md-llbitmap.c b/drivers/md/md-llbitmap.c
index 982ec868ce22..1692942942ff 100644
--- a/drivers/md/md-llbitmap.c
+++ b/drivers/md/md-llbitmap.c
@@ -1071,6 +1071,45 @@ static void llbitmap_flush(struct mddev *mddev)
        flush_work(&llbitmap->daemon_work);
 }
 
+static bool llbitmap_start_sync(struct mddev *mddev, sector_t offset,
+                               sector_t *blocks, bool degraded)
+{
+       struct llbitmap *llbitmap = mddev->bitmap;
+       unsigned long p = offset >> llbitmap->chunkshift;
+
+       /*
+        * Handle one bit at a time, this is much simpler. And it doesn't matter
+        * if md_do_sync() loop more times.
+        */
+       *blocks = llbitmap->chunksize - (offset & (llbitmap->chunksize - 1));
+       return llbitmap_state_machine(llbitmap, p, p, BitmapActionStartsync) == 
BitSyncing;
+}
+
+static void llbitmap_end_sync(struct mddev *mddev, sector_t offset,
+                             sector_t *blocks)
+{
+       struct llbitmap *llbitmap = mddev->bitmap;
+       unsigned long p = offset >> llbitmap->chunkshift;
+
+       *blocks = llbitmap->chunksize - (offset & (llbitmap->chunksize - 1));
+       llbitmap_state_machine(llbitmap, p, llbitmap->chunks - 1, 
BitmapActionAbortsync);
+}
+
+static void llbitmap_close_sync(struct mddev *mddev)
+{
+       struct llbitmap *llbitmap = mddev->bitmap;
+       int i;
+
+       for (i = 0; i < llbitmap->nr_pages; i++) {
+               struct llbitmap_barrier *barrier = &llbitmap->barrier[i];
+
+               /* let daemon_fn clear dirty bits immediately */
+               WRITE_ONCE(barrier->expire, jiffies);
+       }
+
+       llbitmap_state_machine(llbitmap, 0, llbitmap->chunks - 1, 
BitmapActionEndsync);
+}
+
 static struct bitmap_operations llbitmap_ops = {
        .head = {
                .type   = MD_BITMAP,
@@ -1087,4 +1126,8 @@ static struct bitmap_operations llbitmap_ops = {
        .endwrite               = llbitmap_endwrite,
        .unplug                 = llbitmap_unplug,
        .flush                  = llbitmap_flush,
+
+       .start_sync             = llbitmap_start_sync,
+       .end_sync               = llbitmap_end_sync,
+       .close_sync             = llbitmap_close_sync,
 };
-- 
2.39.2


Reply via email to