qemu: Filter models in virQEMUCapsGetCPUDefinitions

Some callers of virQEMUCapsGetCPUDefinitions will need to filter the
returned list of CPU models. Let's add the filtering parameters directly
to virQEMUCapsGetCPUDefinitions to avoid copying the CPU models list
twice.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Jiri Denemark 2019-09-20 22:48:13 +02:00
parent e20a11eecf
commit 4d74990143
5 changed files with 14 additions and 7 deletions

View File

@ -1883,7 +1883,9 @@ virQEMUCapsAddCPUDefinitions(virQEMUCapsPtr qemuCaps,
virDomainCapsCPUModelsPtr
virQEMUCapsGetCPUDefinitions(virQEMUCapsPtr qemuCaps,
virDomainVirtType type)
virDomainVirtType type,
const char **modelWhitelist,
const char **modelBlacklist)
{
virDomainCapsCPUModelsPtr cpuModels;
@ -1895,6 +1897,9 @@ virQEMUCapsGetCPUDefinitions(virQEMUCapsPtr qemuCaps,
if (!cpuModels)
return NULL;
if (modelWhitelist || modelBlacklist)
return virDomainCapsCPUModelsFilter(cpuModels, modelWhitelist, modelBlacklist);
return virDomainCapsCPUModelsCopy(cpuModels);
}
@ -3132,7 +3137,7 @@ virQEMUCapsInitCPUModelX86(virQEMUCapsPtr qemuCaps,
if (!(data = virQEMUCapsGetCPUModelX86Data(qemuCaps, model, migratable)))
goto cleanup;
cpuModels = virQEMUCapsGetCPUDefinitions(qemuCaps, type);
cpuModels = virQEMUCapsGetCPUDefinitions(qemuCaps, type, NULL, NULL);
if (cpuDecode(cpu, data, cpuModels) < 0)
goto cleanup;
@ -3221,7 +3226,7 @@ virQEMUCapsInitHostCPUModel(virQEMUCapsPtr qemuCaps,
VIR_DEBUG("No host CPU model info from QEMU; probing host CPU directly");
cpuModels = virQEMUCapsGetCPUDefinitions(qemuCaps, type);
cpuModels = virQEMUCapsGetCPUDefinitions(qemuCaps, type, NULL, NULL);
hostCPU = virQEMUCapsProbeHostCPU(hostArch, cpuModels);
if (!hostCPU ||

View File

@ -573,7 +573,9 @@ int virQEMUCapsAddCPUDefinitions(virQEMUCapsPtr qemuCaps,
size_t count,
virDomainCapsCPUUsable usable);
virDomainCapsCPUModelsPtr virQEMUCapsGetCPUDefinitions(virQEMUCapsPtr qemuCaps,
virDomainVirtType type);
virDomainVirtType type,
const char **modelWhitelist,
const char **modelBlacklist);
virDomainCapsCPUModelsPtr virQEMUCapsFetchCPUDefinitions(qemuMonitorPtr mon,
virArch arch);

View File

@ -13710,7 +13710,7 @@ qemuConnectBaselineHypervisorCPU(virConnectPtr conn,
if (!qemuCaps)
goto cleanup;
if (!(cpuModels = virQEMUCapsGetCPUDefinitions(qemuCaps, virttype)) ||
if (!(cpuModels = virQEMUCapsGetCPUDefinitions(qemuCaps, virttype, NULL, NULL)) ||
cpuModels->nmodels == 0) {
virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
_("QEMU '%s' does not support any CPU models for "

View File

@ -6054,7 +6054,7 @@ qemuProcessUpdateGuestCPU(virDomainDefPtr def,
VIR_QEMU_CAPS_HOST_CPU_MIGRATABLE)) < 0)
return -1;
cpuModels = virQEMUCapsGetCPUDefinitions(qemuCaps, def->virtType);
cpuModels = virQEMUCapsGetCPUDefinitions(qemuCaps, def->virtType, NULL, NULL);
if (virCPUTranslate(def->os.arch, def->cpu, cpuModels) < 0)
return -1;

View File

@ -542,7 +542,7 @@ cpuTestGetCPUModels(const struct data *data,
if (!(qemuCaps = cpuTestMakeQEMUCaps(data)))
return -1;
*models = virQEMUCapsGetCPUDefinitions(qemuCaps, VIR_DOMAIN_VIRT_KVM);
*models = virQEMUCapsGetCPUDefinitions(qemuCaps, VIR_DOMAIN_VIRT_KVM, NULL, NULL);
virObjectUnref(qemuCaps);