Skip to content

Commit 1598571

Browse files
committed
CLOUDSTACK-4659: Fix the regression caused by worker VM consolidation for GC purpose
1 parent 5820b07 commit 1598571

2 files changed

Lines changed: 12 additions & 21 deletions

File tree

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

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -654,15 +654,10 @@ private Ternary<String, Long, Long> createTemplateFromVolume(VirtualMachineMO vm
654654
}
655655

656656
// 4 MB is the minimum requirement for VM memory in VMware
657-
vmMo.cloneFromCurrentSnapshot(workerVmName, 0, 4, volumeDeviceInfo.second(),
657+
Pair<VirtualMachineMO, String[]> cloneResult = vmMo.cloneFromCurrentSnapshot(workerVmName, 0, 4, volumeDeviceInfo.second(),
658658
VmwareHelper.getDiskDeviceDatastore(volumeDeviceInfo.first()));
659-
clonedVm = vmMo.getRunningHost().findVmOnHyperHost(workerVmName);
660-
if(clonedVm == null) {
661-
String msg = "Unable to create dummy VM to export volume. volume path: " + volumePath;
662-
s_logger.error(msg);
663-
throw new Exception(msg);
664-
}
665-
659+
clonedVm = cloneResult.first();
660+
666661
clonedVm.exportVm(secondaryMountPoint + "/" + installPath, templateUniqueName, true, false);
667662

668663
long physicalSize = new File(installFullPath + "/" + templateUniqueName + ".ova").length();
@@ -978,17 +973,12 @@ private Pair<String, String[]> exportVolumeToSecondaryStroage(VirtualMachineMO v
978973
}
979974

980975
// 4 MB is the minimum requirement for VM memory in VMware
981-
String disks[] = vmMo.cloneFromCurrentSnapshot(workerVmName, 0, 4, volumeDeviceInfo.second(),
982-
VmwareHelper.getDiskDeviceDatastore(volumeDeviceInfo.first()));
983-
clonedVm = vmMo.getRunningHost().findVmOnHyperHost(workerVmName);
984-
if(clonedVm == null) {
985-
String msg = "Unable to create dummy VM to export volume. volume path: " + volumePath;
986-
s_logger.error(msg);
987-
throw new Exception(msg);
988-
}
976+
Pair<VirtualMachineMO, String[]> cloneResult = vmMo.cloneFromCurrentSnapshot(workerVmName, 0, 4, volumeDeviceInfo.second(),
977+
VmwareHelper.getDiskDeviceDatastore(volumeDeviceInfo.first()));
978+
clonedVm = cloneResult.first();
979+
String disks[] = cloneResult.second();
989980

990981
clonedVm.exportVm(exportPath, exportName, false, false);
991-
992982
return new Pair<String, String[]>(volumeDeviceInfo.second(), disks);
993983
} finally {
994984
if(clonedVm != null) {

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,15 +1545,15 @@ public String[] getCurrentSnapshotDiskChainDatastorePaths(String diskDevice) thr
15451545
}
15461546

15471547
// return the disk chain (VMDK datastore paths) for cloned snapshot
1548-
public String[] cloneFromCurrentSnapshot(String clonedVmName, int cpuSpeedMHz, int memoryMb, String diskDevice,
1548+
public Pair<VirtualMachineMO, String[]> cloneFromCurrentSnapshot(String clonedVmName, int cpuSpeedMHz, int memoryMb, String diskDevice,
15491549
ManagedObjectReference morDs) throws Exception {
15501550
assert(morDs != null);
15511551
String[] disks = getCurrentSnapshotDiskChainDatastorePaths(diskDevice);
1552-
cloneFromDiskChain(clonedVmName, cpuSpeedMHz, memoryMb, disks, morDs);
1553-
return disks;
1552+
VirtualMachineMO clonedVm = cloneFromDiskChain(clonedVmName, cpuSpeedMHz, memoryMb, disks, morDs);
1553+
return new Pair<VirtualMachineMO, String[]>(clonedVm, disks);
15541554
}
15551555

1556-
public void cloneFromDiskChain(String clonedVmName, int cpuSpeedMHz, int memoryMb,
1556+
public VirtualMachineMO cloneFromDiskChain(String clonedVmName, int cpuSpeedMHz, int memoryMb,
15571557
String[] disks, ManagedObjectReference morDs) throws Exception {
15581558
assert(disks != null);
15591559
assert(disks.length >= 1);
@@ -1576,6 +1576,7 @@ public void cloneFromDiskChain(String clonedVmName, int cpuSpeedMHz, int memoryM
15761576
vmConfigSpec.getDeviceChange().add(deviceConfigSpec);
15771577
clonedVmMo.configureVm(vmConfigSpec);
15781578
bSuccess = true;
1579+
return clonedVmMo;
15791580
} finally {
15801581
if(!bSuccess) {
15811582
clonedVmMo.detachAllDisks();

0 commit comments

Comments
 (0)