Commit b586b323 authored by Miao Xie's avatar Miao Xie Committed by Josef Bacik

Btrfs: optimize the error handle of use_block_rsv()

cc: Tsutomu Itoh <t-itoh@jp.fujitsu.com>
Signed-off-by: default avatarMiao Xie <miaox@cn.fujitsu.com>
Signed-off-by: default avatarJosef Bacik <jbacik@fusionio.com>
parent 7b61cd92
...@@ -6656,28 +6656,16 @@ use_block_rsv(struct btrfs_trans_handle *trans, ...@@ -6656,28 +6656,16 @@ use_block_rsv(struct btrfs_trans_handle *trans,
block_rsv = get_block_rsv(trans, root); block_rsv = get_block_rsv(trans, root);
if (block_rsv->size == 0) { if (unlikely(block_rsv->size == 0))
ret = reserve_metadata_bytes(root, block_rsv, blocksize, goto try_reserve;
BTRFS_RESERVE_NO_FLUSH);
/*
* If we couldn't reserve metadata bytes try and use some from
* the global reserve.
*/
if (ret && block_rsv != global_rsv) {
ret = block_rsv_use_bytes(global_rsv, blocksize);
if (!ret)
return global_rsv;
return ERR_PTR(ret);
} else if (ret) {
return ERR_PTR(ret);
}
return block_rsv;
}
ret = block_rsv_use_bytes(block_rsv, blocksize); ret = block_rsv_use_bytes(block_rsv, blocksize);
if (!ret) if (!ret)
return block_rsv; return block_rsv;
if (ret && !block_rsv->failfast) {
if (block_rsv->failfast)
return ERR_PTR(ret);
if (btrfs_test_opt(root, ENOSPC_DEBUG)) { if (btrfs_test_opt(root, ENOSPC_DEBUG)) {
static DEFINE_RATELIMIT_STATE(_rs, static DEFINE_RATELIMIT_STATE(_rs,
DEFAULT_RATELIMIT_INTERVAL * 10, DEFAULT_RATELIMIT_INTERVAL * 10,
...@@ -6686,18 +6674,21 @@ use_block_rsv(struct btrfs_trans_handle *trans, ...@@ -6686,18 +6674,21 @@ use_block_rsv(struct btrfs_trans_handle *trans,
WARN(1, KERN_DEBUG WARN(1, KERN_DEBUG
"btrfs: block rsv returned %d\n", ret); "btrfs: block rsv returned %d\n", ret);
} }
try_reserve:
ret = reserve_metadata_bytes(root, block_rsv, blocksize, ret = reserve_metadata_bytes(root, block_rsv, blocksize,
BTRFS_RESERVE_NO_FLUSH); BTRFS_RESERVE_NO_FLUSH);
if (!ret) { if (!ret)
return block_rsv; return block_rsv;
} else if (ret && block_rsv != global_rsv) { /*
* If we couldn't reserve metadata bytes try and use some from
* the global reserve.
*/
if (block_rsv->type != BTRFS_BLOCK_RSV_GLOBAL) {
ret = block_rsv_use_bytes(global_rsv, blocksize); ret = block_rsv_use_bytes(global_rsv, blocksize);
if (!ret) if (!ret)
return global_rsv; return global_rsv;
} }
} return ERR_PTR(ret);
return ERR_PTR(-ENOSPC);
} }
static void unuse_block_rsv(struct btrfs_fs_info *fs_info, static void unuse_block_rsv(struct btrfs_fs_info *fs_info,
......
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