summaryrefslogtreecommitdiffstats
path: root/etc/rc.d
diff options
context:
space:
mode:
authorcrees <crees@FreeBSD.org>2013-06-12 16:44:17 +0000
committercrees <crees@FreeBSD.org>2013-06-12 16:44:17 +0000
commit5219f99e6a6b2825f119d9181112455eacffa110 (patch)
tree0e7fe8efeedf506398362edf9939ba4877755a22 /etc/rc.d
parentefd62e8968170842115fd3214dacd8c6daca3e19 (diff)
downloadFreeBSD-src-5219f99e6a6b2825f119d9181112455eacffa110.zip
FreeBSD-src-5219f99e6a6b2825f119d9181112455eacffa110.tar.gz
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
Diffstat (limited to 'etc/rc.d')
-rwxr-xr-xetc/rc.d/addswap43
1 files changed, 39 insertions, 4 deletions
diff --git a/etc/rc.d/addswap b/etc/rc.d/addswap
index 8dec456..a6ff187 100755
--- a/etc/rc.d/addswap
+++ b/etc/rc.d/addswap
@@ -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
OpenPOWER on IntegriCloud