NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

bin/51019: [PATCH] /etc/rc.d/swap1 indiscriminately unmounts tmpfs filesystems at swapoff



>Number:         51019
>Category:       bin
>Synopsis:       [PATCH] /etc/rc.d/swap1 indiscriminately unmounts tmpfs filesystems at swapoff
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Mar 28 18:20:01 +0000 2016
>Originator:     Ian D. Leroux
>Release:        7.99
>Organization:
>Environment:
NetBSD scrameustache.unrouted.net 7.99.23 NetBSD 7.99.23 (GENERIC.201512021410Z) #0: Wed Dec  2 15:04:23 UTC 2015  builds%b45.netbsd.org@localhost:/home/builds/ab/HEAD/amd64/201512021410Z-obj/home/source/ab/HEAD/src/sys/arch/amd64/compile/GENERIC amd64

>Description:
When local block-type swap devices are removed by the function swap1_stop in /etc/rc.d/swap1, all tmpfs filesystems are forcibly unmounted.  This causes problems if critical filesystems (such as /dev/) are mounted on tmpfs (/dev/-on-tmpfs is common for systems with a ramdisk or read-only root, as well as being the fallback solution if /dev/console cannot be opened).
>How-To-Repeat:
Run shutdown(8) on any machine where /dev is mounted on tmpfs.
>Fix:
The following three patches implement and document the fix discussed and refined in the thread starting at
https://mail-index.netbsd.org/current-users/2016/03/13/msg029029.html


--- /etc/defaults/rc.conf.orig  2015-12-02 16:00:12.000000000 +0100
+++ /etc/defaults/rc.conf       2016-03-21 21:41:40.000000000 +0100
@@ -99,6 +99,12 @@
                        # partitions and don't want to be warned about it.
 swapoff=YES            # Remove block-type swap partitions upon shutdown
                        # This defaults to yes, so that raids shutdown cleanly
+swapoff_umount=auto    # Set to 'manual' to umount the tmpfs partitions listed
+                       # in swapoff_umount_fs before removing swap. Set to
+                       # 'auto' to umount all tmpfs paritions that contain
+                       # no device nodes.
+swapoff_umount_fs=     # space-separated list of tmpfs mount points to umount
+                       # before removing swap if swapoff_umount=manual
 
 # Concatenated disk driver.
 #


--- /etc/rc.d/swap1.orig        2016-03-13 18:54:23.000000000 +0100
+++ /etc/rc.d/swap1     2016-03-23 21:41:54.000000000 +0100
@@ -13,6 +13,40 @@
 start_cmd="swap1_start"
 stop_cmd="swap1_stop"
 
+dev_free_tmpfs()
+{
+       # Generate a list of tmpfs filesystems that contain no device nodes,
+       # which can presumably be unmounted safetly at shutdown time.
+       # Filenames are quoted and the list contains no unquoted newlines,
+       # so that the output can be reparsed as a single argument list.
+       mount -t tmpfs | while read -r line
+       do
+               fs=${line#tmpfs on }
+               fs=${fs% type tmpfs*}
+               find -x "${fs}" \( -type b -or -type c \) -exit 1 &&
+                       echo -n "'${fs}' "
+       done
+}
+
+umount_vm_consumers()
+{
+       case ${swapoff_umount} in
+               auto)
+                       swapoff_umount_fs="$(dev_free_tmpfs)"
+                       ;;
+               manual)
+                       # swapoff_umount_fs set manually
+                       ;;
+       esac
+       # eval so that quotes within $swapoff_umount_fs are parsed properly
+       eval set -- "${swapoff_umount_fs}"
+       for fs in "$@"
+       do
+               echo "Forcibly unmounting ${fs}"
+               umount -ft tmpfs "${fs}"
+       done
+}
+
 #              Add all block-type swap devices; these might be necessary
 #              during disk checks.
 #
@@ -31,8 +65,7 @@
 swap1_stop()
 {
        if checkyesno swapoff || [ -n "$rc_force" ]; then
-               echo "Forcibly unmounting tmpfs filesystems"
-               umount -aft tmpfs
+               umount_vm_consumers
                echo "Removing block-type swap devices"
                swapctl -U -t blk || [ $? = 2 ]
        fi

--- /usr/share/man/man5/rc.conf.5.orig  2015-12-02 15:59:11.000000000 +0100
+++ /usr/share/man/man5/rc.conf.5       2016-03-21 21:49:06.000000000 +0100
@@ -331,6 +331,25 @@
 Boolean value.
 Remove block-type swap devices at shutdown time.
 Useful if swapping onto RAIDframe devices.
+.It Sy swapoff_umount
+.Dq "auto"
+or
+.Dq "manual" .
+Before removing block-type swap devices, it is wise to unmount tmpfs filesystems to avoid having to swap their contents back into RAM.
+By default 
+.Dq ( "auto" )
+all tmpfs filesystems that contain no device nodes are unmounted.
+Set to 
+.Dq "manual"
+to explicitly specify which filesystems to unmount before removing swap.
+.It Sy swapoff_umount_fs
+A space-separated list of absolute paths to tmpfs mount points.
+If 
+.Sy swapoff_umount
+is set to
+.Dq "manual" ,
+these tmpfs filesystems will be forcibly unmounted before removing block-type
+swap devices.
 .El
 .Ss Block device subsystems
 .Bl -tag -width net_interfaces



Home | Main Index | Thread Index | Old Index