提交 4a92b1b8 编写于 作者: J Josef Bacik

Btrfs: stop passing a trans handle all around the reservation code

The only thing that we need to have a trans handle for is in
reserve_metadata_bytes and thats to know how much flushing we can do.  So
instead of passing it around, just check current->journal_info for a
trans_handle so we know if we can commit a transaction to try and free up space
or not.  Thanks,
Signed-off-by: NJosef Bacik <josef@redhat.com>
上级 d02c9955
...@@ -2237,12 +2237,10 @@ void btrfs_init_block_rsv(struct btrfs_block_rsv *rsv); ...@@ -2237,12 +2237,10 @@ void btrfs_init_block_rsv(struct btrfs_block_rsv *rsv);
struct btrfs_block_rsv *btrfs_alloc_block_rsv(struct btrfs_root *root); struct btrfs_block_rsv *btrfs_alloc_block_rsv(struct btrfs_root *root);
void btrfs_free_block_rsv(struct btrfs_root *root, void btrfs_free_block_rsv(struct btrfs_root *root,
struct btrfs_block_rsv *rsv); struct btrfs_block_rsv *rsv);
int btrfs_block_rsv_add(struct btrfs_trans_handle *trans, int btrfs_block_rsv_add(struct btrfs_root *root,
struct btrfs_root *root,
struct btrfs_block_rsv *block_rsv, struct btrfs_block_rsv *block_rsv,
u64 num_bytes); u64 num_bytes);
int btrfs_block_rsv_check(struct btrfs_trans_handle *trans, int btrfs_block_rsv_check(struct btrfs_root *root,
struct btrfs_root *root,
struct btrfs_block_rsv *block_rsv, struct btrfs_block_rsv *block_rsv,
u64 min_reserved, int min_factor, int flush); u64 min_reserved, int min_factor, int flush);
int btrfs_block_rsv_migrate(struct btrfs_block_rsv *src_rsv, int btrfs_block_rsv_migrate(struct btrfs_block_rsv *src_rsv,
......
...@@ -3404,29 +3404,34 @@ static int shrink_delalloc(struct btrfs_trans_handle *trans, ...@@ -3404,29 +3404,34 @@ static int shrink_delalloc(struct btrfs_trans_handle *trans,
return reclaimed >= to_reclaim; return reclaimed >= to_reclaim;
} }
/* /**
* Retries tells us how many times we've called reserve_metadata_bytes. The * reserve_metadata_bytes - try to reserve bytes from the block_rsv's space
* idea is if this is the first call (retries == 0) then we will add to our * @root - the root we're allocating for
* reserved count if we can't make the allocation in order to hold our place * @block_rsv - the block_rsv we're allocating for
* while we go and try and free up space. That way for retries > 1 we don't try * @orig_bytes - the number of bytes we want
* and add space, we just check to see if the amount of unused space is >= the * @flush - wether or not we can flush to make our reservation
* total space, meaning that our reservation is valid.
* *
* However if we don't intend to retry this reservation, pass -1 as retries so * This will reserve orgi_bytes number of bytes from the space info associated
* that it short circuits this logic. * with the block_rsv. If there is not enough space it will make an attempt to
* flush out space to make room. It will do this by flushing delalloc if
* possible or committing the transaction. If flush is 0 then no attempts to
* regain reservations will be made and this will fail if there is not enough
* space already.
*/ */
static int reserve_metadata_bytes(struct btrfs_trans_handle *trans, static int reserve_metadata_bytes(struct btrfs_root *root,
struct btrfs_root *root,
struct btrfs_block_rsv *block_rsv, struct btrfs_block_rsv *block_rsv,
u64 orig_bytes, int flush) u64 orig_bytes, int flush)
{ {
struct btrfs_space_info *space_info = block_rsv->space_info; struct btrfs_space_info *space_info = block_rsv->space_info;
struct btrfs_trans_handle *trans;
u64 unused; u64 unused;
u64 num_bytes = orig_bytes; u64 num_bytes = orig_bytes;
int retries = 0; int retries = 0;
int ret = 0; int ret = 0;
bool committed = false; bool committed = false;
bool flushing = false; bool flushing = false;
trans = (struct btrfs_trans_handle *)current->journal_info;
again: again:
ret = 0; ret = 0;
spin_lock(&space_info->lock); spin_lock(&space_info->lock);
...@@ -3689,8 +3694,7 @@ void btrfs_free_block_rsv(struct btrfs_root *root, ...@@ -3689,8 +3694,7 @@ void btrfs_free_block_rsv(struct btrfs_root *root,
kfree(rsv); kfree(rsv);
} }
int btrfs_block_rsv_add(struct btrfs_trans_handle *trans, int btrfs_block_rsv_add(struct btrfs_root *root,
struct btrfs_root *root,
struct btrfs_block_rsv *block_rsv, struct btrfs_block_rsv *block_rsv,
u64 num_bytes) u64 num_bytes)
{ {
...@@ -3699,7 +3703,7 @@ int btrfs_block_rsv_add(struct btrfs_trans_handle *trans, ...@@ -3699,7 +3703,7 @@ int btrfs_block_rsv_add(struct btrfs_trans_handle *trans,
if (num_bytes == 0) if (num_bytes == 0)
return 0; return 0;
ret = reserve_metadata_bytes(trans, root, block_rsv, num_bytes, 1); ret = reserve_metadata_bytes(root, block_rsv, num_bytes, 1);
if (!ret) { if (!ret) {
block_rsv_add_bytes(block_rsv, num_bytes, 1); block_rsv_add_bytes(block_rsv, num_bytes, 1);
return 0; return 0;
...@@ -3708,8 +3712,7 @@ int btrfs_block_rsv_add(struct btrfs_trans_handle *trans, ...@@ -3708,8 +3712,7 @@ int btrfs_block_rsv_add(struct btrfs_trans_handle *trans,
return ret; return ret;
} }
int btrfs_block_rsv_check(struct btrfs_trans_handle *trans, int btrfs_block_rsv_check(struct btrfs_root *root,
struct btrfs_root *root,
struct btrfs_block_rsv *block_rsv, struct btrfs_block_rsv *block_rsv,
u64 min_reserved, int min_factor, int flush) u64 min_reserved, int min_factor, int flush)
{ {
...@@ -3734,7 +3737,7 @@ int btrfs_block_rsv_check(struct btrfs_trans_handle *trans, ...@@ -3734,7 +3737,7 @@ int btrfs_block_rsv_check(struct btrfs_trans_handle *trans,
if (!ret) if (!ret)
return 0; return 0;
ret = reserve_metadata_bytes(trans, root, block_rsv, num_bytes, flush); ret = reserve_metadata_bytes(root, block_rsv, num_bytes, flush);
if (!ret) { if (!ret) {
block_rsv_add_bytes(block_rsv, num_bytes, 0); block_rsv_add_bytes(block_rsv, num_bytes, 0);
return 0; return 0;
...@@ -4034,7 +4037,7 @@ int btrfs_delalloc_reserve_metadata(struct inode *inode, u64 num_bytes) ...@@ -4034,7 +4037,7 @@ int btrfs_delalloc_reserve_metadata(struct inode *inode, u64 num_bytes)
to_reserve += calc_csum_metadata_size(inode, num_bytes, 1); to_reserve += calc_csum_metadata_size(inode, num_bytes, 1);
spin_unlock(&BTRFS_I(inode)->lock); spin_unlock(&BTRFS_I(inode)->lock);
ret = reserve_metadata_bytes(NULL, root, block_rsv, to_reserve, flush); ret = reserve_metadata_bytes(root, block_rsv, to_reserve, flush);
if (ret) { if (ret) {
u64 to_free = 0; u64 to_free = 0;
unsigned dropped; unsigned dropped;
...@@ -5689,8 +5692,7 @@ use_block_rsv(struct btrfs_trans_handle *trans, ...@@ -5689,8 +5692,7 @@ 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 (block_rsv->size == 0) {
ret = reserve_metadata_bytes(trans, root, block_rsv, ret = reserve_metadata_bytes(root, block_rsv, blocksize, 0);
blocksize, 0);
/* /*
* If we couldn't reserve metadata bytes try and use some from * If we couldn't reserve metadata bytes try and use some from
* the global reserve. * the global reserve.
...@@ -5711,8 +5713,7 @@ use_block_rsv(struct btrfs_trans_handle *trans, ...@@ -5711,8 +5713,7 @@ use_block_rsv(struct btrfs_trans_handle *trans,
return block_rsv; return block_rsv;
if (ret) { if (ret) {
WARN_ON(1); WARN_ON(1);
ret = reserve_metadata_bytes(trans, root, block_rsv, blocksize, ret = reserve_metadata_bytes(root, block_rsv, blocksize, 0);
0);
if (!ret) { if (!ret) {
return block_rsv; return block_rsv;
} else if (ret && block_rsv != global_rsv) { } else if (ret && block_rsv != global_rsv) {
......
...@@ -197,9 +197,7 @@ int btrfs_truncate_free_space_cache(struct btrfs_root *root, ...@@ -197,9 +197,7 @@ int btrfs_truncate_free_space_cache(struct btrfs_root *root,
rsv = trans->block_rsv; rsv = trans->block_rsv;
trans->block_rsv = root->orphan_block_rsv; trans->block_rsv = root->orphan_block_rsv;
ret = btrfs_block_rsv_check(trans, root, ret = btrfs_block_rsv_check(root, root->orphan_block_rsv, 0, 5, 0);
root->orphan_block_rsv,
0, 5, 0);
if (ret) if (ret)
return ret; return ret;
......
...@@ -3577,7 +3577,7 @@ void btrfs_evict_inode(struct inode *inode) ...@@ -3577,7 +3577,7 @@ void btrfs_evict_inode(struct inode *inode)
* doing the truncate. * doing the truncate.
*/ */
while (1) { while (1) {
ret = btrfs_block_rsv_check(NULL, root, rsv, min_size, 0, 1); ret = btrfs_block_rsv_check(root, rsv, min_size, 0, 1);
if (ret) { if (ret) {
printk(KERN_WARNING "Could not get space for a " printk(KERN_WARNING "Could not get space for a "
"delete, will truncate on mount %d\n", ret); "delete, will truncate on mount %d\n", ret);
...@@ -6577,7 +6577,7 @@ static int btrfs_truncate(struct inode *inode) ...@@ -6577,7 +6577,7 @@ static int btrfs_truncate(struct inode *inode)
btrfs_add_ordered_operation(trans, root, inode); btrfs_add_ordered_operation(trans, root, inode);
while (1) { while (1) {
ret = btrfs_block_rsv_check(trans, root, rsv, min_size, 0, 1); ret = btrfs_block_rsv_check(root, rsv, min_size, 0, 1);
if (ret) { if (ret) {
/* /*
* This can only happen with the original transaction we * This can only happen with the original transaction we
......
...@@ -2041,8 +2041,8 @@ static noinline_for_stack int merge_reloc_root(struct reloc_control *rc, ...@@ -2041,8 +2041,8 @@ static noinline_for_stack int merge_reloc_root(struct reloc_control *rc,
BUG_ON(IS_ERR(trans)); BUG_ON(IS_ERR(trans));
trans->block_rsv = rc->block_rsv; trans->block_rsv = rc->block_rsv;
ret = btrfs_block_rsv_check(trans, root, rc->block_rsv, ret = btrfs_block_rsv_check(root, rc->block_rsv, min_reserved,
min_reserved, 0, 0); 0, 0);
if (ret) { if (ret) {
BUG_ON(ret != -EAGAIN); BUG_ON(ret != -EAGAIN);
ret = btrfs_commit_transaction(trans, root); ret = btrfs_commit_transaction(trans, root);
...@@ -2152,8 +2152,7 @@ int prepare_to_merge(struct reloc_control *rc, int err) ...@@ -2152,8 +2152,7 @@ int prepare_to_merge(struct reloc_control *rc, int err)
again: again:
if (!err) { if (!err) {
num_bytes = rc->merging_rsv_size; num_bytes = rc->merging_rsv_size;
ret = btrfs_block_rsv_add(NULL, root, rc->block_rsv, ret = btrfs_block_rsv_add(root, rc->block_rsv, num_bytes);
num_bytes);
if (ret) if (ret)
err = ret; err = ret;
} }
...@@ -2427,7 +2426,7 @@ static int reserve_metadata_space(struct btrfs_trans_handle *trans, ...@@ -2427,7 +2426,7 @@ static int reserve_metadata_space(struct btrfs_trans_handle *trans,
num_bytes = calcu_metadata_size(rc, node, 1) * 2; num_bytes = calcu_metadata_size(rc, node, 1) * 2;
trans->block_rsv = rc->block_rsv; trans->block_rsv = rc->block_rsv;
ret = btrfs_block_rsv_add(trans, root, rc->block_rsv, num_bytes); ret = btrfs_block_rsv_add(root, rc->block_rsv, num_bytes);
if (ret) { if (ret) {
if (ret == -EAGAIN) if (ret == -EAGAIN)
rc->commit_transaction = 1; rc->commit_transaction = 1;
...@@ -3645,7 +3644,7 @@ int prepare_to_relocate(struct reloc_control *rc) ...@@ -3645,7 +3644,7 @@ int prepare_to_relocate(struct reloc_control *rc)
* btrfs_init_reloc_root will use them when there * btrfs_init_reloc_root will use them when there
* is no reservation in transaction handle. * is no reservation in transaction handle.
*/ */
ret = btrfs_block_rsv_add(NULL, rc->extent_root, rc->block_rsv, ret = btrfs_block_rsv_add(rc->extent_root, rc->block_rsv,
rc->extent_root->nodesize * 256); rc->extent_root->nodesize * 256);
if (ret) if (ret)
return ret; return ret;
...@@ -3774,8 +3773,8 @@ static noinline_for_stack int relocate_block_group(struct reloc_control *rc) ...@@ -3774,8 +3773,8 @@ static noinline_for_stack int relocate_block_group(struct reloc_control *rc)
} }
} }
ret = btrfs_block_rsv_check(trans, rc->extent_root, ret = btrfs_block_rsv_check(rc->extent_root, rc->block_rsv, 0,
rc->block_rsv, 0, 5, 0); 5, 0);
if (ret < 0) { if (ret < 0) {
if (ret != -EAGAIN) { if (ret != -EAGAIN) {
err = ret; err = ret;
......
...@@ -275,7 +275,7 @@ static struct btrfs_trans_handle *start_transaction(struct btrfs_root *root, ...@@ -275,7 +275,7 @@ static struct btrfs_trans_handle *start_transaction(struct btrfs_root *root,
*/ */
if (num_items > 0 && root != root->fs_info->chunk_root) { if (num_items > 0 && root != root->fs_info->chunk_root) {
num_bytes = btrfs_calc_trans_metadata_size(root, num_items); num_bytes = btrfs_calc_trans_metadata_size(root, num_items);
ret = btrfs_block_rsv_add(NULL, root, ret = btrfs_block_rsv_add(root,
&root->fs_info->trans_block_rsv, &root->fs_info->trans_block_rsv,
num_bytes); num_bytes);
if (ret) if (ret)
...@@ -418,8 +418,8 @@ static int should_end_transaction(struct btrfs_trans_handle *trans, ...@@ -418,8 +418,8 @@ static int should_end_transaction(struct btrfs_trans_handle *trans,
struct btrfs_root *root) struct btrfs_root *root)
{ {
int ret; int ret;
ret = btrfs_block_rsv_check(trans, root, ret = btrfs_block_rsv_check(root, &root->fs_info->global_block_rsv, 0,
&root->fs_info->global_block_rsv, 0, 5, 0); 5, 0);
return ret ? 1 : 0; return ret ? 1 : 0;
} }
...@@ -914,7 +914,7 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, ...@@ -914,7 +914,7 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
btrfs_reloc_pre_snapshot(trans, pending, &to_reserve); btrfs_reloc_pre_snapshot(trans, pending, &to_reserve);
if (to_reserve > 0) { if (to_reserve > 0) {
ret = btrfs_block_rsv_add(trans, root, &pending->block_rsv, ret = btrfs_block_rsv_add(root, &pending->block_rsv,
to_reserve); to_reserve);
if (ret) { if (ret) {
pending->error = ret; pending->error = ret;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册