open O_CREAT | O_EXCL on NFS in Linux?

后端 未结 1 970
小鲜肉
小鲜肉 2020-12-31 12:17

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 documentatio

1条回答
  •  傲寒
    傲寒 (楼主)
    2020-12-31 13:03

    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.
      • ...

    0 讨论(0)
提交回复
热议问题