From 57525e0d0d1d300aa807f1c876945ee5e38a29df Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 6 Apr 2017 20:08:14 -0400 Subject: tweaks to db45x's patch Removed mountNow as a top-level property, as I don't think it makes sense for anything except for mounted to use it. db45x's patch turns out to have introduced a bug in mounted's use of "mountNow src". That made mountNow check if the device was a mount point, which it isn't. The fix would have been to use "mountNow mnt", but my inlining of mountnow just basically reverted the part of the patch that introduced the bug. swapOn does not involve the fstab so moved to the Mount module. (Also noticed that Mount.mounted is a kind of weird property, given that it fails the next time ran. It's only used internally by some chroot properties, so I left it as-is, but added a comment. It might make sense to make Mount.mounted check like mountNow does if the thing is already mounted.) --- src/Propellor/Property/Mount.hs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/Propellor/Property/Mount.hs') diff --git a/src/Propellor/Property/Mount.hs b/src/Propellor/Property/Mount.hs index 026509a9..5dcc5fe1 100644 --- a/src/Propellor/Property/Mount.hs +++ b/src/Propellor/Property/Mount.hs @@ -40,6 +40,9 @@ formatMountOpts (MountOpts []) = "defaults" formatMountOpts (MountOpts l) = intercalate "," l -- | Mounts a device, without listing it in . +-- +-- Note that this property will fail if the device is already mounted +-- at the MountPoint. mounted :: FsType -> Source -> MountPoint -> MountOpts -> Property UnixLike mounted fs src mnt opts = property (mnt ++ " mounted") $ toResult <$> liftIO (mount fs src mnt opts) @@ -52,6 +55,17 @@ bindMount src dest = tightenTargets $ `assume` MadeChange `describe` ("bind mounted " ++ src ++ " to " ++ dest) +-- | Enables swapping to a device, which must be formatted already as a swap +-- partition. +swapOn :: Source -> RevertableProperty Linux Linux +swapOn mnt = tightenTargets doswapon tightenTargets doswapoff + where + swaps = lines <$> readProcess "swapon" ["--show=NAME"] + doswapon = check (notElem mnt <$> swaps) $ + cmdProperty "swapon" [mnt] + doswapoff = check (elem mnt <$> swaps) $ + cmdProperty "swapoff" [mnt] + mount :: FsType -> Source -> MountPoint -> MountOpts -> IO Bool mount fs src mnt opts = boolSystem "mount" $ [ Param "-t", Param fs -- cgit v1.2.3