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

[libvirt] [PATCH] xen_xs: Guard against set but empty kernel argument



On xen 4.1 I observied configurations that look like:

(image
    (hvm
        (kernel '')
        (loader '/foo/bar')
))

The kernel element is there but unset. This leads to an emtpy <kernel/>
element in the XML and even worse makes us skip the boot order parsing
and therefore not emit a <boot device='$dev>'/> element which breaks CD
booting.

O.k. to apply?
Cheers,
 -- Guido

---
 src/xenxs/xen_sxpr.c                               |    6 +++
 .../sexpr2xmldata/sexpr2xml-fv-empty-kernel.sexpr  |    9 ++++
 tests/sexpr2xmldata/sexpr2xml-fv-empty-kernel.xml  |   41 ++++++++++++++++++++
 tests/sexpr2xmltest.c                              |    2 +
 4 files changed, 58 insertions(+), 0 deletions(-)
 create mode 100644 tests/sexpr2xmldata/sexpr2xml-fv-empty-kernel.sexpr
 create mode 100644 tests/sexpr2xmldata/sexpr2xml-fv-empty-kernel.xml

diff --git a/src/xenxs/xen_sxpr.c b/src/xenxs/xen_sxpr.c
index 72322a7..15eaf18 100644
--- a/src/xenxs/xen_sxpr.c
+++ b/src/xenxs/xen_sxpr.c
@@ -125,6 +125,12 @@ xenParseSxprOS(const struct sexpr *node,
         STREQ(def->os.kernel, def->os.loader)) {
         VIR_FREE(def->os.kernel);
     }
+    /* Drop kernel argument that has no value */
+    if (hvm &&
+        def->os.kernel && *def->os.kernel == '\0' &&
+        def->os.loader) {
+        VIR_FREE(def->os.kernel);
+    }
 
     if (!def->os.kernel &&
         hvm) {
diff --git a/tests/sexpr2xmldata/sexpr2xml-fv-empty-kernel.sexpr b/tests/sexpr2xmldata/sexpr2xml-fv-empty-kernel.sexpr
new file mode 100644
index 0000000..ded668c
--- /dev/null
+++ b/tests/sexpr2xmldata/sexpr2xml-fv-empty-kernel.sexpr
@@ -0,0 +1,9 @@
+(domain (domid 3)(name 'fvtest')(memory 400)(maxmem 400)(vcpus 1)\
+(uuid 'b5d70dd275cdaca517769660b059d8bc')(on_poweroff 'destroy')\
+(on_reboot 'restart')(on_crash 'restart')\
+(image (hvm (loader /usr/lib/xen/boot/hvmloader)(kernel '')\
+(device_model '/usr/lib64/xen/bin/qemu-dm')(boot d)(cdrom '/root/boot.iso')\
+(acpi 1)(vnc 1)(keymap ja)))(device (vbd (dev 'ioemu:hda')\
+(uname 'file:/root/foo.img')(mode 'w')))\
+(device (vif (mac '00:16:3e:1b:b1:47')(bridge 'xenbr0')\
+(script 'vif-bridge')(type ioemu))))
diff --git a/tests/sexpr2xmldata/sexpr2xml-fv-empty-kernel.xml b/tests/sexpr2xmldata/sexpr2xml-fv-empty-kernel.xml
new file mode 100644
index 0000000..2c1c756
--- /dev/null
+++ b/tests/sexpr2xmldata/sexpr2xml-fv-empty-kernel.xml
@@ -0,0 +1,41 @@
+<domain type='xen' id='3'>
+  <name>fvtest</name>
+  <uuid>b5d70dd2-75cd-aca5-1776-9660b059d8bc</uuid>
+  <memory>409600</memory>
+  <currentMemory>409600</currentMemory>
+  <vcpu>1</vcpu>
+  <os>
+    <type>hvm</type>
+    <loader>/usr/lib/xen/boot/hvmloader</loader>
+    <boot dev='cdrom'/>
+  </os>
+  <features>
+    <acpi/>
+  </features>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>restart</on_crash>
+  <devices>
+    <emulator>/usr/lib64/xen/bin/qemu-dm</emulator>
+    <disk type='file' device='disk'>
+      <driver name='file'/>
+      <source file='/root/foo.img'/>
+      <target dev='hda' bus='ide'/>
+    </disk>
+    <disk type='file' device='cdrom'>
+      <driver name='file'/>
+      <source file='/root/boot.iso'/>
+      <target dev='hdc' bus='ide'/>
+      <readonly/>
+    </disk>
+    <interface type='bridge'>
+      <mac address='00:16:3e:1b:b1:47'/>
+      <source bridge='xenbr0'/>
+      <script path='vif-bridge'/>
+      <target dev='vif3.0'/>
+    </interface>
+    <input type='mouse' bus='ps2'/>
+    <graphics type='vnc' port='5903' autoport='no' keymap='ja'/>
+  </devices>
+</domain>
diff --git a/tests/sexpr2xmltest.c b/tests/sexpr2xmltest.c
index 26a987d..126a78c 100644
--- a/tests/sexpr2xmltest.c
+++ b/tests/sexpr2xmltest.c
@@ -180,6 +180,8 @@ mymain(void)
     DO_TEST("fv-net-ioemu", "fv-net-ioemu", 1);
     DO_TEST("fv-net-netfront", "fv-net-netfront", 1);
 
+    DO_TEST("fv-empty-kernel", "fv-empty-kernel", 1);
+
     DO_TEST("boot-grub", "boot-grub", 1);
 
     virCapabilitiesFree(caps);
-- 
1.7.6.3


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