Commit f066e7fb authored by Petr Pudlak's avatar Petr Pudlak
Browse files

Add a function for determining if a client holds a lock

This convenience function examines 'listLocks' for a particular owner
and checks, if it holds a given lock at a given ownership level (or
higher). Therefore checking for a shared locks returns 'True' if the
owner holds a shared or exclusive lock.
Signed-off-by: default avatarPetr Pudlak <>
Reviewed-by: default avatarKlaus Aehlig <>
parent 952cf6e2
......@@ -29,6 +29,7 @@ module Ganeti.Locking.Allocation
, OwnerState(..)
, lockOwners
, listLocks
, holdsLock
, LockRequest(..)
, requestExclusive
, requestShared
......@@ -125,6 +126,13 @@ lockOwners = M.keys . laOwned
listLocks :: Ord b => b -> LockAllocation a b -> M.Map a OwnerState
listLocks owner = fromMaybe M.empty . M.lookup owner . laOwned
-- | 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.
holdsLock :: (Ord a, Ord b)
=> b -> a -> OwnerState -> LockAllocation a b -> Bool
holdsLock owner lock state = (>= Just state) . M.lookup lock . listLocks owner
-- | Data Type describing a change request on a single lock.
data LockRequest a = LockRequest { lockAffected :: a
, lockRequestType :: Maybe OwnerState
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