swap1 revision 1.14
11.1Slukem#!/bin/sh 21.1Slukem# 31.14Sandvar# $NetBSD: swap1,v 1.14 2022/04/16 18:15:20 andvar Exp $ 41.1Slukem# 51.1Slukem 61.1Slukem# PROVIDE: localswap 71.10Sjoerg# REQUIRE: DISKS root 81.7Slukem# KEYWORD: shutdown 91.1Slukem 101.9Smycroft$_rc_subr_loaded . /etc/rc.subr 111.1Slukem 121.1Slukemname="swap1" 131.6Smsaitohstart_cmd="swap1_start" 141.7Slukemstop_cmd="swap1_stop" 151.1Slukem 161.13Smartindev_free_tmpfs() 171.13Smartin{ 181.13Smartin # Generate a list of tmpfs filesystems that contain no device nodes, 191.14Sandvar # which can presumably be unmounted safely at shutdown time. 201.13Smartin # Filenames are quoted and the list contains no unquoted newlines, 211.13Smartin # so that the output can be reparsed as a single argument list. 221.13Smartin mount -t tmpfs | while read -r line 231.13Smartin do 241.13Smartin fs=${line#tmpfs on } 251.13Smartin fs=${fs% type tmpfs*} 261.13Smartin find -x "${fs}" \( -type b -or -type c \) -exit 1 && 271.13Smartin echo -n "'${fs}' " 281.13Smartin done 291.13Smartin} 301.13Smartin 311.13Smartinumount_vm_consumers() 321.13Smartin{ 331.13Smartin case ${swapoff_umount} in 341.13Smartin auto) 351.13Smartin swapoff_umount_fs="$(dev_free_tmpfs)" 361.13Smartin ;; 371.13Smartin manual) 381.13Smartin # swapoff_umount_fs set manually 391.13Smartin ;; 401.13Smartin esac 411.13Smartin # eval so that quotes within $swapoff_umount_fs are parsed properly 421.13Smartin eval set -- "${swapoff_umount_fs}" 431.13Smartin for fs in "$@" 441.13Smartin do 451.13Smartin echo "Forcibly unmounting ${fs}" 461.13Smartin umount -ft tmpfs "${fs}" 471.13Smartin done 481.13Smartin} 491.13Smartin 501.1Slukem# Add all block-type swap devices; these might be necessary 511.1Slukem# during disk checks. 521.1Slukem# 531.6Smsaitohswap1_start() 541.6Smsaitoh{ 551.11Sapb # Treat exit status 2 from swapctl(8) as successful; it means 561.11Sapb # "no error, but no suitable swap devices were configured". 571.11Sapb # 581.6Smsaitoh if ! checkyesno no_swap; then 591.11Sapb swapctl -A -t blk || [ $? = 2 ] 601.6Smsaitoh fi 611.6Smsaitoh} 621.1Slukem 631.1Slukem# Remove all block-type swap devices 641.1Slukem# 651.7Slukemswap1_stop() 661.7Slukem{ 671.8Slukem if checkyesno swapoff || [ -n "$rc_force" ]; then 681.13Smartin umount_vm_consumers 691.7Slukem echo "Removing block-type swap devices" 701.11Sapb swapctl -U -t blk || [ $? = 2 ] 711.7Slukem fi 721.7Slukem} 731.1Slukem 741.5Slukemload_rc_config swap 751.1Slukemrun_rc_command "$1" 76