[PATCH] add bootloader_args to libvirt xml to support bootloaders (like pypxeboot for example) that require arguments

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

 



This patch extends libvirt's XML to include a paramater Xen already supports in sexpr, "bootloader_args." The bootloader_args parameter lets you pass arguments -- "mac=aa:12:34:56:78:90" for example -- to a bootloader program that xend invokes when it starts a guest. One such program, pypxeboot, uses the mac= argument to communicate with a dhcp server and retrieve the pxeboot kernel and initrd for a paravirt guest.

The patch includes new tests for the bootloader_args XML and sexpr, which pass.

Note that for the head of current libvirt, the virsh tests do not pass and virsh will not connect to the xen hypervisor. I don't know if this is my own build environment or some other issue. However the failure is the same with or without this patch, so I am submitting it anyway.

Please let me know what you think...

--Hugh


--
Red Hat Virtualization Group http://redhat.com/virtualization
Hugh Brock           | virt-manager http://virt-manager.org
hbrock@xxxxxxxxxx    | virtualization library http://libvirt.org
diff -ruN --exclude CVS libvirt/src/xend_internal.c libvirt.new/src/xend_internal.c
--- libvirt/src/xend_internal.c	2007-06-04 15:38:31.000000000 -0400
+++ libvirt.new/src/xend_internal.c	2007-06-01 15:20:21.000000000 -0400
@@ -1411,6 +1411,13 @@
         bootloader = 1;
         virBufferVSprintf(&buf, "  <bootloader>%s</bootloader>\n", tmp);
     }
