Skip to content

Commit 66eafbd

Browse files
Kemeng Shitytso
authored andcommitted
ext4: move checksum length calculation of inode bitmap into ext4_inode_bitmap_csum_[verify/set]() functions
There are some little improve: 1. remove repeat code to calculate checksum length of inode bitmap 2. remove unnecessary checksum length calculation if checksum is not enabled. 3. use more efficient bit shift operation instead of div opreation. Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com> Link: https://patch.msgid.link/20240820132234.2759926-6-shikemeng@huaweicloud.com Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent f7c69be commit 66eafbd

File tree

4 files changed

+13
-14
lines changed

4 files changed

+13
-14
lines changed

fs/ext4/bitmap.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,17 @@ unsigned int ext4_count_free(char *bitmap, unsigned int numchars)
1818

1919
int ext4_inode_bitmap_csum_verify(struct super_block *sb,
2020
struct ext4_group_desc *gdp,
21-
struct buffer_head *bh, int sz)
21+
struct buffer_head *bh)
2222
{
2323
__u32 hi;
2424
__u32 provided, calculated;
2525
struct ext4_sb_info *sbi = EXT4_SB(sb);
26+
int sz;
2627

2728
if (!ext4_has_metadata_csum(sb))
2829
return 1;
2930

31+
sz = EXT4_INODES_PER_GROUP(sb) >> 3;
3032
provided = le16_to_cpu(gdp->bg_inode_bitmap_csum_lo);
3133
calculated = ext4_chksum(sbi, sbi->s_csum_seed, (__u8 *)bh->b_data, sz);
3234
if (sbi->s_desc_size >= EXT4_BG_INODE_BITMAP_CSUM_HI_END) {
@@ -40,14 +42,16 @@ int ext4_inode_bitmap_csum_verify(struct super_block *sb,
4042

4143
void ext4_inode_bitmap_csum_set(struct super_block *sb,
4244
struct ext4_group_desc *gdp,
43-
struct buffer_head *bh, int sz)
45+
struct buffer_head *bh)
4446
{
4547
__u32 csum;
4648
struct ext4_sb_info *sbi = EXT4_SB(sb);
49+
int sz;
4750

4851
if (!ext4_has_metadata_csum(sb))
4952
return;
5053

54+
sz = EXT4_INODES_PER_GROUP(sb) >> 3;
5155
csum = ext4_chksum(sbi, sbi->s_csum_seed, (__u8 *)bh->b_data, sz);
5256
gdp->bg_inode_bitmap_csum_lo = cpu_to_le16(csum & 0xFFFF);
5357
if (sbi->s_desc_size >= EXT4_BG_INODE_BITMAP_CSUM_HI_END)

fs/ext4/ext4.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2693,10 +2693,10 @@ struct mmpd_data {
26932693
extern unsigned int ext4_count_free(char *bitmap, unsigned numchars);
26942694
void ext4_inode_bitmap_csum_set(struct super_block *sb,
26952695
struct ext4_group_desc *gdp,
2696-
struct buffer_head *bh, int sz);
2696+
struct buffer_head *bh);
26972697
int ext4_inode_bitmap_csum_verify(struct super_block *sb,
26982698
struct ext4_group_desc *gdp,
2699-
struct buffer_head *bh, int sz);
2699+
struct buffer_head *bh);
27002700
void ext4_block_bitmap_csum_set(struct super_block *sb,
27012701
struct ext4_group_desc *gdp,
27022702
struct buffer_head *bh);

fs/ext4/ialloc.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ static int ext4_validate_inode_bitmap(struct super_block *sb,
9898
if (buffer_verified(bh))
9999
goto verified;
100100
blk = ext4_inode_bitmap(sb, desc);
101-
if (!ext4_inode_bitmap_csum_verify(sb, desc, bh,
102-
EXT4_INODES_PER_GROUP(sb) / 8) ||
101+
if (!ext4_inode_bitmap_csum_verify(sb, desc, bh) ||
103102
ext4_simulate_fail(sb, EXT4_SIM_IBITMAP_CRC)) {
104103
ext4_unlock_group(sb, block_group);
105104
ext4_error(sb, "Corrupt inode bitmap - block_group = %u, "
@@ -327,8 +326,7 @@ void ext4_free_inode(handle_t *handle, struct inode *inode)
327326
if (percpu_counter_initialized(&sbi->s_dirs_counter))
328327
percpu_counter_dec(&sbi->s_dirs_counter);
329328
}
330-
ext4_inode_bitmap_csum_set(sb, gdp, bitmap_bh,
331-
EXT4_INODES_PER_GROUP(sb) / 8);
329+
ext4_inode_bitmap_csum_set(sb, gdp, bitmap_bh);
332330
ext4_group_desc_csum_set(sb, block_group, gdp);
333331
ext4_unlock_group(sb, block_group);
334332

@@ -853,8 +851,7 @@ int ext4_mark_inode_used(struct super_block *sb, int ino)
853851

854852
ext4_free_inodes_set(sb, gdp, ext4_free_inodes_count(sb, gdp) - 1);
855853
if (ext4_has_group_desc_csum(sb)) {
856-
ext4_inode_bitmap_csum_set(sb, gdp, inode_bitmap_bh,
857-
EXT4_INODES_PER_GROUP(sb) / 8);
854+
ext4_inode_bitmap_csum_set(sb, gdp, inode_bitmap_bh);
858855
ext4_group_desc_csum_set(sb, group, gdp);
859856
}
860857

@@ -1225,8 +1222,7 @@ struct inode *__ext4_new_inode(struct mnt_idmap *idmap,
12251222
}
12261223
}
12271224
if (ext4_has_group_desc_csum(sb)) {
1228-
ext4_inode_bitmap_csum_set(sb, gdp, inode_bitmap_bh,
1229-
EXT4_INODES_PER_GROUP(sb) / 8);
1225+
ext4_inode_bitmap_csum_set(sb, gdp, inode_bitmap_bh);
12301226
ext4_group_desc_csum_set(sb, group, gdp);
12311227
}
12321228
ext4_unlock_group(sb, group);

fs/ext4/resize.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,8 +1319,7 @@ static int ext4_set_bitmap_checksums(struct super_block *sb,
13191319
bh = ext4_get_bitmap(sb, group_data->inode_bitmap);
13201320
if (!bh)
13211321
return -EIO;
1322-
ext4_inode_bitmap_csum_set(sb, gdp, bh,
1323-
EXT4_INODES_PER_GROUP(sb) / 8);
1322+
ext4_inode_bitmap_csum_set(sb, gdp, bh);
13241323
brelse(bh);
13251324

13261325
bh = ext4_get_bitmap(sb, group_data->block_bitmap);

0 commit comments

Comments
 (0)