[PATCH v3 09/52] qemu: Change return type of virQEMUCapsFetchCPUDefinitions

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

 



The function would return a valid virDomainCapsCPUModelsPtr with empty
CPU models list if query-cpu-definitions exists in QEMU, but returns
GenericError meaning it's not in fact implemented. This behaviour is a
bit strange especially after such virDomainCapsCPUModels structure is
stored in capabilities XML and parsed back, which will result in NULL
virDomainCapsCPUModelsPtr rather than a structure containing nothing.

Let's just keep virDomainCapsCPUModelsPtr NULL if the QMP command is not
implemented and change the return value to int so that callers can
easily check for failure or success.

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

Notes:
    Version 2:
    - new patch
    
    Version 3:
    - g_steal_pointer

 src/qemu/qemu_capabilities.c | 32 ++++++++++++++++++++------------
 src/qemu/qemu_capabilities.h |  5 +++--
 src/qemu/qemu_process.c      | 17 ++++++++++-------
 3 files changed, 33 insertions(+), 21 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 33b91d23dc..c88cf2f3b0 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -2442,17 +2442,26 @@ virQEMUCapsProbeQMPMachineProps(virQEMUCapsPtr qemuCaps,
 }
 
 
-virDomainCapsCPUModelsPtr
+int
 virQEMUCapsFetchCPUDefinitions(qemuMonitorPtr mon,
-                               virArch arch)
+                               virArch arch,
+                               virDomainCapsCPUModelsPtr *cpuModels)
 {
     virDomainCapsCPUModelsPtr models = NULL;
     qemuMonitorCPUDefInfoPtr *cpus = NULL;
     int ncpus = 0;
     size_t i;
+    int ret = -1;
+
+    *cpuModels = NULL;
 
     if ((ncpus = qemuMonitorGetCPUDefinitions(mon, &cpus)) < 0)
-        return NULL;
+        return -1;
+
+    if (ncpus == 0) {
+        ret = 0;
+        goto cleanup;
+    }
 
     /* 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. */
@@ -2461,7 +2470,7 @@ virQEMUCapsFetchCPUDefinitions(qemuMonitorPtr mon,
         char **name;
 
         if (virCPUGetModels(arch, &libvirtModels) < 0)
-            goto error;
+            goto cleanup;
 
         for (name = libvirtModels; name && *name; name++) {
             for (i = 0; i < ncpus; i++) {
@@ -2475,7 +2484,7 @@ virQEMUCapsFetchCPUDefinitions(qemuMonitorPtr mon,
     }
 
     if (!(models = virDomainCapsCPUModelsNew(ncpus)))
-        goto error;
+        goto cleanup;
 
     for (i = 0; i < ncpus; i++) {
         virDomainCapsCPUUsable usable = VIR_DOMCAPS_CPU_USABLE_UNKNOWN;
@@ -2487,19 +2496,18 @@ virQEMUCapsFetchCPUDefinitions(qemuMonitorPtr mon,
 
         if (virDomainCapsCPUModelsAddSteal(models, &cpus[i]->name, usable,
                                            &cpus[i]->blockers) < 0)
-            goto error;
+            goto cleanup;
     }
 
+    *cpuModels = g_steal_pointer(&models);
+    ret = 0;
+
  cleanup:
     for (i = 0; i < ncpus; i++)
         qemuMonitorCPUDefInfoFree(cpus[i]);
     VIR_FREE(cpus);
-    return models;
-
- error:
     virObjectUnref(models);
-    models = NULL;
-    goto cleanup;
+    return ret;
 }
 
 
@@ -2513,7 +2521,7 @@ virQEMUCapsProbeQMPCPUDefinitions(virQEMUCapsPtr qemuCaps,
     if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_QUERY_CPU_DEFINITIONS))
         return 0;
 
-    if (!(models = virQEMUCapsFetchCPUDefinitions(mon, qemuCaps->arch)))
+    if (virQEMUCapsFetchCPUDefinitions(mon, qemuCaps->arch, &models) < 0)
         return -1;
 
     if (tcg || !virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM))
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index 67dccc522e..ba3fe3d2b6 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -573,8 +573,9 @@ virDomainCapsCPUModelsPtr virQEMUCapsGetCPUDefinitions(virQEMUCapsPtr qemuCaps,
                                                        virDomainVirtType type,
                                                        const char **modelWhitelist,
                                                        const char **modelBlacklist);
-virDomainCapsCPUModelsPtr virQEMUCapsFetchCPUDefinitions(qemuMonitorPtr mon,
-                                                         virArch arch);
+int virQEMUCapsFetchCPUDefinitions(qemuMonitorPtr mon,
+                                   virArch arch,
+                                   virDomainCapsCPUModelsPtr *cpuModels);
 
 typedef enum {
     /* Host CPU definition reported in domain capabilities. */
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 4c61332871..bdd01993a2 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -4345,27 +4345,30 @@ qemuProcessUpdateAndVerifyCPU(virQEMUDriverPtr driver,
 }
 
 
-static virDomainCapsCPUModelsPtr
+static int
 qemuProcessFetchCPUDefinitions(virQEMUDriverPtr driver,
                                virDomainObjPtr vm,
-                               qemuDomainAsyncJob asyncJob)
+                               qemuDomainAsyncJob asyncJob,
+                               virDomainCapsCPUModelsPtr *cpuModels)
 {
     qemuDomainObjPrivatePtr priv = vm->privateData;
     virDomainCapsCPUModelsPtr models = NULL;
+    int rc;
 
     if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
         goto error;
 
-    models = virQEMUCapsFetchCPUDefinitions(priv->mon, vm->def->os.arch);
+    rc = virQEMUCapsFetchCPUDefinitions(priv->mon, vm->def->os.arch, &models);
 
-    if (qemuDomainObjExitMonitor(driver, vm) < 0)
+    if (qemuDomainObjExitMonitor(driver, vm) < 0 || rc < 0)
         goto error;
 
-    return models;
+    *cpuModels = models;
+    return 0;
 
  error:
     virObjectUnref(models);
-    return NULL;
+    return -1;
 }
 
 
@@ -4390,7 +4393,7 @@ qemuProcessUpdateCPU(virQEMUDriverPtr driver,
     if (qemuProcessUpdateLiveGuestCPU(vm, cpu, disabled) < 0)
         goto cleanup;
 
-    if (!(models = qemuProcessFetchCPUDefinitions(driver, vm, asyncJob)) ||
+    if (qemuProcessFetchCPUDefinitions(driver, vm, asyncJob, &models) < 0 ||
         virCPUTranslate(vm->def->os.arch, vm->def->cpu, models) < 0)
         goto cleanup;
 
-- 
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