Signed-off-by: Jiri Denemark <jdenemar(a)redhat.com>
---
Notes:
Version 2:
- fix crash with CPUs without type
src/qemu/qemu_capabilities.c | 36 ++++++++++++++++++++++++++++++++++++
src/qemu/qemu_capabilities.h | 3 +++
2 files changed, 39 insertions(+)
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 33cd3491b2..dd7ea9ae86 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -2179,6 +2179,42 @@ bool virQEMUCapsGetMachineHotplugCpus(virQEMUCapsPtr qemuCaps,
}
+const char *
+virQEMUCapsGetMachineDefaultCPU(virQEMUCapsPtr qemuCaps,
+ const char *name,
+ virDomainVirtType type)
+{
+ qemuMonitorCPUDefsPtr defs;
+ const char *cpuType = NULL;
+ size_t i;
+
+ if (type == VIR_DOMAIN_VIRT_KVM)
+ defs = qemuCaps->kvmCPUModels;
+ else
+ defs = qemuCaps->tcgCPUModels;
+
+ if (!name || !defs)
+ return NULL;
+
+ for (i = 0; i < qemuCaps->nmachineTypes; i++) {
+ if (STREQ(qemuCaps->machineTypes[i].name, name)) {
+ cpuType = qemuCaps->machineTypes[i].defaultCPU;
+ break;
+ }
+ }
+
+ if (!cpuType)
+ return NULL;
+
+ for (i = 0; i < defs->ncpus; i++) {
+ if (STREQ_NULLABLE(defs->cpus[i].type, cpuType))
+ return defs->cpus[i].name;
+ }
+
+ return NULL;
+}
+
+
/**
* virQEMUCapsSetGICCapabilities:
* @qemuCaps: QEMU capabilities
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index 923706c3bf..f5133d083d 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -607,6 +607,9 @@ int virQEMUCapsGetMachineMaxCpus(virQEMUCapsPtr qemuCaps,
const char *name);
bool virQEMUCapsGetMachineHotplugCpus(virQEMUCapsPtr qemuCaps,
const char *name);
+const char *virQEMUCapsGetMachineDefaultCPU(virQEMUCapsPtr qemuCaps,
+ const char *name,
+ virDomainVirtType type);
int virQEMUCapsGetMachineTypesCaps(virQEMUCapsPtr qemuCaps,
size_t *nmachines,
virCapsGuestMachinePtr **machines);
--
2.23.0