Debian Codegraph @

scripts/nfs

raw
1 # NFS filesystem mounting -*- shell-script -*-
2 # shellcheck shell=sh
3
4 # FIXME This needs error checking
5
6 nfs_top()
7 {
8 if [ "${nfs_top_used}" != "yes" ]; then
9 [ "${quiet?}" != "y" ] && log_begin_msg "Running /scripts/nfs-top"
10 run_scripts /scripts/nfs-top
11 [ "$quiet" != "y" ] && log_end_msg
12 fi
13 nfs_top_used=yes
14 }
15
16 nfs_premount()
17 {
18 if [ "${nfs_premount_used}" != "yes" ]; then
19 [ "${quiet?}" != "y" ] && log_begin_msg "Running /scripts/nfs-premount"
20 run_scripts /scripts/nfs-premount
21 [ "$quiet" != "y" ] && log_end_msg
22 fi
23 nfs_premount_used=yes
24 }
25
26 nfs_bottom()
27 {
28 if [ "${nfs_premount_used}" = "yes" ] || [ "${nfs_top_used}" = "yes" ]; then
29 [ "${quiet?}" != "y" ] && log_begin_msg "Running /scripts/nfs-bottom"
30 run_scripts /scripts/nfs-bottom
31 [ "$quiet" != "y" ] && log_end_msg
32 fi
33 nfs_premount_used=no
34 nfs_top_used=no
35 }
36
37 # parse nfs bootargs and mount nfs
38 nfs_mount_root_impl()
39 {
40 configure_networking
41
42 # get nfs root from dhcp
43 if [ "${NFSROOT}" = "auto" ]; then
44 # check if server ip is part of dhcp root-path
45 if [ "${ROOTPATH#*:}" = "${ROOTPATH}" ]; then
46 NFSROOT=${ROOTSERVER}:${ROOTPATH}
47 else
48 NFSROOT=${ROOTPATH}
49 fi
50
51 # nfsroot=[<server-ip>:]<root-dir>[,<nfs-options>]
52 elif [ -n "${NFSROOT}" ]; then
53 # nfs options are an optional arg
54 if [ "${NFSROOT#*,}" != "${NFSROOT}" ]; then
55 NFSOPTS="-o ${NFSROOT#*,}"
56 fi
57 NFSROOT=${NFSROOT%%,*}
58 if [ "${NFSROOT#*:}" = "$NFSROOT" ]; then
59 NFSROOT=${ROOTSERVER}:${NFSROOT}
60 fi
61 fi
62
63 if [ -z "${NFSOPTS}" ]; then
64 NFSOPTS="-o retrans=10"
65 fi
66
67 nfs_premount
68
69 if [ "${readonly?}" = y ]; then
70 roflag="-o ro"
71 else
72 roflag="-o rw"
73 fi
74
75 # shellcheck disable=SC2086
76 nfsmount -o nolock ${roflag} ${NFSOPTS} "${NFSROOT}" "${rootmnt?}"
77 }
78
79 # NFS root mounting
80 nfs_mount_root()
81 {
82 nfs_top
83
84 # For DHCP
85 /sbin/modprobe af_packet
86
87 wait_for_udev 10
88
89 # Default delay is around 180s
90 delay=${ROOTDELAY:-180}
91
92 # loop until nfsmount succeeds
93 nfs_mount_root_impl
94 ret=$?
95 nfs_retry_count=0
96 while [ ${nfs_retry_count} -lt "${delay}" ] \
97 && [ $ret -ne 0 ] ; do
98 [ "$quiet" != "y" ] && log_begin_msg "Retrying nfs mount"
99 sleep 1
100 nfs_mount_root_impl
101 ret=$?
102 nfs_retry_count=$(( nfs_retry_count + 1 ))
103 [ "$quiet" != "y" ] && log_end_msg
104 done
105 }
106
107 nfs_mount_fs_impl()
108 {
109 configure_networking
110
111 if [ -z "${NFSOPTS}" ]; then
112 NFSOPTS="-o retrans=10"
113 fi
114
115 nfs_premount
116
117 if [ "${readonly}" = y ]; then
118 roflag="-o ro"
119 else
120 roflag="-o rw"
121 fi
122
123 read_fstab_entry "$1"
124
125 # shellcheck disable=SC2086
126 nfsmount ${roflag} ${NFSOPTS} -o "${MNT_OPTS}" "$MNT_FSNAME" "${rootmnt}${MNT_DIR}"
127 }
128
129 nfs_mount_fs()
130 {
131 nfs_top
132
133 # For DHCP
134 /sbin/modprobe af_packet
135
136 wait_for_udev 10
137
138 # Default delay is around 180s
139 delay=${ROOTDELAY:-180}
140
141 # Don't loop here; we can't sanely check if it worked like for
142 # the rootfs or /etc.
143 nfs_mount_fs_impl "$1"
144 }
145
146 mountroot()
147 {
148 nfs_mount_root
149 }
150
151 mount_top()
152 {
153 # Note, also called directly in case it's overridden.
154 nfs_top
155 }
156
157 mount_premount()
158 {
159 # Note, also called directly in case it's overridden.
160 nfs_premount
161 }
162
163 mount_bottom()
164 {
165 # Note, also called directly in case it's overridden.
166 nfs_bottom
167 }