9.ms 83 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329
  1. .TL
  2. Plan 9 from Bell Labs
  3. .AU
  4. Rob Pike
  5. Dave Presotto
  6. Sean Dorward
  7. Bob Flandrena
  8. Ken Thompson
  9. Howard Trickey
  10. Phil Winterbottom
  11. .AI
  12. .MH
  13. USA
  14. .SH
  15. Motivation
  16. .PP
  17. .FS
  18. Appeared in a slightly different form in
  19. .I
  20. Computing Systems,
  21. .R
  22. Vol 8 #3, Summer 1995, pp. 221-254.
  23. .FE
  24. By the mid 1980's, the trend in computing was
  25. away from large centralized time-shared computers towards
  26. networks of smaller, personal machines,
  27. typically UNIX `workstations'.
  28. People had grown weary of overloaded, bureaucratic timesharing machines
  29. and were eager to move to small, self-maintained systems, even if that
  30. meant a net loss in computing power.
  31. As microcomputers became faster, even that loss was recovered, and
  32. this style of computing remains popular today.
  33. .PP
  34. In the rush to personal workstations, though, some of their weaknesses
  35. were overlooked.
  36. First, the operating system they run, UNIX, is itself an old timesharing system and
  37. has had trouble adapting to ideas
  38. born after it. Graphics and networking were added to UNIX well into
  39. its lifetime and remain poorly integrated and difficult to administer.
  40. More important, the early focus on having private machines
  41. made it difficult for networks of machines to serve as seamlessly as the old
  42. monolithic timesharing systems.
  43. Timesharing centralized the management
  44. and amortization of costs and resources;
  45. personal computing fractured, democratized, and ultimately amplified
  46. administrative problems.
  47. The choice of
  48. an old timesharing operating system to run those personal machines
  49. made it difficult to bind things together smoothly.
  50. .PP
  51. Plan 9 began in the late 1980's as an attempt to have it both
  52. ways: to build a system that was centrally administered and cost-effective
  53. using cheap modern microcomputers as its computing elements.
  54. The idea was to build a time-sharing system out of workstations, but in a novel way.
  55. Different computers would handle
  56. different tasks: small, cheap machines in people's offices would serve
  57. as terminals providing access to large, central, shared resources such as computing
  58. servers and file servers. For the central machines, the coming wave of
  59. shared-memory multiprocessors seemed obvious candidates.
  60. The philosophy is much like that of the Cambridge
  61. Distributed System [NeHe82].
  62. The early catch phrase was to build a UNIX out of a lot of little systems,
  63. not a system out of a lot of little UNIXes.
  64. .PP
  65. The problems with UNIX were too deep to fix, but some of its ideas could be
  66. brought along. The best was its use of the file system to coordinate
  67. naming of and access to resources, even those, such as devices, not traditionally
  68. treated as files.
  69. For Plan 9, we adopted this idea by designing a network-level protocol, called 9P,
  70. to enable machines to access files on remote systems.
  71. Above this, we built a naming
  72. system that lets people and their computing agents build customized views
  73. of the resources in the network.
  74. This is where Plan 9 first began to look different:
  75. a Plan 9 user builds a private computing environment and recreates it wherever
  76. desired, rather than doing all computing on a private machine.
  77. It soon became clear that this model was richer
  78. than we had foreseen, and the ideas of per-process name spaces
  79. and file-system-like resources were extended throughout
  80. the system\(emto processes, graphics, even the network itself.
  81. .PP
  82. By 1989 the system had become solid enough
  83. that some of us began using it as our exclusive computing environment.
  84. This meant bringing along many of the services and applications we had
  85. used on UNIX. We used this opportunity to revisit many issues, not just
  86. kernel-resident ones, that we felt UNIX addressed badly.
  87. Plan 9 has new compilers,
  88. languages,
  89. libraries,
  90. window systems,
  91. and many new applications.
  92. Many of the old tools were dropped, while those brought along have
  93. been polished or rewritten.
  94. .PP
  95. Why be so all-encompassing?
  96. The distinction between operating system, library, and application
  97. is important to the operating system researcher but uninteresting to the
  98. user. What matters is clean functionality.
  99. By building a complete new system,
  100. we were able to solve problems where we thought they should be solved.
  101. For example, there is no real `tty driver' in the kernel; that is the job of the window
  102. system.
  103. In the modern world, multi-vendor and multi-architecture computing
  104. are essential, yet the usual compilers and tools assume the program is being
  105. built to run locally; we needed to rethink these issues.
  106. Most important, though, the test of a system is the computing
  107. environment it provides.
  108. Producing a more efficient way to run the old UNIX warhorses
  109. is empty engineering;
  110. we were more interested in whether the new ideas suggested by
  111. the architecture of the underlying system encourage a more effective way of working.
  112. Thus, although Plan 9 provides an emulation environment for
  113. running POSIX commands, it is a backwater of the system.
  114. The vast majority
  115. of system software is developed in the `native' Plan 9 environment.
  116. .PP
  117. There are benefits to having an all-new system.
  118. First, our laboratory has a history of building experimental peripheral boards.
  119. To make it easy to write device drivers,
  120. we want a system that is available in source form
  121. (no longer guaranteed with UNIX, even
  122. in the laboratory in which it was born).
  123. Also, we want to redistribute our work, which means the software
  124. must be locally produced. For example, we could have used some vendors'
  125. C compilers for our system, but even had we overcome the problems with
  126. cross-compilation, we would have difficulty
  127. redistributing the result.
  128. .PP
  129. This paper serves as an overview of the system. It discusses the architecture
  130. from the lowest building blocks to the computing environment seen by users.
  131. It also serves as an introduction to the rest of the Plan 9 Programmer's Manual,
  132. which it accompanies. More detail about topics in this paper
  133. can be found elsewhere in the manual.
  134. .SH
  135. Design
  136. .PP
  137. The view of the system is built upon three principles.
  138. First, resources are named and accessed like files in a hierarchical file system.
  139. Second, there is a standard protocol, called 9P, for accessing these
  140. resources.
  141. Third, the disjoint hierarchies provided by different services are
  142. joined together into a single private hierarchical file name space.
  143. The unusual properties of Plan 9 stem from the consistent, aggressive
  144. application of these principles.
  145. .PP
  146. A large Plan 9 installation has a number of computers networked
  147. together, each providing a particular class of service.
  148. Shared multiprocessor servers provide computing cycles;
  149. other large machines offer file storage.
  150. These machines are located in an air-conditioned machine
  151. room and are connected by high-performance networks.
  152. Lower bandwidth networks such as Ethernet or ISDN connect these
  153. servers to office- and home-resident workstations or PCs, called terminals
  154. in Plan 9 terminology.
  155. Figure 1 shows the arrangement.
  156. .KF
  157. .PS < network.pic
  158. .IP
  159. .ps -1
  160. .in .25i
  161. .ll -.25i
  162. .ps -1
  163. .vs -1
  164. .I "Figure 1. Structure of a large Plan 9 installation.
  165. CPU servers and file servers share fast local-area networks,
  166. while terminals use slower wider-area networks such as Ethernet,
  167. Datakit, or telephone lines to connect to them.
  168. Gateway machines, which are just CPU servers connected to multiple
  169. networks, allow machines on one network to see another.
  170. .ps +1
  171. .vs +1
  172. .ll +.25i
  173. .in 0
  174. .ps
  175. .sp
  176. .KE
  177. .PP
  178. The modern style of computing offers each user a dedicated workstation or PC.
  179. Plan 9's approach is different.
  180. The various machines with screens, keyboards, and mice all provide
  181. access to the resources of the network, so they are functionally equivalent,
  182. in the manner of the terminals attached to old timesharing systems.
  183. When someone uses the system, though,
  184. the terminal is temporarily personalized by that user.
  185. Instead of customizing the hardware, Plan 9 offers the ability to customize
  186. one's view of the system provided by the software.
  187. That customization is accomplished by giving local, personal names for the
  188. publicly visible resources in the network.
  189. Plan 9 provides the mechanism to assemble a personal view of the public
  190. space with local names for globally accessible resources.
  191. Since the most important resources of the network are files, the model
  192. of that view is file-oriented.
  193. .PP
  194. The client's local name space provides a way to customize the user's
  195. view of the network. The services available in the network all export file
  196. hierarchies.
  197. Those important to the user are gathered together into
  198. a custom name space; those of no immediate interest are ignored.
  199. This is a different style of use from the idea of a `uniform global name space'.
  200. In Plan 9, there are known names for services and uniform names for
  201. files exported by those services,
  202. but the view is entirely local. As an analogy, consider the difference
  203. between the phrase `my house' and the precise address of the speaker's
  204. home. The latter may be used by anyone but the former is easier to say and
  205. makes sense when spoken.
  206. It also changes meaning depending on who says it,
  207. yet that does not cause confusion.
  208. Similarly, in Plan 9 the name
  209. .CW /dev/cons
  210. always refers to the user's terminal and
  211. .CW /bin/date
  212. the correct version of the date
  213. command to run,
  214. but which files those names represent depends on circumstances such as the
  215. architecture of the machine executing
  216. .CW date .
  217. Plan 9, then, has local name spaces that obey globally understood
  218. conventions;
  219. it is the conventions that guarantee sane behavior in the presence
  220. of local names.
  221. .PP
  222. The 9P protocol is structured as a set of transactions that
  223. send a request from a client to a (local or remote) server and return the result.
  224. 9P controls file systems, not just files:
  225. it includes procedures to resolve file names and traverse the name
  226. hierarchy of the file system provided by the server.
  227. On the other hand,
  228. the client's name space is held by the client system alone, not on or with the server,
  229. a distinction from systems such as Sprite [OCDNW88].
  230. Also, file access is at the level of bytes, not blocks, which distinguishes
  231. 9P from protocols like NFS and RFS.
  232. A paper by Welch compares Sprite, NFS, and Plan 9's network file system structures [Welc94].
  233. .PP
  234. This approach was designed with traditional files in mind,
  235. but can be extended
  236. to many other resources.
  237. Plan 9 services that export file hierarchies include I/O devices,
  238. backup services,
  239. the window system,
  240. network interfaces,
  241. and many others.
  242. One example is the process file system,
  243. .CW /proc ,
  244. which provides a clean way
  245. to examine and control running processes.
  246. Precursor systems had a similar idea [Kill84], but Plan 9 pushes the
  247. file metaphor much further [PPTTW93].
  248. The file system model is well-understood, both by system builders and general users,
  249. so services that present file-like interfaces are easy to build, easy to understand,
  250. and easy to use.
  251. Files come with agreed-upon rules for
  252. protection,
  253. naming,
  254. and access both local and remote,
  255. so services built this way are ready-made for a distributed system.
  256. (This is a distinction from `object-oriented' models, where these issues
  257. must be faced anew for every class of object.)
  258. Examples in the sections that follow illustrate these ideas in action.
  259. .SH
  260. The Command-level View
  261. .PP
  262. Plan 9 is meant to be used from a machine with a screen running
  263. the window system.
  264. It has no notion of `teletype' in the UNIX sense. The keyboard handling of
  265. the bare system is rudimentary, but once the window system, 8½ [Pike91],
  266. is running,
  267. text can be edited with `cut and paste' operations from a pop-up menu,
  268. copied between windows, and so on.
  269. 8½ permits editing text from the past, not just on the current input line.
  270. The text-editing capabilities of 8½ are strong enough to displace
  271. special features such as history in the shell,
  272. paging and scrolling,
  273. and mail editors.
  274. 8½ windows do not support cursor addressing and,
  275. except for one terminal emulator to simplify connecting to traditional systems,
  276. there is no cursor-addressing software in Plan 9.
  277. .PP
  278. Each window is created in a separate name space.
  279. Adjustments made to the name space in a window do not affect other windows
  280. or programs, making it safe to experiment with local modifications to the name
  281. space, for example
  282. to substitute files from the dump file system when debugging.
  283. Once the debugging is done, the window can be deleted and all trace of the
  284. experimental apparatus is gone.
  285. Similar arguments apply to the private space each window has for environment
  286. variables, notes (analogous to UNIX signals), etc.
  287. .PP
  288. Each window is created running an application, such as the shell, with
  289. standard input and output connected to the editable text of the window.
  290. Each window also has a private bitmap and multiplexed access to the
  291. keyboard, mouse, and other graphical resources through files like
  292. .CW /dev/mouse ,
  293. .CW /dev/bitblt ,
  294. and
  295. .CW /dev/cons
  296. (analogous to UNIX's
  297. .CW /dev/tty ).
  298. These files are provided by 8½, which is implemented as a file server.
  299. Unlike X windows, where a new application typically creates a new window
  300. to run in, an 8½ graphics application usually runs in the window where it starts.
  301. It is possible and efficient for an application to create a new window, but
  302. that is not the style of the system.
  303. Again contrasting to X, in which a remote application makes a network
  304. call to the X server to start running,
  305. a remote 8½ application sees the
  306. .CW mouse ,
  307. .CW bitblt ,
  308. and
  309. .CW cons
  310. files for the window as usual in
  311. .CW /dev ;
  312. it does not know whether the files are local.
  313. It just reads and writes them to control the window;
  314. the network connection is already there and multiplexed.
  315. .PP
  316. The intended style of use is to run interactive applications such as the window
  317. system and text editor on the terminal and to run computation- or file-intensive
  318. applications on remote servers.
  319. Different windows may be running programs on different machines over
  320. different networks, but by making the name space equivalent in all windows,
  321. this is transparent: the same commands and resources are available, with the same names,
  322. wherever the computation is performed.
  323. .PP
  324. The command set of Plan 9 is similar to that of UNIX.
  325. The commands fall into several broad classes. Some are new programs for
  326. old jobs: programs like
  327. .CW ls ,
  328. .CW cat ,
  329. and
  330. .CW who
  331. have familiar names and functions but are new, simpler implementations.
  332. .CW Who ,
  333. for example, is a shell script, while
  334. .CW ps
  335. is just 95 lines of C code.
  336. Some commands are essentially the same as their UNIX ancestors:
  337. .CW awk ,
  338. .CW troff ,
  339. and others have been converted to ANSI C and extended to handle
  340. Unicode, but are still the familiar tools.
  341. Some are entirely new programs for old niches: the shell
  342. .CW rc ,
  343. text editor
  344. .CW sam ,
  345. debugger
  346. .CW acid ,
  347. and others
  348. displace the better-known UNIX tools with similar jobs.
  349. Finally, about half the commands are new.
  350. .PP
  351. Compatibility was not a requirement for the system.
  352. Where the old commands or notation seemed good enough, we
  353. kept them. When they didn't, we replaced them.
  354. .SH
  355. The File Server
  356. .PP
  357. A central file server stores permanent files and presents them to the network
  358. as a file hierarchy exported using 9P.
  359. The server is a stand-alone system, accessible only over the network,
  360. designed to do its one job well.
  361. It runs no user processes, only a fixed set of routines compiled into the
  362. boot image.
  363. Rather than a set of disks or separate file systems,
  364. the main hierarchy exported by the server is a single
  365. tree, representing files on many disks.
  366. That hierarchy is
  367. shared by many users over a wide area on a variety of networks.
  368. Other file trees exported by
  369. the server include
  370. special-purpose systems such as temporary storage and, as explained
  371. below, a backup service.
  372. .PP
  373. The file server has three levels of storage.
  374. The central server in our installation has
  375. about 100 megabytes of memory buffers,
  376. 27 gigabytes of magnetic disks,
  377. and 350 gigabytes of
  378. bulk storage in a write-once-read-many (WORM) jukebox.
  379. The disk is a cache for the WORM and the memory is a cache for the disk;
  380. each is much faster, and sees about an order of magnitude more traffic,
  381. than the level it caches.
  382. The addressable data in the file system can be larger than the size of the
  383. magnetic disks, because they are only a cache;
  384. our main file server has about 40 gigabytes of active storage.
  385. .PP
  386. The most unusual feature of the file server
  387. comes from its use of a WORM device for
  388. stable storage.
  389. Every morning at 5 o'clock, a
  390. .I dump
  391. of the file system occurs automatically.
  392. The file system is frozen and
  393. all blocks modified since the last dump
  394. are queued to be written to the WORM.
  395. Once the blocks are queued,
  396. service is restored and
  397. the read-only root of the dumped
  398. file system appears in a
  399. hierarchy of all dumps ever taken, named by its date.
  400. For example, the directory
  401. .CW /n/dump/1995/0315
  402. is the root directory of an image of the file system
  403. as it appeared in the early morning of March 15, 1995.
  404. It takes a few minutes to queue the blocks,
  405. but the process to copy blocks to the WORM, which runs in the background, may take hours.
  406. .PP
  407. There are two ways the dump file system is used.
  408. The first is by the users themselves, who can browse the
  409. dump file system directly or attach pieces of
  410. it to their name space.
  411. For example, to track down a bug,
  412. it is straightforward to try the compiler from three months ago
  413. or to link a program with yesterday's library.
  414. With daily snapshots of all files,
  415. it is easy to find when a particular change was
  416. made or what changes were made on a particular date.
  417. People feel free to make large speculative changes
  418. to files in the knowledge that they can be backed
  419. out with a single
  420. copy command.
  421. There is no backup system as such;
  422. instead, because the dump
  423. is in the file name space,
  424. backup problems can be solved with
  425. standard tools
  426. such as
  427. .CW cp ,
  428. .CW ls ,
  429. .CW grep ,
  430. and
  431. .CW diff .
  432. .PP
  433. The other (very rare) use is complete system backup.
  434. In the event of disaster,
  435. the active file system can be initialized from any dump by clearing the
  436. disk cache and setting the root of
  437. the active file system to be a copy
  438. of the dumped root.
  439. Although easy to do, this is not to be taken lightly:
  440. besides losing any change made after the date of the dump, this recovery method
  441. results in a very slow system.
  442. The cache must be reloaded from WORM, which is much
  443. slower than magnetic disks.
  444. The file system takes a few days to reload the working
  445. set and regain its full performance.
  446. .PP
  447. Access permissions of files in the dump are the same
  448. as they were when the dump was made.
  449. Normal utilities have normal
  450. permissions in the dump without any special arrangement.
  451. The dump file system is read-only, though,
  452. which means that files in the dump cannot be written regardless of their permission bits;
  453. in fact, since directories are part of the read-only structure,
  454. even the permissions cannot be changed.
  455. .PP
  456. Once a file is written to WORM, it cannot be removed,
  457. so our users never see
  458. ``please clean up your files''
  459. messages and there is no
  460. .CW df
  461. command.
  462. We regard the WORM jukebox as an unlimited resource.
  463. The only issue is how long it will take to fill.
  464. Our WORM has served a community of about 50 users
  465. for five years and has absorbed daily dumps, consuming a total of
  466. 65% of the storage in the jukebox.
  467. In that time, the manufacturer has improved the technology,
  468. doubling the capacity of the individual disks.
  469. If we were to upgrade to the new media,
  470. we would have more free space than in the original empty jukebox.
  471. Technology has created storage faster than we can use it.
  472. .SH
  473. Unusual file servers
  474. .PP
  475. Plan 9 is characterized by a variety of servers that offer
  476. a file-like interface to unusual services.
  477. Many of these are implemented by user-level processes, although the distinction
  478. is unimportant to their clients; whether a service is provided by the kernel,
  479. a user process, or a remote server is irrelevant to the way it is used.
  480. There are dozens of such servers; in this section we present three representative ones.
  481. .PP
  482. Perhaps the most remarkable file server in Plan 9 is 8½, the window system.
  483. It is discussed at length elsewhere [Pike91], but deserves a brief explanation here.
  484. 8½ provides two interfaces: to the user seated at the terminal, it offers a traditional
  485. style of interaction with multiple windows, each running an application, all controlled
  486. by a mouse and keyboard.
  487. To the client programs, the view is also fairly traditional:
  488. programs running in a window see a set of files in
  489. .CW /dev
  490. with names like
  491. .CW mouse ,
  492. .CW screen ,
  493. and
  494. .CW cons .
  495. Programs that want to print text to their window write to
  496. .CW /dev/cons ;
  497. to read the mouse, they read
  498. .CW /dev/mouse .
  499. In the Plan 9 style, bitmap graphics is implemented by providing a file
  500. .CW /dev/bitblt
  501. on which clients write encoded messages to execute graphical operations such as
  502. .CW bitblt
  503. (RasterOp).
  504. What is unusual is how this is done:
  505. 8½ is a file server, serving the files in
  506. .CW /dev
  507. to the clients running in each window.
  508. Although every window looks the same to its client,
  509. each window has a distinct set of files in
  510. .CW /dev .
  511. 8½ multiplexes its clients' access to the resources of the terminal
  512. by serving multiple sets of files. Each client is given a private name space
  513. with a
  514. .I different
  515. set of files that behave the same as in all other windows.
  516. There are many advantages to this structure.
  517. One is that 8½ serves the same files it needs for its own implementation\(emit
  518. multiplexes its own interface\(emso it may be run, recursively, as a client of itself.
  519. Also, consider the implementation of
  520. .CW /dev/tty
  521. in UNIX, which requires special code in the kernel to redirect
  522. .CW open
  523. calls to the appropriate device.
  524. Instead, in 8½ the equivalent service falls out
  525. automatically: 8½ serves
  526. .CW /dev/cons
  527. as its basic function; there is nothing extra to do.
  528. When a program wants to
  529. read from the keyboard, it opens
  530. .CW /dev/cons ,
  531. but it is a private file, not a shared one with special properties.
  532. Again, local name spaces make this possible; conventions about the consistency of
  533. the files within them make it natural.
  534. .PP
  535. 8½ has a unique feature made possible by its design.
  536. Because it is implemented as a file server,
  537. it has the power to postpone answering read requests for a particular window.
  538. This behavior is toggled by a reserved key on the keyboard.
  539. Toggling once suspends client reads from the window;
  540. toggling again resumes normal reads, which absorb whatever text has been prepared,
  541. one line at a time.
  542. This allows the user to edit multi-line input text on the screen before the application sees it,
  543. obviating the need to invoke a separate editor to prepare text such as mail
  544. messages.
  545. A related property is that reads are answered directly from the
  546. data structure defining the text on the display: text may be edited until
  547. its final newline makes the prepared line of text readable by the client.
  548. Even then, until the line is read, the text the client will read can be changed.
  549. For example, after typing
  550. .P1
  551. % make
  552. rm *
  553. .P2
  554. to the shell, the user can backspace over the final newline at any time until
  555. .CW make
  556. finishes, holding off execution of the
  557. .CW rm
  558. command, or even point with the mouse
  559. before the
  560. .CW rm
  561. and type another command to be executed first.
  562. .PP
  563. There is no
  564. .CW ftp
  565. command in Plan 9. Instead, a user-level file server called
  566. .CW ftpfs
  567. dials the FTP site, logs in on behalf of the user, and uses the FTP protocol
  568. to examine files in the remote directory.
  569. To the local user, it offers a file hierarchy, attached to
  570. .CW /n/ftp
  571. in the local name space, mirroring the contents of the FTP site.
  572. In other words, it translates the FTP protocol into 9P to offer Plan 9 access to FTP sites.
  573. The implementation is tricky;
  574. .CW ftpfs
  575. must do some sophisticated caching for efficiency and
  576. use heuristics to decode remote directory information.
  577. But the result is worthwhile:
  578. all the local file management tools such as
  579. .CW cp ,
  580. .CW grep ,
  581. .CW diff ,
  582. and of course
  583. .CW ls
  584. are available to FTP-served files exactly as if they were local files.
  585. Other systems such as Jade and Prospero
  586. have exploited the same opportunity [Rao81, Neu92],
  587. but because of local name spaces and the simplicity of implementing 9P,
  588. this approach
  589. fits more naturally into Plan 9 than into other environments.
  590. .PP
  591. One server,
  592. .CW exportfs ,
  593. is a user process that takes a portion of its own name space and
  594. makes it available to other processes by
  595. translating 9P requests into system calls to the Plan 9 kernel.
  596. The file hierarchy it exports may contain files from multiple servers.
  597. .CW Exportfs
  598. is usually run as a remote server
  599. started by a local program,
  600. either
  601. .CW import
  602. or
  603. .CW cpu .
  604. .CW Import
  605. makes a network call to the remote machine, starts
  606. .CW exportfs
  607. there, and attaches its 9P connection to the local name space. For example,
  608. .P1
  609. import helix /net
  610. .P2
  611. makes Helix's network interfaces visible in the local
  612. .CW /net
  613. directory. Helix is a central server and
  614. has many network interfaces, so this permits a machine with one network to
  615. access to any of Helix's networks. After such an import, the local
  616. machine may make calls on any of the networks connected to Helix.
  617. Another example is
  618. .P1
  619. import helix /proc
  620. .P2
  621. which makes Helix's processes visible in the local
  622. .CW /proc ,
  623. permitting local debuggers to examine remote processes.
  624. .PP
  625. The
  626. .CW cpu
  627. command connects the local terminal to a remote
  628. CPU server.
  629. It works in the opposite direction to
  630. .CW import :
  631. after calling the server, it starts a
  632. .I local
  633. .CW exportfs
  634. and mounts it in the name space of a process, typically a newly created shell, on the
  635. server.
  636. It then rearranges the name space
  637. to make local device files (such as those served by
  638. the terminal's window system) visible in the server's
  639. .CW /dev
  640. directory.
  641. The effect of running a
  642. .CW cpu
  643. command is therefore to start a shell on a fast machine, one more tightly
  644. coupled to the file server,
  645. with a name space analogous
  646. to the local one.
  647. All local device files are visible remotely, so remote applications have full
  648. access to local services such as bitmap graphics,
  649. .CW /dev/cons ,
  650. and so on.
  651. This is not the same as
  652. .CW rlogin ,
  653. which does nothing to reproduce the local name space on the remote system,
  654. nor is it the same as
  655. file sharing with, say, NFS, which can achieve some name space equivalence but
  656. not the combination of access to local hardware devices, remote files, and remote
  657. CPU resources.
  658. The
  659. .CW cpu
  660. command is a uniquely transparent mechanism.
  661. For example, it is reasonable
  662. to start a window system in a window running a
  663. .CW cpu
  664. command; all windows created there automatically start processes on the CPU server.
  665. .SH
  666. Configurability and administration
  667. .PP
  668. The uniform interconnection of components in Plan 9 makes it possible to configure
  669. a Plan 9 installation many different ways.
  670. A single laptop PC can function as a stand-alone Plan 9 system;
  671. at the other extreme, our setup has central multiprocessor CPU
  672. servers and file servers and scores of terminals ranging from small PCs to
  673. high-end graphics workstations.
  674. It is such large installations that best represent how Plan 9 operates.
  675. .PP
  676. The system software is portable and the same
  677. operating system runs on all hardware.
  678. Except for performance, the appearance of the system on, say,
  679. an SGI workstation is the same
  680. as on a laptop.
  681. Since computing and file services are centralized, and terminals have
  682. no permanent file storage, all terminals are functionally identical.
  683. In this way, Plan 9 has one of the good properties of old timesharing systems, where
  684. a user could sit in front of any machine and see the same system. In the modern
  685. workstation community, machines tend to be owned by people who customize them
  686. by storing private information on local disk.
  687. We reject this style of use,
  688. although the system itself can be used this way.
  689. In our group, we have a laboratory with many public-access machines\(ema terminal
  690. room\(emand a user may sit down at any one of them and work.
  691. .PP
  692. Central file servers centralize not just the files, but also their administration
  693. and maintenance.
  694. In fact, one server is the main server, holding all system files; other servers provide
  695. extra storage or are available for debugging and other special uses, but the system
  696. software resides on one machine.
  697. This means that each program
  698. has a single copy of the binary for each architecture, so it is
  699. trivial to install updates and bug fixes.
  700. There is also a single user database; there is no need to synchronize distinct
  701. .CW /etc/passwd
  702. files.
  703. On the other hand, depending on a single central server does limit the size of an installation.
  704. .PP
  705. Another example of the power of centralized file service
  706. is the way Plan 9 administers network information.
  707. On the central server there is a directory,
  708. .CW /lib/ndb ,
  709. that contains all the information necessary to administer the local Ethernet and
  710. other networks.
  711. All the machines use the same database to talk to the network; there is no
  712. need to manage a distributed naming system or keep parallel files up to date.
  713. To install a new machine on the local Ethernet, choose a
  714. name and IP address and add these to a single file in
  715. .CW /lib/ndb ;
  716. all the machines in the installation will be able to talk to it immediately.
  717. To start running, plug the machine into the network, turn it on, and use BOOTP
  718. and TFTP to load the kernel.
  719. All else is automatic.
  720. .PP
  721. Finally,
  722. the automated dump file system frees all users from the need to maintain
  723. their systems, while providing easy access to backup files without
  724. tapes, special commands, or the involvement of support staff.
  725. It is difficult to overstate the improvement in lifestyle afforded by this service.
  726. .PP
  727. Plan 9 runs on a variety of hardware without
  728. constraining how to configure an installation.
  729. In our laboratory, we
  730. chose to use central servers because they amortize costs and administration.
  731. A sign that this is a good decision is that our cheap
  732. terminals remain comfortable places
  733. to work for about five years, much longer than workstations that must provide
  734. the complete computing environment.
  735. We do, however, upgrade the central machines, so
  736. the computation available from even old Plan 9 terminals improves with time.
  737. The money saved by avoiding regular upgrades of terminals
  738. is instead spent on the newest, fastest multiprocessor servers.
  739. We estimate this costs about half the money of networked workstations
  740. yet provides general access to more powerful machines.
  741. .SH
  742. C Programming
  743. .PP
  744. Plan 9 utilities are written in several languages.
  745. Some are scripts for the shell,
  746. .CW rc
  747. [Duff90]; a handful
  748. are written in a new C-like concurrent language called Alef [Wint95], described below.
  749. The great majority, though, are written in a dialect of ANSI C [ANSIC].
  750. Of these, most are entirely new programs, but some
  751. originate in pre-ANSI C code
  752. from our research UNIX system [UNIX85].
  753. These have been updated to ANSI C
  754. and reworked for portability and cleanliness.
  755. .PP
  756. The Plan 9 C dialect has some minor extensions,
  757. described elsewhere [Pike95], and a few major restrictions.
  758. The most important restriction is that the compiler demands that
  759. all function definitions have ANSI prototypes
  760. and all function calls appear in the scope of a prototyped declaration
  761. of the function.
  762. As a stylistic rule,
  763. the prototyped declaration is placed in a header file
  764. included by all files that call the function.
  765. Each system library has an associated header file, declaring all
  766. functions in that library.
  767. For example, the standard Plan 9 library is called
  768. .CW libc ,
  769. so all C source files include
  770. .CW <libc.h> .
  771. These rules guarantee that all functions
  772. are called with arguments having the expected types \(em something
  773. that was not true with pre-ANSI C programs.
  774. .PP
  775. Another restriction is that the C compilers accept only a subset of the
  776. preprocessor directives required by ANSI.
  777. The main omission is
  778. .CW #if ,
  779. since we believe it
  780. is never necessary and often abused.
  781. Also, its effect is
  782. better achieved by other means.
  783. For instance, an
  784. .CW #if
  785. used to toggle a feature at compile time can be written
  786. as a regular
  787. .CW if
  788. statement, relying on compile-time constant folding and
  789. dead code elimination to discard object code.
  790. .PP
  791. Conditional compilation, even with
  792. .CW #ifdef ,
  793. is used sparingly in Plan 9.
  794. The only architecture-dependent
  795. .CW #ifdefs
  796. in the system are in low-level routines in the graphics library.
  797. Instead, we avoid such dependencies or, when necessary, isolate
  798. them in separate source files or libraries.
  799. Besides making code hard to read,
  800. .CW #ifdefs
  801. make it impossible to know what source is compiled into the binary
  802. or whether source protected by them will compile or work properly.
  803. They make it harder to maintain software.
  804. .PP
  805. The standard Plan 9 library overlaps much of
  806. ANSI C and POSIX [POSIX], but diverges
  807. when appropriate to Plan 9's goals or implementation.
  808. When the semantics of a function
  809. change, we also change the name.
  810. For instance, instead of UNIX's
  811. .CW creat ,
  812. Plan 9 has a
  813. .CW create
  814. function that takes three arguments,
  815. the original two plus a third that, like the second
  816. argument of
  817. .CW open ,
  818. defines whether the returned file descriptor is to be opened for reading,
  819. writing, or both.
  820. This design was forced by the way 9P implements creation,
  821. but it also simplifies the common use of
  822. .CW create
  823. to initialize a temporary file.
  824. .PP
  825. Another departure from ANSI C is that Plan 9 uses a 16-bit character set
  826. called Unicode [ISO10646, Unicode].
  827. Although we stopped short of full internationalization,
  828. Plan 9 treats the representation
  829. of all major languages uniformly throughout all its
  830. software.
  831. To simplify the exchange of text between programs, the characters are packed into
  832. a byte stream by an encoding we designed, called UTF-8,
  833. which is now
  834. becoming accepted as a standard [FSSUTF].
  835. It has several attractive properties,
  836. including byte-order independence,
  837. backwards compatibility with ASCII,
  838. and ease of implementation.
  839. .PP
  840. There are many problems in adapting existing software to a large
  841. character set with an encoding that represents characters with
  842. a variable number of bytes.
  843. ANSI C addresses some of the issues but
  844. falls short of
  845. solving them all.
  846. It does not pick a character set encoding and does not
  847. define all the necessary I/O library routines.
  848. Furthermore, the functions it
  849. .I does
  850. define have engineering problems.
  851. Since the standard left too many problems unsolved,
  852. we decided to build our own interface.
  853. A separate paper has the details [Pike93].
  854. .PP
  855. A small class of Plan 9 programs do not follow the conventions
  856. discussed in this section.
  857. These are programs imported from and maintained by
  858. the UNIX community;
  859. .CW tex
  860. is a representative example.
  861. To avoid reconverting such programs every time a new version
  862. is released,
  863. we built a porting environment, called the ANSI C/POSIX Environment, or APE [Tric95].
  864. APE comprises separate include files, libraries, and commands,
  865. conforming as much as possible to the strict ANSI C and base-level
  866. POSIX specifications.
  867. To port network-based software such as X Windows, it was necessary to add
  868. some extensions to those
  869. specifications, such as the BSD networking functions.
  870. .SH
  871. Portability and Compilation
  872. .PP
  873. Plan 9 is portable across a variety of processor architectures.
  874. Within a single computing session, it is common to use
  875. several architectures: perhaps the window system running on
  876. an Intel processor connected to a MIPS-based CPU server with files
  877. resident on a SPARC system.
  878. For this heterogeneity to be transparent, there must be conventions
  879. about data interchange between programs; for software maintenance
  880. to be straightforward, there must be conventions about cross-architecture
  881. compilation.
  882. .PP
  883. To avoid byte order problems,
  884. data is communicated between programs as text whenever practical.
  885. Sometimes, though, the amount of data is high enough that a binary
  886. format is necessary;
  887. such data is communicated as a byte stream with a pre-defined encoding
  888. for multi-byte values.
  889. In the rare cases where a format
  890. is complex enough to be defined by a data structure,
  891. the structure is never
  892. communicated as a unit; instead, it is decomposed into
  893. individual fields, encoded as an ordered byte stream, and then
  894. reassembled by the recipient.
  895. These conventions affect data
  896. ranging from kernel or application program state information to object file
  897. intermediates generated by the compiler.
  898. .PP
  899. Programs, including the kernel, often present their data
  900. through a file system interface,
  901. an access mechanism that is inherently portable.
  902. For example, the system clock is represented by a decimal number in the file
  903. .CW /dev/time ;
  904. the
  905. .CW time
  906. library function (there is no
  907. .CW time
  908. system call) reads the file and converts it to binary.
  909. Similarly, instead of encoding the state of an application
  910. process in a series of flags and bits in private memory,
  911. the kernel
  912. presents a text string in the file named
  913. .CW status
  914. in the
  915. .CW /proc
  916. file system associated with each process.
  917. The Plan 9
  918. .CW ps
  919. command is trivial: it prints the contents of
  920. the desired status files after some minor reformatting; moreover, after
  921. .P1
  922. import helix /proc
  923. .P2
  924. a local
  925. .CW ps
  926. command reports on the status of Helix's processes.
  927. .PP
  928. Each supported architecture has its own compilers and loader.
  929. The C and Alef compilers produce intermediate files that
  930. are portably encoded; the contents
  931. are unique to the target architecture but the format of the
  932. file is independent of compiling processor type.
  933. When a compiler for a given architecture is compiled on
  934. another type of processor and then used to compile a program
  935. there,
  936. the intermediate produced on
  937. the new architecture is identical to the intermediate
  938. produced on the native processor. From the compiler's
  939. point of view, every compilation is a cross-compilation.
  940. .PP
  941. Although each architecture's loader accepts only intermediate files produced
  942. by compilers for that architecture,
  943. such files could have been generated by a compiler executing
  944. on any type of processor.
  945. For instance, it is possible to run
  946. the MIPS compiler on a 486, then use the MIPS loader on a
  947. SPARC to produce a MIPS executable.
  948. .PP
  949. Since Plan 9 runs on a variety of architectures, even in a single installation,
  950. distinguishing the compilers and intermediate names
  951. simplifies multi-architecture
  952. development from a single source tree.
  953. The compilers and the loader for each architecture are
  954. uniquely named; there is no
  955. .CW cc
  956. command.
  957. The names are derived by concatenating a code letter
  958. associated with the target architecture with the name of the
  959. compiler or loader. For example, the letter `8' is
  960. the code letter for Intel
  961. .I x 86
  962. processors; the C compiler is named
  963. .CW 8c ,
  964. the Alef compiler
  965. .CW 8al ,
  966. and the loader is called
  967. .CW 8l .
  968. Similarly, the compiler intermediate files are suffixed
  969. .CW .8 ,
  970. not
  971. .CW .o .
  972. .PP
  973. The Plan 9
  974. build program
  975. .CW mk ,
  976. a relative of
  977. .CW make ,
  978. reads the names of the current and target
  979. architectures from environment variables called
  980. .CW $cputype
  981. and
  982. .CW $objtype .
  983. By default the current processor is the target, but setting
  984. .CW $objtype
  985. to the name of another architecture
  986. before invoking
  987. .CW mk
  988. results in a cross-build:
  989. .P1
  990. % objtype=sparc mk
  991. .P2
  992. builds a program for the SPARC architecture regardless of the executing machine.
  993. The value of
  994. .CW $objtype
  995. selects a
  996. file of architecture-dependent variable definitions
  997. that configures the build to use the appropriate compilers and loader.
  998. Although simple-minded, this technique works well in practice:
  999. all applications in Plan 9 are built from a single source tree
  1000. and it is possible to build the various architectures in parallel without conflict.
  1001. .SH
  1002. Parallel programming
  1003. .PP
  1004. Plan 9's support for parallel programming has two aspects.
  1005. First, the kernel provides
  1006. a simple process model and a few carefully designed system calls for
  1007. synchronization and sharing.
  1008. Second, a new parallel programming language called Alef
  1009. supports concurrent programming.
  1010. Although it is possible to write parallel
  1011. programs in C, Alef is the parallel language of choice.
  1012. .PP
  1013. There is a trend in new operating systems to implement two
  1014. classes of processes: normal UNIX-style processes and light-weight
  1015. kernel threads.
  1016. Instead, Plan 9 provides a single class of process but allows fine control of the
  1017. sharing of a process's resources such as memory and file descriptors.
  1018. A single class of process is a
  1019. feasible approach in Plan 9 because the kernel has an efficient system
  1020. call interface and cheap process creation and scheduling.
  1021. .PP
  1022. Parallel programs have three basic requirements:
  1023. management of resources shared between processes,
  1024. an interface to the scheduler,
  1025. and fine-grain process synchronization using spin locks.
  1026. On Plan 9,
  1027. new processes are created using the
  1028. .CW rfork
  1029. system call.
  1030. .CW Rfork
  1031. takes a single argument,
  1032. a bit vector that specifies
  1033. which of the parent process's resources should be shared,
  1034. copied, or created anew
  1035. in the child.
  1036. The resources controlled by
  1037. .CW rfork
  1038. include the name space,
  1039. the environment,
  1040. the file descriptor table,
  1041. memory segments,
  1042. and notes (Plan 9's analog of UNIX signals).
  1043. One of the bits controls whether the
  1044. .CW rfork
  1045. call will create a new process; if the bit is off, the resulting
  1046. modification to the resources occurs in the process making the call.
  1047. For example, a process calls
  1048. .CW rfork(RFNAMEG)
  1049. to disconnect its name space from its parent's.
  1050. Alef uses a
  1051. fine-grained fork in which all the resources, including
  1052. memory, are shared between parent
  1053. and child, analogous to creating a kernel thread in many systems.
  1054. .PP
  1055. An indication that
  1056. .CW rfork
  1057. is the right model is the variety of ways it is used.
  1058. Other than the canonical use in the library routine
  1059. .CW fork ,
  1060. it is hard to find two calls to
  1061. .CW rfork
  1062. with the same bits set; programs
  1063. use it to create many different forms of sharing and resource allocation.
  1064. A system with just two types of processes\(emregular processes and threads\(emcould
  1065. not handle this variety.
  1066. .PP
  1067. There are two ways to share memory.
  1068. First, a flag to
  1069. .CW rfork
  1070. causes all the memory segments of the parent to be shared with the child
  1071. (except the stack, which is
  1072. forked copy-on-write regardless).
  1073. Alternatively, a new segment of memory may be
  1074. attached using the
  1075. .CW segattach
  1076. system call; such a segment
  1077. will always be shared between parent and child.
  1078. .PP
  1079. The
  1080. .CW rendezvous
  1081. system call provides a way for processes to synchronize.
  1082. Alef uses it to implement communication channels,
  1083. queuing locks,
  1084. multiple reader/writer locks, and
  1085. the sleep and wakeup mechanism.
  1086. .CW Rendezvous
  1087. takes two arguments, a tag and a value.
  1088. When a process calls
  1089. .CW rendezvous
  1090. with a tag it sleeps until another process
  1091. presents a matching tag.
  1092. When a pair of tags match, the values are exchanged
  1093. between the two processes and both
  1094. .CW rendezvous
  1095. calls return.
  1096. This primitive is sufficient to implement the full set of synchronization routines.
  1097. .PP
  1098. Finally, spin locks are provided by
  1099. an architecture-dependent library at user level.
  1100. Most processors provide atomic test and set instructions that
  1101. can be used to implement locks.
  1102. A notable exception is the MIPS R3000, so the SGI
  1103. Power series multiprocessors have special lock hardware on the bus.
  1104. User processes gain access to the lock hardware
  1105. by mapping pages of hardware locks
  1106. into their address space using the
  1107. .CW segattach
  1108. system call.
  1109. .PP
  1110. A Plan 9 process in a system call will block regardless of its `weight'.
  1111. This means that when a program wishes to read from a slow
  1112. device without blocking the entire calculation, it must fork a process to do
  1113. the read for it. The solution is to start a satellite
  1114. process that does the I/O and delivers the answer to the main program
  1115. through shared memory or perhaps a pipe.
  1116. This sounds onerous but works easily and efficiently in practice; in fact,
  1117. most interactive Plan 9 applications, even relatively ordinary ones written
  1118. in C, such as
  1119. the text editor Sam [Pike87], run as multiprocess programs.
  1120. .PP
  1121. The kernel support for parallel programming in Plan 9 is a few hundred lines
  1122. of portable code; a handful of simple primitives enable the problems to be handled
  1123. cleanly at user level.
  1124. Although the primitives work fine from C,
  1125. they are particularly expressive from within Alef.
  1126. The creation
  1127. and management of slave I/O processes can be written in a few lines of Alef,
  1128. providing the foundation for a consistent means of multiplexing
  1129. data flows between arbitrary processes.
  1130. Moreover, implementing it in a language rather than in the kernel
  1131. ensures consistent semantics between all devices
  1132. and provides a more general multiplexing primitive.
  1133. Compare this to the UNIX
  1134. .CW select
  1135. system call:
  1136. .CW select
  1137. applies only to a restricted set of devices,
  1138. legislates a style of multiprogramming in the kernel,
  1139. does not extend across networks,
  1140. is difficult to implement, and is hard to use.
  1141. .PP
  1142. Another reason
  1143. parallel programming is important in Plan 9 is that
  1144. multi-threaded user-level file servers are the preferred way
  1145. to implement services.
  1146. Examples of such servers include the programming environment
  1147. Acme [Pike94],
  1148. the name space exporting tool
  1149. .CW exportfs
  1150. [PPTTW93],
  1151. the HTTP daemon,
  1152. and the network name servers
  1153. .CW cs
  1154. and
  1155. .CW dns
  1156. [PrWi93].
  1157. Complex applications such as Acme prove that
  1158. careful operating system support can reduce the difficulty of writing
  1159. multi-threaded applications without moving threading and
  1160. synchronization primitives into the kernel.
  1161. .SH
  1162. Implementation of Name Spaces
  1163. .PP
  1164. User processes construct name spaces using three system calls:
  1165. .CW mount ,
  1166. .CW bind ,
  1167. and
  1168. .CW unmount .
  1169. The
  1170. .CW mount
  1171. system call attaches a tree served by a file server to
  1172. the current name space. Before calling
  1173. .CW mount ,
  1174. the client must (by outside means) acquire a connection to the server in
  1175. the form of a file descriptor that may be written and read to transmit 9P messages.
  1176. That file descriptor represents a pipe or network connection.
  1177. .PP
  1178. The
  1179. .CW mount
  1180. call attaches a new hierarchy to the existing name space.
  1181. The
  1182. .CW bind
  1183. system call, on the other hand, duplicates some piece of existing name space at
  1184. another point in the name space.
  1185. The
  1186. .CW unmount
  1187. system call allows components to be removed.
  1188. .PP
  1189. Using
  1190. either
  1191. .CW bind
  1192. or
  1193. .CW mount ,
  1194. multiple directories may be stacked at a single point in the name space.
  1195. In Plan 9 terminology, this is a
  1196. .I union
  1197. directory and behaves like the concatenation of the constituent directories.
  1198. A flag argument to
  1199. .CW bind
  1200. and
  1201. .CW mount
  1202. specifies the position of a new directory in the union,
  1203. permitting new elements
  1204. to be added either at the front or rear of the union or to replace it entirely.
  1205. When a file lookup is performed in a union directory, each component
  1206. of the union is searched in turn and the first match taken; likewise,
  1207. when a union directory is read, the contents of each of the component directories
  1208. is read in turn.
  1209. Union directories are one of the most widely used organizational features
  1210. of the Plan 9 name space.
  1211. For instance, the directory
  1212. .CW /bin
  1213. is built as a union of
  1214. .CW /$cputype/bin
  1215. (program binaries),
  1216. .CW /rc/bin
  1217. (shell scripts),
  1218. and perhaps more directories provided by the user.
  1219. This construction makes the shell
  1220. .CW $PATH
  1221. variable unnecessary.
  1222. .PP
  1223. One question raised by union directories
  1224. is which element of the union receives a newly created file.
  1225. After several designs, we decided on the following.
  1226. By default, directories in unions do not accept new files, although the
  1227. .CW create
  1228. system call applied to an existing file succeeds normally.
  1229. When a directory is added to the union, a flag to
  1230. .CW bind
  1231. or
  1232. .CW mount
  1233. enables create permission (a property of the name space) in that directory.
  1234. When a file is being created with a new name in a union, it is created in the
  1235. first directory of the union with create permission; if that creation fails,
  1236. the entire
  1237. .CW create
  1238. fails.
  1239. This scheme enables the common use of placing a private directory anywhere
  1240. in a union of public ones,
  1241. while allowing creation only in the private directory.
  1242. .PP
  1243. By convention, kernel device file systems
  1244. are bound into the
  1245. .CW /dev
  1246. directory, but to bootstrap the name space building process it is
  1247. necessary to have a notation that permits
  1248. direct access to the devices without an existing name space.
  1249. The root directory
  1250. of the tree served by a device driver can be accessed using the syntax
  1251. .CW # \f2c\f1,
  1252. where
  1253. .I c
  1254. is a unique character (typically a letter) identifying the
  1255. .I type
  1256. of the device.
  1257. Simple device drivers serve a single level directory containing a few files.
  1258. As an example,
  1259. each serial port is represented by a data and a control file:
  1260. .P1
  1261. % bind -a '#t' /dev
  1262. % cd /dev
  1263. % ls -l eia*
  1264. --rw-rw-rw- t 0 bootes bootes 0 Feb 24 21:14 eia1
  1265. --rw-rw-rw- t 0 bootes bootes 0 Feb 24 21:14 eia1ctl
  1266. --rw-rw-rw- t 0 bootes bootes 0 Feb 24 21:14 eia2
  1267. --rw-rw-rw- t 0 bootes bootes 0 Feb 24 21:14 eia2ctl
  1268. .P2
  1269. The
  1270. .CW bind
  1271. program is an encapsulation of the
  1272. .CW bind
  1273. system call; its
  1274. .CW -a
  1275. flag positions the new directory at the end of the union.
  1276. The data files
  1277. .CW eia1
  1278. and
  1279. .CW eia2
  1280. may be read and written to communicate over the serial line.
  1281. Instead of using special operations on these files to control the devices,
  1282. commands written to the files
  1283. .CW eia1ctl
  1284. and
  1285. .CW eia2ctl
  1286. control the corresponding device;
  1287. for example,
  1288. writing the text string
  1289. .CW b1200
  1290. to
  1291. .CW /dev/eia1ctl
  1292. sets the speed of that line to 1200 baud.
  1293. Compare this to the UNIX
  1294. .CW ioctl
  1295. system call: in Plan 9, devices are controlled by textual messages,
  1296. free of byte order problems, with clear semantics for reading and writing.
  1297. It is common to configure or debug devices using shell scripts.
  1298. .PP
  1299. It is the universal use of the 9P protocol that
  1300. connects Plan 9's components together to form a
  1301. distributed system.
  1302. Rather than inventing a unique protocol for each
  1303. service such as
  1304. .CW rlogin ,
  1305. FTP, TFTP, and X windows,
  1306. Plan 9 implements services
  1307. in terms of operations on file objects,
  1308. and then uses a single, well-documented protocol to exchange information between
  1309. computers.
  1310. Unlike NFS, 9P treats files as a sequence of bytes rather than blocks.
  1311. Also unlike NFS, 9P is stateful: clients perform
  1312. remote procedure calls to establish pointers to objects in the remote
  1313. file server.
  1314. These pointers are called file identifiers or
  1315. .I fids .
  1316. All operations on files supply a fid to identify an object in the remote file system.
  1317. .PP
  1318. The 9P protocol defines 17 messages, providing
  1319. means to authenticate users, navigate fids around
  1320. a file system hierarchy, copy fids, perform I/O, change file attributes,
  1321. and create and delete files.
  1322. Its complete specification is in Section 5 of the Programmer's Manual [9man].
  1323. Here is the procedure to gain access to the name hierarchy supplied by a server.
  1324. A file server connection is established via a pipe or network connection.
  1325. An initial
  1326. .CW session
  1327. message performs a bilateral authentication between client and server.
  1328. An
  1329. .CW attach
  1330. message then connects a fid suggested by the client to the root of the server file
  1331. tree.
  1332. The
  1333. .CW attach
  1334. message includes the identity of the user performing the attach; henceforth all
  1335. fids derived from the root fid will have permissions associated with
  1336. that user.
  1337. Multiple users may share the connection, but each must perform an attach to
  1338. establish his or her identity.
  1339. .PP
  1340. The
  1341. .CW walk
  1342. message moves a fid through a single level of the file system hierarchy.
  1343. The
  1344. .CW clone
  1345. message takes an established fid and produces a copy that points
  1346. to the same file as the original.
  1347. Its purpose is to enable walking to a file in a directory without losing the fid
  1348. on the directory.
  1349. The
  1350. .CW open
  1351. message locks a fid to a specific file in the hierarchy,
  1352. checks access permissions,
  1353. and prepares the fid
  1354. for I/O.
  1355. The
  1356. .CW read
  1357. and
  1358. .CW write
  1359. messages allow I/O at arbitrary offsets in the file;
  1360. the maximum size transferred is defined by the protocol.
  1361. The
  1362. .CW clunk
  1363. message indicates the client has no further use for a fid.
  1364. The
  1365. .CW remove
  1366. message behaves like
  1367. .CW clunk
  1368. but causes the file associated with the fid to be removed and any associated
  1369. resources on the server to be deallocated.
  1370. .PP
  1371. 9P has two forms: RPC messages sent on a pipe or network connection and a procedural
  1372. interface within the kernel.
  1373. Since kernel device drivers are directly addressable,
  1374. there is no need to pass messages to
  1375. communicate with them;
  1376. instead each 9P transaction is implemented by a direct procedure call.
  1377. For each fid,
  1378. the kernel maintains a local representation in a data structure called a
  1379. .I channel ,
  1380. so all operations on files performed by the kernel involve a channel connected
  1381. to that fid.
  1382. The simplest example is a user process's file descriptors, which are
  1383. indexes into an array of channels.
  1384. A table in the kernel provides a list
  1385. of entry points corresponding one to one with the 9P messages for each device.
  1386. A system call such as
  1387. .CW read
  1388. from the user translates into one or more procedure calls
  1389. through that table, indexed by the type character stored in the channel:
  1390. .CW procread ,
  1391. .CW eiaread ,
  1392. etc.
  1393. Each call takes at least
  1394. one channel as an argument.
  1395. A special kernel driver, called the
  1396. .I mount
  1397. driver, translates procedure calls to messages, that is,
  1398. it converts local procedure calls to remote ones.
  1399. In effect, this special driver
  1400. becomes a local proxy for the files served by a remote file server.
  1401. The channel pointer in the local call is translated to the associated fid
  1402. in the transmitted message.
  1403. .PP
  1404. The mount driver is the sole RPC mechanism employed by the system.
  1405. The semantics of the supplied files, rather than the operations performed upon
  1406. them, create a particular service such as the
  1407. .CW cpu
  1408. command.
  1409. The mount driver demultiplexes protocol
  1410. messages between clients sharing a communication channel
  1411. with a file server.
  1412. For each outgoing RPC message,
  1413. the mount driver allocates a buffer labeled by a small unique integer,
  1414. called a
  1415. .I tag .
  1416. The reply to the RPC is labeled with the same tag, which is used by
  1417. the mount driver to match the reply with the request.
  1418. .PP
  1419. The kernel representation of the name space
  1420. is called the
  1421. .I "mount table" ,
  1422. which stores a list of bindings between channels.
  1423. Each entry in the mount table contains a pair of channels: a
  1424. .I from
  1425. channel and a
  1426. .I to
  1427. channel.
  1428. Every time a walk succeeds in moving a channel to a new location in the name space,
  1429. the mount table is consulted to see if a `from' channel matches the new name; if
  1430. so the `to' channel is cloned and substituted for the original.
  1431. Union directories are implemented by converting the `to'
  1432. channel into a list of channels:
  1433. a successful walk to a union directory returns a `to' channel that forms
  1434. the head of
  1435. a list of channels, each representing a component directory
  1436. of the union.
  1437. If a walk
  1438. fails to find a file in the first directory of the union, the list is followed,
  1439. the next component cloned, and walk tried on that directory.
  1440. .PP
  1441. Each file in Plan 9 is uniquely identified by a set of integers:
  1442. the type of the channel (used as the index of the function call table),
  1443. the server or device number
  1444. distinguishing the server from others of the same type (decided locally by the driver),
  1445. and a
  1446. .I qid
  1447. formed from two 32-bit numbers called
  1448. .I path
  1449. and
  1450. .I version .
  1451. The path is a unique file number assigned by a device driver or
  1452. file server when a file is created.
  1453. The version number is updated whenever
  1454. the file is modified; as described in the next section,
  1455. it can be used to maintain cache coherency between
  1456. clients and servers.
  1457. .PP
  1458. The type and device number are analogous to UNIX major and minor
  1459. device numbers;
  1460. the qid is analogous to the i-number.
  1461. The device and type
  1462. connect the channel to a device driver and the qid
  1463. identifies the file within that device.
  1464. If the file recovered from a walk has the same type, device, and qid path
  1465. as an entry in the mount table, they are the same file and the
  1466. corresponding substitution from the mount table is made.
  1467. This is how the name space is implemented.
  1468. .SH
  1469. File Caching
  1470. .PP
  1471. The 9P protocol has no explicit support for caching files on a client.
  1472. The large memory of the central file server acts as a shared cache for all its clients,
  1473. which reduces the total amount of memory needed across all machines in the network.
  1474. Nonetheless, there are sound reasons to cache files on the client, such as a slow
  1475. connection to the file server.
  1476. .PP
  1477. The version field of the qid is changed whenever the file is modified,
  1478. which makes it possible to do some weakly coherent forms of caching.
  1479. The most important is client caching of text and data segments of executable files.
  1480. When a process
  1481. .CW execs
  1482. a program, the file is re-opened and the qid's version is compared with that in the cache;
  1483. if they match, the local copy is used.
  1484. The same method can be used to build a local caching file server.
  1485. This user-level server interposes on the 9P connection to the remote server and
  1486. monitors the traffic, copying data to a local disk.
  1487. When it sees a read of known data, it answers directly,
  1488. while writes are passed on immediately\(emthe cache is write-through\(emto keep
  1489. the central copy up to date.
  1490. This is transparent to processes on the terminal and requires no change to 9P;
  1491. it works well on home machines connected over serial lines.
  1492. A similar method can be applied to build a general client cache in unused local
  1493. memory, but this has not been done in Plan 9.
  1494. .SH
  1495. Networks and Communication Devices
  1496. .PP
  1497. Network interfaces are kernel-resident file systems, analogous to the EIA device
  1498. described earlier.
  1499. Call setup and shutdown are achieved by writing text strings to the control file
  1500. associated with the device;
  1501. information is sent and received by reading and writing the data file.
  1502. The structure and semantics of the devices is common to all networks so,
  1503. other than a file name substitution,
  1504. the same procedure makes a call using TCP over Ethernet as URP over Datakit [Fra80].
  1505. .PP
  1506. This example illustrates the structure of the TCP device:
  1507. .P1
  1508. % ls -lp /net/tcp
  1509. d-r-xr-xr-x I 0 bootes bootes 0 Feb 23 20:20 0
  1510. d-r-xr-xr-x I 0 bootes bootes 0 Feb 23 20:20 1
  1511. --rw-rw-rw- I 0 bootes bootes 0 Feb 23 20:20 clone
  1512. % ls -lp /net/tcp/0
  1513. --rw-rw---- I 0 rob bootes 0 Feb 23 20:20 ctl
  1514. --rw-rw---- I 0 rob bootes 0 Feb 23 20:20 data
  1515. --rw-rw---- I 0 rob bootes 0 Feb 23 20:20 listen
  1516. --r--r--r-- I 0 bootes bootes 0 Feb 23 20:20 local
  1517. --r--r--r-- I 0 bootes bootes 0 Feb 23 20:20 remote
  1518. --r--r--r-- I 0 bootes bootes 0 Feb 23 20:20 status
  1519. %
  1520. .P2
  1521. The top directory,
  1522. .CW /net/tcp ,
  1523. contains a
  1524. .CW clone
  1525. file and a directory for each connection, numbered
  1526. .CW 0
  1527. to
  1528. .I n .
  1529. Each connection directory corresponds to an TCP/IP connection.
  1530. Opening
  1531. .CW clone
  1532. reserves an unused connection and returns its control file.
  1533. Reading the control file returns the textual connection number, so the user
  1534. process can construct the full name of the newly allocated
  1535. connection directory.
  1536. The
  1537. .CW local ,
  1538. .CW remote ,
  1539. and
  1540. .CW status
  1541. files are diagnostic; for example,
  1542. .CW remote
  1543. contains the address (for TCP, the IP address and port number) of the remote side.
  1544. .PP
  1545. A call is initiated by writing a connect message with a network-specific address as
  1546. its argument; for example, to open a Telnet session (port 23) to a remote machine
  1547. with IP address 135.104.9.52,
  1548. the string is:
  1549. .P1
  1550. connect 135.104.9.52!23
  1551. .P2
  1552. The write to the control file blocks until the connection is established;
  1553. if the destination is unreachable, the write returns an error.
  1554. Once the connection is established, the
  1555. .CW telnet
  1556. application reads and writes the
  1557. .CW data
  1558. file
  1559. to talk to the remote Telnet daemon.
  1560. On the other end, the Telnet daemon would start by writing
  1561. .P1
  1562. announce 23
  1563. .P2
  1564. to its control file to indicate its willingness to receive calls to this port.
  1565. Such a daemon is called a
  1566. .I listener
  1567. in Plan 9.
  1568. .PP
  1569. A uniform structure for network devices cannot hide all the details
  1570. of addressing and communication for dissimilar networks.
  1571. For example, Datakit uses textual, hierarchical addresses unlike IP's 32-bit addresses, so
  1572. an application given a control file must still know what network it represents.
  1573. Rather than make every application know the addressing of every network,
  1574. Plan 9 hides these details in a
  1575. .I connection
  1576. .I server ,
  1577. called
  1578. .CW cs .
  1579. .CW Cs
  1580. is a file system mounted in a known place.
  1581. It supplies a single control file that an application uses to discover how to connect
  1582. to a host.
  1583. The application writes the symbolic address and service name for
  1584. the connection it wishes to make,
  1585. and reads back the name of the
  1586. .CW clone
  1587. file to open and the address to present to it.
  1588. If there are multiple networks between the machines,
  1589. .CW cs
  1590. presents a list of possible networks and addresses to be tried in sequence;
  1591. it uses heuristics to decide the order.
  1592. For instance, it presents the highest-bandwidth choice first.
  1593. .PP
  1594. A single library function called
  1595. .CW dial
  1596. talks to
  1597. .CW cs
  1598. to establish the connection.
  1599. An application that uses
  1600. .CW dial
  1601. needs no changes, not even recompilation, to adapt to new networks;
  1602. the interface to
  1603. .CW cs
  1604. hides the details.
  1605. .PP
  1606. The uniform structure for networks in Plan 9 makes the
  1607. .CW import
  1608. command all that is needed to construct gateways.
  1609. .SH
  1610. Kernel structure for networks
  1611. .PP
  1612. The kernel plumbing used to build Plan 9 communications
  1613. channels is called
  1614. .I streams
  1615. [Rit84][Presotto].
  1616. A stream is a bidirectional channel connecting a
  1617. physical or pseudo-device to a user process.
  1618. The user process inserts and removes data at one end of the stream;
  1619. a kernel process acting on behalf of a device operates at
  1620. the other end.
  1621. A stream comprises a linear list of
  1622. .I "processing modules" .
  1623. Each module has both an upstream (toward the process) and
  1624. downstream (toward the device)
  1625. .I "put routine" .
  1626. Calling the put routine of the module on either end of the stream
  1627. inserts data into the stream.
  1628. Each module calls the succeeding one to send data up or down the stream.
  1629. Like UNIX streams [Rit84],
  1630. Plan 9 streams can be dynamically configured.
  1631. .SH
  1632. The IL Protocol
  1633. .PP
  1634. The 9P protocol must run above a reliable transport protocol with delimited messages.
  1635. 9P has no mechanism to recover from transmission errors and
  1636. the system assumes that each read from a communication channel will
  1637. return a single 9P message;
  1638. it does not parse the data stream to discover message boundaries.
  1639. Pipes and some network protocols already have these properties but
  1640. the standard IP protocols do not.
  1641. TCP does not delimit messages, while
  1642. UDP [RFC768] does not provide reliable in-order delivery.
  1643. .PP
  1644. We designed a new protocol, called IL (Internet Link), to transmit 9P messages over IP.
  1645. It is a connection-based protocol that provides
  1646. reliable transmission of sequenced messages between machines.
  1647. Since a process can have only a single outstanding 9P request,
  1648. there is no need for flow control in IL.
  1649. Like TCP, IL has adaptive timeouts: it scales acknowledge and retransmission times
  1650. to match the network speed.
  1651. This allows the protocol to perform well on both the Internet and on local Ethernets.
  1652. Also, IL does no blind retransmission,
  1653. to avoid adding to the congestion of busy networks.
  1654. Full details are in another paper [PrWi95].
  1655. .PP
  1656. In Plan 9, the implementation of IL is smaller and faster than TCP.
  1657. IL is our main Internet transport protocol.
  1658. .SH
  1659. Overview of authentication
  1660. .PP
  1661. Authentication establishes the identity of a
  1662. user accessing a resource.
  1663. The user requesting the resource is called the
  1664. .I client
  1665. and the user granting access to the resource is called the
  1666. .I server .
  1667. This is usually done under the auspices of a 9P attach message.
  1668. A user may be a client in one authentication exchange and a server in another.
  1669. Servers always act on behalf of some user,
  1670. either a normal client or some administrative entity, so authentication
  1671. is defined to be between users, not machines.
  1672. .PP
  1673. Each Plan 9 user has an associated DES [NBS77] authentication key;
  1674. the user's identity is verified by the ability to
  1675. encrypt and decrypt special messages called challenges.
  1676. Since knowledge of a user's key gives access to that user's resources,
  1677. the Plan 9 authentication protocols never transmit a message containing
  1678. a cleartext key.
  1679. .PP
  1680. Authentication is bilateral:
  1681. at the end of the authentication exchange,
  1682. each side is convinced of the other's identity.
  1683. Every machine begins the exchange with a DES key in memory.
  1684. In the case of CPU and file servers, the key, user name, and domain name
  1685. for the server are read from permanent storage,
  1686. usually non-volatile RAM.
  1687. In the case of terminals,
  1688. the key is derived from a password typed by the user at boot time.
  1689. A special machine, known as the
  1690. .I authentication
  1691. .I server ,
  1692. maintains a database of keys for all users in its administrative domain and
  1693. participates in the authentication protocols.
  1694. .PP
  1695. The authentication protocol is as follows:
  1696. after exchanging challenges, one party
  1697. contacts the authentication server to create
  1698. permission-granting
  1699. .I tickets
  1700. encrypted with
  1701. each party's secret key and containing a new conversation key.
  1702. Each
  1703. party decrypts its own ticket and uses the conversation key to
  1704. encrypt the other party's challenge.
  1705. .PP
  1706. This structure is somewhat like Kerberos [MBSS87], but avoids
  1707. its reliance on synchronized clocks.
  1708. Also
  1709. unlike Kerberos, Plan 9 authentication supports a `speaks for'
  1710. relation [LABW91] that enables one user to have the authority
  1711. of another;
  1712. this is how a CPU server runs processes on behalf of its clients.
  1713. .PP
  1714. Plan 9's authentication structure builds
  1715. secure services rather than depending on firewalls.
  1716. Whereas firewalls require special code for every service penetrating the wall,
  1717. the Plan 9 approach permits authentication to be done in a single place\(em9P\(emfor
  1718. all services.
  1719. For example, the
  1720. .CW cpu
  1721. command works securely across the Internet.
  1722. .SH
  1723. Authenticating external connections
  1724. .PP
  1725. The regular Plan 9 authentication protocol is not suitable for text-based services such as
  1726. Telnet
  1727. or FTP.
  1728. In such cases, Plan 9 users authenticate with hand-held DES calculators called
  1729. .I authenticators .
  1730. The authenticator holds a key for the user, distinct from
  1731. the user's normal authentication key.
  1732. The user `logs on' to the authenticator using a 4-digit PIN.
  1733. A correct PIN enables the authenticator for a challenge/response exchange with the server.
  1734. Since a correct challenge/response exchange is valid only once
  1735. and keys are never sent over the network,
  1736. this procedure is not susceptible to replay attacks, yet
  1737. is compatible with protocols like Telnet and FTP.
  1738. .SH
  1739. Special users
  1740. .PP
  1741. Plan 9 has no super-user.
  1742. Each server is responsible for maintaining its own security, usually permitting
  1743. access only from the console, which is protected by a password.
  1744. For example, file servers have a unique administrative user called
  1745. .CW adm ,
  1746. with special privileges that apply only to commands typed at the server's
  1747. physical console.
  1748. These privileges concern the day-to-day maintenance of the server,
  1749. such as adding new users and configuring disks and networks.
  1750. The privileges do
  1751. .I not
  1752. include the ability to modify, examine, or change the permissions of any files.
  1753. If a file is read-protected by a user, only that user may grant access to others.
  1754. .PP
  1755. CPU servers have an equivalent user name that allows administrative access to
  1756. resources on that server such as the control files of user processes.
  1757. Such permission is necessary, for example, to kill rogue processes, but
  1758. does not extend beyond that server.
  1759. On the other hand, by means of a key
  1760. held in protected non-volatile RAM,
  1761. the identity of the administrative user is proven to the
  1762. authentication server.
  1763. This allows the CPU server to authenticate remote users, both
  1764. for access to the server itself and when the CPU server is acting
  1765. as a proxy on their behalf.
  1766. .PP
  1767. Finally, a special user called
  1768. .CW none
  1769. has no password and is always allowed to connect;
  1770. anyone may claim to be
  1771. .CW none .
  1772. .CW None
  1773. has restricted permissions; for example, it is not allowed to examine dump files
  1774. and can read only world-readable files.
  1775. .PP
  1776. The idea behind
  1777. .CW none
  1778. is analogous to the anonymous user in FTP
  1779. services.
  1780. On Plan 9, guest FTP servers are further confined within a special
  1781. restricted name space.
  1782. It disconnects guest users from system programs, such as the contents of
  1783. .CW /bin ,
  1784. but makes it possible to make local files available to guests
  1785. by binding them explicitly into the space.
  1786. A restricted name space is more secure than the usual technique of exporting
  1787. an ad hoc directory tree; the result is a kind of cage around untrusted users.
  1788. .SH
  1789. The cpu command and proxied authentication
  1790. .PP
  1791. When a call is made to a CPU server for a user, say Peter,
  1792. the intent is that Peter wishes to run processes with his own authority.
  1793. To implement this property,
  1794. the CPU server does the following when the call is received.
  1795. First, the listener forks off a process to handle the call.
  1796. This process changes to the user
  1797. .CW none
  1798. to avoid giving away permissions if it is compromised.
  1799. It then performs the authentication protocol to verify that the
  1800. calling user really is Peter, and to prove to Peter that
  1801. the machine is itself trustworthy.
  1802. Finally, it reattaches to all relevant file servers using the
  1803. authentication protocol to identify itself as Peter.
  1804. In this case, the CPU server is a client of the file server and performs the
  1805. client portion of the authentication exchange on behalf of Peter.
  1806. The authentication server will give the process tickets to
  1807. accomplish this only if the CPU server's administrative user name is allowed to
  1808. .I "speak for"
  1809. Peter.
  1810. .PP
  1811. The
  1812. .I "speaks for
  1813. relation [LABW91] is kept in a table on the authentication server.
  1814. To simplify the management of users computing in different authentication domains,
  1815. it also contains mappings between user names in different domains,
  1816. for example saying that user
  1817. .CW rtm
  1818. in one domain is the same person as user
  1819. .CW rtmorris
  1820. in another.
  1821. .SH
  1822. File Permissions
  1823. .PP
  1824. One of the advantages of constructing services as file systems
  1825. is that the solutions to ownership and permission problems fall out naturally.
  1826. As in UNIX,
  1827. each file or directory has separate read, write, and execute/search permissions
  1828. for the file's owner, the file's group, and anyone else.
  1829. The idea of group is unusual:
  1830. any user name is potentially a group name.
  1831. A group is just a user with a list of other users in the group.
  1832. Conventions make the distinction: most people have user names without group members,
  1833. while groups have long lists of attached names. For example, the
  1834. .CW sys
  1835. group traditionally has all the system programmers,
  1836. and system files are accessible
  1837. by group
  1838. .CW sys .
  1839. Consider the following two lines of a user database stored on a server:
  1840. .P1
  1841. pjw:pjw:
  1842. sys::pjw,ken,philw,presotto
  1843. .P2
  1844. The first establishes user
  1845. .CW pjw
  1846. as a regular user. The second establishes user
  1847. .CW sys
  1848. as a group and lists four users who are
  1849. .I members
  1850. of that group.
  1851. The empty colon-separated field is space for a user to be named as the
  1852. .I group
  1853. .I leader .
  1854. If a group has a leader, that user has special permissions for the group,
  1855. such as freedom to change the group permissions
  1856. of files in that group.
  1857. If no leader is specified, each member of the group is considered equal, as if each were
  1858. the leader.
  1859. In our example, only
  1860. .CW pjw
  1861. can add members to his group, but all of
  1862. .CW sys 's
  1863. members are equal partners in that group.
  1864. .PP
  1865. Regular files are owned by the user that creates them.
  1866. The group name is inherited from the directory holding the new file.
  1867. Device files are treated specially:
  1868. the kernel may arrange the ownership and permissions of
  1869. a file appropriate to the user accessing the file.
  1870. .PP
  1871. A good example of the generality this offers is process files,
  1872. which are owned and read-protected by the owner of the process.
  1873. If the owner wants to let someone else access the memory of a process,
  1874. for example to let the author of a program debug a broken image, the standard
  1875. .CW chmod
  1876. command applied to the process files does the job.
  1877. .PP
  1878. Another unusual application of file permissions
  1879. is the dump file system, which is not only served by the same file
  1880. server as the original data, but represented by the same user database.
  1881. Files in the dump are therefore given identical protection as files in the regular
  1882. file system;
  1883. if a file is owned by
  1884. .CW pjw
  1885. and read-protected, once it is in the dump file system it is still owned by
  1886. .CW pjw
  1887. and read-protected.
  1888. Also, since the dump file system is immutable, the file cannot be changed;
  1889. it is read-protected forever.
  1890. Drawbacks are that if the file is readable but should have been read-protected,
  1891. it is readable forever, and that user names are hard to re-use.
  1892. .SH
  1893. Performance
  1894. .PP
  1895. As a simple measure of the performance of the Plan 9 kernel,
  1896. we compared the
  1897. time to do some simple operations on Plan 9 and on SGI's IRIX Release 5.3
  1898. running on an SGI Challenge M with a 100MHz MIPS R4400 and a 1-megabyte
  1899. secondary cache.
  1900. The test program was written in Alef,
  1901. compiled with the same compiler,
  1902. and run on identical hardware,
  1903. so the only variables are the operating system and libraries.
  1904. .PP
  1905. The program tests the time to do a context switch
  1906. .CW rendezvous "" (
  1907. on Plan 9,
  1908. .CW blockproc
  1909. on IRIX);
  1910. a trivial system call
  1911. .CW rfork(0) "" (
  1912. and
  1913. .CW nap(0) );
  1914. and
  1915. lightweight fork
  1916. .CW rfork(RFPROC) "" (
  1917. and
  1918. .CW sproc(PR_SFDS|PR_SADDR) ).
  1919. It also measures the time to send a byte on a pipe from one process
  1920. to another and the throughput on a pipe between two processes.
  1921. The results appear in Table 1.
  1922. .KS
  1923. .TS
  1924. center,box;
  1925. ccc
  1926. lnn.
  1927. Test Plan 9 IRIX
  1928. _
  1929. Context switch 39 µs 150 µs
  1930. System call 6 µs 36 µs
  1931. Light fork 1300 µs 2200 µs
  1932. Pipe latency 110 µs 200 µs
  1933. Pipe bandwidth 11678 KB/s 14545 KB/s
  1934. .TE
  1935. .ce
  1936. .I
  1937. Table 1. Performance comparison.
  1938. .R
  1939. .KE
  1940. .LP
  1941. Although the Plan 9 times are not spectacular, they show that the kernel is
  1942. competitive with commercial systems.
  1943. .SH
  1944. Discussion
  1945. .PP
  1946. Plan 9 has a relatively conventional kernel;
  1947. the system's novelty lies in the pieces outside the kernel and the way they interact.
  1948. When building Plan 9, we considered all aspects
  1949. of the system together, solving problems where the solution fit best.
  1950. Sometimes the solution spanned many components.
  1951. An example is the problem of heterogeneous instruction architectures,
  1952. which is addressed by the compilers (different code characters, portable
  1953. object code),
  1954. the environment
  1955. .CW $cputype "" (
  1956. and
  1957. .CW $objtype ),
  1958. the name space
  1959. (binding in
  1960. .CW /bin ),
  1961. and other components.
  1962. Sometimes many issues could be solved in a single place.
  1963. The best example is 9P,
  1964. which centralizes naming, access, and authentication.
  1965. 9P is really the core
  1966. of the system;
  1967. it is fair to say that the Plan 9 kernel is primarily a 9P multiplexer.
  1968. .PP
  1969. Plan 9's focus on files and naming is central to its expressiveness.
  1970. Particularly in distributed computing, the way things are named has profound
  1971. influence on the system [Nee89].
  1972. The combination of
  1973. local name spaces and global conventions to interconnect networked resources
  1974. avoids the difficulty of maintaining a global uniform name space,
  1975. while naming everything like a file makes the system easy to understand, even for
  1976. novices.
  1977. Consider the dump file system, which is trivial to use for anyone familiar with
  1978. hierarchical file systems.
  1979. At a deeper level, building all the resources above a single uniform interface
  1980. makes interoperability easy.
  1981. Once a resource exports a 9P interface,
  1982. it can combine transparently
  1983. with any other part of the system to build unusual applications;
  1984. the details are hidden.
  1985. This may sound object-oriented, but there are distinctions.
  1986. First, 9P defines a fixed set of `methods'; it is not an extensible protocol.
  1987. More important,
  1988. files are well-defined and well-understood
  1989. and come prepackaged with familiar methods of access, protection, naming, and
  1990. networking.
  1991. Objects, despite their generality, do not come with these attributes defined.
  1992. By reducing `object' to `file', Plan 9 gets some technology for free.
  1993. .PP
  1994. Nonetheless, it is possible to push the idea of file-based computing too far.
  1995. Converting every resource in the system into a file system is a kind of metaphor,
  1996. and metaphors can be abused.
  1997. A good example of restraint is
  1998. .CW /proc ,
  1999. which is only a view of a process, not a representation.
  2000. To run processes, the usual
  2001. .CW fork
  2002. and
  2003. .CW exec
  2004. calls are still necessary, rather than doing something like
  2005. .P1
  2006. cp /bin/date /proc/clone/mem
  2007. .P2
  2008. The problem with such examples is that they require the server to do things
  2009. not under its control.
  2010. The ability to assign meaning to a command like this does not
  2011. imply the meaning will fall naturally out of the structure of answering the 9P requests
  2012. it generates.
  2013. As a related example, Plan 9 does not put machine's network names in the file
  2014. name space.
  2015. The network interfaces provide a very different model of naming, because using
  2016. .CW open ,
  2017. .CW create ,
  2018. .CW read ,
  2019. and
  2020. .CW write
  2021. on such files would not offer a suitable place to encode all the details of call
  2022. setup for an arbitrary network.
  2023. This does not mean that the network interface cannot be file-like, just that it must
  2024. have a more tightly defined structure.
  2025. .PP
  2026. What would we do differently next time?
  2027. Some elements of the implementation are unsatisfactory.
  2028. Using streams to implement network interfaces in the kernel
  2029. allows protocols to be connected together dynamically,
  2030. such as to attach the same TTY driver to TCP, URP, and
  2031. IL connections,
  2032. but Plan 9 makes no use of this configurability.
  2033. (It was exploited, however, in the research UNIX system for which
  2034. streams were invented.)
  2035. Replacing streams by static I/O queues would
  2036. simplify the code and make it faster.
  2037. .PP
  2038. Although the main Plan 9 kernel is portable across many machines,
  2039. the file server is implemented separately.
  2040. This has caused several problems:
  2041. drivers that must be written twice,
  2042. bugs that must be fixed twice,
  2043. and weaker portability of the file system code.
  2044. The solution is easy: the file server kernel should be maintained
  2045. as a variant of the regular operating system, with no user processes and
  2046. special compiled-in
  2047. kernel processes to implement file service.
  2048. Another improvement to the file system would be a change of internal structure.
  2049. The WORM jukebox is the least reliable piece of the hardware, but because
  2050. it holds the metadata of the file system, it must be present in order to serve files.
  2051. The system could be restructured so the WORM is a backup device only, with the
  2052. file system proper residing on magnetic disks.
  2053. This would require no change to the external interface.
  2054. .PP
  2055. Although Plan 9 has per-process name spaces, it has no mechanism to give the
  2056. description of a process's name space to another process except by direct inheritance.
  2057. The
  2058. .CW cpu
  2059. command, for example, cannot in general reproduce the terminal's name space;
  2060. it can only re-interpret the user's login profile and make substitutions for things like
  2061. the name of the binary directory to load.
  2062. This misses any local modifications made before running
  2063. .CW cpu .
  2064. It should instead be possible to capture the terminal's name space and transmit
  2065. its description to a remote process.
  2066. .PP
  2067. Despite these problems, Plan 9 works well.
  2068. It has matured into the system that supports our research,
  2069. rather than being the subject of the research itself.
  2070. Experimental new work includes developing interfaces to faster networks,
  2071. file caching in the client kernel,
  2072. encapsulating and exporting name spaces,
  2073. and the ability to re-establish the client state after a server crash.
  2074. Attention is now focusing on using the system to build distributed applications.
  2075. .PP
  2076. One reason for Plan 9's success is that we use it for our daily work, not just as a research tool.
  2077. Active use forces us to address shortcomings as they arise and to adapt the system
  2078. to solve our problems.
  2079. Through this process, Plan 9 has become a comfortable, productive programming
  2080. environment, as well as a vehicle for further systems research.
  2081. .SH
  2082. References
  2083. .nr PS -1
  2084. .nr VS -2
  2085. .IP [9man] 9
  2086. .I
  2087. Plan 9 Programmer's Manual,
  2088. Volume 1,
  2089. .R
  2090. AT&T Bell Laboratories,
  2091. Murray Hill, NJ,
  2092. 1995.
  2093. .IP [ANSIC] 9
  2094. \f2American National Standard for Information Systems \-
  2095. Programming Language C\f1, American National Standards Institute, Inc.,
  2096. New York, 1990.
  2097. .IP [Duff90] 9
  2098. Tom Duff, ``Rc - A Shell for Plan 9 and UNIX systems'',
  2099. .I
  2100. Proc. of the Summer 1990 UKUUG Conf.,
  2101. .R
  2102. London, July, 1990, pp. 21-33, reprinted, in a different form, in this volume.
  2103. .IP [Fra80] 9
  2104. A.G. Fraser,
  2105. ``Datakit \- A Modular Network for Synchronous and Asynchronous Traffic'',
  2106. .I
  2107. Proc. Int. Conf. on Commun.,
  2108. .R
  2109. June 1980, Boston, MA.
  2110. .IP [FSSUTF] 9
  2111. .I
  2112. File System Safe UCS Transformation Format (FSS-UTF),
  2113. .R
  2114. X/Open Preliminary Specification, 1993.
  2115. ISO designation is
  2116. ISO/IEC JTC1/SC2/WG2 N 1036, dated 1994-08-01.
  2117. .IP "[ISO10646] " 9
  2118. ISO/IEC DIS 10646-1:1993
  2119. .I
  2120. Information technology \-
  2121. Universal Multiple-Octet Coded Character Set (UCS) \(em
  2122. Part 1: Architecture and Basic Multilingual Plane.
  2123. .R
  2124. .IP [Kill84] 9
  2125. T.J. Killian,
  2126. ``Processes as Files'',
  2127. .I
  2128. USENIX Summer 1984 Conf. Proc.,
  2129. .R
  2130. June 1984, Salt Lake City, UT.
  2131. .IP "[LABW91] " 9
  2132. Butler Lampson,
  2133. Martín Abadi,
  2134. Michael Burrows, and
  2135. Edward Wobber,
  2136. ``Authentication in Distributed Systems: Theory and Practice'',
  2137. .I
  2138. Proc. 13th ACM Symp. on Op. Sys. Princ.,
  2139. .R
  2140. Asilomar, 1991,
  2141. pp. 165-182.
  2142. .IP "[MBSS87] " 9
  2143. S. P. Miller,
  2144. B. C. Neumann,
  2145. J. I. Schiller, and
  2146. J. H. Saltzer,
  2147. ``Kerberos Authentication and Authorization System'',
  2148. Massachusetts Institute of Technology,
  2149. 1987.
  2150. .IP [NBS77] 9
  2151. National Bureau of Standards (U.S.),
  2152. .I
  2153. Federal Information Processing Standard 46,
  2154. .R
  2155. National Technical Information Service, Springfield, VA, 1977.
  2156. .IP [Nee89] 9
  2157. R. Needham, ``Names'', in
  2158. .I
  2159. Distributed systems,
  2160. .R
  2161. S. Mullender, ed.,
  2162. Addison Wesley, 1989
  2163. .IP "[NeHe82] " 9
  2164. R.M. Needham and A.J. Herbert,
  2165. .I
  2166. The Cambridge Distributed Computing System,
  2167. .R
  2168. Addison-Wesley, London, 1982
  2169. .IP [Neu92] 9
  2170. B. Clifford Neuman,
  2171. ``The Prospero File System'',
  2172. .I
  2173. USENIX File Systems Workshop Proc.,
  2174. .R
  2175. Ann Arbor, 1992, pp. 13-28.
  2176. .IP "[OCDNW88] " 9
  2177. John Ousterhout, Andrew Cherenson, Fred Douglis, Mike Nelson, and Brent Welch,
  2178. ``The Sprite Network Operating System'',
  2179. .I
  2180. IEEE Computer,
  2181. .R
  2182. 21(2), 23-38, Feb. 1988.
  2183. .IP [Pike87] 9
  2184. Rob Pike, ``The Text Editor \f(CWsam\fP'',
  2185. .I
  2186. Software - Practice and Experience,
  2187. .R
  2188. Nov 1987, \f3\&17\f1(11), pp. 813-845; reprinted in this volume.
  2189. .IP [Pike91] 9
  2190. Rob Pike, ``8½, the Plan 9 Window System'',
  2191. .I
  2192. USENIX Summer Conf. Proc.,
  2193. .R
  2194. Nashville, June, 1991, pp. 257-265,
  2195. reprinted in this volume.
  2196. .IP [Pike93] 9
  2197. Rob Pike and Ken Thompson, ``Hello World or Καλημέρα κόσμε or
  2198. \f(Jpこんにちは 世界\fP'',
  2199. .I
  2200. USENIX Winter Conf. Proc.,
  2201. .R
  2202. San Diego, 1993, pp. 43-50,
  2203. reprinted in this volume.
  2204. .IP [Pike94] 9
  2205. Rob Pike,
  2206. ``Acme: A User Interface for Programmers'',
  2207. .I
  2208. USENIX Proc. of the Winter 1994 Conf.,
  2209. .R
  2210. San Francisco, CA,
  2211. .IP [Pike95] 9
  2212. Rob Pike,
  2213. ``How to Use the Plan 9 C Compiler'',
  2214. .I
  2215. Plan 9 Programmer's Manual,
  2216. Volume 2,
  2217. .R
  2218. AT&T Bell Laboratories,
  2219. Murray Hill, NJ,
  2220. 1995.
  2221. .IP [POSIX] 9
  2222. .I
  2223. Information Technology\(emPortable Operating
  2224. System Interface (POSIX) Part 1:
  2225. System Application Program Interface (API)
  2226. [C Language],
  2227. .R
  2228. IEEE, New York, 1990.
  2229. .IP "[PPTTW93] " 9
  2230. Rob Pike, Dave Presotto, Ken Thompson, Howard Trickey, and Phil Winterbottom, ``The Use of Name Spaces in Plan 9'',
  2231. .I
  2232. Op. Sys. Rev.,
  2233. .R
  2234. Vol. 27, No. 2, April 1993, pp. 72-76,
  2235. reprinted in this volume.
  2236. .IP [Presotto] 9
  2237. Dave Presotto,
  2238. ``Multiprocessor Streams for Plan 9'',
  2239. .I
  2240. UKUUG Summer 1990 Conf. Proc.,
  2241. .R
  2242. July 1990, pp. 11-19.
  2243. .IP [PrWi93] 9
  2244. Dave Presotto and Phil Winterbottom,
  2245. ``The Organization of Networks in Plan 9'',
  2246. .I
  2247. USENIX Proc. of the Winter 1993 Conf.,
  2248. .R
  2249. San Diego, CA,
  2250. pp. 43-50,
  2251. reprinted in this volume.
  2252. .IP [PrWi95] 9
  2253. Dave Presotto and Phil Winterbottom,
  2254. ``The IL Protocol'',
  2255. .I
  2256. Plan 9 Programmer's Manual,
  2257. Volume 2,
  2258. .R
  2259. AT&T Bell Laboratories,
  2260. Murray Hill, NJ,
  2261. 1995.
  2262. .IP "[RFC768] " 9
  2263. J. Postel, RFC768,
  2264. .I "User Datagram Protocol,
  2265. .I "DARPA Internet Program Protocol Specification,
  2266. August 1980.
  2267. .IP "[RFC793] " 9
  2268. RFC793,
  2269. .I "Transmission Control Protocol,
  2270. .I "DARPA Internet Program Protocol Specification,
  2271. September 1981.
  2272. .IP [Rao91] 9
  2273. Herman Chung-Hwa Rao,
  2274. .I
  2275. The Jade File System,
  2276. .R
  2277. (Ph. D. Dissertation),
  2278. Dept. of Comp. Sci,
  2279. University of Arizona,
  2280. TR 91-18.
  2281. .IP [Rit84] 9
  2282. D.M. Ritchie,
  2283. ``A Stream Input-Output System'',
  2284. .I
  2285. AT&T Bell Laboratories Technical Journal,
  2286. \f363\f1(8), October, 1984.
  2287. .IP [Tric95] 9
  2288. Howard Trickey,
  2289. ``APE \(em The ANSI/POSIX Environment'',
  2290. .I
  2291. Plan 9 Programmer's Manual,
  2292. Volume 2,
  2293. .R
  2294. AT&T Bell Laboratories,
  2295. Murray Hill, NJ,
  2296. 1995.
  2297. .IP [Unicode] 9
  2298. .I
  2299. The Unicode Standard,
  2300. Worldwide Character Encoding,
  2301. Version 1.0, Volume 1,
  2302. .R
  2303. The Unicode Consortium,
  2304. Addison Wesley,
  2305. New York,
  2306. 1991.
  2307. .IP [UNIX85] 9
  2308. .I
  2309. UNIX Time-Sharing System Programmer's Manual,
  2310. Research Version, Eighth Edition, Volume 1.
  2311. .R
  2312. AT&T Bell Laboratories, Murray Hill, NJ, 1985.
  2313. .IP [Welc94] 9
  2314. Brent Welch,
  2315. ``A Comparison of Three Distributed File System Architectures: Vnode, Sprite, and Plan 9'',
  2316. .I
  2317. Computing Systems,
  2318. .R
  2319. 7(2), pp. 175-199, Spring, 1994.
  2320. .IP [Wint95] 9
  2321. Phil Winterbottom,
  2322. ``Alef Language Reference Manual'',
  2323. .I
  2324. Plan 9 Programmer's Manual,
  2325. Volume 2,
  2326. .R
  2327. AT&T Bell Laboratories,
  2328. Murray Hill, NJ,
  2329. 1995.