[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Policy wrt mail lockfile (section 4.3)



In article <m0wfM9t-000AiLC@liw.clinet.fi>, Lars Wirzenius <liw@iki.fi> wrote:
>--==_Exmh_970021023P
>Content-Type: text/plain; charset=us-ascii
>
>[ Please don't Cc: public replies to me. ]
>
>Karl M. Hegbloom:
>> What happens?  Can you describe the problem?  Explain your setup in
>> more detail, please.  I would like to know more about the problems
>> that are encountered with nfs.
>
>When you try to create a lock file with open(2) using O_CREAT|O_EXCL
>(i.e., you ask the kernel to create the file, but fail if it exists
>already), the operation will sometimes fail, when you network drops
>a packet. That operation simply isn't guaranteed to work over NFS,
>even though it is for normal Unix filesystems.

It's more the case that the O_EXCL flag doesn't exist in the NFS protocol.
So the operation is not atomic. The kernel itself does:

[pseudo code]

if (flags & O_EXCL) {
	if (stat(file) >= 0)
		return EEXIST;
}
return open (file, flags);

This is atomic on local file systems but not on NFS file systems. Usually
it will work, but I tested it by running a program repeatedly getting
a lockfile on 2 computers on a NFS mounted file system, and every once
in a while this method fails, as you would expect ofcourse.

I once wrote a patch where the kernel does:

if (flags & O_EXCL) {
	/*
	 *	Here the kernel uses a method with link() ing to the
	 *	file, similar to NFS mailbox locking, to create the
	 *	file atomically
	 */
	...
	...
}
return open (file, flags);

It worked like a charm, but Linus wouldn't accept it in the kernel.
Too bad, all of our problems would have been solved..

I now have open() in a preloaded library, /lib/nfslock.so that gets
preloaded on all our machines through /etc/ld.so.preload. Does about
the same thing, and lets us safely share mail over NFS. A bit (a bit?!)
of a hack, though.

Mike.
-- 
| Miquel van Smoorenburg |  "I need more space" "Well, why not move to Texas" |
| miquels@cistron.nl     |  "No, on my account, stupid." "Stupid? Uh-oh.."    |
|     PGP fingerprint: FE 66 52 4F CD 59 A5 36  7F 39 8B 20 F1 D6 74 02       |


--
TO UNSUBSCRIBE FROM THIS MAILING LIST: e-mail the word "unsubscribe" to
debian-devel-request@lists.debian.org . 
Trouble?  e-mail to templin@bucknell.edu .


Reply to: