
On Thu, Sep 24, 2020 at 20:22:38 -0400, Collin Walling wrote:
Check the provided CPU models against the CPU models known by the hypervisor before baselining and print an error if an unrecognized model is found.
Signed-off-by: Collin Walling <walling@linux.ibm.com> --- src/qemu/qemu_driver.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 1c5b1dcfee..fe572b13e1 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -12453,12 +12453,13 @@ qemuConnectCPUModelBaseline(virQEMUCapsPtr qemuCaps, gid_t runGid, bool expand_features, virCPUDefPtr *cpus, - int ncpus) + int ncpus, + virDomainCapsCPUModelsPtr cpuModels) { g_autoptr(qemuProcessQMP) proc = NULL; g_autoptr(virCPUDef) baseline = NULL; qemuMonitorCPUModelInfoPtr result = NULL; - size_t i; + size_t i, j;
for (i = 0; i < ncpus; i++) { if (!cpus[i]) { @@ -12471,6 +12472,16 @@ qemuConnectCPUModelBaseline(virQEMUCapsPtr qemuCaps, _("no CPU model specified at index %zu"), i); return NULL; } + for (j = 0; j < cpuModels->nmodels; j++) { + if (STREQ(cpus[i]->model, cpuModels->models[j].name)) + break; + } + if (j == cpuModels->nmodels) {
You can use an existing internal API instead: if (!virDomainCapsCPUModelsGet(cpuModels, cpus[i]->model)) {
+ virReportError(VIR_ERR_INVALID_ARG, + _("CPU model '%s' not supported by hypervisor"), + cpus[i]->model); + return NULL; + } }
if (!(proc = qemuProcessQMPNew(virQEMUCapsGetBinary(qemuCaps),
Jirka