Skip to content

Commit ad92b85

Browse files
Likitha Shettyyadvr
authored andcommitted
CLOUDSTACK-8113. VM migration fails with "Message: No such disk device: " error.
Consolidate VM disks once VM/volumes are migrated. (cherry picked from commit cb211f1) Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
1 parent 45d3223 commit ad92b85

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3057,6 +3057,18 @@ protected Answer execute(MigrateWithStorageCommand cmd) {
30573057
s_logger.debug("Successfully migrated storage of VM " + vmName + " to target datastore(s)");
30583058
}
30593059

3060+
// Consolidate VM disks.
3061+
// In case of a linked clone VM, if VM's disks are not consolidated,
3062+
// further VM operations such as volume snapshot, VM snapshot etc. will result in DB inconsistencies.
3063+
String apiVersion = HypervisorHostHelper.getVcenterApiVersion(vmMo.getContext());
3064+
if (apiVersion.compareTo("5.0") >= 0) {
3065+
if (!vmMo.consolidateVmDisks()) {
3066+
s_logger.warn("VM disk consolidation failed after storage migration. Yet proceeding with VM migration.");
3067+
} else {
3068+
s_logger.debug("Successfully consolidated disks of VM " + vmName + ".");
3069+
}
3070+
}
3071+
30603072
// Update and return volume path for every disk because that could have changed after migration
30613073
for (Entry<VolumeTO, StorageFilerTO> entry : volToFiler.entrySet()) {
30623074
volume = entry.getKey();
@@ -3166,6 +3178,18 @@ private Answer execute(MigrateVolumeCommand cmd) {
31663178
s_logger.debug("Successfully migrated volume " + volumePath + " to target datastore " + tgtDsName);
31673179
}
31683180

3181+
// Consolidate VM disks.
3182+
// In case of a linked clone VM, if VM's disks are not consolidated,
3183+
// further volume operations on the ROOT volume such as volume snapshot etc. will result in DB inconsistencies.
3184+
String apiVersion = HypervisorHostHelper.getVcenterApiVersion(vmMo.getContext());
3185+
if (apiVersion.compareTo("5.0") >= 0) {
3186+
if (!vmMo.consolidateVmDisks()) {
3187+
s_logger.warn("VM disk consolidation failed after storage migration.");
3188+
} else {
3189+
s_logger.debug("Successfully consolidated disks of VM " + vmName + ".");
3190+
}
3191+
}
3192+
31693193
// Update and return volume path because that could have changed after migration
31703194
if (!targetDsMo.fileExists(fullVolumePath)) {
31713195
VirtualDisk[] disks = vmMo.getAllDiskDevice();

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2638,4 +2638,16 @@ public boolean isMemoryHotAddSupported(String guestOsId) throws Exception {
26382638
}
26392639
return guestOsSupportsMemoryHotAdd && virtualHardwareSupportsMemoryHotAdd;
26402640
}
2641+
2642+
public boolean consolidateVmDisks() throws Exception {
2643+
ManagedObjectReference morTask = _context.getService().consolidateVMDisksTask(_mor);
2644+
boolean result = _context.getVimClient().waitForTask(morTask);
2645+
if (result) {
2646+
_context.waitForTaskProgressDone(morTask);
2647+
return true;
2648+
} else {
2649+
s_logger.error("VMware ConsolidateVMDisks_Task failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
2650+
}
2651+
return false;
2652+
}
26412653
}

0 commit comments

Comments
 (0)