CLOUDSTACK-3237: pass disk file name instead of full datastore path when setting up storage relocation specin order to safely locate the disk device

This commit is contained in:
Kelven Yang 2013-08-09 17:27:26 -07:00
parent dbe4e13e8e
commit c6dfb33d9f
2 changed files with 32 additions and 4 deletions

View File

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

View File

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