Skip to content

Commit 41f6f0e

Browse files
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
1 parent 4acedc8 commit 41f6f0e

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1364,7 +1364,7 @@ protected VolumeVO retrieveAndValidateVolume(long volumeId, Account caller) {
13641364
if (!_snapshotMgr.canOperateOnVolume(volume)) {
13651365
throw new InvalidParameterValueException("There are snapshot operations in progress on the volume, unable to delete it");
13661366
}
1367-
if (volume.getInstanceId() != null && volume.getState() != Volume.State.Expunged) {
1367+
if (volume.getInstanceId() != null && _vmInstanceDao.findById(volume.getInstanceId()) != null && volume.getState() != Volume.State.Expunged) {
13681368
throw new InvalidParameterValueException("Please specify a volume that is not attached to any VM.");
13691369
}
13701370
if (volume.getState() == Volume.State.UploadOp) {
@@ -1520,6 +1520,7 @@ public Volume recoverVolume(long volumeId) {
15201520
}
15211521

15221522
try {
1523+
_volsDao.detachVolume(volume.getId());
15231524
stateTransitTo(volume, Volume.Event.RecoverRequested);
15241525
} catch (NoTransitionException e) {
15251526
s_logger.debug("Failed to recover volume" + volume.getId(), e);

0 commit comments

Comments
 (0)