NetBSD Problem Report #51019
From www@NetBSD.org Mon Mar 28 18:17:20 2016
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
(Client CN "mail.netbsd.org", Issuer "Postmaster NetBSD.org" (verified OK))
by mollari.NetBSD.org (Postfix) with ESMTPS id 358FD7A2AB
for <gnats-bugs@gnats.NetBSD.org>; Mon, 28 Mar 2016 18:17:20 +0000 (UTC)
Message-Id: <20160328181719.1790E7A47B@mollari.NetBSD.org>
Date: Mon, 28 Mar 2016 18:17:19 +0000 (UTC)
From: idleroux@fastmail.fm
Reply-To: idleroux@fastmail.fm
To: gnats-bugs@NetBSD.org
Subject: [PATCH] /etc/rc.d/swap1 indiscriminately unmounts tmpfs filesystems at swapoff
X-Send-Pr-Version: www-1.0
>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: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Mon Mar 28 18:20:01 +0000 2016
>Closed-Date: Fri Oct 19 14:12:00 +0000 2018
>Last-Modified: Fri Oct 19 14:15:00 +0000 2018
>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:/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
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed
State-Changed-By: martin@NetBSD.org
State-Changed-When: Fri, 19 Oct 2018 14:12:00 +0000
State-Changed-Why:
Patch applied - thanks!
From: "Martin Husemann" <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/51019 CVS commit: src
Date: Fri, 19 Oct 2018 14:11:12 +0000
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.
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.43 2018/01/16 07:36:43 maya Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2017
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.