NFS: Big Picture Lecture 19 NFS March 4, 2005 File Lookup File Positioning client request root handle handle Hr lookup a in Hr handle Ha lookup b in Ha handle Hb lookup c in Hb handle Hc server time Server is stateless. Client stores file position. Each request must specify the file position. Directories: can be large, multiple requests may be necessary. NFS uses position identifiers, client can use it in next request to specify which entries it has already received and which it still needs. NFS calls position identifier magic cookie. Version 4 NFS Traditional Client/Server system Version 2 and Version 3 Server stateless Stateless model not always fully implemented (file locking difficult: lock manager; authentication protocols: server maintains state at clients). Very little client info held. Version 4 Stateless model abandoned (although the protocol is designed so that the server needs to hold little client info). Stateful Approach Besides file locking and authentication there is another reason for making the server stateful. NFS 4 is expected to work over WANs. This requires that client can make efficient use of caches. This, in turn, requires an efficient cache consistency protocol. Server needs to maintain information on files used by clients. For example, the server may associate a lease with each client, promising to give client exclusive read/write. 1
Version 3 vs Version 4 Naming a) Reading data from a file in NFS version 3 b) Reading data using a compound procedure in version 4 Naming Automounting File Attributes File Attributes Version 3 used fixed set of attributes Fully implementing version 3 was difficult on some platforms Version 4 split attributes into 3 sets: mandatory attributes recommended attributes named attributes Named attributes not actually part of NFS protocol Attribute TYPE SIZE CHANGE FSID Attribute ACL FILEHANDLE FILEID FS_LOCATIONS OWNER TIME_ACCESS TIME_MODIFY TIME_CREATE The type of the file (regular, directory, symbolic link) The length of the file in bytes Indicator to see if and/or when the file has changed Server-unique identifier of the file's file system an access control list associated with the file The server-provided file handle of this file A file-system unique identifier for this file Locations in the network where this file system may be found The character-string name of the file's owner Time when the file data were last accessed Time when the file data were last modified Time when the file was created 2
Semantics of File Sharing a) On a single processor, when a read follows a write, the value returned by the read is the value just written. b) In a distributed system with caching, obsolete values may be returned. Semantics of File Sharing Immutable Files no updates are possible simplifies sharing and replication only operations are create and read Transaction all changes occur atomically BEGIN_TRANSACTION, END_TRANSACTION File Locking in NFS NFS Caching File contents and attributes. Client versus server caching. Client Server $ $ Operation Lock Lockt Locku Renew Creates a lock for a range of bytes Test whether a conflicting lock has been granted Remove a lock from a range of bytes Renew the lease on a specified lock Client Caching Client Caching: Delegation Client-side caching is left to the implementation (NFS does not prohibit it) Different implementation use different caching policies Sun: allow cache data to be stale for up to 30 seconds NFS V4 supports open delegation Server delegates local open and close requests to the NFS client Uses a callback mechanism to recall file delegation. 3
Client Caching Timestamp-based cache invalidation. Read: Cached entries have TS with last-modified time. Blocks assumed to be valid for TTL. TTL specified at mount time. Typically 3 sec for files. Client Caching Write: Modified pages marked and flushed to server at file close or sync (every 30 sec). Consistency? Not always guaranteed! E.g., client modifies file; delay for modification to reach servers + 3-sec window for cache validation from clients sharing file. Server Caching Read: Same as UNIX FS. Caching of file pages and attributes. Cache replacement uses LRU. Write: Write through (as opposed to delayed writes of conventional UNIX FS). Why? [Delayed writes: modified pages written to disk when buffer space needed, sync operation (every 30 sec), file close]. Cache Validation Validation check performed when: First reference to file after TTL expires. File open or new block fetched from server. Done for all files (even if not being shared). Expensive! Potentially, every 3 sec get file attributes. If needed invalidate all blocks. Fetch fresh copy when file is next accessed. RPC Failures Security Three situations for handling retransmissions. a) The request is still in progress b) The reply has just been returned c) The reply has been some time ago, but was lost. 4
Secure RPCs Access Control Operation Read_data Write_data Append_data Execute List_directory Add_file Add_subdirectory Delete Delete_child Read_acl Write_acl Read_attributes Write_attributes Read_named_attrs Write_named_attrs Write_ow ner Synchronize Permission to read the data contained in a file Permission to modify a file's data Permission to append data to a file Permission to execute a file Permission to list the contents of a directory Permission to add a new file t5o a directory Permission to create a subdirectory to a directory Permission to delete a file Permission to delete a file or directory w ithin a directory Permission to read the ACL Permission to w rite the ACL The ability to read the other basic attributes of a file Permission to change the other basic attributes of a file Permission to read the named attributes of a file Permission to w rite the named attributes of a file Permission to change the ow ner Permission to access a file locally at the server w ith synchronous reads and w rites The classification of operations recognized by NFS with respect to access control. Transport Protocol Originally used UDP. Better performance in LANs. NFS and RPC do their own reliability checks. Most current implementations use TCP. WANs: congestion control. TCP officially integrated in NFS v.3. Virtual File System VFS added to UNIX kernel. Location-transparent file access. Distinguishes between local and remote access. @ client: Processes system calls for file system to determine whether access is local (passes it to UNIX FS) or remote (passes it to NFS client). @ server: NFS server receives request and passes it to local FS through VFS. Virtual File System If local, translates file handle to internal file id s (in UNIX i-nodes). V-node: If file local, reference to file s i-node. If file remote, reference to file handle. File handle: uniquely distinguishes file. File system id I-node # I-node generation # 5