On Sun, Apr 04, 2004 at 02:53:24PM +0200, herrier wrote:
> Hello,
> 
> 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
     establish locks).

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
is supported.

        Cheers,

        Matthew 

-- 
Dr Matthew J Seaman MA, D.Phil.                       26 The Paddocks
                                                      Savill Way
PGP: http://www.infracaninophile.co.uk/pgpkey         Marlow
Tel: +44 1628 476614                                  Bucks., SL7 1TH UK

Attachment: pgp00000.pgp
Description: PGP signature

Reply via email to