diff options
author | Jan Kara <jack@suse.cz> | 2010-01-06 15:58:48 -0500 |
---|---|---|
committer | Jan Kara <jack@suse.cz> | 2010-03-04 18:20:20 -0500 |
commit | 9df93939b735dd273e49cbee290b9f4738500ef4 (patch) | |
tree | 2840172239e13d1c0fea496755b8346a9b394336 /fs/ext3/inode.c | |
parent | 26245c949c8473ea7352907b5a54bc34487eb87f (diff) |
ext3: Use bitops to read/modify EXT3_I(inode)->i_state
At several places we modify EXT3_I(inode)->i_state without holding i_mutex
(ext3_release_file, ext3_bmap, ext3_journalled_writepage, ext3_do_update_inode,
...). These modifications are racy and we can lose updates to i_state. So
convert handling of i_state to use bitops which are atomic.
Signed-off-by: Jan Kara <jack@suse.cz>
Diffstat (limited to 'fs/ext3/inode.c')
-rw-r--r-- | fs/ext3/inode.c | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/fs/ext3/inode.c b/fs/ext3/inode.c index 455e6e6e5cb9..44b53386ab8b 100644 --- a/fs/ext3/inode.c +++ b/fs/ext3/inode.c | |||
@@ -1378,7 +1378,7 @@ static int ext3_journalled_write_end(struct file *file, | |||
1378 | */ | 1378 | */ |
1379 | if (pos + len > inode->i_size && ext3_can_truncate(inode)) | 1379 | if (pos + len > inode->i_size && ext3_can_truncate(inode)) |
1380 | ext3_orphan_add(handle, inode); | 1380 | ext3_orphan_add(handle, inode); |
1381 | EXT3_I(inode)->i_state |= EXT3_STATE_JDATA; | 1381 | ext3_set_inode_state(inode, EXT3_STATE_JDATA); |
1382 | if (inode->i_size > EXT3_I(inode)->i_disksize) { | 1382 | if (inode->i_size > EXT3_I(inode)->i_disksize) { |
1383 | EXT3_I(inode)->i_disksize = inode->i_size; | 1383 | EXT3_I(inode)->i_disksize = inode->i_size; |
1384 | ret2 = ext3_mark_inode_dirty(handle, inode); | 1384 | ret2 = ext3_mark_inode_dirty(handle, inode); |
@@ -1417,7 +1417,7 @@ static sector_t ext3_bmap(struct address_space *mapping, sector_t block) | |||
1417 | journal_t *journal; | 1417 | journal_t *journal; |
1418 | int err; | 1418 | int err; |
1419 | 1419 | ||
1420 | if (EXT3_I(inode)->i_state & EXT3_STATE_JDATA) { | 1420 | if (ext3_test_inode_state(inode, EXT3_STATE_JDATA)) { |
1421 | /* | 1421 | /* |
1422 | * This is a REALLY heavyweight approach, but the use of | 1422 | * This is a REALLY heavyweight approach, but the use of |
1423 | * bmap on dirty files is expected to be extremely rare: | 1423 | * bmap on dirty files is expected to be extremely rare: |
@@ -1436,7 +1436,7 @@ static sector_t ext3_bmap(struct address_space *mapping, sector_t block) | |||
1436 | * everything they get. | 1436 | * everything they get. |
1437 | */ | 1437 | */ |
1438 | 1438 | ||
1439 | EXT3_I(inode)->i_state &= ~EXT3_STATE_JDATA; | 1439 | ext3_clear_inode_state(inode, EXT3_STATE_JDATA); |
1440 | journal = EXT3_JOURNAL(inode); | 1440 | journal = EXT3_JOURNAL(inode); |
1441 | journal_lock_updates(journal); | 1441 | journal_lock_updates(journal); |
1442 | err = journal_flush(journal); | 1442 | err = journal_flush(journal); |
@@ -1670,7 +1670,7 @@ static int ext3_journalled_writepage(struct page *page, | |||
1670 | PAGE_CACHE_SIZE, NULL, write_end_fn); | 1670 | PAGE_CACHE_SIZE, NULL, write_end_fn); |
1671 | if (ret == 0) | 1671 | if (ret == 0) |
1672 | ret = err; | 1672 | ret = err; |
1673 | EXT3_I(inode)->i_state |= EXT3_STATE_JDATA; | 1673 | ext3_set_inode_state(inode, EXT3_STATE_JDATA); |
1674 | unlock_page(page); | 1674 | unlock_page(page); |
1675 | } else { | 1675 | } else { |
1676 | /* | 1676 | /* |
@@ -2402,7 +2402,7 @@ void ext3_truncate(struct inode *inode) | |||
2402 | goto out_notrans; | 2402 | goto out_notrans; |
2403 | 2403 | ||
2404 | if (inode->i_size == 0 && ext3_should_writeback_data(inode)) | 2404 | if (inode->i_size == 0 && ext3_should_writeback_data(inode)) |
2405 | ei->i_state |= EXT3_STATE_FLUSH_ON_CLOSE; | 2405 | ext3_set_inode_state(inode, EXT3_STATE_FLUSH_ON_CLOSE); |
2406 | 2406 | ||
2407 | /* | 2407 | /* |
2408 | * We have to lock the EOF page here, because lock_page() nests | 2408 | * We have to lock the EOF page here, because lock_page() nests |
@@ -2721,7 +2721,7 @@ int ext3_get_inode_loc(struct inode *inode, struct ext3_iloc *iloc) | |||
2721 | { | 2721 | { |
2722 | /* We have all inode data except xattrs in memory here. */ | 2722 | /* We have all inode data except xattrs in memory here. */ |
2723 | return __ext3_get_inode_loc(inode, iloc, | 2723 | return __ext3_get_inode_loc(inode, iloc, |
2724 | !(EXT3_I(inode)->i_state & EXT3_STATE_XATTR)); | 2724 | !ext3_test_inode_state(inode, EXT3_STATE_XATTR)); |
2725 | } | 2725 | } |
2726 | 2726 | ||
2727 | void ext3_set_inode_flags(struct inode *inode) | 2727 | void ext3_set_inode_flags(struct inode *inode) |
@@ -2893,7 +2893,7 @@ struct inode *ext3_iget(struct super_block *sb, unsigned long ino) | |||
2893 | EXT3_GOOD_OLD_INODE_SIZE + | 2893 | EXT3_GOOD_OLD_INODE_SIZE + |
2894 | ei->i_extra_isize; | 2894 | ei->i_extra_isize; |
2895 | if (*magic == cpu_to_le32(EXT3_XATTR_MAGIC)) | 2895 | if (*magic == cpu_to_le32(EXT3_XATTR_MAGIC)) |
2896 | ei->i_state |= EXT3_STATE_XATTR; | 2896 | ext3_set_inode_state(inode, EXT3_STATE_XATTR); |
2897 | } | 2897 | } |
2898 | } else | 2898 | } else |
2899 | ei->i_extra_isize = 0; | 2899 | ei->i_extra_isize = 0; |
@@ -2955,7 +2955,7 @@ again: | |||
2955 | 2955 | ||
2956 | /* For fields not not tracking in the in-memory inode, | 2956 | /* For fields not not tracking in the in-memory inode, |
2957 | * initialise them to zero for new inodes. */ | 2957 | * initialise them to zero for new inodes. */ |
2958 | if (ei->i_state & EXT3_STATE_NEW) | 2958 | if (ext3_test_inode_state(inode, EXT3_STATE_NEW)) |
2959 | memset(raw_inode, 0, EXT3_SB(inode->i_sb)->s_inode_size); | 2959 | memset(raw_inode, 0, EXT3_SB(inode->i_sb)->s_inode_size); |
2960 | 2960 | ||
2961 | ext3_get_inode_flags(ei); | 2961 | ext3_get_inode_flags(ei); |
@@ -3052,7 +3052,7 @@ again: | |||
3052 | rc = ext3_journal_dirty_metadata(handle, bh); | 3052 | rc = ext3_journal_dirty_metadata(handle, bh); |
3053 | if (!err) | 3053 | if (!err) |
3054 | err = rc; | 3054 | err = rc; |
3055 | ei->i_state &= ~EXT3_STATE_NEW; | 3055 | ext3_clear_inode_state(inode, EXT3_STATE_NEW); |
3056 | 3056 | ||
3057 | atomic_set(&ei->i_sync_tid, handle->h_transaction->t_tid); | 3057 | atomic_set(&ei->i_sync_tid, handle->h_transaction->t_tid); |
3058 | out_brelse: | 3058 | out_brelse: |