今日から始めるplan 9 from bell labs
DESCRIPTION
第一回カーネル・VM探検隊。2009-08-10TRANSCRIPT
今日からはじめるPlan 9 from Bell Labs
oracchaPlan9日記(http://d.hatena.ne.jp/oraccha/)
2009年8月10日 第一回カーネル/VM探検隊
Plan 9とは?
本日の発表
• Plan 9とはどんなOSか?
• 9vxでPlan 9を始めよう
• Plan 9のプログラミング環境
Plan 9とは?UNIXを開発したベル研の連中が開発した分散OS
1995
Dennis Ritchie
Dave Presotto
Rob Pike
Phil Winterbottom
Plan 9とは?UNIXを開発したベル研の連中が開発した分散OS
2004
Jim McKie
1995
Dennis Ritchie
Dave Presotto
Rob Pike
Phil Winterbottom
Plan 9は死なず!現在、ベル研が開発の中心でなくなったが、オープンソースソフトウェアとして開発継続
• 最新スパコン(BlueGene/P)に対応
• Google Summer of Code参加
• 年に一度International Workshop開催
なぜ、Plan 9なのか?
“Not only is UNIX dead, it’s starting to smell really bad.” -- Rob Pike, 1991
過去のしがらみ例えば、xterm...
Window Shell
User
ASR-33
Plan 9が提案したアイデア
• すべてがファイル• 9Pプロトコル
• プロセスごとの名前空間
「すべてがファイル」• すべて資源は名前(パス名)を持つ
• バイトストリームのopen-read-write-close
初期のUNIXカーネル
Process
UFS
Char device
Block device
UFSInterface
Char Interface
Block Interface
Kernel
そして、時は流れ...
ハードウェアが進歩して、UNIXは拡張されたが、そこに「UNIX哲学」はなかった
• ネットワーキング
• ソケット(UCB)
• GUI
• Xウィンドウシステム(MIT)
肥大化するカーネル構造
Process
VFS
Char device
Block device
VFSInterface
Char Interface
Block Interface
Socket Other file system
sysfs
Sysctl
Lotsa stuff! UFS
よりよいモデル
ProcessServer
Device
ServerInterface
Kernel
Plan 9カーネル
Process
Server (process)for email file system
Server (process)for local file system
ServerInterface
Kernel
Device
9p2000 protocol
9Pプロトコルクラス オペコード 説明
セッション
version パラメータネゴシエーション
セッションauth 認証
セッション attach コネクションの確立セッションflush リクエストのアボート
セッション
error エラーの応答
ファイル
walk パス名の検索
ファイル
open ファイルのオープン
ファイルcreate ファイルの作成
ファイル read ファイルからデータ転送ファイルwrite ファイルへデータ転送
ファイル
clunk ファイルの解放
ファイル
remove ファイルの削除
メタデータstat ファイル属性の取得
メタデータwstat ファイル属性の更新
重要なアイデア
Plan 9カーネル=「サービスの多重化装置」
• すべての資源に対する単一のI/F
• すべてのサーバに対する共通プロトコル
UNIXカーネル=「I/Oの多重化装置」
名前空間
Plan 9 UNIX
プロセス毎の名前空間システムグローバルなファイル空間
ユーザ権限 root権限
サービスを多重化 ディスクを多重化
UNIXに与えた影響• 9Pファイルシステムプロトコル
• procファイルシステム
• ダンプファイルシステム
• rfork、cloneシステムコール
• ユニオンディレクトリ
• UTF-8 などなど
対応アーキテクチャ
• i386、AMD64、ARM、PowerPC、SPARC
• (仮想化技術)KVM、QEMU、Virtual
Box、VMWare、Xen、KVM、 lguest
• MIPSにも対応していたが、過去の話
UNIXで動くPlan 9環境• Plan9port
• Plan 9コマンドの移植
• v9fsと連携
• 9vx
• Plan 9カーネルをユーザランドで実行
• 軽量なバイナリエミュレーション
• Drawterm
• ターミナルアプリケーション
9vx
Plan 9a.out
Plan 9a.out
Plan 9a.out
vx32 sandbox library
Modified Plan 9 kernel
Host OS(Linux, FreeBSD, MacOS X)
1プロセス
9vx TIPS
• x86_64で実行する場合は、Mercurialリポジトリからビルド
- http://code.google.com/p/vx32/
• Plan 9本体のライブラリやソースコードが含まれないので、リポジトリから取得% 9fs sources% cd /n/sources% @{cd plan9/386/lib && tar c .} | \ @{cd /386/lib && tar x}
プログラミング環境• acme: プログラマのためのエディタ(ただしマウスは必須)
• kencc: ANSI Cじゃないコンパイラ
• acid: マルチアーキ対応デバッグ環境
• APE: POSIX互換サブシステム
man emacs(1)EMACS(1)
NAME emacs - editor macros
SYNOPSIS emacs [ options ]
DESCRIPTION This page intentionally left blank.
SOURCE MIT
SEE ALSO sam(1), vi(1)
BUGS Yes.
kencc: 指示付き初期化子rio/rio.c
58: enum 59: { 60: Cut, 61: Paste, 62: Snarf, 63: Plumb, 64: Send, 65: Scroll, 66: }; 67: 68: char *menu2str[] = { 69: [Cut] "cut", 70: [Paste] "paste", 71: [Snarf] "snarf", 72: [Plumb] "plumb", 73: [Send] "send", 74: [Scroll] "scroll", 75: nil 76: };
C99と文法が異なる[Cut] = “cut”,
kencc: 匿名構造体、複合リテラル
• rio/dat.h 107 struct Mousestate 108 { 109 Mouse; 110 ulong counter; 111 };
rio/wind.c 305: m = (Mousestate){w->mc.Mouse, w->mouse.counter};
• Linuxカーネルでは使われていない?
まずは、Hello, World!% cat hello.c#include <u.h>#include <libc.h>
void main(){ print(“Hello, World!\n”); exits(nil);}
% 8c hello.c% 8l -o hello hello.8% hello
見慣れないヘッダファイル% cat hello.c#include <u.h>#include <libc.h>
void main(){ print(“Hello, World!\n”); exits(nil);}
% 8c hello.c% 8l -o hello hello.8% hello
ANSI C/POSIXじゃない% cat hello.c#include <u.h>#include <libc.h>
void main(){ print(“Hello, World!\n”); exits(nil);}
% 8c hello.c% 8l -o hello hello.8% hello
ライブラリのリンク% cat hello.c#include <u.h>#include <libc.h>
void main(){ print(“Hello, World!\n”); exits(nil);}
% 8c hello.c% 8l -o hello hello.8% hello
include/libc.h:1: #pragma lib “libc.a”2: #pragma src “/sys/src/libc”
./helloじゃない% cat hello.c#include <u.h>#include <libc.h>
void main(){ print(“Hello, World!\n”); exits(nil);}
% 8c hello.c% 8l -o hello hello.8% hello
環境変数もファイル% ls /env'*' boottime 'fn#sigexit'pid terminal0 cflag font prompt timezoneNPROC cputype fs rcname userapid ether0 home rootdir wctlauth facedom ifs service wsysbootargs fileserver objtype statusbootfile 'fn#cpu%'path sysname
% cat /env/path./bin
ユニオンディレクトリ
% ns | grep /binbind /386/bin /binbind -a /rc/bin /binbind -a /usr/oraccha/bin/rc /binbind -a /usr/oraccha/bin/386 /bin
※Linuxにもaufs、unionfsなどファイルシステムレベルで同様の仕掛けを実現するものは存在する
• 複数のディレクトリを一つに統合
例)すべての実行ファイルは/binに
デバッグ• 異常終了してもコアダンプしない!
• acid(1)デバッガ
• リモートデバッグも/procをimportするだけ
% foofoo 151: suicide: sys: trap: page fault pc=0x00001025% ps | grep fooglenda 151 0:00 0:00 8K Broken foo
% acid 151/proc/151/text: 386 plan 9 executable :acid: stk()
Plan 9のコードを読む• Webから:http://plan9.bell-labs.com/
sources/plan9/sys/src/
• (非公式)gitリポジトリ:git://github.com/
ericvh/plan-9.git
sys -- src |-- 9 # kernel | |-- pc | `-- port |-- cmd # uesr command `-- libc # libc library
続きは飲み会で
Plan9日記(http://d.hatena.ne.jp/oraccha/)