mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 06:05:27 +00:00
qemu: Change return type of virQEMUCapsFetchCPUDefinitions
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@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
fb35cbb329
commit
a94f67ee69
@ -2441,17 +2441,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. */
|
||||
@ -2460,7 +2469,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++) {
|
||||
@ -2474,7 +2483,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;
|
||||
@ -2486,19 +2495,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;
|
||||
}
|
||||
|
||||
|
||||
@ -2512,7 +2520,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))
|
||||
|
@ -576,8 +576,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. */
|
||||
|
@ -4328,27 +4328,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;
|
||||
}
|
||||
|
||||
|
||||
@ -4373,7 +4376,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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user