Lee Yarwood has uploaded a new change for review.
Change subject: [WIP] BZ#748386 - refactor qemuConvert to only use qemu-img convert. ......................................................................
[WIP] BZ#748386 - refactor qemuConvert to only use qemu-img convert.
This change refactors the qemuConvert method, dropping the use of dd with RAW volumes in favour of qemu-img convert thus preserving sparseness. The change also introduces the use of the backing_file and backing_fmt options when converting COW volumes.
Change-Id: I7adc41e8a9f5d4b9faa58a8cf5bec685b66e303e Signed-off-by: Lee Yarwood lyarwood@redhat.com --- M vdsm/storage/image.py M vdsm/storage/volume.py 2 files changed, 25 insertions(+), 38 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/28/8728/1
diff --git a/vdsm/storage/image.py b/vdsm/storage/image.py index e86d94c..69ab6b6 100644 --- a/vdsm/storage/image.py +++ b/vdsm/storage/image.py @@ -788,19 +788,9 @@
try: # Start the actual copy image procedure - srcVol.prepare(rw=False) + srcVol.prepare(rw=True, chainrw=True, setrw=True) dstVol.prepare(rw=True, setrw=True) - - try: - (rc, out, err) = volume.qemuConvert(volParams['path'], dstPath, - volParams['volFormat'], dstVolFormat, vars.task.aborting, - size=srcVol.getVolumeSize(bs=1), dstvolType=dstVol.getType()) - if rc: - raise se.StorageException("rc: %s, err: %s" % (rc, err)) - except se.ActionStopped, e: - raise e - except se.StorageException, e: - raise se.CopyImageError(str(e)) + (rc, out, err) = volume.qemuConvert(srcVol, dstVol, self.idle, vars.task.aborting)
# Mark volume as SHARED if volType == volume.SHARED_VOL: @@ -997,12 +987,12 @@
# Step 2: Convert successor to new volume # qemu-img convert -f qcow2 successor -O raw newUUID - (rc, out, err) = volume.qemuConvert(srcVolParams['path'], newVol.getVolumePath(), - srcVolParams['volFormat'], volParams['volFormat'], vars.task.aborting, - size=volParams['apparentsize'], dstvolType=newVol.getType()) - if rc: - self.log.error("qemu-img convert failed: rc=%s, out=%s, err=%s", - rc, out, err) + try: + (rc, out, err) = volume.qemuConvert(srcVol, newVol, self.idle, vars.task.aborting) + except se.ActionStopped: + raise + except se.StorageException: + self.log.error("Unexpected error", exc_info=True) raise se.MergeSnapshotsError(newUUID)
newVol.teardown(sdUUID=newVol.sdUUID, volUUID=newVol.volUUID) diff --git a/vdsm/storage/volume.py b/vdsm/storage/volume.py index b9eb356..875b59a 100644 --- a/vdsm/storage/volume.py +++ b/vdsm/storage/volume.py @@ -960,28 +960,25 @@ log.debug('(qemuRebase): REBASE %s DONE' % (src)) return (rc, out, err)
+def qemuConvert(src, dst, idle, stop): + """ + Copy the src image into the new dst. + """ + cmd = constants.CMD_LOWPRIO + [constants.EXT_QEMUIMG, "convert", "-t", "none", + "-f", fmt2str(src.getFormat()), "-O", fmt2str(dst.getFormat())]
-def qemuConvert(src, dst, src_fmt, dst_fmt, stop, size, dstvolType): - """ - Convert the 'src' image (or chain of images) into a new single 'dst' - """ - src_fmt = fmt2str(src_fmt) - dst_fmt = fmt2str(dst_fmt) - log.debug('(qemuConvert): COPY %s (%s) to %s (%s) START' % - (src, src_fmt, dst, dst_fmt)) + # backing_file only used when src has a parent and both volumes are COW. + if src.getParentVolume() and src.getFormat() == COW_FORMAT and dst.getFormat() == COW_FORMAT : + cmd += ["-o", "backing_file=%s,backing_fmt=%s" % (src.getParentVolume().getVolumePath(), + fmt2str(src.getParentVolume().getFormat()))]
- if (src_fmt == "raw" and dst_fmt == "raw" and - dstvolType == PREALLOCATED_VOL): - (rc, out, err) = misc.ddWatchCopy( - src=src, dst=dst, - stop=stop, size=size, - recoveryCallback=baseAsyncTasksRollback) - else: - cmd = constants.CMD_LOWPRIO + [constants.EXT_QEMUIMG, "convert", - "-t", "none", "-f", src_fmt, src, - "-O", dst_fmt, dst] - (rc, out, err) = misc.watchCmd(cmd, stop=stop, + cmd += [src.getVolumePath(), dst.getVolumePath()] + + (rc, out, err) = misc.watchCmd(cmd, stop=stop, idle=idle, sudo=False, recoveryCallback=baseAsyncTasksRollback)
- log.debug('(qemuConvert): COPY %s to %s DONE' % (src, dst)) + if rc: + raise se.StorageException + return (rc, out, err) +
-- To view, visit http://gerrit.ovirt.org/8728 To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange Gerrit-Change-Id: I7adc41e8a9f5d4b9faa58a8cf5bec685b66e303e Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Lee Yarwood lyarwood@redhat.com