Module Name: src Committed By: martin Date: Fri Oct 19 14:11:12 UTC 2018
Modified Files: src/etc/defaults: rc.conf src/etc/rc.d: swap1 src/share/man/man5: rc.conf.5 Log Message: Apply patch from Ian D. Leroux in PR bin/51019: when unmounting tmpfs file systems at shutdown time, avoid unmounting a tmpfs created by init on /dev - behaviour overridable from rc.conf. By default all tmpfs that have device nodes are not mounted. To generate a diff of this commit: cvs rdiff -u -r1.145 -r1.146 src/etc/defaults/rc.conf cvs rdiff -u -r1.12 -r1.13 src/etc/rc.d/swap1 cvs rdiff -u -r1.177 -r1.178 src/share/man/man5/rc.conf.5 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/etc/defaults/rc.conf diff -u src/etc/defaults/rc.conf:1.145 src/etc/defaults/rc.conf:1.146 --- src/etc/defaults/rc.conf:1.145 Sun Sep 23 07:24:19 2018 +++ src/etc/defaults/rc.conf Fri Oct 19 14:11:12 2018 @@ -1,4 +1,4 @@ -# $NetBSD: rc.conf,v 1.145 2018/09/23 07:24:19 maxv Exp $ +# $NetBSD: rc.conf,v 1.146 2018/10/19 14:11:12 martin Exp $ # # /etc/defaults/rc.conf -- # default configuration of /etc/rc.conf @@ -99,6 +99,12 @@ no_swap=NO # Set to YES if you have pur # 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. # Index: src/etc/rc.d/swap1 diff -u src/etc/rc.d/swap1:1.12 src/etc/rc.d/swap1:1.13 --- src/etc/rc.d/swap1:1.12 Mon Apr 20 18:01:46 2015 +++ src/etc/rc.d/swap1 Fri Oct 19 14:11:12 2018 @@ -1,6 +1,6 @@ #!/bin/sh # -# $NetBSD: swap1,v 1.12 2015/04/20 18:01:46 prlw1 Exp $ +# $NetBSD: swap1,v 1.13 2018/10/19 14:11:12 martin Exp $ # # PROVIDE: localswap @@ -13,6 +13,40 @@ name="swap1" 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_start() 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 Index: src/share/man/man5/rc.conf.5 diff -u src/share/man/man5/rc.conf.5:1.177 src/share/man/man5/rc.conf.5:1.178 --- src/share/man/man5/rc.conf.5:1.177 Mon Oct 1 11:16:04 2018 +++ src/share/man/man5/rc.conf.5 Fri Oct 19 14:11:12 2018 @@ -1,4 +1,4 @@ -.\" $NetBSD: rc.conf.5,v 1.177 2018/10/01 11:16:04 uwe Exp $ +.\" $NetBSD: rc.conf.5,v 1.178 2018/10/19 14:11:12 martin Exp $ .\" .\" Copyright (c) 1996 Matthew R. Green .\" All rights reserved. @@ -55,7 +55,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd September 23, 2018 +.Dd October 19, 2018 .Dt RC.CONF 5 .Os .Sh NAME @@ -353,6 +353,25 @@ Defaults to false. 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. .It Sy var_shm_symlink A path. If set, names a path that