PDA

View Full Version : Exclusive file creation (Samba shares)



marcel
6th April 2007, 19:43
I have the following problem:

I have an app ( Win + Mac ) that stays connected to a samba share ( concurrent access ).
The purpose is to lock a directory( shared ) for exclusive access by creating an empty lock file.

The lock file is created with open(...) using the _O_CREAT and _O_EXCL flags.
Using _O_EXCL I am guaranteed ( at least I thought so ) that open returns an error if the file already exists.

The problem is ( I haven't been able to prove it yet ) that open returns a valid file descriptor sometimes when both clients try to create the lock file simultaneously. The result is not good - both clients think that they have created the lock file and tehrefore have exclusive access on that folder.

Has anyone else encountered this? Or, does anyone sees a problem in this exclusive access mechanism?

As usually, any suggestion is welcome.

Regards,
Marcel.

wysota
13th April 2007, 12:26
I think this is an overall problem with remote volumes - you can't have reliable mandatory locks with them. At least I think I read so a couple of times (the same issue is with NFS volumes). I suggest you try to do the job without relying on the lock.