xref: /freebsd/libexec/rc/rc.d/zvol (revision 5ab1c5846ff41be24b1f6beb0317bf8258cd4409)
1#!/bin/sh
2#
3# $FreeBSD$
4#
5
6# PROVIDE: zvol
7# REQUIRE: hostid
8# BEFORE: dumpon
9# KEYWORD: nojail
10
11. /etc/rc.subr
12
13name="zvol"
14desc="Activate swap on ZVOLs"
15rcvar="zfs_enable"
16start_cmd="zvol_start"
17stop_cmd="zvol_stop"
18required_modules="zfs"
19
20zvol_start()
21{
22	# Enable swap on ZVOLs with property org.freebsd:swap=on.
23	zfs list -H -o org.freebsd:swap,name -t volume |
24	while read state name; do
25		case "${state}" in
26		([oO][nN])
27			swapon /dev/zvol/${name}
28			;;
29		esac
30	done
31}
32
33zvol_stop()
34{
35	# Disable swap on ZVOLs with property org.freebsd:swap=on.
36	zfs list -H -o org.freebsd:swap,name -t volume |
37	while read state name; do
38		case "${state}" in
39		([oO][nN])
40			swapoff /dev/zvol/${name}
41			;;
42		esac
43	done
44}
45
46load_rc_config $name
47run_rc_command "$1"
48