[PATCH v4 2/2] qemu: Add support for zero-detection writes

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

 



Signed-off-by: Martin Kletzander <mkletzan@xxxxxxxxxx>
---
 src/qemu/qemu_capabilities.c                       |  3 +++
 src/qemu/qemu_capabilities.h                       |  3 +++
 src/qemu/qemu_command.c                            | 11 +++++++++
 tests/qemucapabilitiesdata/caps_2.1.1.x86_64.xml   |  1 +
 tests/qemucapabilitiesdata/caps_2.4.0.x86_64.xml   |  1 +
 tests/qemucapabilitiesdata/caps_2.5.0.x86_64.xml   |  1 +
 .../caps_2.6.0-gicv2.aarch64.xml                   |  1 +
 .../caps_2.6.0-gicv3.aarch64.xml                   |  1 +
 tests/qemucapabilitiesdata/caps_2.6.0.ppc64le.xml  |  1 +
 tests/qemucapabilitiesdata/caps_2.6.0.x86_64.xml   |  1 +
 .../qemuxml2argv-disk-drive-detect-zeroes.args     | 27 ++++++++++++++++++++++
 tests/qemuxml2argvtest.c                           |  3 +++
 12 files changed, 54 insertions(+)
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-drive-detect-zeroes.args

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index d32e71f12d24..79f7010fd3b1 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -329,6 +329,8 @@ VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST,
               "nec-usb-xhci-ports",
               "virtio-scsi-pci.iothread",
               "name-guest",
+
+              "drive-detect-zeroes", /* 225 */
     );


@@ -2644,6 +2646,7 @@ static struct virQEMUCapsCommandLineProps virQEMUCapsCommandLine[] = {
     { "machine", "mem-merge", QEMU_CAPS_MEM_MERGE },
     { "machine", "vmport", QEMU_CAPS_MACHINE_VMPORT_OPT },
     { "drive", "discard", QEMU_CAPS_DRIVE_DISCARD },
+    { "drive", "detect-zeroes", QEMU_CAPS_DRIVE_DETECT_ZEROES },
     { "realtime", "mlock", QEMU_CAPS_MLOCK },
     { "boot-opts", "strict", QEMU_CAPS_BOOT_STRICT },
     { "boot-opts", "reboot-timeout", QEMU_CAPS_REBOOT_TIMEOUT },
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index 368996ad29f1..341e00923699 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -361,6 +361,9 @@ typedef enum {
     QEMU_CAPS_VIRTIO_SCSI_IOTHREAD, /* virtio-scsi-{pci,ccw}.iothread */
     QEMU_CAPS_NAME_GUEST, /* -name guest= */

+    /* 225 */
+    QEMU_CAPS_DRIVE_DETECT_ZEROES, /* -drive detect_zeroes= */
+
     QEMU_CAPS_LAST /* this must always be the last item */
 } virQEMUCapsFlags;

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 368bd871f7e3..993e49f832cd 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -1499,6 +1499,17 @@ qemuBuildDriveStr(virDomainDiskDefPtr disk,
         }
     }

