zfs revision 177390
1#!/bin/sh
2#
3# $FreeBSD: head/etc/rc.d/zfs 177390 2008-03-19 14:44:55Z pjd $
4#
5
6# PROVIDE: zfs
7# REQUIRE: mountcritlocal
8# BEFORE:  mountcritremote
9
10. /etc/rc.subr
11
12name="zfs"
13rcvar="zfs_enable"
14start_cmd="zfs_start"
15stop_cmd="zfs_stop"
16required_modules="zfs"
17
18zfs_start_jail()
19{
20	if [ `$SYSCTL_N security.jail.mount_allowed` -eq 1 ]; then
21		zfs mount -a
22	fi
23}
24
25zfs_start_main()
26{
27	zfs volinit
28	zfs mount -a
29	zfs share -a
30	if [ ! -r /etc/zfs/exports ]; then
31		touch /etc/zfs/exports
32	fi
33	# Enable swap on ZVOLs with property org.freebsd:swap=on.
34	zfs list -H -o org.freebsd:swap,name -t volume | \
35	while read state name; do
36		case "${state}" in
37		[oO][nN])
38			swapon /dev/zvol/${name}
39			;;
40		esac
41	done
42}
43
44zfs_start()
45{
46	if [ `$SYSCTL_N security.jail.jailed` -eq 1 ]; then
47		zfs_start_jail
48	else
49		zfs_start_main
50	fi
51}
52
53zfs_stop_jail()
54{
55	if [ `$SYSCTL_N security.jail.mount_allowed` -eq 1 ]; then
56		zfs unmount -a
57	fi
58}
59
60zfs_stop_main()
61{
62	# Disable swap on ZVOLs with property org.freebsd:swap=on.
63	zfs list -H -o org.freebsd:swap,name -t volume | \
64	while read state name; do
65		case "${state}" in
66		[oO][nN])
67			swapoff /dev/zvol/${name}
68			;;
69		esac
70	done
71	zfs unshare -a
72	zfs unmount -a
73	zfs volfini
74}
75
76zfs_stop()
77{
78	if [ `$SYSCTL_N security.jail.jailed` -eq 1 ]; then
79		zfs_stop_jail
80	else
81		zfs_stop_main
82	fi
83}
84
85load_rc_config $name
86run_rc_command "$1"
87