aboutsummaryrefslogtreecommitdiffstats
path: root/fs/lockd
diff options
context:
space:
mode:
authorNeilBrown <neilb@suse.de>2014-02-07 01:10:26 -0500
committerJ. Bruce Fields <bfields@redhat.com>2014-02-13 14:55:02 -0500
commit2ec197db1a56c9269d75e965f14c344b58b2a4f6 (patch)
treede33f16ea4f62413085f1572481de76b2e7533ec /fs/lockd
parent09bdc2d70dedd0fc0358da93bca664c7b11ff907 (diff)
lockd: send correct lock when granting a delayed lock.
If an NFS client attempts to get a lock (using NLM) and the lock is not available, the server will remember the request and when the lock becomes available it will send a GRANT request to the client to provide the lock. If the client already held an adjacent lock, the GRANT callback will report the union of the existing and new locks, which can confuse the client. This happens because __posix_lock_file (called by vfs_lock_file) updates the passed-in file_lock structure when adjacent or over-lapping locks are found. To avoid this problem we take a copy of the two fields that can be changed (fl_start and fl_end) before the call and restore them afterwards. An alternate would be to allocate a 'struct file_lock', initialise it, use locks_copy_lock() to take a copy, then locks_release_private() after the vfs_lock_file() call. But that is a lot more work. Reported-by: Olaf Kirch <okir@suse.com> Signed-off-by: NeilBrown <neilb@suse.de> Cc: stable@vger.kernel.org Signed-off-by: J. Bruce Fields <bfields@redhat.com> -- v1 had a couple of issues (large on-stack struct and didn't really work properly). This version is much better tested. Signed-off-by: J. Bruce Fields <bfields@redhat.com>
Diffstat (limited to 'fs/lockd')
-rw-r--r--fs/lockd/svclock.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/fs/lockd/svclock.c b/fs/lockd/svclock.c
index e066a3902973..ab798a88ec1d 100644
--- a/fs/lockd/svclock.c
+++ b/fs/lockd/svclock.c
@@ -779,6 +779,7 @@ nlmsvc_grant_blocked(struct nlm_block *block)
779 struct nlm_file *file = block->b_file; 779 struct nlm_file *file = block->b_file;
780 struct nlm_lock *lock = &block->b_call->a_args.lock; 780 struct nlm_lock *lock = &block->b_call->a_args.lock;
781 int error; 781 int error;
782 loff_t fl_start, fl_end;
782 783
783 dprintk("lockd: grant blocked lock %p\n", block); 784 dprintk("lockd: grant blocked lock %p\n", block);
784 785
@@ -796,9 +797,16 @@ nlmsvc_grant_blocked(struct nlm_block *block)
796 } 797 }
797 798
798 /* Try the lock operation again */ 799 /* Try the lock operation again */
800 /* vfs_lock_file() can mangle fl_start and fl_end, but we need
801 * them unchanged for the GRANT_MSG
802 */
799 lock->fl.fl_flags |= FL_SLEEP; 803 lock->fl.fl_flags |= FL_SLEEP;
804 fl_start = lock->fl.fl_start;
805 fl_end = lock->fl.fl_end;
800 error = vfs_lock_file(file->f_file, F_SETLK, &lock->fl, NULL); 806 error = vfs_lock_file(file->f_file, F_SETLK, &lock->fl, NULL);
801 lock->fl.fl_flags &= ~FL_SLEEP; 807 lock->fl.fl_flags &= ~FL_SLEEP;
808 lock->fl.fl_start = fl_start;
809 lock->fl.fl_end = fl_end;
802 810
803 switch (error) { 811 switch (error) {
804 case 0: 812 case 0: