NFS(网络文件系统)本质上是一台服务器,多个客户端(host)可能并行地访问NFS上的文件。也因此会产生一些“竞争”或缓存方面的问题。
其中一个例子是“在HostA上创建文件,在HostB上检查该文件是确看不到这个文件”。
原因是:当前系统缓存了目录信息。
解决办法无非两个方向:
用来测试的方法和Tcl脚本如下:
HostA % nfs-check.tcl touch /path/to/dir/tmp.1 HostB % nfs-check.tcl glob /path/to/dir/tmp.1 HostB % nfs-check.tcl check /path/to/dir/tmp.1
File: "nfs-check.tcl"
#!/usr/bin/env tclsh
proc touch_file {file} {
::exec touch $file
puts "[clock seconds] touch $file"
}
proc check_file {file} {
if {[file exist $file]} {
puts "[clock seconds] exist $file"
exit
}
after 100 [list check_file $file]
}
proc glob_file {file} {
glob -nocomplain [file dir $file] *
if {[file exist $file]} {
puts "[clock seconds] exist $file"
exit
}
after 100 [list glob_file $file]
}
lassign $::argv act file
switch $act {
touch {
touch_file $file
}
check {
check_file $file
vwait forever
}
glob {
glob_file $file
vwait forever
}
}