This patch modifies the KVM daemon startup to test whether the node if
the enabled hypervisor is KVM, whether the node is VM capable, and if
user shutdown is enabled.  If at least one of these conditions is not
met, the KVM daemon will exit.

Signed-off-by: Jose A. Lopes <[email protected]>
---
 src/Ganeti/Daemon.hs |  1 +
 src/Ganeti/Kvmd.hs   | 28 +++++++++++++++++++++++++++-
 2 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/src/Ganeti/Daemon.hs b/src/Ganeti/Daemon.hs
index 7bd88f0..a94c88a 100644
--- a/src/Ganeti/Daemon.hs
+++ b/src/Ganeti/Daemon.hs
@@ -41,6 +41,7 @@ module Ganeti.Daemon
   , parseArgs
   , parseAddress
   , cleanupSocket
+  , getFQDN
   , describeError
   , genericMain
   ) where
diff --git a/src/Ganeti/Kvmd.hs b/src/Ganeti/Kvmd.hs
index f8c9d3f..5a3213d 100644
--- a/src/Ganeti/Kvmd.hs
+++ b/src/Ganeti/Kvmd.hs
@@ -66,9 +66,13 @@ import System.IO.Error (isEOFError)
 import System.INotify
 
 import qualified AutoConf
+import qualified Ganeti.BasicTypes as BasicTypes
 import qualified Ganeti.Constants as Constants
+import qualified Ganeti.Daemon as Daemon (getFQDN)
 import qualified Ganeti.Logging as Logging
 import qualified Ganeti.UDSServer as UDSServer
+import qualified Ganeti.Ssconf as Ssconf
+import qualified Ganeti.Types as Types
 
 type Lock = MVar ()
 type Monitors = MVar (Set FilePath)
@@ -305,4 +309,26 @@ startWith dir =
      withINotify (rewatchDir lock dir)
 
 start :: IO ()
-start = startWith monitorDir
+start =
+  do fqdn <- Daemon.getFQDN
+     hypervisors <- Ssconf.getHypervisorList Nothing
+     userShutdown <- Ssconf.getEnabledUserShutdown Nothing
+     vmCapable <- Ssconf.getNodesVmCapable Nothing
+     BasicTypes.genericResult
+       Logging.logInfo
+       (const $ startWith monitorDir) $ do
+         isKvm =<< hypervisors
+         isUserShutdown =<< userShutdown
+         isVmCapable fqdn =<< vmCapable
+  where
+    isKvm hs
+      | Types.Kvm `elem` hs = return ()
+      | otherwise = fail "KVM not enabled, exiting"
+
+    isUserShutdown True = return ()
+    isUserShutdown _ = fail "User shutdown not enabled, exiting"
+
+    isVmCapable node vmCapables =
+      case lookup node vmCapables of
+        Just True -> return ()
+        _ -> fail $ "Node " ++ show node ++ " is not VM capable, exiting"
-- 
2.0.0.526.g5318336

Reply via email to