[PATCH] Fix up broken POSIX locks...

From: Trond Myklebust
Date: Wed Jun 23 2004 - 11:56:54 EST


The following patch fixes up two nasty inconsistencies in the POSIX
byte-range locking code. The lockowner alone is NOT sufficient to
determine ownership of a lock.

Cheers,
Trond
locks.c | 5 ++++-
1 files changed, 4 insertions(+), 1 deletion(-)

diff -u --recursive --new-file --show-c-function linux-2.6.7/fs/locks.c linux-2.6.7-00-fix_locks/fs/locks.c
--- linux-2.6.7/fs/locks.c 2004-06-16 14:58:27.000000000 -0400
+++ linux-2.6.7-00-fix_locks/fs/locks.c 2004-06-23 12:46:29.000000000 -0400
@@ -921,6 +921,7 @@ int posix_lock_file(struct file *filp, s
int locks_mandatory_locked(struct inode *inode)
{
fl_owner_t owner = current->files;
+ unsigned int pid = current->tgid;
struct file_lock *fl;

/*
@@ -932,6 +933,8 @@ int locks_mandatory_locked(struct inode
continue;
if (fl->fl_owner != owner)
break;
+ if (fl->fl_pid != pid)
+ break;
}
unlock_kernel();
return fl ? -EAGAIN : 0;
@@ -1684,7 +1687,7 @@ void locks_remove_posix(struct file *fil
lock_kernel();
while (*before != NULL) {
struct file_lock *fl = *before;
- if (IS_POSIX(fl) && (fl->fl_owner == owner)) {
+ if (IS_POSIX(fl) && posix_same_owner(fl, &lock)) {
locks_delete_lock(before);
continue;
}