Bug 1327578

Summary: xen xm parser assumes 'extra' is always present if 'root' specified
Product: [Community] Virtualization Tools Reporter: Cole Robinson <crobinso>
Component: libvirtAssignee: Libvirt Maintainers <libvirt-maint>
Status: CLOSED UPSTREAM QA Contact:
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: unspecifiedCC: rbalakri
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard: LibvirtFirstBug
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2018-05-15 13:38:08 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Cole Robinson 2016-04-15 12:41:20 UTC
(from bug 584777)

# cat f
kernel      = '/boot/vmlinuz-2.6.26-2-xen-amd64'
ramdisk     = '/boot/initrd.img-2.6.26-2-xen-amd64'
memory      = '128'
root        = '/dev/xvda2 ro'
disk        = [
                  'file:/opt/xen/domains/domU/swap.img,xvda1,w',
                  'file:/opt/xen/domains/domU/disk.img,xvda2,w',
              ]
name        = 'domU'
dhcp        = 'dhcp'
vif = [ 'mac=00:16:3E:70:61:00,bridge=xenbr0' ]
on_poweroff = 'destroy'
on_reboot   = 'restart'
on_crash    = 'restart'

# sudo virsh domxml-from-native xen-xm f | grep cmdline
    <cmdline>root=/dev/xvda2 ro (null)</cmdline>


Notice the '(null)' bit. If root= is specified, the code expects that extra= was always specified too. The code is in src/xenconfig/xen_xm.c:

        if (xenConfigGetString(conf, "extra", &extra, NULL) < 0)
            return -1;

        if (xenConfigGetString(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;

root and extra need to be handled separately. Note, this can be tested without a xen setup, just drop that xm config in tests/xmconfigdata and extend tests/xmconfigtest.c to test it.

Comment 1 Cole Robinson 2018-05-15 13:38:08 UTC
Upstream now:

commit 656151bf5dd299322dcf37d06d20534e667a1963
Author: Filip Alac <filipalac>
Date:   Sat May 12 17:45:02 2018 +0200

    xenconfig: xm: Fix checking for extra in parser