情報学類 分散システム					2008年01月22日
                                       筑波大学システム情報工学研究科
                                       コンピュータサイエンス専攻, 電子・情報工学系
                                       新城 靖
                                       <yas@is.tsukuba.ac.jp>
このページは、次の URL にあります。
	http://www.coins.tsukuba.ac.jp/~yas/coins/dsys-2007/2008-01-22
あるいは、次のページから手繰っていくこともできます。
	http://www.coins.tsukuba.ac.jp/~yas/
	http://www.cs.tsukuba.ac.jp/~yas/
NFS ( Network File System ) は, Sun Microsystems 社が 開発したネットワーク・ファイル・システムの名前(固有名詞, 商標)。
その他のネットワーク・ファイル・システム(用のプロトコル)
NFSを使うと, ネットワークを通じて別のコンピュータ上のファイルシステム
の一部分を, ローカルディスク上にあるファイルシステムと同じように, 自分
のファイルシステムの木に
マウント(mount)
できる。
 図? NFSによるファイルの共有
相互に参照し合える。
nfsd というプログラムが
動いているように見える(
ps コマンドで表示される)
が、それは普通のプロセスではない。
/usr/include/rpcsvc/nfs_prot.x
 表? NFSで使われているRPCの手続き
| 手続き名 | 意味 | 関連するコマンド、システムコール | 
|---|---|---|
| null() | 何もしない | rpcinfo -u hostname nfsコマンド | 
| getattr() | 属性の読み出し | ls -lコマンド,statシステムコール ,openシステムコール | 
| setattr() | 属性の設定 | chmod,chownコマンド | 
| lookup() | ファイルの検索 | openシステムコール | 
| readlink() | シンボリックリンクの読み出し | ls -lコマンド,readlinkシステムコール | 
| read() | ファイルの読み出し | readシステムコール | 
| write() | ファイルの書き込み | writeシステムコール | 
| create() | ファイルの作成 | creatシステムコール,openシステムコール | 
| remove() | ハードリンクの削除 | rmコマンド,unlinkシステムコール | 
| rename() | ファイル名前の変更 | mvコマンド,renameシステムコール | 
| link() | ハードリンクの作成 | lnコマンド,linkシステムコール | 
| symlink() | シンボリックリンクの作成 | ln -sコマンド,symlinkシステムコール | 
| mkdir() | ディレクトリの作成 | mkdirコマンド | 
| rmdir() | ディレクトリの削除 | rmdirコマンド | 
| readdir() | ディレクトリの読み出し | lsコマンド | 
| statfs() | ファイルシステムの利用状況 | dfコマンド,statfsシステムコール | 
| commit()* | ディスクへの書き込み | fsyncシステムコール | 
| access()* | アクセス権のチェック | accessシステムコール | 
NFS でファイルやディレクトリを区別するための識別子。32バイト。
const NFS_FHSIZE	= 32;
...
/*
 * File access handle
 */
struct nfs_fh {
	opaque data[NFS_FHSIZE];
};
一番最初のNFSファイル・ハンドルをどうやって入手するか。
| 手続き名 | 意味 | 関連するコマンド、 システムコール | 
|---|---|---|
| null() | 何もしない | rpcinfo -u hostname mountコマンド | 
| mnt() | NFSファイルハンドルを返す | mountコマンド | 
| dump() | マウント一覧表 | showmount hostnameコマンド | 
| umnt() | アンマウント | umountコマンド | 
| umntall() | 全アンマウント | umount -h hostnameコマンド | 
| export() | アクセス可能なディレクトリのリストを返す | 
2.2.5.  Look Up File Name
	diropres
	NFSPROC_LOOKUP(diropargs) = 4;
If the reply "status" is NFS_OK, then the reply "file" and reply
"attributes" are the file handle and attributes for the file "name"
in the directory given by "dir" in the argument.
2.3.10.  diropargs
    struct diropargs {
	fhandle  dir;
	filename name;
    };
