[libvirt] unable to start guest under kvm (revisited)

The problem, that I post here http://www.mail-archive.com/libvir-list@redhat.com/msg16154.html and that was solved, comes back in a different way. Consider a working kvm machine with the following description: ... <os> <type arch='x86_64' machine='pc'>hvm</type> <boot dev='hd'/> </os> ... If I delete "machine='pc'" attribute from <type>, so description becomes ... <os> <type arch='x86_64'>hvm</type> <boot dev='hd'/> </os> ... then libvirt chooses a machine='pc-0.11' value (again: qemu API version instead of kvm version) and I get virsh # start DD error: Failed to start domain DD error: internal error unable to start guest: Supported machines are: pc Standard PC (default) isapc ISA-only PC --- This problem actually occurs when using virt-manager, see https://www.redhat.com/archives/virt-tools-list/2009-October/msg00037.html

The domain/os/type element may have an arch specified without having a machine variant specified. In fact, this is what python-virtinst does when defining a guest. * docs/schemas/domain.rng: allow missing machine type --- docs/schemas/domain.rng | 86 ++++++++++++++++++++++++++++------------------- 1 files changed, 51 insertions(+), 35 deletions(-) diff --git a/docs/schemas/domain.rng b/docs/schemas/domain.rng index b1987e1..1935f15 100644 --- a/docs/schemas/domain.rng +++ b/docs/schemas/domain.rng @@ -157,53 +157,69 @@ </define> <define name="hvmx86"> <group> - <attribute name="arch"> - <choice> - <value>i686</value> - <value>x86_64</value> - </choice> - </attribute> - <attribute name="machine"> - <choice> - <value>xenfv</value> - <value>pc</value> - <value>isapc</value> - </choice> - </attribute> + <optional> + <attribute name="arch"> + <choice> + <value>i686</value> + <value>x86_64</value> + </choice> + </attribute> + </optional> + <optional> + <attribute name="machine"> + <choice> + <value>xenfv</value> + <value>pc</value> + <value>isapc</value> + </choice> + </attribute> + </optional> </group> </define> <define name="hvmmips"> <group> - <attribute name="arch"> - <value>mips</value> - </attribute> - <attribute name="machine"> - <value>mips</value> - </attribute> + <optional> + <attribute name="arch"> + <value>mips</value> + </attribute> + </optional> + <optional> + <attribute name="machine"> + <value>mips</value> + </attribute> + </optional> </group> </define> <define name="hvmsparc"> <group> - <attribute name="arch"> - <value>sparc</value> - </attribute> - <attribute name="machine"> - <value>sun4m</value> - </attribute> + <optional> + <attribute name="arch"> + <value>sparc</value> + </attribute> + </optional> + <optional> + <attribute name="machine"> + <value>sun4m</value> + </attribute> + </optional> </group> </define> <define name="hvmppc"> <group> - <attribute name="arch"> - <value>ppc</value> - </attribute> - <attribute name="machine"> - <choice> - <value>g3beige</value> - <value>mac99</value> - <value>prep</value> - </choice> - </attribute> + <optional> + <attribute name="arch"> + <value>ppc</value> + </attribute> + </optional> + <optional> + <attribute name="machine"> + <choice> + <value>g3beige</value> + <value>mac99</value> + <value>prep</value> + </choice> + </attribute> + </optional> </group> </define> <define name="osexe"> -- 1.6.2.5

On Mon, Oct 12, 2009 at 11:00:30AM +0100, Mark McLoughlin wrote:
The domain/os/type element may have an arch specified without having a machine variant specified. In fact, this is what python-virtinst does when defining a guest.
Okay, bug fix, ACK, please commit ! Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/

