[PATCH v5 23/36] qemu_monitor: Introduce qemuMonitorCPUModelInfoNew

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

 



Use a helper function to allocate and initializes CPU Model Info structs.

Signed-off-by: Chris Venteicher <cventeic@xxxxxxxxxx>
---
 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 038e3ecf7a..cd685298e6 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -3047,7 +3047,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 84065c59dc..5effc74736 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 66bfdb0e5c..d486af201a 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

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

  Powered by Linux