Skip to content

Commit

Permalink
ext4: fix unjournalled bg descriptor while initializing inode bitmap
Browse files Browse the repository at this point in the history
commit 61c219f upstream.

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 <[email protected]>
Signed-off-by: Jiri Slaby <[email protected]>
  • Loading branch information
tytso authored and Jiri Slaby committed Jul 18, 2014
1 parent 07c0719 commit 95f670b
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions fs/ext4/ialloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,13 @@ struct inode *__ext4_new_inode(handle_t *handle, struct inode *dir,
goto out;
}

BUFFER_TRACE(group_desc_bh, "get_write_access");
err = ext4_journal_get_write_access(handle, group_desc_bh);
if (err) {
ext4_std_error(sb, err);
goto out;
}

/* We may have to initialize the block bitmap if it isn't already */
if (ext4_has_group_desc_csum(sb) &&
gdp->bg_flags & cpu_to_le16(EXT4_BG_BLOCK_UNINIT)) {
Expand Down Expand Up @@ -887,13 +894,6 @@ struct inode *__ext4_new_inode(handle_t *handle, struct inode *dir,
}
}

BUFFER_TRACE(group_desc_bh, "get_write_access");
err = ext4_journal_get_write_access(handle, group_desc_bh);
if (err) {
ext4_std_error(sb, err);
goto out;
}

/* Update the relevant bg descriptor fields */
if (ext4_has_group_desc_csum(sb)) {
int free;
Expand Down

0 comments on commit 95f670b

Please sign in to comment.