From owner-freebsd-fs@FreeBSD.ORG Fri Aug 29 13:05:06 2014 Return-Path: Delivered-To: freebsd-fs@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 7FE14AFF for ; Fri, 29 Aug 2014 13:05:06 +0000 (UTC) Received: from plane.gmane.org (plane.gmane.org [80.91.229.3]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 39ECA1A60 for ; Fri, 29 Aug 2014 13:05:05 +0000 (UTC) Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1XNLrN-0008Ot-4o for freebsd-fs@freebsd.org; Fri, 29 Aug 2014 15:04:57 +0200 Received: from lara.cc.fer.hr ([161.53.72.113]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 29 Aug 2014 15:04:57 +0200 Received: from ivoras by lara.cc.fer.hr with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 29 Aug 2014 15:04:57 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: freebsd-fs@freebsd.org From: Ivan Voras Subject: lockf(1) and NFS Date: Fri, 29 Aug 2014 15:04:22 +0200 Lines: 47 Message-ID: Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="7dC5RRDARlPrAJvalGUKMh7CMnWCFA4Fn" X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: lara.cc.fer.hr User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:31.0) Gecko/20100101 Thunderbird/31.0 X-BeenThere: freebsd-fs@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Filesystems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 29 Aug 2014 13:05:06 -0000 This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --7dC5RRDARlPrAJvalGUKMh7CMnWCFA4Fn Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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 =3D open(name, flags|O_RDONLY|O_EXLOCK|flags, 0666)) =3D=3D -1)= { + if ((fd =3D open(name, flags|O_RDWR|O_EXLOCK|flags, 0666)) =3D=3D -1) {= if (errno =3D=3D EAGAIN || errno =3D=3D EINTR) return (-1); err(EX_CANTCREAT, "cannot open %s", name); --7dC5RRDARlPrAJvalGUKMh7CMnWCFA4Fn Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iKYEARECAGYFAlQAemRfFIAAAAAALgAoaXNzdWVyLWZwckBub3RhdGlvbnMub3Bl bnBncC5maWZ0aGhvcnNlbWFuLm5ldDYxNDE4MkQ3ODMwNDAwMDJFRUIzNDhFNUZE MDhENTA2M0RGRjFEMkMACgkQ/QjVBj3/HSwlVgCeOAIZdpnVbarFltjwPm9SPeH7 VakAnAmzt1PF8iLCMfoTRgoOx9OVzn3V =Ii34 -----END PGP SIGNATURE----- --7dC5RRDARlPrAJvalGUKMh7CMnWCFA4Fn--