Excerpts from ext.misc.info-afs: 29-Oct-92 Re: Write Lock and AFS John
Gardiner Myers@cmu. (516)

> In order to guarantee cache consistency you generally want to obtain
> the write lock before opening the file you want to modify.

> The best way to do this is to lock a different file than the one
> you're trying to modify.  Most of the code I have seen/written that
> locks files in AFS work like this:

> * open lock file (O_RDONLY | O_CREAT)
> * while lock attempt fails (EWOULDBLOCK)
> *   give up if too many tries
> *   wait
> * open data file
> * modify data file
> * close data file
> * release lock & close lock file

>                               _.John


Your answer seem to imply that the file locking facilities provided by
AIX (unix in general) do not really work reliably in AFS? If this is the
case, then what is the directory locking ('k') option for?  Also, it
begs the question of what other, commonly relied upon, system supplied
functions don't work reliably in the AFS environment?

Is there a way in AIX to lock a file prior to opening it?  All the
functions I am familiar with seem to require the file to be open first.

Is there a way to garentee a reread of the open file from AFS after I
have achieved the lock?

I would really like to use the AIX facilities because the lock is
automatically removed when a process has crashed or otherwise abnormally
terminated.    Otherwise, I have to create administration methods to
clean up the lock file.  Also, AFS seems to go down often enough that
even though I was able to create the file, I may not be able to remove
it. So my administration procedures may have to come along after the
connections are back to clean up.

In general, a number of error recovery issue arise if I have to create
another file.  Many solutions require the lock file itself to be
reliably locked.  Other solutions require another form of communications
between the writers of the file.  All of which increases the application
complexity considerably.

Don't get me wrong, I appreciate your answer.  I have considered the
option of using a lock file before.  However, I can't help but think
that such a basic operation should work in AFS.  Also, the documentation
I have seen has enough refererences to "locks" and the "directory Lock"
authority, that I get the impression that it is supported.  But, I don't
seem to be able to get it to work reliably.  I don't know if I am coding
it wrong, using the wrong functions, or running into a bug.  Do I need
to include some special library or code?  As far as I know, I am just
using the libraries generally supplied with AIX.

Kris Davis ([EMAIL PROTECTED], krisd@rchland, krisd@rchvmw2)
Microcode Development Environment  Dept213
1-507-253-3707  IBM Rochester, MN

Reply via email to