LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   flock() fail between NFSv4 server (Linux 3.0/3.2) and client (works with two clients) (https://www.linuxquestions.org/questions/linux-server-73/flock-fail-between-nfsv4-server-linux-3-0-3-2-and-client-works-with-two-clients-4175425036/)

eval- 08-31-2012 04:24 PM

flock() fail between NFSv4 server (Linux 3.0/3.2) and client (works with two clients)
 
If, on NFSv4 client 1, I:
Code:

strace flock -x ./test -c "sleep 60"
it succeeds:
Code:

flock(3, LOCK_EX)                      = 0
On client 2, the same line results in a block, as expected:
Code:

flock(3, LOCK_EX
However, an flock() on the NFSv4 server gets the lock!
Code:

flock(3, LOCK_EX)                      = 0
Why is this? Shouldn't flock() syscall on the NFS server coordinate with the running nfs kernel server?

rpc.statd, lockd, (portmapper: nlockmgr, status) are all running on all clients and also the server.
I've reproduced this on 3.0 and 3.2 kernels and on Ubuntu (12.04) and SuSE (SLES11SP2) Is it expected behavior?

One workaround is to have the NFS server mount itself, then third-party apps depending on flock() still work.
I know that in the ancient past, flock() did not work over NFS, but now it ..almost does?
Does anyone get "proper" behavior with NFSv4 server and client flocks?

eval- 10-02-2012 06:15 AM

Quote:

Originally Posted by eval- (Post 4769489)
Why is this? Shouldn't flock() syscall on the NFS server coordinate with the running nfs kernel server?

I never followed up that I figured this out myself (I think) after reading this comment in the kernel source (fs/nfs/file.c):

Code:

/* We're simulating flock() locks using posix locks on the server */
If I understand correctly the NFS server sees the client's flocks() as fcntl()-implemented locks, which do not conflict with the server's own flock()s. This is rather annoying and counter-intuitive behavior but hey, welcome to Linux, where file locking is a disaster. If I had read these links before banging my head against our servers and these third-party daemons (or grepping through Linux source) I might've saved an evening:

http://0pointer.de/blog/projects/locking2.html
http://0pointer.de/blog/projects/locking.html


All times are GMT -5. The time now is 10:03 AM.