From c229244dabb5c5685fbb1aab84de9afdf199820b Mon Sep 17 00:00:00 2001 From: Wei Zhou Date: Tue, 6 Aug 2013 12:40:06 +0200 Subject: [PATCH] CLOUDSTACK-2729: move unlock to finally block to handle failed libvirt operations (cherry picked from commit 5cb090ed40816950d0c9dbb62135240a7c8b1e3d) --- .../kvm/storage/LibvirtStorageAdaptor.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java index 22a1be9e8fd..1558d9ccd00 100644 --- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java +++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java @@ -1175,10 +1175,13 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { } String lockFile = _mountPoint + File.separator + pool.getUUIDString() + File.separator + _lockfile; if (lock(lockFile, 30)) { - pool.refresh(0); - unlock(lockFile); + try { + pool.refresh(0); + } finally { + unlock(lockFile); + } } else { - throw new CloudRuntimeException("Can not get file lock to refresh the pool" + pool.getUUIDString()); + throw new CloudRuntimeException("Can not get file lock to refresh the pool " + pool.getUUIDString()); } } @@ -1190,10 +1193,13 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { } String lockFile = pool.getLocalPath() + File.separator + _lockfile; if (lock(lockFile, 30)) { - vol.delete(0); - unlock(lockFile); + try { + vol.delete(0); + } finally { + unlock(lockFile); + } } else { - throw new CloudRuntimeException("Can not get file lock to delete the volume" + vol.getPath()); + throw new CloudRuntimeException("Can not get file lock to delete the volume " + vol.getPath()); } }