This patch removes the MSNFS define, since these locks aren't really
dependent on it. Pass struct file * from do_fcntl instead of fd.
Use list_del_init and inline locks_notify_blocked. Remove the old
SHLCK and EXLCK flock emulation code.
diff -u linux-2.5.15-flock/fs/locks.c linux-2.5.15-flock/fs/locks.c
--- linux-2.5.15-flock/fs/locks.c Sun May 12 09:21:40 2002
+++ linux-2.5.15-flock/fs/locks.c Mon May 13 08:05:00 2002
@@ -1,4 +1,3 @@
-#define MSNFS /* HACK HACK */
/*
* linux/fs/locks.c
*
@@ -397,10 +396,8 @@
*/
static void locks_delete_block(struct file_lock *waiter)
{
- list_del(&waiter->fl_block);
- INIT_LIST_HEAD(&waiter->fl_block);
- list_del(&waiter->fl_link);
- INIT_LIST_HEAD(&waiter->fl_link);
+ list_del_init(&waiter->fl_block);
+ list_del_init(&waiter->fl_link);
waiter->fl_next = NULL;
}
@@ -423,15 +420,6 @@
list_add(&waiter->fl_link, &blocked_list);
}
-static inline
-void locks_notify_blocked(struct file_lock *waiter)
-{
- if (waiter->fl_notify)
- waiter->fl_notify(waiter);
- else
- wake_up(&waiter->fl_wait);
-}
-
/* Wake up processes blocked waiting for blocker.
* If told to wait then schedule the processes until the block list
* is empty, otherwise empty the block list ourselves.
@@ -439,12 +427,13 @@
static void locks_wake_up_blocks(struct file_lock *blocker)
{
while (!list_empty(&blocker->fl_block)) {
- struct file_lock *waiter = list_entry(blocker->fl_block.next, struct file_lock, fl_block);
- /* Remove waiter from the block list, because by the
- * time it wakes up blocker won't exist any more.
- */
+ struct file_lock *waiter = list_entry(blocker->fl_block.next,
+ struct file_lock, fl_block);
locks_delete_block(waiter);
- locks_notify_blocked(waiter);
+ if (waiter->fl_notify)
+ waiter->fl_notify(waiter);
+ else
+ wake_up(&waiter->fl_wait);
}
}
@@ -576,10 +565,8 @@
if (!(sys_fl->fl_flags & FL_FLOCK) ||
(caller_fl->fl_file == sys_fl->fl_file))
return (0);
-#ifdef MSNFS
if ((caller_fl->fl_type & LOCK_MAND) || (sys_fl->fl_type & LOCK_MAND))
return 0;
-#endif
return (locks_conflict(caller_fl, sys_fl));
}
@@ -1029,10 +1016,8 @@
}
static inline int flock_translate_cmd(int cmd) {
-#ifdef MSNFS
if (cmd & LOCK_MAND)
return cmd & (LOCK_MAND | LOCK_RW);
-#endif
switch (cmd &~ LOCK_NB) {
case LOCK_SH:
return F_RDLCK;
@@ -1325,11 +1310,7 @@
type = error;
error = -EBADF;
- if ((type != F_UNLCK)
-#ifdef MSNFS
- && !(type & LOCK_MAND)
-#endif
- && !(filp->f_mode & 3))
+ if ((type != F_UNLCK) && !(type & LOCK_MAND) && !(filp->f_mode & 3))
goto out_putf;
lock_kernel();
@@ -1346,9 +1327,8 @@
/* Report the first existing lock that would conflict with l.
* This implements the F_GETLK command of fcntl().
*/
-int fcntl_getlk(unsigned int fd, struct flock *l)
+int fcntl_getlk(struct file *filp, struct flock *l)
{
- struct file *filp;
struct file_lock *fl, file_lock;
struct flock flock;
int error;
@@ -1360,19 +1340,14 @@
if ((flock.l_type != F_RDLCK) && (flock.l_type != F_WRLCK))
goto out;
- error = -EBADF;
- filp = fget(fd);
- if (!filp)
- goto out;
-
error = flock_to_posix_lock(filp, &file_lock, &flock);
if (error)
- goto out_putf;
+ goto out;
if (filp->f_op && filp->f_op->lock) {
error = filp->f_op->lock(filp, F_GETLK, &file_lock);
if (error < 0)
- goto out_putf;
+ goto out;
else if (error == LOCK_USE_CLNT)
/* Bypass for NFS with no locking - 2.0.36 compat */
fl = posix_test_lock(filp, &file_lock);
@@ -1392,10 +1367,10 @@
*/
error = -EOVERFLOW;
if (fl->fl_start > OFFT_OFFSET_MAX)
- goto out_putf;
+ goto out;
if ((fl->fl_end != OFFSET_MAX)
&& (fl->fl_end > OFFT_OFFSET_MAX))
- goto out_putf;
+ goto out;
#endif
flock.l_start = fl->fl_start;
flock.l_len = fl->fl_end == OFFSET_MAX ? 0 :
@@ -1407,8 +1382,6 @@
if (!copy_to_user(l, &flock, sizeof(flock)))
error = 0;
-out_putf:
- fput(filp);
out:
return error;
}
@@ -1416,9 +1389,8 @@
/* Apply the lock described by l to an open file descriptor.
* This implements both the F_SETLK and F_SETLKW commands of fcntl().
*/
-int fcntl_setlk(unsigned int fd, unsigned int cmd, struct flock *l)
+int fcntl_setlk(struct file *filp, unsigned int cmd, struct flock *l)
{
- struct file *filp;
struct file_lock *file_lock = locks_alloc_lock(0);
struct flock flock;
struct inode *inode;
@@ -1434,14 +1406,6 @@
if (copy_from_user(&flock, l, sizeof(flock)))
goto out;
- /* Get arguments and validate them ...
- */
-
- error = -EBADF;
- filp = fget(fd);
- if (!filp)
- goto out;
-
error = -EINVAL;
inode = filp->f_dentry->d_inode;
@@ -1454,57 +1418,38 @@
if (!list_empty(&mapping->i_mmap_shared)) {
error = -EAGAIN;
- goto out_putf;
+ goto out;
}
}
error = flock_to_posix_lock(filp, file_lock, &flock);
if (error)
- goto out_putf;
+ goto out;
error = -EBADF;
switch (flock.l_type) {
case F_RDLCK:
if (!(filp->f_mode & FMODE_READ))
- goto out_putf;
+ goto out;
break;
case F_WRLCK:
if (!(filp->f_mode & FMODE_WRITE))
- goto out_putf;
+ goto out;
break;
case F_UNLCK:
break;
- case F_SHLCK:
- case F_EXLCK:
-#ifdef __sparc__
-/* warn a bit for now, but don't overdo it */
-{
- static int count = 0;
- if (!count) {
- count=1;
- printk(KERN_WARNING
- "fcntl_setlk() called by process %d (%s) with broken flock() emulation\n",
- current->pid, current->comm);
- }
-}
- if (!(filp->f_mode & 3))
- goto out_putf;
- break;
-#endif
default:
error = -EINVAL;
- goto out_putf;
+ goto out;
}
if (filp->f_op && filp->f_op->lock != NULL) {
error = filp->f_op->lock(filp, cmd, file_lock);
if (error < 0)
- goto out_putf;
+ goto out;
}
error = posix_lock_file(filp, file_lock, cmd == F_SETLKW);
-out_putf:
- fput(filp);
out:
locks_free_lock(file_lock);
return error;
@@ -1514,9 +1459,8 @@
/* Report the first existing lock that would conflict with l.
* This implements the F_GETLK command of fcntl().
*/
-int fcntl_getlk64(unsigned int fd, struct flock64 *l)
+int fcntl_getlk64(struct file *filp, struct flock64 *l)
{
- struct file *filp;
struct file_lock *fl, file_lock;
struct flock64 flock;
int error;
@@ -1528,19 +1472,14 @@
if ((flock.l_type != F_RDLCK) && (flock.l_type != F_WRLCK))
goto out;
- error = -EBADF;
- filp = fget(fd);
- if (!filp)
- goto out;
-
error = flock64_to_posix_lock(filp, &file_lock, &flock);
if (error)
- goto out_putf;
+ goto out;
if (filp->f_op && filp->f_op->lock) {
error = filp->f_op->lock(filp, F_GETLK, &file_lock);
if (error < 0)
- goto out_putf;
+ goto out;
else if (error == LOCK_USE_CLNT)
/* Bypass for NFS with no locking - 2.0.36 compat */
fl = posix_test_lock(filp, &file_lock);
@@ -1563,8 +1502,6 @@
if (!copy_to_user(l, &flock, sizeof(flock)))
error = 0;
-out_putf:
- fput(filp);
out:
return error;
}
@@ -1572,9 +1509,8 @@
/* Apply the lock described by l to an open file descriptor.
* This implements both the F_SETLK and F_SETLKW commands of fcntl().
*/
-int fcntl_setlk64(unsigned int fd, unsigned int cmd, struct flock64 *l)
+int fcntl_setlk64(struct file *filp, unsigned int cmd, struct flock64 *l)
{
- struct file *filp;
struct file_lock *file_lock = locks_alloc_lock(0);
struct flock64 flock;
struct inode *inode;
@@ -1590,14 +1526,6 @@
if (copy_from_user(&flock, l, sizeof(flock)))
goto out;
- /* Get arguments and validate them ...
- */
-
- error = -EBADF;
- filp = fget(fd);
- if (!filp)
- goto out;
-
error = -EINVAL;
inode = filp->f_dentry->d_inode;
@@ -1610,42 +1538,38 @@
if (!list_empty(&mapping->i_mmap_shared)) {
error = -EAGAIN;
- goto out_putf;
+ goto out;
}
}
error = flock64_to_posix_lock(filp, file_lock, &flock);
if (error)
- goto out_putf;
+ goto out;
error = -EBADF;
switch (flock.l_type) {
case F_RDLCK:
if (!(filp->f_mode & FMODE_READ))
- goto out_putf;
+ goto out;
break;
case F_WRLCK:
if (!(filp->f_mode & FMODE_WRITE))
- goto out_putf;
+ goto out;
break;
case F_UNLCK:
break;
- case F_SHLCK:
- case F_EXLCK:
default:
error = -EINVAL;
- goto out_putf;
+ goto out;
}
if (filp->f_op && filp->f_op->lock != NULL) {
error = filp->f_op->lock(filp, cmd, file_lock);
if (error < 0)
- goto out_putf;
+ goto out;
}
error = posix_lock_file(filp, file_lock, cmd == F_SETLKW64);
-out_putf:
- fput(filp);
out:
locks_free_lock(file_lock);
return error;
@@ -1755,27 +1679,25 @@
(inode->i_mode & (S_IXGRP | S_ISGID)) == S_ISGID) ?
"MANDATORY" : "ADVISORY ");
} else if (fl->fl_flags & FL_FLOCK) {
-#ifdef MSNFS
if (fl->fl_type & LOCK_MAND) {
out += sprintf(out, "FLOCK MSNFS ");
- } else
-#endif
+ } else {
out += sprintf(out, "FLOCK ADVISORY ");
+ }
} else if (fl->fl_flags & FL_LEASE) {
out += sprintf(out, "LEASE MANDATORY ");
} else {
out += sprintf(out, "UNKNOWN UNKNOWN ");
}
-#ifdef MSNFS
if (fl->fl_type & LOCK_MAND) {
out += sprintf(out, "%s ",
(fl->fl_type & LOCK_READ)
? (fl->fl_type & LOCK_WRITE) ? "RW " : "READ "
: (fl->fl_type & LOCK_WRITE) ? "WRITE" : "NONE ");
- } else
-#endif
+ } else {
out += sprintf(out, "%s ",
(fl->fl_type & F_WRLCK) ? "WRITE" : "READ ");
+ }
out += sprintf(out, "%d %s:%ld ",
fl->fl_pid,
inode ? kdevname(inode->i_dev) : "<none>",
@@ -1855,7 +1777,6 @@
return length;
}
-#ifdef MSNFS
/**
* lock_may_read - checks that the region is free of locks
* @inode: the inode that is being read
@@ -1929,7 +1850,6 @@
unlock_kernel();
return result;
}
-#endif
static int __init filelock_init(void)
{
--- linux-2.5.15/include/linux/fs.h Thu May 9 16:22:54 2002
+++ linux-2.5.15-flock/include/linux/fs.h Mon May 13 07:46:48 2002
@@ -536,11 +536,11 @@
#include <linux/fcntl.h>
-extern int fcntl_getlk(unsigned int, struct flock *);
-extern int fcntl_setlk(unsigned int, unsigned int, struct flock *);
+extern int fcntl_getlk(struct file *, struct flock *);
+extern int fcntl_setlk(struct file *, unsigned int, struct flock *);
-extern int fcntl_getlk64(unsigned int, struct flock64 *);
-extern int fcntl_setlk64(unsigned int, unsigned int, struct flock64 *);
+extern int fcntl_getlk64(struct file *, struct flock64 *);
+extern int fcntl_setlk64(struct file *, unsigned int, struct flock64 *);
/* fs/locks.c */
extern void locks_init_lock(struct file_lock *);
--- linux-2.5.15/fs/fcntl.c Thu May 9 16:21:55 2002
+++ linux-2.5.15-flock/fs/fcntl.c Mon May 13 07:46:07 2002
@@ -300,11 +300,11 @@
unlock_kernel();
break;
case F_GETLK:
- err = fcntl_getlk(fd, (struct flock *) arg);
+ err = fcntl_getlk(filp, (struct flock *) arg);
break;
case F_SETLK:
case F_SETLKW:
- err = fcntl_setlk(fd, cmd, (struct flock *) arg);
+ err = fcntl_setlk(filp, cmd, (struct flock *) arg);
break;
case F_GETOWN:
/*
@@ -386,13 +386,13 @@
switch (cmd) {
case F_GETLK64:
- err = fcntl_getlk64(fd, (struct flock64 *) arg);
+ err = fcntl_getlk64(filp, (struct flock64 *) arg);
break;
case F_SETLK64:
- err = fcntl_setlk64(fd, cmd, (struct flock64 *) arg);
+ err = fcntl_setlk64(filp, cmd, (struct flock64 *) arg);
break;
case F_SETLKW64:
- err = fcntl_setlk64(fd, cmd, (struct flock64 *) arg);
+ err = fcntl_setlk64(filp, cmd, (struct flock64 *) arg);
break;
default:
err = do_fcntl(fd, cmd, arg, filp);