The "diropargs" structure is used in directory operations.  The
"fhandle" "dir" is the directory in which to find the file "name".
A directory operation is one in which the directory is affected.
2.3.11.  diropres
    union diropres switch (stat status) {
    case NFS_OK:
	struct {
	    fhandle file;
	    fattr   attributes;
	} diropok;
    default:
	void;
    };
The results of a directory operation are returned in a "diropres"
structure.  If the call succeeded, a new file handle "file" and
the "attributes" associated with that file are returned along with
the "status".
2.2.7.  Read From File
	struct readargs {
		fhandle file;
		unsigned offset;
		unsigned count;
		unsigned totalcount;
	};
	union readres switch (stat status) {
	case NFS_OK:
		fattr attributes;
		nfsdata data;
	default:
		void;
	};
	readres
	NFSPROC_READ(readargs) = 6;
Returns up to "count" bytes of "data" from the file given by "file",
starting at "offset" bytes from the beginning of the file.  The first
byte of the file is at offset zero.  The file attributes after the
read takes place are returned in "attributes".
Notes:  The argument "totalcount" is unused, and is removed in the
next protocol revision.
2.2.9.  Write to File
	struct writeargs {
		fhandle file;
		unsigned beginoffset;
		unsigned offset;
		unsigned totalcount;
		nfsdata data;
	};
	attrstat
	NFSPROC_WRITE(writeargs) = 8;
