// if the storage is managed, iScsiName should not be null
String datastoreName = isManaged ? VmwareResource.getDatastoreName(iScsiName) : primaryStore.getUuid();
Pair<ManagedObjectReference, DatastoreMO> volumeDsDetails = dataStoresDetails.get(datastoreName);
if(volumeDsDetails == null)
throw new Exception("Primary datastore " + primaryStore.getUuid() + " is not mounted on host.");
DatastoreMO dsMo = volumeDsDetails.second();
// we will honor vCenter's meta if it exists
if(diskInfo != null) {
// to deal with run-time upgrade to maintain the new datastore folder structure
String disks[] = diskInfo.getDiskChain();
for(int i = 0; i < disks.length; i++) {
DatastoreFile file = new DatastoreFile(disks[i]);
if (!isManaged && file.getDir() != null && file.getDir().isEmpty()) {
s_logger.info("Perform run-time datastore folder upgrade. sync " + disks[i] + " to VM folder");
disks[i] = VmwareStorageLayoutHelper.syncVolumeToVmDefaultFolder(
dcMo, vmMo.getName(), dsMo, file.getFileBaseName());
}
}
return disks;
}
final String datastoreDiskPath;
if (isManaged) {
datastoreDiskPath = dsMo.getDatastorePath(dsMo.getName() + ".vmdk");
}
else {
datastoreDiskPath = VmwareStorageLayoutHelper.syncVolumeToVmDefaultFolder(
dcMo, vmMo.getName(), dsMo, volumeTO.getPath());
}
if(!dsMo.fileExists(datastoreDiskPath)) {
s_logger.warn("Volume " + volumeTO.getId() + " does not seem to exist on datastore, out of sync? path: " + datastoreDiskPath);
}
return new String[] { datastoreDiskPath };
}