[Gluster-users] Exclusive file open in gluster 3.3.0

Stephen Pierce spierce at verifyle.com
Wed Jul 11 20:16:44 UTC 2012

Short question: Does gluster and the FUSE client support the O_EXCL flag to open()?

Long question:
So I have several hosts, all using the FUSE client. I mount the same gluster filesystem using the FUSE client on each host. Then, two processes (on separate hosts), try to open() the same file with O_CREAT|O_EXCL. Does the FUSE client and gluster guarantee that only one will be successful (ie: no race condition exists)? Or do I need to implement the suggested work-around for NFS in the man page for open()?

Next question: Is anyone actually relying on O_EXCL? :-)


Open() manpage:

       O_EXCL Ensure that this call creates the file: if this flag is  specified  in  conjunction  with
              O_CREAT,  and  pathname already exists, then open() will fail.  The behavior of O_EXCL is
              undefined if O_CREAT is not specified.

              When these two flags are specified, symbolic links are not followed:  if  pathname  is  a
              symbolic link, then open() fails regardless of where the symbolic link points to.

              O_EXCL  is  only  supported  on NFS when using NFSv3 or later on kernel 2.6 or later.  In
              environments where NFS O_EXCL support is not provided, programs that rely on it for  per-
              forming locking tasks will contain a race condition.  Portable programs that want to per-
              form atomic file locking using a lockfile, and need to avoid reliance on NFS support  for
              O_EXCL,  can  create  a unique file on the same file system (e.g., incorporating hostname
              and PID), and use link(2) to make a link to the lockfile.  If link(2) returns 0, the lock
              is  successful.  Otherwise, use stat(2) on the unique file to check if its link count has
              increased to 2, in which case the lock is also successful.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://supercolony.gluster.org/pipermail/gluster-users/attachments/20120711/dbc36371/attachment.html>

More information about the Gluster-users mailing list