qemu-block
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-block] [PATCH 3/9] block: add bdrv_copy_dirty_bitmap


From: John Snow
Subject: [Qemu-block] [PATCH 3/9] block: add bdrv_copy_dirty_bitmap
Date: Thu, 4 Jun 2015 20:20:36 -0400

One step up from hbitmap, we need a copy primitive for
the BdrvDirtyBitmap type.

Signed-off-by: John Snow <address@hidden>
---
 block.c               | 26 ++++++++++++++++++++++++++
 include/block/block.h |  4 ++++
 2 files changed, 30 insertions(+)

diff --git a/block.c b/block.c
index 1eb81ac..5551f79 100644
--- a/block.c
+++ b/block.c
@@ -3114,6 +3114,32 @@ BdrvDirtyBitmap 
*bdrv_create_dirty_bitmap(BlockDriverState *bs,
     return bitmap;
 }
 
+BdrvDirtyBitmap *bdrv_copy_dirty_bitmap(BlockDriverState *bs,
+                                        const BdrvDirtyBitmap *bitmap,
+                                        const char *name,
+                                        Error **errp)
+{
+    BdrvDirtyBitmap *new_bitmap;
+
+    if (name && bdrv_find_dirty_bitmap(bs, name)) {
+        error_setg(errp, "Bitmap already exists: %s", name);
+        return NULL;
+    }
+
+    new_bitmap = g_new0(BdrvDirtyBitmap, 1);
+    new_bitmap->bitmap = hbitmap_copy(bitmap->bitmap);
+    new_bitmap->size = bitmap->size;
+    new_bitmap->name = g_strdup(name);
+
+    if (bitmap->successor) {
+        /* NB: 2nd arg is read-only. */
+        hbitmap_merge(new_bitmap->bitmap, bitmap->successor->bitmap);
+    }
+
+    QLIST_INSERT_HEAD(&bs->dirty_bitmaps, new_bitmap, list);
+    return new_bitmap;
+}
+
 bool bdrv_dirty_bitmap_frozen(BdrvDirtyBitmap *bitmap)
 {
     return bitmap->successor;
diff --git a/include/block/block.h b/include/block/block.h
index b7892d2..e88a332 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -456,6 +456,10 @@ BdrvDirtyBitmap *bdrv_create_dirty_bitmap(BlockDriverState 
*bs,
                                           uint32_t granularity,
                                           const char *name,
                                           Error **errp);
+BdrvDirtyBitmap *bdrv_copy_dirty_bitmap(BlockDriverState *bs,
+                                        const BdrvDirtyBitmap *bitmap,
+                                        const char *name,
+                                        Error **errp);
 int bdrv_dirty_bitmap_create_successor(BlockDriverState *bs,
                                        BdrvDirtyBitmap *bitmap,
                                        Error **errp);
-- 
2.1.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]