nfs lockup

Kenneth Johansson (ken@canit.se)
Fri, 24 Sep 1999 20:33:59 +0200


This is a multi-part message in MIME format.
--------------B0727ECF313C2A21DA3C4530
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

If I run the included program on a nfs mounted filesystem my system hangs
only ping works.

This happens on 2.2.12 and 2.3.18 systems.

--------------B0727ECF313C2A21DA3C4530
Content-Type: text/plain; charset=us-ascii;
name="1.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="1.c"

/* test whether fcntl locking works on this system */

#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <fcntl.h>
#include <sys/fcntl.h>
#include <errno.h>

static int sys_waitpid(pid_t pid,int *status,int options)
{
return waitpid(pid,status,options);
}

#define DATA "conftest.fcntl"

#ifndef SEEK_SET
#define SEEK_SET 0
#endif

/* lock a byte range in a open file */
int main(int argc, char *argv[])
{
struct flock lock;
int fd, pid, ret, status=1;

if (!(pid=fork())) {
sleep(2);
fd = open(DATA, O_RDONLY);

if (fd == -1) exit(1);

lock.l_type = F_WRLCK;
lock.l_whence = SEEK_SET;
lock.l_start = 0;
lock.l_len = 4;
lock.l_pid = getpid();

lock.l_type = F_WRLCK;

/* check if a lock applies */
ret = fcntl(fd,F_GETLK,&lock);

if ((ret == -1) ||
(lock.l_type == F_UNLCK)) {
exit(1);
} else {
exit(0);
}
}

fd = open(DATA, O_RDWR|O_CREAT|O_TRUNC, 0600);

lock.l_type = F_WRLCK;
lock.l_whence = SEEK_SET;
lock.l_start = 0;
lock.l_len = 4;
lock.l_pid = getpid();

/* set a 4 byte write lock */
fcntl(fd,F_SETLK,&lock);

sys_waitpid(pid, &status, 0);

unlink(DATA);

exit(status);
}

--------------B0727ECF313C2A21DA3C4530--

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/