diff options
author | Jan Kara <jack@suse.cz> | 2008-04-29 03:59:37 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-04-29 11:06:05 -0400 |
commit | eccb95cee4f0d56faa46ef22fb94dd4a3578d3eb (patch) | |
tree | 45f2586854927cef529730ae0c7196d931de0c94 /fs/drop_caches.c | |
parent | a8522509200b460443a7ca59138dc63bec1b690a (diff) |
vfs: fix lock inversion in drop_pagecache_sb()
Fix longstanding lock inversion in drop_pagecache_sb by dropping inode_lock
before calling __invalidate_mapping_pages(). We just have to make sure inode
won't go away from under us by keeping reference to it and putting the
reference only after we have safely resumed the scan of the inode list. A bit
tricky but not too bad...
Signed-off-by: Jan Kara <jack@suse.cz>
Cc: Fengguang Wu <wfg@mail.ustc.edu.cn>
Cc: David Chinner <dgc@sgi.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/drop_caches.c')
-rw-r--r-- | fs/drop_caches.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/fs/drop_caches.c b/fs/drop_caches.c index e2c6b6500c78..50f9087635d8 100644 --- a/fs/drop_caches.c +++ b/fs/drop_caches.c | |||
@@ -14,15 +14,21 @@ int sysctl_drop_caches; | |||
14 | 14 | ||
15 | static void drop_pagecache_sb(struct super_block *sb) | 15 | static void drop_pagecache_sb(struct super_block *sb) |
16 | { | 16 | { |
17 | struct inode *inode; | 17 | struct inode *inode, *toput_inode = NULL; |
18 | 18 | ||
19 | spin_lock(&inode_lock); | 19 | spin_lock(&inode_lock); |
20 | list_for_each_entry(inode, &sb->s_inodes, i_sb_list) { | 20 | list_for_each_entry(inode, &sb->s_inodes, i_sb_list) { |
21 | if (inode->i_state & (I_FREEING|I_WILL_FREE)) | 21 | if (inode->i_state & (I_FREEING|I_WILL_FREE)) |
22 | continue; | 22 | continue; |
23 | __iget(inode); | ||
24 | spin_unlock(&inode_lock); | ||
23 | __invalidate_mapping_pages(inode->i_mapping, 0, -1, true); | 25 | __invalidate_mapping_pages(inode->i_mapping, 0, -1, true); |
26 | iput(toput_inode); | ||
27 | toput_inode = inode; | ||
28 | spin_lock(&inode_lock); | ||
24 | } | 29 | } |
25 | spin_unlock(&inode_lock); | 30 | spin_unlock(&inode_lock); |
31 | iput(toput_inode); | ||
26 | } | 32 | } |
27 | 33 | ||
28 | static void drop_pagecache(void) | 34 | static void drop_pagecache(void) |