[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v5 08/16] block/dirty-bitmap: introduce bdrv_dirty_bitmap_status(
From: |
Vladimir Sementsov-Ogievskiy |
Subject: |
[PATCH v5 08/16] block/dirty-bitmap: introduce bdrv_dirty_bitmap_status() |
Date: |
Mon, 28 Feb 2022 12:39:19 +0100 |
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>
---
include/block/dirty-bitmap.h | 2 ++
include/qemu/hbitmap.h | 12 ++++++++++++
block/dirty-bitmap.c | 6 ++++++
util/hbitmap.c | 33 +++++++++++++++++++++++++++++++++
4 files changed, 53 insertions(+)
diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h
index f95d350b70..6528336c4c 100644
--- a/include/block/dirty-bitmap.h
+++ b/include/block/dirty-bitmap.h
@@ -115,6 +115,8 @@ int64_t bdrv_dirty_bitmap_next_zero(BdrvDirtyBitmap
*bitmap, int64_t offset,
bool bdrv_dirty_bitmap_next_dirty_area(BdrvDirtyBitmap *bitmap,
int64_t start, int64_t end, int64_t max_dirty_count,
int64_t *dirty_start, int64_t *dirty_count);
+bool bdrv_dirty_bitmap_status(BdrvDirtyBitmap *bitmap, int64_t offset,
+ int64_t bytes, int64_t *count);
BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap,
Error **errp);
diff --git a/include/qemu/hbitmap.h b/include/qemu/hbitmap.h
index 5e71b6d6f7..5bd986aa44 100644
--- a/include/qemu/hbitmap.h
+++ b/include/qemu/hbitmap.h
@@ -340,6 +340,18 @@ bool hbitmap_next_dirty_area(const HBitmap *hb, int64_t
start, int64_t end,
int64_t max_dirty_count,
int64_t *dirty_start, int64_t *dirty_count);
+/*
+ * bdrv_dirty_bitmap_status:
+ * @hb: The HBitmap to operate on
+ * @start: The bit to start from
+ * @count: Number of bits to proceed
+ * @pnum: Out-parameter. How many bits has same value starting from @start
+ *
+ * Returns true if bitmap is dirty at @start, false otherwise.
+ */
+bool hbitmap_status(const HBitmap *hb, int64_t start, int64_t count,
+ int64_t *pnum);
+
/**
* hbitmap_iter_next:
* @hbi: HBitmapIter to operate on.
diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c
index 94a0276833..08d56845ad 100644
--- a/block/dirty-bitmap.c
+++ b/block/dirty-bitmap.c
@@ -875,6 +875,12 @@ bool bdrv_dirty_bitmap_next_dirty_area(BdrvDirtyBitmap
*bitmap,
dirty_start, dirty_count);
}
+bool bdrv_dirty_bitmap_status(BdrvDirtyBitmap *bitmap, int64_t offset,
+ int64_t bytes, int64_t *count)
+{
+ return hbitmap_status(bitmap->bitmap, offset, bytes, count);
+}
+
/**
* bdrv_merge_dirty_bitmap: merge src into dest.
* Ensures permissions on bitmaps are reasonable; use for public API.
diff --git a/util/hbitmap.c b/util/hbitmap.c
index 305b894a63..dd0501d9a7 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;
--
2.31.1
- [PATCH v5 00/16] Make image fleecing more usable, Vladimir Sementsov-Ogievskiy, 2022/02/28
- [PATCH v5 05/16] block/block-copy: add block_copy_reset(), Vladimir Sementsov-Ogievskiy, 2022/02/28
- [PATCH v5 01/16] block/block-copy: move copy_bitmap initialization to block_copy_state_new(), Vladimir Sementsov-Ogievskiy, 2022/02/28
- [PATCH v5 04/16] block/copy-before-write: add bitmap open parameter, Vladimir Sementsov-Ogievskiy, 2022/02/28
- [PATCH v5 02/16] block/dirty-bitmap: bdrv_merge_dirty_bitmap(): add return value, Vladimir Sementsov-Ogievskiy, 2022/02/28
- [PATCH v5 06/16] block: intoduce reqlist, Vladimir Sementsov-Ogievskiy, 2022/02/28
- [PATCH v5 07/16] block/reqlist: reqlist_find_conflict(): use ranges_overlap(), Vladimir Sementsov-Ogievskiy, 2022/02/28
- [PATCH v5 08/16] block/dirty-bitmap: introduce bdrv_dirty_bitmap_status(),
Vladimir Sementsov-Ogievskiy <=
- [PATCH v5 03/16] block/block-copy: block_copy_state_new(): add bitmap parameter, Vladimir Sementsov-Ogievskiy, 2022/02/28
- [PATCH v5 10/16] block/io: introduce block driver snapshot-access API, Vladimir Sementsov-Ogievskiy, 2022/02/28
- [PATCH v5 09/16] block/reqlist: add reqlist_wait_all(), Vladimir Sementsov-Ogievskiy, 2022/02/28
- [PATCH v5 11/16] block: introduce snapshot-access block driver, Vladimir Sementsov-Ogievskiy, 2022/02/28
- [PATCH v5 12/16] block: copy-before-write: realize snapshot-access API, Vladimir Sementsov-Ogievskiy, 2022/02/28
- [PATCH v5 13/16] iotests/image-fleecing: add test-case for fleecing format node, Vladimir Sementsov-Ogievskiy, 2022/02/28
- [PATCH v5 15/16] iotests/image-fleecing: add test case with bitmap, Vladimir Sementsov-Ogievskiy, 2022/02/28
- [PATCH v5 14/16] iotests.py: add qemu_io_pipe_and_status(), Vladimir Sementsov-Ogievskiy, 2022/02/28
- [PATCH v5 16/16] iotests/image-fleecing: test push backup with fleecing, Vladimir Sementsov-Ogievskiy, 2022/02/28