[libvirt] [PATCH v2 8/8] qemu_driver: hook up query-cpu-model-comparison
Daniel Henrique Barboza
danielhb413 at gmail.com
Mon Apr 29 20:22:55 UTC 2019
On 4/26/19 5:22 PM, walling at linux.ibm.com wrote:
> From: Collin Walling <walling at linux.ibm.com>
>
> This command is hooked into the virsh hypervisor-cpu-compare command.
> As such, the CPU model XML provided to the command will be compared
> to the hypervisor CPU contained in the QEMU capabilities file for the
> appropriate QEMU binary (for s390x, this CPU definition can be observed
> via virsh domcapabilities).
>
> s390x can report that the first model (A) is a subset of the second
> (B). If A is the hypervisor CPU and a subset of B (the CPU contained
> in the XML), then B would not be able to run on this machine and thus
> we will report that CPU model B is incompatible.
>
> Signed-off-by: Collin Walling <walling at linux.ibm.com>
> Tested-by: Daniel Henrique Barboza <danielhb413 at gmail.com>
> ---
Reviewed-by: Daniel Henrique Barboza <danielh413 at gmail.com>
> src/qemu/qemu_capabilities.c | 48 ++++++++++++++++++++++++++++++++++++++++++++
> src/qemu/qemu_capabilities.h | 9 +++++++++
> src/qemu/qemu_driver.c | 10 +++++++++
> 3 files changed, 67 insertions(+)
>
> diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
> index 374a7c1..bd8c7a1 100644
> --- a/src/qemu/qemu_capabilities.c
> +++ b/src/qemu/qemu_capabilities.c
> @@ -5508,3 +5508,51 @@ virQEMUCapsCPUModelBaseline(virQEMUCapsPtr qemuCaps,
> virCPUDefFree(cpu);
> return baseline;
> }
> +
> +virCPUCompareResult
> +virQEMUCapsCPUModelComparison(virQEMUCapsPtr qemuCaps,
> + const char *libDir,
> + uid_t runUid,
> + gid_t runGid,
> + virCPUDefPtr cpu_a,
> + virCPUDefPtr cpu_b,
> + bool failIncompatible)
> +{
> + qemuProcessQMPPtr proc = NULL;
> + qemuMonitorCPUModelInfoPtr result;
> + int ret = -1;
> +
> + if (!(proc = qemuProcessQMPNew(qemuCaps->binary, libDir,
> + runUid, runGid, false)))
> + goto cleanup;
> +
> + if (qemuProcessQMPStart(proc) < 0)
> + goto cleanup;
> +
> + if (qemuMonitorGetCPUModelComparison(proc->mon, cpu_a->model,
> + cpu_a->nfeatures, cpu_a->features,
> + cpu_b->model, cpu_b->nfeatures,
> + cpu_b->features, &result) < 0)
> + goto cleanup;
> +
> + if (STREQ(result->name, "incompatible") ||
> + STREQ(result->name, "subset"))
> + ret = VIR_CPU_COMPARE_INCOMPATIBLE;
> + else if (STREQ(result->name, "identical"))
> + ret = VIR_CPU_COMPARE_IDENTICAL;
> + else if (STREQ(result->name, "superset"))
> + ret = VIR_CPU_COMPARE_SUPERSET;
> +
> + if (failIncompatible && ret == VIR_CPU_COMPARE_INCOMPATIBLE) {
> + ret = VIR_CPU_COMPARE_ERROR;
> + virReportError(VIR_ERR_CPU_INCOMPATIBLE, NULL);
> + }
> +
> + cleanup:
> + if (ret < 0)
> + virQEMUCapsLogProbeFailure(qemuCaps->binary);
> +
> + qemuMonitorCPUModelInfoFree(result);
> + qemuProcessQMPFree(proc);
> + return ret;
> +}
> diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
> index 47612e9..01aecc0 100644
> --- a/src/qemu/qemu_capabilities.h
> +++ b/src/qemu/qemu_capabilities.h
> @@ -658,4 +658,13 @@ virCPUDefPtr virQEMUCapsCPUModelBaseline(virQEMUCapsPtr qemuCaps,
> int ncpus,
> virCPUDefPtr *cpus);
>
> +virCPUCompareResult
> +virQEMUCapsCPUModelComparison(virQEMUCapsPtr qemuCaps,
> + const char *libDir,
> + uid_t runUid,
> + gid_t runGid,
> + virCPUDefPtr cpu_a,
> + virCPUDefPtr cpu_b,
> + bool failIncompatible);
> +
> #endif /* LIBVIRT_QEMU_CAPABILITIES_H */
> diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
> index e1e1fea..fdf8a53 100644
> --- a/src/qemu/qemu_driver.c
> +++ b/src/qemu/qemu_driver.c
> @@ -13469,9 +13469,11 @@ qemuConnectCompareHypervisorCPU(virConnectPtr conn,
> {
> int ret = VIR_CPU_COMPARE_ERROR;
> virQEMUDriverPtr driver = conn->privateData;
> + virQEMUDriverConfigPtr config = driver->config;
> virQEMUCapsPtr qemuCaps = NULL;
> bool failIncompatible;
> virCPUDefPtr hvCPU;
> + virCPUDefPtr cpu;
> virArch arch;
> virDomainVirtType virttype;
>
> @@ -13506,6 +13508,14 @@ qemuConnectCompareHypervisorCPU(virConnectPtr conn,
>
> if (ARCH_IS_X86(arch)) {
> ret = virCPUCompareXML(arch, hvCPU, xmlCPU, failIncompatible);
> + } else if (ARCH_IS_S390(arch) &&
> + virQEMUCapsGet(qemuCaps, QEMU_CAPS_QUERY_CPU_MODEL_COMPARISON)) {
> + if (virCPUDefParseXMLHelper(xmlCPU, NULL, VIR_CPU_TYPE_AUTO, &cpu) < 0)
> + goto cleanup;
> +
> + ret = virQEMUCapsCPUModelComparison(qemuCaps, config->libDir,
> + config->user, config->group,
> + hvCPU, cpu, failIncompatible);
> } else {
> virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
> _("comparing with the hypervisor CPU is not supported "
More information about the libvir-list
mailing list