The function translates qemuMonitorCPUDefsPtr (used by QEMU caps probing
code) into virDomainCapsCPUModelsPtr used by domain capabilities.
Signed-off-by: Jiri Denemark <jdenemar(a)redhat.com>
---
Notes:
Version 2:
- trivial rebase
src/qemu/qemu_capabilities.c | 71 +++++++++++++++++++++---------------
1 file changed, 42 insertions(+), 29 deletions(-)
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index e38ad03ab5..87ac9bacdc 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -1887,6 +1887,41 @@ virQEMUCapsAddCPUDefinitions(virQEMUCapsPtr qemuCaps,
}
+static virDomainCapsCPUModelsPtr
+virQEMUCapsCPUDefsToModels(qemuMonitorCPUDefsPtr defs,
+ const char **modelWhitelist,
+ const char **modelBlacklist)
+{
+ VIR_AUTOUNREF(virDomainCapsCPUModelsPtr) cpuModels = NULL;
+ size_t i;
+
+ if (!(cpuModels = virDomainCapsCPUModelsNew(defs->ncpus)))
+ return NULL;
+
+ for (i = 0; i < defs->ncpus; i++) {
+ qemuMonitorCPUDefInfoPtr cpu = defs->cpus + i;
+ virDomainCapsCPUUsable usable = VIR_DOMCAPS_CPU_USABLE_UNKNOWN;
+
+ if (modelWhitelist && !virStringListHasString(modelWhitelist,
cpu->name))
+ continue;
+
+ if (modelBlacklist && virStringListHasString(modelBlacklist,
cpu->name))
+ continue;
+
+ if (cpu->usable == VIR_TRISTATE_BOOL_YES)
+ usable = VIR_DOMCAPS_CPU_USABLE_YES;
+ else if (cpu->usable == VIR_TRISTATE_BOOL_NO)
+ usable = VIR_DOMCAPS_CPU_USABLE_NO;
+
+ if (virDomainCapsCPUModelsAdd(cpuModels, cpu->name,
+ usable, cpu->blockers) < 0)
+ return NULL;
+ }
+
+ VIR_RETURN_PTR(cpuModels);
+}
+
+
virDomainCapsCPUModelsPtr
virQEMUCapsGetCPUDefinitions(virQEMUCapsPtr qemuCaps,
virDomainVirtType type,
@@ -2458,19 +2493,15 @@ virQEMUCapsFetchCPUDefinitions(qemuMonitorPtr mon,
virDomainCapsCPUModelsPtr *cpuModels)
{
VIR_AUTOPTR(qemuMonitorCPUDefs) defs = NULL;
- virDomainCapsCPUModelsPtr models = NULL;
size_t i;
- int ret = -1;
*cpuModels = NULL;
if (qemuMonitorGetCPUDefinitions(mon, &defs) < 0)
return -1;
- if (!defs) {
- ret = 0;
- goto cleanup;
- }
+ if (!defs)
+ return 0;
/* QEMU 2.11 for Power renamed all CPU models to lower case, we need to
* translate them back to libvirt's upper case model names. */
@@ -2479,7 +2510,7 @@ virQEMUCapsFetchCPUDefinitions(qemuMonitorPtr mon,
char **name;
if (virCPUGetModels(arch, &libvirtModels) < 0)
- goto cleanup;
+ return -1;
for (name = libvirtModels; name && *name; name++) {
for (i = 0; i < defs->ncpus; i++) {
@@ -2488,33 +2519,15 @@ virQEMUCapsFetchCPUDefinitions(qemuMonitorPtr mon,
VIR_FREE(defs->cpus[i].name);
if (VIR_STRDUP(defs->cpus[i].name, *name) < 0)
- goto cleanup;
+ return -1;
}
}
}
- if (!(models = virDomainCapsCPUModelsNew(defs->ncpus)))
- goto cleanup;
-
- for (i = 0; i < defs->ncpus; i++) {
- virDomainCapsCPUUsable usable = VIR_DOMCAPS_CPU_USABLE_UNKNOWN;
-
- if (defs->cpus[i].usable == VIR_TRISTATE_BOOL_YES)
- usable = VIR_DOMCAPS_CPU_USABLE_YES;
- else if (defs->cpus[i].usable == VIR_TRISTATE_BOOL_NO)
- usable = VIR_DOMCAPS_CPU_USABLE_NO;
-
- if (virDomainCapsCPUModelsAddSteal(models, &defs->cpus[i].name, usable,
- &defs->cpus[i].blockers) < 0)
- goto cleanup;
- }
-
- VIR_STEAL_PTR(*cpuModels, models);
- ret = 0;
+ if (!(*cpuModels = virQEMUCapsCPUDefsToModels(defs, NULL, NULL)))
+ return -1;
- cleanup:
- virObjectUnref(models);
- return ret;
+ return 0;
}
--
2.23.0