Subject: Re: Is O_EXCL in open(2) broken over NFS ?
To: Manuel Bouyer <>
From: Aidan Cully <>
List: tech-userlevel
Date: 07/23/2000 13:57:55
On Sun, Jul 23, 2000 at 05:06:31PM +0200, Manuel Bouyer wrote:
> On Sun, Jul 23, 2000 at 12:32:51PM +0100, Alan C. Horn wrote:
> > 
> > I recall that O_EXCL over NFS never worked right on Linux due to a race
> > condition.
> > 
> > In the NetBSD open(2) manpage I see no mention of this. Does it mean that
> > exclusive locks work properly across NFS in NetBSD ?
> Yes. It doesn't work on linux because linux's NFS implementation is not
> correct.

Interestingly enough, I just looked at NetBSD's implementation of
O_EXCL over NFS, and saw the following:
                if (v3 && (fmode & O_EXCL) && error == NFSERR_NOTSUPP) {
                        fmode &= ~O_EXCL;
                        goto again;
So, if the server doesn't support the NFSV3CREATE_EXCLUSIVE operation,
NetBSD silently tries again without the O_EXCL bit set.  I don't know
what the proper solution for NetBSD is, here...  I know that what we
did at my old job was to call 'open' on a guaranteed unique filename,
and then link()/unlink() it into place, since NFS couldn't guarantee
O_EXCL processing, but could guarantee that link() would fail if the
file already existed.  At the least, I'd hope that an #ifdef NFS_DIAG
(or something) could do a
printf("nfs_create: O_EXCL operation not supported by server.");
to let the user know at some level that O_EXCL isn't doing what sie
thinks it is.