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

[libvirt] [PATCH v4 01/37] qemu_monitor: Introduce qemuMonitorCPUModelInfoNew



A helper function allocates an initializes model name
in CPU Model Info structs.

Signed-off-by: Chris Venteicher <cventeic redhat com>
---
 src/qemu/qemu_capabilities.c |  2 +-
 src/qemu/qemu_monitor.c      | 32 +++++++++++++++++++++++++++-----
 src/qemu/qemu_monitor.h      |  2 ++
 3 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 2ca5af3297..eb9dca05f8 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -3024,7 +3024,7 @@ virQEMUCapsLoadHostCPUModelInfo(virQEMUCapsPtr qemuCaps,
         goto cleanup;
     }
 
-    if (VIR_ALLOC(hostCPU) < 0)
+    if (!(hostCPU = qemuMonitorCPUModelInfoNew(NULL)))
         goto cleanup;
 
     if (!(hostCPU->name = virXMLPropString(hostCPUNode, "model"))) {
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 7f7013e115..45a4568fcc 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -3670,6 +3670,31 @@ qemuMonitorGetCPUModelExpansion(qemuMonitorPtr mon,
 }
 
 
+qemuMonitorCPUModelInfoPtr
+qemuMonitorCPUModelInfoNew(const char *name)
+{
+    qemuMonitorCPUModelInfoPtr ret = NULL;
+    qemuMonitorCPUModelInfoPtr model;
+
+    if (VIR_ALLOC(model) < 0)
+        return NULL;
+
+    model->name = NULL;
+    model->nprops = 0;
+    model->props = NULL;
+    model->migratability = false;
+
+    if (VIR_STRDUP(model->name, name) < 0)
+        goto cleanup;
+
+    VIR_STEAL_PTR(ret, model);
+
+ cleanup:
+    qemuMonitorCPUModelInfoFree(model);
+    return ret;
+}
+
+
 void
 qemuMonitorCPUModelInfoFree(qemuMonitorCPUModelInfoPtr model_info)
 {
@@ -3693,18 +3718,15 @@ qemuMonitorCPUModelInfoFree(qemuMonitorCPUModelInfoPtr model_info)
 qemuMonitorCPUModelInfoPtr
 qemuMonitorCPUModelInfoCopy(const qemuMonitorCPUModelInfo *orig)
 {
-    qemuMonitorCPUModelInfoPtr copy;
+    qemuMonitorCPUModelInfoPtr copy = NULL;
     size_t i;
 
-    if (VIR_ALLOC(copy) < 0)
+    if (!orig || !(copy = qemuMonitorCPUModelInfoNew(orig->name)))
         goto error;
 
     if (VIR_ALLOC_N(copy->props, orig->nprops) < 0)
         goto error;
 
-    if (VIR_STRDUP(copy->name, orig->name) < 0)
-        goto error;
-
     copy->migratability = orig->migratability;
     copy->nprops = orig->nprops;
 
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index 48b142a4f4..d87b5a4ec0 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -1042,6 +1042,8 @@ int qemuMonitorGetCPUModelExpansion(qemuMonitorPtr mon,
 
 void qemuMonitorCPUModelInfoFree(qemuMonitorCPUModelInfoPtr model_info);
 
+qemuMonitorCPUModelInfoPtr qemuMonitorCPUModelInfoNew(const char *name);
+
 qemuMonitorCPUModelInfoPtr
 qemuMonitorCPUModelInfoCopy(const qemuMonitorCPUModelInfo *orig);
 
-- 
2.17.1


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