Plan 9 ====== What is the motivation for this work? People dislike overloaded, "beureaucratic" time-sharing systems What are the system's fundamental principles? 1. Resources are named and accessed like files I.e., like Unix you might have a /dev/cd for the cdrom But you have more extreme examples, like /proc, /net, /dump, etc. 2. Resources are accessed through a standard protocol, 9P Basically a network file system protocol. Why is this important? Combined with 1, means you can access all kinds of devices remotely (Try this with NFS on UNIX and you will not get the desired results...) 3. Disjoint hierarchies of services joined into *private* namespaces In other words, my /bin != your /bin. Very different from UNIX. Why? Compare "my office" to "Gates Hall #290": Former's meaning depends on who says it, but simpler & more intuitive How do namespaces work? Three system calls manipulate the namespace: mount, bind, unmount - int mount(int fd, int afd, char *old, int flag, char *aname) attaches file descriptor "speaking" the 9P protocol to namespace Think of descriptor as pipe or socket Mount regular file? Kernel just writes attach message to file afd is socket to authentication process, if you want authentication aname sent to server in attach message so it can have multiple FSes - int bind(char *name, char *old, int flag) Replicates name at old - int unmount(char *name, char *old) name can be NULL, else it specifies one component of union to remove flags: MREPL, MBEFORE, MAFTER, MCREATE When using bind w/o MREPL, creates a union directory What's this? Example: /bin Can you create files in a union directory? Yes, if MCREATE is set on one or more entries Note: Unlike UNIX, can mount over either a directory, or a file. Why? E.g., might want to replace /dev/kbd Can they get rid of the PATH environment variable? How? Paper claims yes, but short answer is almost, by manipulating namespace But some people still want "." in PATH, so they kept it Serial port example: /dev/eia1, /dev/eia1ctl - how do these work? On plan9, eia1 is just for I/O eia1ctl (control device) sets baud rate w. text commands like "b1200". Why? In distributed environment, no worries about byte-order Easy to use/debug stuff from shell scripts - this is actually a big deal! C.f. UNIX /dev/tty00: set baud rate, etc. w. complicated ioctl calls How does /dev/eia1 get into your namespace in the first place? Each kerel device has a letter -- t for the UART (serial port) Access "root" of device with special pathname #t Startup scripts during boot run: bind -a '#t' /dev What is system like to user? Login process - type your name and password to terminal Password is used to authenticate you to file & CPU servers Terminal doesn't really care who you are - you already have console access Just reboot to log in as a different user How does the 8½ windowing system work? Click right mouse button, menu allows you to create a new window 8½ then runs new shell Mounts over /dev/mouse, /dev/bitblt, and /dev/cons with pipes Filters input events, so shell only gets them when window selected Different from X windows--typically graphical apps take over window run in Note: Can run rio recursively inside a window! "The text-editing features of 8½ are strong enough to displace special features such as history in the shell, paging and scrolling, and mail editors." (p. 4) - How does this work? Everything is editable Can edit current line you are typing For history, scroll back, edit old command, highlight, and "send" Note many people configure their prompt as no-op alias Means you can copy and send old command including prompt (easier) Terminal has "hold mode" toggled by ESC key In hold mode, even pressing return does not send input to program Mail program puts terminal in hold mode by default--easy to edit messages What is the cpu command? Opens shell on another machine--Plan9's SSH. How does it work? Runs a shell on a remote machine (authenticates with your password) Attempts to replicate your local namespace on remote machine Binds /dev/mouse, /dev/bitblt, /dev/cons on server to local devices Re-creates your file server mounts (using proxy authentication) What about /bin? Might not want exact same /bin Substitutes binaries for CPU server arch, which might be different Isn't there a limit to how seamless heterogenous hardware can be? What if CPU server has different endianness? That's why almost everything uses text commands Won't cc produce wrong output? There is no cc command. Explicitly specify architecture in command 8a, 8c, 8l - x86 assembler, compiler, linker; object files named .8 ka, kc, kl - sparc assembler, compiler, linker, use ".k" files How does 9P network protocol work? All operations done in terms of "fids" - fid is 32-bit handle fids are chosen by the client First fid is set in attach message, will correspond to root directory Some operations on fids: walk - traverses the namespace, like "cd" for an individual fid clone - creates new fid as copy of current fid open - pins fid to file (performs access check), can then read/write (can no longer walk a fid after opening) read/write - as expected stat - return attributes: type - type of file on server (e.g., 't' for UART device) dev - instance of device on server (for devices w. multiple mount points) path - 8-byte unique id for file ( is unique for server) version - 32-bit number changed every time file modified wstat - set attributes remove - deletes the file clunk - closes a fid; fid becomes invalid Can you have hard links? Protocol doesn't support creating hard links Might also be hard with remove message? Which link would you remove? Can you implement a file cache? How does version field compare to UNIX combo? Incremental copies/backups much easier with UNIX model Kernel architecture channels mount device Process/thread model rfork - control over namespace, environment, memory, fds, rendezvous, process groups for notes, w/o RFPROC, no new process is created just further dissociates from parent Why not just always copy namespace? How would mount/bind commands work? Spawned by shell, and need to modify parent's namespace Why not just cp /bin/date /proc/clone/mem? rendezvous (tag, value) Alef programming language Basic abstractions: process, task, channel Processes - preemtively scheduled, can run concurrently on multiprocessor proc func (1, 2); - invokes func in new process Channels, kind of like pipes, but typed chan int (c); - create channel to transport integer values alloc c; - allocate the channel (not done during declaration) c <-= 2; - send integer 2 on channel i = <-c; - receive an integer from channel Can have asynchronous channels, that don't block chan(int)[100] (c); - specifies buffer size of 100 alt statement (like switch) allows to select a ready channel alt { case <-c0: /* receive & discard input on channel c0 */ break; case r = <-c1: /* receive from c1 if input */ break; case c2 <-= 1: /* send 1 on c2 if there is a receiver */ break; } selects at random if multiple outcomes possible unfortunately, no equivalent of switch "default:" Tasks are non-preemptive threads within a process task func (1, 2); - creates a task Other aspects of Aleph similar to C but had other differences, for example in structure declarations Probably had a bunch of "fixes" Phil Winterbottom wanted for C Alef required own headers, libraries "...although Alef was a fruitful language, it proved too difficult to maintain a variant language across multiple architectures, so we took what we learned from it and built the thread library for C." - Pike What does exportfs do? Implements 9P protocol in terms of the open/close/read/write/etc. syscalls Is this straight-forward? Ensuring unique type,dev,path is annoying What is file server architecture Have memory, hard disks, and WORM drive - multi-layer architecture View WORM drive as infinite Assume hardware will improve faster than group generates data How do you set up a TCP connection? Open /net/tcp/clone Directory /net/tcp/1 springs into existence File descriptor returned by open is /net/tcp/1/ctl Reading /net/tcp/1/ctl returns "1", so you know what fd you have Write "connect 135.104.9.52!23" to ctl device Blocks until connect succeeds (or fails) Open /net/tcp/1/data to exchange data with server Would you have to re-write Plan9 applications to port to IPv6? No, because network details abstracted by dial library function int dial(char *addr, char *local, char *dir, int *cfdp); addr = [network!]netaddr[!service] (e.g., "tcp!hostname!echo") network = tcp/udp, etc., or "net" just tries all networks netaddr can be symbolic hostname local = can be NULL (or local address to bind) dir = result argument, if non-NULL gets, e.g., "/net/tcp/1" cfdp = fd for /net/tcp/1/ctl (hangup (*cfdp) tears down connection) return value is data fd dial uses /net/cs to find what clone to open and string to write How do gateways work? Can just import another hosts /net directory What is IL and why? Why is Plan9 better than an old time-sharing system? Couldn't you have multiple machines people can log into for less overload? Use NSF to give a single-system image on a bunch of old-school UNIX machines? Point is users have control of their terminals Can construct your own namespace even on CPU servers On UNIX, can be a pain to install software if you don't have root In Plan9 there isn't even really a notion of root What has been the impact of plan 9? /proc file system now standard UTF-8 now standard What do we wish had been the impact of plan 9? power + simplicity of 9P vs. NFS4? Why isn't everyone using Plan 9 today instead of Linux? Plan 9 was certainly ready in time Licensing issues prevented redistribution Maybe would-be early adopters didn't like centralized storage model Administrative issues Plan 9 addresses might not matter to basement hackers Not fundamental to Plan 9, but large installation was focus of Plan 9 group Building from the ground up made for a different user experience Goal of Linux was to replicate experience people already had E.g., people might want emacs, not sam / acme Software portability issues Had POSIX environment, but still easier to build UNIX software on Linux Maybe focus was too much on large installation Developed in very social "UNIX room" Wanted to recreate community feeling dating back to Multics But, for example, most users probably don't have WORM drives So at least some appealing features not generally available