From owner-svn-src-head@FreeBSD.ORG Wed Jun 12 16:44:19 2013 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 28F9A2ED; Wed, 12 Jun 2013 16:44:19 +0000 (UTC) (envelope-from crees@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id 017E51CE2; Wed, 12 Jun 2013 16:44:19 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r5CGiImt068246; Wed, 12 Jun 2013 16:44:18 GMT (envelope-from crees@svn.freebsd.org) Received: (from crees@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r5CGiIEh068242; Wed, 12 Jun 2013 16:44:18 GMT (envelope-from crees@svn.freebsd.org) Message-Id: <201306121644.r5CGiIEh068242@svn.freebsd.org> From: Chris Rees Date: Wed, 12 Jun 2013 16:44:18 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r251660 - in head/etc: defaults rc.d X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 12 Jun 2013 16:44:19 -0000 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