[libvirt] Improve heuristic for default guest architecture

In libvirt 0.6.1, if you create a domain description of type 'kvm' without an arch set on an x86-64 host, you would get an i686 qemu guest rather than the expected x86-64 kvm guest. This is because virCapabilitiesDefaultGuestArch doesn't take the domain type into consideration, so it just returned the first hvm architecutre that has been registered, which is i686. After applying Dan P's patch, http://www.redhat.com/archives/libvir-list/2009-March/msg00281.html, I now get a i686 kvm guest, since kvm now can do i686 guests from libvirt. This is certainly an improvement, but I think a more reasonable default is to attempt to match the host's architecture. This patch makes virCapabilitiesDefaultGuestArch also check the domain type, and also gives preference to a guest architecture that matches the host's architecture. Index: libvirt-0.6.1/src/capabilities.c =================================================================== --- libvirt-0.6.1.orig/src/capabilities.c 2009-03-19 15:18:09.483317579 +0100 +++ libvirt-0.6.1/src/capabilities.c 2009-03-19 15:42:31.027341187 +0100 @@ -468,14 +468,26 @@ */ extern const char * virCapabilitiesDefaultGuestArch(virCapsPtr caps, - const char *ostype) + const char *ostype, + const char *domain) { - int i; + int i, j; + const char *arch = NULL; for (i = 0 ; i < caps->nguests ; i++) { - if (STREQ(caps->guests[i]->ostype, ostype)) - return caps->guests[i]->arch.name; + if (STREQ(caps->guests[i]->ostype, ostype)) { + for (j = 0 ; j < caps->guests[i]->arch.ndomains ; j++) { + if (STREQ(caps->guests[i]->arch.domains[j]->type, domain)) { + /* Use the first match... */ + if (!arch) + arch = caps->guests[i]->arch.name; + /* ...unless we can match the host's architecture. */ + if (STREQ(caps->guests[i]->arch.name, caps->host.arch)) + return caps->guests[i]->arch.name; + } + } + } } - return NULL; + return arch; } /** Index: libvirt-0.6.1/src/capabilities.h =================================================================== --- libvirt-0.6.1.orig/src/capabilities.h 2009-03-19 15:18:09.507338228 +0100 +++ libvirt-0.6.1/src/capabilities.h 2009-03-19 15:42:31.027341187 +0100 @@ -177,7 +177,8 @@ extern const char * virCapabilitiesDefaultGuestArch(virCapsPtr caps, - const char *ostype); + const char *ostype, + const char *domain); extern const char * virCapabilitiesDefaultGuestMachine(virCapsPtr caps, const char *ostype, Index: libvirt-0.6.1/src/domain_conf.c =================================================================== --- libvirt-0.6.1.orig/src/domain_conf.c 2009-03-19 15:18:09.531341976 +0100 +++ libvirt-0.6.1/src/domain_conf.c 2009-03-19 15:42:31.031345327 +0100 @@ -2146,7 +2146,7 @@ goto error; } } else { - const char *defaultArch = virCapabilitiesDefaultGuestArch(caps, def->os.type); + const char *defaultArch = virCapabilitiesDefaultGuestArch(caps, def->os.type, virDomainVirtTypeToString(def->virtType)); if (defaultArch == NULL) { virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR, _("no supported architecture for os type '%s'"), Index: libvirt-0.6.1/src/xm_internal.c =================================================================== --- libvirt-0.6.1.orig/src/xm_internal.c 2009-03-19 15:18:09.559316828 +0100 +++ libvirt-0.6.1/src/xm_internal.c 2009-03-19 15:42:45.807318313 +0100 @@ -695,7 +695,7 @@ if (!(def->os.type = strdup(hvm ? "hvm" : "xen"))) goto no_memory; - defaultArch = virCapabilitiesDefaultGuestArch(priv->caps, def->os.type); + defaultArch = virCapabilitiesDefaultGuestArch(priv->caps, def->os.type, virDomainVirtTypeToString(def->virtType)); if (defaultArch == NULL) { xenXMError(conn, VIR_ERR_INTERNAL_ERROR, _("no supported architecture for os type '%s'"), -- Soren Hansen | Lead Virtualisation Engineer | Ubuntu Server Team Canonical Ltd. | http://www.ubuntu.com/

On Fri, Mar 20, 2009 at 03:34:44PM +0100, Soren Hansen wrote:
In libvirt 0.6.1, if you create a domain description of type 'kvm' without an arch set on an x86-64 host, you would get an i686 qemu guest rather than the expected x86-64 kvm guest.
This is because virCapabilitiesDefaultGuestArch doesn't take the domain type into consideration, so it just returned the first hvm architecutre that has been registered, which is i686.
After applying Dan P's patch,
http://www.redhat.com/archives/libvir-list/2009-March/msg00281.html,
I now get a i686 kvm guest, since kvm now can do i686 guests from libvirt. This is certainly an improvement, but I think a more reasonable default is to attempt to match the host's architecture.
This patch makes virCapabilitiesDefaultGuestArch also check the domain type, and also gives preference to a guest architecture that matches the host's architecture.
ACK, this is good - we definitely want to match native arch by default if not specified otherwise. 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 :|

On Fri, Mar 20, 2009 at 03:34:44PM +0100, Soren Hansen wrote:
In libvirt 0.6.1, if you create a domain description of type 'kvm' without an arch set on an x86-64 host, you would get an i686 qemu guest rather than the expected x86-64 kvm guest.
This is because virCapabilitiesDefaultGuestArch doesn't take the domain type into consideration, so it just returned the first hvm architecutre that has been registered, which is i686.
After applying Dan P's patch,
http://www.redhat.com/archives/libvir-list/2009-March/msg00281.html,
I now get a i686 kvm guest, since kvm now can do i686 guests from libvirt. This is certainly an improvement, but I think a more reasonable default is to attempt to match the host's architecture.
This patch makes virCapabilitiesDefaultGuestArch also check the domain type, and also gives preference to a guest architecture that matches the host's architecture.
I've committed this patch now 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 :|

On Tue, Mar 24, 2009 at 11:16:38AM +0000, Daniel P. Berrange wrote:
On Fri, Mar 20, 2009 at 03:34:44PM +0100, Soren Hansen wrote:
In libvirt 0.6.1, if you create a domain description of type 'kvm' without an arch set on an x86-64 host, you would get an i686 qemu guest rather than the expected x86-64 kvm guest.
This is because virCapabilitiesDefaultGuestArch doesn't take the domain type into consideration, so it just returned the first hvm architecutre that has been registered, which is i686.
After applying Dan P's patch,
http://www.redhat.com/archives/libvir-list/2009-March/msg00281.html,
I now get a i686 kvm guest, since kvm now can do i686 guests from libvirt. This is certainly an improvement, but I think a more reasonable default is to attempt to match the host's architecture.
This patch makes virCapabilitiesDefaultGuestArch also check the domain type, and also gives preference to a guest architecture that matches the host's architecture.
I've committed this patch now
Sorry I nearly did it yesterday when I got distrated and didn't push/mail about it, fine, thanks ! 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/
participants (3)
-
Daniel P. Berrange
-
Daniel Veillard
-
Soren Hansen