X-Git-Url: https://code.grnet.gr/git/ganeti-local/blobdiff_plain/a68fe106549cc204c73210d02b81f608f10361be..b8802cc4d70081232ecee88eedec07189dc77468:/lib/locking.py diff --git a/lib/locking.py b/lib/locking.py index 84268de..d89388c 100644 --- a/lib/locking.py +++ b/lib/locking.py @@ -749,7 +749,7 @@ class SharedLock(object): return False - def acquire(self, shared=0, timeout=None, priority=_DEFAULT_PRIORITY, + def acquire(self, shared=0, timeout=None, priority=None, test_notify=None): """Acquire a shared lock. @@ -764,6 +764,9 @@ class SharedLock(object): @param test_notify: Special callback function for unittesting """ + if priority is None: + priority = _DEFAULT_PRIORITY + self.__lock.acquire() try: # We already got the lock, notify now @@ -800,7 +803,7 @@ class SharedLock(object): finally: self.__lock.release() - def delete(self, timeout=None, priority=_DEFAULT_PRIORITY): + def delete(self, timeout=None, priority=None): """Delete a Shared Lock. This operation will declare the lock for removal. First the lock will be @@ -813,6 +816,9 @@ class SharedLock(object): @param priority: Priority for acquiring lock """ + if priority is None: + priority = _DEFAULT_PRIORITY + self.__lock.acquire() try: assert not self.__is_sharer(), "Cannot delete() a lock while sharing it" @@ -992,7 +998,7 @@ class LockSet: self.__lock.release() return set(result) - def acquire(self, names, timeout=None, shared=0, priority=_DEFAULT_PRIORITY, + def acquire(self, names, timeout=None, shared=0, priority=None, test_notify=None): """Acquire a set of resource locks. @@ -1022,6 +1028,9 @@ class LockSet: assert not self._is_owned(), ("Cannot acquire locks in the same set twice" " (lockset %s)" % self.name) + if priority is None: + priority = _DEFAULT_PRIORITY + # We need to keep track of how long we spent waiting for a lock. The # timeout passed to this function is over all lock acquires. running_timeout = RunningTimeout(timeout, False) @@ -1443,7 +1452,7 @@ class GanetiLockManager: """ return level == LEVEL_CLUSTER and (names is None or BGL in names) - def acquire(self, level, names, timeout=None, shared=0): + def acquire(self, level, names, timeout=None, shared=0, priority=None): """Acquire a set of resource locks, at the same level. @type level: member of locking.LEVELS @@ -1456,6 +1465,8 @@ class GanetiLockManager: an exclusive lock will be acquired @type timeout: float @param timeout: Maximum time to acquire all locks + @type priority: integer + @param priority: Priority for acquiring lock """ assert level in LEVELS, "Invalid locking level %s" % level @@ -1474,7 +1485,8 @@ class GanetiLockManager: " while owning some at a greater one") # Acquire the locks in the set. - return self.__keyring[level].acquire(names, shared=shared, timeout=timeout) + return self.__keyring[level].acquire(names, shared=shared, timeout=timeout, + priority=priority) def release(self, level, names=None): """Release a set of resource locks, at the same level.