Signed-off-by: Martin Kletzander <mkletzan(a)redhat.com>
---
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 de5478879d1b..cff70c25fe8e 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -325,6 +325,7 @@ VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST,
"pxb",
"pxb-pcie", /* 220 */
+ "drive-detect-zeroes",
);
@@ -2635,6 +2636,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 83b8be314a29..e7881aa517f8 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -356,6 +356,7 @@ typedef enum {
/* 220 */
QEMU_CAPS_DEVICE_PXB_PCIE, /* -device pxb-pcie */
+ 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 6fbfe215bf29..d4614278213e 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -1328,6 +1328,17 @@ qemuBuildDriveStr(virConnectPtr conn,
}
}
+ 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-1.caps
b/tests/qemucapabilitiesdata/caps_2.1.1-1.caps
index 8175743fd2b0..be5fc8e22fb8 100644
--- a/tests/qemucapabilitiesdata/caps_2.1.1-1.caps
+++ b/tests/qemucapabilitiesdata/caps_2.1.1-1.caps
@@ -162,4 +162,5 @@
<flag name='qxl.vram64_size_mb'/>
<flag name='qxl-vga.vram64_size_mb'/>
<flag name='debug-threads'/>
+ <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 2cdf961eabfa..b31de2fd67cf 100644
--- a/tests/qemucapabilitiesdata/caps_2.4.0-1.caps
+++ b/tests/qemucapabilitiesdata/caps_2.4.0-1.caps
@@ -174,4 +174,5 @@
<flag name='qxl-vga.vram64_size_mb'/>
<flag name='debug-threads'/>
<flag name='pxb'/>
+ <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 ecaa165f7fa3..012d672b38e4 100644
--- a/tests/qemucapabilitiesdata/caps_2.5.0-1.caps
+++ b/tests/qemucapabilitiesdata/caps_2.5.0-1.caps
@@ -175,4 +175,5 @@
<flag name='qxl-vga.vram64_size_mb'/>
<flag name='debug-threads'/>
<flag name='pxb'/>
+ <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 e243f8a92f0b..11b087a3eeb1 100644
--- a/tests/qemucapabilitiesdata/caps_2.6.0-1.caps
+++ b/tests/qemucapabilitiesdata/caps_2.6.0-1.caps
@@ -180,4 +180,5 @@
<flag name='secret'/>
<flag name='pxb'/>
<flag name='pxb-pcie'/>
+ <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..b19dfb7a8387
--- /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,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 8842b2fb268e..e713e550c1c3 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -854,6 +854,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.8.1