ganeti-htoolsSource codeContentsIndex
Ganeti.Confd.Server
Contents
Types and constants definitions
Confd base functionality
Configuration handling
Helper functions
Configuration loading
Watcher threads
Client input/output handlers
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 ReloadModel
= ReloadNotify
| ReloadPoll Int
data ServerState = ServerState {
reloadModel :: ReloadModel
reloadTime :: Integer
reloadFStat :: FStat
}
maxIdlePollRounds :: Int
configReloadTimeout :: Int
configReloadRatelimit :: Int
initialPoll :: ReloadModel
initialState :: ServerState
data ConfigReload
= ConfigToDate
| ConfigReloaded
| ConfigIOError
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
type CRef = IORef (Result (ConfigData, LinkIpMap))Source
What we store as configuration.
type FStat = (EpochTime, FileID, FileOffset)Source
File stat identifier.
nullFStat :: FStatSource
Null FStat value.
type StatusAnswer = (ConfdReplyStatus, JSValue)Source
A small type alias for readability.
data ReloadModel Source
Reload model data type.
Constructors
ReloadNotifyWe are using notifications
ReloadPoll IntWe are using polling
data ServerState Source
Server state data type.
Constructors
ServerState
reloadModel :: ReloadModel
reloadTime :: Integer
reloadFStat :: FStat
maxIdlePollRounds :: IntSource
Maximum no-reload poll rounds before reverting to inotify.
configReloadTimeout :: IntSource
Reload timeout in microseconds.
configReloadRatelimit :: IntSource
Ratelimit timeout in microseconds.
initialPoll :: ReloadModelSource
Initial poll round.
initialState :: ServerStateSource
Initial server state.
data ConfigReload Source
Reload status data type.
Constructors
ConfigToDateNo need to reload
ConfigReloadedConfiguration reloaded
ConfigIOErrorError during configuration reload
queryUnknownEntry :: StatusAnswerSource
Unknown entry standard response.
queryArgumentError :: StatusAnswerSource
Argument error standard response.
getCurrentTime :: IO IntegerSource
Returns the current time.
Confd base functionality
getClusterHmac :: IO HashKeySource
Returns the HMAC key.
nodeRole :: ConfigData -> String -> Result ConfdNodeRoleSource
Computes the node role.
getNodePipByInstanceIp :: ConfigData -> LinkIpMap -> String -> String -> StatusAnswerSource
Does an instance ip -> instance -> primary node -> primary ip transformation.
buildResponse :: (ConfigData, LinkIpMap) -> ConfdRequest -> Result StatusAnswerSource
Builds the response to a given query.
parseRequest :: HashKey -> String -> Result (String, String, ConfdRequest)Source
Parses a signed request.
serializeResponse :: Result StatusAnswer -> ConfdReplySource
Creates a ConfdReply from a given answer.
signMessage :: HashKey -> String -> String -> SignedMessageSource
Signs a message with a given key and salt.
Configuration handling
Helper functions
moveToPolling :: String -> INotify -> FilePath -> CRef -> MVar ServerState -> IO ReloadModelSource
Helper function for logging transition into polling mode.
moveToNotify :: IO ReloadModelSource
Helper function for logging transition into inotify mode.
Configuration loading
updateConfig :: FilePath -> CRef -> IO ()Source
(Re)loads the configuration.
safeUpdateConfig :: FilePath -> FStat -> CRef -> IO (FStat, ConfigReload)Source
Wrapper over updateConfig that handles IO errors.
buildFileStatus :: FileStatus -> FStatSource
Computes the file cache data from a FileStatus structure.
getFStat :: FilePath -> IO FStatSource
Wrapper over buildFileStatus. This reads the data from the filesystem and then builds our cache structure.
needsReload :: FStat -> FilePath -> IO (Maybe FStat)Source
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).

onTimeoutTimer :: IO Bool -> FilePath -> CRef -> MVar ServerState -> IO ()Source

Long-interval reload watcher.

This is on top of the inotify-based triggered reload.

onTimeoutInner :: FilePath -> CRef -> ServerState -> IO ServerStateSource

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.

onReloadTimer :: IO Bool -> FilePath -> CRef -> MVar ServerState -> IO ()Source

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.

onReloadInner :: IO Bool -> FilePath -> CRef -> ServerState -> IO (ServerState, Bool)Source

Inner onReload handler.

This again mutates the state under a modifyMVar call, and also returns whether the thread should continue or not.

addNotifier :: INotify -> FilePath -> CRef -> MVar ServerState -> IO BoolSource

Setup inotify watcher.

This tries to setup the watch descriptor; in case of any IO errors, it will return False.

onInotify :: INotify -> String -> CRef -> MVar ServerState -> Event -> IO ()Source
Inotify event handler.
Client input/output handlers
responder :: CRef -> Socket -> HashKey -> String -> SockAddr -> IO ()Source
Main loop for a given client.
parseMessage :: HashKey -> String -> Integer -> Result (String, ConfdRequest)Source
Mesage parsing. This can either result in a good, valid message, or fail in the Result monad.
respondInner :: Result (ConfigData, LinkIpMap) -> HashKey -> ConfdRequest -> StringSource
Inner helper function for a given client. This generates the final encoded message (as a string), ready to be sent out to the client.
listener :: Socket -> HashKey -> (Socket -> HashKey -> String -> SockAddr -> IO ()) -> IO ()Source
Main listener loop.
main :: DaemonOptions -> IO ()Source
Main function.
Produced by Haddock version 2.6.0