add patch disable-synchronous-transaction-batching-if-max_batch_time-is-zero
[ext4-patch-queue.git] / fix-unjournaled-bg-descriptor-while-initializing-inode-bitmap
blobebda317f3cd15304eb4ef52c56b5699f3fe3b0f5
1 ext4: fix unjournalled bg descriptor while initializing inode bitmap
3 The first time that we allocate from an uninitialized inode allocation
4 bitmap, if the block allocation bitmap is also uninitalized, we need
5 to get write access to the block group descriptor before we start
6 modifying the block group descriptor flags and updating the free block
7 count, etc.  Otherwise, there is the potential of a bad journal
8 checksum (if journal checksums are enabled), and of the file system
9 becoming inconsistent if we crash at exactly the wrong time.
11 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
12 Cc: stable@vger.kernel.org
13 ---
14  fs/ext4/ialloc.c | 14 +++++++-------
15  1 file changed, 7 insertions(+), 7 deletions(-)
17 diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c
18 index a87455d..0840bf3 100644
19 --- a/fs/ext4/ialloc.c
20 +++ b/fs/ext4/ialloc.c
21 @@ -874,6 +874,13 @@ got:
22                 goto out;
23         }
25 +       BUFFER_TRACE(group_desc_bh, "get_write_access");
26 +       err = ext4_journal_get_write_access(handle, group_desc_bh);
27 +       if (err) {
28 +               ext4_std_error(sb, err);
29 +               goto out;
30 +       }
32         /* We may have to initialize the block bitmap if it isn't already */
33         if (ext4_has_group_desc_csum(sb) &&
34             gdp->bg_flags & cpu_to_le16(EXT4_BG_BLOCK_UNINIT)) {
35 @@ -910,13 +917,6 @@ got:
36                 }
37         }
39 -       BUFFER_TRACE(group_desc_bh, "get_write_access");
40 -       err = ext4_journal_get_write_access(handle, group_desc_bh);
41 -       if (err) {
42 -               ext4_std_error(sb, err);
43 -               goto out;
44 -       }
46         /* Update the relevant bg descriptor fields */
47         if (ext4_has_group_desc_csum(sb)) {
48                 int free;