aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nfsd/nfs4state.c
diff options
context:
space:
mode:
authorJeff Layton <jlayton@redhat.com>2013-06-21 08:58:15 -0400
committerAl Viro <viro@zeniv.linux.org.uk>2013-06-29 04:57:42 -0400
commit1c8c601a8c0dc59fe64907dcd9d512a3d181ddc7 (patch)
tree1a9c91de460a7c2f9fd6ad77060be484456e49b9 /fs/nfsd/nfs4state.c
parent889746917193ab3007a779d65231510715b20fb6 (diff)
locks: protect most of the file_lock handling with i_lock
Having a global lock that protects all of this code is a clear scalability problem. Instead of doing that, move most of the code to be protected by the i_lock instead. The exceptions are the global lists that the ->fl_link sits on, and the ->fl_block list. ->fl_link is what connects these structures to the global lists, so we must ensure that we hold those locks when iterating over or updating these lists. Furthermore, sound deadlock detection requires that we hold the blocked_list state steady while checking for loops. We also must ensure that the search and update to the list are atomic. For the checking and insertion side of the blocked_list, push the acquisition of the global lock into __posix_lock_file and ensure that checking and update of the blocked_list is done without dropping the lock in between. On the removal side, when waking up blocked lock waiters, take the global lock before walking the blocked list and dequeue the waiters from the global list prior to removal from the fl_block list. With this, deadlock detection should be race free while we minimize excessive file_lock_lock thrashing. Finally, in order to avoid a lock inversion problem when handling /proc/locks output we must ensure that manipulations of the fl_block list are also protected by the file_lock_lock. Signed-off-by: Jeff Layton <jlayton@redhat.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs/nfsd/nfs4state.c')
-rw-r--r--fs/nfsd/nfs4state.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index 316ec843dec2..f17051838b41 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -2645,13 +2645,13 @@ static void nfsd_break_one_deleg(struct nfs4_delegation *dp)
2645 2645
2646 list_add_tail(&dp->dl_recall_lru, &nn->del_recall_lru); 2646 list_add_tail(&dp->dl_recall_lru, &nn->del_recall_lru);
2647 2647
2648 /* only place dl_time is set. protected by lock_flocks*/ 2648 /* Only place dl_time is set; protected by i_lock: */
2649 dp->dl_time = get_seconds(); 2649 dp->dl_time = get_seconds();
2650 2650
2651 nfsd4_cb_recall(dp); 2651 nfsd4_cb_recall(dp);
2652} 2652}
2653 2653
2654/* Called from break_lease() with lock_flocks() held. */ 2654/* Called from break_lease() with i_lock held. */
2655static void nfsd_break_deleg_cb(struct file_lock *fl) 2655static void nfsd_break_deleg_cb(struct file_lock *fl)
2656{ 2656{
2657 struct nfs4_file *fp = (struct nfs4_file *)fl->fl_owner; 2657 struct nfs4_file *fp = (struct nfs4_file *)fl->fl_owner;
@@ -4520,7 +4520,7 @@ check_for_locks(struct nfs4_file *filp, struct nfs4_lockowner *lowner)
4520 struct inode *inode = filp->fi_inode; 4520 struct inode *inode = filp->fi_inode;
4521 int status = 0; 4521 int status = 0;
4522 4522
4523 lock_flocks(); 4523 spin_lock(&inode->i_lock);
4524 for (flpp = &inode->i_flock; *flpp != NULL; flpp = &(*flpp)->fl_next) { 4524 for (flpp = &inode->i_flock; *flpp != NULL; flpp = &(*flpp)->fl_next) {
4525 if ((*flpp)->fl_owner == (fl_owner_t)lowner) { 4525 if ((*flpp)->fl_owner == (fl_owner_t)lowner) {
4526 status = 1; 4526 status = 1;
@@ -4528,7 +4528,7 @@ check_for_locks(struct nfs4_file *filp, struct nfs4_lockowner *lowner)
4528 } 4528 }
4529 } 4529 }
4530out: 4530out:
4531 unlock_flocks(); 4531 spin_unlock(&inode->i_lock);
4532 return status; 4532 return status;
4533} 4533}
4534 4534