From f5ed824ea27ee5aacbba8624b9d75790a3c001dd Mon Sep 17 00:00:00 2001 From: Likitha Shetty Date: Thu, 9 Apr 2015 10:55:12 +0530 Subject: [PATCH] CLOUDSTACK-8598. CS reports volume migration as successful but the volume is not migrated in vCenter.. For the following disk operations - migration, snapshot creation, resize, detach and template creation, CS should do an exact disk match between volume path and vCenter disk name. If the exact matching fails to find a disk, CS should fall back to the old method of partial matching on a trimmed disk. Signed-off-by: wilderrodrigues This closes #543 --- .../manager/VmwareStorageManagerImpl.java | 4 +- .../vmware/resource/VmwareResource.java | 4 +- .../resource/VmwareStorageProcessor.java | 6 +-- .../vmware/mo/VirtualMachineMO.java | 48 +++++++++++-------- 4 files changed, 34 insertions(+), 28 deletions(-) diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java index 84f7fc0d95a..316e6dca437 100644 --- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java +++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java @@ -618,7 +618,7 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager { VirtualMachineMO clonedVm = null; try { - Pair volumeDeviceInfo = vmMo.getDiskDevice(volumePath, false); + Pair volumeDeviceInfo = vmMo.getDiskDevice(volumePath); if (volumeDeviceInfo == null) { String msg = "Unable to find related disk device for volume. volume path: " + volumePath; s_logger.error(msg); @@ -941,7 +941,7 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager { VirtualMachineMO clonedVm = null; try { - Pair volumeDeviceInfo = vmMo.getDiskDevice(volumePath, false); + Pair volumeDeviceInfo = vmMo.getDiskDevice(volumePath); if (volumeDeviceInfo == null) { String msg = "Unable to find related disk device for volume. volume path: " + volumePath; s_logger.error(msg); diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java index 6284f86e64c..491323c861a 100644 --- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java +++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java @@ -589,7 +589,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa throw new Exception(msg); } - Pair vdisk = vmMo.getDiskDevice(path, false); + Pair vdisk = vmMo.getDiskDevice(path); if (vdisk == null) { if (s_logger.isTraceEnabled()) s_logger.trace("resize volume done (failed)"); @@ -3347,7 +3347,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa } private int getVirtualDiskInfo(VirtualMachineMO vmMo, String srcDiskName) throws Exception { - Pair deviceInfo = vmMo.getDiskDevice(srcDiskName, false); + Pair deviceInfo = vmMo.getDiskDevice(srcDiskName); if (deviceInfo == null) { throw new Exception("No such disk device: " + srcDiskName); } diff --git a/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java b/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java index ab07ec5804d..ec819f8a184 100644 --- a/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java +++ b/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java @@ -736,7 +736,7 @@ public class VmwareStorageProcessor implements StorageProcessor { VirtualMachineMO clonedVm = null; try { - Pair volumeDeviceInfo = vmMo.getDiskDevice(volumePath, false); + Pair volumeDeviceInfo = vmMo.getDiskDevice(volumePath); if (volumeDeviceInfo == null) { String msg = "Unable to find related disk device for volume. volume path: " + volumePath; s_logger.error(msg); @@ -1068,7 +1068,7 @@ public class VmwareStorageProcessor implements StorageProcessor { VirtualMachineMO clonedVm = null; try { - Pair volumeDeviceInfo = vmMo.getDiskDevice(volumePath, false); + Pair volumeDeviceInfo = vmMo.getDiskDevice(volumePath); if (volumeDeviceInfo == null) { String msg = "Unable to find related disk device for volume. volume path: " + volumePath; s_logger.error(msg); @@ -1219,7 +1219,7 @@ public class VmwareStorageProcessor implements StorageProcessor { for (String vmdkDsFilePath : backupResult.third()) { s_logger.info("Validate disk chain file:" + vmdkDsFilePath); - if (vmMo.getDiskDevice(vmdkDsFilePath, false) == null) { + if (vmMo.getDiskDevice(vmdkDsFilePath) == null) { s_logger.info("" + vmdkDsFilePath + " no longer exists, consolidation detected"); chainConsolidated = true; break; diff --git a/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java b/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java index ae8e860cb3a..b509ba2e1e7 100644 --- a/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java +++ b/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java @@ -1158,7 +1158,7 @@ public class VirtualMachineMO extends BaseMO { // Note: if VM has been taken snapshot, original backing file will be renamed, therefore, when we try to find the matching // VirtualDisk, we only perform prefix matching - Pair deviceInfo = getDiskDevice(vmdkDatastorePath, false); + Pair deviceInfo = getDiskDevice(vmdkDatastorePath); if (deviceInfo == null) { s_logger.warn("vCenter API trace - detachDisk() done (failed)"); throw new Exception("No such disk device: " + vmdkDatastorePath); @@ -1964,18 +1964,15 @@ public class VirtualMachineMO extends BaseMO { } // return pair of VirtualDisk and disk device bus name(ide0:0, etc) - public Pair getDiskDevice(String vmdkDatastorePath, boolean matchExactly) throws Exception { + public Pair getDiskDevice(String vmdkDatastorePath) throws Exception { List devices = _context.getVimClient().getDynamicProperty(_mor, "config.hardware.device"); + ArrayList> partialMatchingDiskDevices = new ArrayList>(); DatastoreFile dsSrcFile = new DatastoreFile(vmdkDatastorePath); String srcBaseName = dsSrcFile.getFileBaseName(); String trimmedSrcBaseName = VmwareHelper.trimSnapshotDeltaPostfix(srcBaseName); - if (matchExactly) { - s_logger.info("Look for disk device info from volume : " + vmdkDatastorePath + " with base name: " + srcBaseName); - } else { - s_logger.info("Look for disk device info from volume : " + vmdkDatastorePath + " with trimmed base name: " + trimmedSrcBaseName); - } + s_logger.info("Look for disk device info for volume : " + vmdkDatastorePath + " with base name: " + srcBaseName); if (devices != null && devices.size() > 0) { for (VirtualDevice device : devices) { @@ -1990,20 +1987,14 @@ public class VirtualMachineMO extends BaseMO { DatastoreFile dsBackingFile = new DatastoreFile(diskBackingInfo.getFileName()); String backingBaseName = dsBackingFile.getFileBaseName(); - if (matchExactly) { - if (backingBaseName.equalsIgnoreCase(srcBaseName)) { - String deviceNumbering = getDeviceBusName(devices, device); - - s_logger.info("Disk backing : " + diskBackingInfo.getFileName() + " matches ==> " + deviceNumbering); - return new Pair((VirtualDisk)device, deviceNumbering); - } - } else { - if (backingBaseName.contains(trimmedSrcBaseName)) { - String deviceNumbering = getDeviceBusName(devices, device); - - s_logger.info("Disk backing : " + diskBackingInfo.getFileName() + " matches ==> " + deviceNumbering); - return new Pair((VirtualDisk)device, deviceNumbering); - } + if (backingBaseName.equalsIgnoreCase(srcBaseName)) { + String deviceNumbering = getDeviceBusName(devices, device); + s_logger.info("Disk backing : " + diskBackingInfo.getFileName() + " matches ==> " + deviceNumbering); + return new Pair((VirtualDisk)device, deviceNumbering); + } + if (backingBaseName.contains(trimmedSrcBaseName)) { + String deviceNumbering = getDeviceBusName(devices, device); + partialMatchingDiskDevices.add(new Pair((VirtualDisk)device, deviceNumbering)); } diskBackingInfo = diskBackingInfo.getParent(); @@ -2013,6 +2004,21 @@ public class VirtualMachineMO extends BaseMO { } } + // No disk device was found with an exact match for the volume path, hence look for disk device that matches the trimmed name. + s_logger.info("No disk device with an exact match found for volume : " + vmdkDatastorePath + ". Look for disk device info against trimmed base name: " + srcBaseName); + if (partialMatchingDiskDevices != null) { + if (partialMatchingDiskDevices.size() == 1) { + VirtualDiskFlatVer2BackingInfo matchingDiskBackingInfo = (VirtualDiskFlatVer2BackingInfo)partialMatchingDiskDevices.get(0).first().getBacking(); + s_logger.info("Disk backing : " + matchingDiskBackingInfo.getFileName() + " matches ==> " + partialMatchingDiskDevices.get(0).second()); + return partialMatchingDiskDevices.get(0); + } else if (partialMatchingDiskDevices.size() > 1) { + s_logger.warn("Disk device info lookup for volume: " + vmdkDatastorePath + " failed as multiple disk devices were found to match" + + " volume's trimmed base name: " + trimmedSrcBaseName); + return null; + } + } + + s_logger.warn("Disk device info lookup for volume: " + vmdkDatastorePath + " failed as no matching disk device found"); return null; }