Skip to content

Commit c652ff4

Browse files
author
Likitha Shetty
committed
CLOUDSTACK-6146. [VMware] [ESXi 5.5] Live storage migration of an already migrated volume fails
In vCenter 5.5, once a volume is migrated the VMDKs are renamed to match the name of the VM. If a volume has been renamed upon migration update its volumePath to that of the new disk filename.
1 parent 20efa0c commit c652ff4

2 files changed

Lines changed: 25 additions & 10 deletions

File tree

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4517,12 +4517,12 @@ private Answer execute(MigrateVolumeCommand cmd) {
45174517
throw new Exception(msg);
45184518
}
45194519

4520-
VmwareStorageLayoutHelper.getVmwareDatastorePathFromVmdkFileName(
4521-
new DatastoreMO(srcHyperHost.getContext(), morDs), vmName,
4522-
volumePath + ".vmdk");
4520+
DatastoreMO targetDsMo = new DatastoreMO(srcHyperHost.getContext(), morDs);
4521+
String fullVolumePath = VmwareStorageLayoutHelper.getVmwareDatastorePathFromVmdkFileName(targetDsMo, vmName, volumePath + ".vmdk");
4522+
int diskId = getVirtualDiskInfo(vmMo, volumePath + ".vmdk");
45234523
diskLocator = new VirtualMachineRelocateSpecDiskLocator();
45244524
diskLocator.setDatastore(morDs);
4525-
diskLocator.setDiskId(getVirtualDiskInfo(vmMo, volumePath + ".vmdk"));
4525+
diskLocator.setDiskId(diskId);
45264526

45274527
diskLocators.add(diskLocator);
45284528
relocateSpec.getDisk().add(diskLocator);
@@ -4534,6 +4534,15 @@ private Answer execute(MigrateVolumeCommand cmd) {
45344534
s_logger.debug("Successfully migrated volume " + volumePath + " to target datastore " + tgtDsName);
45354535
}
45364536

4537+
// Update and return volume path because that could have changed after migration
4538+
if (!targetDsMo.fileExists(fullVolumePath)) {
4539+
VirtualDisk[] disks = vmMo.getAllDiskDevice();
4540+
for (VirtualDisk disk : disks)
4541+
if (disk.getKey() == diskId) {
4542+
volumePath = vmMo.getVmdkFileBaseName(disk);
4543+
}
4544+
}
4545+
45374546
return new MigrateVolumeAnswer(cmd, true, null, volumePath);
45384547
} catch (Exception e) {
45394548
String msg = "Catch Exception " + e.getClass().getName() + " due to " + e.toString();

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1783,17 +1783,23 @@ public List<String> getVmdkFileBaseNames() throws Exception {
17831783
VirtualDevice[] devices = getAllDiskDevice();
17841784
for(VirtualDevice device : devices) {
17851785
if(device instanceof VirtualDisk) {
1786-
VirtualDeviceBackingInfo backingInfo = ((VirtualDisk)device).getBacking();
1787-
if(backingInfo instanceof VirtualDiskFlatVer2BackingInfo) {
1788-
VirtualDiskFlatVer2BackingInfo diskBackingInfo = (VirtualDiskFlatVer2BackingInfo)backingInfo;
1789-
DatastoreFile dsBackingFile = new DatastoreFile(diskBackingInfo.getFileName());
1790-
vmdkFileBaseNames.add(dsBackingFile.getFileBaseName());
1791-
}
1786+
vmdkFileBaseNames.add(getVmdkFileBaseName((VirtualDisk)device));
17921787
}
17931788
}
17941789
return vmdkFileBaseNames;
17951790
}
17961791

1792+
public String getVmdkFileBaseName(VirtualDisk disk) throws Exception {
1793+
String vmdkFileBaseName = null;
1794+
VirtualDeviceBackingInfo backingInfo = disk.getBacking();
1795+
if(backingInfo instanceof VirtualDiskFlatVer2BackingInfo) {
1796+
VirtualDiskFlatVer2BackingInfo diskBackingInfo = (VirtualDiskFlatVer2BackingInfo)backingInfo;
1797+
DatastoreFile dsBackingFile = new DatastoreFile(diskBackingInfo.getFileName());
1798+
vmdkFileBaseName = dsBackingFile.getFileBaseName();
1799+
}
1800+
return vmdkFileBaseName;
1801+
}
1802+
17971803
// this method relies on un-offical VMware API
17981804
@Deprecated
17991805
public void moveAllVmDiskFiles(DatastoreMO destDsMo, String destDsDir, boolean followDiskChain) throws Exception {

0 commit comments

Comments
 (0)