vmware: Fix fetching chain_info of the volumes. It is used to assume datastore names are in the form of UUIDs but it can be any name. So fetch chain_info based on the datastore name. (#5097)

his PR fixes the problem of not updating the chain info or setting chain info to null after volume migrations.

Problem: While fetching the volume chain info, management server assumes datastore name to be a UUID (this is true only for NFS storages added by CloudStack) but datastore name can be with any name.
Solution: To fetch the volume chain info, use datastore name instead of UUID.

The fix is made in the flow of following API operations

migrateVirtualMachine
migrateVirtualMachineWithVolume
migrateVolume
This commit is contained in:
Harikrishna 2021-06-11 20:06:06 +05:30 committed by GitHub
parent 9d9da01626
commit 12b2e80d82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 7 deletions

View File

@ -2307,6 +2307,9 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
VolumeVO volume = _volsDao.findById(result.getId());
volume.setPath(result.getPath());
volume.setPoolId(destPool.getId());
if (result.getChainInfo() != null) {
volume.setChainInfo(result.getChainInfo());
}
_volsDao.update(volume.getId(), volume);
}
}

View File

@ -4429,7 +4429,8 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
} else {
s_logger.debug("Successfully consolidated disks of VM " + vmMo.getVmName() + ".");
}
return createAnswerForCmd(vmMo, poolUuid, cmd, volumeDeviceKey);
DatastoreMO dsMo = new DatastoreMO(getServiceContext(), morDs);
return createAnswerForCmd(vmMo, dsMo, cmd, volumeDeviceKey);
} else {
return new Answer(cmd, false, "failed to changes data store for VM" + vmMo.getVmName());
}
@ -4440,7 +4441,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
}
}
Answer createAnswerForCmd(VirtualMachineMO vmMo, String poolUuid, Command cmd, Map<Integer, Long> volumeDeviceKey) throws Exception {
Answer createAnswerForCmd(VirtualMachineMO vmMo, DatastoreMO dsMo, Command cmd, Map<Integer, Long> volumeDeviceKey) throws Exception {
List<VolumeObjectTO> volumeToList = new ArrayList<>();
VirtualMachineDiskInfoBuilder diskInfoBuilder = vmMo.getDiskInfoBuilder();
VirtualDisk[] disks = vmMo.getAllDiskDevice();
@ -4458,7 +4459,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
for (VirtualDisk disk : disks) {
VolumeObjectTO newVol = new VolumeObjectTO();
String newPath = vmMo.getVmdkFileBaseName(disk);
VirtualMachineDiskInfo diskInfo = diskInfoBuilder.getDiskInfoByBackingFileBaseName(newPath, poolUuid);
VirtualMachineDiskInfo diskInfo = diskInfoBuilder.getDiskInfoByBackingFileBaseName(newPath, dsMo.getName());
newVol.setId(volumeDeviceKey.get(disk.getKey()));
newVol.setPath(newPath);
newVol.setChainInfo(_gson.toJson(diskInfo));
@ -4804,8 +4805,9 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
if (volumeDeviceKey.get(volumeId) == disk.getKey()) {
VolumeObjectTO newVol = new VolumeObjectTO();
String newPath = vmMo.getVmdkFileBaseName(disk);
String poolName = entry.second().getUuid().replace("-", "");
VirtualMachineDiskInfo diskInfo = diskInfoBuilder.getDiskInfoByBackingFileBaseName(newPath, poolName);
ManagedObjectReference morDs = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(tgtHyperHost, entry.second().getUuid());
DatastoreMO dsMo = new DatastoreMO(getServiceContext(), morDs);
VirtualMachineDiskInfo diskInfo = diskInfoBuilder.getDiskInfoByBackingFileBaseName(newPath, dsMo.getName());
newVol.setId(volumeId);
newVol.setPath(newPath);
newVol.setChainInfo(_gson.toJson(diskInfo));
@ -5100,7 +5102,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
}
}
VirtualMachineDiskInfoBuilder diskInfoBuilder = vmMo.getDiskInfoBuilder();
String chainInfo = _gson.toJson(diskInfoBuilder.getDiskInfoByBackingFileBaseName(volumePath, poolTo.getUuid().replace("-", "")));
String chainInfo = _gson.toJson(diskInfoBuilder.getDiskInfoByBackingFileBaseName(volumePath, targetDsMo.getName()));
MigrateVolumeAnswer answer = new MigrateVolumeAnswer(cmd, true, null, volumePath);
answer.setVolumeChainInfo(chainInfo);
return answer;

View File

@ -1745,7 +1745,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
} else {
// This is to find datastores which are removed from datastore cluster.
// The final set childDatastoreUUIDs contains the UUIDs of child datastores which needs to be removed from datastore cluster
childDatastoreUUIDs.remove(childStoragePoolInfo.getUuid());
childDatastoreUUIDs.remove(dataStoreVO.getUuid());
}
} else {
dataStoreVO = createChildDatastoreVO(datastoreClusterPool, childDataStoreAnswer);