From 41f6f0e568f7a2352a7adbccdce33b214c40a370 Mon Sep 17 00:00:00 2001 From: Wei Zhou <57355700+weizhouapache@users.noreply.github.com> Date: Sat, 28 Aug 2021 14:10:31 +0200 Subject: [PATCH] server: allow destroy/recover volumes which are attached to removed vms (#5364) * server: allow destroy volumes which attach to a expunged vm * server: recover volume which is attached to a removed vm --- .../src/main/java/com/cloud/storage/VolumeApiServiceImpl.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java b/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java index 9791267f498..abb8265f20f 100644 --- a/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java +++ b/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java @@ -1364,7 +1364,7 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic if (!_snapshotMgr.canOperateOnVolume(volume)) { throw new InvalidParameterValueException("There are snapshot operations in progress on the volume, unable to delete it"); } - if (volume.getInstanceId() != null && volume.getState() != Volume.State.Expunged) { + if (volume.getInstanceId() != null && _vmInstanceDao.findById(volume.getInstanceId()) != null && volume.getState() != Volume.State.Expunged) { throw new InvalidParameterValueException("Please specify a volume that is not attached to any VM."); } if (volume.getState() == Volume.State.UploadOp) { @@ -1520,6 +1520,7 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic } try { + _volsDao.detachVolume(volume.getId()); stateTransitTo(volume, Volume.Event.RecoverRequested); } catch (NoTransitionException e) { s_logger.debug("Failed to recover volume" + volume.getId(), e);