Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 843fcf35 authored by Miao Xie's avatar Miao Xie Committed by Josef Bacik
Browse files

Btrfs: fix missing release of the space/qgroup reservation in start_transaction()



When we fail to start a transaction, we need to release the reserved free space
and qgroup space, fix it.

Signed-off-by: default avatarMiao Xie <miaox@cn.fujitsu.com>
Reviewed-by: default avatarJan Schmidt <list.btrfs@jan-o-sch.net>
Signed-off-by: default avatarJosef Bacik <jbacik@fusionio.com>
parent 0a3404dc
Loading
Loading
Loading
Loading
+19 −8
Original line number Original line Diff line number Diff line
@@ -333,12 +333,14 @@ start_transaction(struct btrfs_root *root, u64 num_items, int type,
					  &root->fs_info->trans_block_rsv,
					  &root->fs_info->trans_block_rsv,
					  num_bytes, flush);
					  num_bytes, flush);
		if (ret)
		if (ret)
			return ERR_PTR(ret);
			goto reserve_fail;
	}
	}
again:
again:
	h = kmem_cache_alloc(btrfs_trans_handle_cachep, GFP_NOFS);
	h = kmem_cache_alloc(btrfs_trans_handle_cachep, GFP_NOFS);
	if (!h)
	if (!h) {
		return ERR_PTR(-ENOMEM);
		ret = -ENOMEM;
		goto alloc_fail;
	}


	/*
	/*
	 * If we are JOIN_NOLOCK we're already committing a transaction and
	 * If we are JOIN_NOLOCK we're already committing a transaction and
@@ -365,11 +367,7 @@ start_transaction(struct btrfs_root *root, u64 num_items, int type,
	if (ret < 0) {
	if (ret < 0) {
		/* We must get the transaction if we are JOIN_NOLOCK. */
		/* We must get the transaction if we are JOIN_NOLOCK. */
		BUG_ON(type == TRANS_JOIN_NOLOCK);
		BUG_ON(type == TRANS_JOIN_NOLOCK);

		goto join_fail;
		if (type < TRANS_JOIN_NOLOCK)
			sb_end_intwrite(root->fs_info->sb);
		kmem_cache_free(btrfs_trans_handle_cachep, h);
		return ERR_PTR(ret);
	}
	}


	cur_trans = root->fs_info->running_transaction;
	cur_trans = root->fs_info->running_transaction;
@@ -410,6 +408,19 @@ start_transaction(struct btrfs_root *root, u64 num_items, int type,
	if (!current->journal_info && type != TRANS_USERSPACE)
	if (!current->journal_info && type != TRANS_USERSPACE)
		current->journal_info = h;
		current->journal_info = h;
	return h;
	return h;

join_fail:
	if (type < TRANS_JOIN_NOLOCK)
		sb_end_intwrite(root->fs_info->sb);
	kmem_cache_free(btrfs_trans_handle_cachep, h);
alloc_fail:
	if (num_bytes)
		btrfs_block_rsv_release(root, &root->fs_info->trans_block_rsv,
					num_bytes);
reserve_fail:
	if (qgroup_reserved)
		btrfs_qgroup_free(root, qgroup_reserved);
	return ERR_PTR(ret);
}
}


struct btrfs_trans_handle *btrfs_start_transaction(struct btrfs_root *root,
struct btrfs_trans_handle *btrfs_start_transaction(struct btrfs_root *root,