From bba9801cf7ef1eb65a730b45140bf5af0d978741 Mon Sep 17 00:00:00 2001 From: Wido den Hollander Date: Tue, 27 Aug 2013 18:33:46 +0200 Subject: [PATCH] CLOUDSTACK-4423: Do not always append .qcow2 to volume names when copying Disk images are not always in the QCOW2 format, so don't assume that the filename will always and in .qcow2 (cherry picked from commit 93b40b0ca6a796ffbacd80c40897f6ada6284bc4) Signed-off-by: animesh --- .../cloud/hypervisor/kvm/storage/KVMStorageProcessor.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java index fd5c9d9ff32..8482a8d25dc 100644 --- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java +++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java @@ -319,6 +319,8 @@ public class KVMStorageProcessor implements StorageProcessor { DataTO destData = cmd.getDestTO(); DataStoreTO srcStore = srcData.getDataStore(); DataStoreTO destStore = destData.getDataStore(); + VolumeObjectTO srcVol = (VolumeObjectTO) srcData; + ImageFormat srcFormat = srcVol.getFormat(); PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO) destStore; if (!(srcStore instanceof NfsTO)) { return new CopyCmdAnswer("can only handle nfs storage"); @@ -352,14 +354,16 @@ public class KVMStorageProcessor implements StorageProcessor { secondaryStoragePool = storagePoolMgr.getStoragePoolByURI( secondaryStorageUrl + File.separator + volumeDir ); - if (!srcVolumeName.endsWith(".qcow2")) { + if (!srcVolumeName.endsWith(".qcow2") && srcFormat == ImageFormat.QCOW2) { srcVolumeName = srcVolumeName + ".qcow2"; } KVMPhysicalDisk volume = secondaryStoragePool .getPhysicalDisk(srcVolumeName); - storagePoolMgr.copyPhysicalDisk(volume, volumeName, + volume.setFormat(PhysicalDiskFormat.valueOf(srcFormat.toString())); + KVMPhysicalDisk newDisk = storagePoolMgr.copyPhysicalDisk(volume, volumeName, primaryPool); VolumeObjectTO newVol = new VolumeObjectTO(); + newVol.setFormat(ImageFormat.valueOf(newDisk.getFormat().toString().toUpperCase())); newVol.setPath(volumeName); return new CopyCmdAnswer(newVol); } catch (CloudRuntimeException e) {