mirror of
https://gitlab.com/qemu-project/qemu
synced 2024-07-08 20:17:27 +00:00
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>
This commit is contained in:
parent
84b1e80f67
commit
a6426475a7
|
@ -879,6 +879,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.
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue
Block a user