There is a slight problem here. The parameter in QEMU is called
detect_zeroes, but we use "zeros" a tiny bit more in our code and
documentation. I went with "zeros" to be consistent, but it might
confuse some people. However, the other way around might be as
confusing as this one, but we need to choose one.
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 +
.../qemuxml2argv-disk-drive-detect-zeros.args | 27 ++++++++++++++++++++++
tests/qemuxml2argvtest.c | 4 ++++
8 files changed, 48 insertions(+)
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-drive-detect-zeros.args
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 6e5d203f0667..34a492df4538 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -308,6 +308,7 @@ VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST,
"virtio-tablet", /* 205 */
"virtio-input-host",
+ "drive-detect-zeros",
);
@@ -2590,6 +2591,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_ZEROS },
{ "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 61d637997de1..992aea5c93f7 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -335,6 +335,7 @@ typedef enum {
/* 205 */
QEMU_CAPS_VIRTIO_TABLET, /* -device virtio-tablet-{device,pci} */
QEMU_CAPS_VIRTIO_INPUT_HOST, /* -device virtio-input-host-{device,pci} */
+ QEMU_CAPS_DRIVE_DETECT_ZEROS, /* -drive detect_zeros= */
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 d2f37e408bab..49b76adc416f 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3969,6 +3969,17 @@ qemuBuildDriveStr(virConnectPtr conn,
}
}
+ if (disk->detect_zeros) {
+ if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DRIVE_DETECT_ZEROS)) {
+ virBufferAsprintf(&opt, ",detect_zeros=%s",
+
virDomainDiskDetectZerosTypeToString(disk->detect_zeros));
+ } else {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("detect_zeros 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 1098dcf04044..15c6403a4a04 100644
--- a/tests/qemucapabilitiesdata/caps_2.1.1-1.caps
+++ b/tests/qemucapabilitiesdata/caps_2.1.1-1.caps
@@ -159,4 +159,5 @@
<flag name='rtl8139'/>
<flag name='e1000'/>
<flag name='virtio-net'/>
+ <flag name='drive-detect-zeros'/>
</qemuCaps>
diff --git a/tests/qemucapabilitiesdata/caps_2.4.0-1.caps
b/tests/qemucapabilitiesdata/caps_2.4.0-1.caps
index d67a48df1246..a3c4dc0d30b3 100644
--- a/tests/qemucapabilitiesdata/caps_2.4.0-1.caps
+++ b/tests/qemucapabilitiesdata/caps_2.4.0-1.caps
@@ -167,4 +167,5 @@
<flag name='virtio-mouse'/>
<flag name='virtio-tablet'/>
<flag name='virtio-input-host'/>
+ <flag name='drive-detect-zeros'/>
</qemuCaps>
diff --git a/tests/qemucapabilitiesdata/caps_2.5.0-1.caps
b/tests/qemucapabilitiesdata/caps_2.5.0-1.caps
index f4f3673c50b9..1281d23a2536 100644
--- a/tests/qemucapabilitiesdata/caps_2.5.0-1.caps
+++ b/tests/qemucapabilitiesdata/caps_2.5.0-1.caps
@@ -168,4 +168,5 @@
<flag name='virtio-mouse'/>
<flag name='virtio-tablet'/>
<flag name='virtio-input-host'/>
+ <flag name='drive-detect-zeros'/>
</qemuCaps>
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-detect-zeros.args
b/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-detect-zeros.args
new file mode 100644
index 000000000000..5224a69798b2
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-detect-zeros.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,if=none,id=drive-virtio-disk0,\
+format=qcow2,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,if=none,media=cdrom,\
+id=drive-ide0-1-0,format=raw,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 37f806edd3c0..e61553526ed2 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -880,6 +880,10 @@ mymain(void)
DO_TEST("disk-drive-discard",
QEMU_CAPS_DRIVE_DISCARD,
QEMU_CAPS_DEVICE);
+ DO_TEST("disk-drive-discard",
+ QEMU_CAPS_DRIVE_DISCARD,
+ QEMU_CAPS_DRIVE_DETECT_ZEROS,
+ QEMU_CAPS_DEVICE);
DO_TEST("disk-snapshot", NONE);
DO_TEST_FAILURE("disk-same-targets",
QEMU_CAPS_DEVICE, QEMU_CAPS_SCSI_LSI,
--
2.6.4