Skip to content

Commit 044e6e3

Browse files
committed
ext4: don't update checksum of new initialized bitmaps
When reading the inode or block allocation bitmap, if the bitmap needs to be initialized, do not update the checksum in the block group descriptor. That's because we're not set up to journal those changes. Instead, just set the verified bit on the bitmap block, so that it's not necessary to validate the checksum. When a block or inode allocation actually happens, at that point the checksum will be calculated, and update of the bg descriptor block will be properly journalled. Signed-off-by: Theodore Ts'o <tytso@mit.edu> Cc: stable@vger.kernel.org
1 parent 85e0c4e commit 044e6e3

File tree

2 files changed

+4
-46
lines changed

2 files changed

+4
-46
lines changed

fs/ext4/balloc.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,6 @@ static int ext4_init_block_bitmap(struct super_block *sb,
243243
*/
244244
ext4_mark_bitmap_end(num_clusters_in_group(sb, block_group),
245245
sb->s_blocksize * 8, bh->b_data);
246-
ext4_block_bitmap_csum_set(sb, block_group, gdp, bh);
247-
ext4_group_desc_csum_set(sb, block_group, gdp);
248246
return 0;
249247
}
250248

@@ -448,6 +446,7 @@ ext4_read_block_bitmap_nowait(struct super_block *sb, ext4_group_t block_group)
448446
err = ext4_init_block_bitmap(sb, bh, block_group, desc);
449447
set_bitmap_uptodate(bh);
450448
set_buffer_uptodate(bh);
449+
set_buffer_verified(bh);
451450
ext4_unlock_group(sb, block_group);
452451
unlock_buffer(bh);
453452
if (err) {

fs/ext4/ialloc.c

Lines changed: 3 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -66,44 +66,6 @@ void ext4_mark_bitmap_end(int start_bit, int end_bit, char *bitmap)
6666
memset(bitmap + (i >> 3), 0xff, (end_bit - i) >> 3);
6767
}
6868

69-
/* Initializes an uninitialized inode bitmap */
70-
static int ext4_init_inode_bitmap(struct super_block *sb,
71-
struct buffer_head *bh,
72-
ext4_group_t block_group,
73-
struct ext4_group_desc *gdp)
74-
{
75-
struct ext4_group_info *grp;
76-
struct ext4_sb_info *sbi = EXT4_SB(sb);
77-
J_ASSERT_BH(bh, buffer_locked(bh));
78-
79-
/* If checksum is bad mark all blocks and inodes use to prevent
80-
* allocation, essentially implementing a per-group read-only flag. */
81-
if (!ext4_group_desc_csum_verify(sb, block_group, gdp)) {
82-
grp = ext4_get_group_info(sb, block_group);
83-
if (!EXT4_MB_GRP_BBITMAP_CORRUPT(grp))
84-
percpu_counter_sub(&sbi->s_freeclusters_counter,
85-
grp->bb_free);
86-
set_bit(EXT4_GROUP_INFO_BBITMAP_CORRUPT_BIT, &grp->bb_state);
87-
if (!EXT4_MB_GRP_IBITMAP_CORRUPT(grp)) {
88-
int count;
89-
count = ext4_free_inodes_count(sb, gdp);
90-
percpu_counter_sub(&sbi->s_freeinodes_counter,
91-
count);
92-
}
93-
set_bit(EXT4_GROUP_INFO_IBITMAP_CORRUPT_BIT, &grp->bb_state);
94-
return -EFSBADCRC;
95-
}
96-
97-
memset(bh->b_data, 0, (EXT4_INODES_PER_GROUP(sb) + 7) / 8);
98-
ext4_mark_bitmap_end(EXT4_INODES_PER_GROUP(sb), sb->s_blocksize * 8,
99-
bh->b_data);
100-
ext4_inode_bitmap_csum_set(sb, block_group, gdp, bh,
101-
EXT4_INODES_PER_GROUP(sb) / 8);
102-
ext4_group_desc_csum_set(sb, block_group, gdp);
103-
104-
return 0;
105-
}
106-
10769
void ext4_end_bitmap_read(struct buffer_head *bh, int uptodate)
10870
{
10971
if (uptodate) {
@@ -187,17 +149,14 @@ ext4_read_inode_bitmap(struct super_block *sb, ext4_group_t block_group)
187149

188150
ext4_lock_group(sb, block_group);
189151
if (desc->bg_flags & cpu_to_le16(EXT4_BG_INODE_UNINIT)) {
190-
err = ext4_init_inode_bitmap(sb, bh, block_group, desc);
152+
memset(bh->b_data, 0, (EXT4_INODES_PER_GROUP(sb) + 7) / 8);
153+
ext4_mark_bitmap_end(EXT4_INODES_PER_GROUP(sb),
154+
sb->s_blocksize * 8, bh->b_data);
191155
set_bitmap_uptodate(bh);
192156
set_buffer_uptodate(bh);
193157
set_buffer_verified(bh);
194158
ext4_unlock_group(sb, block_group);
195159
unlock_buffer(bh);
196-
if (err) {
197-
ext4_error(sb, "Failed to init inode bitmap for group "
198-
"%u: %d", block_group, err);
199-
goto out;
200-
}
201160
return bh;
202161
}
203162
ext4_unlock_group(sb, block_group);

0 commit comments

Comments
 (0)