Signed-off-by: Jiri Denemark <jdenemar(a)redhat.com>
---
Notes:
Version 3:
- new patch
src/qemu/qemu_capabilities.c | 150 ++++++++++++++++++-----------------
src/qemu/qemu_capabilities.h | 3 -
2 files changed, 76 insertions(+), 77 deletions(-)
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index c66eef3e94..b9307730f1 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -831,6 +831,82 @@ virQEMUCapsInitGuest(virCapsPtr caps,
return ret;
}
+
+static int
+virQEMUCapsGetMachineTypesCaps(virQEMUCapsPtr qemuCaps,
+ size_t *nmachines,
+ virCapsGuestMachinePtr **machines)
+{
+ size_t i;
+
+ *machines = NULL;
+ *nmachines = qemuCaps->nmachineTypes;
+
+ if (*nmachines &&
+ VIR_ALLOC_N(*machines, qemuCaps->nmachineTypes) < 0)
+ goto error;
+
+ for (i = 0; i < qemuCaps->nmachineTypes; i++) {
+ virCapsGuestMachinePtr mach;
+ if (VIR_ALLOC(mach) < 0)
+ goto error;
+ (*machines)[i] = mach;
+ if (qemuCaps->machineTypes[i].alias) {
+ mach->name = g_strdup(qemuCaps->machineTypes[i].alias);
+ mach->canonical = g_strdup(qemuCaps->machineTypes[i].name);
+ } else {
+ mach->name = g_strdup(qemuCaps->machineTypes[i].name);
+ }
+ mach->maxCpus = qemuCaps->machineTypes[i].maxCpus;
+ }
+
+ /* Make sure all canonical machine types also have their own entry so that
+ * /capabilities/guest/arch[@name='...']/machine/text() XPath selects all
+ * supported machine types.
+ */
+ i = 0;
+ while (i < *nmachines) {
+ size_t j;
+ bool found = false;
+ virCapsGuestMachinePtr machine = (*machines)[i];
+
+ if (!machine->canonical) {
+ i++;
+ continue;
+ }
+
+ for (j = 0; j < *nmachines; j++) {
+ if (STREQ(machine->canonical, (*machines)[j]->name)) {
+ found = true;
+ break;
+ }
+ }
+
+ if (!found) {
+ virCapsGuestMachinePtr mach;
+ if (VIR_ALLOC(mach) < 0)
+ goto error;
+ if (VIR_INSERT_ELEMENT_COPY(*machines, i, *nmachines, mach) < 0) {
+ VIR_FREE(mach);
+ goto error;
+ }
+ mach->name = g_strdup(machine->canonical);
+ mach->maxCpus = machine->maxCpus;
+ i++;
+ }
+ i++;
+ }
+
+ return 0;
+
+ error:
+ virCapabilitiesFreeMachines(*machines, *nmachines);
+ *nmachines = 0;
+ *machines = NULL;
+ return -1;
+}
+
+
int
virQEMUCapsInitGuestFromBinary(virCapsPtr caps,
const char *binary,
@@ -2022,80 +2098,6 @@ virQEMUCapsIsCPUModeSupported(virQEMUCapsPtr qemuCaps,
}
-int virQEMUCapsGetMachineTypesCaps(virQEMUCapsPtr qemuCaps,
- size_t *nmachines,
- virCapsGuestMachinePtr **machines)
-{
- size_t i;
-
- *machines = NULL;
- *nmachines = qemuCaps->nmachineTypes;
-
- if (*nmachines &&
- VIR_ALLOC_N(*machines, qemuCaps->nmachineTypes) < 0)
- goto error;
-
- for (i = 0; i < qemuCaps->nmachineTypes; i++) {
- virCapsGuestMachinePtr mach;
- if (VIR_ALLOC(mach) < 0)
- goto error;
- (*machines)[i] = mach;
- if (qemuCaps->machineTypes[i].alias) {
- mach->name = g_strdup(qemuCaps->machineTypes[i].alias);
- mach->canonical = g_strdup(qemuCaps->machineTypes[i].name);
- } else {
- mach->name = g_strdup(qemuCaps->machineTypes[i].name);
- }
- mach->maxCpus = qemuCaps->machineTypes[i].maxCpus;
- }
-
- /* Make sure all canonical machine types also have their own entry so that
- * /capabilities/guest/arch[@name='...']/machine/text() XPath selects all
- * supported machine types.
- */
- i = 0;
- while (i < *nmachines) {
- size_t j;
- bool found = false;
- virCapsGuestMachinePtr machine = (*machines)[i];
-
- if (!machine->canonical) {
- i++;
- continue;
- }
-
- for (j = 0; j < *nmachines; j++) {
- if (STREQ(machine->canonical, (*machines)[j]->name)) {
- found = true;
- break;
- }
- }
-
- if (!found) {
- virCapsGuestMachinePtr mach;
- if (VIR_ALLOC(mach) < 0)
- goto error;
- if (VIR_INSERT_ELEMENT_COPY(*machines, i, *nmachines, mach) < 0) {
- VIR_FREE(mach);
- goto error;
- }
- mach->name = g_strdup(machine->canonical);
- mach->maxCpus = machine->maxCpus;
- i++;
- }
- i++;
- }
-
- return 0;
-
- error:
- virCapabilitiesFreeMachines(*machines, *nmachines);
- *nmachines = 0;
- *machines = NULL;
- return -1;
-}
-
-
/**
* virQEMUCapsGetCanonicalMachine:
* @qemuCaps: qemu capabilities object
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index f43e56a9ca..ee779d90ed 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -606,9 +606,6 @@ int virQEMUCapsGetMachineMaxCpus(virQEMUCapsPtr qemuCaps,
const char *name);
bool virQEMUCapsGetMachineHotplugCpus(virQEMUCapsPtr qemuCaps,
const char *name);
-int virQEMUCapsGetMachineTypesCaps(virQEMUCapsPtr qemuCaps,
- size_t *nmachines,
- virCapsGuestMachinePtr **machines);
void virQEMUCapsFilterByMachineType(virQEMUCapsPtr qemuCaps,
const char *machineType);
--
2.23.0