[PATCH v2 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                       |  2 ++
 src/qemu/qemu_capabilities.h                       |  1 +
 src/qemu/qemu_command.c                            | 11 +++++++++
 tests/qemucapabilitiesdata/caps_2.1.1-1.caps       |  1 +
 tests/qemucapabilitiesdata/caps_2.4.0-1.caps       |  1 +
 tests/qemucapabilitiesdata/caps_2.5.0-1.caps       |  1 +
 tests/qemucapabilitiesdata/caps_2.6.0-1.caps       |  1 +
 .../qemuxml2argv-disk-drive-detect-zeroes.args     | 27 ++++++++++++++++++++++
 tests/qemuxml2argvtest.c                           |  3 +++
 9 files changed, 48 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 1018d6c3cf3c..400c5ed21174 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -315,6 +315,7 @@ VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST,
               "vserport-change-event", /* 210 */
               "virtio-balloon-pci.deflate-on-oom",
               "mptsas1068",
+              "drive-detect-zeroes",
     );


@@ -2616,6 +2617,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 b73c529e768a..5fcabe6d3e83 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -344,6 +344,7 @@ typedef enum {
     QEMU_CAPS_VIRTIO_BALLOON_AUTODEFLATE, /* virtio-balloon-{device,pci,ccw}.
                                            * deflate-on-oom */
     QEMU_CAPS_SCSI_MPTSAS1068, /* -device mptsas1068 */
+    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 78423e7046d9..5b68f0052728 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -1280,6 +1280,17 @@ qemuBuildDriveStr(virConnectPtr conn,
         }
     }

+    if (disk->detect_zeroes) {
+        if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DRIVE_DETECT_ZEROES)) {
+            virBufferAsprintf(&opt, ",detect_zeroes=%s",
+                              virDomainDiskDetectZerosTypeToString(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-1.caps b/tests/qemucapabilitiesdata/caps_2.1.1-1.caps
index 332b85abeb2e..76b9ff4f4ed2 100644
--- a/tests/qemucapabilitiesdata/caps_2.1.1-1.caps
+++ b/tests/qemucapabilitiesdata/caps_2.1.1-1.caps
@@ -160,4 +160,5 @@
     <flag name='e1000'/>
     <flag name='virtio-net'/>
     <flag name='vserport-change-event'/>
+    <flag name='drive-detect-zeroes'/>
   </qemuCaps>
diff --git a/tests/qemucapabilitiesdata/caps_2.4.0-1.caps b/tests/qemucapabilitiesdata/caps_2.4.0-1.caps
index e41154276291..617e2c6bcfdd 100644
--- a/tests/qemucapabilitiesdata/caps_2.4.0-1.caps
+++ b/tests/qemucapabilitiesdata/caps_2.4.0-1.caps
@@ -171,4 +171,5 @@
     <flag name='ich9-disable-s4'/>
     <flag name='vserport-change-event'/>
     <flag name='virtio-balloon-pci.deflate-on-oom'/>
+    <flag name='drive-detect-zeroes'/>
   </qemuCaps>
diff --git a/tests/qemucapabilitiesdata/caps_2.5.0-1.caps b/tests/qemucapabilitiesdata/caps_2.5.0-1.caps
index 931bc4fbcc58..0ba45105a6ac 100644
--- a/tests/qemucapabilitiesdata/caps_2.5.0-1.caps
+++ b/tests/qemucapabilitiesdata/caps_2.5.0-1.caps
@@ -172,4 +172,5 @@
     <flag name='ich9-disable-s4'/>
     <flag name='vserport-change-event'/>
     <flag name='virtio-balloon-pci.deflate-on-oom'/>
+    <flag name='drive-detect-zeroes'/>
   </qemuCaps>
diff --git a/tests/qemucapabilitiesdata/caps_2.6.0-1.caps b/tests/qemucapabilitiesdata/caps_2.6.0-1.caps
index f32d5aaa4742..0d417c533801 100644
--- a/tests/qemucapabilitiesdata/caps_2.6.0-1.caps
+++ b/tests/qemucapabilitiesdata/caps_2.6.0-1.caps
@@ -174,4 +174,5 @@
     <flag name='ich9-disable-s4'/>
     <flag name='vserport-change-event'/>
     <flag name='virtio-balloon-pci.deflate-on-oom'/>
+    <flag name='drive-detect-zeroes'/>
   </qemuCaps>
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..5aecc4190bb6
--- /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/test-monitor,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,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 854623dbe249..e8db7eccd2c4 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -888,6 +888,9 @@ mymain(void)
             QEMU_CAPS_VIRTIO_BLK_SCSI, QEMU_CAPS_VIRTIO_BLK_SG_IO);
     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.7.1

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