Skip to contentSkip to conversation

NFS: Fix fcntl F_GETLK not reporting some conflicts

PATCH Applied Sergey Vlasov 2 participants 2 messages Nov 28, 2010 – Dec 7, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 NFS: Fix fcntl F_GETLK not reporting some conflicts

The commit 129a84de2347002f09721cda3155ccfd19fade40 (locks: fix F_GETLK regression (failure to find conflicts)) fixed the posix_test_lock() function by itself, however, its usage in NFS changed by the commit 9d6a8c5c213e34c475e72b245a8eb709258e968c (locks: give posix_test_lock same interface as ->lock) remained broken - subsequent NFS-specific locking code received F_UNLCK instead of the user-specified lock type. To fix the problem, fl->fl_type needs to be saved before the posix_test_lock() call and restored if no local conflicts were reported.

Reference: https://bugzilla.kernel.org/show_bug.cgi?id=23892

---
 fs/nfs/file.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

There seems to be a similar bug in fs/9p/vfs_file.c:v9fs_file_getlock() and an even worse confusion in fs/afs/flock.c:afs_do_getlk(), but I can't test them.

fs/nfs/file.c +2 -0
index 60677f9..7bf029e 100644
@@ -693,6 +693,7 @@ do_getlk(struct file *filp, int cmd, struct file_lock *fl, int is_local)
 {
 	struct inode *inode = filp->f_mapping->host;
 	int status = 0;
+	unsigned int saved_type = fl->fl_type;
 
 	/* Try local locking first */
 	posix_test_lock(filp, fl);
@@ -700,6 +701,7 @@ do_getlk(struct file *filp, int cmd, struct file_lock *fl, int is_local)
 		/* found a conflict */
 		goto out;
 	}
+	fl->fl_type = saved_type;
 
 	if (nfs_have_delegation(inode, FMODE_READ))
 		goto out_noconflict;
Signature · 1 line
1.7.3.2
#1 lore raw
Quoted 34 lines · Sergey Vlasov

The commit 129a84de2347002f09721cda3155ccfd19fade40 (locks: fix F_GETLK regression (failure to find conflicts)) fixed the posix_test_lock() function by itself, however, its usage in NFS changed by the commit 9d6a8c5c213e34c475e72b245a8eb709258e968c (locks: give posix_test_lock same interface as ->lock) remained broken - subsequent NFS-specific locking code received F_UNLCK instead of the user-specified lock type. To fix the problem, fl->fl_type needs to be saved before the posix_test_lock() call and restored if no local conflicts were reported.

Reference: https://bugzilla.kernel.org/show_bug.cgi?id=23892

---
 fs/nfs/file.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

There seems to be a similar bug in fs/9p/vfs_file.c:v9fs_file_getlock() and an even worse confusion in fs/afs/flock.c:afs_do_getlk(), but I can't test them.

fs/nfs/file.c +1 -0
index 60677f9..7bf029e 100644
@@ -693,6 +693,7 @@ do_getlk(struct file *filp, int cmd, struct file_lock *fl, int is_local)
 {
 	struct inode *inode = filp->f_mapping->host;
 	int status = 0;
+	unsigned int saved_type = fl->fl_type;
 
 	/* Try local locking first */
 	posix_test_lock(filp, fl);

fs/nfs/file.c do_getlk(struct file *filp, int cmd, struct file_lock *fl, int is_local) · line 707

Quoted 7 lines
fs/nfs/file.c +1 -0
@@ -700,6 +701,7 @@ do_getlk(struct file *filp, int cmd, struct file_lock *fl, int is_local)
 		/* found a conflict */
 		goto out;
 	}
+	fl->fl_type = saved_type;
 
 	if (nfs_have_delegation(inode, FMODE_READ))
 		goto out_noconflict;

Thanks! Applied...

Signature · 6 lines
Trond Myklebust
Linux NFS client maintainer

NetApp
[email protected]
www.netapp.com