aboutsummaryrefslogtreecommitdiffstats
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
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>
-rw-r--r--fs/ext3/file.c4
-rw-r--r--fs/ext3/inode.c18
-rw-r--r--fs/ext3/xattr.c14
-rw-r--r--include/linux/ext3_fs.h33
-rw-r--r--include/linux/ext3_fs_i.h2
5 files changed, 44 insertions, 27 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);
diff --git a/include/linux/ext3_fs.h b/include/linux/ext3_fs.h
index 6b049030fbe6..e6590f8f0b3c 100644
--- a/include/linux/ext3_fs.h
+++ b/include/linux/ext3_fs.h
@@ -202,14 +202,6 @@ static inline __u32 ext3_mask_flags(umode_t mode, __u32 flags)
202 return flags & EXT3_OTHER_FLMASK; 202 return flags & EXT3_OTHER_FLMASK;
203} 203}
204 204
205/*
206 * Inode dynamic state flags
207 */
208#define EXT3_STATE_JDATA 0x00000001 /* journaled data exists */
209#define EXT3_STATE_NEW 0x00000002 /* inode is newly created */
210#define EXT3_STATE_XATTR 0x00000004 /* has in-inode xattrs */
211#define EXT3_STATE_FLUSH_ON_CLOSE 0x00000008
212
213/* Used to pass group descriptor data when online resize is done */ 205/* Used to pass group descriptor data when online resize is done */
214struct ext3_new_group_input { 206struct ext3_new_group_input {
215 __u32 group; /* Group number for this data */ 207 __u32 group; /* Group number for this data */
@@ -560,6 +552,31 @@ static inline int ext3_valid_inum(struct super_block *sb, unsigned long ino)
560 (ino >= EXT3_FIRST_INO(sb) && 552 (ino >= EXT3_FIRST_INO(sb) &&
561 ino <= le32_to_cpu(EXT3_SB(sb)->s_es->s_inodes_count)); 553 ino <= le32_to_cpu(EXT3_SB(sb)->s_es->s_inodes_count));
562} 554}
555
556/*
557 * Inode dynamic state flags
558 */
559enum {
560 EXT3_STATE_JDATA, /* journaled data exists */
561 EXT3_STATE_NEW, /* inode is newly created */
562 EXT3_STATE_XATTR, /* has in-inode xattrs */
563 EXT3_STATE_FLUSH_ON_CLOSE, /* flush dirty pages on close */
564};
565
566static inline int ext3_test_inode_state(struct inode *inode, int bit)
567{
568 return test_bit(bit, &EXT3_I(inode)->i_state);
569}
570
571static inline void ext3_set_inode_state(struct inode *inode, int bit)
572{
573 set_bit(bit, &EXT3_I(inode)->i_state);
574}
575
576static inline void ext3_clear_inode_state(struct inode *inode, int bit)
577{
578 clear_bit(bit, &EXT3_I(inode)->i_state);
579}
563#else 580#else
564/* Assume that user mode programs are passing in an ext3fs superblock, not 581/* Assume that user mode programs are passing in an ext3fs superblock, not
565 * a kernel struct super_block. This will allow us to call the feature-test 582 * a kernel struct super_block. This will allow us to call the feature-test
diff --git a/include/linux/ext3_fs_i.h b/include/linux/ext3_fs_i.h
index 93e7428156ba..7679acdb519a 100644
--- a/include/linux/ext3_fs_i.h
+++ b/include/linux/ext3_fs_i.h
@@ -87,7 +87,7 @@ struct ext3_inode_info {
87 * near to their parent directory's inode. 87 * near to their parent directory's inode.
88 */ 88 */
89 __u32 i_block_group; 89 __u32 i_block_group;
90 __u32 i_state; /* Dynamic state flags for ext3 */ 90 unsigned long i_state; /* Dynamic state flags for ext3 */
91 91
92 /* block reservation info */ 92 /* block reservation info */
93 struct ext3_block_alloc_info *i_block_alloc_info; 93 struct ext3_block_alloc_info *i_block_alloc_info;