File libxl-hvm-kernel-boot.patch of Package libvirt

libxl: support hvm direct kernel boot

Xen libxl can support Xen HVM direct kernel boot now. To support
Xen HVM direct kernel boot in libvirt, it still needs some changes
to libvirt code: accept HVM direct kernel boot related configuration
in xml, parse those info into virDomainDefPtr, and fill in related
parts of libxl_domain_build_info, so that libxl can handle. This
patch is just to do this.

Signed-off-by: Chunyan Liu <cyliu@suse.com>


Index: libvirt-1.2.5/src/libxl/libxl_conf.c
===================================================================
--- libvirt-1.2.5.orig/src/libxl/libxl_conf.c
+++ libvirt-1.2.5/src/libxl/libxl_conf.c
@@ -706,6 +706,15 @@ libxlMakeDomBuildInfo(virDomainObjPtr vm
         if (VIR_STRDUP(b_info->u.hvm.boot, bootorder) < 0)
             goto error;
 
+#ifdef LIBXL_HAVE_BUILDINFO_KERNEL
+        if (VIR_STRDUP(b_info->cmdline, def->os.cmdline) < 0)
+            goto error;
+        if (VIR_STRDUP(b_info->kernel, def->os.kernel) < 0)
+            goto error;
+        if (VIR_STRDUP(b_info->ramdisk, def->os.initrd) < 0)
+            goto error;
+#endif
+
         if (def->nserials) {
             if (def->nserials > 1) {
                 virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
@@ -750,6 +759,14 @@ libxlMakeDomBuildInfo(virDomainObjPtr vm
                   virStringSplit(def->os.bootloaderArgs, " \t\n", 0)))
                 goto error;
         }
+#ifdef LIBXL_HAVE_BUILDINFO_KERNEL
+        if (VIR_STRDUP(b_info->cmdline, def->os.cmdline) < 0)
+            goto error;
+        if (VIR_STRDUP(b_info->kernel, def->os.kernel) < 0)
+            goto error;
+        if (VIR_STRDUP(b_info->ramdisk, def->os.initrd) < 0)
+            goto error;
+#else
         if (VIR_STRDUP(b_info->u.pv.cmdline, def->os.cmdline) < 0)
             goto error;
         if (def->os.kernel) {
@@ -760,6 +777,7 @@ libxlMakeDomBuildInfo(virDomainObjPtr vm
         }
         if (VIR_STRDUP(b_info->u.pv.ramdisk, def->os.initrd) < 0)
             goto error;
+#endif
     }
 
     return 0;
Index: libvirt-1.2.5/src/xenxs/xen_xm.c
===================================================================
--- libvirt-1.2.5.orig/src/xenxs/xen_xm.c
+++ libvirt-1.2.5/src/xenxs/xen_xm.c
@@ -40,6 +40,10 @@
 #include "virstoragefile.h"
 #include "virstring.h"
 
+#if WITH_LIBXL
+# include <libxl.h>
+#endif
+
 /* Convenience method to grab a long int from the config file object */
 static int xenXMConfigGetBool(virConfPtr conf,
                               const char *name,
@@ -248,6 +252,28 @@ xenXMConfigGetUUID(virConfPtr conf, cons
     return 0;
 }
 
+static int
+xenParseCmdline(virConfPtr conf, virDomainDefPtr def)
+{
+    const char *extra, *root;
+
+    if (xenXMConfigGetString(conf, "extra", &extra, NULL) < 0)
+        return -1;
+
+    if (xenXMConfigGetString(conf, "root", &root, NULL) < 0)
+        return -1;
+
+    if (root) {
+        if (virAsprintf(&def->os.cmdline, "root=%s %s", root, extra) < 0)
+            return -1;
+    } else {
+        if (VIR_STRDUP(def->os.cmdline, extra) < 0)
+            return -1;
+    }
+
+    return 0;
+}
+
 #define MAX_VFB 1024
 /*
  * Turn a config record into a lump of XML describing the
@@ -314,9 +340,25 @@ xenParseXM(virConfPtr conf, int xendConf
 
     if (hvm) {
         const char *boot;
-        if (xenXMConfigCopyString(conf, "kernel", &def->os.loader) < 0)
+#ifdef LIBXL_HAVE_BUILDINFO_KERNEL
+        if (xenXMConfigCopyStringOpt(conf, "kernel", &def->os.kernel) < 0)
+            goto cleanup;
+
+        if (def->os.kernel && strstr(def->os.kernel, "hvmloader")) {
+            /* 'kernel' set to 'hvmloader' will be ignored in libxl */
+            VIR_FREE(def->os.kernel);
+        }
+
+        if (xenXMConfigCopyStringOpt(conf, "ramdisk", &def->os.initrd) < 0)
             goto cleanup;
 
+        if (xenParseCmdline(conf, def) < 0)
+            goto cleanup;
+#else
+        if (xenXMConfigCopyStringOpt(conf, "kernel", &def->os.loader) < 0)
+            goto cleanup;
+#endif
+
         if (xenXMConfigGetString(conf, "boot", &boot, "c") < 0)
             goto cleanup;
 
@@ -339,8 +381,6 @@ xenParseXM(virConfPtr conf, int xendConf
             def->os.nBootDevs++;
         }
     } else {
-        const char *extra, *root;
-
         if (xenXMConfigCopyStringOpt(conf, "bootloader", &def->os.bootloader) < 0)
             goto cleanup;
         if (xenXMConfigCopyStringOpt(conf, "bootargs", &def->os.bootloaderArgs) < 0)
@@ -350,18 +390,8 @@ xenParseXM(virConfPtr conf, int xendConf
             goto cleanup;
         if (xenXMConfigCopyStringOpt(conf, "ramdisk", &def->os.initrd) < 0)
             goto cleanup;
-        if (xenXMConfigGetString(conf, "extra", &extra, NULL) < 0)
-            goto cleanup;
-        if (xenXMConfigGetString(conf, "root", &root, NULL) < 0)
+        if (xenParseCmdline(conf, def) < 0)
             goto cleanup;
-
-        if (root) {
-            if (virAsprintf(&def->os.cmdline, "root=%s %s", root, extra) < 0)
-                goto cleanup;
-        } else {
-            if (VIR_STRDUP(def->os.cmdline, extra) < 0)
-                goto cleanup;
-        }
     }
 
     if (xenXMConfigGetULongLong(conf, "memory", &def->mem.cur_balloon,