程序的本质是这样的,作者本质上只会附加到文件中.在作者完成并调用fflush之前,读者永远不会访问新添加的信息.
NFSv4是否支持这种情况?
解决方法
1.4.5. File locking
With the NFS version 4 protocol,the support for byte range file locking is part of the NFS protocol. The file locking support is structured so that an RPC callback mechanism is not required. This is a departure from the prevIoUs versions of the NFS file locking protocol,Network Lock Manager (NLM). The state associated with file locks is maintained at the server under a lease-based model. The server defines a single lease period for all state held by a NFS client. If the client does not renew its lease within the defined period,all state associated with the client’s lease may be released by the server. The client may renew its lease with use of the
RENEW
operation or implicitly by use of other operations (primarilyREAD
).
有关锁定和基于租约的模型的更多详细信息,请参阅同一RFC的第8节.
您的程序需要使用fcntl来管理锁定.我的建议是编写一个测试来检查EFS提供的NFS v4的实际实现是否支持按预期进行锁定(某些方面在规范中是可选的).您可以参考this lock testing suite的源代码,它支持多客户端测试.