Bug 168544 - [patch] [rc]: addswap-mounted swapfiles cause panic on shutdown
Summary: [patch] [rc]: addswap-mounted swapfiles cause panic on shutdown
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: Unspecified
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-rc (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-06-01 23:50 UTC by Warren Block
Modified: 2014-07-14 17:59 UTC (History)
1 user (show)

See Also:


Attachments
file.diff (810 bytes, patch)
2012-06-01 23:50 UTC, Warren Block
no flags Details | Diff
addswap99.diff.txt (1.62 KB, TEXT/PLAIN; charset=US-ASCII)
2013-03-12 01:41 UTC, Warren Block
no flags Details
addswap99-2.diff.txt (612 bytes, TEXT/PLAIN; charset=US-ASCII)
2013-03-12 02:28 UTC, Warren Block
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Warren Block freebsd_committer freebsd_triage 2012-06-01 23:50:10 UTC
If swap is not empty on shutdown, swapfiles cause a panic after disks are synced.

Fix: Apply patch, which dismounts the swap file on shutdown.  Patch lightly tested on 9-stable, looks like it should also apply to head, stable/8, and stable/7.

Patch attached with submission follows:
How-To-Repeat: Without any other swap, add a swapfile in /etc/rc.conf:

swapfile="/usr/swap/swap"

Use system until swap is not empty, as shown by top(1).  Shut down system.
Comment 1 Warren Block freebsd_committer freebsd_triage 2012-06-09 07:08:26 UTC
Responsible Changed
From-To: freebsd-bugs->freebsd-rc

Over to maintainer(s).
Comment 2 Warren Block 2013-03-12 01:41:41 UTC
This updated patch adds a user-configurable md unit number and sets the 
default value to 99.  This moves the md swap drive out of the range 
normally used by users, so they won't be surprised that the new unit 
created by mdconfig starts with 1 rather than zero.

Thanks to crees for rewriting and improving parts.
Comment 3 Warren Block 2013-03-12 02:28:57 UTC
Diff for /etc/defaults/rc.conf to set the md unit number.
Comment 4 dfilter service freebsd_committer freebsd_triage 2013-06-12 17:44:26 UTC
Author: crees (doc,ports committer)
Date: Wed Jun 12 16:44:17 2013
New Revision: 251660
URL: http://svnweb.freebsd.org/changeset/base/251660

Log:
  Clean up swapfile memory disk on shutdown
  
  Make the md unit number configurable so that it can be predicted
  
  PR:		bin/168544
  Submitted by:	wblock (based on)
  Approved by:	kevlo

Modified:
  head/etc/defaults/rc.conf
  head/etc/rc.d/addswap

Modified: head/etc/defaults/rc.conf
==============================================================================
--- head/etc/defaults/rc.conf	Wed Jun 12 16:13:05 2013	(r251659)
+++ head/etc/defaults/rc.conf	Wed Jun 12 16:44:17 2013	(r251660)
@@ -33,6 +33,7 @@ always_force_depends="NO"	# Set to check
 				# running during boot (can increase boot time).
 
 swapfile="NO"		# Set to name of swapfile if aux swapfile desired.
+swapfile_mdunit="99"	# Swapfile md(4) unit number created by mdconfig(8).
 apm_enable="NO"		# Set to YES to enable APM BIOS functions (or NO).
 apmd_enable="NO"	# Run apmd to handle APM event from userland.
 apmd_flags=""		# Flags to apmd (if enabled).

Modified: head/etc/rc.d/addswap
==============================================================================
--- head/etc/rc.d/addswap	Wed Jun 12 16:13:05 2013	(r251659)
+++ head/etc/rc.d/addswap	Wed Jun 12 16:44:17 2013	(r251660)
@@ -8,13 +8,13 @@
 # PROVIDE: addswap
 # REQUIRE: FILESYSTEMS kld
 # BEFORE:  netif
-# KEYWORD: nojail
+# KEYWORD: nojail shutdown
 
 . /etc/rc.subr
 
 name="addswap"
 start_cmd="addswap_start"
-stop_cmd=":"
+stop_cmd="addswap_stop"
 
 addswap_start()
 {
@@ -23,8 +23,43 @@ addswap_start()
 		;;
 	*)
 		if [ -w "${swapfile}" ]; then
-			echo "Adding ${swapfile} as additional swap"
-			mdev=`mdconfig -a -t vnode -f ${swapfile}` && swapon /dev/${mdev}
+			check_startmsgs && echo "Adding ${swapfile} as additional swap"
+
+			if [ -n "${swapfile_mdunit}" ]; then
+				mdev="/dev/md${swapfile_mdunit#md}"
+				mdconfig -a -t vnode -f "${swapfile}" -u ${swapfile_mdunit}
+			else
+				mdev="/dev/`mdconfig -a -t vnode -f "${swapfile}"`"
+			fi
+
+			if [ $? -eq 0 ]; then
+				swapon ${mdev}
+			else
+				echo "error creating swapfile device"
+			fi
+		fi
+		;;
+	esac
+}
+
+addswap_stop()
+{
+	case ${swapfile} in
+	[Nn][Oo] | '')
+		;;
+	*)
+		if [ -n "${swapfile_mdunit}" ]; then
+			mdev="/dev/md${swapfile_mdunit#md}"
+		else
+			mdev="/dev/`mdconfig -lv | grep "${swapfile}" | cut -f1`"
+			swapfile_mdunit=${mdev#md}
+		fi
+		if [ -n "${swapfile_mdunit}" ]; then
+			swapctl -l | grep -q ${mdev}
+			if [ $? -eq 0 ]; then
+				echo "Dismounting swapfile ${swapfile}"
+				swapoff ${mdev} && mdconfig -d -u ${swapfile_mdunit}
+			fi
 		fi
 		;;
 	esac
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
Comment 5 Chris Rees freebsd_committer freebsd_triage 2013-06-12 17:44:55 UTC
State Changed
From-To: open->patched

Fixed in head
Comment 6 Chris Rees freebsd_committer freebsd_triage 2014-07-14 17:59:33 UTC
No need to MFC-- different implementation in stable/9 and below.