xref: /freebsd/libexec/rc/rc.d/zfs (revision 2f513db72b034fd5ef7f080b11be5c711c15186a)
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"
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_stop_jail()
45{
46	if [ `$SYSCTL_N security.jail.mount_allowed` -eq 1 ]; then
47		zfs unmount -a
48	fi
49}
50
51zfs_stop_main()
52{
53	zfs unshare -a
54	zfs unmount -a
55}
56
57zfs_stop()
58{
59	if [ `$SYSCTL_N security.jail.jailed` -eq 1 ]; then
60		zfs_stop_jail
61	else
62		zfs_stop_main
63	fi
64}
65
66load_rc_config $name
67run_rc_command "$1"
68