Re: Lock files on NFS
- From: Keith Thompson <kst-u@xxxxxxx>
- Date: Thu, 06 Apr 2006 18:46:14 GMT
"Hubble" <reiner@xxxxxxxxx> writes:
if link call was successful then
we have the lock
if link count == 2 then
we have the lock /* ??? */
we failed to get the lock
Note that link(2) can fail for various reasons, see the man page
section ERRORS (http://bama.ua.edu/cgi-bin/man-cgi?link+2). Namely
EINTR or EAGAIN on some systems can happen, since link is a so called
"slow" system call. There may be other reasons that indicate that link
did not "complete" during the system call, but nevertheless completed.
So the scenario is:
1. The link() call:
returns before the action is completed, and link() therefore
returns a failure indication.
2. But the action of creating the link (which requires several steps)
actually continues on the NFS server, and eventually succeeds.
3. Checking the link count on the linked-to file is a reliable way to
4. The program is going to hold the lock for some time (perhaps a few
seconds); by the time it's done, both ".lock" and ".lock.foo.42"
will exist, and both can be removed to release the lock.
That makes sense, but it's part 3 that I'm still having a little
trouble with. If ".lock.foo.42" already exists, and ".lock" doesn't,
then ideally the link() call will succeed. But because of NFS
semantics, it can appear to fail. In that case, I check the link
count on ".lock.foo.42" -- but isn't there still a delay before
".lock" is created? If another process on another system tries to
during that delay, isn't it possible that it could appear to succeed?
Or is this race condition eliminated by the operations being
serialized on the NFS server?
In any case, my testing shows that the code I'm using now is more
reliable that what I was using before.
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
- Prev by Date: Re: how to open/create a file in C and access it
- Next by Date: Re: Compilation error without stating any reason
- Previous by thread: Re: Lock files on NFS
- Next by thread: Re: Lock files on NFS