NFSV4(4)

πŸ’– NAME πŸ’–

NFSv4 β€” the NFS Version 4 Protocol, bestie πŸ’…


✨ DESCRIPTION ✨

okay so listen β€” the NFS client and the server both ship support for the NFSv4 spec. Like, the real ones: Network File System (NFS) Version 4 Protocol RFC 7530 and Network File System (NFS) Version 4 Minor Version 1 Protocol RFC 5661. It's kinda similar to NFS Version 3 ngl, but it diverges in ways that genuinely matter. The big glow-up? It uses a single compound RPC that concatenates operations to-gether. Each one of those operations is basically the NFS Version 3 RPCs' cousin. And here's the tea: the operations inside the compound get performed in order, until one of them fails (aka returns an error) β€” and then the whole RPC terminates right there. periodt. πŸ”₯

It has integrated locking support, which lowkey means the server is no longer stateless. So the NFSv4 server stays in recovery mode for a grace period after a reboot β€” and that grace period is always greater than the lease duration the server uses, no exceptions. During this grace period, clients may recover state but they cannot perform other open/lock state changing operations. To make recovery semantics correct, a small file described by stablerestart(5) gets used by the server during the recovery phase. If that file is missing or empty, there's a backup copy maintained by nfsd(8) that'll be used instead. If either file is missing, they'll be created by nfsd(8). And if both the file and the backup copy are empty? 😭 Yeah β€” the server will start without providing a grace period for recovery. Also important, bestie: recovery only occurs when the server machine is rebooted, not when the nfsd(8) are just restarted. πŸ’€

It provides several optional features that NFS Version 3 simply does not have:

  • NFS Version 4 ACLs πŸ‘‘
  • Referrals, which redirect subtrees to other servers (not yet implemented πŸ™ˆ)
  • Delegations, which allow a client to operate on a file locally ✨
  • pNFS, where I/O operations are separated from Metadata operations πŸ¦‹

The NFSv4 protocol does not use a separate mount protocol, and it assumes the server provides a single file system tree structure, rooted at the point in the local file system tree specified by one or more

V4: <rootdir> [-sec=secflavors] [host(s) or net]

