From 94ea2736f4a1614e45f4bc56388aad7adeb22a08 Mon Sep 17 00:00:00 2001 From: Likitha Shetty Date: Sun, 10 Nov 2013 23:31:56 +0530 Subject: [PATCH] CLOUDSTACK-5927. Storage garbage collector is trying to destroy the SSVM/CPVM root disk that is in use. In case of VMware VM during root volume preparation if we are switching to a new volume, force expunge root disk that was created from the old template. Because otherwise storage garbage collector will later try to expunge the old disk marked for expunge and fail with 'Cannot delete file' exception since in VMware the new root vmdk has the same name and is now in use. --- .../engine/orchestration/VolumeOrchestrator.java | 11 ++++++++++- .../storage/resource/VmwareStorageProcessor.java | 4 +--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java b/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java index 46199692563..a3ab5a4164a 100644 --- a/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java +++ b/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java @@ -808,7 +808,16 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati } catch (NoTransitionException e) { s_logger.debug("Unable to destroy existing volume: " + e.toString()); } - + // In case of VMware VM will continue to use the old root disk until expunged, so force expunge old root disk + if (vm.getHypervisorType() == HypervisorType.VMware) { + s_logger.info("Expunging volume " + existingVolume.getId() + " from primary data store"); + AsyncCallFuture future = volService.expungeVolumeAsync(volFactory.getVolume(existingVolume.getId())); + try { + future.get(); + } catch (Exception e) { + s_logger.debug("Failed to expunge volume:" + existingVolume.getId(), e); + } + } return newVolume; } }); diff --git a/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java b/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java index 1e4f8d7f01b..2089c084d73 100644 --- a/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java +++ b/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java @@ -363,9 +363,7 @@ public class VmwareStorageProcessor implements StorageProcessor { // restoreVM - move the new ROOT disk into corresponding VM folder String vmInternalCSName = volume.getVmName(); if (dsMo.folderExists(String.format("[%s]", dsMo.getName()), vmInternalCSName)) { - String oldRootDisk = VmwareStorageLayoutHelper.getVmwareDatastorePathFromVmdkFileName(dsMo, vmInternalCSName, vmdkFileBaseName); - if (oldRootDisk != null) - VmwareStorageLayoutHelper.syncVolumeToVmDefaultFolder(dcMo, vmInternalCSName, dsMo, vmdkFileBaseName); + VmwareStorageLayoutHelper.syncVolumeToVmDefaultFolder(dcMo, vmInternalCSName, dsMo, vmdkName); } VolumeObjectTO newVol = new VolumeObjectTO();