Problems gaining/releasing exclusive file locks in Sun NFS

Rahul Dhesi dhesi%cirrusl at oliveb.atc.olivetti.com
Sat Oct 27 09:10:00 AEST 1990


Re the report from angst at batserver.cs.uq.oz.au about problems with lockf
and fcntl for locking:

Many moons ago I experimented with locking mechanisms under SunOS 3.5.  I
found that network-wide locking did not appear to work correctly, even
though the lock daemons were up and running.  I fell back to the old
standard technique of creating a lock file.  Despite rumors that that file
creation over NFS might not be truly exclusive and atomic, I have had no
problems.  Since then, I've often seen complaints posted to Usenet about
lockf and fcntl not working correctly for locking over NFS, and have
always been relieved that I decided not to use them.

Of course, when you use file creation for network-wide locking, you
must store both host name and process id in the lock file, and
supersede an existing lock if the locking process was on the local host
and has crashed.  You must also use a secondary lock before
manipulating the primary lock, so any race condition is minimized to
infinitesimal probability.

Rahul Dhesi <dhesi%cirrusl at oliveb.ATC.olivetti.com>
UUCP:  oliveb!cirrusl!dhesi



More information about the Comp.sys.sun mailing list