Skip to content

Commit 80ee54b

Browse files
josefbacikkdave
authored andcommitted
btrfs: fix insert_reserved error handling
We were not handling the reserved byte accounting properly for data references. Metadata was fine, if it errored out the error paths would free the bytes_reserved count and pin the extent, but it even missed one of the error cases. So instead move this handling up into run_one_delayed_ref so we are sure that both cases are properly cleaned up in case of a transaction abort. CC: stable@vger.kernel.org # 4.18+ Reviewed-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: Josef Bacik <josef@toxicpanda.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 49940bd commit 80ee54b

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

fs/btrfs/extent-tree.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2366,6 +2366,9 @@ static int run_one_delayed_ref(struct btrfs_trans_handle *trans,
23662366
insert_reserved);
23672367
else
23682368
BUG();
2369+
if (ret && insert_reserved)
2370+
btrfs_pin_extent(trans->fs_info, node->bytenr,
2371+
node->num_bytes, 1);
23692372
return ret;
23702373
}
23712374

@@ -8004,21 +8007,14 @@ static int alloc_reserved_tree_block(struct btrfs_trans_handle *trans,
80048007
}
80058008

80068009
path = btrfs_alloc_path();
8007-
if (!path) {
8008-
btrfs_free_and_pin_reserved_extent(fs_info,
8009-
extent_key.objectid,
8010-
fs_info->nodesize);
8010+
if (!path)
80118011
return -ENOMEM;
8012-
}
80138012

80148013
path->leave_spinning = 1;
80158014
ret = btrfs_insert_empty_item(trans, fs_info->extent_root, path,
80168015
&extent_key, size);
80178016
if (ret) {
80188017
btrfs_free_path(path);
8019-
btrfs_free_and_pin_reserved_extent(fs_info,
8020-
extent_key.objectid,
8021-
fs_info->nodesize);
80228018
return ret;
80238019
}
80248020

0 commit comments

Comments
 (0)