|
|
ae23c9 |
From d3cab6731c84ccc36d7a2655451486d1877afcf0 Mon Sep 17 00:00:00 2001
|
|
|
ae23c9 |
From: John Snow <jsnow@redhat.com>
|
|
|
ae23c9 |
Date: Tue, 20 Nov 2018 18:18:07 +0000
|
|
|
ae23c9 |
Subject: [PATCH 13/35] hbitmap: Add @advance param to hbitmap_iter_next()
|
|
|
ae23c9 |
|
|
|
ae23c9 |
RH-Author: John Snow <jsnow@redhat.com>
|
|
|
ae23c9 |
Message-id: <20181120181828.15132-4-jsnow@redhat.com>
|
|
|
ae23c9 |
Patchwork-id: 83063
|
|
|
ae23c9 |
O-Subject: [RHEL8/rhel qemu-kvm PATCH 03/24] hbitmap: Add @advance param to hbitmap_iter_next()
|
|
|
ae23c9 |
Bugzilla: 1518989
|
|
|
ae23c9 |
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
|
|
|
ae23c9 |
RH-Acked-by: Max Reitz <mreitz@redhat.com>
|
|
|
ae23c9 |
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
ae23c9 |
|
|
|
ae23c9 |
From: Max Reitz <mreitz@redhat.com>
|
|
|
ae23c9 |
|
|
|
ae23c9 |
This new parameter allows the caller to just query the next dirty
|
|
|
ae23c9 |
position without moving the iterator.
|
|
|
ae23c9 |
|
|
|
ae23c9 |
Signed-off-by: Max Reitz <mreitz@redhat.com>
|
|
|
ae23c9 |
Reviewed-by: Fam Zheng <famz@redhat.com>
|
|
|
ae23c9 |
Reviewed-by: John Snow <jsnow@redhat.com>
|
|
|
ae23c9 |
Message-id: 20180613181823.13618-8-mreitz@redhat.com
|
|
|
ae23c9 |
Signed-off-by: Max Reitz <mreitz@redhat.com>
|
|
|
ae23c9 |
(cherry picked from commit a33fbb4f8b64226becf502a123733776ce319b24)
|
|
|
ae23c9 |
Signed-off-by: John Snow <jsnow@redhat.com>
|
|
|
ae23c9 |
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
|
|
|
ae23c9 |
---
|
|
|
ae23c9 |
block/backup.c | 2 +-
|
|
|
ae23c9 |
block/dirty-bitmap.c | 2 +-
|
|
|
ae23c9 |
include/qemu/hbitmap.h | 5 ++++-
|
|
|
ae23c9 |
tests/test-hbitmap.c | 26 +++++++++++++-------------
|
|
|
ae23c9 |
util/hbitmap.c | 10 +++++++---
|
|
|
ae23c9 |
5 files changed, 26 insertions(+), 19 deletions(-)
|
|
|
ae23c9 |
|
|
|
ae23c9 |
diff --git a/block/backup.c b/block/backup.c
|
|
|
ae23c9 |
index 524e0ff..ac17db6 100644
|
|
|
ae23c9 |
--- a/block/backup.c
|
|
|
ae23c9 |
+++ b/block/backup.c
|
|
|
ae23c9 |
@@ -409,7 +409,7 @@ static int coroutine_fn backup_run_incremental(BackupBlockJob *job)
|
|
|
ae23c9 |
HBitmapIter hbi;
|
|
|
ae23c9 |
|
|
|
ae23c9 |
hbitmap_iter_init(&hbi, job->copy_bitmap, 0);
|
|
|
ae23c9 |
- while ((cluster = hbitmap_iter_next(&hbi)) != -1) {
|
|
|
ae23c9 |
+ while ((cluster = hbitmap_iter_next(&hbi, true)) != -1) {
|
|
|
ae23c9 |
do {
|
|
|
ae23c9 |
if (yield_and_check(job)) {
|
|
|
ae23c9 |
return 0;
|
|
|
ae23c9 |
diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c
|
|
|
ae23c9 |
index dac8d74..236dce1 100644
|
|
|
ae23c9 |
--- a/block/dirty-bitmap.c
|
|
|
ae23c9 |
+++ b/block/dirty-bitmap.c
|
|
|
ae23c9 |
@@ -525,7 +525,7 @@ void bdrv_dirty_iter_free(BdrvDirtyBitmapIter *iter)
|
|
|
ae23c9 |
|
|
|
ae23c9 |
int64_t bdrv_dirty_iter_next(BdrvDirtyBitmapIter *iter)
|
|
|
ae23c9 |
{
|
|
|
ae23c9 |
- return hbitmap_iter_next(&iter->hbi);
|
|
|
ae23c9 |
+ return hbitmap_iter_next(&iter->hbi, true);
|
|
|
ae23c9 |
}
|
|
|
ae23c9 |
|
|
|
ae23c9 |
/* Called within bdrv_dirty_bitmap_lock..unlock */
|
|
|
ae23c9 |
diff --git a/include/qemu/hbitmap.h b/include/qemu/hbitmap.h
|
|
|
ae23c9 |
index 6b6490e..ddca52c 100644
|
|
|
ae23c9 |
--- a/include/qemu/hbitmap.h
|
|
|
ae23c9 |
+++ b/include/qemu/hbitmap.h
|
|
|
ae23c9 |
@@ -324,11 +324,14 @@ void hbitmap_free_meta(HBitmap *hb);
|
|
|
ae23c9 |
/**
|
|
|
ae23c9 |
* hbitmap_iter_next:
|
|
|
ae23c9 |
* @hbi: HBitmapIter to operate on.
|
|
|
ae23c9 |
+ * @advance: If true, advance the iterator. Otherwise, the next call
|
|
|
ae23c9 |
+ * of this function will return the same result (if that
|
|
|
ae23c9 |
+ * position is still dirty).
|
|
|
ae23c9 |
*
|
|
|
ae23c9 |
* Return the next bit that is set in @hbi's associated HBitmap,
|
|
|
ae23c9 |
* or -1 if all remaining bits are zero.
|
|
|
ae23c9 |
*/
|
|
|
ae23c9 |
-int64_t hbitmap_iter_next(HBitmapIter *hbi);
|
|
|
ae23c9 |
+int64_t hbitmap_iter_next(HBitmapIter *hbi, bool advance);
|
|
|
ae23c9 |
|
|
|
ae23c9 |
/**
|
|
|
ae23c9 |
* hbitmap_iter_next_word:
|
|
|
ae23c9 |
diff --git a/tests/test-hbitmap.c b/tests/test-hbitmap.c
|
|
|
ae23c9 |
index f29631f..f2158f7 100644
|
|
|
ae23c9 |
--- a/tests/test-hbitmap.c
|
|
|
ae23c9 |
+++ b/tests/test-hbitmap.c
|
|
|
ae23c9 |
@@ -46,7 +46,7 @@ static void hbitmap_test_check(TestHBitmapData *data,
|
|
|
ae23c9 |
|
|
|
ae23c9 |
i = first;
|
|
|
ae23c9 |
for (;;) {
|
|
|
ae23c9 |
- next = hbitmap_iter_next(&hbi;;
|
|
|
ae23c9 |
+ next = hbitmap_iter_next(&hbi, true);
|
|
|
ae23c9 |
if (next < 0) {
|
|
|
ae23c9 |
next = data->size;
|
|
|
ae23c9 |
}
|
|
|
ae23c9 |
@@ -435,25 +435,25 @@ static void test_hbitmap_iter_granularity(TestHBitmapData *data,
|
|
|
ae23c9 |
/* Note that hbitmap_test_check has to be invoked manually in this test. */
|
|
|
ae23c9 |
hbitmap_test_init(data, 131072 << 7, 7);
|
|
|
ae23c9 |
hbitmap_iter_init(&hbi, data->hb, 0);
|
|
|
ae23c9 |
- g_assert_cmpint(hbitmap_iter_next(&hbi), <, 0);
|
|
|
ae23c9 |
+ g_assert_cmpint(hbitmap_iter_next(&hbi, true), <, 0);
|
|
|
ae23c9 |
|
|
|
ae23c9 |
hbitmap_test_set(data, ((L2 + L1 + 1) << 7) + 8, 8);
|
|
|
ae23c9 |
hbitmap_iter_init(&hbi, data->hb, 0);
|
|
|
ae23c9 |
- g_assert_cmpint(hbitmap_iter_next(&hbi), ==, (L2 + L1 + 1) << 7);
|
|
|
ae23c9 |
- g_assert_cmpint(hbitmap_iter_next(&hbi), <, 0);
|
|
|
ae23c9 |
+ g_assert_cmpint(hbitmap_iter_next(&hbi, true), ==, (L2 + L1 + 1) << 7);
|
|
|
ae23c9 |
+ g_assert_cmpint(hbitmap_iter_next(&hbi, true), <, 0);
|
|
|
ae23c9 |
|
|
|
ae23c9 |
hbitmap_iter_init(&hbi, data->hb, (L2 + L1 + 2) << 7);
|
|
|
ae23c9 |
- g_assert_cmpint(hbitmap_iter_next(&hbi), <, 0);
|
|
|
ae23c9 |
+ g_assert_cmpint(hbitmap_iter_next(&hbi, true), <, 0);
|
|
|
ae23c9 |
|
|
|
ae23c9 |
hbitmap_test_set(data, (131072 << 7) - 8, 8);
|
|
|
ae23c9 |
hbitmap_iter_init(&hbi, data->hb, 0);
|
|
|
ae23c9 |
- g_assert_cmpint(hbitmap_iter_next(&hbi), ==, (L2 + L1 + 1) << 7);
|
|
|
ae23c9 |
- g_assert_cmpint(hbitmap_iter_next(&hbi), ==, 131071 << 7);
|
|
|
ae23c9 |
- g_assert_cmpint(hbitmap_iter_next(&hbi), <, 0);
|
|
|
ae23c9 |
+ g_assert_cmpint(hbitmap_iter_next(&hbi, true), ==, (L2 + L1 + 1) << 7);
|
|
|
ae23c9 |
+ g_assert_cmpint(hbitmap_iter_next(&hbi, true), ==, 131071 << 7);
|
|
|
ae23c9 |
+ g_assert_cmpint(hbitmap_iter_next(&hbi, true), <, 0);
|
|
|
ae23c9 |
|
|
|
ae23c9 |
hbitmap_iter_init(&hbi, data->hb, (L2 + L1 + 2) << 7);
|
|
|
ae23c9 |
- g_assert_cmpint(hbitmap_iter_next(&hbi), ==, 131071 << 7);
|
|
|
ae23c9 |
- g_assert_cmpint(hbitmap_iter_next(&hbi), <, 0);
|
|
|
ae23c9 |
+ g_assert_cmpint(hbitmap_iter_next(&hbi, true), ==, 131071 << 7);
|
|
|
ae23c9 |
+ g_assert_cmpint(hbitmap_iter_next(&hbi, true), <, 0);
|
|
|
ae23c9 |
}
|
|
|
ae23c9 |
|
|
|
ae23c9 |
static void hbitmap_test_set_boundary_bits(TestHBitmapData *data, ssize_t diff)
|
|
|
ae23c9 |
@@ -893,7 +893,7 @@ static void test_hbitmap_serialize_zeroes(TestHBitmapData *data,
|
|
|
ae23c9 |
for (i = 0; i < num_positions; i++) {
|
|
|
ae23c9 |
hbitmap_deserialize_zeroes(data->hb, positions[i], min_l1, true);
|
|
|
ae23c9 |
hbitmap_iter_init(&iter, data->hb, 0);
|
|
|
ae23c9 |
- next = hbitmap_iter_next(&iter);
|
|
|
ae23c9 |
+ next = hbitmap_iter_next(&iter, true);
|
|
|
ae23c9 |
if (i == num_positions - 1) {
|
|
|
ae23c9 |
g_assert_cmpint(next, ==, -1);
|
|
|
ae23c9 |
} else {
|
|
|
ae23c9 |
@@ -919,10 +919,10 @@ static void test_hbitmap_iter_and_reset(TestHBitmapData *data,
|
|
|
ae23c9 |
|
|
|
ae23c9 |
hbitmap_iter_init(&hbi, data->hb, BITS_PER_LONG - 1);
|
|
|
ae23c9 |
|
|
|
ae23c9 |
- hbitmap_iter_next(&hbi;;
|
|
|
ae23c9 |
+ hbitmap_iter_next(&hbi, true);
|
|
|
ae23c9 |
|
|
|
ae23c9 |
hbitmap_reset_all(data->hb);
|
|
|
ae23c9 |
- hbitmap_iter_next(&hbi;;
|
|
|
ae23c9 |
+ hbitmap_iter_next(&hbi, true);
|
|
|
ae23c9 |
}
|
|
|
ae23c9 |
|
|
|
ae23c9 |
static void test_hbitmap_next_zero_check(TestHBitmapData *data, int64_t start)
|
|
|
ae23c9 |
diff --git a/util/hbitmap.c b/util/hbitmap.c
|
|
|
ae23c9 |
index 58a2c93..bcd3040 100644
|
|
|
ae23c9 |
--- a/util/hbitmap.c
|
|
|
ae23c9 |
+++ b/util/hbitmap.c
|
|
|
ae23c9 |
@@ -141,7 +141,7 @@ unsigned long hbitmap_iter_skip_words(HBitmapIter *hbi)
|
|
|
ae23c9 |
return cur;
|
|
|
ae23c9 |
}
|
|
|
ae23c9 |
|
|
|
ae23c9 |
-int64_t hbitmap_iter_next(HBitmapIter *hbi)
|
|
|
ae23c9 |
+int64_t hbitmap_iter_next(HBitmapIter *hbi, bool advance)
|
|
|
ae23c9 |
{
|
|
|
ae23c9 |
unsigned long cur = hbi->cur[HBITMAP_LEVELS - 1] &
|
|
|
ae23c9 |
hbi->hb->levels[HBITMAP_LEVELS - 1][hbi->pos];
|
|
|
ae23c9 |
@@ -154,8 +154,12 @@ int64_t hbitmap_iter_next(HBitmapIter *hbi)
|
|
|
ae23c9 |
}
|
|
|
ae23c9 |
}
|
|
|
ae23c9 |
|
|
|
ae23c9 |
- /* The next call will resume work from the next bit. */
|
|
|
ae23c9 |
- hbi->cur[HBITMAP_LEVELS - 1] = cur & (cur - 1);
|
|
|
ae23c9 |
+ if (advance) {
|
|
|
ae23c9 |
+ /* The next call will resume work from the next bit. */
|
|
|
ae23c9 |
+ hbi->cur[HBITMAP_LEVELS - 1] = cur & (cur - 1);
|
|
|
ae23c9 |
+ } else {
|
|
|
ae23c9 |
+ hbi->cur[HBITMAP_LEVELS - 1] = cur;
|
|
|
ae23c9 |
+ }
|
|
|
ae23c9 |
item = ((uint64_t)hbi->pos << BITS_PER_LEVEL) + ctzl(cur);
|
|
|
ae23c9 |
|
|
|
ae23c9 |
return item << hbi->granularity;
|
|
|
ae23c9 |
--
|
|
|
ae23c9 |
1.8.3.1
|
|
|
ae23c9 |
|