On Mon, Oct 12, 2009 at 11:00:30AM +0100, Mark McLoughlin wrote:
The domain/os/type element may have an arch specified without having a machine variant specified. In fact, this is what python-virtinst does when defining a guest.
* docs/schemas/domain.rng: allow missing machine type --- docs/schemas/domain.rng | 86 ++++++++++++++++++++++++++++------------------- 1 files changed, 51 insertions(+), 35 deletions(-)
diff --git a/docs/schemas/domain.rng b/docs/schemas/domain.rng index b1987e1..1935f15 100644 --- a/docs/schemas/domain.rng +++ b/docs/schemas/domain.rng @@ -157,53 +157,69 @@ </define> <define name="hvmx86"> <group> - <attribute name="arch"> - <choice> - <value>i686</value> - <value>x86_64</value> - </choice> - </attribute> - <attribute name="machine"> - <choice> - <value>xenfv</value> - <value>pc</value> - <value>isapc</value> - </choice> - </attribute> + <optional> + <attribute name="arch"> + <choice> + <value>i686</value> + <value>x86_64</value> + </choice> + </attribute> + </optional> + <optional> + <attribute name="machine"> + <choice> + <value>xenfv</value> + <value>pc</value> + <value>isapc</value> + </choice> + </attribute> + </optional> </group> </define> <define name="hvmmips"> <group> - <attribute name="arch"> - <value>mips</value> - </attribute> - <attribute name="machine"> - <value>mips</value> - </attribute> + <optional> + <attribute name="arch"> + <value>mips</value> + </attribute> + </optional> + <optional> + <attribute name="machine"> + <value>mips</value> + </attribute> + </optional> </group> </define> <define name="hvmsparc"> <group> - <attribute name="arch"> - <value>sparc</value> - </attribute> - <attribute name="machine"> - <value>sun4m</value> - </attribute> + <optional> + <attribute name="arch"> + <value>sparc</value> + </attribute> + </optional> + <optional> + <attribute name="machine"> + <value>sun4m</value> + </attribute> + </optional> </group> </define> <define name="hvmppc"> <group> - <attribute name="arch"> - <value>ppc</value> - </attribute> - <attribute name="machine"> - <choice> - <value>g3beige</value> - <value>mac99</value> - <value>prep</value> - </choice> - </attribute> + <optional> + <attribute name="arch"> + <value>ppc</value> + </attribute> + </optional> + <optional> + <attribute name="machine"> + <choice> + <value>g3beige</value> + <value>mac99</value> + <value>prep</value> + </choice> + </attribute> + </optional> </group> </define> <define name="osexe"> --
ACK Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

