aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nfs
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/nfs
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/nfs')
-rw-r--r--fs/nfs/delegation.c10
-rw-r--r--fs/nfs/nfs4state.c8
2 files changed, 9 insertions, 9 deletions
diff --git a/fs/nfs/delegation.c b/fs/nfs/delegation.c
index 57db3244f4d9..7ec4814e298d 100644
--- a/fs/nfs/delegation.c
+++ b/fs/nfs/delegation.c
@@ -73,20 +73,20 @@ static int nfs_delegation_claim_locks(struct nfs_open_context *ctx, struct nfs4_
73 if (inode->i_flock == NULL) 73 if (inode->i_flock == NULL)
74 goto out; 74 goto out;
75 75
76 /* Protect inode->i_flock using the file locks lock */ 76 /* Protect inode->i_flock using the i_lock */
77 lock_flocks(); 77 spin_lock(&inode->i_lock);
78 for (fl = inode->i_flock; fl != NULL; fl = fl->fl_next) { 78 for (fl = inode->i_flock; fl != NULL; fl = fl->fl_next) {
79 if (!(fl->fl_flags & (FL_POSIX|FL_FLOCK))) 79 if (!(fl->fl_flags & (FL_POSIX|FL_FLOCK)))
80 continue; 80 continue;
81 if (nfs_file_open_context(fl->fl_file) != ctx) 81 if (nfs_file_open_context(fl->fl_file) != ctx)
82 continue; 82 continue;
83 unlock_flocks(); 83 spin_unlock(&inode->i_lock);
84 status = nfs4_lock_delegation_recall(fl, state, stateid); 84 status = nfs4_lock_delegation_recall(fl, state, stateid);
85 if (status < 0) 85 if (status < 0)
86 goto out; 86 goto out;
87 lock_flocks(); 87 spin_lock(&inode->i_lock);
88 } 88 }
89 unlock_flocks(); 89 spin_unlock(&inode->i_lock);
90out: 90out:
91 return status; 91 return status;
92} 92}
diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c
index 1fab140764c4..ff10b4aa534c 100644
--- a/fs/nfs/nfs4state.c
+++ b/fs/nfs/nfs4state.c
@@ -1373,13 +1373,13 @@ static int nfs4_reclaim_locks(struct nfs4_state *state, const struct nfs4_state_
1373 /* Guard against delegation returns and new lock/unlock calls */ 1373 /* Guard against delegation returns and new lock/unlock calls */
1374 down_write(&nfsi->rwsem); 1374 down_write(&nfsi->rwsem);
1375 /* Protect inode->i_flock using the BKL */ 1375 /* Protect inode->i_flock using the BKL */
1376 lock_flocks(); 1376 spin_lock(&inode->i_lock);
1377 for (fl = inode->i_flock; fl != NULL; fl = fl->fl_next) { 1377 for (fl = inode->i_flock; fl != NULL; fl = fl->fl_next) {
1378 if (!(fl->fl_flags & (FL_POSIX|FL_FLOCK))) 1378 if (!(fl->fl_flags & (FL_POSIX|FL_FLOCK)))
1379 continue; 1379 continue;
1380 if (nfs_file_open_context(fl->fl_file)->state != state) 1380 if (nfs_file_open_context(fl->fl_file)->state != state)
1381 continue; 1381 continue;
1382 unlock_flocks(); 1382 spin_unlock(&inode->i_lock);
1383 status = ops->recover_lock(state, fl); 1383 status = ops->recover_lock(state, fl);
1384 switch (status) { 1384 switch (status) {
1385 case 0: 1385 case 0:
@@ -1406,9 +1406,9 @@ static int nfs4_reclaim_locks(struct nfs4_state *state, const struct nfs4_state_
1406 /* kill_proc(fl->fl_pid, SIGLOST, 1); */ 1406 /* kill_proc(fl->fl_pid, SIGLOST, 1); */
1407 status = 0; 1407 status = 0;
1408 } 1408 }
1409 lock_flocks(); 1409 spin_lock(&inode->i_lock);
1410 } 1410 }
1411 unlock_flocks(); 1411 spin_unlock(&inode->i_lock);
1412out: 1412out:
1413 up_write(&nfsi->rwsem); 1413 up_write(&nfsi->rwsem);
1414 return status; 1414 return status;