diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index 31c48c4c533..16ad69ee68f 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -1414,9 +1414,15 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager // This can be sent to a KVM host too. StoragePool pool = _storagePoolDao.findById(volume.getPoolId()); CreatePrivateTemplateAnswer answer = null; + volume = _volsDao.acquireInLockTable(volumeId, 10); + if( volume == null ) { + throw new CloudRuntimeException("Creating template failed due to volume:" + volumeId + " is being used, try it later "); + } try { answer = (CreatePrivateTemplateAnswer)_storageMgr.sendToPool(pool, cmd); } catch (StorageUnavailableException e) { + } finally { + _volsDao.releaseFromLockTable(volumeId); } if ((answer != null) && answer.getResult()) {