Re: [PATCH 04/14] conf: Extract logic for updating 'detect_zeroes' mode

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

 



On Thu, Mar 29, 2018 at 01:51:01PM +0200, Peter Krempa wrote:
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@xxxxxxxxxx>
---
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.

Ah, that makes it okay.

+ */
+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/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) {

If you created an "accessor" for it, it should be used in the above
condition as well.

ACK

Jano

Attachment: signature.asc
Description: Digital signature

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

  Powered by Linux