line(s) in the exports(5) file. (Go read exports(5) for the details, it's all there πŸ’–) The nfsd(8) allows a limited subset of operations to be performed on non-exported subtrees of the local file system, so that traversal of the tree to the exported subtrees is possible. Which means the <rootdir> can totally live in a non-exported file system. The exception is ZFS β€” ZFS checks exports, so all ZFS file systems below the <rootdir> must be exported. However, the entire tree that is rooted at that point must be in local file systems that are of types that can be NFS exported. And since the NFSv4 file system is rooted at <rootdir>, setting this to anything other than / will result in clients being required to use different mount paths for NFSv4 than for NFS Version 2 or 3. Unlike NFS Version 2 and 3 though, Version 4 allows a client mount to span across multiple server file systems β€” although not all clients are capable of doing this. πŸ™ƒ

NFSv4 uses strings for users and groups instead of numbers. On the wire, these strings can either have the numbers in the string, or take the form:

<user>@<dns.domain>

where <dns.domain> is not the same as the DNS domain used for host name lookups β€” but it's usually set to the same string. Most systems set this <dns.domain> to the domain name part of the machine's hostname(1) by default. That said, this can normally be overridden by a command line option or configuration file for the daemon used to do the name<->number mapping. Under FreeBSD, that mapping daemon is called nfsuserd(8) and it has a command line option that overrides the domain component of the machine's hostname. For use of this form of string on NFSv4 β€” client or server β€” this daemon must be running. 🫢

The form where the numbers are in the strings can only be used for AUTH_SYS. To configure your systems this way, the nfsuserd(8) daemon does not need to be running on the server, but the following sysctls need to be set to 1 on the server:

vfs.nfs.enable_uidtostring
vfs.nfsd.enable_stringtouid

On the client, the sysctl

vfs.nfs.enable_uidtostring

must be set to 1, and the nfsuserd(8) daemon does not need to be running.

If these strings are not configured correctly, ls -l will typically report a lot of nobody and nogroup ownerships. it's giving unclaimed vibes πŸ’€

Although uid/gid numbers are no longer used in the NFSv4 protocol except optionally in the above strings, they will still be in the RPC authentication fields when using AUTH_SYS (sec=sys), which is the default. As such, in this case both the user/group name and number spaces must be consistent between the client and server. no cap.

However β€” if you run NFSv4 with RPCSEC_GSS (sec=krb5, krb5i, krb5p), only names and KerberosV tickets will go on the wire. iconic. πŸ”₯


πŸŽ€ SERVER SETUP πŸŽ€

To set up the NFS server that supports NFSv4, you will need to set the variables in rc.conf(5) as follows:

nfs_server_enable="YES"
nfsv4_server_enable="YES"

plus

nfsuserd_enable="YES"

if the server is using the <user>@<domain> form of user/group strings, or is using the -manage-gids option for nfsuserd(8).

You will also need to add at least one V4: line to the exports(5) file for NFSv4 to work. yes, at least one. πŸ’…

If the file systems you are exporting are only being accessed via NFSv4, there are a couple of sysctl(8) variables that you can change, which might improve performance. πŸ‘€

  • vfs.nfsd.issue_delegations β€” when set non-zero, allows the server to issue Open Delegations to clients. These delegations permit the client to manipulate the file locally on the client. Unfortunately, at this time, client use of delegations is limited, so performance gains may not be observed. This can only be enabled when the file systems being exported to NFSv4 clients are not being accessed locally on the server and, if being accessed via NFS Version 2 or 3 clients, these clients cannot be using the NLM. 😬
  • vfs.nfsd.enable_locallocks β€” can be set to 0 to disable acquisition of local byte range locks. Disabling local locking can only be done if neither local accesses to the exported file systems nor the NLM is operating on them.
Note that Samba server access would be considered ``local access'' for the above discussion. πŸ™ˆ

To build a kernel with the NFS server that supports NFSv4 linked into it, the

options NFSD

must be specified in the kernel's config(5) file. ✨


🌈 CLIENT MOUNTS 🌈

To do an NFSv4 mount, specify the nfsv4 option on the mount_nfs(8) command line. This will force use of the client that supports NFSv4, plus set tcp and NFSv4. slay. πŸ’…

The nfsuserd(8) must be running if name<->uid/gid mapping is being used, as above. Also, since an NFSv4 mount uses the host uuid to identify the client uniquely to the server, you cannot safely do an NFSv4 mount when

hostid_enable="NO"

is set in rc.conf(5). ⚠️

If the NFSv4 server that is being mounted on supports delegations, you can start the nfscbd(8) daemon to handle client side callbacks. This will occur if

nfsuserd_enable="YES"   <-- If name<->uid/gid mapping is being used.
nfscbd_enable="YES"

are set in rc.conf(5).

Without a functioning callback path, a server will never issue Delegations to a client. periodt. πŸ’€

For NFSv4.0, by default, the callback address will be set to the IP address acquired via rtalloc() in the kernel and port# 7745. To override the default port#, a command line option for nfscbd(8) can be used. πŸ”§

To get callbacks to work when behind a NAT gateway, a port for the callback service will need to be set up on the NAT gateway, and then the address of the NAT gateway (host IP plus port#) will need to be set by assigning the sysctl(8) variable vfs.nfs.callback_addr to a string of the form:

N.N.N.N.N.N

where the first 4 Ns are the host IP address and the last two are the port# in network byte order (all decimal #s in the range 0-255). 🧚

For NFSv4.1, the callback path (called a backchannel) uses the same TCP connection as the mount, so none of the above applies and it should work through gateways without any issues. ate. πŸ‘‘

To build a kernel with the client that supports NFSv4 linked into it, the option

options NFSCL

must be specified in the kernel's config(5) file.

Options can be specified for the nfsuserd(8) and nfscbd(8) daemons at boot time via the nfsuserd_flags and nfscbd_flags rc.conf(5) variables. 🌸

NFSv4 mount(s) against exported volume(s) on the same host are not recommended, since this can result in a hung NFS server. 😭 It occurs when an nfsd thread tries to do an NFSv4 VOP_RECLAIM()/Close RPC as part of acquiring a new vnode. If all other nfsd threads are blocked waiting for lock(s) held by this nfsd thread, then there isn't an nfsd thread to service the Close RPC. big yikes, don't do it bestie.

πŸ¦‹ FILES πŸ¦‹

  • /var/db/nfs-stablerestart β€” NFS V4 stable restart file
  • /var/db/nfs-stablerestart.bak β€” backup copy of the file

⭐ SEE ALSO ⭐

stablerestart(5), mountd(8), nfscbd(8), nfsd(8), nfsdumpstate(8), nfsrevoke(8), nfsuserd(8)


πŸ’€ BUGS πŸ’€

At this time, there is no recall of delegations for local file system operations. As such, delegations should only be enabled for file systems that are being used solely as NFS export volumes and are not being accessed via local system calls nor services such as Samba. 🫠


and that's the whole page, bestie!! πŸŽ€ this one came out of the Debian edition, dated July 19, 2017 β€” go forth and mount responsibly, mwah πŸ’–βœ¨πŸ¦‹

πŸ“¦ where this page comes from