[Samba] Samba lock X Unix fcntl() lock

Roberto João Lopes Garcia roberto at mha.com.br
Tue Feb 26 10:12:06 GMT 2002


Hi

I look at list archives and at samba docs but I did not found ...
please can some one help me?

I have to write a unix program that need to check if it can write to a file and place the apropriate locks before write.  Those files are in a Samba share.  I intend to use fcntl() function to check and set the locks.

I wrote a test program to see if the fcntl() function can see the samba locks reported by smbstatus -L. I test it with 5 files opened at the same time: rob.xls (ms excel), rob.doc (ms word), rob.dwg (autocad), rob.sdw (staroffice) and rob.txt (ms wordpad).
 
# smbstatus  -L | grep '/rob/rob'
7499   DENY_WRITE RDWR       NONE /h:/rob/rob.sdw   Tue Feb 26 13:22:20 2002
7499   DENY_NONE  RDWR       NONE /h:/rob/rob.doc   Tue Feb 26 13:10:29 2002
7499   DENY_NONE  RDWR       NONE /h:/rob/rob.xls   Tue Feb 26 13:13:04 2002
7499   DENY_WRITE RDWR       NONE /h:/rob/rob.dwg   Tue Feb 26 13:15:43 2002
# 

WordPad appears to does not lock rob.txt file.

My test program only detects the lock in the rob.doc and rob.xls files. 

What happen? Samba does not put fcntl lock in rob.dwg and rob.sdw files? Is it a normal behaviour or a bug? What is the diference between DENY_NONE and DENY_WRITE? Is it my program fault? Are there some mistakes?

See my C program fragment:
                            
   lock.l_type=F_WRLCK;     /*** Write lock ***/
   lock.l_whence=SEEK_SET;  /*** File begin ***/
   lock.l_start=0;          /*** Off set, 0 ***/
   lock.l_len=0;            /*** Up to the end of file ***/
   lock.l_pid = pid;        /*** this procces pid ***/

   ret=fcntl(fd, F_GETLK, & lock); /** see if the file can be locked **/
   if(ret==-1) {                   /** error, close fd and exit      **/

   if(lock.l_type != F_UNLCK) {    /** File locked by some other proccess, show info **/
   else {                          /** file unlocked, we can lock it      **/

See testparm fragment:

        kernel oplocks = Yes
        blocking locks = Yes
        fake oplocks = No
        locking = Yes
        oplocks = Yes
        level2 oplocks = Yes
        oplock contention limit = 2
        posix locking = Yes
        strict locking = No


[DRV_H]
        path = /h:
        read only = No
        create mask = 0660
        directory mask = 0770
        oplocks = No


Samba: 2.2.3a made from the source tar ball.
Server: Linux 2.4.17 kernel on dual intel PIII.

Obs.: My test program shows the same result when compiled and runed at a Sun ultra1 solaris 2.5 through a NFS mount to the Samba server.

Thank you

Roberto


-----------------------------------------------------------------
Eng. Roberto João Lopes Garcia        E-mail: roberto at mha.com.br 
F. 55 11 3747 7697   FAX  55 11 3747-7700

                MHA Engenharia Ltda     

E-mail: mha at mha.com.br    WWW: http://www.mha.com.br

Av Maria Coelho Aguiar, 215 Bloco D     2 Andar
Centro Empresarial de Sao Paulo
Sao Paulo - BRASIL - 05805 000
------------------------------------------------------------------





More information about the samba mailing list