[libvirt] Improve heuristic for default guest architecture

Soren Hansen soren at ubuntu.com
Fri Mar 20 14:34:44 UTC 2009


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/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 315 bytes
Desc: Digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20090320/15fbb371/attachment-0001.sig>


More information about the libvir-list mailing list