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