+ """
+ adding_locks = level in lu.add_locks
+ acquiring_locks = level in lu.needed_locks
+ if level not in locking.LEVELS:
+ if callable(self._run_notifier):
+ self._run_notifier()
+ result = self._ExecLU(lu)
+ elif adding_locks and acquiring_locks:
+ # We could both acquire and add locks at the same level, but for now we
+ # don't need this, so we'll avoid the complicated code needed.
+ raise NotImplementedError(
+ "Can't declare locks to acquire when adding others")
+ elif adding_locks or acquiring_locks:
+ lu.DeclareLocks(level)
+ share = lu.share_locks[level]
+ if acquiring_locks:
+ needed_locks = lu.needed_locks[level]
+ lu.acquired_locks[level] = self.context.glm.acquire(level,
+ needed_locks,
+ shared=share)
+ else: # adding_locks
+ add_locks = lu.add_locks[level]
+ lu.remove_locks[level] = add_locks
+ try:
+ self.context.glm.add(level, add_locks, acquired=1, shared=share)
+ except errors.LockError:
+ raise errors.OpPrereqError(
+ "Coudn't add locks (%s), probably because of a race condition"
+ " with another job, who added them first" % add_locks)
+ try:
+ try:
+ if adding_locks:
+ lu.acquired_locks[level] = add_locks
+ result = self._LockAndExecLU(lu, level + 1)
+ finally:
+ if level in lu.remove_locks:
+ self.context.glm.remove(level, lu.remove_locks[level])
+ finally:
+ if self.context.glm.is_owned(level):
+ self.context.glm.release(level)
+ else:
+ result = self._LockAndExecLU(lu, level + 1)
+
+ return result
+
+ def ExecOpCode(self, op, feedback_fn, run_notifier):
+ """Execute an opcode.
+
+ @type op: an OpCode instance
+ @param op: the opcode to be executed
+ @type feedback_fn: a function that takes a single argument
+ @param feedback_fn: this function will be used as feedback from the LU
+ code to the end-user
+ @type run_notifier: callable (no arguments) or None
+ @param run_notifier: this function (if callable) will be called when
+ we are about to call the lu's Exec() method, that
+ is, after we have aquired all locks