NFS file locking?

From: Larry McVoy (lm@bitmover.com)
Date: Sun Oct 14 2001 - 13:11:04 EST


Hi, the open(2) man page says:

       O_EXCL When used with O_CREAT, if the file already exists
              it is an error and the open will fail. O_EXCL is
              broken on NFS file systems, programs which rely on
              it for performing locking tasks will contain a race
              condition. The solution for performing atomic file
              locking using a lockfile is to create a unique file
              on the same fs (e.g., incorporating hostname and
              pid), use link(2) to make a link to the lockfile.
              If link() returns 0, the lock is successful. Oth­
              erwise, use stat(2) on the unique file to check if
              its link count has increased to 2, in which case
              the lock is also successful.

I coded this up and tried it here on a cluster of different operating
systems (Linux 2.4.5 server, linux, freebsd, solaris, aix, hpux, irix
clients) and it doesn't work.

2 questions:

a) is it the belief of folks here that this should work?

b) if performance isn't a big issue, is there any portable way to do
   locking over NFS with just files?

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Mon Oct 15 2001 - 21:00:55 EST