btrfs: only free reserved extent if we didn't insert it
authorJosef Bacik <josef@toxicpanda.com>
Thu, 11 Oct 2018 19:54:21 +0000 (15:54 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 13 Nov 2018 19:08:59 +0000 (11:08 -0800)
commit5a1e9bf45a3ce2843bd3d008d07e7de05f3fe105
tree404aca9bbedaa8ad8a18d4c1082152b867cff309
parenta746cfd00197146fbefc7c2d92cddba5f3c7403d
btrfs: only free reserved extent if we didn't insert it

commit 49940bdd57779c78462da7aa5a8650b2fea8c2ff upstream.

When we insert the file extent once the ordered extent completes we free
the reserved extent reservation as it'll have been migrated to the
bytes_used counter.  However if we error out after this step we'll still
clear the reserved extent reservation, resulting in a negative
accounting of the reserved bytes for the block group and space info.
Fix this by only doing the free if we didn't successfully insert a file
extent for this extent.

CC: stable@vger.kernel.org # 4.14+
Reviewed-by: Omar Sandoval <osandov@fb.com>
Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/btrfs/inode.c