Network File System

Basic

The Network File System (NFS) is a client/server application that lets a computer user view and optionally store and update files on a remote computer as though they were on the user’s own computer. NFS is a distributed file system(DFS).

Client/server architecture

Advantage

  • Easy sharing of data across clients
  • Centralized administration
  • Security

Disadvantage:

  • Network overhead
  • More components to fail

DFS

Architecture

Stateless - 无状态协议

  • Server does not keep track of states of clients
    • Which files are currently open at which clients
    • Current position/offset of file
    • Which clients have read/cached which blocks
  • Requests from clients must make sure:
    • the server can deliver all the information needed to complete the requests
    • do not rely on previous requests

file handle

  • Volume (file system) identifier
    • Which volume? (e.g. partition C or D if NTFS)
  • Inode number
    • Which file in the volume?
  • Generation number
    • Needed since inode number may be reused at the server (e.g., after file has been deleted by other clients)

Client uses file handle to communication with server

RPC - Remote procedure call

  • Remote server publishes a set of procedures, for example f(args)
    • example: NFSPROC_LOOKUP for lookup file handle ,read, write, create, remove, etc.
  • In making RPC calls,(客户端调用)
    • Client notifies remote server of executing f & sends over arguments args for f
    • Server executes f(args) => results
    • Server sends back results

Operations on remote file

All CRUD operations use file handle

Read

First obtain file handle via lookup

  • File handle for the root directory may be obtained via the mount protocol
1
2
3
4
5
Look up "/foo/more/bar.txt"
– First, use / file handle to obtain foo's handle
File handle for the root directory may be obtained via the mount protocol
– Next, use foo's handle to obtain more's handle
– Finally, use more's handle to obtain bar.txt handle

Then use file handle to read data

1
2
3
4
5
6
7
8
NFSPROC_READ(file handle, offset, count)
- offset here is explicit
– Return: data + file attributes
– File attributes include modification time, useful for client-size cache validation

Compared to local file system
- n = read(fd, buffer, size)
– n is the number of bytes actually read

Write

First obtain file handle via lookup

Then use file handle to write data

1
2
3
4
5
6
7
NFSPROC_WRITE(file handle, offset, count, data)
– Return: file attributes
Note again explicit offset is specified in the call

Compared to local file system
– n = write(fd, buffer, size)
– Offset is again implicit (current position)

Create

1
2
NFSPROC_CREATE(directory file handle, name of file in the directory, attributes)
– Return: file handle

Remove

1
2
NFSPROC_REMOVE(directory file handle, name of file to be removed)
– Return: Nothing

Failures

Cases

Case1: request lost
Case2: Server down
Case3: Reply lost on way back from Sever

More details

学习资源: https://tools.ietf.org/html/rfc1094


本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!