From 00c6ad2733123cd7107970c65d2c50565b86400a Mon Sep 17 00:00:00 2001 From: sureshanaparti <12028987+sureshanaparti@users.noreply.github.com> Date: Fri, 3 Dec 2021 16:46:31 +0530 Subject: [PATCH] vmware: Perform volume file search in the VM directory on the datastore while computing the VM snapshot chain size. (#5735) This PR improves the volume file search on the datastore while computing the VM snapshot chain size in VMware. The file search is now performed in the VM directory on the datastore, instead of all the directories on the datastore (which is leading to incorrect VM snapshot chain size computation when VM id has 6 digits). --- .../vmware/manager/VmwareStorageManagerImpl.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java b/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java index e84b744d5c1..da317bbdf65 100644 --- a/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java +++ b/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java @@ -31,6 +31,7 @@ import java.util.UUID; import org.apache.log4j.Logger; +import com.cloud.hypervisor.vmware.mo.DatastoreFile; import com.vmware.vim25.FileInfo; import com.vmware.vim25.FileQueryFlags; import com.vmware.vim25.HostDatastoreBrowserSearchResults; @@ -1140,12 +1141,12 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager { return "snapshots/" + accountId + "/" + volumeId; } - private long getVMSnapshotChainSize(VmwareContext context, VmwareHypervisorHost hyperHost, String fileName, ManagedObjectReference morDs, String exceptFileName) - throws Exception { + private long getVMSnapshotChainSize(VmwareContext context, VmwareHypervisorHost hyperHost, String fileName, ManagedObjectReference morDs, + String exceptFileName, String vmName) throws Exception { long size = 0; DatastoreMO dsMo = new DatastoreMO(context, morDs); HostDatastoreBrowserMO browserMo = dsMo.getHostDatastoreBrowserMO(); - String datastorePath = "[" + dsMo.getName() + "]"; + String datastorePath = (new DatastoreFile(dsMo.getName(), vmName)).getPath(); HostDatastoreBrowserSearchSpec searchSpec = new HostDatastoreBrowserSearchSpec(); FileQueryFlags fqf = new FileQueryFlags(); fqf.setFileSize(true); @@ -1306,11 +1307,11 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager { // get volume's chain size for this VM snapshot; exclude current volume vdisk DataStoreTO store = volumeTO.getDataStore(); ManagedObjectReference morDs = getDatastoreAsManagedObjectReference(baseName, hyperHost, store); - long size = getVMSnapshotChainSize(context, hyperHost, baseName + "-*.vmdk", morDs, newPath); + long size = getVMSnapshotChainSize(context, hyperHost, baseName + "-*.vmdk", morDs, newPath, vmName); if (volumeTO.getVolumeType() == Volume.Type.ROOT) { // add memory snapshot size - size += getVMSnapshotChainSize(context, hyperHost, vmName + "-*.vmsn", morDs, null); + size += getVMSnapshotChainSize(context, hyperHost, vmName + "-*.vmsn", morDs, null, vmName); } volumeTO.setSize(size);