diff options
author | Jeff Layton <jeff.layton@primarydata.com> | 2015-04-03 09:04:04 -0400 |
---|---|---|
committer | Jeff Layton <jeff.layton@primarydata.com> | 2015-04-03 09:04:04 -0400 |
commit | 0429c2b5c1c4c8ba6cd563c1964baf3ed238df26 (patch) | |
tree | 60bda1e72adfea7a0a4fe3cdceacc78a3f0e8844 /fs | |
parent | 3648888e90bb7fe6d0586ec177511e6678ee22c3 (diff) | |
download | op-kernel-dev-0429c2b5c1c4c8ba6cd563c1964baf3ed238df26.zip op-kernel-dev-0429c2b5c1c4c8ba6cd563c1964baf3ed238df26.tar.gz |
locks: use cmpxchg to assign i_flctx pointer
During the v3.20/v4.0 cycle, I had originally had the code manage the
inode->i_flctx pointer using a compare-and-swap operation instead of the
i_lock.
Sasha Levin though hit a problem while testing with trinity that made me
believe that that wasn't safe. At the time, changing the code to protect
the i_flctx pointer seemed to fix the issue, but I now think that was
just coincidence.
The issue was likely the same race that Kirill Shutemov hit while
testing the pre-rc1 v4.0 kernel and that Linus spotted. Due to the way
that the spinlock was dropped in the middle of flock_lock_file, you
could end up with multiple flock locks for the same struct file on the
inode.
Reinstate the use of a CAS operation to assign this pointer since it's
likely to be more efficient and gets the i_lock completely out of the
file locking business.
Signed-off-by: Jeff Layton <jeff.layton@primarydata.com>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/locks.c | 9 |
1 files changed, 1 insertions, 8 deletions
@@ -223,14 +223,7 @@ locks_get_lock_context(struct inode *inode, int type) * Assign the pointer if it's not already assigned. If it is, then * free the context we just allocated. */ - spin_lock(&inode->i_lock); - if (likely(!inode->i_flctx)) { - inode->i_flctx = new; - new = NULL; - } - spin_unlock(&inode->i_lock); - - if (new) + if (cmpxchg(&inode->i_flctx, NULL, new)) kmem_cache_free(flctx_cache, new); out: return inode->i_flctx; |