aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/extent-tree.c
diff options
context:
space:
mode:
authorJosef Bacik <jbacik@fusionio.com>2013-10-07 15:21:08 -0400
committerChris Mason <chris.mason@fusionio.com>2013-11-11 21:56:41 -0500
commit857cc2fc29cfaf4ee98fe9967bbf6a3942191136 (patch)
treeae0ba49149643241d5ae8b85e08f7c2dacb04ef8 /fs/btrfs/extent-tree.c
parent0be5dc67c445230b0889dba63defba9a9e5561b4 (diff)
Btrfs: free reserved space on error in a few places
While trying to track down a reserved space leak I noticed a few places where we won't properly clean up reserved space if we have an error, this patch fixes those up. Thanks, Signed-off-by: Josef Bacik <jbacik@fusionio.com> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
Diffstat (limited to 'fs/btrfs/extent-tree.c')
-rw-r--r--fs/btrfs/extent-tree.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 65401d7ef663..054b11dc8edf 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -2234,8 +2234,12 @@ static int run_one_delayed_ref(struct btrfs_trans_handle *trans,
2234{ 2234{
2235 int ret = 0; 2235 int ret = 0;
2236 2236
2237 if (trans->aborted) 2237 if (trans->aborted) {
2238 if (insert_reserved)
2239 btrfs_pin_extent(root, node->bytenr,
2240 node->num_bytes, 1);
2238 return 0; 2241 return 0;
2242 }
2239 2243
2240 if (btrfs_delayed_ref_is_head(node)) { 2244 if (btrfs_delayed_ref_is_head(node)) {
2241 struct btrfs_delayed_ref_head *head; 2245 struct btrfs_delayed_ref_head *head;
@@ -2411,6 +2415,14 @@ static noinline int run_clustered_refs(struct btrfs_trans_handle *trans,
2411 btrfs_free_delayed_extent_op(extent_op); 2415 btrfs_free_delayed_extent_op(extent_op);
2412 2416
2413 if (ret) { 2417 if (ret) {
2418 /*
2419 * Need to reset must_insert_reserved if
2420 * there was an error so the abort stuff
2421 * can cleanup the reserved space
2422 * properly.
2423 */
2424 if (must_insert_reserved)
2425 locked_ref->must_insert_reserved = 1;
2414 btrfs_debug(fs_info, "run_delayed_extent_op returned %d", ret); 2426 btrfs_debug(fs_info, "run_delayed_extent_op returned %d", ret);
2415 spin_lock(&delayed_refs->lock); 2427 spin_lock(&delayed_refs->lock);
2416 btrfs_delayed_ref_unlock(locked_ref); 2428 btrfs_delayed_ref_unlock(locked_ref);
@@ -6731,13 +6743,18 @@ static int alloc_reserved_tree_block(struct btrfs_trans_handle *trans,
6731 size += sizeof(*block_info); 6743 size += sizeof(*block_info);
6732 6744
6733 path = btrfs_alloc_path(); 6745 path = btrfs_alloc_path();
6734 if (!path) 6746 if (!path) {
6747 btrfs_free_and_pin_reserved_extent(root, ins->objectid,
6748 root->leafsize);
6735 return -ENOMEM; 6749 return -ENOMEM;
6750 }
6736 6751
6737 path->leave_spinning = 1; 6752 path->leave_spinning = 1;
6738 ret = btrfs_insert_empty_item(trans, fs_info->extent_root, path, 6753 ret = btrfs_insert_empty_item(trans, fs_info->extent_root, path,
6739 ins, size); 6754 ins, size);
6740 if (ret) { 6755 if (ret) {
6756 btrfs_free_and_pin_reserved_extent(root, ins->objectid,
6757 root->leafsize);
6741 btrfs_free_path(path); 6758 btrfs_free_path(path);
6742 return ret; 6759 return ret;
6743 } 6760 }