Commit 3977a4c1 authored by Guido Trotter's avatar Guido Trotter
Browse files

Make sharing locks possible

LUs can declare which locks they need by populating the
self.needed_locks dictionary, but those locks are always acquired as
exclusive. Make it possible to acquire shared locks as well, by
declaring a particular level as shared in the self.share_locks
dictionary. By default this dictionary is populated so that all locks
are acquired exclusively.

Reviewed-by: iustinp
parent fb8dcb62
......@@ -83,6 +83,7 @@ class LogicalUnit(object):
self.sstore = sstore
self.context = context
self.needed_locks = None
self.share_locks = dict(((i, 0) for i in locking.LEVELS))
self.__ssh = None
for attr_name in self._OP_REQP:
......@@ -128,6 +129,10 @@ class LogicalUnit(object):
(this reflects what LockSet does, and will be replaced before
CheckPrereq with the full list of nodes that have been locked)
If you need to share locks (rather than acquire them exclusively) at one
level you can modify self.share_locks, setting a true value (usually 1) for
that level. By default locks are not shared.
# Acquire all nodes and one instance
self.needed_locks = {
......@@ -134,10 +134,13 @@ class Processor(object):
# This gives a chance to LUs to make last-minute changes after acquiring
# locks at any preceding level.
needed_locks = lu.needed_locks[level]
share = lu.share_locks[level]
# This is always safe to do, as we can't acquire more/less locks than
# what was requested.
lu.needed_locks[level] = self.context.glm.acquire(level,
result = self._LockAndExecLU(lu, level + 1)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment