Home | History | Annotate | Line # | Download | only in rc.d
swap1 revision 1.12.14.1
      1        1.1     lukem #!/bin/sh
      2        1.1     lukem #
      3  1.12.14.1  pgoyette # $NetBSD: swap1,v 1.12.14.1 2018/10/20 06:58:19 pgoyette Exp $
      4        1.1     lukem #
      5        1.1     lukem 
      6        1.1     lukem # PROVIDE: localswap
      7       1.10     joerg # REQUIRE: DISKS root
      8        1.7     lukem # KEYWORD: shutdown
      9        1.1     lukem 
     10        1.9   mycroft $_rc_subr_loaded . /etc/rc.subr
     11        1.1     lukem 
     12        1.1     lukem name="swap1"
     13        1.6   msaitoh start_cmd="swap1_start"
     14        1.7     lukem stop_cmd="swap1_stop"
     15        1.1     lukem 
     16  1.12.14.1  pgoyette dev_free_tmpfs()
     17  1.12.14.1  pgoyette {
     18  1.12.14.1  pgoyette 	# Generate a list of tmpfs filesystems that contain no device nodes,
     19  1.12.14.1  pgoyette 	# which can presumably be unmounted safetly at shutdown time.
     20  1.12.14.1  pgoyette 	# Filenames are quoted and the list contains no unquoted newlines,
     21  1.12.14.1  pgoyette 	# so that the output can be reparsed as a single argument list.
     22  1.12.14.1  pgoyette 	mount -t tmpfs | while read -r line
     23  1.12.14.1  pgoyette 	do
     24  1.12.14.1  pgoyette 		fs=${line#tmpfs on }
     25  1.12.14.1  pgoyette 		fs=${fs% type tmpfs*}
     26  1.12.14.1  pgoyette 		find -x "${fs}" \( -type b -or -type c \) -exit 1 &&
     27  1.12.14.1  pgoyette 			echo -n "'${fs}' "
     28  1.12.14.1  pgoyette 	done
     29  1.12.14.1  pgoyette }
     30  1.12.14.1  pgoyette 
     31  1.12.14.1  pgoyette umount_vm_consumers()
     32  1.12.14.1  pgoyette {
     33  1.12.14.1  pgoyette 	case ${swapoff_umount} in
     34  1.12.14.1  pgoyette 		auto)
     35  1.12.14.1  pgoyette 			swapoff_umount_fs="$(dev_free_tmpfs)"
     36  1.12.14.1  pgoyette 			;;
     37  1.12.14.1  pgoyette 		manual)
     38  1.12.14.1  pgoyette 			# swapoff_umount_fs set manually
     39  1.12.14.1  pgoyette 			;;
     40  1.12.14.1  pgoyette 	esac
     41  1.12.14.1  pgoyette 	# eval so that quotes within $swapoff_umount_fs are parsed properly
     42  1.12.14.1  pgoyette 	eval set -- "${swapoff_umount_fs}"
     43  1.12.14.1  pgoyette 	for fs in "$@"
     44  1.12.14.1  pgoyette 	do
     45  1.12.14.1  pgoyette 		echo "Forcibly unmounting ${fs}"
     46  1.12.14.1  pgoyette 		umount -ft tmpfs "${fs}"
     47  1.12.14.1  pgoyette 	done
     48  1.12.14.1  pgoyette }
     49  1.12.14.1  pgoyette 
     50        1.1     lukem #		Add all block-type swap devices; these might be necessary
     51        1.1     lukem #		during disk checks.
     52        1.1     lukem #
     53        1.6   msaitoh swap1_start()
     54        1.6   msaitoh {
     55       1.11       apb 	# Treat exit status 2 from swapctl(8) as successful; it means
     56       1.11       apb 	# "no error, but no suitable swap devices were configured".
     57       1.11       apb 	#
     58        1.6   msaitoh 	if ! checkyesno no_swap; then
     59       1.11       apb 		swapctl -A -t blk || [ $? = 2 ]
     60        1.6   msaitoh 	fi
     61        1.6   msaitoh }
     62        1.1     lukem 
     63        1.1     lukem #		Remove all block-type swap devices
     64        1.1     lukem #
     65        1.7     lukem swap1_stop()
     66        1.7     lukem {
     67        1.8     lukem 	if checkyesno swapoff || [ -n "$rc_force" ]; then
     68  1.12.14.1  pgoyette 		umount_vm_consumers
     69        1.7     lukem 		echo "Removing block-type swap devices"
     70       1.11       apb 		swapctl -U -t blk || [ $? = 2 ]
     71        1.7     lukem 	fi
     72        1.7     lukem }
     73        1.1     lukem 
     74        1.5     lukem load_rc_config swap
     75        1.1     lukem run_rc_command "$1"
     76