Skip to content

Commit f00b5fc

Browse files
server: Fix for the issue of recover VM not able to attach the data disks which are there before destroy in case of VMware (#4493)
This PR fixes: #4462 Problem Statement: In case of VMware, when a VM having multiple data disk is destroyed (without expunge) and tried to recover the VM then the previous data disks are not attached to the VM like before destroy. Only root disk is attached to the VM. Root cause: All data disks were removed as part of VM destroy. Only the volumes which are selected to delete (while destroying VM) are supposed to be detached and destroyed. Solution: During VM destroy, detach and destroy only volumes which are selected during VM destroy. Detach the other volumes during expunge of VM.
1 parent 6200ac8 commit f00b5fc

2 files changed

Lines changed: 8 additions & 7 deletions

File tree

engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import com.cloud.utils.StringUtils;
3939
import com.cloud.vm.SecondaryStorageVmVO;
4040
import com.cloud.vm.UserVmDetailVO;
41+
import com.cloud.vm.VMInstanceVO;
4142
import com.cloud.vm.VmDetailConstants;
4243
import com.cloud.vm.dao.SecondaryStorageVmDao;
4344
import com.cloud.vm.dao.UserVmDetailsDao;
@@ -220,6 +221,8 @@ public enum UserVmCloneType {
220221
UserVmDetailsDao userVmDetailsDao;
221222
@Inject
222223
private SecondaryStorageVmDao secondaryStorageVmDao;
224+
@Inject
225+
VolumeApiService _volumeApiService;
223226

224227
private final StateMachine2<Volume.State, Volume.Event, Volume> _volStateMachine;
225228
protected List<StoragePoolAllocator> _storagePoolAllocators;
@@ -1038,6 +1041,10 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
10381041
if (s_logger.isDebugEnabled()) {
10391042
s_logger.debug("Detaching " + vol);
10401043
}
1044+
VMInstanceVO vm = _userVmDao.findById(vmId);
1045+
if (vm.getHypervisorType().equals(HypervisorType.VMware)) {
1046+
_volumeApiService.detachVolumeViaDestroyVM(vmId, vol.getId());
1047+
}
10411048
_volsDao.detachVolume(vol.getId());
10421049
}
10431050
}

server/src/main/java/com/cloud/vm/UserVmManagerImpl.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2968,13 +2968,7 @@ public UserVm destroyVm(DestroyVMCmd cmd) throws ResourceUnavailableException, C
29682968

29692969
stopVirtualMachine(vmId, VmDestroyForcestop.value());
29702970

2971-
if (vm.getHypervisorType() == HypervisorType.VMware) {
2972-
List<VolumeVO> allVolumes = _volsDao.findByInstance(vm.getId());
2973-
allVolumes.removeIf(vol -> vol.getVolumeType() == Volume.Type.ROOT);
2974-
detachVolumesFromVm(allVolumes);
2975-
} else {
2976-
detachVolumesFromVm(volumesToBeDeleted);
2977-
}
2971+
detachVolumesFromVm(volumesToBeDeleted);
29782972

29792973
UserVm destroyedVm = destroyVm(vmId, expunge);
29802974
if (expunge) {

0 commit comments

Comments
 (0)