From b5d2ff71fc80d5603d143c6964f336c6e1817a09 Mon Sep 17 00:00:00 2001 From: abhishek Date: Wed, 26 Jan 2011 13:25:28 -0800 Subject: [PATCH] bug 8215: blocking snapshot creation for volumes attached to vms which are in destroyed or expunging state status 8215: resolved fixed --- .../cloud/storage/snapshot/SnapshotManagerImpl.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java index 3a94338daf4..6350834efc1 100755 --- a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java +++ b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java @@ -110,6 +110,7 @@ import com.cloud.utils.db.Transaction; import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.vm.UserVmVO; import com.cloud.vm.VMInstanceVO; +import com.cloud.vm.VirtualMachine.State; import com.cloud.vm.dao.UserVmDao; @Local(value={SnapshotManager.class, SnapshotService.class}) @@ -359,6 +360,16 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma } } + //if volume is attached to a vm in destroyed or expunging state; disallow + if(v.getInstanceId() != null) { + UserVmVO userVm = _vmDao.findById(v.getInstanceId()); + if(userVm != null) { + if(userVm.getState().equals(State.Destroyed) || userVm.getState().equals(State.Expunging)) { + throw new CloudRuntimeException("Creating snapshot failed due to volume:" + volumeId + " due to the associated vm:"+userVm.getInstanceName()+" is in "+userVm.getState().toString()+" state"); + } + } + } + SnapshotVO snapshot = null; boolean backedUp = false; try {