xref: /freebsd/libexec/rc/rc.d/zfs (revision 2e3507c25e42292b45a5482e116d278f5515d04d)
1#!/bin/sh
2#
3#
4
5# PROVIDE: zfs
6# REQUIRE: zfsbe
7# BEFORE: FILESYSTEMS var
8
9. /etc/rc.subr
10
11name="zfs"
12desc="Mount and share ZFS datasets"
13rcvar="zfs_enable"
14start_cmd="zfs_start"
15start_postcmd="zfs_poststart"
16stop_cmd="zfs_stop"
17required_modules="zfs"
18
19zfs_start_jail()
20{
21	if [ `$SYSCTL_N security.jail.mount_allowed` -eq 1 ]; then
22		zfs mount -a
23	fi
24}
25
26zfs_start_main()
27{
28	zfs mount -va
29	zfs share -a
30	if [ ! -r /etc/zfs/exports ]; then
31		touch /etc/zfs/exports
32	fi
33}
34
35zfs_start()
36{
37	if [ `$SYSCTL_N security.jail.jailed` -eq 1 ]; then
38		zfs_start_jail
39	else
40		zfs_start_main
41	fi
42}
43
44zfs_poststart()
45{
46	# Some of the keys to decrypt datasets are potentially stored on ZFS
47	# datasets that just got mounted. Let's try to load those keys and
48	# mount the datasets.
49	if checkyesno zfskeys_enable; then
50		/etc/rc.d/zfskeys start
51		zfs_start
52	fi
53}
54
55zfs_stop_jail()
56{
57	if [ `$SYSCTL_N security.jail.mount_allowed` -eq 1 ]; then
58		zfs unmount -a
59	fi
60}
61
62zfs_stop_main()
63{
64	zfs unshare -a
65	zfs unmount -a
66}
67
68zfs_stop()
69{
70	if [ `$SYSCTL_N security.jail.jailed` -eq 1 ]; then
71		zfs_stop_jail
72	else
73		zfs_stop_main
74	fi
75}
76
77load_rc_config $name
78run_rc_command "$1"
79