NFS -- Network File System

LAN-users might want to access files on more disks than the one that is physically attached to the local computer.  NFS is one tool used to access disks located on remote computers.

NFS provides transparent file access for clients to files and filesystems on a server.  This means that a user need not know if the file (s)he wants to access is physically located on his/her local computer or not, as long as the filesystem containing the file is mounted to his/her local filesystem.

The figure below shows how files are accessed in a NFS-system.

 
 

When a user-process wants to access a local file the client kernel uses a local file access, but when a user-process wants to access a remote file, the kernel sends RPC-calls to the NFS server over TCP/IP or (more likely) UDP/IP. The NFS server then accesses its local file, and sends the result back to the NFS client.

NFS is part of the operating system kernel. Nothing special need be done by the client program to use NFS . The kernel detects that the file is remote and automatically generates the RPC calls to access the file.
 

NFS mount protocol

The client must use the NFS mount protocol to mount a server's filesystem, before the client can access files on that filesystem. This is often done when the client is bootstrapped. The end result is for the client to obtain a file handle for the server's filesystem.

Mounting is done by client RPC calls to the mount deamon, which runs on the server. The mount deamon replies with the file handle for the given filesystem. The file handle is stored in the NFS client code, and from this point on any references by user procedures to files on that server's filesystem will use that file handle as the starting point.   Without this handle, clients cannot access files on the server.

Permissions are checked during mount time.

NFS procedures

The NFS server provides 15 procedures: (see https://www.freesoft.org/CIE/Topics/115.htm).

 

NFS V3.0

Classic NFS is NFS v2.0.  The latest version is NFS v4.  There are a couple of improvements, but the protocol is essencially the same.

Server Crashes

The NFS protocol is stateless.  The NFS server does not need to keep any record of who has an NFS file system mounted.  When a server crashes, all NFS clients can just wait with their request until the server comes back up.  There is no need to remount the server's file system.

Idempotency

Every NFS operation is designed to be idempotent.  That way, if the server crashes in the middle of an operation, the client can retry the operation without worrying if the operation has already happened.  For example, if the client sends a link() command, but the server crashes before getting a reply, the client has no way of knowing if the operations succeeded or not.  All the client can conclude for certain is that the server crashed before the reply could be sent.  Retying the link() command after the server comes back up will ensure that the link is created, even though the first operation might have already made the link.

Some operations are easy to make idempotent, like read or write. Other operations are hard to make idempotent, like delete. For these the server keeps a cache of recent operations, and just replays the answer for every duplicate request. This is a violation of statelessness. Also, if the server reboots then the operation is not idempotent.
 

Server Caching

Someone, either the server or the client, must keep a copy of all data written by an application untill that data hits an actual hard drive.  Otherwise, and unfortunate system crash could cause data to be lost.

The NFS standard says that the NFS server cannot acknowedge a write() operation until that data has hit stable storage.  This safety feature greatly slows NFS writes.  Sometimes people enable a special feature of NFS servers such that the server acknowdges the write before the data hits stable storage, speeding the server at the cost of some safety.  Othes spend money on NVRAM for their write cache, giving safety and speed at the cost of money.

Pros 'n' Cons