Enable disk growth with exclusive storage
[ganeti-local] / lib / locking.py
index b0b4758..7a23af6 100644 (file)
@@ -56,7 +56,7 @@ _LOCK_ACQUIRE_MIN_TIMEOUT = (1.0 / 1000)
  _LS_ACQUIRE_ALL,
  _LS_ACQUIRE_OPPORTUNISTIC) = range(1, 4)
 
-_LS_ACQUIRE_MODES = frozenset([
+_LS_ACQUIRE_MODES = compat.UniqueFrozenset([
   _LS_ACQUIRE_EXACT,
   _LS_ACQUIRE_ALL,
   _LS_ACQUIRE_OPPORTUNISTIC,
@@ -1599,7 +1599,7 @@ LEVELS = [
   ]
 
 # Lock levels which are modifiable
-LEVELS_MOD = frozenset([
+LEVELS_MOD = compat.UniqueFrozenset([
   LEVEL_NODE_RES,
   LEVEL_NODE,
   LEVEL_NODEGROUP,
@@ -1636,15 +1636,15 @@ class GanetiLockManager:
   """
   _instance = None
 
-  def __init__(self, nodes, nodegroups, instances, networks):
+  def __init__(self, node_uuids, nodegroups, instance_names, networks):
     """Constructs a new GanetiLockManager object.
 
     There should be only a GanetiLockManager object at any time, so this
     function raises an error if this is not the case.
 
-    @param nodes: list of node names
+    @param node_uuids: list of node UUIDs
     @param nodegroups: list of nodegroup uuids
-    @param instances: list of instance names
+    @param instance_names: list of instance names
 
     """
     assert self.__class__._instance is None, \
@@ -1658,10 +1658,11 @@ class GanetiLockManager:
     # locking order.
     self.__keyring = {
       LEVEL_CLUSTER: LockSet([BGL], "cluster", monitor=self._monitor),
-      LEVEL_NODE: LockSet(nodes, "node", monitor=self._monitor),
-      LEVEL_NODE_RES: LockSet(nodes, "node-res", monitor=self._monitor),
+      LEVEL_NODE: LockSet(node_uuids, "node", monitor=self._monitor),
+      LEVEL_NODE_RES: LockSet(node_uuids, "node-res", monitor=self._monitor),
       LEVEL_NODEGROUP: LockSet(nodegroups, "nodegroup", monitor=self._monitor),
-      LEVEL_INSTANCE: LockSet(instances, "instance", monitor=self._monitor),
+      LEVEL_INSTANCE: LockSet(instance_names, "instance",
+                              monitor=self._monitor),
       LEVEL_NETWORK: LockSet(networks, "network", monitor=self._monitor),
       LEVEL_NODE_ALLOC: LockSet([NAL], "node-alloc", monitor=self._monitor),
       }
@@ -1751,7 +1752,8 @@ class GanetiLockManager:
     """
     return level == LEVEL_CLUSTER and (names is None or BGL in names)
 
-  def acquire(self, level, names, timeout=None, shared=0, priority=None):
+  def acquire(self, level, names, timeout=None, shared=0, priority=None,
+              opportunistic=False):
     """Acquire a set of resource locks, at the same level.
 
     @type level: member of locking.LEVELS
@@ -1766,6 +1768,9 @@ class GanetiLockManager:
     @param timeout: Maximum time to acquire all locks
     @type priority: integer
     @param priority: Priority for acquiring lock
+    @type opportunistic: boolean
+    @param opportunistic: Acquire locks opportunistically; use the return value
+      to determine which locks were actually acquired
 
     """
     assert level in LEVELS, "Invalid locking level %s" % level
@@ -1785,7 +1790,8 @@ class GanetiLockManager:
 
     # Acquire the locks in the set.
     return self.__keyring[level].acquire(names, shared=shared, timeout=timeout,
-                                         priority=priority)
+                                         priority=priority,
+                                         opportunistic=opportunistic)
 
   def downgrade(self, level, names=None):
     """Downgrade a set of resource locks from exclusive to shared mode.