Date: Fri, 15 May 1998 10:46:00 +0200 From: Robert Frank <frank@ifi.unibas.ch> Subject: file locking To: samba-technical@samba.anu.edu.au
I am looking in getting samba NEXTSTEP/OPENSTEP compatible again.
The first thing I noticed is that locking doesnt work as it should.
When compiling with posix, fcntl(.., ..LK., ..) will work as expected and
will properly wake up on getting a signal. However, using posix will break
several other things and posix isn't implemented under OPENSTEP (or
rather, just about all is broken ...).
So, if I use the flock call, I can get away with it, except for the fact
that this won't wake up on receiving a signal (the man pages claim that it
should!). The work around is to use a non-blocking lock call and sleep(1)
until the timeout has passed or the call is satisfied. That seems to work
fine, but is ugly.
Now, I found that file locking is called in two places: in the samba
password routines (smbpass.c) (when updating a password) and in util.c.
In util.c there is the option of using fcntl or not locking at all.
Could we create a sys_lock in system.c which will do the lock and use that
for smbpass.c, connection.c, locking.c, locking_slow.c, pidfile.c, and
shmem.c ?
<nofill>
sys_lock should be defined a follows:
BOOL sys_lock(int fd, int time_out, int kind, uint32 from, uint32 len);
fd is the open file descriptor,
time_out is the number of seconds to wait for the lock before returning False
a value of zero means don't wait,
kind is one of:
SMB_WRLCK set exclusive write lock
SMB_RDLCK set shared read lock
SMB_UNLCK remove an existing lock
SMB_CKLCK check if a lock is in place
(for posix/sysV this maps to: F_WRLCK, F_RDLCK, F_UNLCK, and F_GETLCK)
from is the byte offset into the file of the beginning of the region to lock
len is the number of bytes to lock, or zero to lock the entire file.
The ifdefs would then be:
#if HAVE_FCNTL_LOCK
#define SMB_WRLCK F_WRLCK
#define SMB_RDLCK F_RDLCK
#define SMB_UNLCK F_UNLCK
#define SMB_CKLCK F_GETLCK
#else
#define SMB_WRLCK 1
#define SMB_RDLCK 2
#define SMB_UNLCK 0
#define SMB_CKLCK 3
#endif
</nofill>
If a system doesn't have fcntl locking and only has flock and locking
specific bytes is requested, what do we do? Is this what locking_slow.c is
supposed to simulate (although it too, uses the fcntl_lock(..) call, which
in turn uses fcntl if available). Shall we just consider the region
locked? (That, of course, is unsafe.)
I can't have the fcntl_lock just return false when requesting a lock but
fcntl locking isn't available! This is currently the case for:
<nofill>
APOLLO
OS2
AMIGA
Hm, why does Samba work on these systems?
</nofill>(When compiling for NEXTSTEP/OPENSTEP, HAVE_FCNTL_LOCK defaults to 1 and
the package compiles, but when run, it fails with the EIN error code,
which cause the fcntl_lock routines to return True nonetheless!)
<nofill>
-Robert
-------------------------------------
Institut fuer Informatik tel +41 (0)61 321 99 67
Universitaet Basel fax. +41 (0)61 321 99 15
Robert Frank
Mittlere Strasse 142 rfc822: frank@ifi.unibas.ch (NeXT,MIME mail ok)
CH-4056 Basel (remove any no_spam_ from my return address)
Switzerland
</nofill>