1 ext4: don't update checksum of new initialized bitmaps
3 When reading the inode or block allocation bitmap, if the bitmap needs
4 to be initialized, do not update the checksum in the block group
5 descriptor. That's because we're not set up to journal those changes.
6 Instead, just set the verified bit on the bitmap block, so that it's
7 not necessary to validate the checksum.
9 When a block or inode allocation actually happens, at that point the
10 checksum will be calculated, and update of the bg descriptor block
11 will be properly journalled.
13 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
14 Cc: stable@vger.kernel.org
16 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
17 index f9b3e0a83526..f82c4966f4ce 100644
18 --- a/fs/ext4/balloc.c
19 +++ b/fs/ext4/balloc.c
20 @@ -243,8 +243,6 @@ static int ext4_init_block_bitmap(struct super_block *sb,
22 ext4_mark_bitmap_end(num_clusters_in_group(sb, block_group),
23 sb->s_blocksize * 8, bh->b_data);
24 - ext4_block_bitmap_csum_set(sb, block_group, gdp, bh);
25 - ext4_group_desc_csum_set(sb, block_group, gdp);
29 @@ -448,6 +446,7 @@ ext4_read_block_bitmap_nowait(struct super_block *sb, ext4_group_t block_group)
30 err = ext4_init_block_bitmap(sb, bh, block_group, desc);
31 set_bitmap_uptodate(bh);
32 set_buffer_uptodate(bh);
33 + set_buffer_verified(bh);
34 ext4_unlock_group(sb, block_group);
37 diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c
38 index 7830d28df331..3fa93665b4a3 100644
39 --- a/fs/ext4/ialloc.c
40 +++ b/fs/ext4/ialloc.c
41 @@ -66,44 +66,6 @@ void ext4_mark_bitmap_end(int start_bit, int end_bit, char *bitmap)
42 memset(bitmap + (i >> 3), 0xff, (end_bit - i) >> 3);
45 -/* Initializes an uninitialized inode bitmap */
46 -static int ext4_init_inode_bitmap(struct super_block *sb,
47 - struct buffer_head *bh,
48 - ext4_group_t block_group,
49 - struct ext4_group_desc *gdp)
51 - struct ext4_group_info *grp;
52 - struct ext4_sb_info *sbi = EXT4_SB(sb);
53 - J_ASSERT_BH(bh, buffer_locked(bh));
55 - /* If checksum is bad mark all blocks and inodes use to prevent
56 - * allocation, essentially implementing a per-group read-only flag. */
57 - if (!ext4_group_desc_csum_verify(sb, block_group, gdp)) {
58 - grp = ext4_get_group_info(sb, block_group);
59 - if (!EXT4_MB_GRP_BBITMAP_CORRUPT(grp))
60 - percpu_counter_sub(&sbi->s_freeclusters_counter,
62 - set_bit(EXT4_GROUP_INFO_BBITMAP_CORRUPT_BIT, &grp->bb_state);
63 - if (!EXT4_MB_GRP_IBITMAP_CORRUPT(grp)) {
65 - count = ext4_free_inodes_count(sb, gdp);
66 - percpu_counter_sub(&sbi->s_freeinodes_counter,
69 - set_bit(EXT4_GROUP_INFO_IBITMAP_CORRUPT_BIT, &grp->bb_state);
73 - memset(bh->b_data, 0, (EXT4_INODES_PER_GROUP(sb) + 7) / 8);
74 - ext4_mark_bitmap_end(EXT4_INODES_PER_GROUP(sb), sb->s_blocksize * 8,
76 - ext4_inode_bitmap_csum_set(sb, block_group, gdp, bh,
77 - EXT4_INODES_PER_GROUP(sb) / 8);
78 - ext4_group_desc_csum_set(sb, block_group, gdp);
83 void ext4_end_bitmap_read(struct buffer_head *bh, int uptodate)
86 @@ -187,17 +149,14 @@ ext4_read_inode_bitmap(struct super_block *sb, ext4_group_t block_group)
88 ext4_lock_group(sb, block_group);
89 if (desc->bg_flags & cpu_to_le16(EXT4_BG_INODE_UNINIT)) {
90 - err = ext4_init_inode_bitmap(sb, bh, block_group, desc);
91 + memset(bh->b_data, 0, (EXT4_INODES_PER_GROUP(sb) + 7) / 8);
92 + ext4_mark_bitmap_end(EXT4_INODES_PER_GROUP(sb),
93 + sb->s_blocksize * 8, bh->b_data);
94 set_bitmap_uptodate(bh);
95 set_buffer_uptodate(bh);
96 set_buffer_verified(bh);
97 ext4_unlock_group(sb, block_group);
100 - ext4_error(sb, "Failed to init inode bitmap for group "
101 - "%u: %d", block_group, err);
106 ext4_unlock_group(sb, block_group);