分散システム
                                       電子・情報工学系
                                       新城 靖
                                       <yas@is.tsukuba.ac.jp>
このページは、次の URL にあります。
	http://www.hlla.is.tsukuba.ac.jp/~yas/coins/dsys-1998/1999-01-19
/nfs.html
あるいは、次のページから手繰っていくこともできます。
	http://www.hlla.is.tsukuba.ac.jp/~yas/coins/
	http://www.hlla.is.tsukuba.ac.jp/~yas/index-j.html
分散ファイル・システムまでは、行っていない。
NFSを使うと, ネットワークを通じて別のコンピュータ上のファイルシステム
の一部分を, ローカルディスク上にあるファイルシステムと同じように, 自分
のファイルシステムの木に
接ぎ木(
マウント(mount)
)
することができる。
 NFSによるファイルの共有
host1 は host2 の 
/home/home2 を自分自身の /home/home2 
にマウントしている。host1 で 
/home/home2 の下のファイルをアクセスすると,
host2 にあるファイルをアクセスすることになる。
普通のプログラムは, /home/home1 の下のローカルディスク
上のファイルと, /home/home2 の下の別のホストのディスク
上にあるファイルを区別できない。若干の制限が残る。

NFSによるファイルの共有
NFSは、SunRPC 上で動いている。データの転送は、UDP/IP (V2/V3)または、 TCP/IP (V3) 。
-------------------------------------------------------------------------------- 手続き名 意味 関連するコマンド、 システムコール -------------------------------------------------------------------------------- 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 Version 3 の新しい手続き。
NFS では、ファイルは、「NFSファイルハンドル」と呼ばれる32バイトの整 数で識別される。
const NFS_FHSIZE	= 32;
struct nfs_fh {
	opaque data[NFS_FHSIZE];
};
ファイルハンドルは、ディレクトリに対するlookup() 手続きで返される。
一番最初のファイルハンドルは、NFS マウントプロトコルで取られる。
 ◆NFSマウントプロトコルのRPCの手続き
-------------------------------------------------------------------------------- 手続き名 意味 関連するコマンド、 システムコール -------------------------------------------------------------------------------- null() 何もしないrpcinfo -u hostname mountコマンド mnt() NFSファイルハンドルを返すmountコマンド dump() マウント一覧表showmount hostnameコマンド umnt() アンマウントumountコマンド umntall() 全アンマウントumount -h hostnameコマンド export() アクセス可能なディレクトリのリストを返す --------------------------------------------------------------------------------
重要なのは、mnt() だけ。
◆/usr/include/rpcsvc/nfs_prot.x
----------------------------------------------------------------------
program NFS_PROGRAM {
	version NFS_VERSION {
		void 
		NFSPROC_NULL(void) = 0;
		attrstat 
		NFSPROC_GETATTR(nfs_fh) =	1;
...
		diropres 
		NFSPROC_LOOKUP(diropargs) = 4;
...
		readres 
		NFSPROC_READ(readargs) = 6;
...
		attrstat
		NFSPROC_WRITE(writeargs) = 8;
		diropres
		NFSPROC_CREATE(createargs) = 9;
	} = 2;
} = 100003;
----------------------------------------------------------------------
----------------------------------------------------------------------
typedef string filename<NFS_MAXNAMLEN>; 
struct fattr {
	ftype type;		/* file type */
	unsigned mode;		/* protection mode bits */
	unsigned nlink;		/* # hard links */
	unsigned uid;		/* owner user id */
	unsigned gid;		/* owner group id */
	unsigned size;		/* file size in bytes */
	unsigned blocksize;	/* prefered block size */
	unsigned rdev;		/* special device # */
	unsigned blocks;	/* Kb of disk used by file */
	unsigned fsid;		/* device # */
	unsigned fileid;	/* inode # */
	nfstime	atime;		/* time of last access */
	nfstime	mtime;		/* time of last modification */
	nfstime	ctime;		/* time of last change */
};
struct diropargs {
	nfs_fh	dir;	/* directory file handle */
	filename name;		/* name (up to NFS_MAXNAMLEN bytes) */
};
struct diropokres {
	nfs_fh file;
	fattr attributes;
};
----------------------------------------------------------------------
----------------------------------------------------------------------
struct readargs {
	nfs_fh file;		/* handle for file */
	unsigned offset;	/* byte offset in file */
	unsigned count;		/* immediate read count */
	unsigned totalcount;	/* total read count (from this offset)*/
};
struct readokres {
	fattr	attributes;	/* attributes, need for pagin*/
	opaque data<NFS_MAXDATA>;
};
union readres switch (nfsstat status) {
case NFS_OK:
	readokres reply;
default:
	void;
};
----------------------------------------------------------------------
----------------------------------------------------------------------
struct writeargs {
	nfs_fh	file;		/* handle for file */
	unsigned beginoffset;	/* beginning byte offset in file */
	unsigned offset;	/* current byte offset in file */
	unsigned totalcount;	/* total write count (to this offset)*/
	opaque data<NFS_MAXDATA>;
};
union attrstat switch (nfsstat status) {
case NFS_OK:
	fattr attributes;
default:
	void;
};
----------------------------------------------------------------------
----------------------------------------------------------------------
struct createargs {
	diropargs where;
	sattr attributes;
};
----------------------------------------------------------------------