2005-10-20 23:01:43

by petter.knutsen

[permalink] [raw]
Subject: File lock with multiple clients

Hello,

I have a question about NFS and file locking on multiple clients.

Let's say I have a NFS server and two clients; "client a" and "client b". Is
it possible to flock() a file on "client a", and make "client b" respect a's
lock?

I've managed to lock files on "client a" and let other processes on "client
a" honour the locks, but "client b" doesn't seem to be able to see the lock=
s.


Before I research any further, does anyone know if this is possible?

Thanks in advance,

Petter=


-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs


2005-10-21 00:43:38

by NeilBrown

[permalink] [raw]
Subject: Re: File lock with multiple clients

On Friday October 21, [email protected] wrote:
> Hello,
>
> I have a question about NFS and file locking on multiple clients.
>
> Let's say I have a NFS server and two clients; "client a" and "client b". Is
> it possible to flock() a file on "client a", and make "client b" respect a's
> lock?
>
> I've managed to lock files on "client a" and let other processes on "client
> a" honour the locks, but "client b" doesn't seem to be able to see the locks.
>
>
> Before I research any further, does anyone know if this is possible?

Check the man page: "man flock":

NOTES
flock(2) does not lock files over NFS. Use fcntl(2) instead: that does
work over NFS, given a sufficiently recent version of Linux and a
server which supports locking.

Use fcntl or lockf (which is wrapper for fcntl) if you want to lock
over NFS.

NeilBrown


-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs

2005-10-21 01:20:20

by Trond Myklebust

[permalink] [raw]
Subject: Re: File lock with multiple clients

fr den 21.10.2005 klokka 10:43 (+1000) skreiv Neil Brown:

> NOTES
> flock(2) does not lock files over NFS. Use fcntl(2) instead: that does
> work over NFS, given a sufficiently recent version of Linux and a
> server which supports locking.
>

Note that this is not entirely accurate any more. Recent kernels will
emulate flock() over NFS by using fcntl() locks.

Cheers,
Trond



-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs

2005-10-21 10:25:15

by petter.knutsen

[permalink] [raw]
Subject: Re: File lock with multiple clients

> Check the man page: "man flock":
>=20
> Use fcntl or lockf (which is wrapper for fcntl) if you want to lock
> over NFS.

As Trond said, flock() seems to work by emulating fcntl(), but regardless of
whether I'm using fcntl() directly or flock() with emulation, should my
scenario with two clients work, where one client locks and the other client
honouring the lock?

As I said, it works between processes on the same client, but not between
processes on different clients.

I would appreciate if someone could tell me if this is possible or not, so I
can either abandon NFS and look for alternatives or, if it should work, go
back and look for flaws in my setup. :-)

--
Petter=


-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs

2005-10-21 10:37:37

by Vincent Roqueta

[permalink] [raw]
Subject: Re: File lock with multiple clients

Le vendredi 21 Octobre 2005 12:25, [email protected] a =E9crit=A0:
> > Check the man page: "man flock":
> >
> > Use fcntl or lockf (which is wrapper for fcntl) if you want to lock
> > over NFS.
>
> As Trond said, flock() seems to work by emulating fcntl(), but regardless
> of whether I'm using fcntl() directly or flock() with emulation, should my
> scenario with two clients work, where one client locks and the other
> client honouring the lock?
>
> As I said, it works between processes on the same client, but not between
> processes on different clients.
I am going to test that on different clients.

> I would appreciate if someone could tell me if this is possible or not
That is possible. (advisory locking)
I have got some experiences of that the last weeks.

Here is for NFSv4.
http://nfsv4.bullopensource.org/tools/tests/page39.php

> , so I can either abandon NFS and look for alternatives or, if it should
> work, go back and look for flaws in my setup. :-)=20


Vincent


-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs

2005-10-21 11:01:35

by Vincent Roqueta

[permalink] [raw]
Subject: Re: File lock with multiple clients

Le vendredi 21 Octobre 2005 12:40, Vincent Roqueta a =E9crit=A0:
> Le vendredi 21 Octobre 2005 12:25, [email protected] a =E9crit=A0:
> > > Check the man page: "man flock":
> > >
> > > Use fcntl or lockf (which is wrapper for fcntl) if you want to lock
> > > over NFS.
> >
> > As Trond said, flock() seems to work by emulating fcntl(), but regardle=
ss
> > of whether I'm using fcntl() directly or flock() with emulation, should
> > my scenario with two clients work, where one client locks and the other
> > client honouring the lock?
> >
> > As I said, it works between processes on the same client, but not betwe=
en
> > processes on different clients.
>
> I am going to test that on different clients.
I have tested it. That works.
kernel : linux 2.6.14-rc4-CITI_NFS4_ALL-1. It may works on older kernel too.

Vincent


-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs

2005-10-21 11:48:12

by NeilBrown

[permalink] [raw]
Subject: Re: File lock with multiple clients

On Friday October 21, [email protected] wrote:
>
> I would appreciate if someone could tell me if this is possible or not, so I
> can either abandon NFS and look for alternatives or, if it should work, go
> back and look for flaws in my setup. :-)

fcntl locking definitely works between separate NFS clients.
There are some common config errors that can cause problems though,
including not having 'statd' running and firewalling the 'lockd' or
'statd' ports (which 'rpcinfo -p' reports are 'nlockmgr' and
'status').

NeilBrown


-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs

2005-10-21 15:23:05

by petter.knutsen

[permalink] [raw]
Subject: Re: File lock with multiple clients

> Note that this is not entirely accurate any more. Recent kernels will
> emulate flock() over NFS by using fcntl() locks.

I've gotten fcntl() to work, but it doesn't seem that flock() works between
clients. Do you know which kernel version implemented the emulation? Are we
talking about the latest 2.6.14 rc, or should a 2.6.x be sufficient? Also,
should this emulation be enough to make flock() work between clients?

Thanks for all your help.

--
Petter=


-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs

2005-10-21 16:33:06

by Trond Myklebust

[permalink] [raw]
Subject: Re: File lock with multiple clients

fr den 21.10.2005 klokka 17:22 (+0200) skreiv [email protected]:
> > Note that this is not entirely accurate any more. Recent kernels will
> > emulate flock() over NFS by using fcntl() locks.
>
> I've gotten fcntl() to work, but it doesn't seem that flock() works between
> clients. Do you know which kernel version implemented the emulation? Are we
> talking about the latest 2.6.14 rc, or should a 2.6.x be sufficient? Also,
> should this emulation be enough to make flock() work between clients?

I think I went into 2.6.12, but a quick hunt through the ChangeLog file
should tell you.

The emulation should make flock() work between clients by converting
flock() calls into fcntl() calls on the wire, but this means that you
have to be very wary of using flock on the server: Linux servers (unlike
most others) will not notice conflicts between an fcntl() lock (which I
remind you is what comes in from the clients) and a flock() lock.

The best option is therefore still to convert your application to use
fcntl() locks if possible.

Cheers,
Trond



-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs