Top Banner
2010210日 グリー勉強会 oraccha@Plan9日記
47

Plan 9のお話

Jun 28, 2015

Download

Technology

Ryousei Takano

2009-02-10 第20回グリーオープンソーステクノロジー勉強会
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Plan 9のお話

2010年2月10日 グリー勉強会

oraccha@Plan9日記

Page 2: Plan 9のお話

本日のお題• Plan 9とはどんなOSか?

• 「すべてがファイル」という思想• Plan 9のプログラミング環境

• 「軽快なPlan 9」(@go_vmさん)

Page 3: Plan 9のお話

Plan 9とは?UNIXを開発したベル研の連中が開発した分散OS

1995

Dennis Ritchie

Dave Presotto

Rob Pike

Phil Winterbottom

Page 4: Plan 9のお話

Plan 9とは?UNIXを開発したベル研の連中が開発した分散OS

2004

Jim McKie

1995

Dennis Ritchie

Dave Presotto

Rob Pike

Phil Winterbottom

Page 5: Plan 9のお話

Plan 9とGoogle

• Rob Pike、Ken Thompson、Russ Coxなど主力開発者がGoogleへ

http://undergoogle.com/tools/GoogleMasterPlanEN.html

Google OSPlan 9

Plan 10

Plan 11?

Page 6: Plan 9のお話

GopherGlen and Glenda

Illustrated by Renée French

Page 7: Plan 9のお話

なぜ、Plan 9なのか?

“Not only is UNIX dead, it’s starting to smell really bad.” -- Rob Pike, 1991

Page 8: Plan 9のお話

UNIXに勝てなかったPlan 9

“the most dangerous enemy of a better solution is an existing codebase that is just good enough”

-- Eric Raymond, “The art of UNIX Programming”

参照:西村賢「Linuxに勝てなかったPlan 9」@IT (2009)

Page 9: Plan 9のお話

UNIXに与えた影響• procファイルシステム

• ダンプファイルシステム• ユーザレベルファイルシステム• rfork、cloneシステムコール

• プロセス毎の名前空間• ユニオンディレクトリ• UTF-8         などなど

Page 10: Plan 9のお話

分散OS Plan 9の全体像!"#"!

$%& '()*+,*-.&*%/ 0(,1-/$/.(%- (, 23-4 5$66*& /*,).%$6- .% 26$% 7 /*,).%(6(89: ;.8<,*="-'(0-"/'*"$,,$%8*)*%/:

32> 32>;.6* ;.6*

?%/*,%*/

@$/*0$9

@$/*0$9

A*,)

A*,) A*,) A*,)

B/'*,%*/

;.C*,"D*/0(,1

E$/$1./

A*,)A*,)A*,)

!"#$%& '( )*%$+*$%& ,- . /.%#& 0/.1 2 "13*.//.*",1( 32> -*,F*,- $%& G.6* -*,F*,- -'$,* G$-/ 6(5$6+$,*$

