NFS READDIR cookie
An NFS READDIR cookie is a server-supplied cursor used to continue retrieving entries from a directory.
In NFSv4.1, a listing starts with cookie zero and a zero cookieverf, then sends a server-issued cookie with the cookieverf from the reply in which it was acquired. The server must reject a verifier it determines is invalid with NFS4ERR_NOT_SAME. The cookie is a 64-bit value meaningful only to the server and is not a byte offset. Cookie values 1 and 2 should not be sent, and 0, 1 and 2 should not be returned. [1]
The verifier is 8 bytes in both NFSv3 and NFSv4.1. NFSv2 had no verifier, so a reorganized directory could make a second READDIR miss entries or return them twice. NFSv3 added the verifier and rejects a stale cookie with NFS3ERR_BAD_COOKIE. [2]
A cookie/verifier pair addresses continuation for that directory, not a coordinated snapshot of a directory tree. If requested, rdattr_error can carry an attribute-fetch failure for one entry inside an otherwise successful READDIR reply, so per-entry errors need inspection as well as the operation status. [1]
Relations
Advantages
- dircount and maxcount let a client bound the XDR-encoded reply in bytes, and the server must return NFS4ERR_TOOSMALL when not even one entry fits. [1]
- A server whose cookies never become invalid may use zero as the verifier on every reply. [2]
Limitations
- Cookie stability across directory changes is only a SHOULD, so a long listing can still end with NFS4ERR_NOT_SAME. [1]
- Servers should not return the . and .. entries, so a client that needs them must fabricate them. [1]
Citations
- Noveck and Lever: RFC 8881, NFSv4.1 READDIR, sections 18.23.3-18.23.4
- Callaghan et al.: RFC 1813, NFS version 3 READDIR, section 3.3.16
Sources & caveats
- nfs-readdir is RFC 8881, re-read for READDIR arguments, results, reserved cookie values, the 64-bit nfs_cookie4 type and the 8-byte NFS4_VERIFIER_SIZE.
- nfs3-readdir is RFC 1813 section 3.3.16, read for the NFSv2 problem the verifier solves, NFS3ERR_BAD_COOKIE and the 8-byte NFS3_COOKIEVERFSIZE.
- The nfs-lookup-cache entry links here because both depend on cached directory state that a server-side change can make stale.