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)
committerDavid Sterba <dsterba@suse.com>
Fri, 19 Oct 2018 10:20:03 +0000 (12:20 +0200)
commit49940bdd57779c78462da7aa5a8650b2fea8c2ff
tree857e78f94bed8f2024aa9468aeaee91efaa4bca7
parentfb5c39d7a887108087de6ff93d3f326b01b4ef41
btrfs: only free reserved extent if we didn't insert it

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>
fs/btrfs/inode.c