+    tmp = sexpr_node(root, "domain/bootloader_args");
+    if (tmp != NULL && bootloader) {
+        /*
+         * Only insert bootloader_args if there is also a bootloader param
+         */
+        virBufferVSprintf(&buf, "  <bootloader_args>%s</bootloader_args>\n", tmp);
+    }
 
     if (domid != 0) {
         if (sexpr_lookup(root, "domain/image")) {
diff -ruN --exclude CVS libvirt/src/xm_internal.c libvirt.new/src/xm_internal.c
--- libvirt/src/xm_internal.c	2007-06-04 15:38:31.000000000 -0400
+++ libvirt.new/src/xm_internal.c	2007-06-01 15:07:27.000000000 -0400
@@ -640,6 +640,8 @@
 
         if (xenXMConfigGetString(conf, "bootloader", &str) == 0)
             virBufferVSprintf(buf, "  <bootloader>%s</bootloader>\n", str);
+        if (xenXMConfigGetString(conf, "bootargs", &str) == 0)
+            virBufferVSprintf(buf, "  <bootloader_args>%s</bootloader_args>\n", str);
         if (xenXMConfigGetString(conf, "kernel", &str) == 0) {
             virBufferAdd(buf, "  <os>\n", -1);
             virBufferAdd(buf, "    <type>linux</type>\n", -1);
@@ -1830,6 +1832,9 @@
         if (xenXMConfigSetStringFromXPath(conn, conf, ctxt, "bootloader", "string(/domain/bootloader)", 1,
                                           "cannot set the bootloader parameter") < 0)
             goto error;
+        if (xenXMConfigSetStringFromXPath(conn, conf, ctxt, "bootargs", "string(/domain/bootloader_args)", 1,
+                                          "cannot set the bootloader_args parameter") < 0)
+            goto error;
         if (xenXMConfigSetStringFromXPath(conn, conf, ctxt, "kernel", "string(/domain/os/kernel)", 1,
                                           "cannot set the kernel parameter") < 0)
             goto error;
diff -ruN --exclude CVS libvirt/src/xml.c libvirt.new/src/xml.c
--- libvirt/src/xml.c	2007-06-04 15:38:32.000000000 -0400
+++ libvirt.new/src/xml.c	2007-06-04 14:20:13.000000000 -0400
@@ -1266,13 +1266,19 @@
     if (str != NULL) {
         virBufferVSprintf(&buf, "(bootloader '%s')", str);
         /*
-         * if using pygrub, the kernel and initrd strings are not
+         * if using a bootloader, the kernel and initrd strings are not
          * significant and should be discarded
          */
-        if (strstr(str, "pygrub"))
-            bootloader = 2;
-        else
-            bootloader = 1;
+        bootloader = 1;
+	free(str);
+    }
+
+    str = virXPathString("string(/domain/bootloader_args[1])", ctxt);
+    if (str != NULL && bootloader) {
+        /*
+         * ignore the bootloader_args value unless a bootloader was specified
+         */
+        virBufferVSprintf(&buf, "(bootloader_args '%s')", str);
 	free(str);
     }
 
@@ -1294,10 +1300,10 @@
 	free(str);
     }
 
-    if (bootloader != 2) {
+    if (!bootloader) {
         if ((node = virXPathNode("/domain/os[1]", ctxt)) != NULL) {
             /* Analyze of the os description, based on HVM or PV. */
-	    str = virXPathString("string(/domain/os/type[1])", ctxt);
+            str = virXPathString("string(/domain/os/type[1])", ctxt);
 
             if ((str == NULL) || (strcmp(str, "hvm"))) {
                 res = virDomainParseXMLOSDescPV(conn, node,
@@ -1312,7 +1318,7 @@
 
             if (res != 0)
                 goto error;
-        } else if (bootloader == 0) {
+        } else {
             virXMLError(conn, VIR_ERR_NO_OS, nam, 0);
             goto error;
         }
diff -ruN --exclude CVS libvirt/tests/sexpr2xmldata/sexpr2xml-pv-bootloader.sexpr libvirt.new/tests/sexpr2xmldata/sexpr2xml-pv-bootloader.sexpr
--- libvirt/tests/sexpr2xmldata/sexpr2xml-pv-bootloader.sexpr	1969-12-31 19:00:00.000000000 -0500
+++ libvirt.new/tests/sexpr2xmldata/sexpr2xml-pv-bootloader.sexpr	2007-06-01 14:52:38.000000000 -0400
@@ -0,0 +1 @@
+(domain (domid 6)(name 'pvtest')(memory 420)(maxmem 420)(vcpus 2)(uuid '596a5d2171f48fb2e068e2386a5c413e')(bootloader '/usr/bin/pypxeboot')(bootloader_args 'mac=AA:00:86:e2:35:72')(on_poweroff 'destroy')(on_reboot 'destroy')(on_crash 'destroy')(device (vbd (dev 'xvda')(uname 'file:/root/some.img')(mode 'w'))))
\ No newline at end of file
diff -ruN --exclude CVS libvirt/tests/sexpr2xmldata/sexpr2xml-pv-bootloader.xml libvirt.new/tests/sexpr2xmldata/sexpr2xml-pv-bootloader.xml
--- libvirt/tests/sexpr2xmldata/sexpr2xml-pv-bootloader.xml	1969-12-31 19:00:00.000000000 -0500
+++ libvirt.new/tests/sexpr2xmldata/sexpr2xml-pv-bootloader.xml	2007-06-01 15:24:30.000000000 -0400
@@ -0,0 +1,18 @@
+<domain type='xen' id='6'>
+  <name>pvtest</name>
+  <uuid>596a5d2171f48fb2e068e2386a5c413e</uuid>
+  <bootloader>/usr/bin/pypxeboot</bootloader>
+  <bootloader_args>mac=AA:00:86:e2:35:72</bootloader_args>
+  <memory>430080</memory>
+  <vcpu>2</vcpu>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>destroy</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <disk type='file' device='disk'>
+      <driver name='file'/>
+      <source file='/root/some.img'/>
+      <target dev='xvda'/>
+    </disk>
+  </devices>
+</domain>
diff -ruN --exclude CVS libvirt/tests/sexpr2xmltest.c libvirt.new/tests/sexpr2xmltest.c
--- libvirt/tests/sexpr2xmltest.c	2007-06-04 15:38:32.000000000 -0400
+++ libvirt.new/tests/sexpr2xmltest.c	2007-06-01 15:04:21.000000000 -0400
@@ -81,6 +81,12 @@
 			  2);
 }
 
+static int testComparePVBootloader(void *data ATTRIBUTE_UNUSED) {
+  return testCompareFiles("sexpr2xmldata/sexpr2xml-pv-bootloader.xml",
+			  "sexpr2xmldata/sexpr2xml-pv-bootloader.sexpr",
+			  2);
+}
+
 static int testCompareDiskFile(void *data ATTRIBUTE_UNUSED) {
   return testCompareFiles("sexpr2xmldata/sexpr2xml-disk-file.xml",
 			  "sexpr2xmldata/sexpr2xml-disk-file.sexpr",
@@ -167,6 +173,10 @@
 		    1, testCompareFVversion2, NULL) != 0)
 	ret = -1;
 
+    if (virtTestRun("SEXPR-2-XML PV config bootloader",
+		    1, testComparePVBootloader, NULL) != 0)
+	ret = -1;
+
     if (virtTestRun("SEXPR-2-XML Disk File config",
 		    1, testCompareDiskFile, NULL) != 0)
 	ret = -1;
diff -ruN --exclude CVS libvirt/tests/xml2sexprdata/xml2sexpr-pv-bootloader.sexpr libvirt.new/tests/xml2sexprdata/xml2sexpr-pv-bootloader.sexpr
--- libvirt/tests/xml2sexprdata/xml2sexpr-pv-bootloader.sexpr	1969-12-31 19:00:00.000000000 -0500
+++ libvirt.new/tests/xml2sexprdata/xml2sexpr-pv-bootloader.sexpr	2007-06-01 14:37:24.000000000 -0400
@@ -0,0 +1 @@
+(vm (name 'pvtest')(memory 420)(maxmem 420)(vcpus 2)(uuid '596a5d2171f48fb2e068e2386a5c413e')(bootloader '/usr/bin/pypxeboot')(bootloader_args 'mac=AA:00:86:e2:35:72')(on_poweroff 'destroy')(on_reboot 'destroy')(on_crash 'destroy')(device (vbd (dev 'xvda')(uname 'file:/root/some.img')(mode 'w'))))
\ No newline at end of file
diff -ruN --exclude CVS libvirt/tests/xml2sexprdata/xml2sexpr-pv-bootloader.xml libvirt.new/tests/xml2sexprdata/xml2sexpr-pv-bootloader.xml
--- libvirt/tests/xml2sexprdata/xml2sexpr-pv-bootloader.xml	1969-12-31 19:00:00.000000000 -0500
+++ libvirt.new/tests/xml2sexprdata/xml2sexpr-pv-bootloader.xml	2007-06-01 13:37:39.000000000 -0400
@@ -0,0 +1,19 @@
+<domain type='xen' id='15'>
+  <name>pvtest</name>
+  <uuid>596a5d2171f48fb2e068e2386a5c413e</uuid>
+  <bootloader>/usr/bin/pypxeboot</bootloader>
+  <bootloader_args>mac=AA:00:86:e2:35:72</bootloader_args>
+  <memory>430080</memory>
+  <vcpu>2</vcpu>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>destroy</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <disk type='file' device='disk'>
+      <source file='/root/some.img'/>
+      <target dev='xvda'/>
+    </disk>
+    <console tty='/dev/pts/4'/>
+  </devices>
+</domain>
+
diff -ruN --exclude CVS libvirt/tests/xml2sexprtest.c libvirt.new/tests/xml2sexprtest.c
--- libvirt/tests/xml2sexprtest.c	2007-06-04 15:38:32.000000000 -0400
+++ libvirt.new/tests/xml2sexprtest.c	2007-06-01 14:23:31.000000000 -0400
@@ -103,6 +103,13 @@
                           3);
 }
 
+static int testComparePVBootloader(void *data ATTRIBUTE_UNUSED) {
+  return testCompareFiles("xml2sexprdata/xml2sexpr-pv-bootloader.xml",
+			  "xml2sexprdata/xml2sexpr-pv-bootloader.sexpr",
+			  "pvtest",
+			  1);
+}
+
 static int testCompareDiskFile(void *data ATTRIBUTE_UNUSED) {
   return testCompareFiles("xml2sexprdata/xml2sexpr-disk-file.xml",
 			  "xml2sexprdata/xml2sexpr-disk-file.sexpr",
@@ -221,6 +228,10 @@
                     1, testComparePVNewVFB, NULL) != 0)
         ret = -1;
 
+    if (virtTestRun("XML-2-SEXPR PV config with bootloader",
+		    1, testComparePVBootloader, NULL) != 0)
+	ret = -1;
+
     if (virtTestRun("XML-2-SEXPR Disk File",
 		    1, testCompareDiskFile, NULL) != 0)
 	ret = -1;

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]