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>
---
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 705e3a87b0..dac3d3b633 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -1881,7 +1881,9 @@ virQEMUCapsAddCPUDefinitions(virQEMUCapsPtr qemuCaps,
virDomainCapsCPUModelsPtr
virQEMUCapsGetCPUDefinitions(virQEMUCapsPtr qemuCaps,
- virDomainVirtType type)
+ virDomainVirtType type,
+ const char **modelWhitelist,
+ const char **modelBlacklist)
{
virDomainCapsCPUModelsPtr cpuModels;
@@ -1893,6 +1895,9 @@ virQEMUCapsGetCPUDefinitions(virQEMUCapsPtr qemuCaps,
if (!cpuModels)
return NULL;
+ if (modelWhitelist || modelBlacklist)
+ return virDomainCapsCPUModelsFilter(cpuModels, modelWhitelist, modelBlacklist);
+
return virDomainCapsCPUModelsCopy(cpuModels);
}
@@ -3101,7 +3106,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;
@@ -3190,7 +3195,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 5e990ce01e..f1510f3a7b 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -564,7 +564,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);
typedef enum {
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 9e681a22b3..265e10b466 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -13780,7 +13780,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 9405bdc3f9..50f6df9dbd 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -6147,7 +6147,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 40b843dd8f..a7cac82d84 100644
--- a/tests/cputest.c
+++ b/tests/cputest.c
@@ -541,7 +541,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