Change in vdsm[master]: use qemu-img convert to copy sparse volumes when moving a vm

ykaplan at redhat.com ykaplan at redhat.com
Mon Jan 14 13:28:25 UTC 2013


Yeela Kaplan has uploaded a new change for review.

Change subject: use qemu-img convert to copy sparse volumes when moving a vm
......................................................................

use qemu-img convert to copy sparse volumes when moving a vm

Previously all volumes were copied with dd, with sparse files this
would result in the destination volume being fully allocated.

Change-Id: I9eedaa41a64502e548e52c10742335abd05301d8
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=748386
Signed-off-by: Yeela Kaplan <ykaplan at redhat.com>
---
M vdsm/qemuImg.py
M vdsm/storage/image.py
2 files changed, 41 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/79/10979/1

diff --git a/vdsm/qemuImg.py b/vdsm/qemuImg.py
index 77befcf..297ad53 100644
--- a/vdsm/qemuImg.py
+++ b/vdsm/qemuImg.py
@@ -19,10 +19,11 @@
 #
 
 import re
+from storage import misc
 from utils import CommandPath, execCmd
 
 _qemuimg = CommandPath("qemu-img",
-                       "/usr/bin/qemu-img",  # Fedora, RHEL
+                       "/usr/bin/qemu-img",  # Fedora, EL6
                        )
 
 
@@ -98,3 +99,26 @@
 
     if rc != 0:
         raise QImgError(rc, out, err)
+
+
+def convert(srcVolPath, dstVolPath, stop, srcFmt=None, dstFmt=None):
+    cmd = [_qemuimg.cmd, "convert", "-t", "none"]
+
+    if srcFmt:
+        cmd.extend(("-f", srcFmt))
+
+    cmd.append(srcVolPath)
+
+    if dstFmt:
+        cmd.extend(("-O", dstFmt))
+
+    cmd.append(dstVolPath)
+
+    (rc, out, err) = misc.watchCmd(cmd, stop=stop,
+                                   nice=misc.NICENESS.LOW,
+                                   ioclass=misc.IOCLASS.IDLE)
+
+    if rc != 0:
+        raise QImgError(rc, out, err)
+
+    return (rc, out, err)
diff --git a/vdsm/storage/image.py b/vdsm/storage/image.py
index 4364c38..411b234 100644
--- a/vdsm/storage/image.py
+++ b/vdsm/storage/image.py
@@ -25,6 +25,7 @@
 from contextlib import contextmanager
 
 import volume
+from vdsm import qemuImg
 from sdc import sdCache
 import sd
 import misc
@@ -582,8 +583,21 @@
                 # Do the actual copy
                 try:
                     dstVol = destDom.produceVolume(imgUUID=imgUUID, volUUID=srcVol.volUUID)
-                    srcSize = srcVol.getVolumeSize(bs=1)
-                    misc.ddWatchCopy(srcVol.getVolumePath(), dstVol.getVolumePath(), vars.task.aborting, size=srcSize)
+                    srcFmt = srcVol.getFormat()
+                    if srcFmt == volume.RAW_FORMAT:
+                        srcFmt = volume.fmt2str(srcFmt)
+                        dstFmt = volume.fmt2str(dstVol.getFormat())
+                        self.log.debug("start qemu convert")
+                        qemuImg.convert(srcVol.getVolumePath(),
+                                        dstVol.getVolumePath(),
+                                        vars.task.aborting,
+                                        srcFmt, dstFmt)
+                    else:
+                        srcSize = srcVol.getVolumeSize(bs=1)
+                        misc.ddWatchCopy(srcVol.getVolumePath(),
+                                         dstVol.getVolumePath(),
+                                         vars.task.aborting,
+                                         size=srcSize)
                 except se.ActionStopped:
                     raise
                 except se.StorageException:


--
To view, visit http://gerrit.ovirt.org/10979
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9eedaa41a64502e548e52c10742335abd05301d8
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Yeela Kaplan <ykaplan at redhat.com>


More information about the vdsm-patches mailing list