This is an automated email from the ASF dual-hosted git repository.

rohit pushed a commit to branch 4.15
in repository https://gitbox.apache.org/repos/asf/cloudstack.git


The following commit(s) were added to refs/heads/4.15 by this push:
     new 12b2e80  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)
12b2e80 is described below

commit 12b2e80d82abd90e17d233c34b4f3bf7847a1d6d
Author: Harikrishna <[email protected]>
AuthorDate: Fri Jun 11 20:06:06 2021 +0530

    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
---
 .../main/java/com/cloud/vm/VirtualMachineManagerImpl.java  |  3 +++
 .../cloud/hypervisor/vmware/resource/VmwareResource.java   | 14 ++++++++------
 .../main/java/com/cloud/storage/StorageManagerImpl.java    |  2 +-
 3 files changed, 12 insertions(+), 7 deletions(-)

diff --git 
a/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java
 
b/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java
index a29c049..3f435e9 100755
--- 
a/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java
+++ 
b/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java
@@ -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);
         }
     }
diff --git 
a/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java
 
b/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java
index 870863d..f8fe2d6 100644
--- 
a/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java
+++ 
b/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java
@@ -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;
diff --git a/server/src/main/java/com/cloud/storage/StorageManagerImpl.java 
b/server/src/main/java/com/cloud/storage/StorageManagerImpl.java
index 2e22003..a3eb1d4 100644
--- a/server/src/main/java/com/cloud/storage/StorageManagerImpl.java
+++ b/server/src/main/java/com/cloud/storage/StorageManagerImpl.java
@@ -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);

Reply via email to