[PATCH 09/20] Add API for copying instances of the qemuCapsPtr object

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

 



From: "Daniel P. Berrange" <berrange@xxxxxxxxxx>

To allow each VM instance to record additional capabilities
without affecting other VMs, there needs to be a way to do
a deep copy of the qemuCapsPtr object
---
 src/qemu/qemu_capabilities.c | 47 ++++++++++++++++++++++++++++++++++++++++++++
 src/qemu/qemu_capabilities.h |  1 +
 2 files changed, 48 insertions(+)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 1e36e4b..bc45c52 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -1723,6 +1723,53 @@ no_memory:
 }
 
 
+qemuCapsPtr qemuCapsNewCopy(qemuCapsPtr caps)
+{
+    qemuCapsPtr ret = qemuCapsNew();
+    size_t i;
+
+    if (!ret)
+        return NULL;
+
+    virBitmapCopy(ret->flags, caps->flags);
+
+    ret->version = caps->version;
+    ret->kvmVersion = caps->kvmVersion;
+
+    if (caps->arch &&
+        !(ret->arch = strdup(caps->arch)))
+        goto no_memory;
+
+    if (VIR_ALLOC_N(ret->cpuDefinitions, caps->ncpuDefinitions) < 0)
+        goto no_memory;
+    ret->ncpuDefinitions = caps->ncpuDefinitions;
+    for (i = 0 ; i < caps->ncpuDefinitions ; i++) {
+        if (!(ret->cpuDefinitions[i] = strdup(caps->cpuDefinitions[i])))
+            goto no_memory;
+    }
+
+    if (VIR_ALLOC_N(ret->machineTypes, caps->nmachineTypes) < 0)
+        goto no_memory;
+    if (VIR_ALLOC_N(ret->machineAliases, caps->nmachineTypes) < 0)
+        goto no_memory;
+    ret->nmachineTypes = caps->nmachineTypes;
+    for (i = 0 ; i < caps->nmachineTypes ; i++) {
+        if (!(ret->machineTypes[i] = strdup(caps->machineTypes[i])))
+            goto no_memory;
+        if (caps->machineAliases[i] &&
+            !(ret->machineAliases[i] = strdup(caps->machineAliases[i])))
+            goto no_memory;
+    }
+
+    return ret;
+
+no_memory:
+    virReportOOMError();
+    virObjectUnref(ret);
+    return NULL;
+}
+
+
 void qemuCapsDispose(void *obj)
 {
     qemuCapsPtr caps = obj;
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index c6e3756..cd104c0 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -149,6 +149,7 @@ typedef struct _qemuCaps qemuCaps;
 typedef qemuCaps *qemuCapsPtr;
 
 qemuCapsPtr qemuCapsNew(void);
+qemuCapsPtr qemuCapsNewCopy(qemuCapsPtr caps);
 
 void qemuCapsSet(qemuCapsPtr caps,
                  enum qemuCapsFlags flag) ATTRIBUTE_NONNULL(1);
-- 
1.7.11.4

--
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]