]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
Add API for copying instances of the qemuCapsPtr object
authorDaniel P. Berrange <berrange@redhat.com>
Tue, 11 Sep 2012 12:42:20 +0000 (13:42 +0100)
committerDaniel P. Berrange <berrange@redhat.com>
Thu, 13 Sep 2012 11:28:01 +0000 (12:28 +0100)
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
src/qemu/qemu_capabilities.h

index 784ba8889cd72e937c260e80fcce28ef4625564e..c0082fb490e2e22fa2334d397b59deb30699fb38 100644 (file)
@@ -1727,6 +1727,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;
index 05e4ad11c705db9a02ba40a3a62c6d92441060b0..8f145a7d007830d101d90b0d854d8878ae29acfa 100644 (file)
@@ -150,6 +150,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);