For some reason we've decided to silently translate the disk
detect_zeroes mode if it would be invalid. Extract the
logic so that it does not need to be copypasta'd across the code base.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/conf/domain_conf.c | 22 ++++++++++++++++++++++
src/conf/domain_conf.h | 3 +++
src/libvirt_private.syms | 1 +
src/qemu/qemu_command.c | 15 ++-------------
4 files changed, 28 insertions(+), 13 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index ac3a3d9966..ef16431aaf 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -29362,3 +29362,25 @@ virDomainDiskTranslateSourcePool(virDomainDiskDefPtr def)
virStoragePoolDefFree(pooldef);
return ret;
}
+
+
+/**
+ * virDomainDiskGetDetectZeroesMode:
+ * @discard: disk/image sector discard setting
+ * @detect_zeroes: disk/image zero sector detection mode
+ *
+ * As a convenience syntax, if discards are ignored and zero detection is set
+ * to 'unmap', then simply behave like zero detection is set to 'on'.
But
+ * don't change it in the XML for easier adjustments. This behaviour is
+ * documented.
+ */
+int
+virDomainDiskGetDetectZeroesMode(virDomainDiskDiscard discard,
+ virDomainDiskDetectZeroes detect_zeroes)
+{
+ if (discard != VIR_DOMAIN_DISK_DISCARD_UNMAP &&
+ detect_zeroes == VIR_DOMAIN_DISK_DETECT_ZEROES_UNMAP)
+ return VIR_DOMAIN_DISK_DETECT_ZEROES_ON;
+
+ return detect_zeroes;
+}
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 650901c1f4..bd17bd99ae 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -3528,5 +3528,8 @@ virDomainNetResolveActualType(virDomainNetDefPtr iface)
int virDomainDiskTranslateSourcePool(virDomainDiskDefPtr def);
+int
+virDomainDiskGetDetectZeroesMode(virDomainDiskDiscard discard,
+ virDomainDiskDetectZeroes detect_zeroes);
#endif /* __DOMAIN_CONF_H */
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 96a0a6de52..8d5509a8a8 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -326,6 +326,7 @@ virDomainDiskErrorPolicyTypeToString;
virDomainDiskFindByBusAndDst;
virDomainDiskGeometryTransTypeFromString;
virDomainDiskGeometryTransTypeToString;
+virDomainDiskGetDetectZeroesMode;
virDomainDiskGetDriver;
virDomainDiskGetFormat;
virDomainDiskGetSource;
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 89fd08b642..6a13714eae 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -1729,6 +1729,8 @@ qemuBuildDriveStr(virDomainDiskDefPtr disk,
virQEMUCapsPtr qemuCaps)
{
virBuffer opt = VIR_BUFFER_INITIALIZER;
+ int detect_zeroes = virDomainDiskGetDetectZeroesMode(disk->discard,
+ disk->detect_zeroes);
if (qemuBuildDriveSourceStr(disk, qemuCaps, &opt) < 0)
goto error;
@@ -1809,19 +1811,6 @@ qemuBuildDriveStr(virDomainDiskDefPtr disk,
}
if (disk->detect_zeroes) {
- int detect_zeroes = disk->detect_zeroes;
-
- /*
- * As a convenience syntax, if discards are ignored and
- * zero detection is set to 'unmap', then simply behave
- * like zero detection is set to 'on'. But don't change
- * it in the XML for easier adjustments. This behaviour
- * is documented.
- */
- if (disk->discard != VIR_DOMAIN_DISK_DISCARD_UNMAP &&
- detect_zeroes == VIR_DOMAIN_DISK_DETECT_ZEROES_UNMAP)
- detect_zeroes = VIR_DOMAIN_DISK_DETECT_ZEROES_ON;
-
virBufferAsprintf(&opt, ",detect-zeroes=%s",
virDomainDiskDetectZeroesTypeToString(detect_zeroes));
}
--
2.16.2