lkml.org 
[lkml]   [2012]   [Sep]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 1/4] fs/inode.c: do not take i_lock on newly allocated inode
Date
Does current thread have the exclusive access to newly allocated inode?
The chanllege comes from individual filesystem's ->alloc_inode method.
It may exposure the inode to private lists, thus give other threads a chance
to access the inode.

That should not happen, however, because the inode is not even gone through a
basic initialization. The locks may not be initialized yet, the inode is not
ready for parallel access.

Thus, from getting an inode from alloc_inode(), till we put it on a list and
that list becomes accessible, we can safely manipulate the inode without
taking i_lock.

This patch fixes three places that take the unnecessary i_lock.

Note in iget5_locked(), I have no strong proof set() should not put the inode
into private lists. Any suggestion?

Signed-off-by: Guo Chao <yan@linux.vnet.ibm.com>
---
fs/inode.c | 6 ------
1 file changed, 6 deletions(-)

diff --git a/fs/inode.c b/fs/inode.c
index ac8d904..d2d15aa 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -895,9 +895,7 @@ struct inode *new_inode_pseudo(struct super_block *sb)
struct inode *inode = alloc_inode(sb);

if (inode) {
- spin_lock(&inode->i_lock);
inode->i_state = 0;
- spin_unlock(&inode->i_lock);
INIT_LIST_HEAD(&inode->i_sb_list);
}
return inode;
@@ -1015,10 +1013,8 @@ struct inode *iget5_locked(struct super_block *sb, unsigned long hashval,
if (set(inode, data))
goto set_failed;

- spin_lock(&inode->i_lock);
inode->i_state = I_NEW;
hlist_add_head(&inode->i_hash, head);
- spin_unlock(&inode->i_lock);
inode_sb_list_add(inode);
spin_unlock(&inode_hash_lock);

@@ -1082,10 +1078,8 @@ struct inode *iget_locked(struct super_block *sb, unsigned long ino)
old = find_inode_fast(sb, head, ino);
if (!old) {
inode->i_ino = ino;
- spin_lock(&inode->i_lock);
inode->i_state = I_NEW;
hlist_add_head(&inode->i_hash, head);
- spin_unlock(&inode->i_lock);
inode_sb_list_add(inode);
spin_unlock(&inode_hash_lock);

--
1.7.9.5


\
 
 \ /
  Last update: 2012-09-21 12:21    [W:0.073 / U:2.468 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site