lkml.org 
[lkml]   [1999]   [Sep]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
Subjectnfs lockup


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.

/* 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);
}
\
 
 \ /
  Last update: 2005-03-22 13:54    [W:0.032 / U:1.056 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site