A remote file
Your program opens /nfs/a, but the file lives on a server's disk across the network. The kernel's NFS client turns each file call into a request message. The server answers each request and then forgets it.
open() first needs to know which file a is. The NFS client sends LOOKUP with two things: the handle of the directory /nfs, which it got when it mounted the server, and the name a.
The server finds a in that directory on its disk and replies with its file handle: a volume number, an inode number and a generation number. The client notes that descriptor 3 means this handle. The server notes nothing.
Crashes and retries
read() becomes READ(handle, offset 0, count 4). Everything the server needs is inside the message. But the server has just crashed, so the request is lost and no reply comes back.
The client's timer runs out, so it sends the same READ again. The rebooted server has forgotten everything and needs nothing: the handle, offset and count are all in the request. Reading twice gives the same answer, so retrying is safe.
The server reads 4 bytes, milk, from its disk and replies with the data and the file's attributes, including when it was last modified. The client keeps a copy in its cache, and read() returns 4.
Caches
Client B writes eggs at offset 0 and closes the file. On close, its NFS client sends WRITE(handle, offset 0, eggs). The server puts the bytes on its disk before it replies, so a server crash cannot lose them.
One second later, A reads again. Its cached attributes are under 3 seconds old, so the cache answers and nothing is sent. pread() returns milk: stale data, while the server already holds eggs.
At 5 seconds the cached attributes are too old. Before using its copy, the client sends GETATTR. The reply shows the file was modified after the copy was made, so the client throws the cached data away.
So the client sends READ(handle, offset 0, count 4) once more. The server replies eggs, the client caches the new copy, and pread() returns the current data.
A stateless server makes crashes easy: clients just repeat requests that are safe to repeat. Caches make reads fast, but a client may return old data for a few seconds. NFS chooses speed, and checks with the server now and then.
What happens
;; step 1/11 · remote
client A server
program open, read, ... NFS server
kernel NFS client ----> disk: /nfs/a = milk
(a file system
that talks)
/nfs is a mount: the server's exported directory
appears inside the client's own directory tree.
The lesson follows NFS versions 2 and 3, the classic stateless design described in OSTEP. NFS version 4 adds state on the server (opens and locks), but it keeps the file handle, the client cache and the attribute checks. Times are Linux defaults: cached file attributes are trusted for at least 3 seconds (acregmin) and at most 60 (acregmax), and over TCP a request waits 60 seconds before a retry. Opening the file again would have asked the server at once (close-to-open).