[PATCHv2 8/9] conf: fix omission of <driver> in domain dumpxml

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

 



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@xxxxxxxxxx>
---
 docs/schemas/domaincommon.rng                      | 20 +++++-----------
 src/conf/domain_conf.c                             |  4 +++-
 .../qemuxml2argv-disk-drive-copy-on-read.args      |  5 ++++
 .../qemuxml2argv-disk-drive-copy-on-read.xml       | 28 ++++++++++++++++++++++
 .../qemuxml2argv-disk-drive-discard.xml            |  2 +-
 tests/qemuxml2argvtest.c                           |  3 +++
 .../qemuxml2xmlout-disk-drive-discard.xml          |  2 +-
 tests/qemuxml2xmltest.c                            |  1 +
 8 files changed, 48 insertions(+), 17 deletions(-)
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-drive-copy-on-read.args
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-drive-copy-on-read.xml

diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 78fed88..09f426a 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -1254,20 +1254,12 @@
     -->
   <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>
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 726c8ba..05fa3f9 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -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
index 0000000..f743b6b
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-copy-on-read.args
@@ -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
index 0000000..c15ca93
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-copy-on-read.xml
@@ -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>
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-discard.xml b/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-discard.xml
index b15fd63..de2855a 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-discard.xml
+++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-discard.xml
@@ -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/>
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 13ed4f6..d43a4de 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -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",
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-disk-drive-discard.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-disk-drive-discard.xml
index f01312f..f20b3b9 100644
--- a/tests/qemuxml2xmloutdata/qemuxml2xmlout-disk-drive-discard.xml
+++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-disk-drive-discard.xml
@@ -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/>
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
index 788adbe..bf9d736 100644
--- a/tests/qemuxml2xmltest.c
+++ b/tests/qemuxml2xmltest.c
@@ -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");
-- 
1.9.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[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]