[PATCH RFC 2/8] qemu: add VirBitmapDup

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

 



Add function to duplicate a virBitmap for returning
cached qemuCaps[Flags] from qemuCapsExtractVersionInfo

TODO:  could factor the size calculation into a macro or inline
function as it's used by both Dup and Alloc.

---
 src/libvirt_private.syms |    1 +
 src/util/bitmap.c        |   24 ++++++++++++++++++++++++
 src/util/bitmap.h        |    6 ++++++
 3 files changed, 31 insertions(+)

Index: libvirt-0.9.10/src/util/bitmap.c
===================================================================
--- libvirt-0.9.10.orig/src/util/bitmap.c
+++ libvirt-0.9.10/src/util/bitmap.c
@@ -80,6 +80,30 @@ virBitmapPtr virBitmapAlloc(size_t size)
 }
 
 /**
+ * virBitmapDup:
+ * @sbm: source bitmap to duplicate
+ *
+ * Duplicate the source bitmap.
+ *
+ * Returns a pointer to the duplicated bitmap or NULL if
+ * memory cannot be allocated.
+ */
+virBitmapPtr virBitmapDup(virBitmapPtr sbm)
+{
+    virBitmapPtr bitmap;
+
+    bitmap = virBitmapAlloc(sbm->size);
+    if (bitmap) {
+        size_t sz = (sbm->size + VIR_BITMAP_BITS_PER_UNIT - 1) /
+                         VIR_BITMAP_BITS_PER_UNIT;
+        int i;
+        for (i = 0; i < sz; ++i)
+            bitmap->map[i] = sbm->map[i];
+    }
+    return bitmap;
+}
+
+/**
  * virBitmapFree:
  * @bitmap: previously allocated bitmap
  *
Index: libvirt-0.9.10/src/util/bitmap.h
===================================================================
--- libvirt-0.9.10.orig/src/util/bitmap.h
+++ libvirt-0.9.10/src/util/bitmap.h
@@ -37,6 +37,12 @@ typedef virBitmap *virBitmapPtr;
 virBitmapPtr virBitmapAlloc(size_t size) ATTRIBUTE_RETURN_CHECK;
 
 /*
+ * Duplicate the specified virBitmap
+ */
+virBitmapPtr virBitmapDup(virBitmapPtr src)
+    ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
+
+/*
  * Free previously allocated bitmap
  */
 void virBitmapFree(virBitmapPtr bitmap);
Index: libvirt-0.9.10/src/libvirt_private.syms
===================================================================
--- libvirt-0.9.10.orig/src/libvirt_private.syms
+++ libvirt-0.9.10/src/libvirt_private.syms
@@ -13,6 +13,7 @@ virRequestUsername;
 # bitmap.h
 virBitmapAlloc;
 virBitmapClearBit;
+virBitmapDup;
 virBitmapFree;
 virBitmapGetBit;
 virBitmapSetBit;

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]