Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
From: mikeh@aslan.eng.mindspring.net (Mike harrelson)
Subject: Re: flock/lockf under DU
Date: 1998/11/15	[thread overview]
Message-ID: <72lfsd$ua7$1@camel18.mindspring.com> (raw)
In-Reply-To: 71ce9q$opb$1@nntpd.lkg.dec.com

In article <71ce9q$opb$1@nntpd.lkg.dec.com>,
Eric Werme - replace nospam with werme <> wrote:
>Massimo Gais <mgais@na.astro.it> writes:
>
>>I'd like to now what's the best function to call under DU (4.0)
>>between flock() and lockf();
>
>I tell everyone to use fcntl() as I can never remember what the others
>do.
>
>Lessee...
>
>From lockf(3)
>  The lockf() function locks and unlocks sections of an open file.  Unlike
>  the fcntl() function, however, its interface is limited to setting only
>  write (exclusive) locks.
>
>  Although the lockf() and fcntl() functions are different, the implementa-
>  tions are fully integrated.  Therefore, locks obtained from one function
>  are honored and enforced by the other lock function.


Its a pity flock(2) locks aren't recognized by fcntl()/lockf() locks, even if
just locally.  The ability to use local locks on files on NFS but not have
them tying up lockd/portmapper can be useful.


>So, flock(2) _in currently shipping code_ is separate:
>
>  The flock() interface is not part of any UNIX standard.  Therefore, if you
>  are designing and writing applications to be portable across platforms,
>  DIGITAL recommends that you use the fcntl() file locking interface instead
>  of flock().
>
>Internally, flock does VFS-level locking, i.e., the real file system is
>not told of what's happening.  This makes flock useleess on NFS files
>if multiple systems are involved.
>
>_However_, in the next major release, the flock interface will
>call the fcntl-style locking routines and _will_ work over NFS.


That is unfortunate for systems that use NFS but only need local file locks.
Our environment uses many files with locks on NFS, but are only accessed
from one machine.  When we used fcntl locking, both portmapper and lockd
used enormous amounts of CPU.  Once we switched to flock, everything still
worked, but without all of the NFS file lock traffic and load by portmapper
and lockd.


>Still, please use fcntl....  BTW, lockf(3) is a libc routine that calls
>fcntl(2).
>
>>I have to fopen() the mail spoolfile for reading, but if I 
>>another process has already locked with flock() the fopen()
>>simple doesn't care...
>
>Both locking styles are "advisory locking"  Mandatory locking is
>available on local file systems.  See chmod(2).  I am in the camp
>that says mandatory locking is the work of the devil.  Don't use it.

Agreed.

>Trying to make this work over NFS would result in massive confusion
>because someone on a NFS client could lock a file on the server.  Either
>lock state would have to be preserved over reboots or reboots could
>only be done when the client releases the lock.
>

-- mikeh




      reply	other threads:[~1998-11-15  5:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-10-30  5:00 flock/lockf under DU Massimo Gais
1998-10-30  5:00 ` Eric Werme - replace nospam with werme
1998-11-15  5:00   ` Mike harrelson [this message]
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox