Skip to content

Commit 7101a91

Browse files
Likitha ShettyManeesha P
authored andcommitted
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 <wrodrigues@schubergphilis.com> This closes apache#543
1 parent 00003d8 commit 7101a91

File tree

4 files changed

+34
-28
lines changed

4 files changed

+34
-28
lines changed

plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ private Ternary<String, Long, Long> createTemplateFromVolume(VirtualMachineMO vm
618618

619619
VirtualMachineMO clonedVm = null;
620620
try {
621-
Pair<VirtualDisk, String> volumeDeviceInfo = vmMo.getDiskDevice(volumePath, false);
621+
Pair<VirtualDisk, String> volumeDeviceInfo = vmMo.getDiskDevice(volumePath);
622622
if (volumeDeviceInfo == null) {
623623
String msg = "Unable to find related disk device for volume. volume path: " + volumePath;
624624
s_logger.error(msg);
@@ -941,7 +941,7 @@ private void exportVolumeToSecondaryStroage(VirtualMachineMO vmMo, String volume
941941
VirtualMachineMO clonedVm = null;
942942
try {
943943

944-
Pair<VirtualDisk, String> volumeDeviceInfo = vmMo.getDiskDevice(volumePath, false);
944+
Pair<VirtualDisk, String> volumeDeviceInfo = vmMo.getDiskDevice(volumePath);
945945
if (volumeDeviceInfo == null) {
946946
String msg = "Unable to find related disk device for volume. volume path: " + volumePath;
947947
s_logger.error(msg);

plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ private Answer execute(ResizeVolumeCommand cmd) {
589589
throw new Exception(msg);
590590
}
591591

592-
Pair<VirtualDisk, String> vdisk = vmMo.getDiskDevice(path, false);
592+
Pair<VirtualDisk, String> vdisk = vmMo.getDiskDevice(path);
593593
if (vdisk == null) {
594594
if (s_logger.isTraceEnabled())
595595
s_logger.trace("resize volume done (failed)");
@@ -3347,7 +3347,7 @@ private Answer execute(MigrateVolumeCommand cmd) {
33473347
}
33483348

33493349
private int getVirtualDiskInfo(VirtualMachineMO vmMo, String srcDiskName) throws Exception {
3350-
Pair<VirtualDisk, String> deviceInfo = vmMo.getDiskDevice(srcDiskName, false);
3350+
Pair<VirtualDisk, String> deviceInfo = vmMo.getDiskDevice(srcDiskName);
33513351
if (deviceInfo == null) {
33523352
throw new Exception("No such disk device: " + srcDiskName);
33533353
}

plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ private Ternary<String, Long, Long> createTemplateFromVolume(VirtualMachineMO vm
736736

737737
VirtualMachineMO clonedVm = null;
738738
try {
739-
Pair<VirtualDisk, String> volumeDeviceInfo = vmMo.getDiskDevice(volumePath, false);
739+
Pair<VirtualDisk, String> volumeDeviceInfo = vmMo.getDiskDevice(volumePath);
740740
if (volumeDeviceInfo == null) {
741741
String msg = "Unable to find related disk device for volume. volume path: " + volumePath;
742742
s_logger.error(msg);
@@ -1068,7 +1068,7 @@ private Pair<String, String[]> exportVolumeToSecondaryStroage(VirtualMachineMO v
10681068
VirtualMachineMO clonedVm = null;
10691069
try {
10701070

1071-
Pair<VirtualDisk, String> volumeDeviceInfo = vmMo.getDiskDevice(volumePath, false);
1071+
Pair<VirtualDisk, String> volumeDeviceInfo = vmMo.getDiskDevice(volumePath);
10721072
if (volumeDeviceInfo == null) {
10731073
String msg = "Unable to find related disk device for volume. volume path: " + volumePath;
10741074
s_logger.error(msg);
@@ -1219,7 +1219,7 @@ public Answer backupSnapshot(CopyCommand cmd) {
12191219
for (String vmdkDsFilePath : backupResult.third()) {
12201220
s_logger.info("Validate disk chain file:" + vmdkDsFilePath);
12211221

1222-
if (vmMo.getDiskDevice(vmdkDsFilePath, false) == null) {
1222+
if (vmMo.getDiskDevice(vmdkDsFilePath) == null) {
12231223
s_logger.info("" + vmdkDsFilePath + " no longer exists, consolidation detected");
12241224
chainConsolidated = true;
12251225
break;

vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,7 +1158,7 @@ public List<Pair<String, ManagedObjectReference>> detachDisk(String vmdkDatastor
11581158

11591159
// Note: if VM has been taken snapshot, original backing file will be renamed, therefore, when we try to find the matching
11601160
// VirtualDisk, we only perform prefix matching
1161-
Pair<VirtualDisk, String> deviceInfo = getDiskDevice(vmdkDatastorePath, false);
1161+
Pair<VirtualDisk, String> deviceInfo = getDiskDevice(vmdkDatastorePath);
11621162
if (deviceInfo == null) {
11631163
s_logger.warn("vCenter API trace - detachDisk() done (failed)");
11641164
throw new Exception("No such disk device: " + vmdkDatastorePath);
@@ -1964,18 +1964,15 @@ public void ensureScsiDeviceController() throws Exception {
19641964
}
19651965

19661966
// return pair of VirtualDisk and disk device bus name(ide0:0, etc)
1967-
public Pair<VirtualDisk, String> getDiskDevice(String vmdkDatastorePath, boolean matchExactly) throws Exception {
1967+
public Pair<VirtualDisk, String> getDiskDevice(String vmdkDatastorePath) throws Exception {
19681968
List<VirtualDevice> devices = _context.getVimClient().getDynamicProperty(_mor, "config.hardware.device");
1969+
ArrayList<Pair<VirtualDisk, String>> partialMatchingDiskDevices = new ArrayList<Pair<VirtualDisk, String>>();
19691970

19701971
DatastoreFile dsSrcFile = new DatastoreFile(vmdkDatastorePath);
19711972
String srcBaseName = dsSrcFile.getFileBaseName();
19721973
String trimmedSrcBaseName = VmwareHelper.trimSnapshotDeltaPostfix(srcBaseName);
19731974

1974-
if (matchExactly) {
1975-
s_logger.info("Look for disk device info from volume : " + vmdkDatastorePath + " with base name: " + srcBaseName);
1976-
} else {
1977-
s_logger.info("Look for disk device info from volume : " + vmdkDatastorePath + " with trimmed base name: " + trimmedSrcBaseName);
1978-
}
1975+
s_logger.info("Look for disk device info for volume : " + vmdkDatastorePath + " with base name: " + srcBaseName);
19791976

19801977
if (devices != null && devices.size() > 0) {
19811978
for (VirtualDevice device : devices) {
@@ -1990,20 +1987,14 @@ public Pair<VirtualDisk, String> getDiskDevice(String vmdkDatastorePath, boolean
19901987

19911988
DatastoreFile dsBackingFile = new DatastoreFile(diskBackingInfo.getFileName());
19921989
String backingBaseName = dsBackingFile.getFileBaseName();
1993-
if (matchExactly) {
1994-
if (backingBaseName.equalsIgnoreCase(srcBaseName)) {
1995-
String deviceNumbering = getDeviceBusName(devices, device);
1996-
1997-
s_logger.info("Disk backing : " + diskBackingInfo.getFileName() + " matches ==> " + deviceNumbering);
1998-
return new Pair<VirtualDisk, String>((VirtualDisk)device, deviceNumbering);
1999-
}
2000-
} else {
2001-
if (backingBaseName.contains(trimmedSrcBaseName)) {
2002-
String deviceNumbering = getDeviceBusName(devices, device);
2003-
2004-
s_logger.info("Disk backing : " + diskBackingInfo.getFileName() + " matches ==> " + deviceNumbering);
2005-
return new Pair<VirtualDisk, String>((VirtualDisk)device, deviceNumbering);
2006-
}
1990+
if (backingBaseName.equalsIgnoreCase(srcBaseName)) {
1991+
String deviceNumbering = getDeviceBusName(devices, device);
1992+
s_logger.info("Disk backing : " + diskBackingInfo.getFileName() + " matches ==> " + deviceNumbering);
1993+
return new Pair<VirtualDisk, String>((VirtualDisk)device, deviceNumbering);
1994+
}
1995+
if (backingBaseName.contains(trimmedSrcBaseName)) {
1996+
String deviceNumbering = getDeviceBusName(devices, device);
1997+
partialMatchingDiskDevices.add(new Pair<VirtualDisk, String>((VirtualDisk)device, deviceNumbering));
20071998
}
20081999

20092000
diskBackingInfo = diskBackingInfo.getParent();
@@ -2013,6 +2004,21 @@ public Pair<VirtualDisk, String> getDiskDevice(String vmdkDatastorePath, boolean
20132004
}
20142005
}
20152006

2007+
// No disk device was found with an exact match for the volume path, hence look for disk device that matches the trimmed name.
2008+
s_logger.info("No disk device with an exact match found for volume : " + vmdkDatastorePath + ". Look for disk device info against trimmed base name: " + srcBaseName);
2009+
if (partialMatchingDiskDevices != null) {
2010+
if (partialMatchingDiskDevices.size() == 1) {
2011+
VirtualDiskFlatVer2BackingInfo matchingDiskBackingInfo = (VirtualDiskFlatVer2BackingInfo)partialMatchingDiskDevices.get(0).first().getBacking();
2012+
s_logger.info("Disk backing : " + matchingDiskBackingInfo.getFileName() + " matches ==> " + partialMatchingDiskDevices.get(0).second());
2013+
return partialMatchingDiskDevices.get(0);
2014+
} else if (partialMatchingDiskDevices.size() > 1) {
2015+
s_logger.warn("Disk device info lookup for volume: " + vmdkDatastorePath + " failed as multiple disk devices were found to match" +
2016+
" volume's trimmed base name: " + trimmedSrcBaseName);
2017+
return null;
2018+
}
2019+
}
2020+
2021+
s_logger.warn("Disk device info lookup for volume: " + vmdkDatastorePath + " failed as no matching disk device found");
20162022
return null;
20172023
}
20182024

0 commit comments

Comments
 (0)