linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [2.6.10-rc3:fs/locks.c] fcntl  F_SETLEASE/[ F_WRLCK| F_RDLCK] inconsistencies
@ 2004-12-05 22:13 Ricky Ng-Adam
  0 siblings, 0 replies; only message in thread
From: Ricky Ng-Adam @ 2004-12-05 22:13 UTC (permalink / raw)
  To: linux-fsdevel

[-- Attachment #1: Type: text/plain, Size: 1937 bytes --]

Hello!

Behavior for fcntl seems to have changed for F_SETLEASE between 2.6.9 
and 2.6.10-rcX.

I've noticed this problem while running LTP (Linux Test Project) suite; 
test fcntl23 FAIL while it doesn't in 2.6.8.1 and 2.6.9.

I've noticed that this bit of code was added in fs/locks.c:__setlease:

         error = -EAGAIN;
         if ((arg == F_RDLCK) && (atomic_read(&inode->i_writecount) > 0))
                 goto out;
         if ((arg == F_WRLCK)
             && ((atomic_read(&dentry->d_count) > 1)
                 || (atomic_read(&inode->i_count) > 1)))
                 goto out;

With this change, doing a

  fd = open("/tmp/mytest", O_RDONLY|O_CREAT,0777)

and trying to do

  fcntl(fd, F_SETLEASE, F_RDLCK)

FAILs with EAGAIN (Resource temporarily unavailable).

If I change

  if ((arg == F_RDLCK) && (atomic_read(&inode->i_writecount) > 0))

to

  if ((arg == F_RDLCK) && (atomic_read(&inode->i_writecount) > 1))

it works for F_RDLCK. After all, the process calling fcntl may have the 
file opened for writing...

I'm attaching sample programs that I ran on each.  There results are here:

2.6.8:

warren:~# ./rdlck
handler called!
warren:~# ./wrlck
F_SETLEASE, F_WRLCK failed: 11, Resource temporarily unavailable

2.6.8.1 (on coLinux;  2.6.8.1-co-0.6.2-pre6):

colinux:~# ./rdlck
handler called!
colinux:~# ./wrlck
handler called!

2.6.9:

warren:~# ./rdlck
handler called!
warren:~# ./wrlck
F_SETLEASE, F_WRLCK failed: 11, Resource temporarily unavailable

2.6.10-rc3:

warren:~# ./rdlck
F_SETLEASE, F_RDLCK failed: 11, Resource temporarily unavailable
warren:~# ./wrlck
F_SETLEASE, F_WRLCK failed: 11, Resource temporarily unavailable

2.6.10-rc3, modified:

warren:~# ./rdlck
handler called!
warren:~# ./wrlck
F_SETLEASE, F_WRLCK failed: 11, Resource temporarily unavailable

Is the test wrong or is this a bug? Why is it never possible to get a 
F_WRLCK (except, strangely, on coLinux)?

Thanks,

Ricky Ng-Adam


[-- Attachment #2: wrlck.c --]
[-- Type: text/plain, Size: 774 bytes --]


#define _GNU_SOURCE

#include <fcntl.h>
#include <signal.h>
#include <unistd.h>
#include <errno.h>

int	event_fd;
struct sigaction	act;

void handler(int sig, siginfo_t *si, void *data)
{
	event_fd = si->si_fd;
	printf("handler called!\n");
	exit(0);
}

int main(void)
{
	int fd;
	act.sa_sigaction = handler;
	sigemptyset(&act.sa_mask);
	act.sa_flags = SA_SIGINFO;
	sigaction(SIGRTMIN, &act, NULL);
	if ((fd = open("/tmp/mytest", O_RDONLY|O_CREAT,0777)) == -1)
		printf("Create file failed: %d, %s \n", errno, strerror(errno));

	fcntl(fd, F_SETSIG, SIGRTMIN);
	if(fcntl(fd, F_SETLEASE, F_WRLCK) == -1) {
		printf("F_SETLEASE, F_WRLCK failed: %d, %s \n", 
				errno, strerror(errno));
		exit(1);
	}
	fd = open("/tmp/mytest", O_RDWR|O_CREAT,0777);
	while(1) 
		sleep(1);
}


[-- Attachment #3: rdlck.c --]
[-- Type: text/plain, Size: 772 bytes --]


#define _GNU_SOURCE

#include <fcntl.h>
#include <signal.h>
#include <unistd.h>
#include <errno.h>

int	event_fd;
struct sigaction	act;

void handler(int sig, siginfo_t *si, void *data)
{
	event_fd = si->si_fd;
	printf("handler called!\n");
	exit(0);
}

int main(void)
{
	int fd;
	act.sa_sigaction = handler;
	sigemptyset(&act.sa_mask);
	act.sa_flags = SA_SIGINFO;
	sigaction(SIGRTMIN, &act, NULL);
	if ((fd = open("/tmp/mytest", O_RDWR|O_CREAT,0777)) == -1)
		printf("Create file failed: %d, %s \n", errno, strerror(errno));

	fcntl(fd, F_SETSIG, SIGRTMIN);
	if(fcntl(fd, F_SETLEASE, F_RDLCK) == -1) {
		printf("F_SETLEASE, F_RDLCK failed: %d, %s \n", 
				errno, strerror(errno));
		exit(1);
	}
	fd = open("/tmp/mytest", O_RDWR|O_CREAT,0777);
	while(1) 
		sleep(1);
}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2004-12-05 22:22 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-12-05 22:13 [2.6.10-rc3:fs/locks.c] fcntl F_SETLEASE/[ F_WRLCK| F_RDLCK] inconsistencies Ricky Ng-Adam

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).