Skip to content
SEE Exam Prep

Question 10 of 15 · CIE-2 QB · 7 marks

Open in ChatGPT

Explain the architecture and working of NFS. Discuss its file access and caching mechanisms.


Introduction

NFS (Network File System) lets a client mount a directory exported by a server and then use ordinary file calls on it. It is the standard shared file system of Unix, and its design is deliberately simple: a stateless server and a client that caches aggressively.

Architecture

  1. Server: exports a directory, and identifies each file by a file handle (file system id, inode, generation number) that survives a restart.
  2. Client: mounts the export at a local path through the VFS layer, so read() on a mounted path becomes an NFS call.
  3. Protocol: remote procedure calls: LOOKUP, READ, WRITE, GETATTR, SETATTR, READDIR: each carrying the handle and all needed arguments.
  4. Statelessness: the server keeps no per-client state, so a crashed server can restart and continue; the client retries.

NFS architecture: processes reach a Virtual File System, which either passes the call to the local UNIX file system and its disk, or to the NFS client, which sends it over the network to the NFS server and its own file system

File access

  • A LOOKUP resolves a name to a handle; subsequent operations use the handle.
  • Reads and writes are done in blocks (commonly 4–64 KB) with a byte offset and a count, so large files are read incrementally.
  • Close-to-open consistency: the client flushes dirty blocks on close, and revalidates cached attributes on open.

Caching

  • The client caches file data, attributes and directory entries, each with a timestamp.
  • A cached block is considered stale after a short interval; attribute caching makes repeated stat calls local.
  • The kernel also does read-ahead and write-behind, batching NFS requests.

Diagram

read(fd, buf, 4096)cache missREAD handle, offsetdatadatabytes readAppVFSNFS clientServerAppVFSNFS clientServer

Limitations

  • Statelessness means every call repeats the handle, and locking needs a separate protocol (NLM).
  • Cache revalidation by timeout gives weak consistency between clients.
  • A single server is a single point of failure unless exported from a replicated or clustered file system.

Conclusion

NFS is a thin protocol over RPC with a stateless server and a trusting client cache. That is what makes it easy to implement, easy to recover, and only eventually consistent.