Change in vdsm[ovirt-3.5]: qemu-img: check/use "-T src_cache" option in convert/rebase ...

apahim at redhat.com apahim at redhat.com
Thu Mar 5 17:26:56 UTC 2015


Hello Nir Soffer, Federico Simoncelli,

I'd like you to do a code review.  Please visit

    https://gerrit.ovirt.org/38434

to review the following change.

Change subject: qemu-img: check/use "-T src_cache" option in convert/rebase when available
......................................................................

qemu-img: check/use "-T src_cache" option in convert/rebase when available

"qemu-img" is used for operations like disk move or snapshot delete.
This process reads data using the hypervisor page cache. As this data might
be hotter than any VM memory the system starts swapping out memory pages of
the running VMs.

vdsm already uses "-t none" option to avoid cache for output image. Now
"qemu-img" introduced a new "-T src_cache" to avoid cache for the
input image (bz#1116558).

This patch is testing if qemu-img has the new "-T src_cache" option available
for convert and rebase commands and using it with "-T none" when true.

Change-Id: I6e07f182e880f79055e53ef47aa28ddcf9659c45
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1138690
Signed-off-by: Amador Pahim <apahim at redhat.com>
Reviewed-on: http://gerrit.ovirt.org/36308
Reviewed-by: Nir Soffer <nsoffer at redhat.com>
Reviewed-by: Federico Simoncelli <fsimonce at redhat.com>
Signed-off-by: Amador Pahim <apahim at redhat.com>
---
M lib/vdsm/qemuimg.py
1 file changed, 29 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/34/38434/1

diff --git a/lib/vdsm/qemuimg.py b/lib/vdsm/qemuimg.py
index 2aa130a..90e5e0f 100644
--- a/lib/vdsm/qemuimg.py
+++ b/lib/vdsm/qemuimg.py
@@ -193,6 +193,9 @@
 def convert(srcImage, dstImage, stop, srcFormat=None, dstFormat=None):
     cmd = [_qemuimg.cmd, "convert", "-t", "none"]
 
+    if _supports_src_cache('convert'):
+        cmd.extend(("-T", "none"))
+
     if srcFormat:
         cmd.extend(("-f", srcFormat))
 
@@ -231,6 +234,9 @@
            stop=None):
     cmd = [_qemuimg.cmd, "rebase", "-t", "none"]
 
+    if _supports_src_cache('rebase'):
+        cmd.extend(("-T", "none"))
+
     if unsafe:
         cmd.extend(("-u",))
 
@@ -249,3 +255,26 @@
 
     if rc != 0:
         raise QImgError(rc, out, err)
+
+
+# Testing capabilities
+
+ at utils.memoized
+def _supports_src_cache(command):
+    """
+    The "-T" option specifies the cache mode that should be used with the
+    source file. This will check if "-T" option is available, aiming to set it
+    to "none", avoiding the use of cache memory (BZ#1138690).
+    """
+    # REQUIRED_FOR: FEDORA 20 (no qemu-img with -T support)
+    cmd = [_qemuimg.cmd, "--help"]
+    rc, out, err = utils.execCmd(cmd, raw=True)
+
+    # REQUIRED_FOR: EL6 (--help returns 1)
+    if rc not in (0, 1):
+        raise QImgError(rc, out, err)
+
+    # Line to match:
+    #   convert [-c] [-p] [-q] [-n] [-f fmt] [-t cache] [-T src_cache]...
+    pattern = r"\n +%s .*\[-T src_cache\]" % command
+    return re.search(pattern, out) is not None


-- 
To view, visit https://gerrit.ovirt.org/38434
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6e07f182e880f79055e53ef47aa28ddcf9659c45
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: ovirt-3.5
Gerrit-Owner: Amador Pahim <apahim at redhat.com>
Gerrit-Reviewer: Federico Simoncelli <fsimonce at redhat.com>
Gerrit-Reviewer: Nir Soffer <nsoffer at redhat.com>


More information about the vdsm-patches mailing list