[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH v4 09/13] block/dirty-bitmap: Add bdrv_dirty_iter_ne
From: |
Max Reitz |
Subject: |
[Qemu-block] [PATCH v4 09/13] block/dirty-bitmap: Add bdrv_dirty_iter_next_area |
Date: |
Wed, 11 Apr 2018 20:54:21 +0200 |
This new function allows to look for a consecutively dirty area in a
dirty bitmap.
Signed-off-by: Max Reitz <address@hidden>
Reviewed-by: Fam Zheng <address@hidden>
Reviewed-by: John Snow <address@hidden>
---
include/block/dirty-bitmap.h | 2 ++
block/dirty-bitmap.c | 55 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 57 insertions(+)
diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h
index 1ff8949b1b..0d52cdaf3b 100644
--- a/include/block/dirty-bitmap.h
+++ b/include/block/dirty-bitmap.h
@@ -82,6 +82,8 @@ void bdrv_set_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap,
void bdrv_reset_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap,
int64_t offset, int64_t bytes);
int64_t bdrv_dirty_iter_next(BdrvDirtyBitmapIter *iter);
+bool bdrv_dirty_iter_next_area(BdrvDirtyBitmapIter *iter, uint64_t max_offset,
+ uint64_t *offset, int *bytes);
void bdrv_set_dirty_iter(BdrvDirtyBitmapIter *hbi, int64_t offset);
int64_t bdrv_get_dirty_count(BdrvDirtyBitmap *bitmap);
int64_t bdrv_get_meta_dirty_count(BdrvDirtyBitmap *bitmap);
diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c
index df7b711610..8758edb261 100644
--- a/block/dirty-bitmap.c
+++ b/block/dirty-bitmap.c
@@ -549,6 +549,61 @@ int64_t bdrv_dirty_iter_next(BdrvDirtyBitmapIter *iter)
return hbitmap_iter_next(&iter->hbi, true);
}
+/**
+ * Return the next consecutively dirty area in the dirty bitmap
+ * belonging to the given iterator @iter.
+ *
+ * @max_offset: Maximum value that may be returned for
+ * *offset + *bytes
+ * @offset: Will contain the start offset of the next dirty area
+ * @bytes: Will contain the length of the next dirty area
+ *
+ * Returns: True if a dirty area could be found before max_offset
+ * (which means that *offset and *bytes then contain valid
+ * values), false otherwise.
+ *
+ * Note that @iter is never advanced if false is returned. If an area
+ * is found (which means that true is returned), it will be advanced
+ * past that area.
+ */
+bool bdrv_dirty_iter_next_area(BdrvDirtyBitmapIter *iter, uint64_t max_offset,
+ uint64_t *offset, int *bytes)
+{
+ uint32_t granularity = bdrv_dirty_bitmap_granularity(iter->bitmap);
+ uint64_t gran_max_offset;
+ int64_t ret;
+ int size;
+
+ if (max_offset == iter->bitmap->size) {
+ /* If max_offset points to the image end, round it up by the
+ * bitmap granularity */
+ gran_max_offset = ROUND_UP(max_offset, granularity);
+ } else {
+ gran_max_offset = max_offset;
+ }
+
+ ret = hbitmap_iter_next(&iter->hbi, false);
+ if (ret < 0 || ret + granularity > gran_max_offset) {
+ return false;
+ }
+
+ *offset = ret;
+ size = 0;
+
+ assert(granularity <= INT_MAX);
+
+ do {
+ /* Advance iterator */
+ ret = hbitmap_iter_next(&iter->hbi, true);
+ size += granularity;
+ } while (ret + granularity <= gran_max_offset &&
+ hbitmap_iter_next(&iter->hbi, false) == ret + granularity &&
+ size <= INT_MAX - granularity);
+
+ *bytes = MIN(size, max_offset - *offset);
+ return true;
+}
+
/* Called within bdrv_dirty_bitmap_lock..unlock */
void bdrv_set_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap,
int64_t offset, int64_t bytes)
--
2.14.3
- [Qemu-block] [PATCH v4 03/13] block/mirror: Use CoQueue to wait on in-flight ops, (continued)
- [Qemu-block] [PATCH v4 03/13] block/mirror: Use CoQueue to wait on in-flight ops, Max Reitz, 2018/04/11
- [Qemu-block] [PATCH v4 04/13] block/mirror: Wait for in-flight op conflicts, Max Reitz, 2018/04/11
- [Qemu-block] [PATCH v4 05/13] block/mirror: Use source as a BdrvChild, Max Reitz, 2018/04/11
- [Qemu-block] [PATCH v4 06/13] block: Generalize should_update_child() rule, Max Reitz, 2018/04/11
- [Qemu-block] [PATCH v4 07/13] hbitmap: Add @advance param to hbitmap_iter_next(), Max Reitz, 2018/04/11
- [Qemu-block] [PATCH v4 08/13] test-hbitmap: Add non-advancing iter_next tests, Max Reitz, 2018/04/11
- [Qemu-block] [PATCH v4 09/13] block/dirty-bitmap: Add bdrv_dirty_iter_next_area,
Max Reitz <=
- [Qemu-block] [PATCH v4 10/13] block/mirror: Add MirrorBDSOpaque, Max Reitz, 2018/04/11
- [Qemu-block] [PATCH v4 11/13] block/mirror: Add active mirroring, Max Reitz, 2018/04/11
- [Qemu-block] [PATCH v4 12/13] block/mirror: Add copy mode QAPI interface, Max Reitz, 2018/04/11
- [Qemu-block] [PATCH v4 13/13] iotests: Add test for active mirroring, Max Reitz, 2018/04/11