263c54
From 778d5a7d8ee0f9d25e70fecf867934e9d54f6526 Mon Sep 17 00:00:00 2001
263c54
Message-Id: <778d5a7d8ee0f9d25e70fecf867934e9d54f6526@dist-git>
263c54
From: Jiri Denemark <jdenemar@redhat.com>
263c54
Date: Fri, 12 Jun 2015 14:36:51 +0200
263c54
Subject: [PATCH] qemu: Report all supported machine types in capabilities
263c54
263c54
Some machine types are only reported as canonical names for other
263c54
machine types, which make it a bit harder to find what machine types are
263c54
supported by a specific QEMU binary. Ideally, one would just use
263c54
/capabilities/guest/arch[@name='...']/machine/text() XPath to get a list
263c54
of all supported machine types, but it doesn't work right now.
263c54
263c54
For example, we report
263c54
263c54
    <machine canonical='pc-i440fx-2.3' maxCpus='255'>pc</machine>
263c54
263c54
in guest capabilities, but the corresponding
263c54
263c54
    <machine maxCpus='255'>pc-i440fx-2.3</machine>
263c54
263c54
is missing.
263c54
263c54
This is a result of QMP probing. With "-machine ?" parsing QEMU sends
263c54
us two lines:
263c54
263c54
pc                   Standard PC (i440FX + PIIX, 1996) (alias of pc-i440fx-2.3)
263c54
pc-i440fx-2.3        Standard PC (i440FX + PIIX, 1996) (default)
263c54
263c54
while query-machines QMP command reports both in the same entry:
263c54
263c54
{"name": "pc-i440fx-2.3", "is-default": true, "cpu-max": 255, "alias": "pc"}
263c54
263c54
Let's make sure we always report separate <machine/> for both the
263c54
canonical name and its alias and using the canonical name as the default
263c54
machine type (i.e., inserting it before its alias) in case is-default is
263c54
true.
263c54
263c54
https://bugzilla.redhat.com/show_bug.cgi?id=1229666
263c54
263c54
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
263c54
(cherry picked from commit beca509e437b51b68ff42494cc67919d306876ea)
263c54
263c54
https://bugzilla.redhat.com/show_bug.cgi?id=1263317
263c54
263c54
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
263c54
---
263c54
 src/qemu/qemu_capabilities.c | 38 ++++++++++++++++++++++++++++++++++++++
263c54
 1 file changed, 38 insertions(+)
263c54
263c54
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
263c54
index f827d3f..f16c1f5 100644
263c54
--- a/src/qemu/qemu_capabilities.c
263c54
+++ b/src/qemu/qemu_capabilities.c
263c54
@@ -2163,6 +2163,44 @@ int virQEMUCapsGetMachineTypesCaps(virQEMUCapsPtr qemuCaps,
263c54
         mach->maxCpus = qemuCaps->machineMaxCpus[i];
263c54
     }
263c54
 
263c54
+    /* Make sure all canonical machine types also have their own entry so that
263c54
+     * /capabilities/guest/arch[@name='...']/machine/text() XPath selects all
263c54
+     * supported machine types.
263c54
+     */
263c54
+    i = 0;
263c54
+    while (i < *nmachines) {
263c54
+        size_t j;
263c54
+        bool found = false;
263c54
+        virCapsGuestMachinePtr machine = (*machines)[i];
263c54
+
263c54
+        if (!machine->canonical) {
263c54
+            i++;
263c54
+            continue;
263c54
+        }
263c54
+
263c54
+        for (j = 0; j < *nmachines; j++) {
263c54
+            if (STREQ(machine->canonical, (*machines)[j]->name)) {
263c54
+                found = true;
263c54
+                break;
263c54
+            }
263c54
+        }
263c54
+
263c54
+        if (!found) {
263c54
+            virCapsGuestMachinePtr mach;
263c54
+            if (VIR_ALLOC(mach) < 0)
263c54
+                goto error;
263c54
+            if (VIR_INSERT_ELEMENT_COPY(*machines, i, *nmachines, mach) < 0) {
263c54
+                VIR_FREE(mach);
263c54
+                goto error;
263c54
+            }
263c54
+            if (VIR_STRDUP(mach->name, machine->canonical) < 0)
263c54
+                goto error;
263c54
+            mach->maxCpus = machine->maxCpus;
263c54
+            i++;
263c54
+        }
263c54
+        i++;
263c54
+    }
263c54
+
263c54
     return 0;
263c54
 
263c54
  error:
263c54
-- 
263c54
2.5.3
263c54