Move the release statement for the BGL to the finally block enclosing the statement that acquired it. In this way, we are sure to always eventually release the BGL. Also replace the freeing request by a FreeLocksLevel request, which also cancels all pending requests that still might exist.
Signed-off-by: Klaus Aehlig <[email protected]> --- lib/mcpu.py | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/lib/mcpu.py b/lib/mcpu.py index f08c3c9..db53ed3 100644 --- a/lib/mcpu.py +++ b/lib/mcpu.py @@ -633,26 +633,21 @@ class Processor(object): raise errors.ProgrammerError("Opcode '%s' requires BGL, but locks are" " disabled" % op.OP_ID) + lu = lu_class(self, op, self.context, self.cfg, self.rpc, + self._wconfdcontext, self.wconfd) + lu.wconfdlocks = self.wconfd.Client().ListLocks(self._wconfdcontext) + lu.ExpandNames() + assert lu.needed_locks is not None, "needed_locks not set by LU" + try: - lu = lu_class(self, op, self.context, self.cfg, self.rpc, - self._wconfdcontext, self.wconfd) - lu.wconfdlocks = self.wconfd.Client().ListLocks(self._wconfdcontext) - lu.ExpandNames() - assert lu.needed_locks is not None, "needed_locks not set by LU" - - try: - result = self._LockAndExecLU(lu, locking.LEVEL_CLUSTER + 1, - calc_timeout) - finally: - if self._ec_id: - self.cfg.DropECReservations(self._ec_id) + result = self._LockAndExecLU(lu, locking.LEVEL_CLUSTER + 1, + calc_timeout) finally: - # Release BGL if owned - bglname = "%s/%s" % (locking.LEVEL_NAMES[locking.LEVEL_CLUSTER], - locking.BGL) - self.wconfd.Client().TryUpdateLocks(self._wconfdcontext, - [[bglname, "release"]]) + if self._ec_id: + self.cfg.DropECReservations(self._ec_id) finally: + self.wconfd.Client().FreeLocksLevel( + self._wconfdcontext, locking.LEVEL_NAMES[locking.LEVEL_CLUSTER]) self._cbs = None self._CheckLUResult(op, result) -- 2.0.0.526.g5318336
