ext4: fix ext4_discard_allocated_blocks() if we can't allocate the pa struct
authorTheodore Ts'o <tytso@mit.edu>
Thu, 31 Jul 2014 02:17:17 +0000 (22:17 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 5 Sep 2014 23:28:35 +0000 (16:28 -0700)
commit0ec5ac16b3d5b70cd0b34249addea6fb104e4305
tree09e93bf5e8f584bfad12bccb0d7dce6c6730d6c5
parentb3a80775fa94e2896ecbd6e591bb3c5ff79003c4
ext4: fix ext4_discard_allocated_blocks() if we can't allocate the pa struct

commit 86f0afd463215fc3e58020493482faa4ac3a4d69 upstream.

If there is a failure while allocating the preallocation structure, a
number of blocks can end up getting marked in the in-memory buddy
bitmap, and then not getting released.  This can result in the
following corruption getting reported by the kernel:

EXT4-fs error (device sda3): ext4_mb_generate_buddy:758: group 1126,
12793 clusters in bitmap, 12729 in gd

In that case, we need to release the blocks using mb_free_blocks().

Tested: fs smoke test; also demonstrated that with injected errors,
the file system is no longer getting corrupted

Google-Bug-Id: 16657874

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/ext4/mballoc.c