Skip to content

Commit fb58947

Browse files
BT HF11: don't use redundant worker vm while exporting volume (#25)
https://shapeblue.atlassian.net/browse/FRO-206 VM with VMsnapshots fails to start after extract volume is done on a stopped VM.
1 parent 603ec27 commit fb58947

File tree

2 files changed

+47
-32
lines changed

2 files changed

+47
-32
lines changed

plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -930,12 +930,12 @@ private String backupSnapshotToSecondaryStorage(VirtualMachineMO vmMo, long acco
930930
String prevSnapshotUuid, String prevBackupUuid, String workerVmName, Integer nfsVersion) throws Exception {
931931

932932
String backupUuid = UUID.randomUUID().toString();
933-
exportVolumeToSecondaryStroage(vmMo, volumePath, secStorageUrl, getSnapshotRelativeDirInSecStorage(accountId, volumeId), backupUuid, workerVmName, nfsVersion);
933+
exportVolumeToSecondaryStorage(vmMo, volumePath, secStorageUrl, getSnapshotRelativeDirInSecStorage(accountId, volumeId), backupUuid, workerVmName, nfsVersion, true);
934934
return backupUuid + "/" + backupUuid;
935935
}
936936

937-
private void exportVolumeToSecondaryStroage(VirtualMachineMO vmMo, String volumePath, String secStorageUrl, String secStorageDir, String exportName, String workerVmName,
938-
Integer nfsVersion) throws Exception {
937+
private void exportVolumeToSecondaryStorage(VirtualMachineMO vmMo, String volumePath, String secStorageUrl, String secStorageDir, String exportName, String workerVmName,
938+
Integer nfsVersion, boolean clonedWorkerVMNeeded) throws Exception {
939939

940940
String secondaryMountPoint = _mountService.getMountPoint(secStorageUrl, nfsVersion);
941941
String exportPath = secondaryMountPoint + "/" + secStorageDir + "/" + exportName;
@@ -961,16 +961,19 @@ private void exportVolumeToSecondaryStroage(VirtualMachineMO vmMo, String volume
961961
throw new Exception(msg);
962962
}
963963

964-
// 4 MB is the minimum requirement for VM memory in VMware
965-
vmMo.cloneFromCurrentSnapshot(workerVmName, 0, 4, volumeDeviceInfo.second(), VmwareHelper.getDiskDeviceDatastore(volumeDeviceInfo.first()));
966-
clonedVm = vmMo.getRunningHost().findVmOnHyperHost(workerVmName);
967-
if (clonedVm == null) {
968-
String msg = "Unable to create dummy VM to export volume. volume path: " + volumePath;
969-
s_logger.error(msg);
970-
throw new Exception(msg);
964+
if (clonedWorkerVMNeeded) {
965+
// 4 MB is the minimum requirement for VM memory in VMware
966+
vmMo.cloneFromCurrentSnapshot(workerVmName, 0, 4, volumeDeviceInfo.second(), VmwareHelper.getDiskDeviceDatastore(volumeDeviceInfo.first()));
967+
clonedVm = vmMo.getRunningHost().findVmOnHyperHost(workerVmName);
968+
if (clonedVm == null) {
969+
String msg = "Unable to create dummy VM to export volume. volume path: " + volumePath;
970+
s_logger.error(msg);
971+
throw new Exception(msg);
972+
}
973+
clonedVm.exportVm(exportPath, exportName, false, false); //Note: volss: not to create ova.
974+
} else {
975+
vmMo.exportVm(exportPath, exportName, false, false);
971976
}
972-
973-
clonedVm.exportVm(exportPath, exportName, false, false); //Note: volss: not to create ova.
974977
} finally {
975978
if (clonedVm != null) {
976979
clonedVm.detachAllDisks();
@@ -998,6 +1001,7 @@ private Pair<String, String> copyVolumeToSecStorage(VmwareHostService hostServic
9981001
throw new Exception(msg);
9991002
}
10001003

1004+
boolean clonedWorkerVMNeeded = true;
10011005
vmMo = hyperHost.findVmOnHyperHost(vmName);
10021006
if (vmMo == null) {
10031007
// create a dummy worker vm for attaching the volume
@@ -1014,16 +1018,19 @@ private Pair<String, String> copyVolumeToSecStorage(VmwareHostService hostServic
10141018
String datastoreVolumePath = getVolumePathInDatastore(dsMo, volumePath + ".vmdk", searchExcludedFolders);
10151019
workerVm.attachDisk(new String[] {datastoreVolumePath}, morDs);
10161020
vmMo = workerVm;
1021+
clonedWorkerVMNeeded = false;
1022+
} else {
1023+
vmMo.createSnapshot(exportName, "Temporary snapshot for copy-volume command", false, false);
10171024
}
10181025

1019-
vmMo.createSnapshot(exportName, "Temporary snapshot for copy-volume command", false, false);
1020-
1021-
exportVolumeToSecondaryStroage(vmMo, volumePath, secStorageUrl, "volumes/" + volumeFolder, exportName, hostService.getWorkerName(hyperHost.getContext(), cmd, 1),
1022-
nfsVersion);
1026+
exportVolumeToSecondaryStorage(vmMo, volumePath, secStorageUrl, "volumes/" + volumeFolder, exportName, hostService.getWorkerName(hyperHost.getContext(), cmd, 1),
1027+
nfsVersion, clonedWorkerVMNeeded);
10231028
return new Pair<String, String>(volumeFolder, exportName);
10241029

10251030
} finally {
1026-
vmMo.removeSnapshot(exportName, false);
1031+
if (vmMo != null && vmMo.getSnapshotMor(exportName) != null) {
1032+
vmMo.removeSnapshot(exportName, false);
1033+
}
10271034
if (workerVm != null) {
10281035
//detach volume and destroy worker vm
10291036
workerVm.detachAllDisks();

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

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -982,6 +982,7 @@ private Pair<String, String> copyVolumeToSecStorage(VmwareHostService hostServic
982982
throw new Exception(msg);
983983
}
984984

985+
boolean clonedWorkerVMNeeded = true;
985986
vmMo = hyperHost.findVmOnHyperHost(vmName);
986987
if (vmMo == null || VmwareResource.getVmState(vmMo) == PowerState.PowerOff) {
987988
// create a dummy worker vm for attaching the volume
@@ -998,15 +999,18 @@ private Pair<String, String> copyVolumeToSecStorage(VmwareHostService hostServic
998999
String datastoreVolumePath = getVolumePathInDatastore(dsMo, volumePath + ".vmdk", searchExcludedFolders);
9991000
workerVm.attachDisk(new String[] {datastoreVolumePath}, morDs);
10001001
vmMo = workerVm;
1002+
clonedWorkerVMNeeded = false;
1003+
} else {
1004+
vmMo.createSnapshot(exportName, "Temporary snapshot for copy-volume command", false, false);
10011005
}
10021006

1003-
vmMo.createSnapshot(exportName, "Temporary snapshot for copy-volume command", false, false);
1004-
1005-
exportVolumeToSecondaryStroage(vmMo, volumePath, secStorageUrl, destVolumePath, exportName, hostService.getWorkerName(hyperHost.getContext(), cmd, 1), _nfsVersion);
1007+
exportVolumeToSecondaryStorage(vmMo, volumePath, secStorageUrl, destVolumePath, exportName, hostService.getWorkerName(hyperHost.getContext(), cmd, 1), _nfsVersion, clonedWorkerVMNeeded);
10061008
return new Pair<>(destVolumePath, exportName);
10071009

10081010
} finally {
1009-
vmMo.removeSnapshot(exportName, false);
1011+
if (vmMo != null && vmMo.getSnapshotMor(exportName) != null) {
1012+
vmMo.removeSnapshot(exportName, false);
1013+
}
10101014
if (workerVm != null) {
10111015
//detach volume and destroy worker vm
10121016
workerVm.detachAllDisks();
@@ -1656,8 +1660,8 @@ public Answer createTemplateFromSnapshot(CopyCommand cmd) {
16561660
}
16571661

16581662
// return Pair<String(divice bus name), String[](disk chain)>
1659-
private Pair<String, String[]> exportVolumeToSecondaryStroage(VirtualMachineMO vmMo, String volumePath, String secStorageUrl, String secStorageDir,
1660-
String exportName, String workerVmName, Integer nfsVersion) throws Exception {
1663+
private Pair<String, String[]> exportVolumeToSecondaryStorage(VirtualMachineMO vmMo, String volumePath, String secStorageUrl, String secStorageDir,
1664+
String exportName, String workerVmName, Integer nfsVersion, boolean clonedWorkerVMNeeded) throws Exception {
16611665

16621666
String secondaryMountPoint = mountService.getMountPoint(secStorageUrl, nfsVersion);
16631667
String exportPath = secondaryMountPoint + "/" + secStorageDir + "/" + exportName;
@@ -1683,14 +1687,18 @@ private Pair<String, String[]> exportVolumeToSecondaryStroage(VirtualMachineMO v
16831687
throw new Exception(msg);
16841688
}
16851689

1686-
// 4 MB is the minimum requirement for VM memory in VMware
1687-
Pair<VirtualMachineMO, String[]> cloneResult =
1688-
vmMo.cloneFromCurrentSnapshot(workerVmName, 0, 4, volumeDeviceInfo.second(), VmwareHelper.getDiskDeviceDatastore(volumeDeviceInfo.first()));
1689-
clonedVm = cloneResult.first();
1690-
String disks[] = cloneResult.second();
1691-
1692-
clonedVm.exportVm(exportPath, exportName, false, false);
1693-
return new Pair<>(volumeDeviceInfo.second(), disks);
1690+
String diskDevice = volumeDeviceInfo.second();
1691+
String disks[] = vmMo.getCurrentSnapshotDiskChainDatastorePaths(diskDevice);
1692+
if (clonedWorkerVMNeeded) {
1693+
// 4 MB is the minimum requirement for VM memory in VMware
1694+
Pair<VirtualMachineMO, String[]> cloneResult =
1695+
vmMo.cloneFromCurrentSnapshot(workerVmName, 0, 4, diskDevice, VmwareHelper.getDiskDeviceDatastore(volumeDeviceInfo.first()));
1696+
clonedVm = cloneResult.first();
1697+
clonedVm.exportVm(exportPath, exportName, false, false);
1698+
} else {
1699+
vmMo.exportVm(exportPath, exportName, false, false);
1700+
}
1701+
return new Pair<>(diskDevice, disks);
16941702
} finally {
16951703
if (clonedVm != null) {
16961704
clonedVm.detachAllDisks();
@@ -1705,7 +1713,7 @@ private Ternary<String, String, String[]> backupSnapshotToSecondaryStorage(Virtu
17051713
Integer nfsVersion) throws Exception {
17061714

17071715
String backupUuid = UUID.randomUUID().toString();
1708-
Pair<String, String[]> snapshotInfo = exportVolumeToSecondaryStroage(vmMo, volumePath, secStorageUrl, installPath, backupUuid, workerVmName, nfsVersion);
1716+
Pair<String, String[]> snapshotInfo = exportVolumeToSecondaryStorage(vmMo, volumePath, secStorageUrl, installPath, backupUuid, workerVmName, nfsVersion, true);
17091717
return new Ternary<>(backupUuid, snapshotInfo.first(), snapshotInfo.second());
17101718
}
17111719

0 commit comments

Comments
 (0)