Skip to content

Commit c6dfb33

Browse files
committed
CLOUDSTACK-3237: pass disk file name instead of full datastore path when setting up storage relocation specin order to safely locate the disk device
1 parent dbe4e13 commit c6dfb33

2 files changed

Lines changed: 32 additions & 4 deletions

File tree

‎plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3954,10 +3954,13 @@ protected Answer execute(MigrateWithStorageCommand cmd) {
39543954
relocateSpec.setDatastore(morDsAtSource);
39553955
isFirstDs = false;
39563956
}
3957-
srcDiskName = String.format("[%s] %s.vmdk", srcDsName, volume.getPath());
3957+
srcDiskName = VmwareStorageLayoutHelper.getVmwareDatastorePathFromVmdkFileName(
3958+
new DatastoreMO(srcHyperHost.getContext(), morDsAtSource),
3959+
vmName,
3960+
volume.getPath() + ".vmdk");
39583961
diskLocator = new VirtualMachineRelocateSpecDiskLocator();
39593962
diskLocator.setDatastore(morDsAtSource);
3960-
diskLocator.setDiskId(getVirtualDiskInfo(vmMo, srcDiskName));
3963+
diskLocator.setDiskId(getVirtualDiskInfo(vmMo, volume.getPath() + ".vmdk"));
39613964

39623965
diskLocators.add(diskLocator);
39633966

@@ -4075,10 +4078,12 @@ private Answer execute(MigrateVolumeCommand cmd) {
40754078
throw new Exception(msg);
40764079
}
40774080

4078-
srcDiskName = String.format("[%s] %s.vmdk", srcDsName, volumePath);
4081+
srcDiskName = VmwareStorageLayoutHelper.getVmwareDatastorePathFromVmdkFileName(
4082+
new DatastoreMO(srcHyperHost.getContext(), morDs), vmName,
4083+
volumePath + ".vmdk");
40794084
diskLocator = new VirtualMachineRelocateSpecDiskLocator();
40804085
diskLocator.setDatastore(morDs);
4081-
diskLocator.setDiskId(getVirtualDiskInfo(vmMo, srcDiskName));
4086+
diskLocator.setDiskId(getVirtualDiskInfo(vmMo, volumePath + ".vmdk"));
40824087

40834088
diskLocators.add(diskLocator);
40844089
relocateSpec.getDisk().add(diskLocator);

‎plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageLayoutHelper.java‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,29 @@ public static String[] getVmdkFilePairDatastorePath(DatastoreMO dsMo, String vmN
6464
return null;
6565
}
6666

67+
public static String findVolumeDatastoreFullPath(DatastoreMO dsMo, String vmName, String vmdkFileName) throws Exception {
68+
if(vmName != null) {
69+
String path = getVmwareDatastorePathFromVmdkFileName(dsMo, vmName, vmdkFileName);
70+
if(!dsMo.fileExists(path)) {
71+
path = getLegacyDatastorePathFromVmdkFileName(dsMo, vmdkFileName);
72+
73+
// to save one call to vCenter, we won't check file existence for this round, so the caller
74+
// may still fail with exception, but if that's case, we will let it fail anyway
75+
}
76+
return path;
77+
} else {
78+
String path = getLegacyDatastorePathFromVmdkFileName(dsMo, vmdkFileName);
79+
if(!dsMo.fileExists(path)) {
80+
// Datastore file movement is not atomic operations, we need to sync and repair
81+
path = dsMo.searchFileInSubFolders(vmdkFileName, false);
82+
83+
// to save one call to vCenter, we won't check file existence for this round, so the caller
84+
// may still fail with exception, but if that's case, we will let it fail anyway
85+
}
86+
return path;
87+
}
88+
}
89+
6790
public static String syncVolumeToVmDefaultFolder(DatacenterMO dcMo, String vmName,
6891
DatastoreMO ds, String vmdkName) throws Exception {
6992

0 commit comments

Comments
 (0)