lockf(1) and NFS

Ivan Voras ivoras at freebsd.org
Fri Aug 29 13:05:06 UTC 2014


Hi,

I had some fun troubleshooting NFS locking and among other things, found
that lockf(1) doesn't really work on NFSv4 mounts. Googling around (so
correct me if I'm wrong), it looks like this is because NFS quietly
translates the old-style locks into POSIX range locks, and those cannot
be acquired exclusively if the file is opened read-only.

I've tested the following patch and it works.
Any objections to committing it?

--- a/lockf.c	Fri Aug 29 14:58:10 2014 +0200
+++ b/lockf.c	Fri Aug 29 14:59:12 2014 +0200
@@ -169,7 +169,7 @@
 {
 	int fd;

-	if ((fd = open(name, flags|O_RDONLY|O_EXLOCK|flags, 0666)) == -1) {
+	if ((fd = open(name, flags|O_RDWR|O_EXLOCK|flags, 0666)) == -1) {
 		if (errno == EAGAIN || errno == EINTR)
 			return (-1);
 		err(EX_CANTCREAT, "cannot open %s", name);

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 311 bytes
Desc: OpenPGP digital signature
URL: <http://lists.freebsd.org/pipermail/freebsd-fs/attachments/20140829/36868368/attachment.sig>


More information about the freebsd-fs mailing list