Skip to contentSkip to conversation

Locking over NFS

DISCUSSION J.A. Magallon 2 participants 3 messages Nov 27, 2003 – Nov 28, 2003

lore
Share & tools
lore
#0 lore raw

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

Signature · 4 lines
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))
#1 lore raw
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

" " == 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

#2 lore raw
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

" " == 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