ext4: move checksum length calculation of inode bitmap into ext4_inode_bitmap_csum_...
authorKemeng Shi <shikemeng@huaweicloud.com>
Tue, 20 Aug 2024 13:22:32 +0000 (21:22 +0800)
committerTheodore Ts'o <tytso@mit.edu>
Wed, 4 Sep 2024 02:12:15 +0000 (22:12 -0400)
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>
fs/ext4/bitmap.c
fs/ext4/ext4.h
fs/ext4/ialloc.c
fs/ext4/resize.c

index cd725bebe69ee3285c2c97c343bb914eaf86a172..2a135075468d359bd148bfa9d73ab392c41794e0 100644 (file)
@@ -18,15 +18,17 @@ unsigned int ext4_count_free(char *bitmap, unsigned int numchars)
 
 int ext4_inode_bitmap_csum_verify(struct super_block *sb,
                                  struct ext4_group_desc *gdp,
-                                 struct buffer_head *bh, int sz)
+                                 struct buffer_head *bh)
 {
        __u32 hi;
        __u32 provided, calculated;
        struct ext4_sb_info *sbi = EXT4_SB(sb);
+       int sz;
 
        if (!ext4_has_metadata_csum(sb))
                return 1;
 
+       sz = EXT4_INODES_PER_GROUP(sb) >> 3;
        provided = le16_to_cpu(gdp->bg_inode_bitmap_csum_lo);
        calculated = ext4_chksum(sbi, sbi->s_csum_seed, (__u8 *)bh->b_data, sz);
        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,
 
 void ext4_inode_bitmap_csum_set(struct super_block *sb,
                                struct ext4_group_desc *gdp,
-                               struct buffer_head *bh, int sz)
+                               struct buffer_head *bh)
 {
        __u32 csum;
        struct ext4_sb_info *sbi = EXT4_SB(sb);
+       int sz;
 
        if (!ext4_has_metadata_csum(sb))
                return;
 
+       sz = EXT4_INODES_PER_GROUP(sb) >> 3;
        csum = ext4_chksum(sbi, sbi->s_csum_seed, (__u8 *)bh->b_data, sz);
        gdp->bg_inode_bitmap_csum_lo = cpu_to_le16(csum & 0xFFFF);
        if (sbi->s_desc_size >= EXT4_BG_INODE_BITMAP_CSUM_HI_END)
index 5845e4aa091ac0103e3319d6833da222d467284d..7c3438b431e4b9edcb9fe7dcfcba69e131c28727 100644 (file)
@@ -2693,10 +2693,10 @@ struct mmpd_data {
 extern unsigned int ext4_count_free(char *bitmap, unsigned numchars);
 void ext4_inode_bitmap_csum_set(struct super_block *sb,
                                struct ext4_group_desc *gdp,
-                               struct buffer_head *bh, int sz);
+                               struct buffer_head *bh);
 int ext4_inode_bitmap_csum_verify(struct super_block *sb,
                                  struct ext4_group_desc *gdp,
-                                 struct buffer_head *bh, int sz);
+                                 struct buffer_head *bh);
 void ext4_block_bitmap_csum_set(struct super_block *sb,
                                struct ext4_group_desc *gdp,
                                struct buffer_head *bh);
index 8ee4754c70f56830d0631a2a584fc38f6d67f404..0234f5e91d8d8ccb4385278f101c36fb91801f49 100644 (file)
@@ -98,8 +98,7 @@ static int ext4_validate_inode_bitmap(struct super_block *sb,
        if (buffer_verified(bh))
                goto verified;
        blk = ext4_inode_bitmap(sb, desc);
-       if (!ext4_inode_bitmap_csum_verify(sb, desc, bh,
-                                          EXT4_INODES_PER_GROUP(sb) / 8) ||
+       if (!ext4_inode_bitmap_csum_verify(sb, desc, bh) ||
            ext4_simulate_fail(sb, EXT4_SIM_IBITMAP_CRC)) {
                ext4_unlock_group(sb, block_group);
                ext4_error(sb, "Corrupt inode bitmap - block_group = %u, "
@@ -327,8 +326,7 @@ void ext4_free_inode(handle_t *handle, struct inode *inode)
                if (percpu_counter_initialized(&sbi->s_dirs_counter))
                        percpu_counter_dec(&sbi->s_dirs_counter);
        }
-       ext4_inode_bitmap_csum_set(sb, gdp, bitmap_bh,
-                                  EXT4_INODES_PER_GROUP(sb) / 8);
+       ext4_inode_bitmap_csum_set(sb, gdp, bitmap_bh);
        ext4_group_desc_csum_set(sb, block_group, gdp);
        ext4_unlock_group(sb, block_group);
 
@@ -853,8 +851,7 @@ int ext4_mark_inode_used(struct super_block *sb, int ino)
 
        ext4_free_inodes_set(sb, gdp, ext4_free_inodes_count(sb, gdp) - 1);
        if (ext4_has_group_desc_csum(sb)) {
-               ext4_inode_bitmap_csum_set(sb, gdp, inode_bitmap_bh,
-                                          EXT4_INODES_PER_GROUP(sb) / 8);
+               ext4_inode_bitmap_csum_set(sb, gdp, inode_bitmap_bh);
                ext4_group_desc_csum_set(sb, group, gdp);
        }
 
@@ -1225,8 +1222,7 @@ got:
                }
        }
        if (ext4_has_group_desc_csum(sb)) {
-               ext4_inode_bitmap_csum_set(sb, gdp, inode_bitmap_bh,
-                                          EXT4_INODES_PER_GROUP(sb) / 8);
+               ext4_inode_bitmap_csum_set(sb, gdp, inode_bitmap_bh);
                ext4_group_desc_csum_set(sb, group, gdp);
        }
        ext4_unlock_group(sb, group);
index 0ba9837d65cac90d74e6b2ce23050c4cae165953..e04eb08b90601e935f7337a6e482f7bea90634b9 100644 (file)
@@ -1319,8 +1319,7 @@ static int ext4_set_bitmap_checksums(struct super_block *sb,
        bh = ext4_get_bitmap(sb, group_data->inode_bitmap);
        if (!bh)
                return -EIO;
-       ext4_inode_bitmap_csum_set(sb, gdp, bh,
-                                  EXT4_INODES_PER_GROUP(sb) / 8);
+       ext4_inode_bitmap_csum_set(sb, gdp, bh);
        brelse(bh);
 
        bh = ext4_get_bitmap(sb, group_data->block_bitmap);