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
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 a40bf99aa3..e6a7ee4f14 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -1889,7 +1889,9 @@ virQEMUCapsAddCPUDefinitions(virQEMUCapsPtr qemuCaps,
virDomainCapsCPUModelsPtr
virQEMUCapsGetCPUDefinitions(virQEMUCapsPtr qemuCaps,
- virDomainVirtType type)
+ virDomainVirtType type,
+ const char **modelWhitelist,
+ const char **modelBlacklist)
{
virDomainCapsCPUModelsPtr cpuModels;
@@ -1901,6 +1903,9 @@ virQEMUCapsGetCPUDefinitions(virQEMUCapsPtr qemuCaps,
if (!cpuModels)
return NULL;
+ if (modelWhitelist || modelBlacklist)
+ return virDomainCapsCPUModelsFilter(cpuModels, modelWhitelist, modelBlacklist);
+
return virDomainCapsCPUModelsCopy(cpuModels);
}
@@ -3142,7 +3147,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;
@@ -3231,7 +3236,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 15c69667a5..802f07fe92 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -13939,7 +13939,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 58192612b0..f37acab9e4 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -6136,7 +6136,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 3aa8fd7bf3..4428d451cf 100644
--- a/tests/cputest.c
+++ b/tests/cputest.c
@@ -550,7 +550,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