Class 21 (by video) CS 372H 8 April 2011 On the board ------------ 1. Last time 2. Transactions, continued 3. RPC, client/server systems 4. NFS (case study of client/server) 5. Other distributed file systems --------------------------------------------------------------------------- 1. Last time --finished LFS --discussed how transactions are implemented --note: you should compare transactions, and their approach to crash recovery, to the ad-hoc file system crash recovery that we discussed. transactions are far more principled and far harder to implement incorrectly. --another note: in everyday life, go with redo logging! (the refinement we saw last time wherein the changes associated with a transaction are propagated from the log to cell storage only after the COMMIT record is logged). --undo logging not needed for most things 2. Transactions, continued --Remember the A C I D guarantees. Last time, we showed how a transaction system can provide 'A'. It uses the logging discipline (and the associated invariants) and the recovery protocol. With just those things, the transaction system provides to *its* users (that is, those who call BEGIN_TX/END_TX from programs) the 'A' guarantee. --Today: quickly go over 'I' but not in great detail. A. [last time] Atomicity ("all-or-nothing atomicity") B. Isolation ("before-or-after atomicity") --easiest approach: one giant lock. only one transaction active at a time. so everything really is serialized --advantage: easy to reason about --disadvantage: no concurrency --next approach: fine-grained locks (e.g., one per cell, or per-table, or whatever), and acquire all needed locks at begin_transaction and release all of them at end_transaction --advantage: easy to reason about. works great if it could be implemented --disadvantage: requires transaction to know all of its needed locks in advance --actual approach: two-phase locking. gradually acquire locks as needed (phase 1), and then release all of them together at the commit point (phase 2). (this is implemented inside the transaction manager.) --your intuition from the concurrency unit will tell you that this creates a problem....namely deadlock. we'll come back to that in a second. --why does this actually preserve a serial ordering? here's an informal argument: --consider the lock point, that is, the point in time at which the transaction owns all of the locks it will ever acquire. --consider any lock that is acquired. call it l.from the point that l is acquired to the lock point, the application always sees the same values for the data that lock l protects (because no other transaction or thread can get the lock). --so regard the application as having done all of its reads and writes instantly at the lock point --the lock points create the needed serialization. Here's why, informally. Regard the transactions as having taken place in the order given by their lock points. Okay, but how do we know that the lock points serialize? Answer: each lock point takes place at an instant, and any lock points with intersecting lock sets must be serialized with respect to each other as a result of the mutual exclusion given by locks. --to fix deadlock, several possibilities: --one of them is to remove the no-preempt condition: have the transaction manager abort transactions (roll them back) after a timeout C. One more loose end: --we haven't incorporated checkpoints into our recovery protocol. they help performance (less work to do on crash recovery), but, in their full generality, they add complexity. However, it's usually possible to reduce the complexity by using redo logging. Maintain a trailing pointer in the W.A.L. to mean: "everything before here has been propagated". that trailing pointer identifies the current checkpoint state. ---------------------------------------------------------------------- admin notes: --lab 6 out --due two weeks from tomorrow --start on time: meaning now or next week --don't fall behind on networking material, 'cause you need to understand some aspects of networking to see what's going on in the lab ---------------------------------------------------------------------- 3. RPC, client/server systems --what the heck is RPC? (compare to local function calls.) --client/server systems --potential of RPC: fantastic way to build distributed systems --RPC system takes care of all the distributed/network issues --how well does all of this work? 4. NFS: case study of client/server, and case study of network file system Networked file systems: --What's a network file system? --Looks like a file system (e.g., FFS) to applications --But data potentially stored on another machine --Reads and writes must go over the network --Also called distributed file systems --Advantages of network file systems --Easy to share if files available on multiple machines --Often easier to administer servers than clients --Access way more data than fits on your local disk --Network + remote buffer cache faster than local disk --Disadvantages --Network + remote disk slower than local disk --Network or server may fail even when client OK --Complexity, security issues NFS: seminal networked file system (NFS = Network File System) --see the assigned paper. we're going to go through its material now. * Intro and background * How it works * Statelessness * Transparency * Security A. Intro and background --Reasons to study it --case study of RPC transparency --NFS was very successful. --Still in widespread use today (we're using it in class machines). --Much research uses it. --Can view much networked file systems research as fixing problems with NFS --Is this actually a good paper? (Very interesting paper, but perhaps not the best example of technical communication. Lots of Unix jargon, use of "I" on a multi-author paper (!), thanking of co-authors in the acknowledgments (!), references section not very useful, etc., etc.) --background and context --designed in mid 1980s --before this, Sun was selling Unix workstations --diskless (to save money) --"ND" network disk protocol (use one big central disk, and let the diskless workstations use it) --allowed disk to live somewhere else, but did not allow for shared file system (every workstation had a partitioned piece of the ND *not* a shared file system) More detail on context: NFS arose in the early-to-mid 1980s. Prior to NFS, each computer had its own private disk and file system. That worked for expensive central time-sharing systems when there weren't many workstations. But in the LAN environment, with workstations becoming cheaper, people wanted ways to share files within organizations. The goal was to allow a user to sit down at any workstation and access his or her files even though the files might live on a central server. --Advantages: --convenience (get your files anywhere) --cost (buy workstations without disks) --only sysadmin has to know where files live. shell, user program, etc. do _not_ have to know (way better than competitors at the time) B. How it works --What's the software/hardware structure? [DRAW PICTURE] --array of vnodes in both client and server --vnode like a primitive C++ or Java object, with methods --represents an open (or openable) file --Bunch of generic "vnode operations": --lookup, create, open, close, getattr, setattr, read, write, fsync, remove, link, rename, mkdir, rmdir, symlink, readdir, readlink, ... --Called through function pointers, so most system calls don't care what type of file system a file resides on --We have seen this function-pointer-as-abstraction pattern before with device drivers (more generally, it shows up everywhere). --NFS implements vnode operations through RPC --Client request to server over network, awaits response --Each system call may require a series of RPCs --System mostly determined by NFS RPC **protocol** --How does it work? [TRACE RPC FOR OPEN AND WRITE: LOOKUP AND WRITE] --nice separation between interface and implementation --loopback server --replace NFS server altogether with something that *acts* like an NFS server to the client. --can make lots of things *look* like a file system just by implementing the NFS interface. extremely powerful technique --this gain mostly arises because of the power of RPC and modularity, rather than anything about NFS in particular --What does a file handle look like? [FS ID | inode # | generation #] Why not embed file name in file handle? (file names can change; would mess everything up. client needs to use an identifier that's invariant across such renames.) How does client know what file handle to send? (stored with the vnode) C. Statelessness --What the heck do they mean? The file server keeps files; that's certainly state!! --What they really mean is that every network protocol request contains all of the information needed to carry out that request, without relying on anything remembered from previous protocol requests. --convince yourself of this by looking at the calls --but are operations really idempotent? --what happens if two renames() are sent, and the reply to the first one is lost? client sends another one. then the second one returns an error code, even though the operation conceptually succeeded. --similar issue with "mkdir", "create", etc. --How are READ and WRITE stateless? (Answer: they contain the disk address (the inode at the server) as well as an offset.) --What are the advantages and disadvantages? +: simplifies implementation +: simplifies server failure recovery -: messes up traditional Unix semantics; will discuss below --What happens if the server reboots while the client has a file open? --Nothing! --Client just uses the same file handle. (file handles are usable across server failures.) --NOTE: a crashed and rebooted server looks the same to clients as a slow server. Which is cool. --Why doesn't NFS have RPCs called OPEN() and CLOSE()? D. Transparency and non-traditional Unix semantics --Note: transparency is not just about preserving the syscall API (which they do). Transparency requires that the system calls *mean* the same things. Otherwise, existing programs may compile and run but experience different behavior. In other words, formerly correct programs may now be incorrect. (This happened with NFS because of its close-to-open consistency.) --what is generation number for? (*) What if client A deletes a file and it (or another client) creates a new one that uses the same i-node? --generation number prevents --Stale FH error --served file systems must support --So not fully transparent More detail: For *all* files that could ever be exposed by NFS, the server stores, in the i-node on disk, a generation number. Every time the server allocates a given i-node, it increments the i-node's generation number. When the server passes a FH to the client (say, in response to a LOOKUP RPC from the client), the server puts the given i-node's _current_ generation number in the FH. How: The way the generation number avoids problems that arise from the special case in (*) is as follows: for each request the client makes of the server, the server checks to see whether the generation number in the client's FH matches the on-disk generation number for the i-node in question. If so, the client has a current FH, and the special case has not arisen. If not, the client's generation number must be older, so we are in the special case, and the client gets a "stale FH" error when it tries to READ() or WRITE(). Why: Without the generation number, the special case in (*) would cause a client to read and write data it had no business reading or writing (since the given i-node now belongs to some other file). --non-traditional Unix semantics (i) we mentioned one example above: error returns on successful operations. now we'll go through some other examples of changed semantics (ii) server failure --previously, open() failed only if file didn't exist --now, if server has failed, open() can fail or apps hang [fundamental trade-off if server is remote] (iii) deletion of open files --What if client A deletes a file that client B has "open"? --Unix: my reads still work (file exists until all clients close() it) --NFS: my reads fail --Why? --To get Unix-like behavior using NFS, server would have to keep track of all kinds of stuff. That state would have to persist across reboots. --But they wanted stateless server --So NFS just does the wrong thing --RPCs fail if another client deletes a file you have open. --(Hack if the *same* client does the delete: the NFS client asks the NFS server to do a rename. that's where stale file handles come from. more on this below.) detour: --Server must flush to disk before returning (why?) --Inode with new block # and new length safe on disk. --Indirect block safe on disk. --So writes have to be synchronous --so why isn't performance bad? caching. not all RPCs actually go to server [see (iv) below] [NFSv3 handles this a bit better. WRITES() go to server but don't necessarily cause disk accesses at server.] --what kind of caching do they have? --Read-caching of data. Why does this help? (re-reading files) --Write-caching of data. Why does this help? (see above) --Caching of file attributes. Why does this help? (ls -l) --Caching of name->fh mappings. Why does this help? (cache prefix like /home/bob) (iv) but once you have a cache, you have to worry about coherence and semantics. what kind of coherence/consistency does it actually give? (Answer: close-to-open) A: write(), then close(), B: open(), read(). B sees A's data. Otherwise, B has an "old" picture because data not sent by A until close(). At a high level, how do they implement it? --writing client forces dirty blocks during a close() --reading client checks with server during open() and asks, "is this data current?" What's wrong with this? (1) what if there's no more space on server? (close fails!!!) (2) "some_proc > out" on one client ; "tail -f out" on another client Why do they give this guarantee instead of a stronger guarantee? (Performance. They are trading off the semantics for performance.) (iv) Other transparency things. --out of space: write() error vs close() error --delete a file when in use. why would you do this? if unlink() on the same client, move to .nfsXXX if unlink() on some other client? (see (iii) above) --chmod -r while file is open() (in Unix, nothing happens. in NFS, future reads fail, since NFS checks permissions on every RPC.) --execute-only implies read, unlike in Unix (in Unix, the operating system draws a distinction between demand-paging in the executable, to execute it, versus returning bytes in a file to a requesting program. a user might have permission to do one, or the other, or both. in NFS, the NFS server cannot care about this distinction because the NFS client needs the data blocks in the file, period. thus, if a file is marked execute-only on the NFS server, the NFS client will still be able to read it if the NFS client really wants (once the NFS client has the data blocks, it has the data blocks). (put differently, under NFS, once a client has the file, it has the file. compare to Unix, where Unix really can execute a file for a user but not let the user read it.) Areas of RPC non-transparency * Partial failure, network failure * Latency * Efficiency/semantics tradeoff * Security. You can rarely deal with it transparently (see below) * Pointers. Write-sharing. Portable object references is hard under RPC * Concurrency (if multiple clients) Solution 1: expose RPC to application Solution 2: work harder on transparent RPC E. Security [cover next time but leaving the notes here for reference] --Only security is via IP address --Another case of non-transparency: --On local system: UNIX enforces read/write protections Can't read my files w/o my password --On NFS: --Server believes whatever UID appears in NFS request --Anyone on the Internet can put whatever they like in the request --Or you (on your workstation) can su to root, then su to me --2nd su requires no password --Then NFS will let you read/write my files --In other words, to steal data, just adopt the uid of the person whose files you're trying to read....or just spoof packets. --So why aren't NFS servers ridiculously vulnerable? --Hard to guess correct file handles. --(Which rules out one class of attacks but not spoofed UIDs) --Observe: the vulnerabilities are fixable --Other file systems do it --Require clients to authenticate themselves cryptographically. --But very hard to reconcile with statelessness. F. Concluding note --None of the above issues prevent NFS from being useful. --People fix their programs to handle new semantics. --Or install firewalls for security. --And get most advantages of transparent client/server. References --"RFC 1094": NFS v2 --"RFC 1813": NFS v3 5. Other distributed file systems (disconnected operation, etc.) --disconnected operation: where have we seen this? (answer: git) --long literature on this (Coda, Bayou, Andrew File System, etc., etc.) [thanks to Robert Morris for some of this content.]