diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java index af6026b6f8c..70b5bf0b225 100755 --- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java +++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java @@ -3954,10 +3954,13 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa relocateSpec.setDatastore(morDsAtSource); isFirstDs = false; } - srcDiskName = String.format("[%s] %s.vmdk", srcDsName, volume.getPath()); + srcDiskName = VmwareStorageLayoutHelper.getVmwareDatastorePathFromVmdkFileName( + new DatastoreMO(srcHyperHost.getContext(), morDsAtSource), + vmName, + volume.getPath() + ".vmdk"); diskLocator = new VirtualMachineRelocateSpecDiskLocator(); diskLocator.setDatastore(morDsAtSource); - diskLocator.setDiskId(getVirtualDiskInfo(vmMo, srcDiskName)); + diskLocator.setDiskId(getVirtualDiskInfo(vmMo, volume.getPath() + ".vmdk")); diskLocators.add(diskLocator); @@ -4075,10 +4078,12 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa throw new Exception(msg); } - srcDiskName = String.format("[%s] %s.vmdk", srcDsName, volumePath); + srcDiskName = VmwareStorageLayoutHelper.getVmwareDatastorePathFromVmdkFileName( + new DatastoreMO(srcHyperHost.getContext(), morDs), vmName, + volumePath + ".vmdk"); diskLocator = new VirtualMachineRelocateSpecDiskLocator(); diskLocator.setDatastore(morDs); - diskLocator.setDiskId(getVirtualDiskInfo(vmMo, srcDiskName)); + diskLocator.setDiskId(getVirtualDiskInfo(vmMo, volumePath + ".vmdk")); diskLocators.add(diskLocator); relocateSpec.getDisk().add(diskLocator); diff --git a/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageLayoutHelper.java b/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageLayoutHelper.java index b41b72a5e32..c61f15e2b4c 100644 --- a/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageLayoutHelper.java +++ b/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageLayoutHelper.java @@ -64,6 +64,29 @@ public class VmwareStorageLayoutHelper { return null; } + public static String findVolumeDatastoreFullPath(DatastoreMO dsMo, String vmName, String vmdkFileName) throws Exception { + if(vmName != null) { + String path = getVmwareDatastorePathFromVmdkFileName(dsMo, vmName, vmdkFileName); + if(!dsMo.fileExists(path)) { + path = getLegacyDatastorePathFromVmdkFileName(dsMo, vmdkFileName); + + // to save one call to vCenter, we won't check file existence for this round, so the caller + // may still fail with exception, but if that's case, we will let it fail anyway + } + return path; + } else { + String path = getLegacyDatastorePathFromVmdkFileName(dsMo, vmdkFileName); + if(!dsMo.fileExists(path)) { + // Datastore file movement is not atomic operations, we need to sync and repair + path = dsMo.searchFileInSubFolders(vmdkFileName, false); + + // to save one call to vCenter, we won't check file existence for this round, so the caller + // may still fail with exception, but if that's case, we will let it fail anyway + } + return path; + } + } + public static String syncVolumeToVmDefaultFolder(DatacenterMO dcMo, String vmName, DatastoreMO ds, String vmdkName) throws Exception {