aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ceph
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/ceph
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/ceph')
-rw-r--r--fs/ceph/locks.c2
-rw-r--r--fs/ceph/mds_client.c8
2 files changed, 5 insertions, 5 deletions
diff --git a/fs/ceph/locks.c b/fs/ceph/locks.c
index ebbf680378e2..690f73f42425 100644
--- a/fs/ceph/locks.c
+++ b/fs/ceph/locks.c
@@ -192,7 +192,7 @@ void ceph_count_locks(struct inode *inode, int *fcntl_count, int *flock_count)
192 192
193/** 193/**
194 * Encode the flock and fcntl locks for the given inode into the ceph_filelock 194 * Encode the flock and fcntl locks for the given inode into the ceph_filelock
195 * array. Must be called with lock_flocks() already held. 195 * array. Must be called with inode->i_lock already held.
196 * If we encounter more of a specific lock type than expected, return -ENOSPC. 196 * If we encounter more of a specific lock type than expected, return -ENOSPC.
197 */ 197 */
198int ceph_encode_locks_to_buffer(struct inode *inode, 198int ceph_encode_locks_to_buffer(struct inode *inode,
diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c
index 4d2920304be8..74fd2898b2ab 100644
--- a/fs/ceph/mds_client.c
+++ b/fs/ceph/mds_client.c
@@ -2481,20 +2481,20 @@ static int encode_caps_cb(struct inode *inode, struct ceph_cap *cap,
2481 struct ceph_filelock *flocks; 2481 struct ceph_filelock *flocks;
2482 2482
2483encode_again: 2483encode_again:
2484 lock_flocks(); 2484 spin_lock(&inode->i_lock);
2485 ceph_count_locks(inode, &num_fcntl_locks, &num_flock_locks); 2485 ceph_count_locks(inode, &num_fcntl_locks, &num_flock_locks);
2486 unlock_flocks(); 2486 spin_unlock(&inode->i_lock);
2487 flocks = kmalloc((num_fcntl_locks+num_flock_locks) * 2487 flocks = kmalloc((num_fcntl_locks+num_flock_locks) *
2488 sizeof(struct ceph_filelock), GFP_NOFS); 2488 sizeof(struct ceph_filelock), GFP_NOFS);
2489 if (!flocks) { 2489 if (!flocks) {
2490 err = -ENOMEM; 2490 err = -ENOMEM;
2491 goto out_free; 2491 goto out_free;
2492 } 2492 }
2493 lock_flocks(); 2493 spin_lock(&inode->i_lock);
2494 err = ceph_encode_locks_to_buffer(inode, flocks, 2494 err = ceph_encode_locks_to_buffer(inode, flocks,
2495 num_fcntl_locks, 2495 num_fcntl_locks,
2496 num_flock_locks); 2496 num_flock_locks);
2497 unlock_flocks(); 2497 spin_unlock(&inode->i_lock);
2498 if (err) { 2498 if (err) {
2499 kfree(flocks); 2499 kfree(flocks);
2500 if (err == -ENOSPC) 2500 if (err == -ENOSPC)