Repository navigation
Conversation
cberner
force-pushed
the
claude/nfs4-prototype
branch
2 times, most recently
from
November 27, 2026 23:02
69149e4 to
08a01fc
Compare
cberner
force-pushed
the
claude/nfs4-prototype
branch
4 times, most recently
from
November 28, 2026 01:08
13235b9 to
ef01938
Compare
cberner
force-pushed
the
claude/nfs4-prototype
branch
15 times, most recently
from
November 28, 2026 18:54
f11adb3 to
7312966
Compare
Experimental, next to NFSv3, which stays the default: with
MountOption::CUSTOM("vers=4") (or "vers=4.1") the backend mounts with
mount_nfs -o vers=4.1, and the same in-process server answers NFS
version 4, minor version 1 only.
nfs4.rs answers COMPOUND, with the operations a client needs to mount and
use a filesystem:
- sessions: EXCHANGE_ID, CREATE_SESSION, SEQUENCE, DESTROY_SESSION,
BIND_CONN_TO_SESSION, BACKCHANNEL_CTL, DESTROY_CLIENTID and
RECLAIM_COMPLETE;
- file handles: PUTROOTFH, PUTFH, GETFH, SAVEFH and RESTOREFH;
- names: LOOKUP, LOOKUPP, CREATE, REMOVE, RENAME and LINK;
- data: GETATTR (a broad fattr4 set, with suppattr_exclcreat), SETATTR,
ACCESS, READ, WRITE, COMMIT, READDIR and READLINK;
- opens: OPEN (CLAIM_NULL and CLAIM_FH, all four create modes),
OPEN_DOWNGRADE and CLOSE;
- locks: LOCK, LOCKT and LOCKU;
- security and state: SECINFO, SECINFO_NO_NAME, TEST_STATEID and
FREE_STATEID.
Every COMPOUND but those setting up a session starts with SEQUENCE. Each
session has up to 16 slots, and a slot keeps its last reply when the
client asks or the reply is small, so a retransmitted request is answered
again rather than run twice, and one whose reply was not kept gets
NFS4ERR_RETRY_UNCACHED_REP. The current stateid is tracked through a
COMPOUND. NFSv4.0's SETCLIENTID, RENEW, OPEN_CONFIRM and
RELEASE_LOCKOWNER are refused as 4.1 requires.
OPEN and CLOSE become FUSE open and release, and READ and WRITE use the
open's handle. Locks go to the filesystem's getlk and setlk, or to a table
kept here when it answers ENOSYS. Other state is kept in its simplest
form: client ids never expire, and there are no delegations, callbacks or
pNFS. A client that restarts, or is destroyed, has its opens released.
Owners are numeric strings.
The pseudo-root's one entry is the export, by a name made up for the
server, which can be looked up only until the mount is made. Handles carry
the server's key as for v3, and a v4 server refuses v3's MNT, so neither
version hands other local users a handle.
Unit tests drive COMPOUNDs through the RPC layer against the in-memory
filesystem, sessions and their reply cache included. mac-ci runs the
macOS mount tests, pjdfstest and the benchmark with vers=4.1 too, as
experimental steps next to the v3 ones, and the Linux job runs cthon04
through Linux's NFSv4.1 client as well as its v3 one.
A SETATTR of the size through an open for writing is an ftruncate: the
open's FUSE handle goes with it, so the filesystem may allow what the
file's mode would not.
For both versions:
- mount_nfs caches attributes for a second (actimeo=1), as FUSE does by
default, instead of not at all: uncached, each operation cost the
client several calls to revalidate every directory on its path
(about 10 per create, stat or unlink). On mac-ci this cut stat from 4
calls to 1, read from 9 to 3, create and unlink from about 14 to 7.
MountOption::CUSTOM("actimeo=0") restores no caching;
- NFSv4.1 mounts with rsize and wsize of 1 MiB, rather than the
client's 32 KiB: on mac-ci, writes of 256 MiB went from 67 to 584
MiB/s and reads from 239 to 491 MiB/s, with the attribute caching;
- READDIR and READDIRPLUS stop adding entries after 100 ms and return
what they have: a 1 MiB listing of 1000 entries of the simple example,
whose every lookup reads its whole directory, took 8 s, and macOS gave
up on it with ETIMEDOUT;
- ACCESS always grants DELETE. macOS asks it of the node to be removed
or renamed, which only its directory decides, and REMOVE and RENAME
are the filesystem's to refuse. Until now deleting a read-only file
from a writable directory was refused by the client;
- each COMPOUND's operations and status are logged at debug, and each
call's time in the server at trace; a call taking over a second is a
warning, as the client may retransmit it or give up on it.
NFSv3 mounts with rsize 1 MiB and wsize 512 KiB. FSINFO offered 1 MiB
as rtmax but 128 KiB as rtpref, to which macOS shrank rsize; it now
offers 1 MiB for both. At wsize 1 MiB macOS's v3 client stalls a large
writer for 15 to 30 s after each 64 MiB or so, for 2 MiB/s in all; on
mac-ci 256 MiB went at 39 MiB/s with 32 KiB writes, 173 with 128 KiB
and 433 with 512 KiB, without stalls. v3 WRITE and COMMIT now return
the file's attributes from before and after (wcc_data), as RFC 1813
has them, rather than none.
From a review of the server:
- the export's path holds a secret, for v3 too: MNT answers only that
path, and EXPORT lists nothing. v4 seals the export at the first PUTFH
of a handle of it, rather than once mount_nfs has returned, and from
then on refuses EXCHANGE_ID but from the mount's own client;
- v4 client and session ids are random. They were a counter, and the
session id held the server's verifier, which EXCHANGE_ID hands out:
another local user could have named the mount's session and read the
replies it kept, file handles among them;
- cached FUSE handles are told apart by an id of their own, not by fh,
which a filesystem may give every open;
- v4 OPEN compares access modes only, so a file created by an owner is
no longer reopened read-write when it opens it again; concurrent
OPENs by one owner no longer make two opens;
- CLOSE drops the open's byte-range locks, waits for the flush and
reports its error; FREE_STATEID of a lock-owner still holding locks
kept here gets NFS4ERR_LOCKS_HELD; a filesystem without getlk but with
setlk gets NFS4ERR_NOTSUPP for LOCKT, rather than its locks forgotten;
- a stateid is checked against the current file; lock offsets beyond
FUSE's are refused or clipped;
- COMMIT and stable WRITE sync through the handles written through;
- names are checked as the kernel would before reaching the filesystem
('/', NUL, empty, longer than NAME_MAX, "." and ".." as targets);
- calls without AUTH_SYS credentials are nobody's, not the mounting
user's;
- a reply beyond the session's maximum gets NFS4ERR_REP_TOO_BIG;
- each connection queues at most 32 calls, no more than 16 connections
are served, and no more than 64 clients and 64 sessions are kept;
- a connection accepted while the server stops is closed.
A request retransmitted while it is still being answered gets
NFS4ERR_DELAY, and its reply is then kept whatever its size, so that the
retransmission is answered with it rather than with
NFS4ERR_RETRY_UNCACHED_REP. macos_bench.sh shows the server's log when
it fails.
macOS's v4 client cannot send owner or group 0 while it maps ids
through its identity service, its default: chown to root fails with
ENOSPC before any request is made. With
vfs.generic.nfs.client.idmap_ctrl=0 it sends "root" and "wheel", which
the server resolves. This is documented, and mac-ci sets it for the v4.1
run of the excluded pjdfstest cases.
Requests now carry the caller's uid and gid, from each call's AUTH_SYS
credentials, for both NFS versions, so the filesystem checks permissions
against the user who made the call, and SessionACL applies as it does
with FUSE. ACCESS asks the filesystem, through FUSE_ACCESS as the
caller, rather than granting all, and cached file handles serve only
the user who opened them. NFSv4 owners may be names the host's user
database knows, as macOS sends root. pjdfstest's excluded cases, most of
which switch users, run as root in mac-ci on FSKit, NFSv3 and NFSv4.1,
reported in the job summary (PJDFS_EXCLUDED=1).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ALhxewwQVDkW5VehX2vkXu
cberner
force-pushed
the
claude/nfs4-prototype
branch
from
November 28, 2026 19:09
7312966 to
9fe778e
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Draft, not to merge. NFSv4.1 for the macOS NFS backend, stacked on #793. NFSv3 stays the default.
MountOption::CUSTOM("vers=4")or"vers=4.1"selects 4.1 (macOS'smount_nfssupports minor versions 0 and 1). This also brings fixes to the shared NFS code that apply to v3 as well.v3 and v4.1 compared
Features
open/releasereach the filesystemlocallocks), never reach the filesystemgetlk/setlk, or a table in the serverftruncateon a file without write permissionsysctl vfs.generic.nfs.client.idmap_ctrl=0(macOS client bug, see below)Both versions share identity (AUTH_SYS uid/gid passed to the filesystem, ACCESS through FUSE_ACCESS), the secret export path, handle keys, the transport and the FUSE glue.
Performance (mac-ci, simple example; medians of 3 interleaved rounds on one runner)
Implementation size (lines of code, excluding comments and blank lines)
nfs3.rs, which also holds attribute and name helpers v4 uses)nfs4.rs, about 215 of which are constants)What the 4.1 server does
sa_cachethisor the reply is under 4 KiB.suppattr_exclcreat), SETATTR, ACCESS, READ, WRITE, COMMIT, READDIR and READLINK.Shared fixes from review (both versions)
fh./, NUL, empty, longer than NAME_MAX, and.or..as targets.Defaults chosen from measurements on mac-ci
actimeo=1, matching FUSE's default 1-second timeouts:CUSTOM("actimeo=0")turns it off.rsize1 MiB for both versions: v3's FSINFO now offers 1 MiB as rtpref too, where it was 128 KiB.wsize: 1 MiB for v4.1 and 512 KiB for v3.At 1 MiB, macOS's v3 client stalls a writer for 15-30 s after each ~64 MiB, about 2 MiB/s overall.
256 MiB of writes over v3 by wsize:
pjdfstest excluded cases on 4.1: the 56 left
vn_authorize_renamex). APFS behaves the same.ftruncatecase.macOS client quirk: chown to root
chownto root fails with ENOSPC before any request is sent.sudo sysctl vfs.generic.nfs.client.idmap_ctrl=0. The client then sends "root" and "wheel", which the server resolves.Testing
Known gaps
namedattr.🤖 Generated with Claude Code
https://claude.ai/code/session_01ALhxewwQVDkW5VehX2vkXu