+    if (disk->detect_zeroes) {
+        if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DRIVE_DETECT_ZEROES)) {
+            virBufferAsprintf(&opt, ",detect_zeroes=%s",
+                              virDomainDiskDetectZeroesTypeToString(disk->detect_zeroes));
+        } else {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("detect_zeroes is not supported by this QEMU binary"));
+            goto error;
+        }
+    }
+
     if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_MONITOR_JSON)) {
         const char *wpolicy = NULL, *rpolicy = NULL;

diff --git a/tests/qemucapabilitiesdata/caps_2.1.1.x86_64.xml b/tests/qemucapabilitiesdata/caps_2.1.1.x86_64.xml
index 5e9b34d8a493..964b6f020483 100644
--- a/tests/qemucapabilitiesdata/caps_2.1.1.x86_64.xml
+++ b/tests/qemucapabilitiesdata/caps_2.1.1.x86_64.xml
@@ -164,6 +164,7 @@
   <flag name='device-tray-moved-event'/>
   <flag name='nec-usb-xhci-ports'/>
   <flag name='name-guest'/>
+  <flag name='drive-detect-zeroes'/>
   <version>2001001</version>
   <kvmVersion>0</kvmVersion>
   <package></package>
diff --git a/tests/qemucapabilitiesdata/caps_2.4.0.x86_64.xml b/tests/qemucapabilitiesdata/caps_2.4.0.x86_64.xml
index e56b7e58be85..cd544ca1394e 100644
--- a/tests/qemucapabilitiesdata/caps_2.4.0.x86_64.xml
+++ b/tests/qemucapabilitiesdata/caps_2.4.0.x86_64.xml
@@ -178,6 +178,7 @@
   <flag name='nec-usb-xhci-ports'/>
   <flag name='virtio-scsi-pci.iothread'/>
   <flag name='name-guest'/>
+  <flag name='drive-detect-zeroes'/>
   <version>2004000</version>
   <kvmVersion>0</kvmVersion>
   <package></package>
diff --git a/tests/qemucapabilitiesdata/caps_2.5.0.x86_64.xml b/tests/qemucapabilitiesdata/caps_2.5.0.x86_64.xml
index 4df48435c460..ba129776ca46 100644
--- a/tests/qemucapabilitiesdata/caps_2.5.0.x86_64.xml
+++ b/tests/qemucapabilitiesdata/caps_2.5.0.x86_64.xml
@@ -182,6 +182,7 @@
   <flag name='nec-usb-xhci-ports'/>
   <flag name='virtio-scsi-pci.iothread'/>
   <flag name='name-guest'/>
+  <flag name='drive-detect-zeroes'/>
   <version>2005000</version>
   <kvmVersion>0</kvmVersion>
   <package></package>
diff --git a/tests/qemucapabilitiesdata/caps_2.6.0-gicv2.aarch64.xml b/tests/qemucapabilitiesdata/caps_2.6.0-gicv2.aarch64.xml
index 8b68291aecb4..29f3b5ac3f11 100644
--- a/tests/qemucapabilitiesdata/caps_2.6.0-gicv2.aarch64.xml
+++ b/tests/qemucapabilitiesdata/caps_2.6.0-gicv2.aarch64.xml
@@ -155,6 +155,7 @@
   <flag name='nec-usb-xhci-ports'/>
   <flag name='virtio-scsi-pci.iothread'/>
   <flag name='name-guest'/>
+  <flag name='drive-detect-zeroes'/>
   <version>2005094</version>
   <kvmVersion>0</kvmVersion>
   <package></package>
diff --git a/tests/qemucapabilitiesdata/caps_2.6.0-gicv3.aarch64.xml b/tests/qemucapabilitiesdata/caps_2.6.0-gicv3.aarch64.xml
index d65523ee285f..7c0dcf6b218b 100644
--- a/tests/qemucapabilitiesdata/caps_2.6.0-gicv3.aarch64.xml
+++ b/tests/qemucapabilitiesdata/caps_2.6.0-gicv3.aarch64.xml
@@ -155,6 +155,7 @@
   <flag name='nec-usb-xhci-ports'/>
   <flag name='virtio-scsi-pci.iothread'/>
   <flag name='name-guest'/>
+  <flag name='drive-detect-zeroes'/>
   <version>2005094</version>
   <kvmVersion>0</kvmVersion>
   <package></package>
diff --git a/tests/qemucapabilitiesdata/caps_2.6.0.ppc64le.xml b/tests/qemucapabilitiesdata/caps_2.6.0.ppc64le.xml
index 771d20954387..8438deb3d6d4 100644
--- a/tests/qemucapabilitiesdata/caps_2.6.0.ppc64le.xml
+++ b/tests/qemucapabilitiesdata/caps_2.6.0.ppc64le.xml
@@ -149,6 +149,7 @@
   <flag name='nec-usb-xhci-ports'/>
   <flag name='virtio-scsi-pci.iothread'/>
   <flag name='name-guest'/>
+  <flag name='drive-detect-zeroes'/>
   <version>2005094</version>
   <kvmVersion>0</kvmVersion>
   <package></package>
diff --git a/tests/qemucapabilitiesdata/caps_2.6.0.x86_64.xml b/tests/qemucapabilitiesdata/caps_2.6.0.x86_64.xml
index 8af08943693f..68d14b207be2 100644
--- a/tests/qemucapabilitiesdata/caps_2.6.0.x86_64.xml
+++ b/tests/qemucapabilitiesdata/caps_2.6.0.x86_64.xml
@@ -188,6 +188,7 @@
   <flag name='nec-usb-xhci-ports'/>
   <flag name='virtio-scsi-pci.iothread'/>
   <flag name='name-guest'/>
+  <flag name='drive-detect-zeroes'/>
   <version>2006000</version>
   <kvmVersion>0</kvmVersion>
   <package></package>
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-detect-zeroes.args b/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-detect-zeroes.args
new file mode 100644
index 000000000000..f55786458efe
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-detect-zeroes.args
@@ -0,0 +1,27 @@
+LC_ALL=C \
+PATH=/bin \
+HOME=/home/test \
+USER=test \
+LOGNAME=test \
+QEMU_AUDIO_DRV=none \
+/usr/bin/qemu \
+-name test \
+-S \
+-M pc-0.13 \
+-m 1024 \
+-smp 1 \
+-uuid 92d7a226-cfae-425b-a6d3-00bbf9ec5c9e \
+-nographic \
+-nodefaults \
+-monitor unix:/tmp/lib/domain--1-test/monitor.sock,server,nowait \
+-no-acpi \
+-boot dc \
+-usb \
+-drive file=/var/lib/libvirt/images/f14.img,format=qcow2,if=none,\
+id=drive-virtio-disk0,discard=unmap,detect_zeroes=unmap \
+-device virtio-blk-pci,bus=pci.0,addr=0x4,drive=drive-virtio-disk0,\
+id=virtio-disk0 \
+-drive file=/var/lib/libvirt/Fedora-14-x86_64-Live-KDE.iso,format=raw,if=none,\
+media=cdrom,id=drive-ide0-1-0,readonly=on,discard=ignore,detect_zeroes=off \
+-device ide-drive,bus=ide.1,unit=0,drive=drive-ide0-1-0,id=ide0-1-0 \
+-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index db42b7bd71be..67c1b0f71521 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -875,6 +875,9 @@ mymain(void)
             QEMU_CAPS_VIRTIO_BLK_SCSI);
     DO_TEST("disk-drive-discard",
             QEMU_CAPS_DRIVE_DISCARD);
+    DO_TEST("disk-drive-detect-zeroes",
+            QEMU_CAPS_DRIVE_DISCARD,
+            QEMU_CAPS_DRIVE_DETECT_ZEROES);
     DO_TEST("disk-snapshot", NONE);
     DO_TEST_FAILURE("disk-same-targets",
                     QEMU_CAPS_SCSI_LSI,
-- 
2.8.3

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