Commit 0191874e authored by Petr Pudlak's avatar Petr Pudlak

Separate client and server config for Luxi communication

The daemon identity is only required for server connections to set the
access mode to its socket appropriately. For client connections it's
not needed and requiring it prevents creating standalone clients, for
example for inter-process communication.
Signed-off-by: default avatarPetr Pudlak <pudlak@google.com>
Reviewed-by: default avatarKlaus Aehlig <aehlig@google.com>
parent 8275c414
......@@ -171,15 +171,15 @@ $(genAllConstr (drop 3) ''LuxiReq "allLuxiCalls")
$(genStrOfOp ''LuxiOp "strOfOp")
luxiConnectConfig :: ConnectConfig
luxiConnectConfig = ConnectConfig { connDaemon = GanetiLuxid
, recvTmo = luxiDefRwto
, sendTmo = luxiDefRwto
}
luxiConnectConfig :: ServerConfig
luxiConnectConfig = ServerConfig GanetiLuxid
ConnectConfig { recvTmo = luxiDefRwto
, sendTmo = luxiDefRwto
}
-- | Connects to the master daemon and returns a luxi Client.
getLuxiClient :: String -> IO Client
getLuxiClient = connectClient luxiConnectConfig luxiDefCtmo
getLuxiClient = connectClient (connConfig luxiConnectConfig) luxiDefCtmo
-- | Creates and returns a server endpoint.
getLuxiServer :: Bool -> FilePath -> IO Server
......
......@@ -36,7 +36,7 @@ import Ganeti.Path as Path
import Ganeti.Daemon (DaemonOptions)
import qualified Ganeti.Logging as Logging
import Ganeti.Runtime (GanetiDaemon(..))
import Ganeti.UDSServer (Client, ConnectConfig(..), Server)
import Ganeti.UDSServer (Client, ConnectConfig(..), Server, ServerConfig(..))
import qualified Ganeti.UDSServer as UDSServer
import Ganeti.Metad.Config as Config
......@@ -94,4 +94,4 @@ start _ config =
(acceptClients config server)
(UDSServer.closeServer server)
where
metadConfig = ConnectConfig GanetiMetad 60 60
metadConfig = ServerConfig GanetiMetad $ ConnectConfig 60 60
......@@ -28,6 +28,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
module Ganeti.UDSServer
( ConnectConfig(..)
, ServerConfig(..)
, Client
, Server
, RecvResult(..)
......@@ -129,9 +130,15 @@ data MsgKeys = Method
$(genStrOfKey ''MsgKeys "strOfKey")
-- Information required for creating a server connection.
data ServerConfig = ServerConfig
{ connDaemon :: GanetiDaemon
, connConfig :: ConnectConfig
}
-- Information required for creating a client or server connection.
data ConnectConfig = ConnectConfig
{ connDaemon :: GanetiDaemon
, recvTmo :: Int
{ recvTmo :: Int
, sendTmo :: Int
}
......@@ -201,13 +208,13 @@ connectClient conf tmo path = do
return Client { rsocket=h, wsocket=h, rbuf=rf, clientConfig=conf }
-- | Creates and returns a server endpoint.
connectServer :: ConnectConfig -> Bool -> FilePath -> IO Server
connectServer conf setOwner path = do
connectServer :: ServerConfig -> Bool -> FilePath -> IO Server
connectServer sconf setOwner path = do
s <- openServerSocket path
when setOwner . setOwnerAndGroupFromNames path (connDaemon conf) $
when setOwner . setOwnerAndGroupFromNames path (connDaemon sconf) $
ExtraGroup DaemonsGroup
S.listen s 5 -- 5 is the max backlog
return Server { sSocket=s, sPath=path, serverConfig=conf }
return Server { sSocket = s, sPath = path, serverConfig = connConfig sconf }
-- | Creates a new bi-directional client pipe. The two returned clients
-- talk to each other through the pipe.
......
......@@ -31,7 +31,6 @@ module Ganeti.WConfd.Client where
import Ganeti.THH.HsRPC
import Ganeti.Constants
import Ganeti.Runtime (GanetiDaemon(..))
import Ganeti.UDSServer (ConnectConfig(..), Client, connectClient)
import Ganeti.WConfd.Core (exportedFunctions)
......@@ -43,8 +42,7 @@ $(mkRpcCalls exportedFunctions)
-- | The default WConfd client configuration
wconfdConnectConfig :: ConnectConfig
wconfdConnectConfig = ConnectConfig { connDaemon = GanetiWConfd
, recvTmo = wconfdDefRwto
wconfdConnectConfig = ConnectConfig { recvTmo = wconfdDefRwto
, sendTmo = wconfdDefRwto
}
......
......@@ -70,7 +70,7 @@ prepMain _ _ = do
socket_path <- Path.defaultWConfdSocket
cleanupSocket socket_path
s <- describeError "binding to the socket" Nothing (Just socket_path)
$ connectServer connectConfig True socket_path
$ connectServer serverConfig True socket_path
-- TODO: Lock the configuration file so that running the daemon twice fails?
conf_file <- Path.clusterConfFile
......@@ -97,8 +97,8 @@ prepMain _ _ = do
return (s, dh)
connectConfig :: ConnectConfig
connectConfig = ConnectConfig GanetiLuxid 60 60
serverConfig :: ServerConfig
serverConfig = ServerConfig GanetiLuxid $ ConnectConfig 60 60
-- | Main function.
main :: MainFn () PrepResult
......
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