aboutsummaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>2022-03-03 20:43:41 +0100
committerHanna Reitz <hreitz@redhat.com>2022-03-07 09:33:30 +0100
commita6426475a75fb793d4c9dd9fe94815e8d18ddaa1 (patch)
tree4d51988de6bc5f7c12b7b927799f68b054595e8f /util
parent84b1e80f67f74a9d505802343458d4ebe8bdb3e4 (diff)
downloadqemu-a6426475a75fb793d4c9dd9fe94815e8d18ddaa1.zip
qemu-a6426475a75fb793d4c9dd9fe94815e8d18ddaa1.tar.gz
qemu-a6426475a75fb793d4c9dd9fe94815e8d18ddaa1.tar.bz2
block/dirty-bitmap: introduce bdrv_dirty_bitmap_status()
Add a convenient function similar with bdrv_block_status() to get status of dirty bitmap. Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> Reviewed-by: Hanna Reitz <hreitz@redhat.com> Message-Id: <20220303194349.2304213-9-vsementsov@virtuozzo.com> Signed-off-by: Hanna Reitz <hreitz@redhat.com>
Diffstat (limited to 'util')
-rw-r--r--util/hbitmap.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/util/hbitmap.c b/util/hbitmap.c
index 305b894..dd0501d 100644
--- a/util/hbitmap.c
+++ b/util/hbitmap.c
@@ -301,6 +301,39 @@ bool hbitmap_next_dirty_area(const HBitmap *hb, int64_t start, int64_t end,
return true;
}
+bool hbitmap_status(const HBitmap *hb, int64_t start, int64_t count,
+ int64_t *pnum)
+{
+ int64_t next_dirty, next_zero;
+
+ assert(start >= 0);
+ assert(count > 0);
+ assert(start + count <= hb->orig_size);
+
+ next_dirty = hbitmap_next_dirty(hb, start, count);
+ if (next_dirty == -1) {
+ *pnum = count;
+ return false;
+ }
+
+ if (next_dirty > start) {
+ *pnum = next_dirty - start;
+ return false;
+ }
+
+ assert(next_dirty == start);
+
+ next_zero = hbitmap_next_zero(hb, start, count);
+ if (next_zero == -1) {
+ *pnum = count;
+ return true;
+ }
+
+ assert(next_zero > start);
+ *pnum = next_zero - start;
+ return false;
+}
+
bool hbitmap_empty(const HBitmap *hb)
{
return hb->count == 0;