@@ -110,3 +110,27 @@ void ext4_block_bitmap_csum_set(struct super_block *sb,
csum = ext4_chksum(sbi->s_csum_seed, (__u8 *)bh->b_data, sz);
ext4_block_bitmap_csum_store(sb, gdp, csum);
}
+
+/*
+ * Update block bitmap checksum using incremental CRC calculation.
+ *
+ * This function assumes that ALL bits in the range [offset, offset+len)
+ * have been flipped (XORed with 1). It uses crc32c_flip_range() to
+ * efficiently compute the CRC delta without re-scanning the entire bitmap.
+ * The csum_seed cancels out in the XOR delta, so it is not needed here.
+ */
+void ext4_block_bitmap_csum_set_range(struct super_block *sb,
+ struct ext4_group_desc *gdp,
+ ext4_grpblk_t offset, ext4_grpblk_t len)
+{
+ __u32 new_csum, old_csum;
+
+ if (!ext4_has_feature_metadata_csum(sb))
+ return;
+
+ old_csum = ext4_block_bitmap_csum_get(sb, gdp);
+ new_csum = crc32c_flip_range(old_csum, EXT4_CLUSTERS_PER_GROUP(sb),
+ offset, len);
+
+ ext4_block_bitmap_csum_store(sb, gdp, new_csum);
+}
@@ -2770,6 +2770,9 @@ int ext4_inode_bitmap_csum_verify(struct super_block *sb,
void ext4_block_bitmap_csum_set(struct super_block *sb,
struct ext4_group_desc *gdp,
struct buffer_head *bh);
+void ext4_block_bitmap_csum_set_range(struct super_block *sb,
+ struct ext4_group_desc *gdp,
+ ext4_grpblk_t offset, ext4_grpblk_t len);
int ext4_block_bitmap_csum_verify(struct super_block *sb,
struct ext4_group_desc *gdp,
struct buffer_head *bh);
Add a helper function ext4_block_bitmap_csum_set_range() that updates the block bitmap checksum using crc32c_flip_range() for incremental CRC calculation. Unlike ext4_block_bitmap_csum_set() which re-scans the entire bitmap buffer, this function efficiently computes the CRC delta for a range of flipped bits, avoiding the cost of a full CRC recalculation. Signed-off-by: Baokun Li <libaokun@linux.alibaba.com> --- fs/ext4/bitmap.c | 24 ++++++++++++++++++++++++ fs/ext4/ext4.h | 3 +++ 2 files changed, 27 insertions(+)