util-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] flock: make flock(3) work on NFSv4
@ 2011-09-15  8:19 Petr Uzel
  2011-09-15  8:23 ` Petr Uzel
  2011-09-27 13:03 ` Karel Zak
  0 siblings, 2 replies; 3+ messages in thread
From: Petr Uzel @ 2011-09-15  8:19 UTC (permalink / raw)
  To: util-linux; +Cc: Michal Kubecek

[-- Attachment #1: Type: text/plain, Size: 1477 bytes --]

To pleace an exclusive lock on a file, NFSv4 requires
the file to be opened RW because of the emulation of flock()
by fcntl():

http://www.spinics.net/lists/linux-nfs/msg18502.html

So instead of O_RDONLY, open the file in O_RDWR if access()
indicates it is possible (unless shared lock is requested).

From: Michal Kubecek <mkubecek@suse.cz>
Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
---
 sys-utils/flock.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/sys-utils/flock.c b/sys-utils/flock.c
index 7d321de..a500319 100644
--- a/sys-utils/flock.c
+++ b/sys-utils/flock.c
@@ -129,6 +129,7 @@ int main(int argc, char *argv[])
   int have_timeout = 0;
   int type = LOCK_EX;
   int block = 0;
+  int open_accmode;
   int fd = -1;
   int opt, ix;
   int do_close = 0;
@@ -211,9 +212,11 @@ int main(int argc, char *argv[])
     }
 
     filename = argv[optind];
-    fd = open(filename, O_RDONLY|O_NOCTTY|O_CREAT, 0666);
+    open_accmode = ((type == LOCK_SH || access(filename, R_OK|W_OK) < 0) ?
+                    O_RDONLY : O_RDWR);
+    fd = open(filename, open_accmode|O_NOCTTY|O_CREAT, 0666);
     /* Linux doesn't like O_CREAT on a directory, even though it should be a
-       no-op */
+       no-op; POSIX doesn't allow O_RDWR or O_WRONLY */
     if (fd < 0 && errno == EISDIR)
         fd = open(filename, O_RDONLY|O_NOCTTY);
 
-- 
1.7.3.4


Petr

--
Petr Uzel
IRC: ptr_uzl @ freenode

[-- Attachment #2: Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] flock: make flock(3) work on NFSv4
  2011-09-15  8:19 [PATCH] flock: make flock(3) work on NFSv4 Petr Uzel
@ 2011-09-15  8:23 ` Petr Uzel
  2011-09-27 13:03 ` Karel Zak
  1 sibling, 0 replies; 3+ messages in thread
From: Petr Uzel @ 2011-09-15  8:23 UTC (permalink / raw)
  To: util-linux, Michal Kubecek

[-- Attachment #1: Type: text/plain, Size: 292 bytes --]

On Thu, Sep 15, 2011 at 10:19:17AM +0200, Petr Uzel wrote:
> To pleace an exclusive lock on a file, NFSv4 requires
> the file to be opened RW because of the emulation of flock()
> by fcntl():

Argh, the subject be:

s/flock(3)/flock(1)

... sorry


Petr

--
Petr Uzel
IRC: ptr_uzl @ freenode

[-- Attachment #2: Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] flock: make flock(3) work on NFSv4
  2011-09-15  8:19 [PATCH] flock: make flock(3) work on NFSv4 Petr Uzel
  2011-09-15  8:23 ` Petr Uzel
@ 2011-09-27 13:03 ` Karel Zak
  1 sibling, 0 replies; 3+ messages in thread
From: Karel Zak @ 2011-09-27 13:03 UTC (permalink / raw)
  To: util-linux, Michal Kubecek

On Thu, Sep 15, 2011 at 10:19:17AM +0200, Petr Uzel wrote:
>  sys-utils/flock.c |    7 +++++--
>  1 files changed, 5 insertions(+), 2 deletions(-)

 Applied, thanks.

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-09-27 13:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-09-15  8:19 [PATCH] flock: make flock(3) work on NFSv4 Petr Uzel
2011-09-15  8:23 ` Petr Uzel
2011-09-27 13:03 ` Karel Zak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).