Commit 10e55cd4 authored by Dmitry Monakhov's avatar Dmitry Monakhov Committed by Luis Henriques

ext4: Replace open coded mdata csum feature to helper function

commit 9aa5d32b upstream.

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=82201Signed-off-by: default avatarDmitry Monakhov <dmonakhov@openvz.org>
Signed-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
Signed-off-by: default avatarLuis Henriques <luis.henriques@canonical.com>
parent 8035ac91
...@@ -24,8 +24,7 @@ int ext4_inode_bitmap_csum_verify(struct super_block *sb, ext4_group_t group, ...@@ -24,8 +24,7 @@ int ext4_inode_bitmap_csum_verify(struct super_block *sb, ext4_group_t group,
__u32 provided, calculated; __u32 provided, calculated;
struct ext4_sb_info *sbi = EXT4_SB(sb); struct ext4_sb_info *sbi = EXT4_SB(sb);
if (!EXT4_HAS_RO_COMPAT_FEATURE(sb, if (!ext4_has_metadata_csum(sb))
EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
return 1; return 1;
provided = le16_to_cpu(gdp->bg_inode_bitmap_csum_lo); 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,8 +45,7 @@ void ext4_inode_bitmap_csum_set(struct super_block *sb, ext4_group_t group,
__u32 csum; __u32 csum;
struct ext4_sb_info *sbi = EXT4_SB(sb); struct ext4_sb_info *sbi = EXT4_SB(sb);
if (!EXT4_HAS_RO_COMPAT_FEATURE(sb, if (!ext4_has_metadata_csum(sb))
EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
return; return;
csum = ext4_chksum(sbi, sbi->s_csum_seed, (__u8 *)bh->b_data, sz); 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,8 +63,7 @@ int ext4_block_bitmap_csum_verify(struct super_block *sb, ext4_group_t group,
struct ext4_sb_info *sbi = EXT4_SB(sb); struct ext4_sb_info *sbi = EXT4_SB(sb);
int sz = EXT4_CLUSTERS_PER_GROUP(sb) / 8; int sz = EXT4_CLUSTERS_PER_GROUP(sb) / 8;
if (!EXT4_HAS_RO_COMPAT_FEATURE(sb, if (!ext4_has_metadata_csum(sb))
EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
return 1; return 1;
provided = le16_to_cpu(gdp->bg_block_bitmap_csum_lo); 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,8 +88,7 @@ void ext4_block_bitmap_csum_set(struct super_block *sb, ext4_group_t group,
__u32 csum; __u32 csum;
struct ext4_sb_info *sbi = EXT4_SB(sb); struct ext4_sb_info *sbi = EXT4_SB(sb);
if (!EXT4_HAS_RO_COMPAT_FEATURE(sb, if (!ext4_has_metadata_csum(sb))
EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
return; return;
csum = ext4_chksum(sbi, sbi->s_csum_seed, (__u8 *)bh->b_data, sz); csum = ext4_chksum(sbi, sbi->s_csum_seed, (__u8 *)bh->b_data, sz);
......
...@@ -2336,6 +2336,14 @@ static inline int ext4_has_group_desc_csum(struct super_block *sb) ...@@ -2336,6 +2336,14 @@ static inline int ext4_has_group_desc_csum(struct super_block *sb)
EXT4_FEATURE_RO_COMPAT_METADATA_CSUM); EXT4_FEATURE_RO_COMPAT_METADATA_CSUM);
} }
static inline int ext4_has_metadata_csum(struct super_block *sb)
{
WARN_ON_ONCE(EXT4_HAS_RO_COMPAT_FEATURE(sb,
EXT4_FEATURE_RO_COMPAT_METADATA_CSUM) &&
!EXT4_SB(sb)->s_chksum_driver);
return (EXT4_SB(sb)->s_chksum_driver != NULL);
}
static inline ext4_fsblk_t ext4_blocks_count(struct ext4_super_block *es) static inline ext4_fsblk_t ext4_blocks_count(struct ext4_super_block *es)
{ {
return ((ext4_fsblk_t)le32_to_cpu(es->s_blocks_count_hi) << 32) | return ((ext4_fsblk_t)le32_to_cpu(es->s_blocks_count_hi) << 32) |
......
...@@ -73,8 +73,7 @@ static int ext4_extent_block_csum_verify(struct inode *inode, ...@@ -73,8 +73,7 @@ static int ext4_extent_block_csum_verify(struct inode *inode,
{ {
struct ext4_extent_tail *et; struct ext4_extent_tail *et;
if (!EXT4_HAS_RO_COMPAT_FEATURE(inode->i_sb, if (!ext4_has_metadata_csum(inode->i_sb))
EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
return 1; return 1;
et = find_ext4_extent_tail(eh); et = find_ext4_extent_tail(eh);
...@@ -88,8 +87,7 @@ static void ext4_extent_block_csum_set(struct inode *inode, ...@@ -88,8 +87,7 @@ static void ext4_extent_block_csum_set(struct inode *inode,
{ {
struct ext4_extent_tail *et; struct ext4_extent_tail *et;
if (!EXT4_HAS_RO_COMPAT_FEATURE(inode->i_sb, if (!ext4_has_metadata_csum(inode->i_sb))
EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
return; return;
et = find_ext4_extent_tail(eh); et = find_ext4_extent_tail(eh);
......
...@@ -1011,8 +1011,7 @@ struct inode *__ext4_new_inode(handle_t *handle, struct inode *dir, ...@@ -1011,8 +1011,7 @@ struct inode *__ext4_new_inode(handle_t *handle, struct inode *dir,
spin_unlock(&sbi->s_next_gen_lock); spin_unlock(&sbi->s_next_gen_lock);
/* Precompute checksum seed for inode metadata */ /* Precompute checksum seed for inode metadata */
if (EXT4_HAS_RO_COMPAT_FEATURE(sb, if (ext4_has_metadata_csum(sb)) {
EXT4_FEATURE_RO_COMPAT_METADATA_CSUM)) {
__u32 csum; __u32 csum;
__le32 inum = cpu_to_le32(inode->i_ino); __le32 inum = cpu_to_le32(inode->i_ino);
__le32 gen = cpu_to_le32(inode->i_generation); __le32 gen = cpu_to_le32(inode->i_generation);
......
...@@ -1132,8 +1132,7 @@ static int ext4_finish_convert_inline_dir(handle_t *handle, ...@@ -1132,8 +1132,7 @@ static int ext4_finish_convert_inline_dir(handle_t *handle,
memcpy((void *)de, buf + EXT4_INLINE_DOTDOT_SIZE, memcpy((void *)de, buf + EXT4_INLINE_DOTDOT_SIZE,
inline_size - EXT4_INLINE_DOTDOT_SIZE); inline_size - EXT4_INLINE_DOTDOT_SIZE);
if (EXT4_HAS_RO_COMPAT_FEATURE(inode->i_sb, if (ext4_has_metadata_csum(inode->i_sb))
EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
csum_size = sizeof(struct ext4_dir_entry_tail); csum_size = sizeof(struct ext4_dir_entry_tail);
inode->i_size = inode->i_sb->s_blocksize; inode->i_size = inode->i_sb->s_blocksize;
......
...@@ -83,8 +83,7 @@ static int ext4_inode_csum_verify(struct inode *inode, struct ext4_inode *raw, ...@@ -83,8 +83,7 @@ static int ext4_inode_csum_verify(struct inode *inode, struct ext4_inode *raw,
if (EXT4_SB(inode->i_sb)->s_es->s_creator_os != if (EXT4_SB(inode->i_sb)->s_es->s_creator_os !=
cpu_to_le32(EXT4_OS_LINUX) || cpu_to_le32(EXT4_OS_LINUX) ||
!EXT4_HAS_RO_COMPAT_FEATURE(inode->i_sb, !ext4_has_metadata_csum(inode->i_sb))
EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
return 1; return 1;
provided = le16_to_cpu(raw->i_checksum_lo); 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,8 +104,7 @@ static void ext4_inode_csum_set(struct inode *inode, struct ext4_inode *raw,
if (EXT4_SB(inode->i_sb)->s_es->s_creator_os != if (EXT4_SB(inode->i_sb)->s_es->s_creator_os !=
cpu_to_le32(EXT4_OS_LINUX) || cpu_to_le32(EXT4_OS_LINUX) ||
!EXT4_HAS_RO_COMPAT_FEATURE(inode->i_sb, !ext4_has_metadata_csum(inode->i_sb))
EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
return; return;
csum = ext4_inode_csum(inode, raw, ei); csum = ext4_inode_csum(inode, raw, ei);
...@@ -4068,8 +4066,7 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino) ...@@ -4068,8 +4066,7 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino)
ei->i_extra_isize = 0; ei->i_extra_isize = 0;
/* Precompute checksum seed for inode metadata */ /* Precompute checksum seed for inode metadata */
if (EXT4_HAS_RO_COMPAT_FEATURE(sb, if (ext4_has_metadata_csum(sb)) {
EXT4_FEATURE_RO_COMPAT_METADATA_CSUM)) {
struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
__u32 csum; __u32 csum;
__le32 inum = cpu_to_le32(inode->i_ino); __le32 inum = cpu_to_le32(inode->i_ino);
......
...@@ -331,8 +331,7 @@ long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) ...@@ -331,8 +331,7 @@ long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
if (!inode_owner_or_capable(inode)) if (!inode_owner_or_capable(inode))
return -EPERM; return -EPERM;
if (EXT4_HAS_RO_COMPAT_FEATURE(inode->i_sb, if (ext4_has_metadata_csum(inode->i_sb)) {
EXT4_FEATURE_RO_COMPAT_METADATA_CSUM)) {
ext4_warning(sb, "Setting inode version is not " ext4_warning(sb, "Setting inode version is not "
"supported with metadata_csum enabled."); "supported with metadata_csum enabled.");
return -ENOTTY; return -ENOTTY;
......
...@@ -20,8 +20,7 @@ static __le32 ext4_mmp_csum(struct super_block *sb, struct mmp_struct *mmp) ...@@ -20,8 +20,7 @@ static __le32 ext4_mmp_csum(struct super_block *sb, struct mmp_struct *mmp)
static int ext4_mmp_csum_verify(struct super_block *sb, struct mmp_struct *mmp) static int ext4_mmp_csum_verify(struct super_block *sb, struct mmp_struct *mmp)
{ {
if (!EXT4_HAS_RO_COMPAT_FEATURE(sb, if (!ext4_has_metadata_csum(sb))
EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
return 1; return 1;
return mmp->mmp_checksum == ext4_mmp_csum(sb, mmp); 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,8 +28,7 @@ static int ext4_mmp_csum_verify(struct super_block *sb, struct mmp_struct *mmp)
static void ext4_mmp_csum_set(struct super_block *sb, struct mmp_struct *mmp) static void ext4_mmp_csum_set(struct super_block *sb, struct mmp_struct *mmp)
{ {
if (!EXT4_HAS_RO_COMPAT_FEATURE(sb, if (!ext4_has_metadata_csum(sb))
EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
return; return;
mmp->mmp_checksum = ext4_mmp_csum(sb, mmp); mmp->mmp_checksum = ext4_mmp_csum(sb, mmp);
......
...@@ -124,8 +124,7 @@ static struct buffer_head *__ext4_read_dirblock(struct inode *inode, ...@@ -124,8 +124,7 @@ static struct buffer_head *__ext4_read_dirblock(struct inode *inode,
"directory leaf block found instead of index block"); "directory leaf block found instead of index block");
return ERR_PTR(-EIO); return ERR_PTR(-EIO);
} }
if (!EXT4_HAS_RO_COMPAT_FEATURE(inode->i_sb, if (!ext4_has_metadata_csum(inode->i_sb) ||
EXT4_FEATURE_RO_COMPAT_METADATA_CSUM) ||
buffer_verified(bh)) buffer_verified(bh))
return bh; return bh;
...@@ -340,8 +339,7 @@ int ext4_dirent_csum_verify(struct inode *inode, struct ext4_dir_entry *dirent) ...@@ -340,8 +339,7 @@ int ext4_dirent_csum_verify(struct inode *inode, struct ext4_dir_entry *dirent)
{ {
struct ext4_dir_entry_tail *t; struct ext4_dir_entry_tail *t;
if (!EXT4_HAS_RO_COMPAT_FEATURE(inode->i_sb, if (!ext4_has_metadata_csum(inode->i_sb))
EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
return 1; return 1;
t = get_dirent_tail(inode, dirent); t = get_dirent_tail(inode, dirent);
...@@ -362,8 +360,7 @@ static void ext4_dirent_csum_set(struct inode *inode, ...@@ -362,8 +360,7 @@ static void ext4_dirent_csum_set(struct inode *inode,
{ {
struct ext4_dir_entry_tail *t; struct ext4_dir_entry_tail *t;
if (!EXT4_HAS_RO_COMPAT_FEATURE(inode->i_sb, if (!ext4_has_metadata_csum(inode->i_sb))
EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
return; return;
t = get_dirent_tail(inode, dirent); t = get_dirent_tail(inode, dirent);
...@@ -438,8 +435,7 @@ static int ext4_dx_csum_verify(struct inode *inode, ...@@ -438,8 +435,7 @@ static int ext4_dx_csum_verify(struct inode *inode,
struct dx_tail *t; struct dx_tail *t;
int count_offset, limit, count; int count_offset, limit, count;
if (!EXT4_HAS_RO_COMPAT_FEATURE(inode->i_sb, if (!ext4_has_metadata_csum(inode->i_sb))
EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
return 1; return 1;
c = get_dx_countlimit(inode, dirent, &count_offset); c = get_dx_countlimit(inode, dirent, &count_offset);
...@@ -468,8 +464,7 @@ static void ext4_dx_csum_set(struct inode *inode, struct ext4_dir_entry *dirent) ...@@ -468,8 +464,7 @@ static void ext4_dx_csum_set(struct inode *inode, struct ext4_dir_entry *dirent)
struct dx_tail *t; struct dx_tail *t;
int count_offset, limit, count; int count_offset, limit, count;
if (!EXT4_HAS_RO_COMPAT_FEATURE(inode->i_sb, if (!ext4_has_metadata_csum(inode->i_sb))
EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
return; return;
c = get_dx_countlimit(inode, dirent, &count_offset); c = get_dx_countlimit(inode, dirent, &count_offset);
...@@ -557,8 +552,7 @@ static inline unsigned dx_root_limit(struct inode *dir, unsigned infosize) ...@@ -557,8 +552,7 @@ static inline unsigned dx_root_limit(struct inode *dir, unsigned infosize)
unsigned entry_space = dir->i_sb->s_blocksize - EXT4_DIR_REC_LEN(1) - unsigned entry_space = dir->i_sb->s_blocksize - EXT4_DIR_REC_LEN(1) -
EXT4_DIR_REC_LEN(2) - infosize; EXT4_DIR_REC_LEN(2) - infosize;
if (EXT4_HAS_RO_COMPAT_FEATURE(dir->i_sb, if (ext4_has_metadata_csum(dir->i_sb))
EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
entry_space -= sizeof(struct dx_tail); entry_space -= sizeof(struct dx_tail);
return entry_space / sizeof(struct dx_entry); return entry_space / sizeof(struct dx_entry);
} }
...@@ -567,8 +561,7 @@ static inline unsigned dx_node_limit(struct inode *dir) ...@@ -567,8 +561,7 @@ static inline unsigned dx_node_limit(struct inode *dir)
{ {
unsigned entry_space = dir->i_sb->s_blocksize - EXT4_DIR_REC_LEN(0); unsigned entry_space = dir->i_sb->s_blocksize - EXT4_DIR_REC_LEN(0);
if (EXT4_HAS_RO_COMPAT_FEATURE(dir->i_sb, if (ext4_has_metadata_csum(dir->i_sb))
EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
entry_space -= sizeof(struct dx_tail); entry_space -= sizeof(struct dx_tail);
return entry_space / sizeof(struct dx_entry); return entry_space / sizeof(struct dx_entry);
} }
...@@ -1548,8 +1541,7 @@ static struct ext4_dir_entry_2 *do_split(handle_t *handle, struct inode *dir, ...@@ -1548,8 +1541,7 @@ static struct ext4_dir_entry_2 *do_split(handle_t *handle, struct inode *dir,
int csum_size = 0; int csum_size = 0;
int err = 0, i; int err = 0, i;
if (EXT4_HAS_RO_COMPAT_FEATURE(dir->i_sb, if (ext4_has_metadata_csum(dir->i_sb))
EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
csum_size = sizeof(struct ext4_dir_entry_tail); csum_size = sizeof(struct ext4_dir_entry_tail);
bh2 = ext4_append(handle, dir, &newblock); bh2 = ext4_append(handle, dir, &newblock);
...@@ -1718,8 +1710,7 @@ static int add_dirent_to_buf(handle_t *handle, struct dentry *dentry, ...@@ -1718,8 +1710,7 @@ static int add_dirent_to_buf(handle_t *handle, struct dentry *dentry,
int csum_size = 0; int csum_size = 0;
int err; int err;
if (EXT4_HAS_RO_COMPAT_FEATURE(inode->i_sb, if (ext4_has_metadata_csum(inode->i_sb))
EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
csum_size = sizeof(struct ext4_dir_entry_tail); csum_size = sizeof(struct ext4_dir_entry_tail);
if (!de) { if (!de) {
...@@ -1786,8 +1777,7 @@ static int make_indexed_dir(handle_t *handle, struct dentry *dentry, ...@@ -1786,8 +1777,7 @@ static int make_indexed_dir(handle_t *handle, struct dentry *dentry,
struct fake_dirent *fde; struct fake_dirent *fde;
int csum_size = 0; int csum_size = 0;
if (EXT4_HAS_RO_COMPAT_FEATURE(inode->i_sb, if (ext4_has_metadata_csum(inode->i_sb))
EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
csum_size = sizeof(struct ext4_dir_entry_tail); csum_size = sizeof(struct ext4_dir_entry_tail);
blocksize = dir->i_sb->s_blocksize; blocksize = dir->i_sb->s_blocksize;
...@@ -1904,8 +1894,7 @@ static int ext4_add_entry(handle_t *handle, struct dentry *dentry, ...@@ -1904,8 +1894,7 @@ static int ext4_add_entry(handle_t *handle, struct dentry *dentry,
ext4_lblk_t block, blocks; ext4_lblk_t block, blocks;
int csum_size = 0; int csum_size = 0;
if (EXT4_HAS_RO_COMPAT_FEATURE(inode->i_sb, if (ext4_has_metadata_csum(inode->i_sb))
EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
csum_size = sizeof(struct ext4_dir_entry_tail); csum_size = sizeof(struct ext4_dir_entry_tail);
sb = dir->i_sb; sb = dir->i_sb;
...@@ -2167,8 +2156,7 @@ static int ext4_delete_entry(handle_t *handle, ...@@ -2167,8 +2156,7 @@ static int ext4_delete_entry(handle_t *handle,
return err; return err;
} }
if (EXT4_HAS_RO_COMPAT_FEATURE(dir->i_sb, if (ext4_has_metadata_csum(dir->i_sb))
EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
csum_size = sizeof(struct ext4_dir_entry_tail); csum_size = sizeof(struct ext4_dir_entry_tail);
BUFFER_TRACE(bh, "get_write_access"); BUFFER_TRACE(bh, "get_write_access");
...@@ -2387,8 +2375,7 @@ static int ext4_init_new_dir(handle_t *handle, struct inode *dir, ...@@ -2387,8 +2375,7 @@ static int ext4_init_new_dir(handle_t *handle, struct inode *dir,
int csum_size = 0; int csum_size = 0;
int err; int err;
if (EXT4_HAS_RO_COMPAT_FEATURE(dir->i_sb, if (ext4_has_metadata_csum(dir->i_sb))
EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
csum_size = sizeof(struct ext4_dir_entry_tail); csum_size = sizeof(struct ext4_dir_entry_tail);
if (ext4_test_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA)) { if (ext4_test_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA)) {
......
...@@ -1212,8 +1212,7 @@ static int ext4_set_bitmap_checksums(struct super_block *sb, ...@@ -1212,8 +1212,7 @@ static int ext4_set_bitmap_checksums(struct super_block *sb,
{ {
struct buffer_head *bh; struct buffer_head *bh;
if (!EXT4_HAS_RO_COMPAT_FEATURE(sb, if (!ext4_has_metadata_csum(sb))
EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
return 0; return 0;
bh = ext4_get_bitmap(sb, group_data->inode_bitmap); bh = ext4_get_bitmap(sb, group_data->inode_bitmap);
......
...@@ -141,8 +141,7 @@ static __le32 ext4_superblock_csum(struct super_block *sb, ...@@ -141,8 +141,7 @@ static __le32 ext4_superblock_csum(struct super_block *sb,
static int ext4_superblock_csum_verify(struct super_block *sb, static int ext4_superblock_csum_verify(struct super_block *sb,
struct ext4_super_block *es) struct ext4_super_block *es)
{ {
if (!EXT4_HAS_RO_COMPAT_FEATURE(sb, if (!ext4_has_metadata_csum(sb))
EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
return 1; return 1;
return es->s_checksum == ext4_superblock_csum(sb, es); return es->s_checksum == ext4_superblock_csum(sb, es);
...@@ -152,8 +151,7 @@ void ext4_superblock_csum_set(struct super_block *sb) ...@@ -152,8 +151,7 @@ void ext4_superblock_csum_set(struct super_block *sb)
{ {
struct ext4_super_block *es = EXT4_SB(sb)->s_es; struct ext4_super_block *es = EXT4_SB(sb)->s_es;
if (!EXT4_HAS_RO_COMPAT_FEATURE(sb, if (!ext4_has_metadata_csum(sb))
EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
return; return;
es->s_checksum = ext4_superblock_csum(sb, es); es->s_checksum = ext4_superblock_csum(sb, es);
...@@ -2009,8 +2007,7 @@ static __le16 ext4_group_desc_csum(struct ext4_sb_info *sbi, __u32 block_group, ...@@ -2009,8 +2007,7 @@ static __le16 ext4_group_desc_csum(struct ext4_sb_info *sbi, __u32 block_group,
__u16 crc = 0; __u16 crc = 0;
__le32 le_group = cpu_to_le32(block_group); __le32 le_group = cpu_to_le32(block_group);
if ((sbi->s_es->s_feature_ro_compat & if (ext4_has_metadata_csum(sbi->s_sb)) {
cpu_to_le32(EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))) {
/* Use new metadata_csum algorithm */ /* Use new metadata_csum algorithm */
__le16 save_csum; __le16 save_csum;
__u32 csum32; __u32 csum32;
...@@ -3176,8 +3173,7 @@ static int set_journal_csum_feature_set(struct super_block *sb) ...@@ -3176,8 +3173,7 @@ static int set_journal_csum_feature_set(struct super_block *sb)
int compat, incompat; int compat, incompat;
struct ext4_sb_info *sbi = EXT4_SB(sb); struct ext4_sb_info *sbi = EXT4_SB(sb);
if (EXT4_HAS_RO_COMPAT_FEATURE(sb, if (ext4_has_metadata_csum(sb)) {
EXT4_FEATURE_RO_COMPAT_METADATA_CSUM)) {
/* journal checksum v3 */ /* journal checksum v3 */
compat = 0; compat = 0;
incompat = JBD2_FEATURE_INCOMPAT_CSUM_V3; incompat = JBD2_FEATURE_INCOMPAT_CSUM_V3;
...@@ -3484,8 +3480,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) ...@@ -3484,8 +3480,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
} }
/* Precompute checksum seed for all metadata */ /* Precompute checksum seed for all metadata */
if (EXT4_HAS_RO_COMPAT_FEATURE(sb, if (ext4_has_metadata_csum(sb))
EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
sbi->s_csum_seed = ext4_chksum(sbi, ~0, es->s_uuid, sbi->s_csum_seed = ext4_chksum(sbi, ~0, es->s_uuid,
sizeof(es->s_uuid)); sizeof(es->s_uuid));
......
...@@ -142,8 +142,7 @@ static int ext4_xattr_block_csum_verify(struct inode *inode, ...@@ -142,8 +142,7 @@ static int ext4_xattr_block_csum_verify(struct inode *inode,
sector_t block_nr, sector_t block_nr,
struct ext4_xattr_header *hdr) struct ext4_xattr_header *hdr)
{ {
if (EXT4_HAS_RO_COMPAT_FEATURE(inode->i_sb, if (ext4_has_metadata_csum(inode->i_sb) &&
EXT4_FEATURE_RO_COMPAT_METADATA_CSUM) &&
(hdr->h_checksum != ext4_xattr_block_csum(inode, block_nr, hdr))) (hdr->h_checksum != ext4_xattr_block_csum(inode, block_nr, hdr)))
return 0; return 0;
return 1; return 1;
...@@ -153,8 +152,7 @@ static void ext4_xattr_block_csum_set(struct inode *inode, ...@@ -153,8 +152,7 @@ static void ext4_xattr_block_csum_set(struct inode *inode,
sector_t block_nr, sector_t block_nr,
struct ext4_xattr_header *hdr) struct ext4_xattr_header *hdr)
{ {
if (!EXT4_HAS_RO_COMPAT_FEATURE(inode->i_sb, if (!ext4_has_metadata_csum(inode->i_sb))
EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
return; return;
hdr->h_checksum = ext4_xattr_block_csum(inode, block_nr, hdr); hdr->h_checksum = ext4_xattr_block_csum(inode, block_nr, hdr);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment