Commit bd1d7b91 authored by Klaus Aehlig's avatar Klaus Aehlig
Browse files

Add a function to list livelock files found on the system



While we mainly care to detect deaths of resource owners, we
also want to avoid leaking stale livelock files. Those can
occur is someone dies after returning all resources. Provide
a function listing them, so that they can be cleaned up.
Signed-off-by: default avatarKlaus Aehlig <aehlig@google.com>
Reviewed-by: default avatarNiklas Hambuechen <niklash@google.com>
parent f4bdea49
......@@ -35,13 +35,15 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
module Ganeti.Utils.Livelock
( Livelock
, mkLivelockFile
, listLiveLocks
, isDead
) where
import qualified Control.Exception as E
import Control.Monad
import Control.Monad.Error
import System.Directory (doesFileExist)
import System.Directory (doesFileExist, getDirectoryContents)
import System.FilePath.Posix ((</>))
import System.IO
import System.Posix.IO
import System.Posix.Types (Fd)
......@@ -49,7 +51,7 @@ import System.Time (ClockTime(..), getClockTime)
import Ganeti.BasicTypes
import Ganeti.Logging
import Ganeti.Path (livelockFile)
import Ganeti.Path (livelockFile, livelockDir)
import Ganeti.Utils (lockFile)
type Livelock = FilePath
......@@ -68,6 +70,16 @@ mkLivelockFile prefix = do
Ok fd -> return fd
return (fd, lockfile)
-- | List currently existing livelocks. Underapproximate if
-- some error occurs.
listLiveLocks :: IO [FilePath]
listLiveLocks =
fmap (genericResult (const [] :: IOError -> [FilePath]) id)
. runResultT . liftIO $ do
dir <- livelockDir
entries <- getDirectoryContents dir
filterM doesFileExist $ map (dir </>) entries
-- | Detect whether a the process identified by the given path
-- does not exist any more. This function never fails and only
-- returns True if it has positive knowledge that the process
......
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