]>
Commit | Line | Data |
---|---|---|
31953fc7 GKH |
1 | From 580be0837a7a59b207c3d5c661d044d8dd0a6a30 Mon Sep 17 00:00:00 2001 |
2 | From: Jan Kara <jack@suse.cz> | |
3 | Date: Mon, 21 Sep 2009 17:01:06 -0700 | |
4 | Subject: fs: make sure data stored into inode is properly seen before unlocking new inode | |
5 | ||
6 | From: Jan Kara <jack@suse.cz> | |
7 | ||
8 | commit 580be0837a7a59b207c3d5c661d044d8dd0a6a30 upstream. | |
9 | ||
10 | In theory it could happen that on one CPU we initialize a new inode but | |
11 | clearing of I_NEW | I_LOCK gets reordered before some of the | |
12 | initialization. Thus on another CPU we return not fully uptodate inode | |
13 | from iget_locked(). | |
14 | ||
15 | This seems to fix a corruption issue on ext3 mounted over NFS. | |
16 | ||
17 | [akpm@linux-foundation.org: add some commentary] | |
18 | Signed-off-by: Jan Kara <jack@suse.cz> | |
19 | Cc: Christoph Hellwig <hch@infradead.org> | |
20 | Signed-off-by: Andrew Morton <akpm@linux-foundation.org> | |
21 | Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> | |
22 | Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de> | |
23 | ||
24 | --- | |
25 | fs/inode.c | 14 ++++++++------ | |
26 | 1 file changed, 8 insertions(+), 6 deletions(-) | |
27 | ||
28 | --- a/fs/inode.c | |
29 | +++ b/fs/inode.c | |
30 | @@ -590,13 +590,15 @@ void unlock_new_inode(struct inode *inod | |
31 | } | |
32 | #endif | |
33 | /* | |
34 | - * This is special! We do not need the spinlock | |
35 | - * when clearing I_LOCK, because we're guaranteed | |
36 | - * that nobody else tries to do anything about the | |
37 | - * state of the inode when it is locked, as we | |
38 | - * just created it (so there can be no old holders | |
39 | - * that haven't tested I_LOCK). | |
40 | + * This is special! We do not need the spinlock when clearing I_LOCK, | |
41 | + * because we're guaranteed that nobody else tries to do anything about | |
42 | + * the state of the inode when it is locked, as we just created it (so | |
43 | + * there can be no old holders that haven't tested I_LOCK). | |
44 | + * However we must emit the memory barrier so that other CPUs reliably | |
45 | + * see the clearing of I_LOCK after the other inode initialisation has | |
46 | + * completed. | |
47 | */ | |
48 | + smp_mb(); | |
49 | WARN_ON((inode->i_state & (I_LOCK|I_NEW)) != (I_LOCK|I_NEW)); | |
50 | inode->i_state &= ~(I_LOCK|I_NEW); | |
51 | wake_up_inode(inode); |