If one has e.g. <guest> <os_type>hvm</os_type> <arch name='x86_64'> <wordsize>64</wordsize> <emulator>/usr/bin/qemu-system-x86_64</emulator> <machine>pc-0.11</machine> <machine canonical='pc-0.11'>pc</machine> <machine>pc-0.10</machine> <machine>isapc</machine> <domain type='qemu'> </domain> <domain type='kvm'> <emulator>/usr/bin/kvm</emulator> <machine>pc</machine> <machine>isapc</machine> </domain> </arch> </guest> and start a guest with: <domain type='kvm'> ... <os> <type arch='x86_64'>hvm</type> ... </os> </domain> then the default machine type should be 'pc' and not 'pc-0.11' Issue was reported by Anton Protopopov. * src/capabilities.[ch]: pass the domain type to virCapabilitiesDefaultGuestArch() and use it to look up the default machine type from a specific guest domain if needed. * src/conf/domain_conf.c, src/xen/xm_internal.c: update * tests/qemuxml2argvdata/qemuxml2argv-machine-aliases2.xml: update the domain type to 'kvm' and remove the machine type to check that the default gets looked up correctly --- src/conf/capabilities.c | 31 ++++++++++++++++--- src/conf/capabilities.h | 3 +- src/conf/domain_conf.c | 3 +- src/xen/xm_internal.c | 3 +- .../qemuxml2argv-machine-aliases2.xml | 4 +- 5 files changed, 34 insertions(+), 10 deletions(-) diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index 38fe7fc..6ebddf5 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -549,22 +549,43 @@ virCapabilitiesDefaultGuestArch(virCapsPtr caps, * @caps: capabilities to query * @ostype: OS type to search for * @arch: architecture to search for + * @domain: domain type to search for * * Returns the first machine variant associated with - * the requested operating system type and architecture + * the requested operating system type, architecture + * and domain type */ extern const char * virCapabilitiesDefaultGuestMachine(virCapsPtr caps, const char *ostype, - const char *arch) + const char *arch, + const char *domain) { int i; + for (i = 0 ; i < caps->nguests ; i++) { - if (STREQ(caps->guests[i]->ostype, ostype) && - STREQ(caps->guests[i]->arch.name, arch) && - caps->guests[i]->arch.defaultInfo.nmachines) + virCapsGuestPtr guest = caps->guests[i]; + int j; + + if (!STREQ(guest->ostype, ostype) || !STREQ(guest->arch.name, arch)) + continue; + + for (j = 0; j < guest->arch.ndomains; j++) { + virCapsGuestDomainPtr dom= guest->arch.domains[j]; + + if (!STREQ(dom->type, domain)) + continue; + + if (!dom->info.nmachines) + break; + + return dom->info.machines[0]->name; + } + + if (guest->arch.defaultInfo.nmachines) return caps->guests[i]->arch.defaultInfo.machines[0]->name; } + return NULL; } diff --git a/src/conf/capabilities.h b/src/conf/capabilities.h index b958d95..2f24605 100644 --- a/src/conf/capabilities.h +++ b/src/conf/capabilities.h @@ -207,7 +207,8 @@ virCapabilitiesDefaultGuestArch(virCapsPtr caps, extern const char * virCapabilitiesDefaultGuestMachine(virCapsPtr caps, const char *ostype, - const char *arch); + const char *arch, + const char *domain); extern const char * virCapabilitiesDefaultGuestEmulator(virCapsPtr caps, const char *ostype, diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 87e05c2..f50a8ef 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -2669,7 +2669,8 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn, if (!def->os.machine) { const char *defaultMachine = virCapabilitiesDefaultGuestMachine(caps, def->os.type, - def->os.arch); + def->os.arch, + virDomainVirtTypeToString(def->virtType)); if (defaultMachine != NULL) { if (!(def->os.machine = strdup(defaultMachine))) { virReportOOMError(conn); diff --git a/src/xen/xm_internal.c b/src/xen/xm_internal.c index 9c78f0d..ebbaae8 100644 --- a/src/xen/xm_internal.c +++ b/src/xen/xm_internal.c @@ -720,7 +720,8 @@ xenXMDomainConfigParse(virConnectPtr conn, virConfPtr conf) { defaultMachine = virCapabilitiesDefaultGuestMachine(priv->caps, def->os.type, - def->os.arch); + def->os.arch, + virDomainVirtTypeToString(def->virtType)); if (defaultMachine != NULL) { if (!(def->os.machine = strdup(defaultMachine))) goto no_memory; diff --git a/tests/qemuxml2argvdata/qemuxml2argv-machine-aliases2.xml b/tests/qemuxml2argvdata/qemuxml2argv-machine-aliases2.xml index 6f62243..a2c6254 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-machine-aliases2.xml +++ b/tests/qemuxml2argvdata/qemuxml2argv-machine-aliases2.xml @@ -1,11 +1,11 @@ -<domain type='qemu'> +<domain type='kvm'> <name>QEMUGuest1</name> <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> <memory>219200</memory> <currentMemory>219200</currentMemory> <vcpu>1</vcpu> <os> - <type arch='x86_64' machine='pc'>hvm</type> + <type arch='x86_64'>hvm</type> <boot dev='hd'/> </os> <clock offset='utc'/> -- 1.6.2.5

On Mon, Oct 12, 2009 at 11:00:31AM +0100, Mark McLoughlin wrote:
If one has e.g.
<guest> <os_type>hvm</os_type> <arch name='x86_64'> <wordsize>64</wordsize> <emulator>/usr/bin/qemu-system-x86_64</emulator> <machine>pc-0.11</machine> <machine canonical='pc-0.11'>pc</machine> <machine>pc-0.10</machine> <machine>isapc</machine> <domain type='qemu'> </domain> <domain type='kvm'> <emulator>/usr/bin/kvm</emulator> <machine>pc</machine> <machine>isapc</machine> </domain> </arch> </guest>
and start a guest with:
<domain type='kvm'> ... <os> <type arch='x86_64'>hvm</type> ... </os> </domain>
then the default machine type should be 'pc' and not 'pc-0.11'
Okay, the patch looks strangely formatted on my screen but I assume it's just a rendering problem. The principle and code looks fine to me ACK, Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/

On Mon, Oct 12, 2009 at 11:00:31AM +0100, Mark McLoughlin wrote:
If one has e.g.
<guest> <os_type>hvm</os_type> <arch name='x86_64'> <wordsize>64</wordsize> <emulator>/usr/bin/qemu-system-x86_64</emulator> <machine>pc-0.11</machine> <machine canonical='pc-0.11'>pc</machine> <machine>pc-0.10</machine> <machine>isapc</machine> <domain type='qemu'> </domain> <domain type='kvm'> <emulator>/usr/bin/kvm</emulator> <machine>pc</machine> <machine>isapc</machine> </domain> </arch> </guest>
and start a guest with:
<domain type='kvm'> ... <os> <type arch='x86_64'>hvm</type> ... </os> </domain>
then the default machine type should be 'pc' and not 'pc-0.11'
Issue was reported by Anton Protopopov.
* src/capabilities.[ch]: pass the domain type to virCapabilitiesDefaultGuestArch() and use it to look up the default machine type from a specific guest domain if needed.
* src/conf/domain_conf.c, src/xen/xm_internal.c: update
* tests/qemuxml2argvdata/qemuxml2argv-machine-aliases2.xml: update the domain type to 'kvm' and remove the machine type to check that the default gets looked up correctly --- src/conf/capabilities.c | 31 ++++++++++++++++--- src/conf/capabilities.h | 3 +- src/conf/domain_conf.c | 3 +- src/xen/xm_internal.c | 3 +- .../qemuxml2argv-machine-aliases2.xml | 4 +- 5 files changed, 34 insertions(+), 10 deletions(-)
ACK Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
participants (4)
-
Anton Protopopov
-
Daniel P. Berrange
-
Daniel Veillard
-
Mark McLoughlin