[Samba] [SMB 3.0.10] File Locking Mechanism Windows <-> Unix
Asif.M at siemens.com
Wed Mar 16 03:41:33 GMT 2005
We have samba 3.0.10 running on Solaris 9 with the smb.conf as follows.
# Global parameters
workgroup = NMUINT
netbios name = NMUINTFS
interfaces = <IP>
bind interfaces only = Yes
security = DOMAIN
password server = XXX.XXX.XXX.XXX
log level = 1
ldap ssl = no
#oplocks = no
kernel oplocks = no
path = /export/home/Testdev/share
read only = No
oplocks = no
strict locking = yes
level2 oplocks = no
Oplocks were disabled. Any idea what else could be the problem?
Thanks and best regards,
From: Jeremy Allison [mailto:jra at samba.org]
Sent: Tuesday, March 15, 2005 11:33 PM
To: Asif, M
Cc: samba at samba.org
Subject: Re: [Samba] [SMB 3.0.10] File Locking Mechanism Windows <-> Unix
On Tue, Mar 15, 2005 at 07:54:38PM +0530, Asif, M wrote:
> Hello Jeremy,
> Thanks for your response.
> I tried the following
> On Windows side, an MFC application with the code given below access
> the file using the samba share.
> CString strFile =
> CStdioFile fValueFile;
> if (!fValueFile.Open( strFile ,CFile::modeWrite |
> CFile::shareExclusive ) )
> wcout<<_T("Open failed")<<endl;
> //wcout<<_T("Open Success")<<endl;
> fValueFile.WriteString( strt );
> On UNIX side, code is something similar to this
> int fid =
> open("/export/home/scsd13/kiran/NetMBase/tmp/test.txt", O_RDWR|O_EXCL ) ;
> if( 0 > fid )
> struct flock lockDetails ;
> lockDetails.l_start = 0 ;
> lockDetails.l_whence = SEEK_SET;
> lockDetails.l_len = 0 ;
> lockDetails.l_type = F_WRLCK ;
> int nErr = fcntl( fid, F_SETLK, &lockDetails);
> if( 0 > nErr )
> 1. Two instances of the executable runs on Windows side, open fails
> with sharing violation if the first one is not released ( blocked at
> call) , no problem.
> 2. Same is the case with two instances of UNIX processes.
> 3.The unix process locks the file and does not release it (blocked at
> getchar() ), and then the windows client is executed, WriteString
> throws an exceptoin giving error 33(locked by other process). No
> problem 4. Now if the Windows client opens the file first (blocked at
> getchar() ) and then the unix client is invoked, the fcntl call
> I tried lockf() instead of fcntl(), turned on mandatory locking etc,
> but with no success.
> Am I missing out some thing? Is there an easier way for getting this work?
> Basically, I want to ensure that there is no read happening when any
> one (from unix or windows) is writing into the file an vice versa.
What OS are you running on ? This code will work on Linux with kernel
oplocks, and if you turn off oplocks should work on other UNIXes.
More information about the samba