2003-11-27 23:09:53

by J.A. Magallon

[permalink] [raw]
Subject: Locking over NFS

Hi all...

Is locking via lockf/fcntl supposed to work over NFS mounted volumes
in 2.4 ?
I can't get it to work, even if kernel [lockd] is running in the server.
Server locks the file, and client gets an error:

annwn:~/dev/lk> lockf 10000
locked
<switch term>
annwn:~/dev/lk> bpsh 0 lockf
lockf:F_LOCK: No locks available

lockf.c:

#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>

int main(int argc, char** argv)
{
int fd;

fd = open("lock",O_RDWR);
if (fd<0)
perror("open");

if (lockf(fd,F_LOCK,0)<0)
perror("lockf:F_LOCK");
else
printf("locked\n");
fflush(stdout);

if (argc>1)
sleep(atoi(argv[1]));

if (lockf(fd,F_ULOCK,0)<0)
perror("lockf:F_ULOCK");
else
printf("unlocked\n");
fflush(stdout);

return 0;
}

TIA

--
J.A. Magallon <jamagallon()able!es> \ Software is like sex:
werewolf!able!es \ It's better when it's free
Mandrake Linux release 10.0 (Cooker) for i586
Linux 2.4.23-rc5-jam1 (gcc 3.3.1 (Mandrake Linux 9.2 3.3.1-4mdk))


2003-11-28 01:01:53

by Trond Myklebust

[permalink] [raw]
Subject: Re: Locking over NFS

>>>>> " " == J A Magallon <J.A.> writes:

> Hi all... Is locking via lockf/fcntl supposed to work over NFS
> mounted volumes in 2.4 ? I can't get it to work, even if

Yes, it works just fine.

You're probably failing to run rpc.statd or something like that. See
the NFS FAQ & HOWTO on http://nfs.sourceforge.net

Cheers,
Trond

2003-11-28 01:13:01

by Trond Myklebust

[permalink] [raw]
Subject: Re: Locking over NFS

>>>>> " " == Trond Myklebust <[email protected]> writes:

> Yes, it works just fine.

> You're probably failing to run rpc.statd or something like
> that. See the NFS FAQ & HOWTO on http://nfs.sourceforge.net

Come to think of it, are you perhaps trying to set the lock on an
NFSroot volume? Those are automatically mounted with the 'nolock'
mount option set.

Cheers,
Trond