]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - libexec/rc/rc.d/zfsbe
amd64: use register macros for gdb_cpu_getreg()
[FreeBSD/FreeBSD.git] / libexec / rc / rc.d / zfsbe
1 #!/bin/sh
2 #
3 # $FreeBSD$
4 #
5
6 # PROVIDE: zfsbe
7 # REQUIRE: mountcritlocal
8
9 # Handle boot environment subordinate filesystems
10 # that may have canmount property set to noauto.
11 # For these filesystems mountpoint relative to /
12 # must be the same as their dataset name relative
13 # to BE root dataset.
14
15 . /etc/rc.subr
16
17 name="zfsbe"
18 rcvar="zfs_enable"
19 start_cmd="be_start"
20 stop_cmd="be_stop"
21 required_modules="zfs"
22
23 mount_subordinate()
24 {
25         local _be
26
27         _be=$1
28         zfs list -rH -o mountpoint,name,canmount,mounted -s mountpoint -t filesystem $_be | \
29         while read _mp _name _canmount _mounted ; do
30                 # skip filesystems that must not be mounted
31                 [ "$_canmount" = "off" ] && continue
32                 # skip filesystems that are already mounted
33                 [ "$_mounted" = "yes" ] && continue
34                 case "$_mp" in
35                 "none" | "legacy" | "/" | "/$_be")
36                         # do nothing for filesystems with unset or legacy mountpoint
37                         # or those that would be mounted over /
38                         ;;
39                 "/$_be/"*)
40                         # filesystems with mountpoint relative to BE
41                         mount -t zfs $_name ${_mp#/$_be}
42                         ;;
43                 *)
44                         # filesystems with mountpoint elsewhere
45                         zfs mount $_name
46                         ;;
47                 esac
48         done
49 }
50
51 activate_bootonce()
52 {
53         local _dev
54         local _bootonce
55         local _be
56
57         _dev=$1
58         _be=${_dev##*/}
59
60         _bootonce="`kenv -q zfs-bootonce`"
61         if [ "$_bootonce" = "zfs:${_dev}:" ] ; then
62                 bectl activate $_be
63         fi
64 }
65
66 be_start()
67 {
68         if [ `$SYSCTL_N security.jail.jailed` -eq 1 ]; then
69                 :
70         else
71                 mount -p | while read _dev _mp _type _rest; do
72                         [ $_mp  = "/" ] || continue
73                         if [ $_type = "zfs" ] ; then
74                                 mount_subordinate $_dev
75                                 if checkyesno zfs_bootonce_activate; then
76                                         activate_bootonce $_dev
77                                 fi
78                         fi
79                         break
80                 done
81         fi
82 }
83
84 be_stop()
85 {
86 }
87
88 load_rc_config $name
89 run_rc_command "$1"