Messages in this thread |  | | Date | Sat, 14 Sep 1996 22:42:07 -0400 (EDT) | From | Kenneth Albanowski <> | Subject | Re: patch: NFS and O_EXCL. Also: is O_EXCL really atomic? |
| |
On 14 Sep 1996, Miquel van Smoorenburg wrote:
> However most systems use open(file, O_CREAT|O_WRONLY|O_EXCL, mode) to > creat a lockfile. And NFS doesn't know about O_EXCL, so this still doesn't > work. I created a patch for the Linux NFS client code that guarantees > an atomic creat by first creating a temporary file, and then linking it > to its destination.
Very elegant. It can't be relied on in general purpose UNIX code, for portability reasons, but it is a pleasent improvement for Linux specific code. And even if it isn't perfect, it's a great deal better then it was, and will help naive code immensely.
My only problem with the patch is that it does not precisely match traditional NFS linking. The different may be irrelevant, but I'm not sure. Specifically, you say (pardon the perl code):
$tmp = "$filename.foobar"; $err = nfslink($tmp,$filename); nfsunlink($tmp); if($err == 0) { #success }
However, the traditional code that I'm familiar with goes more like this:
$tmp = "$filename.foobar"; retry: nfslink($tmp,$filename); if(nfsstat($tmp)->{links} == 2) { nfsunlink($tmp); #success } else { nfsunlink($tmp); $retries++; goto retry if $retries<5; }
Apart from the retrying, the important difference (I think) is the stat call to verify that the link was actually successful, instead of relying on the return code.
-- Kenneth Albanowski (kjahds@kjahds.com, CIS: 70705,126)
|  |