render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
c1c534
From bc3c538ac7b184edea12e1377ec7cdce1d7bb9d2 Mon Sep 17 00:00:00 2001
c1c534
Message-Id: <bc3c538ac7b184edea12e1377ec7cdce1d7bb9d2@dist-git>
c1c534
From: Jiri Denemark <jdenemar@redhat.com>
c1c534
Date: Thu, 7 Dec 2017 11:21:48 +0100
c1c534
Subject: [PATCH] qemu: Separate fetching CPU definitions from filling qemuCaps
c1c534
c1c534
virQEMUCapsProbeQMPCPUDefinitions is now a small wrapper which fills in
c1c534
qemuCaps with CPU models fetched by virQEMUCapsFetchCPUDefinitions.
c1c534
c1c534
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
c1c534
(cherry picked from commit 4486dcdb4a386a906807d4eb7de586202e50cd18)
c1c534
c1c534
https://bugzilla.redhat.com/show_bug.cgi?id=1521202
c1c534
c1c534
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
c1c534
---
c1c534
 src/qemu/qemu_capabilities.c | 59 +++++++++++++++++++++++++++-----------------
c1c534
 src/qemu/qemu_capabilities.h |  1 +
c1c534
 2 files changed, 38 insertions(+), 22 deletions(-)
c1c534
c1c534
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
c1c534
index 4301d2e799..4af1b6c662 100644
c1c534
--- a/src/qemu/qemu_capabilities.c
c1c534
+++ b/src/qemu/qemu_capabilities.c
c1c534
@@ -2956,30 +2956,19 @@ virQEMUCapsProbeQMPMachineTypes(virQEMUCapsPtr qemuCaps,
c1c534
 }
c1c534
 
c1c534
 
c1c534
-int
c1c534
-virQEMUCapsProbeQMPCPUDefinitions(virQEMUCapsPtr qemuCaps,
c1c534
-                                  qemuMonitorPtr mon,
c1c534
-                                  bool tcg)
c1c534
+virDomainCapsCPUModelsPtr
c1c534
+virQEMUCapsFetchCPUDefinitions(qemuMonitorPtr mon)
c1c534
 {
c1c534
-    virDomainCapsCPUModelsPtr models;
c1c534
-    qemuMonitorCPUDefInfoPtr *cpus;
c1c534
-    int ncpus;
c1c534
-    int ret = -1;
c1c534
+    virDomainCapsCPUModelsPtr models = NULL;
c1c534
+    qemuMonitorCPUDefInfoPtr *cpus = NULL;
c1c534
+    int ncpus = 0;
c1c534
     size_t i;
c1c534
 
c1c534
-    if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_QUERY_CPU_DEFINITIONS))
c1c534
-        return 0;
c1c534
-
c1c534
     if ((ncpus = qemuMonitorGetCPUDefinitions(mon, &cpus)) < 0)
c1c534
-        return -1;
c1c534
+        goto error;
c1c534
 
c1c534
     if (!(models = virDomainCapsCPUModelsNew(ncpus)))
c1c534
-        goto cleanup;
c1c534
-
c1c534
-    if (tcg || !virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM))
c1c534
-        qemuCaps->tcgCPUModels = models;
c1c534
-    else
c1c534
-        qemuCaps->kvmCPUModels = models;
c1c534
+        goto error;
c1c534
 
c1c534
     for (i = 0; i < ncpus; i++) {
c1c534
         virDomainCapsCPUUsable usable = VIR_DOMCAPS_CPU_USABLE_UNKNOWN;
c1c534
@@ -2991,18 +2980,44 @@ virQEMUCapsProbeQMPCPUDefinitions(virQEMUCapsPtr qemuCaps,
c1c534
 
c1c534
         if (virDomainCapsCPUModelsAddSteal(models, &cpus[i]->name, usable,
c1c534
                                            &cpus[i]->blockers) < 0)
c1c534
-            goto cleanup;
c1c534
+            goto error;
c1c534
     }
c1c534
 
c1c534
-    ret = 0;
c1c534
-
c1c534
  cleanup:
c1c534
     for (i = 0; i < ncpus; i++)
c1c534
         qemuMonitorCPUDefInfoFree(cpus[i]);
c1c534
     VIR_FREE(cpus);
c1c534
-    return ret;
c1c534
+    return models;
c1c534
+
c1c534
+ error:
c1c534
+    virObjectUnref(models);
c1c534
+    models = NULL;
c1c534
+    goto cleanup;
c1c534
 }
c1c534
 
c1c534
+
c1c534
+int
c1c534
+virQEMUCapsProbeQMPCPUDefinitions(virQEMUCapsPtr qemuCaps,
c1c534
+                                  qemuMonitorPtr mon,
c1c534
+                                  bool tcg)
c1c534
+{
c1c534
+    virDomainCapsCPUModelsPtr models = NULL;
c1c534
+
c1c534
+    if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_QUERY_CPU_DEFINITIONS))
c1c534
+        return 0;
c1c534
+
c1c534
+    if (!(models = virQEMUCapsFetchCPUDefinitions(mon)))
c1c534
+        return -1;
c1c534
+
c1c534
+    if (tcg || !virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM))
c1c534
+        qemuCaps->tcgCPUModels = models;
c1c534
+    else
c1c534
+        qemuCaps->kvmCPUModels = models;
c1c534
+
c1c534
+    return 0;
c1c534
+}
c1c534
+
c1c534
+
c1c534
 static int
c1c534
 virQEMUCapsProbeQMPHostCPU(virQEMUCapsPtr qemuCaps,
c1c534
                            qemuMonitorPtr mon,
c1c534
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
c1c534
index c6eb9df146..0fb2a10a17 100644
c1c534
--- a/src/qemu/qemu_capabilities.h
c1c534
+++ b/src/qemu/qemu_capabilities.h
c1c534
@@ -485,6 +485,7 @@ int virQEMUCapsAddCPUDefinitions(virQEMUCapsPtr qemuCaps,
c1c534
                                  virDomainCapsCPUUsable usable);
c1c534
 virDomainCapsCPUModelsPtr virQEMUCapsGetCPUDefinitions(virQEMUCapsPtr qemuCaps,
c1c534
                                                        virDomainVirtType type);
c1c534
+virDomainCapsCPUModelsPtr virQEMUCapsFetchCPUDefinitions(qemuMonitorPtr mon);
c1c534
 
c1c534
 typedef enum {
c1c534
     /* Host CPU definition reported in domain capabilities. */
c1c534
-- 
c1c534
2.15.1
c1c534