by Christopher Ishida for a lecture by Professor Paul Eggert, November 27, 2013
Caller DATA |
----------> |
Callee DATA |
Caller wants to say:
stat(fd, &st)
Server code:
int struct stat*
int stat(int fd, struct stat *st) {
return unpickled st val;
}
int stat (int fd, struct stat *p) {
Client code:
if (tab[fd] ... )
*p = st;
}
Glue code:
pickle fd;
ship fd over net;
wait for answer;
unpickle struct stat;
*st = (unpickled version)
If no response ______ client won't know whether server got request
Couple of ways to deal with this:
- Timeout: If you don't hear back for a certain amount of time, assumes message was not sent.
- Sequence Number: unique number for each message sent, so one will know when out of order. (TCP, this is similar to checksum)
Checksum the message (at protocol level, end to end)
Resend if corrupted
Isn't perfect but works decently
Client: ------------> Server:
Send x (co-ord) ------------> Read x
Send y (co-ord) ------------> Read y
Send "blue" ------------> Read "blue", color pixel "blue"
Read reply ------------> Send "OK"
Unix file syscalls on wheels (read, write, rename, mkdir...etc. Not dup, pip..etc.)
process p ---> kernel ---> ps process desciptor ---> file descriptor ---> for NFS (stub for NFS protocol) ---> read request
NFS protocol looks like Unix file syscalls
LOOKUP(dirfh, name)
open ("/usr/include/stdio.h", ...)
each directory/file is LOOKUPCREATE (dirfh, name, attr)
(syscall looks like "open(..., O_CREATE)" ) MKDIR (dirfh, name, attr)
returns fh + attrs (creates directory)REMOVE (dirfh, name)
returns status (removes file)RMDIR
- same as above for directoriesREAD (...)
WRITE (...)
(cat a & mv b c) > b
Does this work in NFS?
Yes, because still have file handle which doesn't change inode number
NFS model: Server doesn't care about client state(cat a & rm b) > b
-Naive implementation requires NFS server to keep track of client state
NFS server is "stateless"Suppose:
if server creashes and reboots, clients won't care (except for performance)
client 1:cat a > b
(WRITE request will fail)
client 2:rm b
("stale file handle")
thenerrno == ESTALE;
Process 1: | Process 2: |
get_time_of_day(...); | 1. write(fd, buf, 1024); |
2. read(fd, buf, 1024); | get_time_of_day(...); |
Latency issues & caching issues
NFS (in general) does not have read-after-write consistency
However, it does have open-after-close consistency (must do pending writes)
Considered to be heavyweight operations