From 08339d663fc132d5ac07ca64035fd8739f93b31e Mon Sep 17 00:00:00 2001 From: Kelven Yang Date: Wed, 16 Nov 2011 18:01:52 -0800 Subject: [PATCH] bug 12039,12041: when taking snapshot for detached volume, keep the worker VM around until backup copy to SSVM is done Reviewed-by: Frank --- .../manager/VmwareStorageManagerImpl.java | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/core/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java b/core/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java index 3e36e4876eb..b88117b4301 100644 --- a/core/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java +++ b/core/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java @@ -158,7 +158,7 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager { String snapshotBackupUuid = null; VmwareContext context = hostService.getServiceContext(cmd); - VirtualMachineMO vmMo; + VirtualMachineMO vmMo = null; try { VmwareHypervisorHost hyperHost = hostService.getHyperHost(context, cmd); @@ -201,11 +201,22 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager { throw new Exception("Failed to take snapshot " + cmd.getSnapshotName() + " on vm: " + cmd.getVmName()); } } + + snapshotBackupUuid = backupSnapshotToSecondaryStorage(vmMo, accountId, volumeId, cmd.getVolumePath(), snapshotUuid, secondaryStorageUrl, prevSnapshotUuid, prevBackupUuid, + UUID.randomUUID().toString().replace("-", "")); + + success = (snapshotBackupUuid != null); + if (success) { + details = "Successfully backedUp the snapshotUuid: " + snapshotUuid + " to secondary storage."; + } + } finally { + if(vmMo != null) + vmMo.removeAllSnapshots(); + try { if (workerVm != null) { // detach volume and destroy worker vm - workerVm.moveAllVmDiskFiles(dsMo, "", false); workerVm.detachAllDisks(); workerVm.destroy(); } @@ -213,16 +224,6 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager { s_logger.warn("Failed to destroy worker VM: " + workerVMName); } } - - snapshotBackupUuid = backupSnapshotToSecondaryStorage(vmMo, accountId, volumeId, cmd.getVolumePath(), snapshotUuid, secondaryStorageUrl, prevSnapshotUuid, prevBackupUuid, - hostService.getWorkerName(context, cmd)); - - success = (snapshotBackupUuid != null); - - if (success) { - details = "Successfully backedUp the snapshotUuid: " + snapshotUuid + " to secondary storage."; - vmMo.removeAllSnapshots(); - } } catch (Throwable e) { if (e instanceof RemoteException) { hostService.invalidateServiceContext(context); @@ -299,7 +300,7 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager { try { Ternary result = createTemplateFromSnapshot(accountId, newTemplateId, uniqeName, - secondaryStorageUrl, volumeId, + secondaryStorageUrl, volumeId, backedUpSnapshotUuid); return new CreatePrivateTemplateAnswer(cmd, true, null,