Signed-off-by: Jiri Denemark <jdenemar(a)redhat.com>
Reviewed-by: Ján Tomko <jtomko(a)redhat.com>
---
Notes:
Version 2:
- fix crash with CPUs without type
Version 3:
- no change
src/qemu/qemu_capabilities.c | 32 ++++++++++++++++++++++++++++++++
src/qemu/qemu_capabilities.h | 3 +++
2 files changed, 35 insertions(+)
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index dc2723d025..9829860d4d 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -2195,6 +2195,38 @@ virQEMUCapsGetMachineHotplugCpus(virQEMUCapsPtr qemuCaps,
}
+const char *
+virQEMUCapsGetMachineDefaultCPU(virQEMUCapsPtr qemuCaps,
+ const char *name,
+ virDomainVirtType type)
+{
+ virQEMUCapsAccelPtr accel = virQEMUCapsGetAccel(qemuCaps, type);
+ qemuMonitorCPUDefsPtr defs = accel->cpuModels;
+ const char *cpuType = NULL;
+ size_t i;
+
+ if (!name || !defs)
+ return NULL;
+
+ for (i = 0; i < accel->nmachineTypes; i++) {
+ if (STREQ(accel->machineTypes[i].name, name)) {
+ cpuType = accel->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 bc43b99579..f063d95048 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -609,6 +609,9 @@ int virQEMUCapsGetMachineMaxCpus(virQEMUCapsPtr qemuCaps,
bool virQEMUCapsGetMachineHotplugCpus(virQEMUCapsPtr qemuCaps,
virDomainVirtType virtType,
const char *name);
+const char *virQEMUCapsGetMachineDefaultCPU(virQEMUCapsPtr qemuCaps,
+ const char *name,
+ virDomainVirtType type);
void virQEMUCapsFilterByMachineType(virQEMUCapsPtr qemuCaps,
virDomainVirtType virtType,
--
2.23.0