From 63e6a7f64c763e9b9fe30bc3d373fed8888cb587 Mon Sep 17 00:00:00 2001 From: Michael Hanselmann <hansmi@google.com> Date: Tue, 15 Nov 2011 12:23:43 +0100 Subject: [PATCH] cmdlib._ReleaseLock: Do nothing if no locks are owned MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The locking library doesn't like it when βrelease()β is called on a lockset or lock which isn't held by the current thread. Instead of modifying the library, which could have other side-effects, this rather simple change avoids errors when a LU simply tries to release all locks, even when it doesn't own any at a certain level. Signed-off-by: Michael Hanselmann <hansmi@google.com> Reviewed-by: Iustin Pop <iustin@google.com> --- lib/cmdlib.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/cmdlib.py b/lib/cmdlib.py index c61bc4d55..0e1e5827e 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -721,12 +721,17 @@ def _ReleaseLocks(lu, level, names=None, keep=None): else: should_release = None - if should_release: + owned = lu.owned_locks(level) + if not owned: + # Not owning any lock at this level, do nothing + pass + + elif should_release: retain = [] release = [] # Determine which locks to release - for name in lu.owned_locks(level): + for name in owned: if should_release(name): release.append(name) else: -- GitLab