aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Monakhov <dmonakhov@openvz.org>2014-10-13 03:36:16 -0400
committerTheodore Ts'o <tytso@mit.edu>2014-10-13 03:36:16 -0400
commit9aa5d32ba269bec0e7eaba2697a986a7b0bc8528 (patch)
tree3702c0a5ff64152ecd33d7469164832a7811f28f
parent65dd8327eb055a393a413a2214f70a9a10ff7ad6 (diff)
ext4: Replace open coded mdata csum feature to helper function
Besides the fact that this replacement improves code readability it also protects from errors caused direct EXT4_S(sb)->s_es manipulation which may result attempt to use uninitialized csum machinery. #Testcase_BEGIN IMG=/dev/ram0 MNT=/mnt mkfs.ext4 $IMG mount $IMG $MNT #Enable feature directly on disk, on mounted fs tune2fs -O metadata_csum $IMG # Provoke metadata update, likey result in OOPS touch $MNT/test umount $MNT #Testcase_END # Replacement script @@ expression E; @@ - EXT4_HAS_RO_COMPAT_FEATURE(E, EXT4_FEATURE_RO_COMPAT_METADATA_CSUM) + ext4_has_metadata_csum(E) https://bugzilla.kernel.org/show_bug.cgi?id=82201 Signed-off-by: Dmitry Monakhov <dmonakhov@openvz.org> Signed-off-by: Theodore Ts'o <tytso@mit.edu> Cc: stable@vger.kernel.org
-rw-r--r--fs/ext4/bitmap.c12
-rw-r--r--fs/ext4/ext4.h8
-rw-r--r--fs/ext4/extents.c6
-rw-r--r--fs/ext4/ialloc.c3
-rw-r--r--fs/ext4/inline.c3
-rw-r--r--fs/ext4/inode.c9
-rw-r--r--fs/ext4/ioctl.c3
-rw-r--r--fs/ext4/mmp.c6
-rw-r--r--fs/ext4/namei.c39
-rw-r--r--fs/ext4/resize.c3
-rw-r--r--fs/ext4/super.c15
-rw-r--r--fs/ext4/xattr.c6
12 files changed, 43 insertions, 70 deletions
diff --git a/fs/ext4/bitmap.c b/fs/ext4/bitmap.c
index 3285aa5a706a..b610779a958c 100644
--- a/fs/ext4/bitmap.c
+++ b/fs/ext4/bitmap.c
@@ -24,8 +24,7 @@ int ext4_inode_bitmap_csum_verify(struct super_block *sb, ext4_group_t group,
24 __u32 provided, calculated; 24 __u32 provided, calculated;
25 struct ext4_sb_info *sbi = EXT4_SB(sb); 25 struct ext4_sb_info *sbi = EXT4_SB(sb);
26 26
27 if (!EXT4_HAS_RO_COMPAT_FEATURE(sb, 27 if (!ext4_has_metadata_csum(sb))
28 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
29 return 1; 28 return 1;
30 29
31 provided = le16_to_cpu(gdp->bg_inode_bitmap_csum_lo); 30 provided = le16_to_cpu(gdp->bg_inode_bitmap_csum_lo);
@@ -46,8 +45,7 @@ void ext4_inode_bitmap_csum_set(struct super_block *sb, ext4_group_t group,
46 __u32 csum; 45 __u32 csum;
47 struct ext4_sb_info *sbi = EXT4_SB(sb); 46 struct ext4_sb_info *sbi = EXT4_SB(sb);
48 47
49 if (!EXT4_HAS_RO_COMPAT_FEATURE(sb, 48 if (!ext4_has_metadata_csum(sb))
50 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
51 return; 49 return;
52 50
53 csum = ext4_chksum(sbi, sbi->s_csum_seed, (__u8 *)bh->b_data, sz); 51 csum = ext4_chksum(sbi, sbi->s_csum_seed, (__u8 *)bh->b_data, sz);
@@ -65,8 +63,7 @@ int ext4_block_bitmap_csum_verify(struct super_block *sb, ext4_group_t group,
65 struct ext4_sb_info *sbi = EXT4_SB(sb); 63 struct ext4_sb_info *sbi = EXT4_SB(sb);
66 int sz = EXT4_CLUSTERS_PER_GROUP(sb) / 8; 64 int sz = EXT4_CLUSTERS_PER_GROUP(sb) / 8;
67 65
68 if (!EXT4_HAS_RO_COMPAT_FEATURE(sb, 66 if (!ext4_has_metadata_csum(sb))
69 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
70 return 1; 67 return 1;
71 68
72 provided = le16_to_cpu(gdp->bg_block_bitmap_csum_lo); 69 provided = le16_to_cpu(gdp->bg_block_bitmap_csum_lo);
@@ -91,8 +88,7 @@ void ext4_block_bitmap_csum_set(struct super_block *sb, ext4_group_t group,
91 __u32 csum; 88 __u32 csum;
92 struct ext4_sb_info *sbi = EXT4_SB(sb); 89 struct ext4_sb_info *sbi = EXT4_SB(sb);
93 90
94 if (!EXT4_HAS_RO_COMPAT_FEATURE(sb, 91 if (!ext4_has_metadata_csum(sb))
95 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
96 return; 92 return;
97 93
98 csum = ext4_chksum(sbi, sbi->s_csum_seed, (__u8 *)bh->b_data, sz); 94 csum = ext4_chksum(sbi, sbi->s_csum_seed, (__u8 *)bh->b_data, sz);
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index 012e89bd9644..1483d9c6061f 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -2337,6 +2337,14 @@ static inline int ext4_has_group_desc_csum(struct super_block *sb)
2337 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM); 2337 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM);
2338} 2338}
2339 2339
2340static inline int ext4_has_metadata_csum(struct super_block *sb)
2341{
2342 WARN_ON_ONCE(EXT4_HAS_RO_COMPAT_FEATURE(sb,
2343 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM) &&
2344 !EXT4_SB(sb)->s_chksum_driver);
2345
2346 return (EXT4_SB(sb)->s_chksum_driver != NULL);
2347}
2340static inline ext4_fsblk_t ext4_blocks_count(struct ext4_super_block *es) 2348static inline ext4_fsblk_t ext4_blocks_count(struct ext4_super_block *es)
2341{ 2349{
2342 return ((ext4_fsblk_t)le32_to_cpu(es->s_blocks_count_hi) << 32) | 2350 return ((ext4_fsblk_t)le32_to_cpu(es->s_blocks_count_hi) << 32) |
diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index c3ed9af20d20..37043d0b2be8 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -73,8 +73,7 @@ static int ext4_extent_block_csum_verify(struct inode *inode,
73{ 73{
74 struct ext4_extent_tail *et; 74 struct ext4_extent_tail *et;
75 75
76 if (!EXT4_HAS_RO_COMPAT_FEATURE(inode->i_sb, 76 if (!ext4_has_metadata_csum(inode->i_sb))
77 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
78 return 1; 77 return 1;
79 78
80 et = find_ext4_extent_tail(eh); 79 et = find_ext4_extent_tail(eh);
@@ -88,8 +87,7 @@ static void ext4_extent_block_csum_set(struct inode *inode,
88{ 87{
89 struct ext4_extent_tail *et; 88 struct ext4_extent_tail *et;
90 89
91 if (!EXT4_HAS_RO_COMPAT_FEATURE(inode->i_sb, 90 if (!ext4_has_metadata_csum(inode->i_sb))
92 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
93 return; 91 return;
94 92
95 et = find_ext4_extent_tail(eh); 93 et = find_ext4_extent_tail(eh);
diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c
index 5b87fc36aab8..8012a5daf401 100644
--- a/fs/ext4/ialloc.c
+++ b/fs/ext4/ialloc.c
@@ -1011,8 +1011,7 @@ got:
1011 spin_unlock(&sbi->s_next_gen_lock); 1011 spin_unlock(&sbi->s_next_gen_lock);
1012 1012
1013 /* Precompute checksum seed for inode metadata */ 1013 /* Precompute checksum seed for inode metadata */
1014 if (EXT4_HAS_RO_COMPAT_FEATURE(sb, 1014 if (ext4_has_metadata_csum(sb)) {
1015 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM)) {
1016 __u32 csum; 1015 __u32 csum;
1017 __le32 inum = cpu_to_le32(inode->i_ino); 1016 __le32 inum = cpu_to_le32(inode->i_ino);
1018 __le32 gen = cpu_to_le32(inode->i_generation); 1017 __le32 gen = cpu_to_le32(inode->i_generation);
diff --git a/fs/ext4/inline.c b/fs/ext4/inline.c
index 378aadf5e6db..3ea62695abce 100644
--- a/fs/ext4/inline.c
+++ b/fs/ext4/inline.c
@@ -1128,8 +1128,7 @@ static int ext4_finish_convert_inline_dir(handle_t *handle,
1128 memcpy((void *)de, buf + EXT4_INLINE_DOTDOT_SIZE, 1128 memcpy((void *)de, buf + EXT4_INLINE_DOTDOT_SIZE,
1129 inline_size - EXT4_INLINE_DOTDOT_SIZE); 1129 inline_size - EXT4_INLINE_DOTDOT_SIZE);
1130 1130
1131 if (EXT4_HAS_RO_COMPAT_FEATURE(inode->i_sb, 1131 if (ext4_has_metadata_csum(inode->i_sb))
1132 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
1133 csum_size = sizeof(struct ext4_dir_entry_tail); 1132 csum_size = sizeof(struct ext4_dir_entry_tail);
1134 1133
1135 inode->i_size = inode->i_sb->s_blocksize; 1134 inode->i_size = inode->i_sb->s_blocksize;
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 0dd9150c0c04..e9777f93cf05 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -83,8 +83,7 @@ static int ext4_inode_csum_verify(struct inode *inode, struct ext4_inode *raw,
83 83
84 if (EXT4_SB(inode->i_sb)->s_es->s_creator_os != 84 if (EXT4_SB(inode->i_sb)->s_es->s_creator_os !=
85 cpu_to_le32(EXT4_OS_LINUX) || 85 cpu_to_le32(EXT4_OS_LINUX) ||
86 !EXT4_HAS_RO_COMPAT_FEATURE(inode->i_sb, 86 !ext4_has_metadata_csum(inode->i_sb))
87 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
88 return 1; 87 return 1;
89 88
90 provided = le16_to_cpu(raw->i_checksum_lo); 89 provided = le16_to_cpu(raw->i_checksum_lo);
@@ -105,8 +104,7 @@ static void ext4_inode_csum_set(struct inode *inode, struct ext4_inode *raw,
105 104
106 if (EXT4_SB(inode->i_sb)->s_es->s_creator_os != 105 if (EXT4_SB(inode->i_sb)->s_es->s_creator_os !=
107 cpu_to_le32(EXT4_OS_LINUX) || 106 cpu_to_le32(EXT4_OS_LINUX) ||
108 !EXT4_HAS_RO_COMPAT_FEATURE(inode->i_sb, 107 !ext4_has_metadata_csum(inode->i_sb))
109 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
110 return; 108 return;
111 109
112 csum = ext4_inode_csum(inode, raw, ei); 110 csum = ext4_inode_csum(inode, raw, ei);
@@ -3928,8 +3926,7 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino)
3928 ei->i_extra_isize = 0; 3926 ei->i_extra_isize = 0;
3929 3927
3930 /* Precompute checksum seed for inode metadata */ 3928 /* Precompute checksum seed for inode metadata */
3931 if (EXT4_HAS_RO_COMPAT_FEATURE(sb, 3929 if (ext4_has_metadata_csum(sb)) {
3932 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM)) {
3933 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); 3930 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
3934 __u32 csum; 3931 __u32 csum;
3935 __le32 inum = cpu_to_le32(inode->i_ino); 3932 __le32 inum = cpu_to_le32(inode->i_ino);
diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
index 3d5de16f028f..bfda18a15592 100644
--- a/fs/ext4/ioctl.c
+++ b/fs/ext4/ioctl.c
@@ -331,8 +331,7 @@ flags_out:
331 if (!inode_owner_or_capable(inode)) 331 if (!inode_owner_or_capable(inode))
332 return -EPERM; 332 return -EPERM;
333 333
334 if (EXT4_HAS_RO_COMPAT_FEATURE(inode->i_sb, 334 if (ext4_has_metadata_csum(inode->i_sb)) {
335 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM)) {
336 ext4_warning(sb, "Setting inode version is not " 335 ext4_warning(sb, "Setting inode version is not "
337 "supported with metadata_csum enabled."); 336 "supported with metadata_csum enabled.");
338 return -ENOTTY; 337 return -ENOTTY;
diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
index 32bce844c2e1..8313ca3324ec 100644
--- a/fs/ext4/mmp.c
+++ b/fs/ext4/mmp.c
@@ -20,8 +20,7 @@ static __le32 ext4_mmp_csum(struct super_block *sb, struct mmp_struct *mmp)
20 20
21static int ext4_mmp_csum_verify(struct super_block *sb, struct mmp_struct *mmp) 21static int ext4_mmp_csum_verify(struct super_block *sb, struct mmp_struct *mmp)
22{ 22{
23 if (!EXT4_HAS_RO_COMPAT_FEATURE(sb, 23 if (!ext4_has_metadata_csum(sb))
24 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
25 return 1; 24 return 1;
26 25
27 return mmp->mmp_checksum == ext4_mmp_csum(sb, mmp); 26 return mmp->mmp_checksum == ext4_mmp_csum(sb, mmp);
@@ -29,8 +28,7 @@ static int ext4_mmp_csum_verify(struct super_block *sb, struct mmp_struct *mmp)
29 28
30static void ext4_mmp_csum_set(struct super_block *sb, struct mmp_struct *mmp) 29static void ext4_mmp_csum_set(struct super_block *sb, struct mmp_struct *mmp)
31{ 30{
32 if (!EXT4_HAS_RO_COMPAT_FEATURE(sb, 31 if (!ext4_has_metadata_csum(sb))
33 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
34 return; 32 return;
35 33
36 mmp->mmp_checksum = ext4_mmp_csum(sb, mmp); 34 mmp->mmp_checksum = ext4_mmp_csum(sb, mmp);
diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
index 7037ecf0fc23..61756f941ed0 100644
--- a/fs/ext4/namei.c
+++ b/fs/ext4/namei.c
@@ -124,8 +124,7 @@ static struct buffer_head *__ext4_read_dirblock(struct inode *inode,
124 "directory leaf block found instead of index block"); 124 "directory leaf block found instead of index block");
125 return ERR_PTR(-EIO); 125 return ERR_PTR(-EIO);
126 } 126 }
127 if (!EXT4_HAS_RO_COMPAT_FEATURE(inode->i_sb, 127 if (!ext4_has_metadata_csum(inode->i_sb) ||
128 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM) ||
129 buffer_verified(bh)) 128 buffer_verified(bh))
130 return bh; 129 return bh;
131 130
@@ -338,8 +337,7 @@ int ext4_dirent_csum_verify(struct inode *inode, struct ext4_dir_entry *dirent)
338{ 337{
339 struct ext4_dir_entry_tail *t; 338 struct ext4_dir_entry_tail *t;
340 339
341 if (!EXT4_HAS_RO_COMPAT_FEATURE(inode->i_sb, 340 if (!ext4_has_metadata_csum(inode->i_sb))
342 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
343 return 1; 341 return 1;
344 342
345 t = get_dirent_tail(inode, dirent); 343 t = get_dirent_tail(inode, dirent);
@@ -360,8 +358,7 @@ static void ext4_dirent_csum_set(struct inode *inode,
360{ 358{
361 struct ext4_dir_entry_tail *t; 359 struct ext4_dir_entry_tail *t;
362 360
363 if (!EXT4_HAS_RO_COMPAT_FEATURE(inode->i_sb, 361 if (!ext4_has_metadata_csum(inode->i_sb))
364 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
365 return; 362 return;
366 363
367 t = get_dirent_tail(inode, dirent); 364 t = get_dirent_tail(inode, dirent);
@@ -436,8 +433,7 @@ static int ext4_dx_csum_verify(struct inode *inode,
436 struct dx_tail *t; 433 struct dx_tail *t;
437 int count_offset, limit, count; 434 int count_offset, limit, count;
438 435
439 if (!EXT4_HAS_RO_COMPAT_FEATURE(inode->i_sb, 436 if (!ext4_has_metadata_csum(inode->i_sb))
440 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
441 return 1; 437 return 1;
442 438
443 c = get_dx_countlimit(inode, dirent, &count_offset); 439 c = get_dx_countlimit(inode, dirent, &count_offset);
@@ -466,8 +462,7 @@ static void ext4_dx_csum_set(struct inode *inode, struct ext4_dir_entry *dirent)
466 struct dx_tail *t; 462 struct dx_tail *t;
467 int count_offset, limit, count; 463 int count_offset, limit, count;
468 464
469 if (!EXT4_HAS_RO_COMPAT_FEATURE(inode->i_sb, 465 if (!ext4_has_metadata_csum(inode->i_sb))
470 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
471 return; 466 return;
472 467
473 c = get_dx_countlimit(inode, dirent, &count_offset); 468 c = get_dx_countlimit(inode, dirent, &count_offset);
@@ -555,8 +550,7 @@ static inline unsigned dx_root_limit(struct inode *dir, unsigned infosize)
555 unsigned entry_space = dir->i_sb->s_blocksize - EXT4_DIR_REC_LEN(1) - 550 unsigned entry_space = dir->i_sb->s_blocksize - EXT4_DIR_REC_LEN(1) -
556 EXT4_DIR_REC_LEN(2) - infosize; 551 EXT4_DIR_REC_LEN(2) - infosize;
557 552
558 if (EXT4_HAS_RO_COMPAT_FEATURE(dir->i_sb, 553 if (ext4_has_metadata_csum(dir->i_sb))
559 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
560 entry_space -= sizeof(struct dx_tail); 554 entry_space -= sizeof(struct dx_tail);
561 return entry_space / sizeof(struct dx_entry); 555 return entry_space / sizeof(struct dx_entry);
562} 556}
@@ -565,8 +559,7 @@ static inline unsigned dx_node_limit(struct inode *dir)
565{ 559{
566 unsigned entry_space = dir->i_sb->s_blocksize - EXT4_DIR_REC_LEN(0); 560 unsigned entry_space = dir->i_sb->s_blocksize - EXT4_DIR_REC_LEN(0);
567 561
568 if (EXT4_HAS_RO_COMPAT_FEATURE(dir->i_sb, 562 if (ext4_has_metadata_csum(dir->i_sb))
569 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
570 entry_space -= sizeof(struct dx_tail); 563 entry_space -= sizeof(struct dx_tail);
571 return entry_space / sizeof(struct dx_entry); 564 return entry_space / sizeof(struct dx_entry);
572} 565}
@@ -1524,8 +1517,7 @@ static struct ext4_dir_entry_2 *do_split(handle_t *handle, struct inode *dir,
1524 int csum_size = 0; 1517 int csum_size = 0;
1525 int err = 0, i; 1518 int err = 0, i;
1526 1519
1527 if (EXT4_HAS_RO_COMPAT_FEATURE(dir->i_sb, 1520 if (ext4_has_metadata_csum(dir->i_sb))
1528 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
1529 csum_size = sizeof(struct ext4_dir_entry_tail); 1521 csum_size = sizeof(struct ext4_dir_entry_tail);
1530 1522
1531 bh2 = ext4_append(handle, dir, &newblock); 1523 bh2 = ext4_append(handle, dir, &newblock);
@@ -1691,8 +1683,7 @@ static int add_dirent_to_buf(handle_t *handle, struct dentry *dentry,
1691 int csum_size = 0; 1683 int csum_size = 0;
1692 int err; 1684 int err;
1693 1685
1694 if (EXT4_HAS_RO_COMPAT_FEATURE(inode->i_sb, 1686 if (ext4_has_metadata_csum(inode->i_sb))
1695 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
1696 csum_size = sizeof(struct ext4_dir_entry_tail); 1687 csum_size = sizeof(struct ext4_dir_entry_tail);
1697 1688
1698 if (!de) { 1689 if (!de) {
@@ -1759,8 +1750,7 @@ static int make_indexed_dir(handle_t *handle, struct dentry *dentry,
1759 struct fake_dirent *fde; 1750 struct fake_dirent *fde;
1760 int csum_size = 0; 1751 int csum_size = 0;
1761 1752
1762 if (EXT4_HAS_RO_COMPAT_FEATURE(inode->i_sb, 1753 if (ext4_has_metadata_csum(inode->i_sb))
1763 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
1764 csum_size = sizeof(struct ext4_dir_entry_tail); 1754 csum_size = sizeof(struct ext4_dir_entry_tail);
1765 1755
1766 blocksize = dir->i_sb->s_blocksize; 1756 blocksize = dir->i_sb->s_blocksize;
@@ -1877,8 +1867,7 @@ static int ext4_add_entry(handle_t *handle, struct dentry *dentry,
1877 ext4_lblk_t block, blocks; 1867 ext4_lblk_t block, blocks;
1878 int csum_size = 0; 1868 int csum_size = 0;
1879 1869
1880 if (EXT4_HAS_RO_COMPAT_FEATURE(inode->i_sb, 1870 if (ext4_has_metadata_csum(inode->i_sb))
1881 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
1882 csum_size = sizeof(struct ext4_dir_entry_tail); 1871 csum_size = sizeof(struct ext4_dir_entry_tail);
1883 1872
1884 sb = dir->i_sb; 1873 sb = dir->i_sb;
@@ -2142,8 +2131,7 @@ static int ext4_delete_entry(handle_t *handle,
2142 return err; 2131 return err;
2143 } 2132 }
2144 2133
2145 if (EXT4_HAS_RO_COMPAT_FEATURE(dir->i_sb, 2134 if (ext4_has_metadata_csum(dir->i_sb))
2146 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
2147 csum_size = sizeof(struct ext4_dir_entry_tail); 2135 csum_size = sizeof(struct ext4_dir_entry_tail);
2148 2136
2149 BUFFER_TRACE(bh, "get_write_access"); 2137 BUFFER_TRACE(bh, "get_write_access");
@@ -2362,8 +2350,7 @@ static int ext4_init_new_dir(handle_t *handle, struct inode *dir,
2362 int csum_size = 0; 2350 int csum_size = 0;
2363 int err; 2351 int err;
2364 2352
2365 if (EXT4_HAS_RO_COMPAT_FEATURE(dir->i_sb, 2353 if (ext4_has_metadata_csum(dir->i_sb))
2366 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
2367 csum_size = sizeof(struct ext4_dir_entry_tail); 2354 csum_size = sizeof(struct ext4_dir_entry_tail);
2368 2355
2369 if (ext4_test_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA)) { 2356 if (ext4_test_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA)) {
diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c
index bb0e80f03e2e..d5afb0a0cf25 100644
--- a/fs/ext4/resize.c
+++ b/fs/ext4/resize.c
@@ -1210,8 +1210,7 @@ static int ext4_set_bitmap_checksums(struct super_block *sb,
1210{ 1210{
1211 struct buffer_head *bh; 1211 struct buffer_head *bh;
1212 1212
1213 if (!EXT4_HAS_RO_COMPAT_FEATURE(sb, 1213 if (!ext4_has_metadata_csum(sb))
1214 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
1215 return 0; 1214 return 0;
1216 1215
1217 bh = ext4_get_bitmap(sb, group_data->inode_bitmap); 1216 bh = ext4_get_bitmap(sb, group_data->inode_bitmap);
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index a0811cc00c91..5afe42db303c 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -140,8 +140,7 @@ static __le32 ext4_superblock_csum(struct super_block *sb,
140static int ext4_superblock_csum_verify(struct super_block *sb, 140static int ext4_superblock_csum_verify(struct super_block *sb,
141 struct ext4_super_block *es) 141 struct ext4_super_block *es)
142{ 142{
143 if (!EXT4_HAS_RO_COMPAT_FEATURE(sb, 143 if (!ext4_has_metadata_csum(sb))
144 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
145 return 1; 144 return 1;
146 145
147 return es->s_checksum == ext4_superblock_csum(sb, es); 146 return es->s_checksum == ext4_superblock_csum(sb, es);
@@ -151,8 +150,7 @@ void ext4_superblock_csum_set(struct super_block *sb)
151{ 150{
152 struct ext4_super_block *es = EXT4_SB(sb)->s_es; 151 struct ext4_super_block *es = EXT4_SB(sb)->s_es;
153 152
154 if (!EXT4_HAS_RO_COMPAT_FEATURE(sb, 153 if (!ext4_has_metadata_csum(sb))
155 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
156 return; 154 return;
157 155
158 es->s_checksum = ext4_superblock_csum(sb, es); 156 es->s_checksum = ext4_superblock_csum(sb, es);
@@ -1989,8 +1987,7 @@ static __le16 ext4_group_desc_csum(struct ext4_sb_info *sbi, __u32 block_group,
1989 __u16 crc = 0; 1987 __u16 crc = 0;
1990 __le32 le_group = cpu_to_le32(block_group); 1988 __le32 le_group = cpu_to_le32(block_group);
1991 1989
1992 if ((sbi->s_es->s_feature_ro_compat & 1990 if (ext4_has_metadata_csum(sbi->s_sb)) {
1993 cpu_to_le32(EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))) {
1994 /* Use new metadata_csum algorithm */ 1991 /* Use new metadata_csum algorithm */
1995 __le16 save_csum; 1992 __le16 save_csum;
1996 __u32 csum32; 1993 __u32 csum32;
@@ -3199,8 +3196,7 @@ static int set_journal_csum_feature_set(struct super_block *sb)
3199 int compat, incompat; 3196 int compat, incompat;
3200 struct ext4_sb_info *sbi = EXT4_SB(sb); 3197 struct ext4_sb_info *sbi = EXT4_SB(sb);
3201 3198
3202 if (EXT4_HAS_RO_COMPAT_FEATURE(sb, 3199 if (ext4_has_metadata_csum(sb)) {
3203 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM)) {
3204 /* journal checksum v3 */ 3200 /* journal checksum v3 */
3205 compat = 0; 3201 compat = 0;
3206 incompat = JBD2_FEATURE_INCOMPAT_CSUM_V3; 3202 incompat = JBD2_FEATURE_INCOMPAT_CSUM_V3;
@@ -3508,8 +3504,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
3508 } 3504 }
3509 3505
3510 /* Precompute checksum seed for all metadata */ 3506 /* Precompute checksum seed for all metadata */
3511 if (EXT4_HAS_RO_COMPAT_FEATURE(sb, 3507 if (ext4_has_metadata_csum(sb))
3512 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
3513 sbi->s_csum_seed = ext4_chksum(sbi, ~0, es->s_uuid, 3508 sbi->s_csum_seed = ext4_chksum(sbi, ~0, es->s_uuid,
3514 sizeof(es->s_uuid)); 3509 sizeof(es->s_uuid));
3515 3510
diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
index 42823ab3718c..1e09fc77395c 100644
--- a/fs/ext4/xattr.c
+++ b/fs/ext4/xattr.c
@@ -142,8 +142,7 @@ static int ext4_xattr_block_csum_verify(struct inode *inode,
142 sector_t block_nr, 142 sector_t block_nr,
143 struct ext4_xattr_header *hdr) 143 struct ext4_xattr_header *hdr)
144{ 144{
145 if (EXT4_HAS_RO_COMPAT_FEATURE(inode->i_sb, 145 if (ext4_has_metadata_csum(inode->i_sb) &&
146 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM) &&
147 (hdr->h_checksum != ext4_xattr_block_csum(inode, block_nr, hdr))) 146 (hdr->h_checksum != ext4_xattr_block_csum(inode, block_nr, hdr)))
148 return 0; 147 return 0;
149 return 1; 148 return 1;
@@ -153,8 +152,7 @@ static void ext4_xattr_block_csum_set(struct inode *inode,
153 sector_t block_nr, 152 sector_t block_nr,
154 struct ext4_xattr_header *hdr) 153 struct ext4_xattr_header *hdr)
155{ 154{
156 if (!EXT4_HAS_RO_COMPAT_FEATURE(inode->i_sb, 155 if (!ext4_has_metadata_csum(inode->i_sb))
157 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
158 return; 156 return;
159 157
160 hdr->h_checksum = ext4_xattr_block_csum(inode, block_nr, hdr); 158 hdr->h_checksum = ext4_xattr_block_csum(inode, block_nr, hdr);