Commit 6ea23205 authored by Klaus Aehlig's avatar Klaus Aehlig
Browse files

Add a function to provide all the full lock state



This function will be used to provide the information required
to answer lock queries.
Signed-off-by: default avatarKlaus Aehlig <aehlig@google.com>
Reviewed-by: default avatarPetr Pudlak <pudlak@google.com>
parent 9fc1fe11
......@@ -30,6 +30,7 @@ module Ganeti.Locking.Allocation
, lockOwners
, listLocks
, listAllLocks
, listAllLocksOwners
, holdsLock
, LockRequest(..)
, requestExclusive
......@@ -131,6 +132,17 @@ listLocks owner = fromMaybe M.empty . M.lookup owner . laOwned
listAllLocks :: Ord b => LockAllocation a b -> [a]
listAllLocks = M.keys . laLocks
-- | Map an AllocationState to a list of pairs of owners and type of
-- ownership, showing the direct owners only.
toOwnersList :: AllocationState a b -> [(b, OwnerState)]
toOwnersList (Exclusive owner _) = [(owner, OwnExclusive)]
toOwnersList (Shared owners _) = map (flip (,) OwnShared) . S.elems $ owners
-- | List all locks currently (directly of indirectly) in use together
-- with the direct owners.
listAllLocksOwners :: LockAllocation a b -> [(a, [(b, OwnerState)])]
listAllLocksOwners = M.toList . M.map toOwnersList . laLocks
-- | Returns 'True' if the given owner holds the given lock at the given
-- ownership level or higher. This means that querying for a shared lock
-- returns 'True' of the owner holds the lock in shared or exlusive mode.
......
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