[Samba] Need some explanation on Samba/NFS locks handle

Alain.Gorlier at altissemiconductor.com Alain.Gorlier at altissemiconductor.com
Tue Mar 13 15:02:44 GMT 2007

Hi there,

We are thinking about sharing same files:
- OS2/Win clients with Samba
- Linux clients with NFS.
So, the same files would be shared by 2 different protocols.

Looking at the open.c samba code, there seems to be no check / no error 
(sharing violation) returned to the smb client when the file is already 
locked by an NFS client.
- So, even if a file is opened and locked by an NFS client, Samba let a 
smb client access the file ? Is there a parameter to change this behaviour 

- On the other hand, could you confirm me that, in case of a file opened 
and locked by an smb client, Samba server locks the file, then NFS client 
could check the lock ?

- Could you please explain me what "hack for NFS" means in open.c ?

- Do I miss something ?

open.c :

 /*note that we ignore failure for the following. It is
           basically a hack for NFS, and NFS will never set one of
           these only read them. Nobody but Samba can ever set a deny
           mode and we have already checked our more authoritative
           locking database for permission to set this deny mode. If
           the kernel refuses the operations then the kernel is wrong  */

        kernel_flock(fsp, share_access);

         * At this point onwards, we can guarentee that the share entry
         * is locked, whether we created the file or not, and that the
         * deny mode is compatible with all current opens.

kernel_flock :
 Set a kernel flock on a file for NFS interoperability.
 This requires a patch to Linux.

static void kernel_flock(files_struct *fsp, uint32 share_mode)
        int kernel_mode = 0;
        if (share_mode == FILE_SHARE_WRITE) {
                kernel_mode = LOCK_MAND|LOCK_WRITE;
        } else if (share_mode == FILE_SHARE_READ) {
                kernel_mode = LOCK_MAND|LOCK_READ;
        } else if (share_mode == FILE_SHARE_NONE) {
                kernel_mode = LOCK_MAND;
        if (kernel_mode) {
                flock(fsp->fh->fd, kernel_mode);


More information about the samba mailing list