%*/0(,1-4 0'.6* /*,).%$6- <-* -6(0*, 0.&*,+$,*$ %*/0(,1- -<5' $- B/'*,%*/4 E$/$1./4 (, /*6*H'(%*

6.%*- /( 5(%%*5/ /( /'*): @$/*0$9 )$5'.%*-4 0'.5' $,* I<-/ 32> -*,F*,- 5(%%*5/*& /( )<6/.H6* %*/!

0(,1-4 $66(0 )$5'.%*- (% (%* %*/0(,1 /( -** $%(/'*,:

A'* )(&*,% -/96* (G 5()H</.%8 (GG*,- *$5' <-*, $ &*&.5$/*& 0(,1-/$/.(% (, 23:26$% 7!- $HH,($5' .- &.GG*,*%/: A'* F$,.(<- )$5'.%*- 0./' -5,**%-4 1*9C($,&-4 $%& ).5*$66 H,(F.&* $55*-- /( /'* ,*-(<,5*- (G /'* %*/0(,14 -( /'*9 $,* G<%5/.(%$669 *J<.F$6*%/4 .%/'* )$%%*, (G /'* /*,).%$6- $//$5'*& /( (6& /.)*-'$,.%8 -9-/*)-: K'*% -()*(%* <-*-/'* -9-/*)4 /'(<8'4 /'* /*,).%$6 .- /*)H(,$,.69 H*,-(%$6.L*& C9 /'$/ <-*,: ?%-/*$& (G5<-/().L.%8 /'* '$,&0$,*4 26$% 7 (GG*,- /'* $C.6./9 /( 5<-/().L* (%*!- F.*0 (G /'* -9-!/*) H,(F.&*& C9 /'* -(G/0$,*: A'$/ 5<-/().L$/.(% .- $55()H6.-'*& C9 8.F.%8 6(5$64 H*,!-(%$6 %$)*- G(, /'* H<C6.569 F.-.C6* ,*-(<,5*- .% /'* %*/0(,1: 26$% 7 H,(F.&*- /'* )*5'!$%.-) /( $--*)C6* $ H*,-(%$6 F.*0 (G /'* H<C6.5 -H$5* 0./' 6(5$6 %$)*- G(, 86(C$669$55*--.C6* ,*-(<,5*-: M.%5* /'* )(-/ .)H(,/$%/ ,*-(<,5*- (G /'* %*/0(,1 $,* G.6*-4 /'*)(&*6"(G"/'$/"F.*0".-"G.6*+(,.*%/*&:

A'* 56.*%/!- 6(5$6 %$)* -H$5* H,(F.&*- $ 0$9 /( 5<-/().L* /'* <-*,!- F.*0 (G /'*%*/0(,1: A'* -*,F.5*- $F$.6$C6* .% /'* %*/0(,1 $66 *NH(,/ G.6* '.*,$,5'.*-: A'(-* .)H(,!/$%/ /( /'* <-*, $,* 8$/'*,*& /(8*/'*, .%/( $ 5<-/() %$)* -H$5*O /'(-* (G %( .))*&.$/*.%/*,*-/ $,* .8%(,*&: A'.- .- $ &.GG*,*%/ -/96* (G <-* G,() /'* .&*$ (G $ "<%.G(,) 86(C$6%$)* -H$5*!: ?% 26$% 74 /'*,* $,* 1%(0% %$)*- G(, -*,F.5*- $%& <%.G(,) %$)*- G(, G.6*-*NH(,/*& C9 /'(-* -*,F.5*-4 C</ /'* F.*0 .- *%/.,*69 6(5$6: P- $% $%$6(894 5(%-.&*, /'*&.GG*,*%5* C*/0**% /'* H',$-* ")9 '(<-*! $%& /'* H,*5.-* $&&,*-- (G /'* -H*$1*,!-'()*: A'* 6$//*, )$9 C* <-*& C9 $%9(%* C</ /'* G(,)*, .- *$-.*, /( -$9 $%& )$1*--*%-* 0'*% -H(1*%: ?/ $6-( 5'$%8*- )*$%.%8 &*H*%&.%8 (% 0'( -$9- ./4 9*/ /'$/ &(*-

出典:Rob Pike, “Plan 9 from Bell Labs” (1995)

共有メモリ型SMPマシン

WORM jukebox

WS or PC

資源へのアクセスは共通なプロトコル使用

Page 11: Plan 9のお話

Plan 9の核となるアイデア

• すべてがファイル• 9Pプロトコル

• プロセスごとの名前空間

Page 12: Plan 9のお話

「すべてがファイル」• すべて資源は名前(パス名)を持つ

• バイトストリームのopen-read-write-close

Page 13: Plan 9のお話

そして、時は流れ...

ハードウェアが進歩して、UNIXは拡張されたが、そこに「UNIX哲学」はなかった

• GUI

• Xウィンドウシステム(MIT)

• ネットワーキング

• ソケット(UCB)

Page 14: Plan 9のお話

「ファイル」メタファ• UNIXはたいていのものがファイル

O /dev/tty, /proc

X network interface, X window system

• Plan 9はすべてがファイル

O /dev/cons, /proc, network interface, rio window system, http, ftp, environment variable

X プロセス生成、ネットワークアドレス、共有メモリ

Page 15: Plan 9のお話

ウィンドウもファイル• 全画面:/dev/screen

• 各ウィンドウ:/dev/window、/dev/wsys/*/window

• デモ:スクリーンショット

Page 16: Plan 9のお話

rioウィンドウシステム• /dev/^(cons mouse window)をプロセス毎に多重化するファイルサーバ

rioapp.

app.

app.User

Kernel #s #m

read /dev/mouseread /dev/mouse

Page 17: Plan 9のお話

/net

• ネットワークもファイルとして抽象化net

ether0 tcp udp cs dns

clone stats0 1

listenerrdatactl local remote status

デバイス プロトコルスタック サービス

Page 18: Plan 9のお話

/net/tcp• /net/tcp/N:コネクション毎ディレクトリ

• ctl:制御用ファイル

• data:データ通信用ファイル

• /net/tcp/clone:新規にディレクトリ作成% lc /net/tcp0 1 10 ... clone stats

% lc /net/tcp/0ctl data err listen localremote status

Page 19: Plan 9のお話

echoクライアント% cat /net/tcp/clone

5

% cat > /net/tcp/clone

connect 192.168.182.130!7

% cat /net/tcp/5/data &

% echo hoge > /net/tcp/5/data

echo

terminal 2:

terminal 1:

open(“/net/tcp/clone”)はopen

(“/net/tcp/*/ctl”)と等価

Page 20: Plan 9のお話

echoサーバ• listen(UNIXのinetd相当)経由で実行

• ポート監視して、ネットワークをstdioにつなぎ替える

% aux/listen1 -t tcp!*!7 /bin/service/tcp7 &

% cat /bin/service/tcp7

#!/bin/rc

/bin/cat

Page 21: Plan 9のお話

tcpdumpモドキ#!/bin/rcclonefile=/net/ether0/clone<[4] $clonefile { netdir=`{basename -d $clonefile} ^ / ^ `{cat /fd/4} echo connect -1 >$netdir/ctl || exit 'cannot connect' cat $netdir/data | xd -u -x2}

Page 22: Plan 9のお話

ネットワーキングAPI• ネットワーク操作もファイルへの

open-read-write-closeで可能

(Plan 9にioctlはない)

• BSDソケットのように、専用システムコールは不要

• 使いやすいライブラリ関数を提供

Page 23: Plan 9のお話

echoクライアントint fd, n;

char *name;

name = netmkaddr(“plan9.bell-labs.com”, “tcp”, “echo”);

fd = dial(name, 0, 0, 0);

:n = write(fd, buf, sizeof(buf));

read(1, buf, n);

“204.178.31.2!echo

Page 24: Plan 9のお話

echoサーバint acfd, lcfd, dfd, n;char adir[40], ldir[40]acfd = announce("tcp!*!7", adir);for (;;) { lcfd = listen(adir, ldir); switch (fork()) { case 0: dfd = accept(lcfd, ldir); while ((n = read(dfd, buf, sizeof(buf))) > 0) write(dfd, buf, n); exits(0); }}

/net/tcp/5

/net/tcp/6

注意:UNIXとは別物

Page 25: Plan 9のお話

BSDソケットとの比較Plan 9 BSD socket 説明dial

socketactive open用fdの取得

announcesocket

passive open用fdの取得dial connect active open

- bind アドレスの割当てannounce listen 接続待ち

listen/accept accept 接続の受付reject close 接続の切断

- shutdown接続の切断

Page 26: Plan 9のお話

重要なアイデア

Plan 9カーネル=「サービスの多重化装置」

• 資源アクセスインタフェースの共通化

• カーネルインタフェースの簡素化

UNIXカーネル=「I/Oの多重化装置」

Page 27: Plan 9のお話

使ってみようPlan 9

• まずはスタンドアローン版から

• ターミナル+fossil(ファイルサーバ)

• Go Plan 9 wiki!

http://plan9.bell-labs.com/wiki/plan9/

Page 28: Plan 9のお話

対応アーキテクチャ• i386、AMD64、ARM、PowerPC、...

• (仮想化技術いろいろ)KVM、QEMU、Virtual Box、VMWare、Xen、 lguest

• 最近一部で話題なのは、

Page 29: Plan 9のお話

UNIXで動くPlan 9環境• Plan9port

• Plan 9コマンドセットのUNIX移植

• 9vx

• 軽量なa.outバイナリエミュレーション

• Plan 9カーネルをユーザランドに移植

• Glandix

• Linuxカーネル拡張

Page 30: Plan 9のお話

drawterm

• UNIXからPlan 9 CPUサーバに接続するためのグラフィカルターミナル

• おまけ機能:/mnt/termにローカルファイルシステムをmount

Page 31: Plan 9のお話

プログラミング環境• kencc: ANSI Cじゃないコンパイラ

• acme: プログラマのためのエディタ(ただしマウスは必須)

• acid: マルチアーキ対応デバッグ環境

• APE: POSIX互換サブシステム

Page 32: Plan 9のお話

kencc:奇妙なコマンド名compiler assembler loader

SPARC kc ka klPower PC qc qa qlMIPS (BE) vc va vlMIPS (LE) 0c 0a 0l

Motorola 68000 1c 1a 1lMotorola 68020 2c 2a 2l

ARM (LE) 5c 5a 5lAMD64 Intel 960 6c 6a 6l

DEC Alpha 7c 7a 7lIntel 386 8c 8a 8l

AMD 29000 9c 9a 9l

Page 33: Plan 9のお話

acme: テキストエディタ

パネル

カラム

タグ

Page 34: Plan 9のお話

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.

Page 35: Plan 9のお話

まずは、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

Page 36: Plan 9のお話

見慣れないヘッダファイル% 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

Page 37: Plan 9のお話

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

Page 38: Plan 9のお話

ライブラリのリンク% 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”

Page 39: Plan 9のお話

./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

Page 40: Plan 9のお話

環境変数もファイル% 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

Page 41: Plan 9のお話

ユニオンディレクトリ

% 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に

Page 42: Plan 9のお話

デバッグ• 異常終了してもコアダンプしない!

• 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()

Page 43: Plan 9のお話

FAQ• ブートしたはいいがリブート方法がわからない

• ウィンドウがスクロールしない

• Ctrl-Cが効かない

• UNIXのあのコマンド・オプションはないの?

• ホストOSとファイル共有したい

• システムを最新に保つには?

• createシステムコール

• 動的リンクがないって本当?

• 日本語は読み書きできるの?

Page 44: Plan 9のお話

Plan 9は死なず!ベル研が開発の中心でなくなったが、オープンソースソフトウェアとして開発継続

An army of Glendas take over IBM’s Blue Gene!!

Page 45: Plan 9のお話

宣伝• 2/23 第三回カーネル/VM探検隊@IIJ

• 今回はPlan 9大会かも!?

• 3月? Plug 9ハッカソン@つくば

一緒にPlan 9で遊んでみませんか?

Page 46: Plan 9のお話

続きは懇親会で

Plan9日記(http://d.hatena.ne.jp/oraccha/)@glenda9pもよろしく

Page 47: Plan 9のお話

なぜ、Plan 9なのか?“Narrowness of experience leads to narrowness of imagination..”

-- Rob Pike, “Systems Software Research is Irrelevant”,

2000