qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] [PATCH 2/9] hbitmap: add hbitmap_copy


From: John Snow
Subject: [Qemu-devel] [PATCH 2/9] hbitmap: add hbitmap_copy
Date: Thu, 4 Jun 2015 20:20:35 -0400

It would be nice to have the flexibility to decide that
we would like multiple backup chains (perhaps of differing
frequency, or stored at different sites -- who knows.)

If the user didn't have the foresight to add all the requisite
bitmaps before the drive was engaged, the copy function will
allow them to later differentiate an incremental backup chain
into two or more chains at will.

hbitmap_copy here is just the primitive to make copies of the
implementation bitmap.

Signed-off-by: John Snow <address@hidden>
---
 include/qemu/hbitmap.h |  9 +++++++++
 util/hbitmap.c         | 17 +++++++++++++++++
 2 files changed, 26 insertions(+)

diff --git a/include/qemu/hbitmap.h b/include/qemu/hbitmap.h
index f0a85f8..e24fbe7 100644
--- a/include/qemu/hbitmap.h
+++ b/include/qemu/hbitmap.h
@@ -88,6 +88,15 @@ void hbitmap_truncate(HBitmap *hb, uint64_t size);
 bool hbitmap_merge(HBitmap *a, const HBitmap *b);
 
 /**
+ * hbitmap_copy:
+ * @hb: The bitmap to copy.
+ * @return The newly copied bitmap.
+ *
+ * Given a bitmap, create a new one with all the same bits set.
+ */
+HBitmap *hbitmap_copy(const HBitmap *hb);
+
+/**
  * hbitmap_empty:
  * @hb: HBitmap to operate on.
  *
diff --git a/util/hbitmap.c b/util/hbitmap.c
index a10c7ae..544ecd5 100644
--- a/util/hbitmap.c
+++ b/util/hbitmap.c
@@ -93,6 +93,9 @@ struct HBitmap {
 
     /* The length of each levels[] array. */
     uint64_t sizes[HBITMAP_LEVELS];
+
+    /* NB: If any pointers are introduced into this structure, take care to
+     * update hbitmap_copy() accordingly. */
 };
 
 /* Advance hbi to the next nonzero word and return it.  hbi->pos
@@ -480,3 +483,17 @@ bool hbitmap_merge(HBitmap *a, const HBitmap *b)
 
     return true;
 }
+
+
+HBitmap *hbitmap_copy(const HBitmap *bitmap)
+{
+    int i;
+    HBitmap *hb = g_memdup(bitmap, sizeof(HBitmap));
+
+    for (i = HBITMAP_LEVELS - 1; i >= 0; i--) {
+        hb->levels[i] = g_memdup(bitmap->levels[i],
+                                 hb->sizes[i] * sizeof(unsigned long));
+    }
+
+    return hb;
+}
-- 
2.1.0




reply via email to

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