[libvirt] [PATCH] qemu: Report all supported machine types in capabilities

Some machine types are only reported as canonical names for other machine types, which make it a bit harder to find what machine types are supported by a specific QEMU binary. Ideally, one would just use /capabilities/guest/arch[@name='...']/machine/text() XPath to get a list of all supported machine types, but it doesn't work right now. For example, we report <machine canonical='pc-i440fx-2.3' maxCpus='255'>pc</machine> in guest capabilities, but the corresponding <machine maxCpus='255'>pc-i440fx-2.3</machine> is missing. This is a result of QMP probing. With "-machine ?" parsing QEMU sends us two lines: pc Standard PC (i440FX + PIIX, 1996) (alias of pc-i440fx-2.3) pc-i440fx-2.3 Standard PC (i440FX + PIIX, 1996) (default) while query-machines QMP command reports both in the same entry: {"name": "pc-i440fx-2.3", "is-default": true, "cpu-max": 255, "alias": "pc"} Let's make sure we always report separate <machine/> for both the canonical name and its alias and using the canonical name as the default machine type (i.e., inserting it before its alias) in case is-default is true. https://bugzilla.redhat.com/show_bug.cgi?id=1229666 Signed-off-by: Jiri Denemark <jdenemar@redhat.com> --- src/qemu/qemu_capabilities.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index ca7a7c2..e9b3bb5 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -2223,6 +2223,44 @@ int virQEMUCapsGetMachineTypesCaps(virQEMUCapsPtr qemuCaps, mach->maxCpus = qemuCaps->machineMaxCpus[i]; } + /* 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; + } + if (VIR_STRDUP(mach->name, machine->canonical) < 0) + goto error; + mach->maxCpus = machine->maxCpus; + i++; + } + i++; + } + return 0; error: -- 2.4.3

On 06/12/2015 08:53 AM, Jiri Denemark wrote:
Some machine types are only reported as canonical names for other machine types, which make it a bit harder to find what machine types are supported by a specific QEMU binary. Ideally, one would just use /capabilities/guest/arch[@name='...']/machine/text() XPath to get a list of all supported machine types, but it doesn't work right now.
For example, we report
<machine canonical='pc-i440fx-2.3' maxCpus='255'>pc</machine>
in guest capabilities, but the corresponding
<machine maxCpus='255'>pc-i440fx-2.3</machine>
is missing.
This is a result of QMP probing. With "-machine ?" parsing QEMU sends us two lines:
pc Standard PC (i440FX + PIIX, 1996) (alias of pc-i440fx-2.3) pc-i440fx-2.3 Standard PC (i440FX + PIIX, 1996) (default)
while query-machines QMP command reports both in the same entry:
{"name": "pc-i440fx-2.3", "is-default": true, "cpu-max": 255, "alias": "pc"}
Let's make sure we always report separate <machine/> for both the canonical name and its alias and using the canonical name as the default machine type (i.e., inserting it before its alias) in case is-default is true.
https://bugzilla.redhat.com/show_bug.cgi?id=1229666
Signed-off-by: Jiri Denemark <jdenemar@redhat.com> --- src/qemu/qemu_capabilities.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+)
There's no existing test for this? I guess I would have expected to see differences in output and thus test adjustments as well. The code seems to be doing what is stated though... and the tests/capabilityschemadata/caps-qemu-kvm.xml seems to show the output as desired. ACK - John
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index ca7a7c2..e9b3bb5 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -2223,6 +2223,44 @@ int virQEMUCapsGetMachineTypesCaps(virQEMUCapsPtr qemuCaps, mach->maxCpus = qemuCaps->machineMaxCpus[i]; }
+ /* 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; + } + if (VIR_STRDUP(mach->name, machine->canonical) < 0) + goto error; + mach->maxCpus = machine->maxCpus; + i++; + } + i++; + } + return 0;
error:

On Wed, Jun 17, 2015 at 14:18:23 -0400, John Ferlan wrote:
On 06/12/2015 08:53 AM, Jiri Denemark wrote:
Some machine types are only reported as canonical names for other machine types, which make it a bit harder to find what machine types are supported by a specific QEMU binary. Ideally, one would just use /capabilities/guest/arch[@name='...']/machine/text() XPath to get a list of all supported machine types, but it doesn't work right now.
For example, we report
<machine canonical='pc-i440fx-2.3' maxCpus='255'>pc</machine>
in guest capabilities, but the corresponding
<machine maxCpus='255'>pc-i440fx-2.3</machine>
is missing.
This is a result of QMP probing. With "-machine ?" parsing QEMU sends us two lines:
pc Standard PC (i440FX + PIIX, 1996) (alias of pc-i440fx-2.3) pc-i440fx-2.3 Standard PC (i440FX + PIIX, 1996) (default)
while query-machines QMP command reports both in the same entry:
{"name": "pc-i440fx-2.3", "is-default": true, "cpu-max": 255, "alias": "pc"}
Let's make sure we always report separate <machine/> for both the canonical name and its alias and using the canonical name as the default machine type (i.e., inserting it before its alias) in case is-default is true.
https://bugzilla.redhat.com/show_bug.cgi?id=1229666
Signed-off-by: Jiri Denemark <jdenemar@redhat.com> --- src/qemu/qemu_capabilities.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+)
There's no existing test for this? I guess I would have expected to see differences in output and thus test adjustments as well.
The code seems to be doing what is stated though... and the tests/capabilityschemadata/caps-qemu-kvm.xml seems to show the output as desired.
ACK -
Pushed, thanks. Jirka
participants (2)
-
Jiri Denemark
-
John Ferlan