[PATCH v6 21/33] 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 |  8 ++++----
 src/qemu/qemu_monitor.c      | 27 ++++++++++++++++++++++-----
 src/qemu/qemu_monitor.h      |  2 ++
 src/qemu/qemu_monitor_json.c |  5 +----
 4 files changed, 29 insertions(+), 13 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index bac8487a78..02911a2a10 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -3063,16 +3063,16 @@ virQEMUCapsLoadHostCPUModelInfo(virQEMUCapsPtr qemuCaps,
         goto cleanup;
     }
 
-    if (VIR_ALLOC(hostCPU) < 0)
-        goto cleanup;
-
-    if (!(hostCPU->name = virXMLPropString(hostCPUNode, "model"))) {
+    if (!(str = virXMLPropString(hostCPUNode, "model"))) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("missing host CPU model name in QEMU "
                          "capabilities cache"));
         goto cleanup;
     }
 
+    if (!(hostCPU = qemuMonitorCPUModelInfoNew(str)))
+        goto cleanup;
+
     if (!(str = virXMLPropString(hostCPUNode, "migratability")) ||
         (val = virTristateBoolTypeFromString(str)) <= 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 7ce5bd668e..815a30c275 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -3686,6 +3686,26 @@ qemuMonitorGetCPUModelExpansion(qemuMonitorPtr mon,
 }
 
 
+qemuMonitorCPUModelInfoPtr
+qemuMonitorCPUModelInfoNew(const char *name)
+{
+    qemuMonitorCPUModelInfoPtr ret = NULL;
+    qemuMonitorCPUModelInfoPtr model;
+
+    if (VIR_ALLOC(model) < 0)
+        return NULL;
+
+    if (VIR_STRDUP(model->name, name) < 0)
+        goto cleanup;
+
+    VIR_STEAL_PTR(ret, model);
+
+ cleanup:
+    qemuMonitorCPUModelInfoFree(model);
+    return ret;
+}
+
+
 void
 qemuMonitorCPUModelInfoFree(qemuMonitorCPUModelInfoPtr model_info)
 {
@@ -3709,18 +3729,15 @@ qemuMonitorCPUModelInfoFree(qemuMonitorCPUModelInfoPtr model_info)
 qemuMonitorCPUModelInfoPtr
 qemuMonitorCPUModelInfoCopy(const qemuMonitorCPUModelInfo *orig)
 {
-    qemuMonitorCPUModelInfoPtr copy;
+    qemuMonitorCPUModelInfoPtr copy = NULL;
     size_t i;
 
-    if (VIR_ALLOC(copy) < 0)
+    if (!(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 8fcac8850f..d17bda75c3 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -1067,6 +1067,8 @@ int qemuMonitorGetCPUModelExpansion(qemuMonitorPtr mon,
 
 void qemuMonitorCPUModelInfoFree(qemuMonitorCPUModelInfoPtr model_info);
 
+qemuMonitorCPUModelInfoPtr qemuMonitorCPUModelInfoNew(const char *name);
+
 qemuMonitorCPUModelInfoPtr
 qemuMonitorCPUModelInfoCopy(const qemuMonitorCPUModelInfo *orig);
 
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 1f7eb20a25..dcb468c747 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -5642,10 +5642,7 @@ qemuMonitorJSONGetCPUModelExpansion(qemuMonitorPtr mon,
         goto cleanup;
     }
 
-    if (VIR_ALLOC(machine_model) < 0)
-        goto cleanup;
-
-    if (VIR_STRDUP(machine_model->name, cpu_name) < 0)
+    if (!(machine_model = qemuMonitorCPUModelInfoNew(cpu_name)))
         goto cleanup;
 
     if (VIR_ALLOC_N(machine_model->props, virJSONValueObjectKeysNumber(cpu_props)) < 0)
-- 
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