284 NFS • NFS file servers simplify network management because only one computer need be regularly written to backup tape. • NFS lets “client computers” mount the disks on the server as if they were physically connected to themselves. The network fades away and a dozen or a hundred individual workstations look to the user like one big happy time-sharing machine. • NFS is “operating system independent.” This is all the more remark- able, considering that it was designed by Unix systems program- mers, developed for Unix, and indeed never tested on a non-Unix system until several years after its initial release. Nevertheless, it is testimony to the wisdom of the programmers at Sun Microsystems that the NFS protocol has nothing in it that is Unix-specific: any computer can be an NFS server or client. Several companies now offer NFS clients for such microcomputers as the IBM PC and Apple Macintosh, apparently proving this claim. • NFS users never need to log onto the server the workstation alone suffices. Remote disks are automatically mounted as necessary, and files are accessed transparently. Alternatively, workstations can be set to mount the disks on the server automatically at boot time. But practice rarely agrees with theory when the Nightmare File System is at work. Not Fully Serviceable NFS is based on the concept of the “magic cookie.” Every file and every directory on the file server is represented by a magic cookie. To read a file, you send the file server a packet containing the file’s magic cookie and the range of bytes that you want to read. The file server sends you back a packet with the bytes. Likewise, to read the contents of a directory, you send the server the directory's magic cookie. The server sends you back a list of the files that are in the remote directory, as well as a magic cookie for each of the files that the remote directory contains. To start this whole process off, you need the magic cookie for the remote file system's root directory. NFS uses a separate protocol for this called MOUNT. Send the file server’s mount daemon the name of the directory that you want to mount, and it sends you back a magic cookie for that directory.
Not Fully Serviceable 285 By design, NFS is connectionless and stateless. In practice, it is neither. This conflict between design and implementation is at the root of most NFS problems. “Connectionless” means that the server program does not keep connections for each client. Instead, NFS uses the Internet UDP protocol to transmit information between the client and the server. People who know about net- work protocols realize that the initials UDP stand for “Unreliable Data- gram Protocol.” That’s because UDP doesn’t guarantee that your packets will get delivered. But no matter: if an answer to a request isn’t received, the NFS client simply waits for a few milliseconds and then resends its request. “Stateless” means that all of the information that the client needs to mount a remote file system is kept on the client, instead of having additional infor- mation stored on the server. Once a magic cookie is issued for a file, that file handle will remain good even if the server is shut down and rebooted, as long as the file continues to exist and no major changes are made to the configuration of the server. Sun would have us believe that the advantage of a connectionless, stateless system is that clients can continue using a network file server even if that server crashes and restarts because there is no connection that must be rees- tablished, and all of the state information associated with the remote mount is kept on the client. In fact, this was only an advantage for Sun’s engi- neers, who didn’t have to write additional code to handle server and client crashes and restarts gracefully. That was important in Sun’s early days, when both kinds of crashes were frequent occurrences. There’s only one problem with a connectionless, stateless system: it doesn’t work. File systems, by their very nature, have state. You can only delete a file once, and then it’s gone. That’s why, if you look inside the NFS code, you’ll see lots of hacks and kludges—all designed to impose state on a stateless protocol. Broken Cookie Over the years, Sun has discovered many cases in which the NFS breaks down. Rather than fundamentally redesign NFS, all Sun has done is hacked upon it. Let’s see how the NFS model breaks down in some common cases: