[Samba] [SMB 3.0.10] File Locking Mechanism Windows <-> Unix

Asif, M Asif.M at siemens.com
Wed Mar 16 03:41:33 GMT 2005


 Hello Jeremy,

We have samba 3.0.10 running on Solaris 9 with the smb.conf as follows.
<http://lists.samba.org/archive/samba/2005-March/101953.html>

# Global parameters
[global]
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

[Share1]
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,
Asif

-----Original Message-----
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 =
> _T("\\\\180.144.1.11\\netmbase\\tmp\\test.txt");
> 		CStdioFile fValueFile;
> 			if (!fValueFile.Open( strFile ,CFile::modeWrite |
> CFile::shareExclusive    ) )
> 			{
> 				wcout<<_T("Open failed")<<endl;
> 			}
> 			else
> 			{
> 				//wcout<<_T("Open Success")<<endl;
> 			}
> 
> 		fValueFile.WriteString( strt );
> 		getchar()
> 
> 		fValueFile.Close();
> 
> 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 )
> 		{
> 			perror("open"),exit(1);
> 		}
> 
> 		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 )
> 		{
> 			perror("lock"),exit(1);
> 		}
> 		getchar();
> 		close(fid);
> 	
> Now,
> 
> 1. Two instances of the executable runs on Windows side, open fails 
> with sharing violation if the first one is not released ( blocked at 
> getchar()
> 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
succeeds...
> 
> 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.

Jeremy.


More information about the samba mailing list