打开O_CREAT |在Linux上的NFS的O_EXCL? [英] open O_CREAT | O_EXCL on NFS in Linux?

查看:177
本文介绍了打开O_CREAT |在Linux上的NFS的O_EXCL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Linux 2.6内核和NFSv3中,当 open(fname,O_CREAT | O_EXCL)有效时,当前规范打开(2)系统调用文档( http://www.kernel.org/doc/man-pages/online/pages/man2/open.2.html )说一切都很好:

   -  O_EXCL 
- ...
在NFS上,仅在使用NFSv3时才支持O_EXCL或稍后在内核
2.6或更高版本上。在O_EXCL支持不是
的NFS环境中,依赖它执行锁定任务的程序
将包含竞争条件。可移植程序,想要使用锁文件执行
原子文件锁定,并且需要避免依赖NFS
支持O_EXCL,可以...

看起来好像所有的2.6内核都可以,但手册页 0现场直播,网络用户在过去一年或两年内谴责这种使用。我想在RHEL 5(2.6.18)系统上使用这个设置,但是当它真的变得安全的时候,我不能确定它。有没有人有一个明确的答案?

显然,NFS家伙声称,从 NFSv3 和Linux 2.6.5 是OK。



来自 http://nfs.sourceforge.net/#faq_d10




  • D10。我试图使用flock()/ BSD锁来锁定多个客户端上使用的文件,但文件被损坏。怎么样?


    • A。 flock()/ BSD锁只能在2.6.12之前的Linux NFS客户端上进行本地操作。使用fcntl()/ POSIX锁来确保文件锁对其他客户端可见。
    • 以下是一些序列化NFS文件访问的方法。


      • 使用fcntl()/ POSIX锁定API。这种类型的锁定可通过NLM协议或通过NFSv4跨多个客户端提供字节范围锁定。

      • 使用单独的锁定文件,并创建硬链接。请参阅creat(2)手册页的O_EXCL部分中的说明。


    • 值得注意的是,在早期的2.6内核之前,O_EXCL会创建在Linux NFS客户端上不是原子的。不要使用O_EXCL在多个NFS客户端之间创建并期望原子行为,除非您正在运行比 2.6.5 更新的内核。
    • >


When in the Linux 2.6 kernel and in NFSv3 did open("fname", O_CREAT|O_EXCL) became valid? The current canonical open(2) system call documentation (http://www.kernel.org/doc/man-pages/online/pages/man2/open.2.html) says everything is fine:

  - O_EXCL  
   - ...  
      On NFS, O_EXCL is only supported when using NFSv3 or later on kernel  
      2.6 or later.  In NFS environments where O_EXCL support is not  
      provided, programs that rely on it for performing locking tasks will  
      contain a race condition.  Portable programs that want to perform  
      atomic file locking using a lockfile, and need to avoid reliance on NFS  
      support for O_EXCL, can  ...

This reads as though all 2.6 kernels are OK, but the man page changelog (ca late kernel 2.6.23) begins indicating validity four years after 2.6.0 went live, and the web is rife with boards users censuring this use within the last year or two. I'd like to use this setup on RHEL 5 (2.6.18) systems, but I couldn't pin down when it truly became safe. Does anyone have a definitive answer?

解决方案

Apparently, the NFS guys claim that anything from NFSv3 and Linux 2.6.5 on is OK.

From http://nfs.sourceforge.net/#faq_d10:

  • D10. I'm trying to use flock()/BSD locks to lock files used on multiple clients, but the files become corrupted. How come?
    • A. flock()/BSD locks act only locally on Linux NFS clients prior to 2.6.12. Use fcntl()/POSIX locks to ensure that file locks are visible to other clients.
    • Here are some ways to serialize access to an NFS file.
      • Use the fcntl()/POSIX locking API. This type of locking provides byte-range locking across multiple clients via the NLM protocol, or via NFSv4.
      • Use a separate lockfile, and create hard links to it. See the description in the O_EXCL section of the creat(2) man page.
    • It's worth noting that until early 2.6 kernels, O_EXCL creates were not atomic on Linux NFS clients. Don't use O_EXCL creates and expect atomic behavior among multiple NFS client unless you are running a kernel newer than 2.6.5.
    • ...

这篇关于打开O_CREAT |在Linux上的NFS的O_EXCL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