When executing the hypervisor-cpu-compare/baseline commands and the XML file contains a CPU definition using host-passthrough and no model name, the commands will fail and return an error message from the QMP response. Let's fix this by checking for host-passthrough and a missing model name after the CPU definition has been converted from XML. If these conditions are matched, then the CPU definition's model name will be set to "host". Signed-off-by: Collin Walling <walling@xxxxxxxxxxxxx> --- src/qemu/qemu_driver.c | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 1cecef01f7..427d2419f3 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -12281,6 +12281,26 @@ qemuConnectCPUModelComparison(virQEMUCapsPtr qemuCaps, } +static int +qemuConnectCheckCPUModel(virCPUDefPtr cpu) +{ + if (!cpu->model) { + /* + * On some architectures a model name is never present + * for the host-passthrough mode, so default it to "host" + */ + if (cpu->mode == VIR_CPU_MODE_HOST_PASSTHROUGH) { + cpu->model = g_strdup("host"); + } else { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("cpu parameter is missing a model name")); + return -1; + } + } + return 0; +} + + static int qemuConnectCompareHypervisorCPU(virConnectPtr conn, const char *emulator, @@ -12336,15 +12356,9 @@ qemuConnectCompareHypervisorCPU(virConnectPtr conn, if (virCPUDefParseXMLString(xmlCPU, VIR_CPU_TYPE_AUTO, &cpu) < 0) goto cleanup; - if (!cpu->model) { - if (cpu->mode == VIR_CPU_MODE_HOST_PASSTHROUGH) { - cpu->model = g_strdup("host"); - } else { - virReportError(VIR_ERR_INVALID_ARG, "%s", - _("cpu parameter is missing a model name")); - goto cleanup; - } - } + if (qemuConnectCheckCPUModel(cpu) < 0) + goto cleanup; + ret = qemuConnectCPUModelComparison(qemuCaps, cfg->libDir, cfg->user, cfg->group, hvCPU, cpu, failIncompatible); @@ -12470,10 +12484,17 @@ qemuConnectCPUModelBaseline(virQEMUCapsPtr qemuCaps, if (VIR_ALLOC(baseline) < 0) return NULL; - if (virCPUDefCopyModel(baseline, cpus[0], false)) + if (qemuConnectCheckCPUModel(cpus[0]) < 0) + return NULL; + + if (virCPUDefCopyModel(baseline, cpus[0], false) < 0) return NULL; for (i = 1; i < ncpus; i++) { + + if (qemuConnectCheckCPUModel(cpus[i]) < 0) + return NULL; + if (qemuMonitorGetCPUModelBaseline(proc->mon, baseline, cpus[i], &result) < 0) return NULL; -- 2.26.2