]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.sbin/nfsd/nfsv4.4
nfsv4(4): Reflow lines to 80 character limit
[FreeBSD/FreeBSD.git] / usr.sbin / nfsd / nfsv4.4
1 .\" Copyright (c) 2009 Rick Macklem, University of Guelph
2 .\" All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\"
13 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 .\" SUCH DAMAGE.
24 .\"
25 .Dd January 8, 2024
26 .Dt NFSV4 4
27 .Os
28 .Sh NAME
29 .Nm NFSv4
30 .Nd NFS Version 4 Protocol
31 .Sh DESCRIPTION
32 The NFS client and server provides support for the
33 .Tn NFSv4
34 specification; see
35 .%T "Network File System (NFS) Version 4 Protocol RFC 7530" ,
36 .%T "Network File System (NFS) Version 4 Minor Version 1 Protocol RFC 5661" ,
37 .%T "Network File System (NFS) Version 4 Minor Version 2 Protocol RFC 7862" ,
38 .%T "File System Extended Attributes in NFSv4 RFC 8276" and
39 .%T "Parallel NFS (pNFS) Flexible File Layout RFC 8435" .
40 The protocol is somewhat similar to NFS Version 3, but differs in significant
41 ways.
42 It uses a single compound RPC that concatenates operations to-gether.
43 Each of these operations are similar to the RPCs of NFS Version 3.
44 The operations in the compound are performed in order, until one of
45 them fails (returns an error) and then the RPC terminates at that point.
46 .Pp
47 It has
48 integrated locking support, which implies that the server is no longer
49 stateless.
50 As such, the
51 .Nm
52 server remains in recovery mode for a grace period (always greater than the
53 lease duration the server uses) after a reboot.
54 During this grace period, clients may recover state but not perform other
55 open/lock state changing operations.
56 To provide for correct recovery semantics, a small file described by
57 .Xr stablerestart 5
58 is used by the server during the recovery phase.
59 If this file is missing or empty, there is a backup copy maintained by
60 .Xr nfsd 8
61 that will be used.
62 If either file is missing, they will be created by the
63 .Xr nfsd 8 .
64 If both the file and the backup copy are empty,
65 it will result in the server starting without providing a grace period
66 for recovery.
67 Note that recovery only occurs when the server
68 machine is rebooted, not when the
69 .Xr nfsd 8
70 are just restarted.
71 .Pp
72 It provides several optional features not present in NFS Version 3:
73 .sp
74 .Bd -literal -offset indent -compact
75 - NFS Version 4 ACLs
76 - Referrals, which redirect subtrees to other servers
77   (not yet implemented)
78 - Delegations, which allow a client to operate on a file locally
79 - pNFS, where I/O operations are separated from Metadata operations
80 And for NFSv4.2 only
81 - User namespace extended attributes
82 - lseek(SEEK_DATA/SEEK_HOLE)
83 - File copying done locally on the server for copy_file_range(2)
84 - posix_fallocate(2)
85 - posix_fadvise(POSIX_FADV_WILLNEED/POSIX_FADV_DONTNEED)
86 .Ed
87 .Pp
88 The
89 .Nm
90 protocol does not use a separate mount protocol and assumes that the
91 server provides a single file system tree structure, rooted at the point
92 in the local file system tree specified by one or more
93 .sp 1
94 .Bd -literal -offset indent -compact
95 V4: <rootdir> [-sec=secflavors] [host(s) or net]
96 .Ed
97 .sp 1
98 line(s) in the
99 .Xr exports 5
100 file.
101 (See
102 .Xr exports 5
103 for details.)
104 The
105 .Xr nfsd 8
106 allows a limited subset of operations to be performed on non-exported subtrees
107 of the local file system, so that traversal of the tree to the exported
108 subtrees is possible.
109 As such, the ``<rootdir>'' can be in a non-exported file system.
110 The exception is ZFS, which checks exports and, as such, all ZFS file systems
111 below the ``<rootdir>'' must be exported.
112 However,
113 the entire tree that is rooted at that point must be in local file systems
114 that are of types that can be NFS exported.
115 Since the
116 .Nm
117 file system is rooted at ``<rootdir>'', setting this to anything other
118 than ``/'' will result in clients being required to use different mount
119 paths for
120 .Nm
121 than for NFS Version 2 or 3.
122 Unlike NFS Version 2 and 3, Version 4 allows a client mount to span across
123 multiple server file systems, although not all clients are capable of doing
124 this.
125 .Pp
126 .Nm
127 uses strings for users and groups instead of numbers.
128 On the wire, these strings can either have the numbers in the string or
129 take the form:
130 .sp
131 .Bd -literal -offset indent -compact
132 <user>@<dns.domain>
133 .Ed
134 .sp
135 where ``<dns.domain>'' is not the same as the DNS domain used
136 for host name lookups, but is usually set to the same string.
137 Most systems set this ``<dns.domain>''
138 to the domain name part of the machine's
139 .Xr hostname 1
140 by default.
141 However, this can normally be overridden by a command line
142 option or configuration file for the daemon used to do the name<->number
143 mapping.
144 Under
145 .Fx ,
146 the mapping daemon is called
147 .Xr nfsuserd 8
148 and has a command line option that overrides the domain component of the
149 machine's hostname.
150 For use of this form of string on
151 .Nm ,
152 either client or server, this daemon must be running.
153 .Pp
154 The form where the numbers are in the strings can only be used for AUTH_SYS.
155 To configure your systems this way, the
156 .Xr nfsuserd 8
157 daemon does not need to be running on the server, but the following sysctls
158 need to be set to 1 on the server.
159 .sp
160 .Bd -literal -offset indent -compact
161 vfs.nfs.enable_uidtostring
162 vfs.nfsd.enable_stringtouid
163 .Ed
164 .sp
165 On the client, the sysctl
166 .sp
167 .Bd -literal -offset indent -compact
168 vfs.nfs.enable_uidtostring
169 .Ed
170 .sp
171 must be set to 1 and the
172 .Xr nfsuserd 8
173 daemon does not need to be running.
174 .Pp
175 If these strings are not configured correctly, ``ls -l'' will typically
176 report a lot of ``nobody'' and ``nogroup'' ownerships.
177 .Pp
178 Although uid/gid numbers are no longer used in the
179 .Nm
180 protocol except optionally in the above strings, they will still be in the RPC
181 authentication fields when using AUTH_SYS (sec=sys), which is the default.
182 As such, in this case both the user/group name and number spaces must
183 be consistent between the client and server.
184 .Pp
185 However, if you run
186 .Nm
187 with RPCSEC_GSS (sec=krb5, krb5i, krb5p), only names and KerberosV tickets
188 will go on the wire.
189 .Sh SERVER SETUP
190 To set up the NFS server that supports
191 .Nm ,
192 you will need to set the variables in
193 .Xr rc.conf 5
194 as follows:
195 .sp
196 .Bd -literal -offset indent -compact
197 nfs_server_enable="YES"
198 nfsv4_server_enable="YES"
199 .Ed
200 .sp
201 plus
202 .sp
203 .Bd -literal -offset indent -compact
204 nfsuserd_enable="YES"
205 .Ed
206 .sp
207 if the server is using the ``<user>@<domain>'' form of user/group strings or
208 is using the ``-manage-gids'' option for
209 .Xr nfsuserd 8 .
210 .Pp
211 In addition, you can set:
212 .sp
213 .Bd -literal -offset indent -compact
214 nfsv4_server_only="YES"
215 .Ed
216 .sp
217 to disable support for NFSv2 and NFSv3.
218 .Pp
219 You will also need to add at least one ``V4:'' line to the
220 .Xr exports 5
221 file for
222 .Nm
223 to work.
224 .Pp
225 If the file systems you are exporting are only being accessed via
226 .Nm
227 there are a couple of
228 .Xr sysctl 8
229 variables that you can change, which might improve performance.
230 .Bl -tag -width Ds
231 .It Cm vfs.nfsd.issue_delegations
232 when set non-zero, allows the server to issue Open Delegations to
233 clients.
234 These delegations permit the client to manipulate the file
235 locally on the client.
236 Unfortunately, at this time, client use of
237 delegations is limited, so performance gains may not be observed.
238 This can only be enabled when the file systems being exported to
239 .Nm
240 clients are not being accessed locally on the server and, if being
241 accessed via NFS Version 2 or 3 clients, these clients cannot be
242 using the NLM.
243 .It Cm vfs.nfsd.enable_locallocks
244 can be set to 0 to disable acquisition of local byte range locks.
245 Disabling local locking can only be done if neither local accesses
246 to the exported file systems nor the NLM is operating on them.
247 .El
248 .sp
249 Note that Samba server access would be considered ``local access'' for the above
250 discussion.
251 .Pp
252 To build a kernel with the NFS server that supports
253 .Nm
254 linked into it, the
255 .sp
256 .Bd -literal -offset indent -compact
257 options NFSD
258 .Ed
259 .sp
260 must be specified in the kernel's
261 .Xr config 5
262 file.
263 .Sh CLIENT MOUNTS
264 To do an
265 .Nm
266 mount, specify the ``nfsv4'' option on the
267 .Xr mount_nfs 8
268 command line.
269 This will force use of the client that supports
270 .Nm
271 plus set ``tcp'' and
272 .Nm .
273 .Pp
274 The
275 .Xr nfsuserd 8
276 must be running if name<->uid/gid mapping is being used, as above.
277 Also, since an
278 .Nm
279 mount uses the host uuid to identify the client uniquely to the server,
280 you cannot safely do an
281 .Nm
282 mount when
283 .sp
284 .Bd -literal -offset indent -compact
285 hostid_enable="NO"
286 .Ed
287 .sp
288 is set in
289 .Xr rc.conf 5 .
290 .sp
291 If the
292 .Nm
293 server that is being mounted on supports delegations, you can start the
294 .Xr nfscbd 8
295 daemon to handle client side callbacks.
296 This will occur if
297 .sp
298 .Bd -literal -offset indent -compact
299 nfsuserd_enable="YES"   <-- If name<->uid/gid mapping is being used.
300 nfscbd_enable="YES"
301 .Ed
302 .sp
303 are set in
304 .Xr rc.conf 5 .
305 .sp
306 Without a functioning callback path, a server will never issue Delegations
307 to a client.
308 .sp
309 For NFSv4.0, by default, the callback address will be set to the IP address
310 acquired via
311 .Fn rtalloc
312 in the kernel and port# 7745.
313 To override the default port#, a command line option for
314 .Xr nfscbd 8
315 can be used.
316 .sp
317 To get callbacks to work when behind a NAT gateway, a port for the callback
318 service will need to be set up on the NAT gateway and then the address
319 of the NAT gateway (host IP plus port#) will need to be set by assigning the
320 .Xr sysctl 8
321 variable vfs.nfs.callback_addr to a string of the form:
322 .sp
323 N.N.N.N.N.N
324 .sp
325 where the first 4 Ns are the host IP address and the last two are the
326 port# in network byte order (all decimal #s in the range 0-255).
327 .Pp
328 For NFSv4.1 and NFSv4.2, the callback path (called a backchannel) uses the
329 same TCP connection as the mount, so none of the above applies and should
330 work through gateways without any issues.
331 .Pp
332 To build a kernel with the client that supports
333 .Nm
334 linked into it, the option
335 .sp
336 .Bd -literal -offset indent -compact
337 options NFSCL
338 .Ed
339 .sp
340 must be specified in the kernel's
341 .Xr config 5
342 file.
343 .Pp
344 Options can be specified for the
345 .Xr nfsuserd 8
346 and
347 .Xr nfscbd 8
348 daemons at boot time via the ``nfsuserd_flags'' and ``nfscbd_flags''
349 .Xr rc.conf 5
350 variables.
351 .Pp
352 NFSv4 mount(s) against exported volume(s) on the same host are not recommended,
353 since this can result in a hung NFS server.
354 It occurs when an nfsd thread tries to do an NFSv4
355 .Fn VOP_RECLAIM
356 / Close RPC as part of acquiring a new vnode.
357 If all other nfsd threads are blocked waiting for lock(s) held by this nfsd
358 thread, then there is no nfsd thread to service the Close RPC.
359 .Sh FILES
360 .Bl -tag -width /var/db/nfs-stablerestart.bak -compact
361 .It Pa /var/db/nfs-stablerestart
362 NFS V4 stable restart file
363 .It Pa /var/db/nfs-stablerestart.bak
364 backup copy of the file
365 .El
366 .Sh SEE ALSO
367 .Xr stablerestart 5 ,
368 .Xr mountd 8 ,
369 .Xr nfscbd 8 ,
370 .Xr nfsd 8 ,
371 .Xr nfsdumpstate 8 ,
372 .Xr nfsrevoke 8 ,
373 .Xr nfsuserd 8
374 .Sh BUGS
375 At this time, there is no recall of delegations for local file system
376 operations.
377 As such, delegations should only be enabled for file systems
378 that are being used solely as NFS export volumes and are not being accessed
379 via local system calls nor services such as Samba.