From: Ricky Ng-Adam <rngadam@yahoo.com>
To: linux-fsdevel@vger.kernel.org
Subject: [2.6.10-rc3:fs/locks.c] fcntl F_SETLEASE/[ F_WRLCK| F_RDLCK] inconsistencies
Date: Sun, 05 Dec 2004 17:13:37 -0500 [thread overview]
Message-ID: <cp0153$e4m$1@sea.gmane.org> (raw)
[-- 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);
}
reply other threads:[~2004-12-05 22:22 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='cp0153$e4m$1@sea.gmane.org' \
--to=rngadam@yahoo.com \
--cc=linux-fsdevel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).