Writes "data" beginning "offset" bytes from the beginning of "file".
The first byte of the file is at offset zero.  If the reply "status"
is NFS_OK, then the reply "attributes" contains the attributes of the
file after the write has completed.  The write operation is atomic.
Data from this "WRITE" will not be mixed with data from another
client's "WRITE".
Notes:  The arguments "beginoffset" and "totalcount" are ignored and
are removed in the next protocol revision.
RPC のようにコネクションが作られない通信サービスを使う時に冪等や無状態 といった性質を実現する時に必要になる技術。
例:NFSでのディレクトリの読み込み手続き nfsproc_readdir() で、1回の RPC で全部のデータを返せないことが起きる。 ディレクトリのどの位置まで読み込んだかを 示す中間状態を クッキー(cookie) という形でクライアントに返す。
クライアントは、次の RPC の呼び出しで、 前回受けとった応答の中のクッキーを、サーバへの要求に含めて送す。
const NFS_COOKIESIZE = 4; typedef opaque nfscookie[NFS_COOKIESIZE];
2.2.17.  Read From Directory
	 struct readdirargs {
		 fhandle dir;
		 nfscookie cookie;
		 unsigned count;
	 };
	 struct entry {
		 unsigned fileid;
		 filename name;
		 nfscookie cookie;
		 entry *nextentry;
	 };
	 union readdirres switch (stat status) {
	 case NFS_OK:
		 struct {
			 entry *entries;
			 bool eof;
		 } readdirok;
	 default:
		 void;
	 };
	 readdirres
	 NFSPROC_READDIR (readdirargs) = 16;
 Returns a variable number of directory entries, with a total size of
 up to "count" bytes, from the directory given by "dir".  If the
 returned value of "status" is NFS_OK, then it is followed by a
 variable number of "entry"s.  Each "entry" contains a "fileid" which
 consists of a unique number to identify the file within a filesystem,
 the "name" of the file, and a "cookie" which is an opaque pointer to
 the next entry in the directory.  The cookie is used in the next
 READDIR call to get more entries starting at a given point in the
 directory.  The special cookie zero (all bits zero) can be used to
 get the entries starting at the beginning of the directory.  The
 "fileid" field should be the same number as the "fileid" in the the
 attributes of the file.  (See section "2.3.5. fattr" under "Basic
 Data Types".)  The "eof" flag has a value of TRUE if there are no
 more entries in the directory.
nfsproc_readdir() で、1回目と2回目の RPC の間にディレクトリの内容が 更新された場合、どのような結果になるのか不明。
commit() という手続きが追加。
それまでに行われた書き込みをディスクに行うように指示できる。
(NFS v2 では、write で必ずディスクに書き込む。)
昔の名前は、 SMB (Server Message Block) プロトコル。 Samba は、 CIFS/SMB を、Unix 系のオペレーティング・システムで実現したプログラム。
Samba の利用法
オブジェクトは、専門家(人間)と対比される。

図? スタック・オブジェクト

図? スタック・オブジェクト(分散システム)
| RPC (Remoe Procedure Call) | 分散オブジェクト | 
| 手続き型言語 | オブジェクト指向言語 | 
| 手続き | メソッド | 
| クライアント側スタブ | スタブ | 
| サーバ側スタブ | スケルトン | 
| インタフェース記述言語 | インタフェース記述言語 | 
| バインディング | 発見(discovery) | 
| ポインタ、参照がない | オブジェクトへの参照が渡せる | 
様々なプログラミング言語のオブジェクトを相互に接続できる。
RPC, ORB は、middleware の一種。 分散OSなどでは、RPC を直接 OS が実装することもある。
Middleware == CORBA という思想の人もいた。
CORBA は、C++風のインタフェース定義言語を持つ。
特徴
例:
   1: module Counter
   2: {
   3:     interface Counter
   4:     {
   5:         void up();
   6:         long getValue();
   7:         void reset(in long newVal);
   8:     };
   9: };
% ls ![[←]](../icons/screen-return.gif) Counter.idl
% idlj Counter.idl
Counter.idl
% idlj Counter.idl ![[←]](../icons/screen-return.gif) % ls -l
% ls -l ![[←]](../icons/screen-return.gif) total 8
drwxr-xr-x   7 yas  prof  238 Jan 21 19:14 Counter
-rw-r--r--   1 yas  prof  114 Feb  7  2002 Counter.idl
% ls Counter
total 8
drwxr-xr-x   7 yas  prof  238 Jan 21 19:14 Counter
-rw-r--r--   1 yas  prof  114 Feb  7  2002 Counter.idl
% ls Counter ![[←]](../icons/screen-return.gif) Counter.java            CounterHolder.java      _CounterStub.java
CounterHelper.java      CounterOperations.java
%
Counter.java            CounterHolder.java      _CounterStub.java
CounterHelper.java      CounterOperations.java
% ![[]](../icons/screen-cursor.gif) 
Counter.idl を元にして、ディレクトリ Counter/ 以下にい
くつかのファイルが作られる。
COM の利用法
COM では、別プロセス(別のアドレス空間)にRPCをする方法の他に、 同一アドレス空間内で、動的リンク技術で動作させられるものもある。
http://horb.aist.go.jp/horb-j/
RMI は、いくつかの層を見えなくする。
Web サービスを、一般の World Wide Web と紛れないように呼ぶ時には、「XML Web サービス」と 頭に XML を使う。
XML は、歴史的に、HTML の反省で作られた。 メッセージの送受信には、HTTP が使われる。
XML サービスでよく使われている遠隔手続き呼出しの仕組みは、 XML-RPC と SOAP である。
Web サービスでは、異なるプログラミング言語で書かれたコンポーネントも相 互に接続できる。
XML-RPCは、クライアントとサーバの間で交換されるメッセージとして XML を 用いる RPC の標準の一種である。一般的な概念というよりは、特定の標準を意 味する。
XML-RPC では、クライアントとサーバの間の通信は、XML により行われる。ク ライアントは、手続きの名前や入力パラメタを XML の形式にまとめて、サーバ へ送る。サーバでは、手続きが実行され、その結果もXMLの形でクライアントへ 返される。 XML-RPC では、クライアントとサーバの間の通信には、WWW で使わ れている HTTP が使われる。
XML-RPC では、メッセージが長くなり過ぎたり、型付けに問題があった。これ を解決するために、SOAP が作られた。
SOAP は、最初は、Simple Object Access Protocol の略であったが、 Object-Oriented ではないということで、この略は捨てられた。
XML-RPC では、データを交換するための中間形式として XML を使っていただけ であったが、SOAP では、XML のデータを直接 XML として渡すことができる。
SOAP では、HTTP の他に電子メールも通信媒体として使う事ができる。 SOAP 用に、HTTP のヘッダがいくつか拡張されたが、実際問題として活用しに くい。 SOAP は、Microsoft 社などにより提案され、その後、W3C で標準化が行われ ている。