[Samba] O_EXCL unreliable?

Egon Eckert egon at heaven.industries.cz
Mon Jun 17 00:32:03 GMT 2002


Hi all,

I fear I can't rely on "open (path, O_CREAT | O_EXCL)" behaviour
on samba share.

The libc's doc says:

     If both `O_CREAT' and `O_EXCL' are set, then `open' fails
     if the specified file already exists.  This is guaranteed
     to never clobber an existing file.

But this isn't probably true on network filesystems.  When I run
this tiny program on 2 hosts in the same directory on samba
share (with 'oplocks = no' in smb.conf):

--<cut>--
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>  // unlink

main ()
{
  const char * path = "locktest.lck";
  while (1) {
    int f = open (path, O_WRONLY | O_CREAT | O_EXCL);
    if (f > 0) {
      close (f);
      if (unlink (path) < 0) {
        perror ("unlink");
        exit (1);
      }
    }
  }
  return 0;
}
--<cut>--

it fails quickly with:

unlink: Text file busy

When I run it on the same host (as 2 processes), it runs as I
expect -- forever -- even on a samba share (talking to the same
smbd on other side).

To be fair, it fails on NFS as well -- immediately, just the
message is different ("unlink: No such file or directory"). 
This is why I think it's unreliable on ANY or most network
filesystems.  But I'd like to be sure, of course. :-)  May be
it's just out config error...  What do you think?

Thanks,

-- 
Egon Eckert, Heaven Industries, s.r.o.
E-mail: egon at heaven.industries.cz




More information about the samba mailing list