[PATCH v3 29/52] qemu: Refactor virQEMUCapsLoadAccel

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

 



And make it use virQEMUCapsGetAccel once rather than repeating the same
code in all functions called from virQEMUCapsLoadAccel.

Signed-off-by: Jiri Denemark <jdenemar@xxxxxxxxxx>
---

Notes:
    Version 3:
    - new patch

 src/qemu/qemu_capabilities.c | 40 ++++++++++++++----------------------
 1 file changed, 15 insertions(+), 25 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 62667cb882..d19bcebdeb 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -3338,26 +3338,22 @@ virQEMUCapsSetCPUModelInfo(virQEMUCapsPtr qemuCaps,
 
 
 static int
-virQEMUCapsLoadHostCPUModelInfo(virQEMUCapsPtr qemuCaps,
+virQEMUCapsLoadHostCPUModelInfo(virQEMUCapsAccelPtr caps,
                                 xmlXPathContextPtr ctxt,
-                                virDomainVirtType virtType)
+                                const char *typeStr)
 {
     char *str = NULL;
     xmlNodePtr hostCPUNode;
     xmlNodePtr *nodes = NULL;
     VIR_XPATH_NODE_AUTORESTORE(ctxt);
     qemuMonitorCPUModelInfoPtr hostCPU = NULL;
+    g_autofree char *xpath = g_strdup_printf("./hostCPU[@type='%s']", typeStr);
     int ret = -1;
     size_t i;
     int n;
     int val;
 
-    if (virtType == VIR_DOMAIN_VIRT_KVM)
-        hostCPUNode = virXPathNode("./hostCPU[@type='kvm']", ctxt);
-    else
-        hostCPUNode = virXPathNode("./hostCPU[@type='tcg']", ctxt);
-
-    if (!hostCPUNode) {
+    if (!(hostCPUNode = virXPathNode(xpath, ctxt))) {
         ret = 0;
         goto cleanup;
     }
@@ -3458,8 +3454,7 @@ virQEMUCapsLoadHostCPUModelInfo(virQEMUCapsPtr qemuCaps,
         }
     }
 
-    virQEMUCapsSetCPUModelInfo(qemuCaps, virtType, hostCPU);
-    hostCPU = NULL;
+    caps->hostCPU.info = g_steal_pointer(&hostCPU);
     ret = 0;
 
  cleanup:
@@ -3471,22 +3466,18 @@ virQEMUCapsLoadHostCPUModelInfo(virQEMUCapsPtr qemuCaps,
 
 
 static int
-virQEMUCapsLoadCPUModels(virQEMUCapsPtr qemuCaps,
+virQEMUCapsLoadCPUModels(virQEMUCapsAccelPtr caps,
                          xmlXPathContextPtr ctxt,
-                         virDomainVirtType type)
+                         const char *typeStr)
 {
     g_autoptr(qemuMonitorCPUDefs) defs = NULL;
     g_autofree xmlNodePtr * nodes = NULL;
+    g_autofree char *xpath = g_strdup_printf("./cpu[@type='%s']", typeStr);
     size_t i;
     int n;
     xmlNodePtr node;
 
-    if (type == VIR_DOMAIN_VIRT_KVM)
-        n = virXPathNodeSet("./cpu[@type='kvm']", ctxt, &nodes);
-    else
-        n = virXPathNodeSet("./cpu[@type='tcg']", ctxt, &nodes);
-
-    if (n < 0) {
+    if ((n = virXPathNodeSet(xpath, ctxt, &nodes)) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("failed to parse qemu capabilities cpus"));
         return -1;
@@ -3550,11 +3541,7 @@ virQEMUCapsLoadCPUModels(virQEMUCapsPtr qemuCaps,
         }
     }
 
-    if (type == VIR_DOMAIN_VIRT_KVM)
-        qemuCaps->kvm.cpuModels = g_steal_pointer(&defs);
-    else
-        qemuCaps->tcg.cpuModels = g_steal_pointer(&defs);
-
+    caps->cpuModels = g_steal_pointer(&defs);
     return 0;
 }
 
@@ -3564,10 +3551,13 @@ virQEMUCapsLoadAccel(virQEMUCapsPtr qemuCaps,
                      xmlXPathContextPtr ctxt,
                      virDomainVirtType type)
 {
-    if (virQEMUCapsLoadHostCPUModelInfo(qemuCaps, ctxt, type) < 0)
+    virQEMUCapsAccelPtr caps = virQEMUCapsGetAccel(qemuCaps, type);
+    const char *typeStr = type == VIR_DOMAIN_VIRT_KVM ? "kvm" : "tcg";
+
+    if (virQEMUCapsLoadHostCPUModelInfo(caps, ctxt, typeStr) < 0)
         return -1;
 
-    if (virQEMUCapsLoadCPUModels(qemuCaps, ctxt, type) < 0)
+    if (virQEMUCapsLoadCPUModels(caps, ctxt, typeStr) < 0)
         return -1;
 
     return 0;
-- 
2.23.0

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