CLOUDSTACK-2729: move unlock to finally block to handle failed libvirt operations

(cherry picked from commit 5cb090ed40)
This commit is contained in:
Wei Zhou 2013-08-06 12:40:06 +02:00
parent fd7b9c44bc
commit c229244dab
1 changed files with 12 additions and 6 deletions

View File

@ -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());
}
}