Revision a317d77a src/Ganeti/WConfd/Monad.hs

b/src/Ganeti/WConfd/Monad.hs
43 43
  , runWConfdMonadInt
44 44
  , WConfdMonad
45 45
  , modifyConfigState
46
  , modifyLockAllocation
46 47
  ) where
47 48

  
48 49
import Control.Applicative
......
55 56

  
56 57
import Ganeti.BasicTypes
57 58
import Ganeti.Errors
59
import Ganeti.Locking.Locks
58 60
import Ganeti.Logging
59 61
import Ganeti.Types
60 62
import Ganeti.WConfd.ConfigState
......
63 65

  
64 66
-- | The state of the daemon, capturing both the configuration state and the
65 67
-- locking state.
66
--
67
-- Currently contains only the configuration state, the the locking state will
68
-- go here in the future as well.
69 68
data DaemonState = DaemonState
70 69
  { dsConfigState :: ConfigState
70
  , dsLockAllocation :: GanetiLockAllocation
71 71
  }
72 72

  
73 73
data DaemonHandle = DaemonHandle
......
80 80

  
81 81
mkDaemonHandle :: FilePath
82 82
               -> ConfigState
83
               -> GanetiLockAllocation
83 84
               -> ResultT GanetiException IO DaemonHandle
84
mkDaemonHandle cp cs =
85
  DaemonHandle <$> liftBase (newIORef $ DaemonState cs) <*> pure cp
85
mkDaemonHandle cp cs la =
86
  DaemonHandle <$> liftBase (newIORef $ DaemonState cs la) <*> pure cp
86 87

  
87 88
data ClientState = ClientState
88 89
  { clLiveFilePath :: FilePath
......
145 146
  let mf ds = let (cs', r) = f (dsConfigState ds)
146 147
              in (ds { dsConfigState = cs' }, r)
147 148
  liftBase $ atomicModifyIORef (dhDaemonState dh) mf
149

  
150
-- | Atomically modifies the lock allocation state in WConfdMonad.
151
modifyLockAllocation :: (GanetiLockAllocation -> (GanetiLockAllocation, a))
152
                     -> WConfdMonad a
153
modifyLockAllocation f = do
154
  dh <- lift . WConfdMonadInt $ ask
155
  let mf ds = let (la', r) = f (dsLockAllocation ds)
156
              in (ds { dsLockAllocation = la' }, r)
157
  liftBase $ atomicModifyIORef (dhDaemonState dh) mf

Also available in: Unified diff