Commit 5d9efc0f authored by Klaus Aehlig's avatar Klaus Aehlig
Browse files

Make locks field use live data

So far, the description of the locks fields was made under the assumption
that lock queries wouldn't be answered by Luxid anyway, and hence it was
enough to parse such requests. However, now luxid will answer these queries
after getting a snapshot of the locks status from wconfd. Hence make the fields
describe how to obtain the information from the data obtained at run time.
Signed-off-by: default avatarKlaus Aehlig <>
Reviewed-by: default avatarPetr Pudlak <>
parent d00aadee
......@@ -28,27 +28,54 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
module Ganeti.Query.Locks
( fieldsMap
, RuntimeData
) where
import qualified Text.JSON as J
import Ganeti.Locking.Allocation (OwnerState(..))
import Ganeti.Locking.Locks (GanetiLocks, ClientId, ciIdentifier)
import Ganeti.Query.Common
import Ganeti.Query.Language
import Ganeti.Query.Types
-- | The runtime information for locks. As all information about locks
-- 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)])
-- | Obtain the owners of a lock from the runtime data.
getOwners :: RuntimeData -> a -> ResultEntry
getOwners (Just (_, ownerinfo)) _ =
rsNormal . map (either J.encode J.encode . ciIdentifier . fst)
$ ownerinfo
getOwners _ _ = rsNormal ([] :: [(ClientId, OwnerState)])
-- | Obtain the mode of a lock from the runtime data.
getMode :: RuntimeData -> a -> ResultEntry
getMode (Just (_, ownerinfo)) _
| null ownerinfo = rsNormal J.JSNull
| any ((==) OwnExclusive . snd) ownerinfo = rsNormal "exclusive"
| otherwise = rsNormal "shared"
getMode _ _ = rsNormal J.JSNull
-- | List of all lock fields.
lockFields :: FieldList String ()
lockFields :: FieldList String RuntimeData
lockFields =
[ (FieldDefinition "name" "Name" QFTOther "Lock name",
FieldSimple rsNormal, QffNormal)
, (FieldDefinition "mode" "Mode" QFTOther "Mode in which the lock is\
\ currently acquired\
\ (exclusive or shared)",
FieldSimple rsNormal, QffNormal)
FieldRuntime getMode, QffNormal)
, (FieldDefinition "owner" "Owner" QFTOther "Current lock owner(s)",
FieldSimple rsNormal, QffNormal)
FieldRuntime getOwners, QffNormal)
, (FieldDefinition "pending" "Pending" QFTOther "Jobs waiting for the lock",
FieldSimple rsNormal, QffNormal)
FieldSimple (const $ rsNormal ([] :: [ClientId])), QffNormal)
-- TODO: as soon as jobs stop polling, report the pending locks
-- | The lock fields map.
fieldsMap :: FieldMap String ()
fieldsMap :: FieldMap String RuntimeData
fieldsMap = fieldListToFieldMap lockFields
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