[arch-projects] [PATCH 2/2] swapoff: umount swap-backed fs before switching off swap
Dave Reisner
d at falconindy.com
Sat Oct 29 21:54:09 EDT 2011
On Sun, Oct 30, 2011 at 12:00:09AM +0200, Tom Gundersen wrote:
> Factor out umounting. Explicitly skip umounting API directories, rather
> than matching on fs type. This allows us to e.g. unmount all tmpfs but leaving
> /run and /dev/shm alone.
>
> Signed-off-by: Tom Gundersen <teg at jklm.no>
> ---
> functions | 6 ++++++
> rc.shutdown | 9 ++++-----
> 2 files changed, 10 insertions(+), 5 deletions(-)
>
> diff --git a/functions b/functions
> index 05d8f56..47146ea 100644
> --- a/functions
> +++ b/functions
> @@ -460,6 +460,12 @@ mount_all() {
> mount -a -t "nosysfs,no${NETFS//,/,no}" -O no_netdev
> }
>
> +umount_all() {
> + # $1: restrict to fstype
> + umount `mount | grep -e "^\(${1}\)" | awk '{ print $3 }' | grep -v -e "^/\(proc\|sys\|dev\|run\)" | sort -r` \
> + -O no_netdev -r
> +}
> +
> remove_leftover() {
> stat_busy "Removing Leftover Files"
> # handle this separately until we declare the non-symlinks obsoleted
> diff --git a/rc.shutdown b/rc.shutdown
> index 1946068..c042948 100755
> --- a/rc.shutdown
> +++ b/rc.shutdown
> @@ -50,16 +50,15 @@ kill_all
>
> run_hook shutdown_postkillall
>
> -# TODO: unmount any non-api partitions that are backed by swap, we don't want to
> -# move their contents into memory (waste of time and might caues OOM).
> +# unmount any non-api partitions that are backed by swap, we don't want to
> +# move their contents into memory (waste of time and might caues OOM).
> +status "Unmounting Swap-backed Filesystems" umount_all "tmpfs\|ramfs"
>
> # almost everything is dead now, so the swap should hopefully be relatively
> # empty, and quick to switch off
> status "Deactivating Swap" swapoff -a
>
> -# if we don't have devtmpfs support, /dev is mounted as tmpfs, so don't unmount it
> -status "Unmounting Filesystems" \
> - umount -a -r -t nodevtmpfs,notmpfs,nosysfs,noproc,nodevpts -O no_netdev
> +status "Unmounting Non-API Filesystems" umount_all
>
> run_hook shutdown_postumount
>
> --
> 1.7.7.1
>
So, as we discussed, I does not like your umount_all. It'll be really
nice when umount can do this on its own, but until then, something such
as the following should suffice:
umount_all() {
while read -r fstype options target; do
# match only targetted fstypes
if [[ $1 && $1 != "$fstype" ]]; then
continue
fi
# don't unmount API filesystems
if [[ $target = /@(proc|sys|run|dev)?(/*) ]]; then
continue
fi
# avoid networked devices
IFS=, read -ra opts <<< "$options"
if in_array _netdev "${opts[@]}"; then
continue
fi
mounts+=("$target")
done < <(findmnt -runRo FSTYPE,OPTIONS,TARGET / | tac)
}
d
More information about the arch-projects
mailing list