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 #543
This commit is contained in:
Likitha Shetty 2015-04-09 10:55:12 +05:30 committed by wilderrodrigues
parent 5eccf88508
commit f5ed824ea2
4 changed files with 34 additions and 28 deletions

View File

@ -618,7 +618,7 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
VirtualMachineMO clonedVm = null;
try {
Pair<VirtualDisk, String> volumeDeviceInfo = vmMo.getDiskDevice(volumePath, false);
Pair<VirtualDisk, String> 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<VirtualDisk, String> volumeDeviceInfo = vmMo.getDiskDevice(volumePath, false);
Pair<VirtualDisk, String> volumeDeviceInfo = vmMo.getDiskDevice(volumePath);
if (volumeDeviceInfo == null) {
String msg = "Unable to find related disk device for volume. volume path: " + volumePath;
s_logger.error(msg);

View File

@ -589,7 +589,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
throw new Exception(msg);
}
Pair<VirtualDisk, String> vdisk = vmMo.getDiskDevice(path, false);
Pair<VirtualDisk, String> 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<VirtualDisk, String> deviceInfo = vmMo.getDiskDevice(srcDiskName, false);
Pair<VirtualDisk, String> deviceInfo = vmMo.getDiskDevice(srcDiskName);
if (deviceInfo == null) {
throw new Exception("No such disk device: " + srcDiskName);
}

View File

@ -736,7 +736,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
VirtualMachineMO clonedVm = null;
try {
Pair<VirtualDisk, String> volumeDeviceInfo = vmMo.getDiskDevice(volumePath, false);
Pair<VirtualDisk, String> 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<VirtualDisk, String> volumeDeviceInfo = vmMo.getDiskDevice(volumePath, false);
Pair<VirtualDisk, String> 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;

View File

@ -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<VirtualDisk, String> deviceInfo = getDiskDevice(vmdkDatastorePath, false);
Pair<VirtualDisk, String> 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<VirtualDisk, String> getDiskDevice(String vmdkDatastorePath, boolean matchExactly) throws Exception {
public Pair<VirtualDisk, String> getDiskDevice(String vmdkDatastorePath) throws Exception {
List<VirtualDevice> devices = _context.getVimClient().getDynamicProperty(_mor, "config.hardware.device");
ArrayList<Pair<VirtualDisk, String>> partialMatchingDiskDevices = new ArrayList<Pair<VirtualDisk, String>>();
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, String>((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, String>((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, String>((VirtualDisk)device, deviceNumbering);
}
if (backingBaseName.contains(trimmedSrcBaseName)) {
String deviceNumbering = getDeviceBusName(devices, device);
partialMatchingDiskDevices.add(new Pair<VirtualDisk, String>((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;
}