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(a)redhat.com>
---
Notes:
Version 2:
- new patch
src/qemu/qemu_capabilities.c | 34 +++++++++++++++++++++-------------
src/qemu/qemu_capabilities.h | 5 +++--
src/qemu/qemu_process.c | 17 ++++++++++-------
3 files changed, 34 insertions(+), 22 deletions(-)
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index b608eb1a43..6fa5e06edb 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -2452,17 +2452,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. */
@@ -2471,7 +2480,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++) {
@@ -2480,13 +2489,13 @@ virQEMUCapsFetchCPUDefinitions(qemuMonitorPtr mon,
VIR_FREE(cpus[i]->name);
if (VIR_STRDUP(cpus[i]->name, *name) < 0)
- goto error;
+ goto cleanup;
}
}
}
if (!(models = virDomainCapsCPUModelsNew(ncpus)))
- goto error;
+ goto cleanup;
for (i = 0; i < ncpus; i++) {
virDomainCapsCPUUsable usable = VIR_DOMCAPS_CPU_USABLE_UNKNOWN;
@@ -2498,19 +2507,18 @@ virQEMUCapsFetchCPUDefinitions(qemuMonitorPtr mon,
if (virDomainCapsCPUModelsAddSteal(models, &cpus[i]->name, usable,
&cpus[i]->blockers) < 0)
- goto error;
+ goto cleanup;
}
+ VIR_STEAL_PTR(*cpuModels, 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;
}
@@ -2524,7 +2532,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 f37acab9e4..93fe994f8e 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -4353,27 +4353,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;
}
@@ -4398,7 +4401,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