From owner-freebsd-fs@FreeBSD.ORG Fri Aug 29 23:54:59 2014 Return-Path: Delivered-To: freebsd-fs@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 5AF88FEA; Fri, 29 Aug 2014 23:54:59 +0000 (UTC) Received: from esa-jnhn.mail.uoguelph.ca (esa-jnhn.mail.uoguelph.ca [131.104.91.44]) by mx1.freebsd.org (Postfix) with ESMTP id 0CA601C37; Fri, 29 Aug 2014 23:54:58 +0000 (UTC) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AqMEAKISAVSDaFve/2dsb2JhbABbhDuCeMklgx8BgSl3hAMBAQQBI1YFFg4KAgINGQJLAQ0GiE0Ip2OVHwEXgSyNbDQHgnmBUwWodYkFg3whgXeBBwEBAQ X-IronPort-AV: E=Sophos;i="5.04,427,1406606400"; d="scan'208";a="150641379" Received: from muskoka.cs.uoguelph.ca (HELO zcs3.mail.uoguelph.ca) ([131.104.91.222]) by esa-jnhn.mail.uoguelph.ca with ESMTP; 29 Aug 2014 19:54:37 -0400 Received: from zcs3.mail.uoguelph.ca (localhost.localdomain [127.0.0.1]) by zcs3.mail.uoguelph.ca (Postfix) with ESMTP id 735A5B3F41; Fri, 29 Aug 2014 19:54:37 -0400 (EDT) Date: Fri, 29 Aug 2014 19:54:37 -0400 (EDT) From: Rick Macklem To: Ivan Voras Message-ID: <1912666252.30566061.1409356477461.JavaMail.root@uoguelph.ca> In-Reply-To: Subject: Re: lockf(1) and NFS MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Originating-IP: [172.17.91.202] X-Mailer: Zimbra 7.2.6_GA_2926 (ZimbraWebClient - FF3.0 (Win)/7.2.6_GA_2926) Cc: freebsd-fs@freebsd.org 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 23:54:59 -0000 Ivan Voras wrote: > 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. > Yes, the NFSv4 protocol only supports POSIX byte range locks. The only alternative to translating flock(2) locks to POSIX locks is to not support flock(2) locks at all. To be honest, NFSv4 does have Windows style Open locks, which would implement something close to O_EXLOCK, but not flock(2). Since they couldn't be flock(2) compatible, I didn't do this. > I've tested the following patch and it works. > Any objections to committing it? > What happens if the file "name" exists and the process only has read access to it for a file on a local fs? (I'm wondering if the patch breaks that case and causes a POLA?) Alternately you could add a new command option for this case and document the need to use it for NFSv4 mounts, maybe? Have fun with it, rick > --- 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); > >