ext4: undo ext4_calc_metadata_amount if we fail to claim space
authorTheodore Ts'o <tytso@mit.edu>
Mon, 23 Jul 2012 04:00:20 +0000 (00:00 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 9 Aug 2012 15:31:41 +0000 (08:31 -0700)
commitc0ce1fd51e122606d555dfd57f5c703b2af12146
tree6490b66667d746ec0236e09868e78b13af7c543f
parent2dd71727e4bf6787caa56770b99a9102ac9a65f4
ext4: undo ext4_calc_metadata_amount if we fail to claim space

commit 03179fe92318e7934c180d96f12eff2cb36ef7b6 upstream.

The function ext4_calc_metadata_amount() has side effects, although
it's not obvious from its function name.  So if we fail to claim
space, regardless of whether we retry to claim the space again, or
return an error, we need to undo these side effects.

Otherwise we can end up incorrectly calculating the number of metadata
blocks needed for the operation, which was responsible for an xfstests
failure for test #271 when using an ext2 file system with delalloc
enabled.

Reported-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/ext4/inode.c