Updated Branches: refs/heads/qemu-img 2a773af6d -> 500bba834 (forced update)
Replace all convert places by the new QemuImg object Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/500bba83 Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/500bba83 Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/500bba83 Branch: refs/heads/qemu-img Commit: 500bba834ecab8c72357bcd6e58c3703046b9a62 Parents: e9924a8 Author: Wido den Hollander <w...@42on.com> Authored: Thu Feb 14 20:56:22 2013 +0100 Committer: Wido den Hollander <w...@42on.com> Committed: Thu Feb 14 20:56:22 2013 +0100 ---------------------------------------------------------------------- .../kvm/resource/LibvirtComputingResource.java | 18 +++- .../kvm/storage/LibvirtStorageAdaptor.java | 59 ++++++++------- 2 files changed, 43 insertions(+), 34 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/500bba83/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java index 6c3b87d..790691c 100755 --- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java +++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java @@ -56,6 +56,8 @@ import javax.naming.ConfigurationException; import org.apache.log4j.Logger; import org.apache.cloudstack.utils.qemu.QemuImg.PhysicalDiskFormat; +import org.apache.cloudstack.utils.qemu.QemuImg; +import org.apache.cloudstack.utils.qemu.QemuImgFile; import org.libvirt.Connect; import org.libvirt.Domain; import org.libvirt.DomainInfo; @@ -2132,14 +2134,20 @@ ServerResource { } } else { s_logger.debug("Converting RBD disk " + disk.getPath() + " into template " + cmd.getUniqueName()); - Script.runSimpleBashScript("qemu-img convert" - + " -f raw -O qcow2 " - + KVMPhysicalDisk.RBDStringBuilder(primary.getSourceHost(), + + QemuImgFile srcFile = new QemuImgFile(KVMPhysicalDisk.RBDStringBuilder(primary.getSourceHost(), primary.getSourcePort(), primary.getAuthUserName(), primary.getAuthSecret(), - disk.getPath()) - + " " + tmpltPath + "/" + cmd.getUniqueName() + ".qcow2"); + disk.getPath())); + srcFile.setFormat(PhysicalDiskFormat.RAW); + + QemuImgFile destFile = new QemuImgFile(tmpltPath + "/" + cmd.getUniqueName() + ".qcow2"); + destFile.setFormat(PhysicalDiskFormat.QCOW2); + + QemuImg q = new QemuImg(); + q.convert(srcFile, destFile); + File templateProp = new File(tmpltPath + "/template.properties"); if (!templateProp.exists()) { templateProp.createNewFile(); http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/500bba83/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java ---------------------------------------------------------------------- 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 b17633a..6cb6441 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 @@ -607,31 +607,27 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { disk.setSize(template.getVirtualSize()); disk.setVirtualSize(disk.getSize()); - if (srcPool.getType() != StoragePoolType.RBD) { - Script.runSimpleBashScript("qemu-img convert" - + " -f " + template.getFormat() - + " -O " + format - + " " + template.getPath() - + " " + KVMPhysicalDisk.RBDStringBuilder(destPool.getSourceHost(), + QemuImg qemu = new QemuImg(); + QemuImgFile srcFile; + QemuImgFile destFile = new QemuImgFile(KVMPhysicalDisk.RBDStringBuilder(destPool.getSourceHost(), destPool.getSourcePort(), destPool.getAuthUserName(), destPool.getAuthSecret(), disk.getPath())); + destFile.setFormat(format); + + if (srcPool.getType() != StoragePoolType.RBD) { + srcFile = new QemuImgFile(template.getPath(), template.getFormat()); + qemu.convert(srcFile, destFile); } else { template.setFormat(PhysicalDiskFormat.RAW); - Script.runSimpleBashScript("qemu-img convert" - + " -f " + template.getFormat() - + " -O " + format - + " " + KVMPhysicalDisk.RBDStringBuilder(srcPool.getSourceHost(), + srcFile = new QemuImgFile(KVMPhysicalDisk.RBDStringBuilder(srcPool.getSourceHost(), srcPool.getSourcePort(), srcPool.getAuthUserName(), srcPool.getAuthSecret(), - template.getPath()) - + " " + KVMPhysicalDisk.RBDStringBuilder(destPool.getSourceHost(), - destPool.getSourcePort(), - destPool.getAuthUserName(), - destPool.getAuthSecret(), - disk.getPath())); + template.getPath())); + srcFile.setFormat(template.getFormat()); + qemu.convert(srcFile, destFile); } } return disk; @@ -690,39 +686,44 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { PhysicalDiskFormat sourceFormat = disk.getFormat(); PhysicalDiskFormat destFormat = newDisk.getFormat(); + QemuImg qemu = new QemuImg(); + QemuImgFile srcFile = null; + QemuImgFile destFile = null; + if ((srcPool.getType() != StoragePoolType.RBD) && (destPool.getType() != StoragePoolType.RBD)) { 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); + srcFile = new QemuImgFile(sourcePath, sourceFormat); + destFile = new QemuImgFile(destPath, destFormat); } } else if ((srcPool.getType() != StoragePoolType.RBD) && (destPool.getType() == StoragePoolType.RBD)) { - Script.runSimpleBashScript("qemu-img convert -f " + sourceFormat - + " -O " + destFormat - + " " + sourcePath - + " " + KVMPhysicalDisk.RBDStringBuilder(destPool.getSourceHost(), + srcFile = new QemuImgFile(sourcePath, sourceFormat); + destFile = new QemuImgFile(KVMPhysicalDisk.RBDStringBuilder(destPool.getSourceHost(), destPool.getSourcePort(), destPool.getAuthUserName(), destPool.getAuthSecret(), destPath)); + destFile.setFormat(destFormat); } else { - Script.runSimpleBashScript("qemu-img convert -f " + sourceFormat - + " -O " + destFormat - + " " + KVMPhysicalDisk.RBDStringBuilder(srcPool.getSourceHost(), + srcFile = new QemuImgFile(KVMPhysicalDisk.RBDStringBuilder(srcPool.getSourceHost(), srcPool.getSourcePort(), srcPool.getAuthUserName(), srcPool.getAuthSecret(), - sourcePath) - + " " + KVMPhysicalDisk.RBDStringBuilder(destPool.getSourceHost(), + sourcePath)); + srcFile.setFormat(sourceFormat); + destFile = new QemuImgFile(KVMPhysicalDisk.RBDStringBuilder(destPool.getSourceHost(), destPool.getSourcePort(), destPool.getAuthUserName(), destPool.getAuthSecret(), destPath)); + destFile.setFormat(destFormat); + } + + if (srcFile != null && destFile != null) { + qemu.convert(srcFile, destFile); } return newDisk;