aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ext3
diff options
context:
space:
mode:
authorJan Kara <jack@suse.cz>2010-01-06 15:58:48 -0500
committerJan Kara <jack@suse.cz>2010-03-04 18:20:20 -0500
commit9df93939b735dd273e49cbee290b9f4738500ef4 (patch)
tree2840172239e13d1c0fea496755b8346a9b394336 /fs/ext3
parent26245c949c8473ea7352907b5a54bc34487eb87f (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')
-rw-r--r--fs/ext3/file.c4
-rw-r--r--fs/ext3/inode.c18
-rw-r--r--fs/ext3/xattr.c14
3 files changed, 18 insertions, 18 deletions
diff --git a/fs/ext3/file.c b/fs/ext3/file.c
index 388bbdfa0b4e..a86d3302cdc2 100644
--- a/fs/ext3/file.c
+++ b/fs/ext3/file.c
@@ -33,9 +33,9 @@
33 */ 33 */
34static int ext3_release_file (struct inode * inode, struct file * filp) 34static int ext3_release_file (struct inode * inode, struct file * filp)
35{ 35{
36 if (EXT3_I(inode)->i_state & EXT3_STATE_FLUSH_ON_CLOSE) { 36 if (ext3_test_inode_state(inode, EXT3_STATE_FLUSH_ON_CLOSE)) {
37 filemap_flush(inode->i_mapping); 37 filemap_flush(inode->i_mapping);
38 EXT3_I(inode)->i_state &= ~EXT3_STATE_FLUSH_ON_CLOSE; 38 ext3_clear_inode_state(inode, EXT3_STATE_FLUSH_ON_CLOSE);
39 } 39 }
40 /* if we are the last writer on the inode, drop the block reservation */ 40 /* if we are the last writer on the inode, drop the block reservation */
41 if ((filp->f_mode & FMODE_WRITE) && 41 if ((filp->f_mode & FMODE_WRITE) &&
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
2727void ext3_set_inode_flags(struct inode *inode) 2727void 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);
3058out_brelse: 3058out_brelse:
diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
index 66895ccf76c7..2d2fb2a85961 100644
--- a/fs/ext3/xattr.c
+++ b/fs/ext3/xattr.c
@@ -274,7 +274,7 @@ ext3_xattr_ibody_get(struct inode *inode, int name_index, const char *name,
274 void *end; 274 void *end;
275 int error; 275 int error;
276 276
277 if (!(EXT3_I(inode)->i_state & EXT3_STATE_XATTR)) 277 if (!ext3_test_inode_state(inode, EXT3_STATE_XATTR))
278 return -ENODATA; 278 return -ENODATA;
279 error = ext3_get_inode_loc(inode, &iloc); 279 error = ext3_get_inode_loc(inode, &iloc);
280 if (error) 280 if (error)
@@ -403,7 +403,7 @@ ext3_xattr_ibody_list(struct dentry *dentry, char *buffer, size_t buffer_size)
403 void *end; 403 void *end;
404 int error; 404 int error;
405 405
406 if (!(EXT3_I(inode)->i_state & EXT3_STATE_XATTR)) 406 if (!ext3_test_inode_state(inode, EXT3_STATE_XATTR))
407 return 0; 407 return 0;
408 error = ext3_get_inode_loc(inode, &iloc); 408 error = ext3_get_inode_loc(inode, &iloc);
409 if (error) 409 if (error)
@@ -882,7 +882,7 @@ ext3_xattr_ibody_find(struct inode *inode, struct ext3_xattr_info *i,
882 is->s.base = is->s.first = IFIRST(header); 882 is->s.base = is->s.first = IFIRST(header);
883 is->s.here = is->s.first; 883 is->s.here = is->s.first;
884 is->s.end = (void *)raw_inode + EXT3_SB(inode->i_sb)->s_inode_size; 884 is->s.end = (void *)raw_inode + EXT3_SB(inode->i_sb)->s_inode_size;
885 if (EXT3_I(inode)->i_state & EXT3_STATE_XATTR) { 885 if (ext3_test_inode_state(inode, EXT3_STATE_XATTR)) {
886 error = ext3_xattr_check_names(IFIRST(header), is->s.end); 886 error = ext3_xattr_check_names(IFIRST(header), is->s.end);
887 if (error) 887 if (error)
888 return error; 888 return error;
@@ -914,10 +914,10 @@ ext3_xattr_ibody_set(handle_t *handle, struct inode *inode,
914 header = IHDR(inode, ext3_raw_inode(&is->iloc)); 914 header = IHDR(inode, ext3_raw_inode(&is->iloc));
915 if (!IS_LAST_ENTRY(s->first)) { 915 if (!IS_LAST_ENTRY(s->first)) {
916 header->h_magic = cpu_to_le32(EXT3_XATTR_MAGIC); 916 header->h_magic = cpu_to_le32(EXT3_XATTR_MAGIC);
917 EXT3_I(inode)->i_state |= EXT3_STATE_XATTR; 917 ext3_set_inode_state(inode, EXT3_STATE_XATTR);
918 } else { 918 } else {
919 header->h_magic = cpu_to_le32(0); 919 header->h_magic = cpu_to_le32(0);
920 EXT3_I(inode)->i_state &= ~EXT3_STATE_XATTR; 920 ext3_clear_inode_state(inode, EXT3_STATE_XATTR);
921 } 921 }
922 return 0; 922 return 0;
923} 923}
@@ -967,10 +967,10 @@ ext3_xattr_set_handle(handle_t *handle, struct inode *inode, int name_index,
967 if (error) 967 if (error)
968 goto cleanup; 968 goto cleanup;
969 969
970 if (EXT3_I(inode)->i_state & EXT3_STATE_NEW) { 970 if (ext3_test_inode_state(inode, EXT3_STATE_NEW)) {
971 struct ext3_inode *raw_inode = ext3_raw_inode(&is.iloc); 971 struct ext3_inode *raw_inode = ext3_raw_inode(&is.iloc);
972 memset(raw_inode, 0, EXT3_SB(inode->i_sb)->s_inode_size); 972 memset(raw_inode, 0, EXT3_SB(inode->i_sb)->s_inode_size);
973 EXT3_I(inode)->i_state &= ~EXT3_STATE_NEW; 973 ext3_clear_inode_state(inode, EXT3_STATE_NEW);
974 } 974 }
975 975
976 error = ext3_xattr_ibody_find(inode, &i, &is); 976 error = ext3_xattr_ibody_find(inode, &i, &is);