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