Commit e310b019 authored by Guido Trotter's avatar Guido Trotter
Browse files

Add locking.ALL_SET constant and use it

Rather than specifying None in needed_locks every time, with a nice
comment saying to read what we mean rather than what we write, and that
None actually means All, in our magic world, we'll hide this secret
under the ALL_SET constant in the locking module, which has value, you
guessed it, None. After that we'll substitute all usage in cmdlib.

Some comments and examples have been fixed as well.

Reviewed-by: iustinp
parent 45bc5e4a
......@@ -126,9 +126,7 @@ class LogicalUnit(object):
- Use an empty dict if you don't need any lock
- If you don't need any lock at a particular level omit that level
- Don't put anything for the BGL level
- If you want all locks at a level use None as a value
(this reflects what LockSet does, and will be replaced before
CheckPrereq with the full list of nodes that have been locked)
- If you want all locks at a level use locking.ALL_SET as a value
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
......@@ -137,7 +135,7 @@ class LogicalUnit(object):
Examples:
# Acquire all nodes and one instance
self.needed_locks = {
locking.LEVEL_NODE: None,
locking.LEVEL_NODE: locking.ALL_SET,
locking.LEVEL_INSTANCES: ['instance1.example.tld'],
}
# Acquire just two nodes
......@@ -1232,7 +1230,7 @@ class LUDiagnoseOS(NoHooksLU):
# Lock all nodes, in shared mode
self.needed_locks = {}
self.share_locks[locking.LEVEL_NODE] = 1
self.needed_locks[locking.LEVEL_NODE] = None
self.needed_locks[locking.LEVEL_NODE] = locking.ALL_SET
def CheckPrereq(self):
"""Check prerequisites.
......@@ -1395,7 +1393,7 @@ class LUQueryNodes(NoHooksLU):
# that we need atomic ways to get info for a group of nodes from the
# config, though.
if not self.op.names:
self.needed_locks[locking.LEVEL_NODE] = None
self.needed_locks[locking.LEVEL_NODE] = locking.ALL_SET
else:
self.needed_locks[locking.LEVEL_NODE] = \
_GetWantedNodes(self, self.op.names)
......@@ -1499,7 +1497,7 @@ class LUQueryNodeVolumes(NoHooksLU):
self.needed_locks = {}
self.share_locks[locking.LEVEL_NODE] = 1
if not self.op.nodes:
self.needed_locks[locking.LEVEL_NODE] = None
self.needed_locks[locking.LEVEL_NODE] = locking.ALL_SET
else:
self.needed_locks[locking.LEVEL_NODE] = \
_GetWantedNodes(self, self.op.nodes)
......@@ -2504,7 +2502,7 @@ class LUQueryInstances(NoHooksLU):
# dynamic fields. For that we need atomic ways to get info for a group of
# instances from the config, though.
if not self.op.names:
self.needed_locks[locking.LEVEL_INSTANCE] = None # Acquire all
self.needed_locks[locking.LEVEL_INSTANCE] = locking.ALL_SET
else:
self.needed_locks[locking.LEVEL_INSTANCE] = \
_GetWantedInstances(self, self.op.names)
......@@ -4479,7 +4477,7 @@ class LUQueryExports(NoHooksLU):
self.needed_locks = {}
self.share_locks[locking.LEVEL_NODE] = 1
if not self.op.nodes:
self.needed_locks[locking.LEVEL_NODE] = None
self.needed_locks[locking.LEVEL_NODE] = locking.ALL_SET
else:
self.needed_locks[locking.LEVEL_NODE] = \
_GetWantedNodes(self, self.op.nodes)
......
......@@ -298,6 +298,11 @@ class SharedLock:
self.__lock.release()
# Whenever we want to acquire a full LockSet we pass None as the value to acquire.
# Hide this behing this nicely named constant.
ALL_SET = None
class LockSet:
"""Implements a set of locks.
......
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