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