aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Monakhov <dmonakhov@openvz.org>2010-05-16 22:00:00 -0400
committerTheodore Ts'o <tytso@mit.edu>2010-05-16 22:00:00 -0400
commit12e9b892002d9af057655d35b44db8ee9243b0dc (patch)
treec5831b4bcf98eebdd39158d08dab97c198f5c683
parent24676da469f50f433baa347845639662c561d1f6 (diff)
ext4: Use bitops to read/modify i_flags in struct ext4_inode_info
At several places we modify EXT4_I(inode)->i_flags without holding i_mutex (ext4_do_update_inode, ...). These modifications are racy and we can lose updates to i_flags. So convert handling of i_flags to use bitops which are atomic. https://bugzilla.kernel.org/show_bug.cgi?id=15792 Signed-off-by: Dmitry Monakhov <dmonakhov@openvz.org> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
-rw-r--r--fs/ext4/dir.c4
-rw-r--r--fs/ext4/ext4.h109
-rw-r--r--fs/ext4/ext4_jbd2.h8
-rw-r--r--fs/ext4/extents.c10
-rw-r--r--fs/ext4/file.c2
-rw-r--r--fs/ext4/ialloc.c4
-rw-r--r--fs/ext4/inode.c30
-rw-r--r--fs/ext4/mballoc.c4
-rw-r--r--fs/ext4/migrate.c2
-rw-r--r--fs/ext4/move_extent.c4
-rw-r--r--fs/ext4/namei.c10
-rw-r--r--fs/ext4/super.c1
-rw-r--r--fs/ext4/xattr.c4
13 files changed, 136 insertions, 56 deletions
diff --git a/fs/ext4/dir.c b/fs/ext4/dir.c
index 6a2b8bcff641..ea5e6cb7e2a5 100644
--- a/fs/ext4/dir.c
+++ b/fs/ext4/dir.c
@@ -110,7 +110,7 @@ static int ext4_readdir(struct file *filp,
110 110
111 if (EXT4_HAS_COMPAT_FEATURE(inode->i_sb, 111 if (EXT4_HAS_COMPAT_FEATURE(inode->i_sb,
112 EXT4_FEATURE_COMPAT_DIR_INDEX) && 112 EXT4_FEATURE_COMPAT_DIR_INDEX) &&
113 ((EXT4_I(inode)->i_flags & EXT4_INDEX_FL) || 113 ((ext4_test_inode_flag(inode, EXT4_INODE_INDEX)) ||
114 ((inode->i_size >> sb->s_blocksize_bits) == 1))) { 114 ((inode->i_size >> sb->s_blocksize_bits) == 1))) {
115 err = ext4_dx_readdir(filp, dirent, filldir); 115 err = ext4_dx_readdir(filp, dirent, filldir);
116 if (err != ERR_BAD_DX_DIR) { 116 if (err != ERR_BAD_DX_DIR) {
@@ -121,7 +121,7 @@ static int ext4_readdir(struct file *filp,
121 * We don't set the inode dirty flag since it's not 121 * We don't set the inode dirty flag since it's not
122 * critical that it get flushed back to the disk. 122 * critical that it get flushed back to the disk.
123 */ 123 */
124 EXT4_I(filp->f_path.dentry->d_inode)->i_flags &= ~EXT4_INDEX_FL; 124 ext4_clear_inode_flag(filp->f_path.dentry->d_inode, EXT4_INODE_INDEX);
125 } 125 }
126 stored = 0; 126 stored = 0;
127 offset = filp->f_pos & (sb->s_blocksize - 1); 127 offset = filp->f_pos & (sb->s_blocksize - 1);
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index 413321ff1e20..74414884580c 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -344,6 +344,83 @@ static inline __u32 ext4_mask_flags(umode_t mode, __u32 flags)
344 return flags & EXT4_OTHER_FLMASK; 344 return flags & EXT4_OTHER_FLMASK;
345} 345}
346 346
347/*
348 * Inode flags used for atomic set/get
349 */
350enum {
351 EXT4_INODE_SECRM = 0, /* Secure deletion */
352 EXT4_INODE_UNRM = 1, /* Undelete */
353 EXT4_INODE_COMPR = 2, /* Compress file */
354 EXT4_INODE_SYNC = 3, /* Synchronous updates */
355 EXT4_INODE_IMMUTABLE = 4, /* Immutable file */
356 EXT4_INODE_APPEND = 5, /* writes to file may only append */
357 EXT4_INODE_NODUMP = 6, /* do not dump file */
358 EXT4_INODE_NOATIME = 7, /* do not update atime */
359/* Reserved for compression usage... */
360 EXT4_INODE_DIRTY = 8,
361 EXT4_INODE_COMPRBLK = 9, /* One or more compressed clusters */
362 EXT4_INODE_NOCOMPR = 10, /* Don't compress */
363 EXT4_INODE_ECOMPR = 11, /* Compression error */
364/* End compression flags --- maybe not all used */
365 EXT4_INODE_INDEX = 12, /* hash-indexed directory */
366 EXT4_INODE_IMAGIC = 13, /* AFS directory */
367 EXT4_INODE_JOURNAL_DATA = 14, /* file data should be journaled */
368 EXT4_INODE_NOTAIL = 15, /* file tail should not be merged */
369 EXT4_INODE_DIRSYNC = 16, /* dirsync behaviour (directories only) */
370 EXT4_INODE_TOPDIR = 17, /* Top of directory hierarchies*/
371 EXT4_INODE_HUGE_FILE = 18, /* Set to each huge file */
372 EXT4_INODE_EXTENTS = 19, /* Inode uses extents */
373 EXT4_INODE_EA_INODE = 21, /* Inode used for large EA */
374 EXT4_INODE_EOFBLOCKS = 22, /* Blocks allocated beyond EOF */
375 EXT4_INODE_RESERVED = 31, /* reserved for ext4 lib */
376};
377
378#define TEST_FLAG_VALUE(FLAG) (EXT4_##FLAG##_FL == (1 << EXT4_INODE_##FLAG))
379#define CHECK_FLAG_VALUE(FLAG) if (!TEST_FLAG_VALUE(FLAG)) { \
380 printk(KERN_EMERG "EXT4 flag fail: " #FLAG ": %d %d\n", \
381 EXT4_##FLAG##_FL, EXT4_INODE_##FLAG); BUG_ON(1); }
382
383/*
384 * Since it's pretty easy to mix up bit numbers and hex values, and we
385 * can't do a compile-time test for ENUM values, we use a run-time
386 * test to make sure that EXT4_XXX_FL is consistent with respect to
387 * EXT4_INODE_XXX. If all is well the printk and BUG_ON will all drop
388 * out so it won't cost any extra space in the compiled kernel image.
389 * But it's important that these values are the same, since we are
390 * using EXT4_INODE_XXX to test for the flag values, but EXT4_XX_FL
391 * must be consistent with the values of FS_XXX_FL defined in
392 * include/linux/fs.h and the on-disk values found in ext2, ext3, and
393 * ext4 filesystems, and of course the values defined in e2fsprogs.
394 *
395 * It's not paranoia if the Murphy's Law really *is* out to get you. :-)
396 */
397static inline void ext4_check_flag_values(void)
398{
399 CHECK_FLAG_VALUE(SECRM);
400 CHECK_FLAG_VALUE(UNRM);
401 CHECK_FLAG_VALUE(COMPR);
402 CHECK_FLAG_VALUE(SYNC);
403 CHECK_FLAG_VALUE(IMMUTABLE);
404 CHECK_FLAG_VALUE(APPEND);
405 CHECK_FLAG_VALUE(NODUMP);
406 CHECK_FLAG_VALUE(NOATIME);
407 CHECK_FLAG_VALUE(DIRTY);
408 CHECK_FLAG_VALUE(COMPRBLK);
409 CHECK_FLAG_VALUE(NOCOMPR);
410 CHECK_FLAG_VALUE(ECOMPR);
411 CHECK_FLAG_VALUE(INDEX);
412 CHECK_FLAG_VALUE(IMAGIC);
413 CHECK_FLAG_VALUE(JOURNAL_DATA);
414 CHECK_FLAG_VALUE(NOTAIL);
415 CHECK_FLAG_VALUE(DIRSYNC);
416 CHECK_FLAG_VALUE(TOPDIR);
417 CHECK_FLAG_VALUE(HUGE_FILE);
418 CHECK_FLAG_VALUE(EXTENTS);
419 CHECK_FLAG_VALUE(EA_INODE);
420 CHECK_FLAG_VALUE(EOFBLOCKS);
421 CHECK_FLAG_VALUE(RESERVED);
422}
423
347/* Used to pass group descriptor data when online resize is done */ 424/* Used to pass group descriptor data when online resize is done */
348struct ext4_new_group_input { 425struct ext4_new_group_input {
349 __u32 group; /* Group number for this data */ 426 __u32 group; /* Group number for this data */
@@ -639,9 +716,8 @@ struct ext4_ext_cache {
639 */ 716 */
640struct ext4_inode_info { 717struct ext4_inode_info {
641 __le32 i_data[15]; /* unconverted */ 718 __le32 i_data[15]; /* unconverted */
642 __u32 i_flags;
643 ext4_fsblk_t i_file_acl;
644 __u32 i_dtime; 719 __u32 i_dtime;
720 ext4_fsblk_t i_file_acl;
645 721
646 /* 722 /*
647 * i_block_group is the number of the block group which contains 723 * i_block_group is the number of the block group which contains
@@ -652,6 +728,7 @@ struct ext4_inode_info {
652 */ 728 */
653 ext4_group_t i_block_group; 729 ext4_group_t i_block_group;
654 unsigned long i_state_flags; /* Dynamic state flags */ 730 unsigned long i_state_flags; /* Dynamic state flags */
731 unsigned long i_flags;
655 732
656 ext4_lblk_t i_dir_start_lookup; 733 ext4_lblk_t i_dir_start_lookup;
657#ifdef CONFIG_EXT4_FS_XATTR 734#ifdef CONFIG_EXT4_FS_XATTR
@@ -1087,20 +1164,22 @@ enum {
1087 EXT4_STATE_DIO_UNWRITTEN, /* need convert on dio done*/ 1164 EXT4_STATE_DIO_UNWRITTEN, /* need convert on dio done*/
1088}; 1165};
1089 1166
1090static inline int ext4_test_inode_state(struct inode *inode, int bit) 1167#define EXT4_INODE_BIT_FNS(name, field) \
1091{ 1168static inline int ext4_test_inode_##name(struct inode *inode, int bit) \
1092 return test_bit(bit, &EXT4_I(inode)->i_state_flags); 1169{ \
1170 return test_bit(bit, &EXT4_I(inode)->i_##field); \
1171} \
1172static inline void ext4_set_inode_##name(struct inode *inode, int bit) \
1173{ \
1174 set_bit(bit, &EXT4_I(inode)->i_##field); \
1175} \
1176static inline void ext4_clear_inode_##name(struct inode *inode, int bit) \
1177{ \
1178 clear_bit(bit, &EXT4_I(inode)->i_##field); \
1093} 1179}
1094 1180
1095static inline void ext4_set_inode_state(struct inode *inode, int bit) 1181EXT4_INODE_BIT_FNS(flag, flags)
1096{ 1182EXT4_INODE_BIT_FNS(state, state_flags)
1097 set_bit(bit, &EXT4_I(inode)->i_state_flags);
1098}
1099
1100static inline void ext4_clear_inode_state(struct inode *inode, int bit)
1101{
1102 clear_bit(bit, &EXT4_I(inode)->i_state_flags);
1103}
1104#else 1183#else
1105/* Assume that user mode programs are passing in an ext4fs superblock, not 1184/* Assume that user mode programs are passing in an ext4fs superblock, not
1106 * a kernel struct super_block. This will allow us to call the feature-test 1185 * a kernel struct super_block. This will allow us to call the feature-test
@@ -1287,7 +1366,7 @@ struct ext4_dir_entry_2 {
1287 1366
1288#define is_dx(dir) (EXT4_HAS_COMPAT_FEATURE(dir->i_sb, \ 1367#define is_dx(dir) (EXT4_HAS_COMPAT_FEATURE(dir->i_sb, \
1289 EXT4_FEATURE_COMPAT_DIR_INDEX) && \ 1368 EXT4_FEATURE_COMPAT_DIR_INDEX) && \
1290 (EXT4_I(dir)->i_flags & EXT4_INDEX_FL)) 1369 ext4_test_inode_flag((dir), EXT4_INODE_INDEX))
1291#define EXT4_DIR_LINK_MAX(dir) (!is_dx(dir) && (dir)->i_nlink >= EXT4_LINK_MAX) 1370#define EXT4_DIR_LINK_MAX(dir) (!is_dx(dir) && (dir)->i_nlink >= EXT4_LINK_MAX)
1292#define EXT4_DIR_LINK_EMPTY(dir) ((dir)->i_nlink == 2 || (dir)->i_nlink == 1) 1371#define EXT4_DIR_LINK_EMPTY(dir) ((dir)->i_nlink == 2 || (dir)->i_nlink == 1)
1293 1372
diff --git a/fs/ext4/ext4_jbd2.h b/fs/ext4/ext4_jbd2.h
index b79ad5126468..dade0c024797 100644
--- a/fs/ext4/ext4_jbd2.h
+++ b/fs/ext4/ext4_jbd2.h
@@ -273,7 +273,7 @@ static inline int ext4_should_journal_data(struct inode *inode)
273 return 1; 273 return 1;
274 if (test_opt(inode->i_sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA) 274 if (test_opt(inode->i_sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA)
275 return 1; 275 return 1;
276 if (EXT4_I(inode)->i_flags & EXT4_JOURNAL_DATA_FL) 276 if (ext4_test_inode_flag(inode, EXT4_INODE_JOURNAL_DATA))
277 return 1; 277 return 1;
278 return 0; 278 return 0;
279} 279}
@@ -284,7 +284,7 @@ static inline int ext4_should_order_data(struct inode *inode)
284 return 0; 284 return 0;
285 if (!S_ISREG(inode->i_mode)) 285 if (!S_ISREG(inode->i_mode))
286 return 0; 286 return 0;
287 if (EXT4_I(inode)->i_flags & EXT4_JOURNAL_DATA_FL) 287 if (ext4_test_inode_flag(inode, EXT4_INODE_JOURNAL_DATA))
288 return 0; 288 return 0;
289 if (test_opt(inode->i_sb, DATA_FLAGS) == EXT4_MOUNT_ORDERED_DATA) 289 if (test_opt(inode->i_sb, DATA_FLAGS) == EXT4_MOUNT_ORDERED_DATA)
290 return 1; 290 return 1;
@@ -297,7 +297,7 @@ static inline int ext4_should_writeback_data(struct inode *inode)
297 return 0; 297 return 0;
298 if (EXT4_JOURNAL(inode) == NULL) 298 if (EXT4_JOURNAL(inode) == NULL)
299 return 1; 299 return 1;
300 if (EXT4_I(inode)->i_flags & EXT4_JOURNAL_DATA_FL) 300 if (ext4_test_inode_flag(inode, EXT4_INODE_JOURNAL_DATA))
301 return 0; 301 return 0;
302 if (test_opt(inode->i_sb, DATA_FLAGS) == EXT4_MOUNT_WRITEBACK_DATA) 302 if (test_opt(inode->i_sb, DATA_FLAGS) == EXT4_MOUNT_WRITEBACK_DATA)
303 return 1; 303 return 1;
@@ -321,7 +321,7 @@ static inline int ext4_should_dioread_nolock(struct inode *inode)
321 return 0; 321 return 0;
322 if (!S_ISREG(inode->i_mode)) 322 if (!S_ISREG(inode->i_mode))
323 return 0; 323 return 0;
324 if (!(EXT4_I(inode)->i_flags & EXT4_EXTENTS_FL)) 324 if (!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)))
325 return 0; 325 return 0;
326 if (ext4_should_journal_data(inode)) 326 if (ext4_should_journal_data(inode))
327 return 0; 327 return 0;
diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index 91c3873970e4..42d8ce91adbd 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -3498,7 +3498,7 @@ int ext4_ext_map_blocks(handle_t *handle, struct inode *inode,
3498 map->m_flags |= EXT4_MAP_UNINIT; 3498 map->m_flags |= EXT4_MAP_UNINIT;
3499 } 3499 }
3500 3500
3501 if (unlikely(EXT4_I(inode)->i_flags & EXT4_EOFBLOCKS_FL)) { 3501 if (unlikely(ext4_test_inode_flag(inode, EXT4_INODE_EOFBLOCKS))) {
3502 if (unlikely(!eh->eh_entries)) { 3502 if (unlikely(!eh->eh_entries)) {
3503 EXT4_ERROR_INODE(inode, 3503 EXT4_ERROR_INODE(inode,
3504 "eh->eh_entries == 0 ee_block %d", 3504 "eh->eh_entries == 0 ee_block %d",
@@ -3509,7 +3509,7 @@ int ext4_ext_map_blocks(handle_t *handle, struct inode *inode,
3509 last_ex = EXT_LAST_EXTENT(eh); 3509 last_ex = EXT_LAST_EXTENT(eh);
3510 if (map->m_lblk + ar.len > le32_to_cpu(last_ex->ee_block) 3510 if (map->m_lblk + ar.len > le32_to_cpu(last_ex->ee_block)
3511 + ext4_ext_get_actual_len(last_ex)) 3511 + ext4_ext_get_actual_len(last_ex))
3512 EXT4_I(inode)->i_flags &= ~EXT4_EOFBLOCKS_FL; 3512 ext4_clear_inode_flag(inode, EXT4_INODE_EOFBLOCKS);
3513 } 3513 }
3514 err = ext4_ext_insert_extent(handle, inode, path, &newex, flags); 3514 err = ext4_ext_insert_extent(handle, inode, path, &newex, flags);
3515 if (err) { 3515 if (err) {
@@ -3650,7 +3650,7 @@ static void ext4_falloc_update_inode(struct inode *inode,
3650 * can proceed even if the new size is the same as i_size. 3650 * can proceed even if the new size is the same as i_size.
3651 */ 3651 */
3652 if (new_size > i_size_read(inode)) 3652 if (new_size > i_size_read(inode))
3653 EXT4_I(inode)->i_flags |= EXT4_EOFBLOCKS_FL; 3653 ext4_set_inode_flag(inode, EXT4_INODE_EOFBLOCKS);
3654 } 3654 }
3655 3655
3656} 3656}
@@ -3677,7 +3677,7 @@ long ext4_fallocate(struct inode *inode, int mode, loff_t offset, loff_t len)
3677 * currently supporting (pre)allocate mode for extent-based 3677 * currently supporting (pre)allocate mode for extent-based
3678 * files _only_ 3678 * files _only_
3679 */ 3679 */
3680 if (!(EXT4_I(inode)->i_flags & EXT4_EXTENTS_FL)) 3680 if (!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)))
3681 return -EOPNOTSUPP; 3681 return -EOPNOTSUPP;
3682 3682
3683 /* preallocation to directories is currently not supported */ 3683 /* preallocation to directories is currently not supported */
@@ -3922,7 +3922,7 @@ int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
3922 int error = 0; 3922 int error = 0;
3923 3923
3924 /* fallback to generic here if not in extents fmt */ 3924 /* fallback to generic here if not in extents fmt */
3925 if (!(EXT4_I(inode)->i_flags & EXT4_EXTENTS_FL)) 3925 if (!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)))
3926 return generic_block_fiemap(inode, fieinfo, start, len, 3926 return generic_block_fiemap(inode, fieinfo, start, len,
3927 ext4_get_block); 3927 ext4_get_block);
3928 3928
diff --git a/fs/ext4/file.c b/fs/ext4/file.c
index d0776e410f34..5313ae4cda2d 100644
--- a/fs/ext4/file.c
+++ b/fs/ext4/file.c
@@ -66,7 +66,7 @@ ext4_file_write(struct kiocb *iocb, const struct iovec *iov,
66 * is smaller than s_maxbytes, which is for extent-mapped files. 66 * is smaller than s_maxbytes, which is for extent-mapped files.
67 */ 67 */
68 68
69 if (!(EXT4_I(inode)->i_flags & EXT4_EXTENTS_FL)) { 69 if (!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))) {
70 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); 70 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
71 size_t length = iov_length(iov, nr_segs); 71 size_t length = iov_length(iov, nr_segs);
72 72
diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c
index 52618d5a1773..7f6b5826d5a6 100644
--- a/fs/ext4/ialloc.c
+++ b/fs/ext4/ialloc.c
@@ -492,7 +492,7 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent,
492 492
493 if (S_ISDIR(mode) && 493 if (S_ISDIR(mode) &&
494 ((parent == sb->s_root->d_inode) || 494 ((parent == sb->s_root->d_inode) ||
495 (EXT4_I(parent)->i_flags & EXT4_TOPDIR_FL))) { 495 (ext4_test_inode_flag(parent, EXT4_INODE_TOPDIR)))) {
496 int best_ndir = inodes_per_group; 496 int best_ndir = inodes_per_group;
497 int ret = -1; 497 int ret = -1;
498 498
@@ -1038,7 +1038,7 @@ got:
1038 if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_EXTENTS)) { 1038 if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_EXTENTS)) {
1039 /* set extent flag only for directory, file and normal symlink*/ 1039 /* set extent flag only for directory, file and normal symlink*/
1040 if (S_ISDIR(mode) || S_ISREG(mode) || S_ISLNK(mode)) { 1040 if (S_ISDIR(mode) || S_ISREG(mode) || S_ISLNK(mode)) {
1041 EXT4_I(inode)->i_flags |= EXT4_EXTENTS_FL; 1041 ext4_set_inode_flag(inode, EXT4_INODE_EXTENTS);
1042 ext4_ext_tree_init(handle, inode); 1042 ext4_ext_tree_init(handle, inode);
1043 } 1043 }
1044 } 1044 }
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 3b6877257580..c2b0724e8ad6 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -931,7 +931,7 @@ static int ext4_ind_map_blocks(handle_t *handle, struct inode *inode,
931 int count = 0; 931 int count = 0;
932 ext4_fsblk_t first_block = 0; 932 ext4_fsblk_t first_block = 0;
933 933
934 J_ASSERT(!(EXT4_I(inode)->i_flags & EXT4_EXTENTS_FL)); 934 J_ASSERT(!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)));
935 J_ASSERT(handle != NULL || (flags & EXT4_GET_BLOCKS_CREATE) == 0); 935 J_ASSERT(handle != NULL || (flags & EXT4_GET_BLOCKS_CREATE) == 0);
936 depth = ext4_block_to_path(inode, map->m_lblk, offsets, 936 depth = ext4_block_to_path(inode, map->m_lblk, offsets,
937 &blocks_to_boundary); 937 &blocks_to_boundary);
@@ -1059,7 +1059,7 @@ static int ext4_indirect_calc_metadata_amount(struct inode *inode,
1059 */ 1059 */
1060static int ext4_calc_metadata_amount(struct inode *inode, sector_t lblock) 1060static int ext4_calc_metadata_amount(struct inode *inode, sector_t lblock)
1061{ 1061{
1062 if (EXT4_I(inode)->i_flags & EXT4_EXTENTS_FL) 1062 if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))
1063 return ext4_ext_calc_metadata_amount(inode, lblock); 1063 return ext4_ext_calc_metadata_amount(inode, lblock);
1064 1064
1065 return ext4_indirect_calc_metadata_amount(inode, lblock); 1065 return ext4_indirect_calc_metadata_amount(inode, lblock);
@@ -1236,7 +1236,7 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode,
1236 * file system block. 1236 * file system block.
1237 */ 1237 */
1238 down_read((&EXT4_I(inode)->i_data_sem)); 1238 down_read((&EXT4_I(inode)->i_data_sem));
1239 if (EXT4_I(inode)->i_flags & EXT4_EXTENTS_FL) { 1239 if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) {
1240 retval = ext4_ext_map_blocks(handle, inode, map, 0); 1240 retval = ext4_ext_map_blocks(handle, inode, map, 0);
1241 } else { 1241 } else {
1242 retval = ext4_ind_map_blocks(handle, inode, map, 0); 1242 retval = ext4_ind_map_blocks(handle, inode, map, 0);
@@ -1295,7 +1295,7 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode,
1295 * We need to check for EXT4 here because migrate 1295 * We need to check for EXT4 here because migrate
1296 * could have changed the inode type in between 1296 * could have changed the inode type in between
1297 */ 1297 */
1298 if (EXT4_I(inode)->i_flags & EXT4_EXTENTS_FL) { 1298 if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) {
1299 retval = ext4_ext_map_blocks(handle, inode, map, flags); 1299 retval = ext4_ext_map_blocks(handle, inode, map, flags);
1300 } else { 1300 } else {
1301 retval = ext4_ind_map_blocks(handle, inode, map, flags); 1301 retval = ext4_ind_map_blocks(handle, inode, map, flags);
@@ -2325,7 +2325,7 @@ static void mpage_add_bh_to_extent(struct mpage_da_data *mpd,
2325 goto flush_it; 2325 goto flush_it;
2326 2326
2327 /* check if thereserved journal credits might overflow */ 2327 /* check if thereserved journal credits might overflow */
2328 if (!(EXT4_I(mpd->inode)->i_flags & EXT4_EXTENTS_FL)) { 2328 if (!(ext4_test_inode_flag(mpd->inode, EXT4_INODE_EXTENTS))) {
2329 if (nrblocks >= EXT4_MAX_TRANS_DATA) { 2329 if (nrblocks >= EXT4_MAX_TRANS_DATA) {
2330 /* 2330 /*
2331 * With non-extent format we are limited by the journal 2331 * With non-extent format we are limited by the journal
@@ -2779,7 +2779,7 @@ static int ext4_da_writepages_trans_blocks(struct inode *inode)
2779 * number of contiguous block. So we will limit 2779 * number of contiguous block. So we will limit
2780 * number of contiguous block to a sane value 2780 * number of contiguous block to a sane value
2781 */ 2781 */
2782 if (!(EXT4_I(inode)->i_flags & EXT4_EXTENTS_FL) && 2782 if (!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) &&
2783 (max_blocks > EXT4_MAX_TRANS_DATA)) 2783 (max_blocks > EXT4_MAX_TRANS_DATA))
2784 max_blocks = EXT4_MAX_TRANS_DATA; 2784 max_blocks = EXT4_MAX_TRANS_DATA;
2785 2785
@@ -3995,7 +3995,7 @@ static ssize_t ext4_direct_IO(int rw, struct kiocb *iocb,
3995 struct file *file = iocb->ki_filp; 3995 struct file *file = iocb->ki_filp;
3996 struct inode *inode = file->f_mapping->host; 3996 struct inode *inode = file->f_mapping->host;
3997 3997
3998 if (EXT4_I(inode)->i_flags & EXT4_EXTENTS_FL) 3998 if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))
3999 return ext4_ext_direct_IO(rw, iocb, iov, offset, nr_segs); 3999 return ext4_ext_direct_IO(rw, iocb, iov, offset, nr_segs);
4000 4000
4001 return ext4_ind_direct_IO(rw, iocb, iov, offset, nr_segs); 4001 return ext4_ind_direct_IO(rw, iocb, iov, offset, nr_segs);
@@ -4631,12 +4631,12 @@ void ext4_truncate(struct inode *inode)
4631 if (!ext4_can_truncate(inode)) 4631 if (!ext4_can_truncate(inode))
4632 return; 4632 return;
4633 4633
4634 EXT4_I(inode)->i_flags &= ~EXT4_EOFBLOCKS_FL; 4634 ext4_clear_inode_flag(inode, EXT4_INODE_EOFBLOCKS);
4635 4635
4636 if (inode->i_size == 0 && !test_opt(inode->i_sb, NO_AUTO_DA_ALLOC)) 4636 if (inode->i_size == 0 && !test_opt(inode->i_sb, NO_AUTO_DA_ALLOC))
4637 ext4_set_inode_state(inode, EXT4_STATE_DA_ALLOC_CLOSE); 4637 ext4_set_inode_state(inode, EXT4_STATE_DA_ALLOC_CLOSE);
4638 4638
4639 if (EXT4_I(inode)->i_flags & EXT4_EXTENTS_FL) { 4639 if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) {
4640 ext4_ext_truncate(inode); 4640 ext4_ext_truncate(inode);
4641 return; 4641 return;
4642 } 4642 }
@@ -5473,7 +5473,7 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr)
5473 } 5473 }
5474 5474
5475 if (attr->ia_valid & ATTR_SIZE) { 5475 if (attr->ia_valid & ATTR_SIZE) {
5476 if (!(EXT4_I(inode)->i_flags & EXT4_EXTENTS_FL)) { 5476 if (!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))) {
5477 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); 5477 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
5478 5478
5479 if (attr->ia_size > sbi->s_bitmap_maxbytes) { 5479 if (attr->ia_size > sbi->s_bitmap_maxbytes) {
@@ -5486,7 +5486,7 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr)
5486 if (S_ISREG(inode->i_mode) && 5486 if (S_ISREG(inode->i_mode) &&
5487 attr->ia_valid & ATTR_SIZE && 5487 attr->ia_valid & ATTR_SIZE &&
5488 (attr->ia_size < inode->i_size || 5488 (attr->ia_size < inode->i_size ||
5489 (EXT4_I(inode)->i_flags & EXT4_EOFBLOCKS_FL))) { 5489 (ext4_test_inode_flag(inode, EXT4_INODE_EOFBLOCKS)))) {
5490 handle_t *handle; 5490 handle_t *handle;
5491 5491
5492 handle = ext4_journal_start(inode, 3); 5492 handle = ext4_journal_start(inode, 3);
@@ -5518,7 +5518,7 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr)
5518 } 5518 }
5519 } 5519 }
5520 /* ext4_truncate will clear the flag */ 5520 /* ext4_truncate will clear the flag */
5521 if ((EXT4_I(inode)->i_flags & EXT4_EOFBLOCKS_FL)) 5521 if ((ext4_test_inode_flag(inode, EXT4_INODE_EOFBLOCKS)))
5522 ext4_truncate(inode); 5522 ext4_truncate(inode);
5523 } 5523 }
5524 5524
@@ -5594,7 +5594,7 @@ static int ext4_indirect_trans_blocks(struct inode *inode, int nrblocks,
5594 5594
5595static int ext4_index_trans_blocks(struct inode *inode, int nrblocks, int chunk) 5595static int ext4_index_trans_blocks(struct inode *inode, int nrblocks, int chunk)
5596{ 5596{
5597 if (!(EXT4_I(inode)->i_flags & EXT4_EXTENTS_FL)) 5597 if (!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)))
5598 return ext4_indirect_trans_blocks(inode, nrblocks, chunk); 5598 return ext4_indirect_trans_blocks(inode, nrblocks, chunk);
5599 return ext4_ext_index_trans_blocks(inode, nrblocks, chunk); 5599 return ext4_ext_index_trans_blocks(inode, nrblocks, chunk);
5600} 5600}
@@ -5929,9 +5929,9 @@ int ext4_change_inode_journal_flag(struct inode *inode, int val)
5929 */ 5929 */
5930 5930
5931 if (val) 5931 if (val)
5932 EXT4_I(inode)->i_flags |= EXT4_JOURNAL_DATA_FL; 5932 ext4_set_inode_flag(inode, EXT4_INODE_JOURNAL_DATA);
5933 else 5933 else
5934 EXT4_I(inode)->i_flags &= ~EXT4_JOURNAL_DATA_FL; 5934 ext4_clear_inode_flag(inode, EXT4_INODE_JOURNAL_DATA);
5935 ext4_set_aops(inode); 5935 ext4_set_aops(inode);
5936 5936
5937 jbd2_journal_unlock_updates(journal); 5937 jbd2_journal_unlock_updates(journal);
diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index e5dcdc9bd56b..0bdc0188e5e2 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -2006,7 +2006,7 @@ ext4_mb_regular_allocator(struct ext4_allocation_context *ac)
2006 sbi = EXT4_SB(sb); 2006 sbi = EXT4_SB(sb);
2007 ngroups = ext4_get_groups_count(sb); 2007 ngroups = ext4_get_groups_count(sb);
2008 /* non-extent files are limited to low blocks/groups */ 2008 /* non-extent files are limited to low blocks/groups */
2009 if (!(EXT4_I(ac->ac_inode)->i_flags & EXT4_EXTENTS_FL)) 2009 if (!(ext4_test_inode_flag(ac->ac_inode, EXT4_INODE_EXTENTS)))
2010 ngroups = sbi->s_blockfile_groups; 2010 ngroups = sbi->s_blockfile_groups;
2011 2011
2012 BUG_ON(ac->ac_status == AC_STATUS_FOUND); 2012 BUG_ON(ac->ac_status == AC_STATUS_FOUND);
@@ -3171,7 +3171,7 @@ ext4_mb_use_preallocated(struct ext4_allocation_context *ac)
3171 continue; 3171 continue;
3172 3172
3173 /* non-extent files can't have physical blocks past 2^32 */ 3173 /* non-extent files can't have physical blocks past 2^32 */
3174 if (!(EXT4_I(ac->ac_inode)->i_flags & EXT4_EXTENTS_FL) && 3174 if (!(ext4_test_inode_flag(ac->ac_inode, EXT4_INODE_EXTENTS)) &&
3175 pa->pa_pstart + pa->pa_len > EXT4_MAX_BLOCK_FILE_PHYS) 3175 pa->pa_pstart + pa->pa_len > EXT4_MAX_BLOCK_FILE_PHYS)
3176 continue; 3176 continue;
3177 3177
diff --git a/fs/ext4/migrate.c b/fs/ext4/migrate.c
index 34dcfc52ef44..6f3a27ec30bf 100644
--- a/fs/ext4/migrate.c
+++ b/fs/ext4/migrate.c
@@ -475,7 +475,7 @@ int ext4_ext_migrate(struct inode *inode)
475 */ 475 */
476 if (!EXT4_HAS_INCOMPAT_FEATURE(inode->i_sb, 476 if (!EXT4_HAS_INCOMPAT_FEATURE(inode->i_sb,
477 EXT4_FEATURE_INCOMPAT_EXTENTS) || 477 EXT4_FEATURE_INCOMPAT_EXTENTS) ||
478 (EXT4_I(inode)->i_flags & EXT4_EXTENTS_FL)) 478 (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)))
479 return -EINVAL; 479 return -EINVAL;
480 480
481 if (S_ISLNK(inode->i_mode) && inode->i_blocks == 0) 481 if (S_ISLNK(inode->i_mode) && inode->i_blocks == 0)
diff --git a/fs/ext4/move_extent.c b/fs/ext4/move_extent.c
index b8b8ea1ceda8..3a6c92ac131c 100644
--- a/fs/ext4/move_extent.c
+++ b/fs/ext4/move_extent.c
@@ -977,11 +977,11 @@ mext_check_arguments(struct inode *orig_inode,
977 } 977 }
978 978
979 /* Ext4 move extent supports only extent based file */ 979 /* Ext4 move extent supports only extent based file */
980 if (!(EXT4_I(orig_inode)->i_flags & EXT4_EXTENTS_FL)) { 980 if (!(ext4_test_inode_flag(orig_inode, EXT4_INODE_EXTENTS))) {
981 ext4_debug("ext4 move extent: orig file is not extents " 981 ext4_debug("ext4 move extent: orig file is not extents "
982 "based file [ino:orig %lu]\n", orig_inode->i_ino); 982 "based file [ino:orig %lu]\n", orig_inode->i_ino);
983 return -EOPNOTSUPP; 983 return -EOPNOTSUPP;
984 } else if (!(EXT4_I(donor_inode)->i_flags & EXT4_EXTENTS_FL)) { 984 } else if (!(ext4_test_inode_flag(donor_inode, EXT4_INODE_EXTENTS))) {
985 ext4_debug("ext4 move extent: donor file is not extents " 985 ext4_debug("ext4 move extent: donor file is not extents "
986 "based file [ino:donor %lu]\n", donor_inode->i_ino); 986 "based file [ino:donor %lu]\n", donor_inode->i_ino);
987 return -EOPNOTSUPP; 987 return -EOPNOTSUPP;
diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
index bff77b04f0d1..7b4bf8feae4e 100644
--- a/fs/ext4/namei.c
+++ b/fs/ext4/namei.c
@@ -656,7 +656,7 @@ int ext4_htree_fill_tree(struct file *dir_file, __u32 start_hash,
656 dxtrace(printk(KERN_DEBUG "In htree_fill_tree, start hash: %x:%x\n", 656 dxtrace(printk(KERN_DEBUG "In htree_fill_tree, start hash: %x:%x\n",
657 start_hash, start_minor_hash)); 657 start_hash, start_minor_hash));
658 dir = dir_file->f_path.dentry->d_inode; 658 dir = dir_file->f_path.dentry->d_inode;
659 if (!(EXT4_I(dir)->i_flags & EXT4_INDEX_FL)) { 659 if (!(ext4_test_inode_flag(dir, EXT4_INODE_INDEX))) {
660 hinfo.hash_version = EXT4_SB(dir->i_sb)->s_def_hash_version; 660 hinfo.hash_version = EXT4_SB(dir->i_sb)->s_def_hash_version;
661 if (hinfo.hash_version <= DX_HASH_TEA) 661 if (hinfo.hash_version <= DX_HASH_TEA)
662 hinfo.hash_version += 662 hinfo.hash_version +=
@@ -801,7 +801,7 @@ static void ext4_update_dx_flag(struct inode *inode)
801{ 801{
802 if (!EXT4_HAS_COMPAT_FEATURE(inode->i_sb, 802 if (!EXT4_HAS_COMPAT_FEATURE(inode->i_sb,
803 EXT4_FEATURE_COMPAT_DIR_INDEX)) 803 EXT4_FEATURE_COMPAT_DIR_INDEX))
804 EXT4_I(inode)->i_flags &= ~EXT4_INDEX_FL; 804 ext4_clear_inode_flag(inode, EXT4_INODE_INDEX);
805} 805}
806 806
807/* 807/*
@@ -1416,7 +1416,7 @@ static int make_indexed_dir(handle_t *handle, struct dentry *dentry,
1416 brelse(bh); 1416 brelse(bh);
1417 return retval; 1417 return retval;
1418 } 1418 }
1419 EXT4_I(dir)->i_flags |= EXT4_INDEX_FL; 1419 ext4_set_inode_flag(dir, EXT4_INODE_INDEX);
1420 data1 = bh2->b_data; 1420 data1 = bh2->b_data;
1421 1421
1422 memcpy (data1, de, len); 1422 memcpy (data1, de, len);
@@ -1489,7 +1489,7 @@ static int ext4_add_entry(handle_t *handle, struct dentry *dentry,
1489 retval = ext4_dx_add_entry(handle, dentry, inode); 1489 retval = ext4_dx_add_entry(handle, dentry, inode);
1490 if (!retval || (retval != ERR_BAD_DX_DIR)) 1490 if (!retval || (retval != ERR_BAD_DX_DIR))
1491 return retval; 1491 return retval;
1492 EXT4_I(dir)->i_flags &= ~EXT4_INDEX_FL; 1492 ext4_clear_inode_flag(dir, EXT4_INODE_INDEX);
1493 dx_fallback++; 1493 dx_fallback++;
1494 ext4_mark_inode_dirty(handle, dir); 1494 ext4_mark_inode_dirty(handle, dir);
1495 } 1495 }
@@ -2294,7 +2294,7 @@ retry:
2294 } 2294 }
2295 } else { 2295 } else {
2296 /* clear the extent format for fast symlink */ 2296 /* clear the extent format for fast symlink */
2297 EXT4_I(inode)->i_flags &= ~EXT4_EXTENTS_FL; 2297 ext4_clear_inode_flag(inode, EXT4_INODE_EXTENTS);
2298 inode->i_op = &ext4_fast_symlink_inode_operations; 2298 inode->i_op = &ext4_fast_symlink_inode_operations;
2299 memcpy((char *)&EXT4_I(inode)->i_data, symname, l); 2299 memcpy((char *)&EXT4_I(inode)->i_data, symname, l);
2300 inode->i_size = l-1; 2300 inode->i_size = l-1;
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 2e8790e801f4..9766b2ae6cdc 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -4148,6 +4148,7 @@ static int __init init_ext4_fs(void)
4148{ 4148{
4149 int err; 4149 int err;
4150 4150
4151 ext4_check_flag_values();
4151 err = init_ext4_system_zone(); 4152 err = init_ext4_system_zone();
4152 if (err) 4153 if (err)
4153 return err; 4154 return err;
diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
index 0a09a2e96f0a..47431bc662ab 100644
--- a/fs/ext4/xattr.c
+++ b/fs/ext4/xattr.c
@@ -818,7 +818,7 @@ inserted:
818 EXT4_I(inode)->i_block_group); 818 EXT4_I(inode)->i_block_group);
819 819
820 /* non-extent files can't have physical blocks past 2^32 */ 820 /* non-extent files can't have physical blocks past 2^32 */
821 if (!(EXT4_I(inode)->i_flags & EXT4_EXTENTS_FL)) 821 if (!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)))
822 goal = goal & EXT4_MAX_BLOCK_FILE_PHYS; 822 goal = goal & EXT4_MAX_BLOCK_FILE_PHYS;
823 823
824 block = ext4_new_meta_blocks(handle, inode, 824 block = ext4_new_meta_blocks(handle, inode,
@@ -826,7 +826,7 @@ inserted:
826 if (error) 826 if (error)
827 goto cleanup; 827 goto cleanup;
828 828
829 if (!(EXT4_I(inode)->i_flags & EXT4_EXTENTS_FL)) 829 if (!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)))
830 BUG_ON(block > EXT4_MAX_BLOCK_FILE_PHYS); 830 BUG_ON(block > EXT4_MAX_BLOCK_FILE_PHYS);
831 831
832 ea_idebug(inode, "creating block %d", block); 832 ea_idebug(inode, "creating block %d", block);