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

Include following left APIs
 - llbitmap_enabled
 - llbitmap_dirty_bits
 - llbitmap_update_sb

And following APIs that are not needed:
 - llbitmap_write_all, used in old bitmap to mark all pages need
 writeback;
 - llbitmap_daemon_work, used in old bitmap, llbitmap use timer to
   trigger daemon;
 - llbitmap_cond_end_sync, use to end sync for completed sectors(TODO,
   don't affect functionality)

And following APIs that are not supported:
 - llbitmap_start_behind_write
 - llbitmap_end_behind_write
 - llbitmap_wait_behind_writes
 - llbitmap_sync_with_cluster
 - llbitmap_get_from_slot
 - llbitmap_copy_from_slot
 - llbitmap_set_pages
 - llbitmap_free

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

diff --git a/drivers/md/md-llbitmap.c b/drivers/md/md-llbitmap.c
index 1692942942ff..a16bc84d9fa2 100644
--- a/drivers/md/md-llbitmap.c
+++ b/drivers/md/md-llbitmap.c
@@ -1110,6 +1110,130 @@ static void llbitmap_close_sync(struct mddev *mddev)
        llbitmap_state_machine(llbitmap, 0, llbitmap->chunks - 1, 
BitmapActionEndsync);
 }
 
+static bool llbitmap_enabled(void *data)
+{
+       struct llbitmap *llbitmap = data;
+
+       return llbitmap && !test_bit(BITMAP_WRITE_ERROR, &llbitmap->flags);
+}
+
+static void llbitmap_dirty_bits(struct mddev *mddev, unsigned long s,
+                               unsigned long e)
+{
+       llbitmap_state_machine(mddev->bitmap, s, e, BitmapActionStartwrite);
+}
+
+static void llbitmap_update_sb(void *data)
+{
+       struct llbitmap *llbitmap = data;
+       struct mddev *mddev = llbitmap->mddev;
+       struct page *sb_page;
+       bitmap_super_t *sb;
+
+       if (test_bit(BITMAP_WRITE_ERROR, &llbitmap->flags))
+               return;
+
+       sb_page = read_mapping_page(llbitmap->bitmap_file->f_mapping, 0, NULL);
+       if (IS_ERR(sb_page)) {
+               pr_err("%s: %s: read super block failed", __func__,
+                      mdname(mddev));
+               set_bit(BITMAP_WRITE_ERROR, &llbitmap->flags);
+               return;
+       }
+
+       if (mddev->events < llbitmap->events_cleared)
+               llbitmap->events_cleared = mddev->events;
+
+       sb = kmap_local_page(sb_page);
+       sb->events = cpu_to_le64(mddev->events);
+       sb->state = cpu_to_le32(llbitmap->flags);
+       sb->chunksize = cpu_to_le32(llbitmap->chunksize);
+       sb->sync_size = cpu_to_le64(mddev->resync_max_sectors);
+       sb->events_cleared = cpu_to_le64(llbitmap->events_cleared);
+       sb->sectors_reserved = cpu_to_le32(mddev->bitmap_info.space);
+       sb->daemon_sleep = cpu_to_le32(mddev->bitmap_info.daemon_sleep);
+
+       kunmap_local(sb);
+       set_page_dirty(sb_page);
+       put_page(sb_page);
+
+       if (filemap_write_and_wait_range(llbitmap->bitmap_file->f_mapping, 0,
+                                        BITMAP_SB_SIZE) != 0) {
+               pr_err("%s: %s: write super block failed", __func__,
+                      mdname(mddev));
+               set_bit(BITMAP_WRITE_ERROR, &llbitmap->flags);
+       }
+}
+
+static int llbitmap_get_stats(void *data, struct md_bitmap_stats *stats)
+{
+       struct llbitmap *llbitmap = data;
+
+       memset(stats, 0, sizeof(*stats));
+
+       stats->missing_pages = 0;
+       stats->pages = llbitmap->nr_pages;
+       stats->file_pages = llbitmap->nr_pages;
+
+       return 0;
+}
+
+static void llbitmap_write_all(struct mddev *mddev)
+{
+
+}
+
+static void llbitmap_daemon_work(struct mddev *mddev)
+{
+
+}
+
+static void llbitmap_start_behind_write(struct mddev *mddev)
+{
+
+}
+
+static void llbitmap_end_behind_write(struct mddev *mddev)
+{
+
+}
+
+static void llbitmap_wait_behind_writes(struct mddev *mddev)
+{
+
+}
+
+static void llbitmap_cond_end_sync(struct mddev *mddev, sector_t sector,
+                                  bool force)
+{
+}
+
+static void llbitmap_sync_with_cluster(struct mddev *mddev,
+                                      sector_t old_lo, sector_t old_hi,
+                                      sector_t new_lo, sector_t new_hi)
+{
+
+}
+
+static void *llbitmap_get_from_slot(struct mddev *mddev, int slot)
+{
+       return ERR_PTR(-EOPNOTSUPP);
+}
+
+static int llbitmap_copy_from_slot(struct mddev *mddev, int slot, sector_t 
*low,
+                                  sector_t *high, bool clear_bits)
+{
+       return -EOPNOTSUPP;
+}
+
+static void llbitmap_set_pages(void *data, unsigned long pages)
+{
+}
+
+static void llbitmap_free(void *data)
+{
+}
+
 static struct bitmap_operations llbitmap_ops = {
        .head = {
                .type   = MD_BITMAP,
@@ -1117,6 +1241,7 @@ static struct bitmap_operations llbitmap_ops = {
                .name   = "llbitmap",
        },
 
+       .enabled                = llbitmap_enabled,
        .create                 = llbitmap_create,
        .resize                 = llbitmap_resize,
        .load                   = llbitmap_load,
@@ -1130,4 +1255,23 @@ static struct bitmap_operations llbitmap_ops = {
        .start_sync             = llbitmap_start_sync,
        .end_sync               = llbitmap_end_sync,
        .close_sync             = llbitmap_close_sync,
+
+       .update_sb              = llbitmap_update_sb,
+       .get_stats              = llbitmap_get_stats,
+       .dirty_bits             = llbitmap_dirty_bits,
+
+       /* not needed */
+       .write_all              = llbitmap_write_all,
+       .daemon_work            = llbitmap_daemon_work,
+       .cond_end_sync          = llbitmap_cond_end_sync,
+
+       /* not supported */
+       .start_behind_write     = llbitmap_start_behind_write,
+       .end_behind_write       = llbitmap_end_behind_write,
+       .wait_behind_writes     = llbitmap_wait_behind_writes,
+       .sync_with_cluster      = llbitmap_sync_with_cluster,
+       .get_from_slot          = llbitmap_get_from_slot,
+       .copy_from_slot         = llbitmap_copy_from_slot,
+       .set_pages              = llbitmap_set_pages,
+       .free                   = llbitmap_free,
 };
-- 
2.39.2


Reply via email to