conf: fix omission of <driver> in domain dumpxml

I noticed that depending on the <driver> attributes the user passed
in, the output may omit the <driver> element altogether.  For example,
the rerror_policy has had this problem since commit 4bb4109 in Oct
2011.  But in adding testsuite coverage to expose it, I found another
problem: the C code is just fine without a driver name, but the
XML validator required either a name or a cache mode.

* src/conf/domain_conf.c (virDomainDiskDefFormat): Update
conditional.
* docs/schemas/domaincommon.rng (diskDriver): Simplify.
* tests/qemuxml2argvdata/qemuxml2argv-disk-drive-copy-on-read.xml:
* tests/qemuxml2argvdata/qemuxml2argv-disk-drive-copy-on-read.args:
New files.
* tests/qemuxml2argvdata/qemuxml2argv-disk-drive-discard.xml:
Enhance test.
* tests/qemuxml2xmloutdata/qemuxml2xmlout-disk-drive-discard.xml:
Likewise.
* tests/qemuxml2argvtest.c (mymain): New test.
* tests/qemuxml2xmltest.c (mymain): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
This commit is contained in:
Eric Blake 2014-04-14 16:54:19 -06:00 committed by Jiri Denemark
parent fec1a93927
commit 8fb446754d
8 changed files with 48 additions and 17 deletions

View File

@ -1461,20 +1461,12 @@
-->
<define name="diskDriver">
<element name="driver">
<choice>
<group>
<ref name="driverFormat"/>
<optional>
<ref name="driverCache"/>
</optional>
</group>
<group>
<optional>
<ref name="driverFormat"/>
</optional>
<optional>
<ref name="driverCache"/>
</group>
</choice>
</optional>
<optional>
<ref name="driverErrorPolicy"/>
</optional>

View File

@ -14963,7 +14963,9 @@ virDomainDiskDefFormat(virBufferPtr buf,
virBufferAdjustIndent(buf, 2);
if (def->src.driverName || def->src.format > 0 || def->cachemode ||
def->ioeventfd || def->event_idx || def->copy_on_read) {
def->error_policy || def->rerror_policy || def->iomode ||
def->ioeventfd || def->event_idx || def->copy_on_read ||
def->discard) {
virBufferAddLit(buf, "<driver");
if (def->src.driverName)
virBufferAsprintf(buf, " name='%s'", def->src.driverName);

View File

@ -0,0 +1,5 @@
LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test QEMU_AUDIO_DRV=none \
/usr/bin/qemu -S -M \
pc -m 214 -smp 1 -nographic -monitor unix:/tmp/test-monitor,server,nowait \
-no-acpi -boot c -usb -drive file=/dev/HostVG/QEMUGuest1,if=ide,bus=0,unit=0,\
format=raw,copy-on-read=on -net none -serial none -parallel none

View File

@ -0,0 +1,28 @@
<domain type='qemu'>
<name>QEMUGuest1</name>
<uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
<memory unit='KiB'>219136</memory>
<currentMemory unit='KiB'>219136</currentMemory>
<vcpu placement='static'>1</vcpu>
<os>
<type arch='i686' machine='pc'>hvm</type>
<boot dev='hd'/>
</os>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<emulator>/usr/bin/qemu</emulator>
<disk type='block' device='disk'>
<driver copy_on_read='on'/>
<source dev='/dev/HostVG/QEMUGuest1'/>
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
</disk>
<controller type='usb' index='0'/>
<controller type='ide' index='0'/>
<controller type='pci' index='0' model='pci-root'/>
<memballoon model='virtio'/>
</devices>
</domain>

View File

@ -25,7 +25,7 @@
<driver discard='unmap' name='qemu' type='qcow2'/>
</disk>
<disk type='file' device='cdrom'>
<driver name='qemu' type='raw' discard='ignore'/>
<driver discard='ignore'/>
<source file='/var/lib/libvirt/Fedora-14-x86_64-Live-KDE.iso'/>
<target dev='hdc' bus='ide'/>
<readonly/>

View File

@ -739,6 +739,9 @@ mymain(void)
DO_TEST("disk-drive-cache-unsafe",
QEMU_CAPS_DRIVE, QEMU_CAPS_DRIVE_CACHE_V2,
QEMU_CAPS_DRIVE_CACHE_UNSAFE, QEMU_CAPS_DRIVE_FORMAT);
DO_TEST("disk-drive-copy-on-read",
QEMU_CAPS_DRIVE, QEMU_CAPS_DRIVE_CACHE_V2,
QEMU_CAPS_DRIVE_COPY_ON_READ, QEMU_CAPS_DRIVE_FORMAT);
DO_TEST("disk-drive-network-nbd",
QEMU_CAPS_DRIVE, QEMU_CAPS_DRIVE_FORMAT);
DO_TEST("disk-drive-network-nbd-export",

View File

@ -23,7 +23,7 @@
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
</disk>
<disk type='file' device='cdrom'>
<driver name='qemu' type='raw' discard='ignore'/>
<driver discard='ignore'/>
<source file='/var/lib/libvirt/Fedora-14-x86_64-Live-KDE.iso'/>
<target dev='hdc' bus='ide'/>
<readonly/>

View File

@ -187,6 +187,7 @@ mymain(void)
DO_TEST("disk-drive-cache-v1-wt");
DO_TEST("disk-drive-cache-v1-wb");
DO_TEST("disk-drive-cache-v1-none");
DO_TEST("disk-drive-copy-on-read");
DO_TEST("disk-drive-network-nbd");
DO_TEST("disk-drive-network-nbd-export");
DO_TEST("disk-drive-network-nbd-ipv6");