[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[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/

Attachment: signature.asc
Description: Digital signature


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]