add new function to copy dirty-bitmap
PATCH 1/1 add new function to copy dirty-bitmap
From: mahaocong <[email protected]>
This patch adds new function to copy the hbitmap from an exist dirty-bitmap to another. The destination bitmap should have the same size and granularity with the source bitmap, or the copy will fail.
--- block/dirty-bitmap.c | 14 ++++++++++++++ include/block/dirty-bitmap.h | 3 +++ include/qemu/hbitmap.h | 2 ++ util/hbitmap.c | 28 ++++++++++++++++++++++++++++ 4 files changed, 47 insertions(+)
block/dirty-bitmap.c +14 -0
@@ -348,6 +348,20 @@ BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap(BlockDriverState *bs,return ret; } +BdrvDirtyBitmap *bdrv_copy_dirty_bitmap (BdrvDirtyBitmap *src, +BdrvDirtyBitmap *dest, +Error **errp) +{ +qemu_mutex_lock (src->mutex); +if (!hbitmap_copy (dest->bitmap, src->bitmap)) { +error_setg (errp,"Error: copy src bitmap failed" ); +return NULL ; + } +qemu_mutex_unlock (src->mutex); + +return dest; +} +/** * Truncates _all_ bitmaps attached to a BDS. * Called with BQL taken.
include/block/dirty-bitmap.h +3 -0
@@ -21,6 +21,9 @@ BdrvDirtyBitmap *bdrv_dirty_bitmap_abdicate(BlockDriverState *bs,BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap (BlockDriverState *bs,BdrvDirtyBitmap *bitmap,Error **errp); +BdrvDirtyBitmap *bdrv_copy_dirty_bitmap (BdrvDirtyBitmap *src, +BdrvDirtyBitmap *dest, +Error **errp);void bdrv_dirty_bitmap_enable_successor (BdrvDirtyBitmap *bitmap);BdrvDirtyBitmap *bdrv_find_dirty_bitmap (BlockDriverState *bs,const char *name);
include/qemu/hbitmap.h +2 -0
@@ -91,6 +91,8 @@ bool hbitmap_merge(const HBitmap *a, const HBitmap *b, HBitmap *result);*/ bool hbitmap_can_merge (const HBitmap *a,const HBitmap *b); +bool hbitmap_copy (HBitmap *dst,const HBitmap *src); +/** * hbitmap_empty: * @hb: HBitmap to operate on.
util/hbitmap.c +28 -0
@@ -765,6 +765,34 @@ bool hbitmap_merge(const HBitmap *a, const HBitmap *b, HBitmap *result)return true; } +/* +* Copy HBitmaps form src to dst. +* +* @return true if the copy was successful, +* false if it was not attempted. +*/ +bool hbitmap_copy (HBitmap *dst,const HBitmap *src) +{ +int i; + +if ((dst->size != src->size) || (dst->granularity != src->granularity)) { +return false; + } + +if (hbitmap_count (src) ==0 ) { +return true; + } + +for (i =HBITMAP_LEVELS -1 ; i >=0 ; i--) { +memcpy (dst->levels[i], src->levels[i], + src->sizes[i] *sizeof (unsigned long )); + } + + dst->count = src->count; +return true; +} + +HBitmap *hbitmap_create_meta (HBitmap *hb,int chunk_size) {assert (!(chunk_size & (chunk_size -1 )));
Signature · 1 line
2.14.1
Quoted 5 lines · mahaocong
From: mahaocong <[email protected]>
This patch adds new function to copy the hbitmap from an exist dirty-bitmap to another. The destination bitmap should have the same size and granularity with the source bitmap, or the copy will fail.
Is there a client in mind for this new code? And how does it differ to what you can already achieve by the combination of bdrv_clear_dirty_bitmap/bdrv_merge_dirty_bitmap?
Quoted 2 lines
Signed-off-by mahaocong <[email protected]>
Typical S-o-b and git authorship uses a preferred legal name rather than a single-word username (there have been exceptions made in the past, but we try not to introduce more without good reason). You can also teach git to spell your name in both native UTF-8 characters and a Latinized form, if you prefer.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Quoted 7 lines · mahaocong
From: mahaocong <[email protected]>
This patch adds new function to copy the hbitmap from an exist dirty-bitmap to another. The destination bitmap should have the same size and granularity with the source bitmap, or the copy will fail.
Signed-off-by mahaocong <[email protected]>
/technically/ we *can* do this already by creating a blank bitmap and merging from one bitmap to the empty one.
Do you have a good argument for why copy is needed in addition?
--js