.\" mk slides.show
.fp 9 CB \" Code bold
.de IT
.if !"\\$1"" .ds BX \\$1
.if "\\$1"" .ds BX \(bu
.IP \\*(BX
..
.de SS
.ds CH \s+0\f3\\$1\fP\s-0
.bp
.LP
.na
..
.nr PO 0.5i
.nr HM 1i
.nr PS 14
.nr VS 16p
.nr PD 3p
.nr LL 6.5i
.nr XP 0 \" delta point size for program
.nr XT 8 \" delta tab stop for programs
.nr DV .5v \" space before start of program
.nr HM 0.8i \" Top margin
.nr FM 0.1i \" Bottom margin
.ds CH "
.pl 15c
.ds RF "
.TL
The Unix Spirit set Free: Plan 9 from Bell Labs
.AU
Uriel
.AI
uriel@cat-v.org
.PP
.SS "The most common question about Plan 9
Is Plan 9 Free Software/Open Source?
.ce
.B
Yes!
.R
.IT
Latest Plan 9 license is considered Free Software by RMS and the FSF.
.IT
Considered Open Source by the OSI.
.IT
Free according to the DFSG.
.LP
With politics out of the way, lets get on with the important stuff...
.SS "The JWZ test
.ce
.BI
.vs 128p
Your "use case" should be, there's a 22 year old college student living in the dorms.
.vs 20p
How will this software get him laid?
.R
.ce
Jamie Zawinski
\""How will Plan 9 help me get laid?"
.SS "Glenda, the Plan 9 Bunny
.BP glenda.ps
.EP
.VS
.vs 16
.ce
.BI
The cutest mascot
.SS "The history of Plan 9
.IT
Started in the mid 1980's at Bell Labs by the same team that created Unix.
.IT
First full time users in 1989, in production since then.
.LP
Four public releases
.IT
1st Ed (1993): First public release, only to universities.
.IT
2nd Ed (1995): First general public release.
.IT
Inferno 1st Ed (1997): Based in many of the ideas and technologies in Plan 9.
.IT
3rd Ed (2000): First free release including source code; codename
.I Brazil .
.IT
4th Ed (2002): Approved Open Source license.
.IT
Inferno 4th Ed (2005): Released under GPL/MIT license.
.LP
Still in active development
.IT
Daily ISO builds.
.IT
Continuous updates delivered over 9p/replica.
.IT
Any user can submit changes using a simple patch creation and tracking system.
.IT
Repository of contributed programs and other resources in
.I /n/sources/contrib/ .
.SS "Some background history: In the beginning...
Multics
.IT
Multiuser.
.IT
Multiprocessing.
.IT
Multiprogramming.
.IT
Big, slow, bloated and
.BI complex .
.LP
While Multics collapsed under its own weight, Ken started to play with a
.SM PDP -7.
.SS "Unix
What was different: Small, fast, lean and
.BI simple .
In other words: KISS
Unix distilled and polished many of the Multics ideas, and added some of its own.
.IT
Hierarchical file system.
.IT
Everything is a file.
.IT
Each tool does one thing and does it well.
.IT
Processes communicate and interact through pipes.
.IT
Text is the universal language.
.IT
Written in a high-level language.
.LP
This was mostly true in the 1970's, since then, little has improved and some things now are worse.
.SS "What was wrong with Unix?
.ce
.I
"Not only is UNIX dead, it's starting to smell really bad."
.R
.ce
Rob Pike circa 1991
.ps
.IT
Designed as an old fashion timesharing system, has trouble adapting to a world of networks and workstations.
.IT
The advantages of timesharing were lost in the switch to workstations: Centralized management and administration, amortization of costs and resources.
.IT
Many features badly retrofitted over the years (eg., graphics, networking.)
.IT
Lots of hanging historical baggage.
.IT
Loss of conceptual integrity.
.IT
Unix is not
.BI simple
anymore.
.SS "What Plan 9 doesn't have...
.IT
root, suid
.IT
tty, curses
.IT
ioctl
.IT
sockets
.IT
select/poll
.IT
symlinks
.IT
pthreads
.IT
mmap
.IT
dynamic linking
.IT
loadable kernel modules
.IT
locales
.IT
gcc
.IT
C++
.IT
emacs (or vi)
.IT
X11
.IT
XML
.IT
WEB 2.0
.SS "Plan 9 is a completely new system
\" The problems with Unix were too deep to fix, but some of its ideas could be brought along.
Plan 9 distills and polishes many of the Unix ideas; and adds some of its own.
.IT
New kernel: designed to be portable and support SMP.
.IT
New compilers: small, fast and portable, cross compiling is the same as compiling.
.IT
New libraries: simpler and less error-prone.
.IT
New user interface: takes advantage of modern display and input devices.
.IT
New tools: debugger, text editors, mail system, network database, etc.
.IT
All components designed to work well together in a distributed environment.
.IT
Back to the Unix roots: Simplicity, Clarity and Generality
.LP
Note: To really understand Plan 9, you have to
.BI unlearn
the last 30 years of Unix. The similarities are big enough to create false expectations.
.SS "Main ideas
.LP
Three major concepts
.IT
.I Everything
is a file tree (
.I
file system
.R
):
.BI All
.R
resources are named and accessed like files in a hierarchical file system. No files are more special than others.
.IT
.I
9P:
.R
A single protocol to securely and transparently access resources independently of their location.
.IT
.I
Private namespaces:
.R
Every process can customize its view of the world by changing its private namespace that joins together the file hierarchies provided by different servers representing the network resources.
.SS "All resources as file systems
.IT
Networking:
.I /net/
.IT
Authentication:
.I /mnt/factotum/
.IT
Encryption:
.I /net/tls/
.IT
Graphics:
.I /dev/draw/
.IT
Window system:
.I /dev/wsys/
.IT
Process control and debugging:
.I /proc/
.IT
Environment:
.I /env/
.IT
Email:
.I /mail/fs/
.IT
Boring stuff: cdfs, webfs, tarfs, ftpfs, etc...
.IT
Weird stuff: wikifs, gpsfs, sshnet, iostats and others.
.SS "The 9P protocol
Lightweight network file system (but in Plan 9,
.I everything
is a file.)
.IT
Not block oriented, byte oriented.
.IT
Minimalistic and lightweight: Only 13 message types (NFSv3 has 22, NFSv4 has 42)
.IT
Can run over any reliable transport (directly over TCP, IL, RUDP, PPP, shared memory, serial port connections, PCI bus and others)
.IT
Encompassing: used for local and remote access; for
.I synthetic
and
.I physical
files.
.IT
Authentication and encryption agnostic.
.IT
Designed for transparent caching and stacking.
.SS "Namespaces
Imagine using a programming language where all variables were global...
...that is how Plan 9 users feel when they have to use Unix.
Three namespace operations:
.P1
int bind(char *name, char *old, int flag)
int mount(int fd, int afd, char *old, int flag,char *aname)
int unmount(char *name, char *old)
.P2
.LP
Example:
.I
/sys/src/libdraw/newwindow.c
.LP
From the shell:
.P1
% mount `{cat /env/wsys} /n/foo new
% cat /proc/$pid/ns
.P2
.SS "Union mounts
Flags for
.I bind
and
.I mount :
.IT
.I MREPL :
Replace the old file by the new one. Henceforth, an evaluation of old will be translated to the new file.
.IT
.I MBEFORE :
Both the old and new files must be directories. Add the files of the new directory to the union directory at old so its contents appear first in the union.
.IT
.I MAFTER :
Like MBEFORE but the new directory goes at the end of the union.
.IT
.I MCREATE :
OR'd with any of the above. When
.I create
attempts to create in a new file in a union directory will create the file in the first mount with the
.I MCREATE
flag.
Example:
.P1
% ns | grep /bin
.P2
.SS "The kernel
.TL
Linux
.IT
Over 300 syscalls and counting; hundreds (thousands?) of ioctls.
.IT
4,827,671 lines of code.
.LP
Others not better... Unix not small anymore.
.TL
Plan 9
.IT
37 syscalls; no networking related syscalls; no ioctls.
.IT
148,787 lines of code.
.IT
Optional real-time scheduler.
.IT
Microkernel or monolithic kernel? Who cares?
.IT
Inside the kernel or outside the kernel? Do what makes most sense,
can change it later without breaking the interface.
.IT
Pragmatic, not dogmatic design.
\" USER INTERFACES ----------------------------------------------------
.SS "Unix: X terminal (emulator)
.LP
Wow, how advanced; 1,000,000 times the performance and there's still an ASR-33 in the middle!
.BP asr-33.ps
.EP
.LP
.ce
Don't believe me? Type 'stty' in an xterm and tell me why a window has a baud rate.
.SS "Rio - the Plan 9 window system
The Plan 9 user interface was designed to take full advantage of modern
bitmapped displays and input mechanisms.
Yes, you really want to use a 3 button mouse.
.IT
All text is editable.
.IT
No cursor addressing.
.IT
Works as simple text editor.
.IT
Use the output of previous commands as the basis of new commands.
.IT
All applications transparently take advantage of its features: Plumbing, chording, hold mode, tab completion.
.IT
Multiplexes its environment: rio runs inside rio.
Who needs shell history when you can grep
.I /dev/text ,
edit the output, and click "Send"?
Using the mouse
.I is
faster and much more
.I expressive
if the user interface designed to take advantage of it.)
.SS "Acme: a user interface for programmers
.IT
Windows organized in stacks. Makes management of many windows easy.
.IT
All text is editable and executable.
.IT
Mouse chording.
.IT
File system interface provides programability.
.IT
Acme applications: Wiki browser/editor, email and news clients, debugger interface, ...
.SS "Plumbing
.IT
Text everywhere can be plumbed.
.IT
Plumbing rules determine what to do.
.IT
Flexible and powerful.
.IT
File system interface.
.IT
Works across the network.
\" TOOLS -----------------------------------------
.SS "The cross compilers
.IT
One program per architecture.
.IT
Cross compiling is the same as compiling.
.IT
Very fast, I/O bound.
.IT
Reliable.
.IT
Very portable: aprox 7,000 lines of code per arch (gcc is >150,000 lines per arch.)
.IT
Existing ports to: Motorola MC68000/MC68020, StrongARM, Alpha, i386, amd64, SPARC, SPARC64, PowerPC, MIPS and others.
.LP
ken's C
.IT
Very simplified preprocessor.
.IT
Support for UTF-8 literals.
.IT
Some small and convenient extensions.
.SS "The acid debugging language
.IT
Implemented as a language-agnostic language to prove and manipulate processes.
.IT
Can write your own library of helpful functions in the acid language for specific tasks.
.IT
Interfaces with processes over /proc/, allows transparent remote debugging, even across different architectures!
.IT
Can take a
.I snap
of a process directly from /proc/ for later analysis. No need for core dumps!
\" NETWORK PROGRAMMING -----------------------------------------
.SS "Opening a network connection in Unix
.nr XP 2
.nr XV 0
.nr VS 15p
.KF
.P1
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
...
struct sockaddr_in sock_in;
struct servent *sp;
struct hostent *host;
...
memset(&sock_in, 0, sizeof (sock_in));
sock_in.sin_family = AF_INET;
f = socket(AF_INET, SOCK_STREAM, 0);
if (f < 0)
error("socket");
if (bind(f, (struct sockaddr*)&sock_in, sizeof sock_in) < 0){
error("bind");
host = gethostbyname(argv[1]);
if(host){
sock_in.sin_family = host->h_addrtype;
memmove(&sock_in.sin_addr, host->h_addr, host->h_length);
.P2
.KE
.SS "...
.KF
.P1
}else{
sock_in.sin_family = AF_INET;
sock_in.sin_addr.s_addr = inet_addr(argv[1]);
if (sock_in.sin_addr.s_addr == -1)
error("unknown host %s", argv[1]);
}
sp = getservbyname("discard", "tcp");
if (sp)
sock_in.sin_port = sp->s_port;
else
sock_in.sin_port = htons(9);
if (connect(f, (struct sockaddr*)&sock_in, sizeof sock_in) < 0){
error("connect:");
.P2
.KE
.IT
Tedious and clunky
.IT
Protocol-specific details leak thru the API
.IT
C-specific, hard to access from elsewhere without ugly wrapping
.SS "Opening a network connection In Plan 9
.P1
#include <u.h>
#include <libc.h>
...
fd = dial(netmkaddr(argv[1], "tcp", "discard"), 0, 0, 0);
if(fd < 0)
sysfatal("can't dial %s: %r", argv[1]);
.P2
.nr VS 16p
.IT
Clean and simple
.IT
Abstracts the protocol details from the application, addresses
.SS "/net
.P1
/net/cs
/net/dns
/net/tcp/
/net/udp/
/net/etherX/
.P2
.IT
No need for NAT or VPN, just import
.I /net
from the g�ateway or remote host, all applications will use it transparently.
.IT
Can mount multiple local IP stacks concurrently. Each stack is physically independent of all others.
Normally a system uses only one stack. Multiple stacks can be used for debugging, implementing
firewalls or proxy services, eg., ipmux.
.SS "Fossil and Venti
.IT
Venti provides block storage indexed by hash. Duplicated blocks stored only once.
.IT
Fossil: Permanent storage of files with automatic snapshots using Venti for storage.
Examples:
.IT
To see what changes have been made to the user database since the system was setup:
.P1
% history -D /adm/users
.P2
.IT
To compile a kernel with the version of the Intel PRO/1000 ethernet driver from 3 days ago:
.P1
% cd /sys/src/9/pc
% yesterday -b -n 3 ./etherigbe.c
.P2
.SS "Security, factotum and secstore
.LP
No root and no suid.
.LP
When everyone has the same privileges(none), escalation is impossible.
.IT
Namespaces provide isolation, much cleaner and secure than chroot.
.IT
Authentication and encryption implemented in a single place, thru file systems!
.SH
Factotum
.IT
Handles all authentication tasks.
.IT
Transparently for the application.
.IT
Manages keys, keeps private keys secret from applications!
.IT
Can store all keys securely in a
.I secstore
encrypted with a master key (often in remobable media).
.SS "Concurrency with Communicating Sequential Processes
Introduced by Hoare's 1978 paper, based on Dijkstra's work. Book online at:
.B
http://www.usingcsp.com/
.IT
Procs: preemptively scheduled by operating system, shared address space.
.IT
Threads: cooperatively scheduled coroutines within a proc. (
.BI Not
pthreads! think coroutines. )
.IT
Channels: all communication is done through synchronous typed channels.
.LP
Avoids locking and simplifies design of concurrent systems.
.LP
Implementations:
.IT
Alef: compiled language, for systems.
.IT
Limbo: portable, bytecode-based. The main language used in Inferno.
.IT
Libthread: translate Alef programs to C. Lose syntactic sugar.
.IT
Others: Occam, concurrent ML, Moby, Erlang, StacklessPython.
.SS "Inferno/Limbo
Based on the ideas researched in Plan 9 but taking a more radical approach.
.IT
Limbo: New GC concurrent language while keeping the C philosophy.
.IT
Dis: Virtual machine designed for portability and JIT.
.IT
Can run directly on hardware or hosted on almost any operating system (Plan 9,
Linux, *BSD, Solaris, Irix, Windows, MacOS and others.)
.IT
Extremely portable, doesn't require MMU!
.IT
Processes
.B extremely
cheap.
.LP
Inferno and Plan 9 complement each other, for example:
.IT
Can mount
.I /net
in Plan 9 from Inferno instances running on any OS.
.IT
Can debug embeded Inferno systems remotely from Plan 9.
.IT
Can write cross platform applications in Limbo.
.IT
Allows integration of non-Plan 9 systems in a Plan 9 network, Inferno
Grid.
.LP
Released last year under a GPL/MIT dual license.
.SS "The Plan 9 community
.BP plan9-guru.ps
.EP
.ce
If you thought BSD users were arrogant, you aint seen nuthing.
.SS "Conclusions
.IT
Plan 9 shares the Unix spirt of simplicity, clarity and generality.
.IT
But despite some superficial similarities, it is very different; be ready to unlearn all you know.
.IT
If you can't give up what you are used to, there is still a lot to learn from Plan 9.
.IT
Chances are that the kind of problems you are facing are not too different from the ones Plan 9 has tried to solve;
looking at Plan 9 you might be surprised by simpler solutions than you thought possible.
.SS "Resources and references
.I http://9fans.net
- The main Plan 9 website.
.I http://plan9.bell-labs.com/sys/doc/
- The main collection of papers.
.I http://plan9.bell-labs.com/wiki/plan9/Papers/
- Other papers and publications.
.I http://www.vitanuova.com/inferno/net_download4T.html
- Inferno.
.I http://plan9.us
- Plan 9 from User Space for Unix systems.
.I
http://www.usingcsp.com/ - Communicating Sequential Processes
.R
by Tony Hoare.
|