[PATCH v3 15/52] qemu: Introduce virQEMUCapsCPUDefsToModels

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

 



The function translates qemuMonitorCPUDefsPtr (used by QEMU caps probing
code) into virDomainCapsCPUModelsPtr used by domain capabilities.

Signed-off-by: Jiri Denemark <jdenemar@xxxxxxxxxx>
Reviewed-by: Ján Tomko <jtomko@xxxxxxxxxx>
---

Notes:
    Version 2:
    - trivial rebase
    
    Version 3:
    - g_autoptr, g_steal_pointer

 src/qemu/qemu_capabilities.c | 58 ++++++++++++++++++++++--------------
 1 file changed, 35 insertions(+), 23 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 2a93488520..1497c4f645 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -1881,6 +1881,35 @@ virQEMUCapsAddCPUDefinitions(virQEMUCapsPtr qemuCaps,
 }
 
 
+static virDomainCapsCPUModelsPtr
+virQEMUCapsCPUDefsToModels(qemuMonitorCPUDefsPtr defs,
+                           const char **modelWhitelist,
+                           const char **modelBlacklist)
+{
+    g_autoptr(virDomainCapsCPUModels) cpuModels = NULL;
+    size_t i;
+
+    if (!(cpuModels = virDomainCapsCPUModelsNew(defs->ncpus)))
+        return NULL;
+
+    for (i = 0; i < defs->ncpus; i++) {
+        qemuMonitorCPUDefInfoPtr cpu = defs->cpus + i;
+
+        if (modelWhitelist && !virStringListHasString(modelWhitelist, cpu->name))
+            continue;
+
+        if (modelBlacklist && virStringListHasString(modelBlacklist, cpu->name))
+            continue;
+
+        if (virDomainCapsCPUModelsAdd(cpuModels, cpu->name, cpu->usable,
+                                      cpu->blockers) < 0)
+            return NULL;
+    }
+
+    return g_steal_pointer(&cpuModels);
+}
+
+
 virDomainCapsCPUModelsPtr
 virQEMUCapsGetCPUDefinitions(virQEMUCapsPtr qemuCaps,
                              virDomainVirtType type,
@@ -2448,19 +2477,15 @@ virQEMUCapsFetchCPUDefinitions(qemuMonitorPtr mon,
                                virDomainCapsCPUModelsPtr *cpuModels)
 {
     g_autoptr(qemuMonitorCPUDefs) defs = NULL;
-    virDomainCapsCPUModelsPtr models = NULL;
     size_t i;
-    int ret = -1;
 
     *cpuModels = NULL;
 
     if (qemuMonitorGetCPUDefinitions(mon, &defs) < 0)
         return -1;
 
-    if (!defs) {
-        ret = 0;
-        goto cleanup;
-    }
+    if (!defs)
+        return 0;
 
     /* QEMU 2.11 for Power renamed all CPU models to lower case, we need to
      * translate them back to libvirt's upper case model names. */
@@ -2469,7 +2494,7 @@ virQEMUCapsFetchCPUDefinitions(qemuMonitorPtr mon,
         char **name;
 
         if (virCPUGetModels(arch, &libvirtModels) < 0)
-            goto cleanup;
+            return -1;
 
         for (name = libvirtModels; name && *name; name++) {
             for (i = 0; i < defs->ncpus; i++) {
@@ -2482,23 +2507,10 @@ virQEMUCapsFetchCPUDefinitions(qemuMonitorPtr mon,
         }
     }
 
-    if (!(models = virDomainCapsCPUModelsNew(defs->ncpus)))
-        goto cleanup;
-
-    for (i = 0; i < defs->ncpus; i++) {
-        if (virDomainCapsCPUModelsAddSteal(models,
-                                           &defs->cpus[i].name,
-                                           defs->cpus[i].usable,
-                                           &defs->cpus[i].blockers) < 0)
-            goto cleanup;
-    }
-
-    *cpuModels = g_steal_pointer(&models);
-    ret = 0;
+    if (!(*cpuModels = virQEMUCapsCPUDefsToModels(defs, NULL, NULL)))
+        return -1;
 
- cleanup:
-    virObjectUnref(models);
-    return ret;
+    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