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(a)redhat.com>
Reviewed-by: Ján Tomko <jtomko(a)redhat.com>
---
Notes:
Version 2:
- no change
Version 3:
- no change
src/qemu/qemu_capabilities.c | 11 ++++++++---
src/qemu/qemu_capabilities.h | 4 +++-
src/qemu/qemu_driver.c | 2 +-
src/qemu/qemu_process.c | 2 +-
tests/cputest.c | 2 +-
5 files changed, 14 insertions(+), 7 deletions(-)
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index afac77c1e4..3d8a1c1721 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -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);
}
@@ -3129,7 +3134,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;
@@ -3218,7 +3223,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 ||
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index 10f0ce2654..67dccc522e 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -570,7 +570,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);
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 380943dda3..76787bf56a 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -13730,7 +13730,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
"
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 5bc13035a4..4c61332871 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -6124,7 +6124,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;
diff --git a/tests/cputest.c b/tests/cputest.c
index e75e8bf906..11c061e37a 100644
--- a/tests/cputest.c
+++ b/tests/cputest.c
@@ -548,7 +548,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);
--
2.23.0