To fully answer queries about locks, the live data also needs to include information about pending requests. To comply with the general scheme of queries, the information is resampled per lock.
Signed-off-by: Klaus Aehlig <[email protected]> --- src/Ganeti/Query/Locks.hs | 9 ++++++--- src/Ganeti/Query/Query.hs | 3 ++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Ganeti/Query/Locks.hs b/src/Ganeti/Query/Locks.hs index 183d8a8..a915b3a 100644 --- a/src/Ganeti/Query/Locks.hs +++ b/src/Ganeti/Query/Locks.hs @@ -43,18 +43,21 @@ import Ganeti.Query.Types -- is handled by WConfD, the actual information is obtained as live data. -- The type represents the information for a single lock, even though all -- locks are queried simultaneously, ahead of time. -type RuntimeData = Maybe (GanetiLocks, [(ClientId, OwnerState)]) +type RuntimeData = Maybe ( GanetiLocks + , [(ClientId, OwnerState)] -- current state + , [(ClientId, OwnerState)] -- pending requests + ) -- | Obtain the owners of a lock from the runtime data. getOwners :: RuntimeData -> a -> ResultEntry -getOwners (Just (_, ownerinfo)) _ = +getOwners (Just (_, ownerinfo, _)) _ = rsNormal . map (J.encode . ciIdentifier . fst) $ ownerinfo getOwners _ _ = rsNormal ([] :: [ClientId]) -- | Obtain the mode of a lock from the runtime data. getMode :: RuntimeData -> a -> ResultEntry -getMode (Just (_, ownerinfo)) _ +getMode (Just (_, ownerinfo, _)) _ | null ownerinfo = rsNormal J.JSNull | any ((==) OwnExclusive . snd) ownerinfo = rsNormal "exclusive" | otherwise = rsNormal "shared" diff --git a/src/Ganeti/Query/Query.hs b/src/Ganeti/Query/Query.hs index 3cb7c0d..dadd36d 100644 --- a/src/Ganeti/Query/Query.hs +++ b/src/Ganeti/Query/Query.hs @@ -235,7 +235,8 @@ recollectLocksData :: [(GanetiLocks, [(ClientId, OwnerState)])] -> Bool -> ConfigData -> [String] -> IO [(String, Locks.RuntimeData)] recollectLocksData allLocks _ _ = - let lookuplock lock = (,) lock + let lookuplock lock = (,) lock + . fmap (\(l, c) -> (l, c, [])) . find ((==) lock . lockName . fst) $ allLocks in return . map lookuplock -- 2.0.0.526.g5318336
