CLOUDSTACK-8113. VM migration fails with "Message: No such disk device: " error.

Consolidate VM disks once VM/volumes are migrated.

(cherry picked from commit cb211f18d1)
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
This commit is contained in:
Likitha Shetty 2014-12-23 14:20:34 +05:30 committed by Rohit Yadav
parent 45d32234a6
commit ad92b85076
2 changed files with 36 additions and 0 deletions

View File

@ -3057,6 +3057,18 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
s_logger.debug("Successfully migrated storage of VM " + vmName + " to target datastore(s)");
}
// Consolidate VM disks.
// In case of a linked clone VM, if VM's disks are not consolidated,
// further VM operations such as volume snapshot, VM snapshot etc. will result in DB inconsistencies.
String apiVersion = HypervisorHostHelper.getVcenterApiVersion(vmMo.getContext());
if (apiVersion.compareTo("5.0") >= 0) {
if (!vmMo.consolidateVmDisks()) {
s_logger.warn("VM disk consolidation failed after storage migration. Yet proceeding with VM migration.");
} else {
s_logger.debug("Successfully consolidated disks of VM " + vmName + ".");
}
}
// Update and return volume path for every disk because that could have changed after migration
for (Entry<VolumeTO, StorageFilerTO> entry : volToFiler.entrySet()) {
volume = entry.getKey();
@ -3166,6 +3178,18 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
s_logger.debug("Successfully migrated volume " + volumePath + " to target datastore " + tgtDsName);
}
// Consolidate VM disks.
// In case of a linked clone VM, if VM's disks are not consolidated,
// further volume operations on the ROOT volume such as volume snapshot etc. will result in DB inconsistencies.
String apiVersion = HypervisorHostHelper.getVcenterApiVersion(vmMo.getContext());
if (apiVersion.compareTo("5.0") >= 0) {
if (!vmMo.consolidateVmDisks()) {
s_logger.warn("VM disk consolidation failed after storage migration.");
} else {
s_logger.debug("Successfully consolidated disks of VM " + vmName + ".");
}
}
// Update and return volume path because that could have changed after migration
if (!targetDsMo.fileExists(fullVolumePath)) {
VirtualDisk[] disks = vmMo.getAllDiskDevice();

View File

@ -2638,4 +2638,16 @@ public class VirtualMachineMO extends BaseMO {
}
return guestOsSupportsMemoryHotAdd && virtualHardwareSupportsMemoryHotAdd;
}
public boolean consolidateVmDisks() throws Exception {
ManagedObjectReference morTask = _context.getService().consolidateVMDisksTask(_mor);
boolean result = _context.getVimClient().waitForTask(morTask);
if (result) {
_context.waitForTaskProgressDone(morTask);
return true;
} else {
s_logger.error("VMware ConsolidateVMDisks_Task failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
}
return false;
}
}