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 <marcus@betterservers.com> 1354755241 -0700
This commit is contained in:
Marcus Sorensen 2012-12-05 17:54:01 -07:00
parent a91df8f32d
commit 7ce2227108
4 changed files with 29 additions and 5 deletions

View File

@ -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

View File

@ -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

View File

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

View File

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