分散システム 電子・情報工学系 新城 靖 <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; }; ----------------------------------------------------------------------