NFS File Locking & fcntl
m.seaman at infracaninophile.co.uk
Sun Apr 4 06:39:54 PDT 2004
On Sun, Apr 04, 2004 at 02:53:24PM +0200, herrier wrote:
> First of all I a very happy using FreeBSD and I have a question regarding Locking of files over NFS.
> Here is my configuration:
> I have an apache server running with FreeBSD 4.8 Stable (server 1)
> I have a NFS server where I put all my website files running FreeBSD 4.8 Stable. (server 2)
> Both server are linked using Ethernet cards.
> rpc.lockd is not activated: neither on server 1 nor on server 2
Which means that there's no chance of file locking happening.
> On server 1, I have concurrent CGI processes accessing files on server 2 using the locking api:
> fcntl(m_hdlFile,F_SETLKW, &objLock);
> to lock part of the accessed files.
> Question: Despite lockd is missing, does this invokation works well i.e do we have the expected locking behavior ?
Afraid not. FreeBSD 4.9 doesn't provide the client side functionality
for locking over NFS -- as the rpc.lockd(8) man page says:
The current implementation provides only the server side of the protocol
(ie. clients running other OS types can establish locks on a FreeBSD
fileserver, but there is currently no means for a FreeBSD client to
In fact, what happens with FreeBSD clients is that the kernel lies to
the process requesting the lock, and just anyswers "yes, lock
achieved" to every request.
You should take care that your CGI doesn't depend critically on being
able to achieve an exclusive lock on a file shared over a network,
especially if that file is going to be accessed from several machines.
You can use the technique of 'dot locking' (as often used by mail
delivery agents) where the process accessing the file creates a lock
file to signal that it is accessing the shared resource, and removes
the lock file when it's done. So long as everything that accesses the
shared resource can be rewritten to abide by this protocol, then it
should work pretty well.
This is not a problem with 5.x -- the full functionality of rpc.lockd
Dr Matthew J Seaman MA, D.Phil. 26 The Paddocks
PGP: http://www.infracaninophile.co.uk/pgpkey Marlow
Tel: +44 1628 476614 Bucks., SL7 1TH UK
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 187 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-questions/attachments/20040404/a6cb0466/attachment.bin
More information about the freebsd-questions