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