aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosef Bacik <josef@redhat.com>2011-08-30 12:34:28 -0400
committerJosef Bacik <josef@redhat.com>2011-10-19 15:12:44 -0400
commit4a92b1b8d2810db4ea0c34616b94c0b3810fa027 (patch)
treedd01cff1987b8178be84f8b750951497b7f525a7
parentd02c9955ded7fc56dd1edc987558b084ccb03eb4 (diff)
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: Josef Bacik <josef@redhat.com>
-rw-r--r--fs/btrfs/ctree.h6
-rw-r--r--fs/btrfs/extent-tree.c45
-rw-r--r--fs/btrfs/free-space-cache.c4
-rw-r--r--fs/btrfs/inode.c4
-rw-r--r--fs/btrfs/relocation.c15
-rw-r--r--fs/btrfs/transaction.c8
6 files changed, 39 insertions, 43 deletions
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index caa73cd8c00a..a5faf8e33baa 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -2237,12 +2237,10 @@ void btrfs_init_block_rsv(struct btrfs_block_rsv *rsv);
2237struct btrfs_block_rsv *btrfs_alloc_block_rsv(struct btrfs_root *root); 2237struct btrfs_block_rsv *btrfs_alloc_block_rsv(struct btrfs_root *root);
2238void btrfs_free_block_rsv(struct btrfs_root *root, 2238void btrfs_free_block_rsv(struct btrfs_root *root,
2239 struct btrfs_block_rsv *rsv); 2239 struct btrfs_block_rsv *rsv);
2240int btrfs_block_rsv_add(struct btrfs_trans_handle *trans, 2240int btrfs_block_rsv_add(struct btrfs_root *root,
2241 struct btrfs_root *root,
2242 struct btrfs_block_rsv *block_rsv, 2241 struct btrfs_block_rsv *block_rsv,
2243 u64 num_bytes); 2242 u64 num_bytes);
2244int btrfs_block_rsv_check(struct btrfs_trans_handle *trans, 2243int btrfs_block_rsv_check(struct btrfs_root *root,
2245 struct btrfs_root *root,
2246 struct btrfs_block_rsv *block_rsv, 2244 struct btrfs_block_rsv *block_rsv,
2247 u64 min_reserved, int min_factor, int flush); 2245 u64 min_reserved, int min_factor, int flush);
2248int btrfs_block_rsv_migrate(struct btrfs_block_rsv *src_rsv, 2246int btrfs_block_rsv_migrate(struct btrfs_block_rsv *src_rsv,
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index d236df790156..9bb71597aa54 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -3404,29 +3404,34 @@ static int shrink_delalloc(struct btrfs_trans_handle *trans,
3404 return reclaimed >= to_reclaim; 3404 return reclaimed >= to_reclaim;
3405} 3405}
3406 3406
3407/* 3407/**
3408 * Retries tells us how many times we've called reserve_metadata_bytes. The 3408 * reserve_metadata_bytes - try to reserve bytes from the block_rsv's space
3409 * idea is if this is the first call (retries == 0) then we will add to our 3409 * @root - the root we're allocating for
3410 * reserved count if we can't make the allocation in order to hold our place 3410 * @block_rsv - the block_rsv we're allocating for
3411 * while we go and try and free up space. That way for retries > 1 we don't try 3411 * @orig_bytes - the number of bytes we want
3412 * and add space, we just check to see if the amount of unused space is >= the 3412 * @flush - wether or not we can flush to make our reservation
3413 * total space, meaning that our reservation is valid.
3414 * 3413 *
3415 * However if we don't intend to retry this reservation, pass -1 as retries so 3414 * This will reserve orgi_bytes number of bytes from the space info associated
3416 * that it short circuits this logic. 3415 * with the block_rsv. If there is not enough space it will make an attempt to
3416 * flush out space to make room. It will do this by flushing delalloc if
3417 * possible or committing the transaction. If flush is 0 then no attempts to
3418 * regain reservations will be made and this will fail if there is not enough
3419 * space already.
3417 */ 3420 */
3418static int reserve_metadata_bytes(struct btrfs_trans_handle *trans, 3421static int reserve_metadata_bytes(struct btrfs_root *root,
3419 struct btrfs_root *root,
3420 struct btrfs_block_rsv *block_rsv, 3422 struct btrfs_block_rsv *block_rsv,
3421 u64 orig_bytes, int flush) 3423 u64 orig_bytes, int flush)
3422{ 3424{
3423 struct btrfs_space_info *space_info = block_rsv->space_info; 3425 struct btrfs_space_info *space_info = block_rsv->space_info;
3426 struct btrfs_trans_handle *trans;
3424 u64 unused; 3427 u64 unused;
3425 u64 num_bytes = orig_bytes; 3428 u64 num_bytes = orig_bytes;
3426 int retries = 0; 3429 int retries = 0;
3427 int ret = 0; 3430 int ret = 0;
3428 bool committed = false; 3431 bool committed = false;
3429 bool flushing = false; 3432 bool flushing = false;
3433
3434 trans = (struct btrfs_trans_handle *)current->journal_info;
3430again: 3435again:
3431 ret = 0; 3436 ret = 0;
3432 spin_lock(&space_info->lock); 3437 spin_lock(&space_info->lock);
@@ -3689,8 +3694,7 @@ void btrfs_free_block_rsv(struct btrfs_root *root,
3689 kfree(rsv); 3694 kfree(rsv);
3690} 3695}
3691 3696
3692int btrfs_block_rsv_add(struct btrfs_trans_handle *trans, 3697int btrfs_block_rsv_add(struct btrfs_root *root,
3693 struct btrfs_root *root,
3694 struct btrfs_block_rsv *block_rsv, 3698 struct btrfs_block_rsv *block_rsv,
3695 u64 num_bytes) 3699 u64 num_bytes)
3696{ 3700{
@@ -3699,7 +3703,7 @@ int btrfs_block_rsv_add(struct btrfs_trans_handle *trans,
3699 if (num_bytes == 0) 3703 if (num_bytes == 0)
3700 return 0; 3704 return 0;
3701 3705
3702 ret = reserve_metadata_bytes(trans, root, block_rsv, num_bytes, 1); 3706 ret = reserve_metadata_bytes(root, block_rsv, num_bytes, 1);
3703 if (!ret) { 3707 if (!ret) {
3704 block_rsv_add_bytes(block_rsv, num_bytes, 1); 3708 block_rsv_add_bytes(block_rsv, num_bytes, 1);
3705 return 0; 3709 return 0;
@@ -3708,8 +3712,7 @@ int btrfs_block_rsv_add(struct btrfs_trans_handle *trans,
3708 return ret; 3712 return ret;
3709} 3713}
3710 3714
3711int btrfs_block_rsv_check(struct btrfs_trans_handle *trans, 3715int btrfs_block_rsv_check(struct btrfs_root *root,
3712 struct btrfs_root *root,
3713 struct btrfs_block_rsv *block_rsv, 3716 struct btrfs_block_rsv *block_rsv,
3714 u64 min_reserved, int min_factor, int flush) 3717 u64 min_reserved, int min_factor, int flush)
3715{ 3718{
@@ -3734,7 +3737,7 @@ int btrfs_block_rsv_check(struct btrfs_trans_handle *trans,
3734 if (!ret) 3737 if (!ret)
3735 return 0; 3738 return 0;
3736 3739
3737 ret = reserve_metadata_bytes(trans, root, block_rsv, num_bytes, flush); 3740 ret = reserve_metadata_bytes(root, block_rsv, num_bytes, flush);
3738 if (!ret) { 3741 if (!ret) {
3739 block_rsv_add_bytes(block_rsv, num_bytes, 0); 3742 block_rsv_add_bytes(block_rsv, num_bytes, 0);
3740 return 0; 3743 return 0;
@@ -4034,7 +4037,7 @@ int btrfs_delalloc_reserve_metadata(struct inode *inode, u64 num_bytes)
4034 to_reserve += calc_csum_metadata_size(inode, num_bytes, 1); 4037 to_reserve += calc_csum_metadata_size(inode, num_bytes, 1);
4035 spin_unlock(&BTRFS_I(inode)->lock); 4038 spin_unlock(&BTRFS_I(inode)->lock);
4036 4039
4037 ret = reserve_metadata_bytes(NULL, root, block_rsv, to_reserve, flush); 4040 ret = reserve_metadata_bytes(root, block_rsv, to_reserve, flush);
4038 if (ret) { 4041 if (ret) {
4039 u64 to_free = 0; 4042 u64 to_free = 0;
4040 unsigned dropped; 4043 unsigned dropped;
@@ -5689,8 +5692,7 @@ use_block_rsv(struct btrfs_trans_handle *trans,
5689 block_rsv = get_block_rsv(trans, root); 5692 block_rsv = get_block_rsv(trans, root);
5690 5693
5691 if (block_rsv->size == 0) { 5694 if (block_rsv->size == 0) {
5692 ret = reserve_metadata_bytes(trans, root, block_rsv, 5695 ret = reserve_metadata_bytes(root, block_rsv, blocksize, 0);
5693 blocksize, 0);
5694 /* 5696 /*
5695 * If we couldn't reserve metadata bytes try and use some from 5697 * If we couldn't reserve metadata bytes try and use some from
5696 * the global reserve. 5698 * the global reserve.
@@ -5711,8 +5713,7 @@ use_block_rsv(struct btrfs_trans_handle *trans,
5711 return block_rsv; 5713 return block_rsv;
5712 if (ret) { 5714 if (ret) {
5713 WARN_ON(1); 5715 WARN_ON(1);
5714 ret = reserve_metadata_bytes(trans, root, block_rsv, blocksize, 5716 ret = reserve_metadata_bytes(root, block_rsv, blocksize, 0);
5715 0);
5716 if (!ret) { 5717 if (!ret) {
5717 return block_rsv; 5718 return block_rsv;
5718 } else if (ret && block_rsv != global_rsv) { 5719 } else if (ret && block_rsv != global_rsv) {
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
index 3bde17ff14c0..ffc42ef44711 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
@@ -197,9 +197,7 @@ int btrfs_truncate_free_space_cache(struct btrfs_root *root,
197 197
198 rsv = trans->block_rsv; 198 rsv = trans->block_rsv;
199 trans->block_rsv = root->orphan_block_rsv; 199 trans->block_rsv = root->orphan_block_rsv;
200 ret = btrfs_block_rsv_check(trans, root, 200 ret = btrfs_block_rsv_check(root, root->orphan_block_rsv, 0, 5, 0);
201 root->orphan_block_rsv,
202 0, 5, 0);
203 if (ret) 201 if (ret)
204 return ret; 202 return ret;
205 203
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 78b5ae59ac4f..2947e94947b5 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -3577,7 +3577,7 @@ void btrfs_evict_inode(struct inode *inode)
3577 * doing the truncate. 3577 * doing the truncate.
3578 */ 3578 */
3579 while (1) { 3579 while (1) {
3580 ret = btrfs_block_rsv_check(NULL, root, rsv, min_size, 0, 1); 3580 ret = btrfs_block_rsv_check(root, rsv, min_size, 0, 1);
3581 if (ret) { 3581 if (ret) {
3582 printk(KERN_WARNING "Could not get space for a " 3582 printk(KERN_WARNING "Could not get space for a "
3583 "delete, will truncate on mount %d\n", ret); 3583 "delete, will truncate on mount %d\n", ret);
@@ -6577,7 +6577,7 @@ static int btrfs_truncate(struct inode *inode)
6577 btrfs_add_ordered_operation(trans, root, inode); 6577 btrfs_add_ordered_operation(trans, root, inode);
6578 6578
6579 while (1) { 6579 while (1) {
6580 ret = btrfs_block_rsv_check(trans, root, rsv, min_size, 0, 1); 6580 ret = btrfs_block_rsv_check(root, rsv, min_size, 0, 1);
6581 if (ret) { 6581 if (ret) {
6582 /* 6582 /*
6583 * This can only happen with the original transaction we 6583 * This can only happen with the original transaction we
diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index fd9ac66434b0..3ab67409f90f 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -2041,8 +2041,8 @@ static noinline_for_stack int merge_reloc_root(struct reloc_control *rc,
2041 BUG_ON(IS_ERR(trans)); 2041 BUG_ON(IS_ERR(trans));
2042 trans->block_rsv = rc->block_rsv; 2042 trans->block_rsv = rc->block_rsv;
2043 2043
2044 ret = btrfs_block_rsv_check(trans, root, rc->block_rsv, 2044 ret = btrfs_block_rsv_check(root, rc->block_rsv, min_reserved,
2045 min_reserved, 0, 0); 2045 0, 0);
2046 if (ret) { 2046 if (ret) {
2047 BUG_ON(ret != -EAGAIN); 2047 BUG_ON(ret != -EAGAIN);
2048 ret = btrfs_commit_transaction(trans, root); 2048 ret = btrfs_commit_transaction(trans, root);
@@ -2152,8 +2152,7 @@ int prepare_to_merge(struct reloc_control *rc, int err)
2152again: 2152again:
2153 if (!err) { 2153 if (!err) {
2154 num_bytes = rc->merging_rsv_size; 2154 num_bytes = rc->merging_rsv_size;
2155 ret = btrfs_block_rsv_add(NULL, root, rc->block_rsv, 2155 ret = btrfs_block_rsv_add(root, rc->block_rsv, num_bytes);
2156 num_bytes);
2157 if (ret) 2156 if (ret)
2158 err = ret; 2157 err = ret;
2159 } 2158 }
@@ -2427,7 +2426,7 @@ static int reserve_metadata_space(struct btrfs_trans_handle *trans,
2427 num_bytes = calcu_metadata_size(rc, node, 1) * 2; 2426 num_bytes = calcu_metadata_size(rc, node, 1) * 2;
2428 2427
2429 trans->block_rsv = rc->block_rsv; 2428 trans->block_rsv = rc->block_rsv;
2430 ret = btrfs_block_rsv_add(trans, root, rc->block_rsv, num_bytes); 2429 ret = btrfs_block_rsv_add(root, rc->block_rsv, num_bytes);
2431 if (ret) { 2430 if (ret) {
2432 if (ret == -EAGAIN) 2431 if (ret == -EAGAIN)
2433 rc->commit_transaction = 1; 2432 rc->commit_transaction = 1;
@@ -3645,7 +3644,7 @@ int prepare_to_relocate(struct reloc_control *rc)
3645 * btrfs_init_reloc_root will use them when there 3644 * btrfs_init_reloc_root will use them when there
3646 * is no reservation in transaction handle. 3645 * is no reservation in transaction handle.
3647 */ 3646 */
3648 ret = btrfs_block_rsv_add(NULL, rc->extent_root, rc->block_rsv, 3647 ret = btrfs_block_rsv_add(rc->extent_root, rc->block_rsv,
3649 rc->extent_root->nodesize * 256); 3648 rc->extent_root->nodesize * 256);
3650 if (ret) 3649 if (ret)
3651 return ret; 3650 return ret;
@@ -3774,8 +3773,8 @@ restart:
3774 } 3773 }
3775 } 3774 }
3776 3775
3777 ret = btrfs_block_rsv_check(trans, rc->extent_root, 3776 ret = btrfs_block_rsv_check(rc->extent_root, rc->block_rsv, 0,
3778 rc->block_rsv, 0, 5, 0); 3777 5, 0);
3779 if (ret < 0) { 3778 if (ret < 0) {
3780 if (ret != -EAGAIN) { 3779 if (ret != -EAGAIN) {
3781 err = ret; 3780 err = ret;
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index a770f4bd9d31..8d6f4c78f73f 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -275,7 +275,7 @@ static struct btrfs_trans_handle *start_transaction(struct btrfs_root *root,
275 */ 275 */
276 if (num_items > 0 && root != root->fs_info->chunk_root) { 276 if (num_items > 0 && root != root->fs_info->chunk_root) {
277 num_bytes = btrfs_calc_trans_metadata_size(root, num_items); 277 num_bytes = btrfs_calc_trans_metadata_size(root, num_items);
278 ret = btrfs_block_rsv_add(NULL, root, 278 ret = btrfs_block_rsv_add(root,
279 &root->fs_info->trans_block_rsv, 279 &root->fs_info->trans_block_rsv,
280 num_bytes); 280 num_bytes);
281 if (ret) 281 if (ret)
@@ -418,8 +418,8 @@ static int should_end_transaction(struct btrfs_trans_handle *trans,
418 struct btrfs_root *root) 418 struct btrfs_root *root)
419{ 419{
420 int ret; 420 int ret;
421 ret = btrfs_block_rsv_check(trans, root, 421 ret = btrfs_block_rsv_check(root, &root->fs_info->global_block_rsv, 0,
422 &root->fs_info->global_block_rsv, 0, 5, 0); 422 5, 0);
423 return ret ? 1 : 0; 423 return ret ? 1 : 0;
424} 424}
425 425
@@ -914,7 +914,7 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
914 btrfs_reloc_pre_snapshot(trans, pending, &to_reserve); 914 btrfs_reloc_pre_snapshot(trans, pending, &to_reserve);
915 915
916 if (to_reserve > 0) { 916 if (to_reserve > 0) {
917 ret = btrfs_block_rsv_add(trans, root, &pending->block_rsv, 917 ret = btrfs_block_rsv_add(root, &pending->block_rsv,
918 to_reserve); 918 to_reserve);
919 if (ret) { 919 if (ret) {
920 pending->error = ret; 920 pending->error = ret;