From f825a94dc459e49f43a5dfc30fec8da563281269 Mon Sep 17 00:00:00 2001 From: Harikrishna Patnala Date: Thu, 10 Sep 2020 15:00:42 +0530 Subject: [PATCH] Fixed volume migrations to and fro vVols datastorewq --- .../hypervisor/vmware/resource/VmwareResource.java | 14 +++++++++++--- .../storage/resource/VmwareStorageProcessor.java | 6 +++--- .../cloud/hypervisor/vmware/mo/DatastoreMO.java | 2 ++ .../cloud/hypervisor/vmware/util/VmwareHelper.java | 10 ++++++++-- 4 files changed, 24 insertions(+), 8 deletions(-) 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 54c3b4449af..ad69d89e595 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 @@ -4760,7 +4760,9 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext()); VirtualMachineMO vmMo = null; DatastoreMO dsMo = null; + DatastoreMO destinationDsMo = null; ManagedObjectReference morSourceDS = null; + ManagedObjectReference morDestintionDS = null; String vmdkDataStorePath = null; String vmName = null; @@ -4768,15 +4770,21 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa // OfflineVmwareMigration: we need to refactor the worker vm creation out for use in migration methods as well as here // OfflineVmwareMigration: this method is 100 lines and needs refactorring anyway // we need to spawn a worker VM to attach the volume to and move it - vmName = getWorkerName(getServiceContext(), cmd, 0, dsMo); + morSourceDS = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, cmd.getSourcePool().getUuid()); + dsMo = new DatastoreMO(hyperHost.getContext(), morSourceDS); + morDestintionDS = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, cmd.getTargetPool().getUuid()); + destinationDsMo = new DatastoreMO(hyperHost.getContext(), morDestintionDS); + if (dsMo.getDatastoreType().equalsIgnoreCase("VVOL")) + vmName = getWorkerName(getServiceContext(), cmd, 0, dsMo); + + if (destinationDsMo.getDatastoreType().equalsIgnoreCase("VVOL")) + vmName = getWorkerName(getServiceContext(), cmd, 0, destinationDsMo); // OfflineVmwareMigration: refactor for re-use // OfflineVmwareMigration: 1. find data(store) // OfflineVmwareMigration: more robust would be to find the store given the volume as it might have been moved out of band or due to error // example: DatastoreMO existingVmDsMo = new DatastoreMO(dcMo.getContext(), dcMo.findDatastore(fileInDatastore.getDatastoreName())); - morSourceDS = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, cmd.getSourcePool().getUuid()); - dsMo = new DatastoreMO(hyperHost.getContext(), morSourceDS); s_logger.info("Create worker VM " + vmName); // OfflineVmwareMigration: 2. create the worker with access to the data(store) vmMo = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, vmName, null); diff --git a/plugins/hypervisors/vmware/src/main/java/com/cloud/storage/resource/VmwareStorageProcessor.java b/plugins/hypervisors/vmware/src/main/java/com/cloud/storage/resource/VmwareStorageProcessor.java index 5ff4ee33808..40a9617cdec 100644 --- a/plugins/hypervisors/vmware/src/main/java/com/cloud/storage/resource/VmwareStorageProcessor.java +++ b/plugins/hypervisors/vmware/src/main/java/com/cloud/storage/resource/VmwareStorageProcessor.java @@ -989,7 +989,7 @@ public class VmwareStorageProcessor implements StorageProcessor { volumeName = srcVolumePath.substring(index + 1); } - String newVolume = VmwareHelper.getVCenterSafeUuid(); + String newVolume = VmwareHelper.getVCenterSafeUuid(dsMo); restoreVolumeFromSecStorage(hyperHost, dsMo, newVolume, secStorageUrl, volumeFolder, volumeName, wait, nfsVersion); return new Pair<>(volumeFolder, newVolume); @@ -3590,7 +3590,6 @@ public class VmwareStorageProcessor implements StorageProcessor { String backupPath = backedUpSnapshotUuid.substring(0, index); backedUpSnapshotUuid = backedUpSnapshotUuid.substring(index + 1); String details; - String newVolumeName = VmwareHelper.getVCenterSafeUuid(); VmwareContext context = hostService.getServiceContext(cmd); try { @@ -3602,13 +3601,14 @@ public class VmwareStorageProcessor implements StorageProcessor { throw new Exception(msg); } + DatastoreMO primaryDsMo = new DatastoreMO(hyperHost.getContext(), morPrimaryDs); + String newVolumeName = VmwareHelper.getVCenterSafeUuid(primaryDsMo); // strip off the extension since restoreVolumeFromSecStorage internally will append suffix there. if (backedUpSnapshotUuid.endsWith(".ova")){ backedUpSnapshotUuid = backedUpSnapshotUuid.replace(".ova", ""); } else if (backedUpSnapshotUuid.endsWith(".ovf")){ backedUpSnapshotUuid = backedUpSnapshotUuid.replace(".ovf", ""); } - DatastoreMO primaryDsMo = new DatastoreMO(hyperHost.getContext(), morPrimaryDs); restoreVolumeFromSecStorage(hyperHost, primaryDsMo, newVolumeName, secondaryStorageUrl, backupPath, backedUpSnapshotUuid, (long)cmd.getWait() * 1000, _nfsVersion); VolumeObjectTO newVol = new VolumeObjectTO(); diff --git a/vmware-base/src/main/java/com/cloud/hypervisor/vmware/mo/DatastoreMO.java b/vmware-base/src/main/java/com/cloud/hypervisor/vmware/mo/DatastoreMO.java index fb9e83cf308..804af6286d1 100644 --- a/vmware-base/src/main/java/com/cloud/hypervisor/vmware/mo/DatastoreMO.java +++ b/vmware-base/src/main/java/com/cloud/hypervisor/vmware/mo/DatastoreMO.java @@ -406,6 +406,8 @@ public class DatastoreMO extends BaseMO { s_logger.info("Found file " + fileName + " in datastore at " + absoluteFileName); if (parentFolderPath.endsWith("]")) absoluteFileName += " "; + else if (!parentFolderPath.endsWith("/")) + absoluteFileName +="/"; absoluteFileName += fi.getPath(); if(isValidCloudStackFolderPath(parentFolderPath, searchExcludedFolders)) { return absoluteFileName; diff --git a/vmware-base/src/main/java/com/cloud/hypervisor/vmware/util/VmwareHelper.java b/vmware-base/src/main/java/com/cloud/hypervisor/vmware/util/VmwareHelper.java index babb954eec7..e00bc237018 100644 --- a/vmware-base/src/main/java/com/cloud/hypervisor/vmware/util/VmwareHelper.java +++ b/vmware-base/src/main/java/com/cloud/hypervisor/vmware/util/VmwareHelper.java @@ -76,7 +76,9 @@ import com.vmware.vim25.VirtualVmxnet2; import com.vmware.vim25.VirtualVmxnet3; import com.cloud.hypervisor.vmware.mo.DiskControllerType; +import com.cloud.hypervisor.vmware.mo.DatastoreMO; import com.cloud.hypervisor.vmware.mo.HostMO; +import com.cloud.hypervisor.vmware.mo.CustomFieldConstants; import com.cloud.hypervisor.vmware.mo.LicenseAssignmentManagerMO; import com.cloud.hypervisor.vmware.mo.VirtualEthernetCardType; import com.cloud.hypervisor.vmware.mo.VirtualMachineMO; @@ -692,9 +694,13 @@ public class VmwareHelper { return hotplugSupportedByLicense; } - public static String getVCenterSafeUuid() { + public static String getVCenterSafeUuid(DatastoreMO dsMo) throws Exception{ // Object name that is greater than 32 is not safe in vCenter - return UUID.randomUUID().toString().replaceAll("-", ""); + String uuid = UUID.randomUUID().toString().replaceAll("-", ""); + if (dsMo.getDatastoreType().equalsIgnoreCase("VVOL")) { + return CustomFieldConstants.CLOUD_UUID + "-" + uuid; + } + return uuid; } public static String getRecommendedDiskControllerFromDescriptor(GuestOsDescriptor guestOsDescriptor) throws Exception {