|
|
|
|
|
Description |
Implementation of the Ganeti confd server functionality.
|
|
Synopsis |
|
type CRef = IORef (Result (ConfigData, LinkIpMap)) | | type FStat = (EpochTime, FileID, FileOffset) | | nullFStat :: FStat | | type StatusAnswer = (ConfdReplyStatus, JSValue) | | | | data ServerState = ServerState {} | | maxIdlePollRounds :: Int | | configReloadTimeout :: Int | | configReloadRatelimit :: Int | | initialPoll :: ReloadModel | | initialState :: ServerState | | | | queryUnknownEntry :: StatusAnswer | | queryArgumentError :: StatusAnswer | | getCurrentTime :: IO Integer | | getClusterHmac :: IO HashKey | | nodeRole :: ConfigData -> String -> Result ConfdNodeRole | | getNodePipByInstanceIp :: ConfigData -> LinkIpMap -> String -> String -> StatusAnswer | | buildResponse :: (ConfigData, LinkIpMap) -> ConfdRequest -> Result StatusAnswer | | parseRequest :: HashKey -> String -> Result (String, String, ConfdRequest) | | serializeResponse :: Result StatusAnswer -> ConfdReply | | signMessage :: HashKey -> String -> String -> SignedMessage | | moveToPolling :: String -> INotify -> FilePath -> CRef -> MVar ServerState -> IO ReloadModel | | moveToNotify :: IO ReloadModel | | updateConfig :: FilePath -> CRef -> IO () | | safeUpdateConfig :: FilePath -> FStat -> CRef -> IO (FStat, ConfigReload) | | buildFileStatus :: FileStatus -> FStat | | getFStat :: FilePath -> IO FStat | | needsReload :: FStat -> FilePath -> IO (Maybe FStat) | | onTimeoutTimer :: IO Bool -> FilePath -> CRef -> MVar ServerState -> IO () | | onTimeoutInner :: FilePath -> CRef -> ServerState -> IO ServerState | | onReloadTimer :: IO Bool -> FilePath -> CRef -> MVar ServerState -> IO () | | onReloadInner :: IO Bool -> FilePath -> CRef -> ServerState -> IO (ServerState, Bool) | | addNotifier :: INotify -> FilePath -> CRef -> MVar ServerState -> IO Bool | | onInotify :: INotify -> String -> CRef -> MVar ServerState -> Event -> IO () | | responder :: CRef -> Socket -> HashKey -> String -> SockAddr -> IO () | | parseMessage :: HashKey -> String -> Integer -> Result (String, ConfdRequest) | | respondInner :: Result (ConfigData, LinkIpMap) -> HashKey -> ConfdRequest -> String | | listener :: Socket -> HashKey -> (Socket -> HashKey -> String -> SockAddr -> IO ()) -> IO () | | main :: DaemonOptions -> IO () |
|
|
|
Types and constants definitions
|
|
|
What we store as configuration.
|
|
type FStat = (EpochTime, FileID, FileOffset) | Source |
|
File stat identifier.
|
|
|
Null FStat value.
|
|
|
A small type alias for readability.
|
|
|
Reload model data type.
| Constructors | ReloadNotify | We are using notifications
| ReloadPoll Int | We are using polling
|
|
|
|
|
Server state data type.
| Constructors | |
|
|
maxIdlePollRounds :: Int | Source |
|
Maximum no-reload poll rounds before reverting to inotify.
|
|
configReloadTimeout :: Int | Source |
|
Reload timeout in microseconds.
|
|
configReloadRatelimit :: Int | Source |
|
Ratelimit timeout in microseconds.
|
|
|
Initial poll round.
|
|
|
Initial server state.
|
|
|
Reload status data type.
| Constructors | ConfigToDate | No need to reload
| ConfigReloaded | Configuration reloaded
| ConfigIOError | Error during configuration reload
|
|
|
|
|
Unknown entry standard response.
|
|
|
Argument error standard response.
|
|
getCurrentTime :: IO Integer | Source |
|
Returns the current time.
|
|
Confd base functionality
|
|
|
Returns the HMAC key.
|
|
|
Computes the node role.
|
|
|
Does an instance ip -> instance -> primary node -> primary ip
transformation.
|
|
|
Builds the response to a given query.
|
|
|
Parses a signed request.
|
|
|
Creates a ConfdReply from a given answer.
|
|
|
Signs a message with a given key and salt.
|
|
Configuration handling
|
|
Helper functions
|
|
|
Helper function for logging transition into polling mode.
|
|
|
Helper function for logging transition into inotify mode.
|
|
Configuration loading
|
|
|
(Re)loads the configuration.
|
|
|
Wrapper over updateConfig that handles IO errors.
|
|
|
Computes the file cache data from a FileStatus structure.
|
|
|
Wrapper over buildFileStatus. This reads the data from the
filesystem and then builds our cache structure.
|
|
|
Check if the file needs reloading
|
|
Watcher threads
|
|
We have three threads/functions that can mutate the server state:
1. the long-interval watcher (onTimeoutTimer)
2. the polling watcher (onReloadTimer)
3. the inotify event handler (onInotify)
All of these will mutate the server state under modifyMVar or
modifyMVar_, so that server transitions are more or less
atomic. The inotify handler remains active during polling mode, but
checks for polling mode and doesn't do anything in this case (this
check is needed even if we would unregister the event handler due
to how events are serialised).
|
|
|
Long-interval reload watcher.
This is on top of the inotify-based triggered reload.
|
|
|
Inner onTimeout handler.
This mutates the server state under a modifyMVar_ call. It never
changes the reload model, just does a safety reload and tried to
re-establish the inotify watcher.
|
|
|
Short-interval (polling) reload watcher.
This is only active when we're in polling mode; it will
automatically exit when it detects that the state has changed to
notification.
|
|
|
Inner onReload handler.
This again mutates the state under a modifyMVar call, and also
returns whether the thread should continue or not.
|
|
|
Setup inotify watcher.
This tries to setup the watch descriptor; in case of any IO errors,
it will return False.
|
|
|
Inotify event handler.
|
|
Client input/output handlers
|
|
|
Main loop for a given client.
|
|
|
Mesage parsing. This can either result in a good, valid message,
or fail in the Result monad.
|
|
|
Inner helper function for a given client. This generates the
final encoded message (as a string), ready to be sent out to the
client.
|
|
|
Main listener loop.
|
|
|
Main function.
|
|
Produced by Haddock version 2.6.0 |