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
This commit is contained in:
parent
3c2305c3a5
commit
c45506efd1
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=251660
@ -33,6 +33,7 @@ always_force_depends="NO" # Set to check that indicated dependencies are
|
||||
# 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).
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user