diff --git a/server/src/com/cloud/storage/StorageManagerImpl.java b/server/src/com/cloud/storage/StorageManagerImpl.java index 844d26e1114..b835f4fe26b 100755 --- a/server/src/com/cloud/storage/StorageManagerImpl.java +++ b/server/src/com/cloud/storage/StorageManagerImpl.java @@ -627,8 +627,8 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag } Long templateId = template.getId(); Long tmpltAccountId = template.getAccountId(); - if (!_volsDao.lockInLockTable(volumeId.toString(), 10)) { - throw new CloudRuntimeException("failed to upgrade snapshot " + snapshotId + " due to volume:" + volumeId + " is being used, try it later "); + if (!_snapshotDao.lockInLockTable(snapshotId.toString(), 10)) { + throw new CloudRuntimeException("failed to upgrade snapshot " + snapshotId + " due to this snapshot is being used, try it later "); } UpgradeSnapshotCommand cmd = new UpgradeSnapshotCommand(null, secondaryStoragePoolUrl, dcId, accountId, volumeId, templateId, tmpltAccountId, null, snapshot.getBackupSnapshotId(), snapshot.getName(), "2.1"); @@ -637,7 +637,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag answer = sendToPool(pool, cmd); } catch (StorageUnavailableException e) { } finally { - _volsDao.unlockFromLockTable(volumeId.toString()); + _snapshotDao.unlockFromLockTable(snapshotId.toString()); } if ((answer != null) && answer.getResult()) { _snapshotDao.updateSnapshotVersion(volumeId, "2.1", "2.2"); @@ -655,7 +655,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag String basicErrMsg = "Failed to create volume from " + snapshot.getName(); CreateVolumeFromSnapshotAnswer answer; if (!_snapshotDao.lockInLockTable(snapshotId.toString(), 10)) { - throw new CloudRuntimeException("failed to create volume from " + snapshotId + " due to original volume:" + volumeId + " is being used, try it later "); + throw new CloudRuntimeException("failed to create volume from " + snapshotId + " due to this snapshot is being used, try it later "); } try { answer = (CreateVolumeFromSnapshotAnswer) sendToPool(pool, createVolumeFromSnapshotCommand); diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index 69cd573c499..7e2f9210b53 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -1545,14 +1545,24 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager // This can be sent to a KVM host too. CreatePrivateTemplateAnswer answer = null; - if (!_volsDao.lockInLockTable(volumeId.toString(), 10)) { - throw new CloudRuntimeException("Creating template failed due to volume:" + volumeId + " is being used, try it later "); + if (snapshotId != null) { + if (!_snapshotDao.lockInLockTable(snapshotId.toString(), 10)) { + throw new CloudRuntimeException("Creating template from snapshot failed due to snapshot:" + snapshotId + " is being used, try it later "); + } + } else { + if (!_volsDao.lockInLockTable(volumeId.toString(), 10)) { + throw new CloudRuntimeException("Creating template from volume failed due to volume:" + volumeId + " is being used, try it later "); + } } try { answer = (CreatePrivateTemplateAnswer) _storageMgr.sendToPool(pool, cmd); } catch (StorageUnavailableException e) { } finally { - _volsDao.unlockFromLockTable(volumeId.toString()); + if (snapshotId != null) { + _snapshotDao.unlockFromLockTable(snapshotId.toString()); + } else { + _volsDao.unlockFromLockTable(volumeId.toString()); + } } if ((answer != null) && answer.getResult()) { privateTemplate = _templateDao.findById(templateId);