Blame SOURCES/kvm-block-dirty-bitmap-Add-bdrv_dirty_iter_next_area.patch

7711c0
From 7e539b23b6911cb38bf70dcbf818acbc10790816 Mon Sep 17 00:00:00 2001
7711c0
From: John Snow <jsnow@redhat.com>
7711c0
Date: Wed, 6 Feb 2019 22:12:25 +0100
7711c0
Subject: [PATCH 15/33] block/dirty-bitmap: Add bdrv_dirty_iter_next_area
7711c0
7711c0
RH-Author: John Snow <jsnow@redhat.com>
7711c0
Message-id: <20190206221243.7407-6-jsnow@redhat.com>
7711c0
Patchwork-id: 84265
7711c0
O-Subject: [RHEL-7.7 qemu-kvm-rhev PATCH v2 05/23] block/dirty-bitmap: Add bdrv_dirty_iter_next_area
7711c0
Bugzilla: 1658343
7711c0
RH-Acked-by: Thomas Huth <thuth@redhat.com>
7711c0
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
7711c0
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
7711c0
7711c0
From: Max Reitz <mreitz@redhat.com>
7711c0
7711c0
This new function allows to look for a consecutively dirty area in a
7711c0
dirty bitmap.
7711c0
7711c0
Signed-off-by: Max Reitz <mreitz@redhat.com>
7711c0
Reviewed-by: Fam Zheng <famz@redhat.com>
7711c0
Reviewed-by: John Snow <jsnow@redhat.com>
7711c0
Message-id: 20180613181823.13618-10-mreitz@redhat.com
7711c0
Signed-off-by: Max Reitz <mreitz@redhat.com>
7711c0
(cherry picked from commit 72d10a94213a954ad569095cb4491f2ae0853c40)
7711c0
Signed-off-by: John Snow <jsnow@redhat.com>
7711c0
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
7711c0
---
7711c0
 block/dirty-bitmap.c         | 55 ++++++++++++++++++++++++++++++++++++++++++++
7711c0
 include/block/dirty-bitmap.h |  2 ++
7711c0
 2 files changed, 57 insertions(+)
7711c0
7711c0
diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c
7711c0
index f4a4cb7..59027d4 100644
7711c0
--- a/block/dirty-bitmap.c
7711c0
+++ b/block/dirty-bitmap.c
7711c0
@@ -528,6 +528,61 @@ int64_t bdrv_dirty_iter_next(BdrvDirtyBitmapIter *iter)
7711c0
     return hbitmap_iter_next(&iter->hbi, true);
7711c0
 }
7711c0
 
7711c0
+/**
7711c0
+ * Return the next consecutively dirty area in the dirty bitmap
7711c0
+ * belonging to the given iterator @iter.
7711c0
+ *
7711c0
+ * @max_offset: Maximum value that may be returned for
7711c0
+ *              *offset + *bytes
7711c0
+ * @offset:     Will contain the start offset of the next dirty area
7711c0
+ * @bytes:      Will contain the length of the next dirty area
7711c0
+ *
7711c0
+ * Returns: True if a dirty area could be found before max_offset
7711c0
+ *          (which means that *offset and *bytes then contain valid
7711c0
+ *          values), false otherwise.
7711c0
+ *
7711c0
+ * Note that @iter is never advanced if false is returned.  If an area
7711c0
+ * is found (which means that true is returned), it will be advanced
7711c0
+ * past that area.
7711c0
+ */
7711c0
+bool bdrv_dirty_iter_next_area(BdrvDirtyBitmapIter *iter, uint64_t max_offset,
7711c0
+                               uint64_t *offset, int *bytes)
7711c0
+{
7711c0
+    uint32_t granularity = bdrv_dirty_bitmap_granularity(iter->bitmap);
7711c0
+    uint64_t gran_max_offset;
7711c0
+    int64_t ret;
7711c0
+    int size;
7711c0
+
7711c0
+    if (max_offset == iter->bitmap->size) {
7711c0
+        /* If max_offset points to the image end, round it up by the
7711c0
+         * bitmap granularity */
7711c0
+        gran_max_offset = ROUND_UP(max_offset, granularity);
7711c0
+    } else {
7711c0
+        gran_max_offset = max_offset;
7711c0
+    }
7711c0
+
7711c0
+    ret = hbitmap_iter_next(&iter->hbi, false);
7711c0
+    if (ret < 0 || ret + granularity > gran_max_offset) {
7711c0
+        return false;
7711c0
+    }
7711c0
+
7711c0
+    *offset = ret;
7711c0
+    size = 0;
7711c0
+
7711c0
+    assert(granularity <= INT_MAX);
7711c0
+
7711c0
+    do {
7711c0
+        /* Advance iterator */
7711c0
+        ret = hbitmap_iter_next(&iter->hbi, true);
7711c0
+        size += granularity;
7711c0
+    } while (ret + granularity <= gran_max_offset &&
7711c0
+             hbitmap_iter_next(&iter->hbi, false) == ret + granularity &&
7711c0
+             size <= INT_MAX - granularity);
7711c0
+
7711c0
+    *bytes = MIN(size, max_offset - *offset);
7711c0
+    return true;
7711c0
+}
7711c0
+
7711c0
 /* Called within bdrv_dirty_bitmap_lock..unlock */
7711c0
 void bdrv_set_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap,
7711c0
                                   int64_t offset, int64_t bytes)
7711c0
diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h
7711c0
index bf68dd7..259bd27 100644
7711c0
--- a/include/block/dirty-bitmap.h
7711c0
+++ b/include/block/dirty-bitmap.h
7711c0
@@ -83,6 +83,8 @@ void bdrv_set_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap,
7711c0
 void bdrv_reset_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap,
7711c0
                                     int64_t offset, int64_t bytes);
7711c0
 int64_t bdrv_dirty_iter_next(BdrvDirtyBitmapIter *iter);
7711c0
+bool bdrv_dirty_iter_next_area(BdrvDirtyBitmapIter *iter, uint64_t max_offset,
7711c0
+                               uint64_t *offset, int *bytes);
7711c0
 void bdrv_set_dirty_iter(BdrvDirtyBitmapIter *hbi, int64_t offset);
7711c0
 int64_t bdrv_get_dirty_count(BdrvDirtyBitmap *bitmap);
7711c0
 int64_t bdrv_get_meta_dirty_count(BdrvDirtyBitmap *bitmap);
7711c0
-- 
7711c0
1.8.3.1
7711c0