Commit 88e081bf authored by Wang Shilong's avatar Wang Shilong Committed by Josef Bacik

Btrfs: cleanup to make the function btrfs_delalloc_reserve_metadata more logic

The original code is a little confusing and not clear, The right
way to deal with the kernel code like this:
		[...]
		if (ret)
			goto out;
		[...]

So i move the common clean_up code to the place labeled with
out_fail, this will be easier to maintain.
Signed-off-by: default avatarWang Shilong <wangsl-fnst@cn.fujitsu.com>
Signed-off-by: default avatarJosef Bacik <jbacik@fusionio.com>
parent a9870c0e
...@@ -4721,6 +4721,8 @@ int btrfs_delalloc_reserve_metadata(struct inode *inode, u64 num_bytes) ...@@ -4721,6 +4721,8 @@ int btrfs_delalloc_reserve_metadata(struct inode *inode, u64 num_bytes)
enum btrfs_reserve_flush_enum flush = BTRFS_RESERVE_FLUSH_ALL; enum btrfs_reserve_flush_enum flush = BTRFS_RESERVE_FLUSH_ALL;
int ret = 0; int ret = 0;
bool delalloc_lock = true; bool delalloc_lock = true;
u64 to_free = 0;
unsigned dropped;
/* If we are a free space inode we need to not flush since we will be in /* If we are a free space inode we need to not flush since we will be in
* the middle of a transaction commit. We also don't need the delalloc * the middle of a transaction commit. We also don't need the delalloc
...@@ -4764,27 +4766,41 @@ int btrfs_delalloc_reserve_metadata(struct inode *inode, u64 num_bytes) ...@@ -4764,27 +4766,41 @@ int btrfs_delalloc_reserve_metadata(struct inode *inode, u64 num_bytes)
csum_bytes = BTRFS_I(inode)->csum_bytes; csum_bytes = BTRFS_I(inode)->csum_bytes;
spin_unlock(&BTRFS_I(inode)->lock); spin_unlock(&BTRFS_I(inode)->lock);
if (root->fs_info->quota_enabled) if (root->fs_info->quota_enabled) {
ret = btrfs_qgroup_reserve(root, num_bytes + ret = btrfs_qgroup_reserve(root, num_bytes +
nr_extents * root->leafsize); nr_extents * root->leafsize);
if (ret)
goto out_fail;
}
/* ret = reserve_metadata_bytes(root, block_rsv, to_reserve, flush);
* ret != 0 here means the qgroup reservation failed, we go straight to if (unlikely(ret)) {
* the shared error handling then. if (root->fs_info->quota_enabled)
*/
if (ret == 0) {
ret = reserve_metadata_bytes(root, block_rsv,
to_reserve, flush);
if (ret && root->fs_info->quota_enabled) {
btrfs_qgroup_free(root, num_bytes + btrfs_qgroup_free(root, num_bytes +
nr_extents * root->leafsize); nr_extents * root->leafsize);
goto out_fail;
} }
spin_lock(&BTRFS_I(inode)->lock);
if (extra_reserve) {
set_bit(BTRFS_INODE_DELALLOC_META_RESERVED,
&BTRFS_I(inode)->runtime_flags);
nr_extents--;
} }
BTRFS_I(inode)->reserved_extents += nr_extents;
spin_unlock(&BTRFS_I(inode)->lock);
if (ret) { if (delalloc_lock)
u64 to_free = 0; mutex_unlock(&BTRFS_I(inode)->delalloc_mutex);
unsigned dropped;
if (to_reserve)
trace_btrfs_space_reservation(root->fs_info,"delalloc",
btrfs_ino(inode), to_reserve, 1);
block_rsv_add_bytes(block_rsv, to_reserve, 1);
return 0;
out_fail:
spin_lock(&BTRFS_I(inode)->lock); spin_lock(&BTRFS_I(inode)->lock);
dropped = drop_outstanding_extent(inode); dropped = drop_outstanding_extent(inode);
/* /*
...@@ -4805,34 +4821,12 @@ int btrfs_delalloc_reserve_metadata(struct inode *inode, u64 num_bytes) ...@@ -4805,34 +4821,12 @@ int btrfs_delalloc_reserve_metadata(struct inode *inode, u64 num_bytes)
if (to_free) { if (to_free) {
btrfs_block_rsv_release(root, block_rsv, to_free); btrfs_block_rsv_release(root, block_rsv, to_free);
trace_btrfs_space_reservation(root->fs_info, trace_btrfs_space_reservation(root->fs_info, "delalloc",
"delalloc", btrfs_ino(inode), to_free, 0);
btrfs_ino(inode),
to_free, 0);
} }
if (delalloc_lock) if (delalloc_lock)
mutex_unlock(&BTRFS_I(inode)->delalloc_mutex); mutex_unlock(&BTRFS_I(inode)->delalloc_mutex);
return ret; return ret;
}
spin_lock(&BTRFS_I(inode)->lock);
if (extra_reserve) {
set_bit(BTRFS_INODE_DELALLOC_META_RESERVED,
&BTRFS_I(inode)->runtime_flags);
nr_extents--;
}
BTRFS_I(inode)->reserved_extents += nr_extents;
spin_unlock(&BTRFS_I(inode)->lock);
if (delalloc_lock)
mutex_unlock(&BTRFS_I(inode)->delalloc_mutex);
if (to_reserve)
trace_btrfs_space_reservation(root->fs_info,"delalloc",
btrfs_ino(inode), to_reserve, 1);
block_rsv_add_bytes(block_rsv, to_reserve, 1);
return 0;
} }
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment