xref: /freebsd/usr.sbin/nfsd/nfsv4.4 (revision bdcbfde31e8e9b343f113a1956384bdf30d1ed62)
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 December 20, 2019
26.Dt NFSV4 4
27.Os
28.Sh NAME
29.Nm NFSv4
30.Nd NFS Version 4 Protocol
31.Sh DESCRIPTION
32The NFS client and server provides support for the
33.Tn NFSv4
34specification; 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" .
40The protocol is somewhat similar to NFS Version 3, but differs in significant
41ways.
42It uses a single compound RPC that concatenates operations to-gether.
43Each of these operations are similar to the RPCs of NFS Version 3.
44The operations in the compound are performed in order, until one of
45them fails (returns an error) and then the RPC terminates at that point.
46.Pp
47It has
48integrated locking support, which implies that the server is no longer
49stateless.
50As such, the
51.Nm
52server remains in recovery mode for a grace period (always greater than the
53lease duration the server uses) after a reboot.
54During this grace period, clients may recover state but not perform other
55open/lock state changing operations.
56To provide for correct recovery semantics, a small file described by
57.Xr stablerestart 5
58is used by the server during the recovery phase.
59If this file is missing or empty, there is a backup copy maintained by
60.Xr nfsd 8
61that will be used.
62If either file is missing, they will be created by the
63.Xr nfsd 8 .
64If both the file and the backup copy are empty,
65it will result in the server starting without providing a grace period
66for recovery.
67Note that recovery only occurs when the server
68machine is rebooted, not when the
69.Xr nfsd 8
70are just restarted.
71.Pp
72It 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
80And 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
88The
89.Nm
90protocol does not use a separate mount protocol and assumes that the
91server provides a single file system tree structure, rooted at the point
92in the local file system tree specified by one or more
93.sp 1
94.Bd -literal -offset indent -compact
95V4: <rootdir> [-sec=secflavors] [host(s) or net]
96.Ed
97.sp 1
98line(s) in the
99.Xr exports 5
100file.
101(See
102.Xr exports 5
103for details.)
104The
105.Xr nfsd 8
106allows a limited subset of operations to be performed on non-exported subtrees
107of the local file system, so that traversal of the tree to the exported
108subtrees is possible.
109As such, the ``<rootdir>'' can be in a non-exported file system.
110The exception is ZFS, which checks exports and, as such, all ZFS file systems
111below the ``<rootdir>'' must be exported.
112However,
113the entire tree that is rooted at that point must be in local file systems
114that are of types that can be NFS exported.
115Since the
116.Nm
117file system is rooted at ``<rootdir>'', setting this to anything other
118than ``/'' will result in clients being required to use different mount
119paths for
120.Nm
121than for NFS Version 2 or 3.
122Unlike NFS Version 2 and 3, Version 4 allows a client mount to span across
123multiple server file systems, although not all clients are capable of doing
124this.
125.Pp
126.Nm
127uses strings for users and groups instead of numbers.
128On the wire, these strings can either have the numbers in the string or
129take the form:
130.sp
131.Bd -literal -offset indent -compact
132<user>@<dns.domain>
133.Ed
134.sp
135where ``<dns.domain>'' is not the same as the DNS domain used
136for host name lookups, but is usually set to the same string.
137Most systems set this ``<dns.domain>''
138to the domain name part of the machine's
139.Xr hostname 1
140by default.
141However, this can normally be overridden by a command line
142option or configuration file for the daemon used to do the name<->number
143mapping.
144Under
145.Fx ,
146the mapping daemon is called
147.Xr nfsuserd 8
148and has a command line option that overrides the domain component of the
149machine's hostname.
150For use of this form of string on
151.Nm ,
152either client or server, this daemon must be running.
153.Pp
154The form where the numbers are in the strings can only be used for AUTH_SYS.
155To configure your systems this way, the
156.Xr nfsuserd 8
157daemon does not need to be running on the server, but the following sysctls need to be
158set to 1 on the server.
159.sp
160.Bd -literal -offset indent -compact
161vfs.nfs.enable_uidtostring
162vfs.nfsd.enable_stringtouid
163.Ed
164.sp
165On the client, the sysctl
166.sp
167.Bd -literal -offset indent -compact
168vfs.nfs.enable_uidtostring
169.Ed
170.sp
171must be set to 1 and the
172.Xr nfsuserd 8
173daemon does not need to be running.
174.Pp
175If these strings are not configured correctly, ``ls -l'' will typically
176report a lot of ``nobody'' and ``nogroup'' ownerships.
177.Pp
178Although uid/gid numbers are no longer used in the
179.Nm
180protocol except optionally in the above strings, they will still be in the RPC authentication fields when
181using AUTH_SYS (sec=sys), which is the default.
182As such, in this case both the user/group name and number spaces must
183be consistent between the client and server.
184.Pp
185However, if you run
186.Nm
187with RPCSEC_GSS (sec=krb5, krb5i, krb5p), only names and KerberosV tickets
188will go on the wire.
189.Sh SERVER SETUP
190To set up the NFS server that supports
191.Nm ,
192you will need to set the variables in
193.Xr rc.conf 5
194as follows:
195.sp
196.Bd -literal -offset indent -compact
197nfs_server_enable="YES"
198nfsv4_server_enable="YES"
199.Ed
200.sp
201plus
202.sp
203.Bd -literal -offset indent -compact
204nfsuserd_enable="YES"
205.Ed
206.sp
207if the server is using the ``<user>@<domain>'' form of user/group strings or
208is using the ``-manage-gids'' option for
209.Xr nfsuserd 8 .
210.Pp
211You will also need to add at least one ``V4:'' line to the
212.Xr exports 5
213file for
214.Nm
215to work.
216.Pp
217If the file systems you are exporting are only being accessed via
218.Nm
219there are a couple of
220.Xr sysctl 8
221variables that you can change, which might improve performance.
222.Bl -tag -width Ds
223.It Cm vfs.nfsd.issue_delegations
224when set non-zero, allows the server to issue Open Delegations to
225clients.
226These delegations permit the client to manipulate the file
227locally on the client.
228Unfortunately, at this time, client use of
229delegations is limited, so performance gains may not be observed.
230This can only be enabled when the file systems being exported to
231.Nm
232clients are not being accessed locally on the server and, if being
233accessed via NFS Version 2 or 3 clients, these clients cannot be
234using the NLM.
235.It Cm vfs.nfsd.enable_locallocks
236can be set to 0 to disable acquisition of local byte range locks.
237Disabling local locking can only be done if neither local accesses
238to the exported file systems nor the NLM is operating on them.
239.El
240.sp
241Note that Samba server access would be considered ``local access'' for the above
242discussion.
243.Pp
244To build a kernel with the NFS server that supports
245.Nm
246linked into it, the
247.sp
248.Bd -literal -offset indent -compact
249options	NFSD
250.Ed
251.sp
252must be specified in the kernel's
253.Xr config 5
254file.
255.Sh CLIENT MOUNTS
256To do an
257.Nm
258mount, specify the ``nfsv4'' option on the
259.Xr mount_nfs 8
260command line.
261This will force use of the client that supports
262.Nm
263plus set ``tcp'' and
264.Nm .
265.Pp
266The
267.Xr nfsuserd 8
268must be running if name<->uid/gid mapping is being used, as above.
269Also, since an
270.Nm
271mount uses the host uuid to identify the client uniquely to the server,
272you cannot safely do an
273.Nm
274mount when
275.sp
276.Bd -literal -offset indent -compact
277hostid_enable="NO"
278.Ed
279.sp
280is set in
281.Xr rc.conf 5 .
282.sp
283If the
284.Nm
285server that is being mounted on supports delegations, you can start the
286.Xr nfscbd 8
287daemon to handle client side callbacks.
288This will occur if
289.sp
290.Bd -literal -offset indent -compact
291nfsuserd_enable="YES"	<-- If name<->uid/gid mapping is being used.
292nfscbd_enable="YES"
293.Ed
294.sp
295are set in
296.Xr rc.conf 5 .
297.sp
298Without a functioning callback path, a server will never issue Delegations
299to a client.
300.sp
301For NFSv4.0, by default, the callback address will be set to the IP address acquired via
302.Fn rtalloc
303in the kernel and port# 7745.
304To override the default port#, a command line option for
305.Xr nfscbd 8
306can be used.
307.sp
308To get callbacks to work when behind a NAT gateway, a port for the callback
309service will need to be set up on the NAT gateway and then the address
310of the NAT gateway (host IP plus port#) will need to be set by assigning the
311.Xr sysctl 8
312variable vfs.nfs.callback_addr to a string of the form:
313.sp
314N.N.N.N.N.N
315.sp
316where the first 4 Ns are the host IP address and the last two are the
317port# in network byte order (all decimal #s in the range 0-255).
318.Pp
319For NFSv4.1 and NFSv4.2, the callback path (called a backchannel) uses the same TCP connection as the mount,
320so none of the above applies and should work through gateways without
321any issues.
322.Pp
323To build a kernel with the client that supports
324.Nm
325linked into it, the option
326.sp
327.Bd -literal -offset indent -compact
328options	NFSCL
329.Ed
330.sp
331must be specified in the kernel's
332.Xr config 5
333file.
334.Pp
335Options can be specified for the
336.Xr nfsuserd 8
337and
338.Xr nfscbd 8
339daemons at boot time via the ``nfsuserd_flags'' and ``nfscbd_flags''
340.Xr rc.conf 5
341variables.
342.Pp
343NFSv4 mount(s) against exported volume(s) on the same host are not recommended,
344since this can result in a hung NFS server.
345It occurs when an nfsd thread tries to do an NFSv4
346.Fn VOP_RECLAIM
347/ Close RPC as part of acquiring a new vnode.
348If all other nfsd threads are blocked waiting for lock(s) held by this nfsd
349thread, then there isn't an nfsd thread to service the Close RPC.
350.Sh FILES
351.Bl -tag -width /var/db/nfs-stablerestart.bak -compact
352.It Pa /var/db/nfs-stablerestart
353NFS V4 stable restart file
354.It Pa /var/db/nfs-stablerestart.bak
355backup copy of the file
356.El
357.Sh SEE ALSO
358.Xr stablerestart 5 ,
359.Xr mountd 8 ,
360.Xr nfscbd 8 ,
361.Xr nfsd 8 ,
362.Xr nfsdumpstate 8 ,
363.Xr nfsrevoke 8 ,
364.Xr nfsuserd 8
365.Sh BUGS
366At this time, there is no recall of delegations for local file system
367operations.
368As such, delegations should only be enabled for file systems
369that are being used solely as NFS export volumes and are not being accessed
370via local system calls nor services such as Samba.
371