From 7ce2227108dd0ffe9d2f7bd75ab1b36190053266 Mon Sep 17 00:00:00 2001 From: Marcus Sorensen Date: Wed, 5 Dec 2012 17:54:01 -0700 Subject: [PATCH] Summary: master - Copy qcow2 instead of converting if source and dest are qcow2 Detail: If source image is qcow2, and we want a qcow2 image, then doing a convert strips off compression and any snapshots the user had in that image. If a backing file exists, we stick with convert so we can pull in both the backing file and the COW image, otherwise we just cp the qcow2 file. This is also faster Signed-off-by: Marcus Sorensen 1354755241 -0700 --- .../kvm/storage/LibvirtStorageAdaptor.java | 14 ++++++++++---- scripts/storage/qcow2/create_private_template.sh | 8 +++++++- scripts/storage/qcow2/createtmplt.sh | 6 ++++++ scripts/storage/qcow2/createvolume.sh | 6 ++++++ 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java index 6c55743696d..2a603cb0f47 100644 --- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java +++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java @@ -688,10 +688,16 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { PhysicalDiskFormat destFormat = newDisk.getFormat(); if ((srcPool.getType() != StoragePoolType.RBD) && (destPool.getType() != StoragePoolType.RBD)) { - Script.runSimpleBashScript("qemu-img convert -f " + sourceFormat - + " -O " + destFormat - + " " + sourcePath - + " " + destPath); + if (sourceFormat.equals(destFormat) && + Script.runSimpleBashScript("qemu-img info " + sourcePath + "|grep backing") == null) { + Script.runSimpleBashScript("cp -f " + sourcePath + " " + destPath); + + } else { + Script.runSimpleBashScript("qemu-img convert -f " + sourceFormat + + " -O " + destFormat + + " " + sourcePath + + " " + destPath); + } } else if ((srcPool.getType() != StoragePoolType.RBD) && (destPool.getType() == StoragePoolType.RBD)) { Script.runSimpleBashScript("qemu-img convert -f " + sourceFormat + " -O " + destFormat diff --git a/scripts/storage/qcow2/create_private_template.sh b/scripts/storage/qcow2/create_private_template.sh index 4b93380bc52..8e9e26c4104 100755 --- a/scripts/storage/qcow2/create_private_template.sh +++ b/scripts/storage/qcow2/create_private_template.sh @@ -31,7 +31,13 @@ create_template() { local fspath=$1 local destpath=$2 - qemu-img convert -O qcow2 /$fspath $destpath + # if backing image exists, we need to combine them, otherwise + # copy the image to preserve snapshots/compression + if $qemu_img info "$tmpltimg" | grep -q backing; then + qemu-img convert -O qcow2 /$fspath $destpath + else + cp -f /$fspath $destpath + fi if [ $? -gt 0 ]; then printf " Failed to export template $destpath\n" >&2 diff --git a/scripts/storage/qcow2/createtmplt.sh b/scripts/storage/qcow2/createtmplt.sh index 84d2ba80b8c..152268f651a 100755 --- a/scripts/storage/qcow2/createtmplt.sh +++ b/scripts/storage/qcow2/createtmplt.sh @@ -100,7 +100,13 @@ create_from_file() { if [ -b $tmpltimg ]; then $qemu_img convert -f raw -O qcow2 "$tmpltimg" /$tmpltfs/$tmpltname else + # if backing image exists, we need to combine them, otherwise + # copy the image to preserve snapshots/compression + if $qemu_img info "$tmpltimg" | grep -q backing; then $qemu_img convert -f qcow2 -O qcow2 "$tmpltimg" /$tmpltfs/$tmpltname >& /dev/null + else + cp -f $tmpltimg /$tmpltfs/$tmpltname + fi fi if [ "$cleanup" == "true" ] diff --git a/scripts/storage/qcow2/createvolume.sh b/scripts/storage/qcow2/createvolume.sh index 10fa6dd617b..527aa68db28 100755 --- a/scripts/storage/qcow2/createvolume.sh +++ b/scripts/storage/qcow2/createvolume.sh @@ -101,7 +101,13 @@ create_from_file() { if [ -b $volimg ]; then $qemu_img convert -f raw -O qcow2 "$volimg" /$volfs/$volname else + # if backing image exists, we need to combine them, otherwise + # copy the image to preserve snapshots/compression + if $qemu_img info "$volimg" | grep -q backing; then $qemu_img convert -f qcow2 -O qcow2 "$volimg" /$volfs/$volname >& /dev/null + else + cp -f $volimg /$volfs/$volname + fi fi if [ "$cleanup" == "true" ]