If a given CPU model is supported by the hypervisor, we want to know more about it, e.g., what features may block its usage on the current host and such details are stored in the virDomainCapsCPUModelsPtr list which virCPUModelIsAllowed uses to check whether the CPU model is supported. Thus if the CPU model is found in the list we can directly return a pointer to the corresponding virDomainCapsCPUModel if the caller needs to look at the details. Signed-off-by: Jiri Denemark <jdenemar@xxxxxxxxxx> --- src/cpu/cpu.c | 18 ++++++++++++++---- src/cpu/cpu.h | 3 ++- src/cpu/cpu_ppc64.c | 2 +- src/cpu/cpu_x86.c | 2 +- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c index b815ed383a..48290a471b 100644 --- a/src/cpu/cpu.c +++ b/src/cpu/cpu.c @@ -819,24 +819,34 @@ virCPUDataParse(const char *xmlStr) * * @model: CPU model to be checked * @models: list of supported CPU models + * @hvModel: pointer to matching model from @models will be returned here * * Checks whether @model can be found in the list of supported @models. - * If @models is NULL, all models are supported. + * If @models is NULL, all models are supported. If both @models and @hvModel + * are non-NULL and @model is found in the list of supported models, @hvModel + * will be filled with the pointer to the matching CPU model from @models. * * Returns true if @model is supported, false otherwise. */ bool virCPUModelIsAllowed(const char *model, - virDomainCapsCPUModelsPtr models) + virDomainCapsCPUModelsPtr models, + virDomainCapsCPUModelPtr *hvModel) { size_t i; + if (hvModel) + *hvModel = NULL; + if (!models) return true; for (i = 0; i < models->nmodels; i++) { - if (STREQ(models->models[i].name, model)) + if (STREQ(models->models[i].name, model)) { + if (hvModel) + *hvModel = models->models + i; return true; + } } return false; } @@ -908,7 +918,7 @@ virCPUTranslate(virArch arch, cpu->mode == VIR_CPU_MODE_HOST_PASSTHROUGH) return 0; - if (virCPUModelIsAllowed(cpu->model, models)) + if (virCPUModelIsAllowed(cpu->model, models, NULL)) return 0; if (cpu->fallback != VIR_CPU_FALLBACK_ALLOW) { diff --git a/src/cpu/cpu.h b/src/cpu/cpu.h index 83d5bcb63f..2d81927a0b 100644 --- a/src/cpu/cpu.h +++ b/src/cpu/cpu.h @@ -227,7 +227,8 @@ virCPUDataCheckFeature(const virCPUData *data, bool virCPUModelIsAllowed(const char *model, - virDomainCapsCPUModelsPtr models) + virDomainCapsCPUModelsPtr models, + virDomainCapsCPUModelPtr *hvModel) ATTRIBUTE_NONNULL(1); int diff --git a/src/cpu/cpu_ppc64.c b/src/cpu/cpu_ppc64.c index 7eb27c59bd..9f990a3fb5 100644 --- a/src/cpu/cpu_ppc64.c +++ b/src/cpu/cpu_ppc64.c @@ -679,7 +679,7 @@ ppc64DriverDecode(virCPUDefPtr cpu, goto cleanup; } - if (!virCPUModelIsAllowed(model->name, models)) { + if (!virCPUModelIsAllowed(model->name, models, NULL)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("CPU model %s is not supported by hypervisor"), model->name); diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c index 84ec878d1b..198e80a5c2 100644 --- a/src/cpu/cpu_x86.c +++ b/src/cpu/cpu_x86.c @@ -1854,7 +1854,7 @@ x86Decode(virCPUDefPtr cpu, */ for (i = map->nmodels - 1; i >= 0; i--) { candidate = map->models[i]; - if (!virCPUModelIsAllowed(candidate->name, models)) { + if (!virCPUModelIsAllowed(candidate->name, models, NULL)) { if (preferred && STREQ(candidate->name, preferred)) { if (cpu->fallback != VIR_CPU_FALLBACK_ALLOW) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, -- 2.14.2 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list