]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
conf: fix omission of <driver> in domain dumpxml
authorEric Blake <eblake@redhat.com>
Mon, 14 Apr 2014 22:54:19 +0000 (16:54 -0600)
committerJiri Denemark <jdenemar@redhat.com>
Wed, 16 Apr 2014 08:49:07 +0000 (10:49 +0200)
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>
docs/schemas/domaincommon.rng
src/conf/domain_conf.c
tests/qemuxml2argvdata/qemuxml2argv-disk-drive-copy-on-read.args [new file with mode: 0644]
tests/qemuxml2argvdata/qemuxml2argv-disk-drive-copy-on-read.xml [new file with mode: 0644]
tests/qemuxml2argvdata/qemuxml2argv-disk-drive-discard.xml
tests/qemuxml2argvtest.c
tests/qemuxml2xmloutdata/qemuxml2xmlout-disk-drive-discard.xml
tests/qemuxml2xmltest.c

index 7739fd818f5e4ea4ea82a46c65ec4231225c64ef..d2235e1f566dc7ffffd96c0113b7ca2761db3b6a 100644 (file)
     -->
   <define name="diskDriver">
     <element name="driver">
-      <choice>
-        <group>
-          <ref name="driverFormat"/>
-          <optional>
-            <ref name="driverCache"/>
-          </optional>
-        </group>
-        <group>
-          <optional>
-            <ref name="driverFormat"/>
-          </optional>
-          <ref name="driverCache"/>
-        </group>
-      </choice>
+      <optional>
+        <ref name="driverFormat"/>
+      </optional>
+      <optional>
+        <ref name="driverCache"/>
+      </optional>
       <optional>
         <ref name="driverErrorPolicy"/>
       </optional>
index 726c8bad04e98b423b1f737d377d124877df399d..05fa3f9ffbbf55f964897a0388e337f371151980 100644 (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);
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-copy-on-read.args b/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-copy-on-read.args
new file mode 100644 (file)
index 0000000..f743b6b
--- /dev/null
@@ -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
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-copy-on-read.xml b/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-copy-on-read.xml
new file mode 100644 (file)
index 0000000..c15ca93
--- /dev/null
@@ -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>
index b15fd63e9e419250433661518fee837197d2e859..de2855a30d9a51c4a9b2ffe467510f2faddb082d 100644 (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/>
index 13ed4f6f471b89dc385eb9e47af140da13eb0853..d43a4de266850af37d3cf7f22b7852b0cd4262a5 100644 (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",
index f01312f5339215c622abc36d360bf9ae93dde4bb..f20b3b99e0fc9740be353c9e05eb20b6cfcd3255 100644 (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/>
index 788adbe3867d60d50b985de85c795c55ea6f35ca..bf9d736561084be658d332c13f6ce73b83ac9f1b 100644 (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");