Skip to content

Commit 61c219f

Browse files
committed
ext4: fix unjournalled bg descriptor while initializing inode bitmap
The first time that we allocate from an uninitialized inode allocation bitmap, if the block allocation bitmap is also uninitalized, we need to get write access to the block group descriptor before we start modifying the block group descriptor flags and updating the free block count, etc. Otherwise, there is the potential of a bad journal checksum (if journal checksums are enabled), and of the file system becoming inconsistent if we crash at exactly the wrong time. Signed-off-by: Theodore Ts'o <tytso@mit.edu> Cc: stable@vger.kernel.org
1 parent 16874b2 commit 61c219f

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

‎fs/ext4/ialloc.c‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,13 @@ struct inode *__ext4_new_inode(handle_t *handle, struct inode *dir,
874874
goto out;
875875
}
876876

877+
BUFFER_TRACE(group_desc_bh, "get_write_access");
878+
err = ext4_journal_get_write_access(handle, group_desc_bh);
879+
if (err) {
880+
ext4_std_error(sb, err);
881+
goto out;
882+
}
883+
877884
/* We may have to initialize the block bitmap if it isn't already */
878885
if (ext4_has_group_desc_csum(sb) &&
879886
gdp->bg_flags & cpu_to_le16(EXT4_BG_BLOCK_UNINIT)) {
@@ -910,13 +917,6 @@ struct inode *__ext4_new_inode(handle_t *handle, struct inode *dir,
910917
}
911918
}
912919

913-
BUFFER_TRACE(group_desc_bh, "get_write_access");
914-
err = ext4_journal_get_write_access(handle, group_desc_bh);
915-
if (err) {
916-
ext4_std_error(sb, err);
917-
goto out;
918-
}
919-
920920
/* Update the relevant bg descriptor fields */
921921
if (ext4_has_group_desc_csum(sb)) {
922922
int free;

0 commit comments

Comments
 (0)