aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/extent-tree.c
diff options
context:
space:
mode:
authorChris Mason <chris.mason@oracle.com>2011-05-28 07:00:39 -0400
committerChris Mason <chris.mason@oracle.com>2011-05-28 07:00:39 -0400
commitff5714cca971848963b87d6b477c16ca8abbaa54 (patch)
tree17ee34b9b5e00804df4059503f82f6f1d94383a9 /fs/btrfs/extent-tree.c
parent174ba50915b08dcfd07c8b5fb795b46a165fa09a (diff)
parentd90c732122a1f6d0efe388a8a204f67f144b2eb3 (diff)
Merge branch 'for-chris' of
git://git.kernel.org/pub/scm/linux/kernel/git/josef/btrfs-work into for-linus Conflicts: fs/btrfs/disk-io.c fs/btrfs/extent-tree.c fs/btrfs/free-space-cache.c fs/btrfs/inode.c fs/btrfs/transaction.c Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/extent-tree.c')
-rw-r--r--fs/btrfs/extent-tree.c100
1 files changed, 67 insertions, 33 deletions
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 169bd62ce776..c9173a7827b0 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -348,7 +348,7 @@ static int caching_kthread(void *data)
348 */ 348 */
349 path->skip_locking = 1; 349 path->skip_locking = 1;
350 path->search_commit_root = 1; 350 path->search_commit_root = 1;
351 path->reada = 2; 351 path->reada = 1;
352 352
353 key.objectid = last; 353 key.objectid = last;
354 key.offset = 0; 354 key.offset = 0;
@@ -379,15 +379,18 @@ again:
379 if (ret) 379 if (ret)
380 break; 380 break;
381 381
382 caching_ctl->progress = last; 382 if (need_resched() ||
383 btrfs_release_path(path); 383 btrfs_next_leaf(extent_root, path)) {
384 up_read(&fs_info->extent_commit_sem); 384 caching_ctl->progress = last;
385 mutex_unlock(&caching_ctl->mutex); 385 btrfs_release_path(path);
386 if (btrfs_transaction_in_commit(fs_info)) 386 up_read(&fs_info->extent_commit_sem);
387 schedule_timeout(1); 387 mutex_unlock(&caching_ctl->mutex);
388 else
389 cond_resched(); 388 cond_resched();
390 goto again; 389 goto again;
390 }
391 leaf = path->nodes[0];
392 nritems = btrfs_header_nritems(leaf);
393 continue;
391 } 394 }
392 395
393 if (key.objectid < block_group->key.objectid) { 396 if (key.objectid < block_group->key.objectid) {
@@ -3065,7 +3068,7 @@ again:
3065 spin_unlock(&data_sinfo->lock); 3068 spin_unlock(&data_sinfo->lock);
3066alloc: 3069alloc:
3067 alloc_target = btrfs_get_alloc_profile(root, 1); 3070 alloc_target = btrfs_get_alloc_profile(root, 1);
3068 trans = btrfs_join_transaction(root, 1); 3071 trans = btrfs_join_transaction(root);
3069 if (IS_ERR(trans)) 3072 if (IS_ERR(trans))
3070 return PTR_ERR(trans); 3073 return PTR_ERR(trans);
3071 3074
@@ -3091,9 +3094,10 @@ alloc:
3091 3094
3092 /* commit the current transaction and try again */ 3095 /* commit the current transaction and try again */
3093commit_trans: 3096commit_trans:
3094 if (!committed && !root->fs_info->open_ioctl_trans) { 3097 if (!committed &&
3098 !atomic_read(&root->fs_info->open_ioctl_trans)) {
3095 committed = 1; 3099 committed = 1;
3096 trans = btrfs_join_transaction(root, 1); 3100 trans = btrfs_join_transaction(root);
3097 if (IS_ERR(trans)) 3101 if (IS_ERR(trans))
3098 return PTR_ERR(trans); 3102 return PTR_ERR(trans);
3099 ret = btrfs_commit_transaction(trans, root); 3103 ret = btrfs_commit_transaction(trans, root);
@@ -3472,7 +3476,7 @@ again:
3472 goto out; 3476 goto out;
3473 3477
3474 ret = -ENOSPC; 3478 ret = -ENOSPC;
3475 trans = btrfs_join_transaction(root, 1); 3479 trans = btrfs_join_transaction(root);
3476 if (IS_ERR(trans)) 3480 if (IS_ERR(trans))
3477 goto out; 3481 goto out;
3478 ret = btrfs_commit_transaction(trans, root); 3482 ret = btrfs_commit_transaction(trans, root);
@@ -3699,7 +3703,7 @@ int btrfs_block_rsv_check(struct btrfs_trans_handle *trans,
3699 if (trans) 3703 if (trans)
3700 return -EAGAIN; 3704 return -EAGAIN;
3701 3705
3702 trans = btrfs_join_transaction(root, 1); 3706 trans = btrfs_join_transaction(root);
3703 BUG_ON(IS_ERR(trans)); 3707 BUG_ON(IS_ERR(trans));
3704 ret = btrfs_commit_transaction(trans, root); 3708 ret = btrfs_commit_transaction(trans, root);
3705 return 0; 3709 return 0;
@@ -3837,6 +3841,37 @@ static void release_global_block_rsv(struct btrfs_fs_info *fs_info)
3837 WARN_ON(fs_info->chunk_block_rsv.reserved > 0); 3841 WARN_ON(fs_info->chunk_block_rsv.reserved > 0);
3838} 3842}
3839 3843
3844int btrfs_truncate_reserve_metadata(struct btrfs_trans_handle *trans,
3845 struct btrfs_root *root,
3846 struct btrfs_block_rsv *rsv)
3847{
3848 struct btrfs_block_rsv *trans_rsv = &root->fs_info->trans_block_rsv;
3849 u64 num_bytes;
3850 int ret;
3851
3852 /*
3853 * Truncate should be freeing data, but give us 2 items just in case it
3854 * needs to use some space. We may want to be smarter about this in the
3855 * future.
3856 */
3857 num_bytes = btrfs_calc_trans_metadata_size(root, 2);
3858
3859 /* We already have enough bytes, just return */
3860 if (rsv->reserved >= num_bytes)
3861 return 0;
3862
3863 num_bytes -= rsv->reserved;
3864
3865 /*
3866 * You should have reserved enough space before hand to do this, so this
3867 * should not fail.
3868 */
3869 ret = block_rsv_migrate_bytes(trans_rsv, rsv, num_bytes);
3870 BUG_ON(ret);
3871
3872 return 0;
3873}
3874
3840int btrfs_trans_reserve_metadata(struct btrfs_trans_handle *trans, 3875int btrfs_trans_reserve_metadata(struct btrfs_trans_handle *trans,
3841 struct btrfs_root *root, 3876 struct btrfs_root *root,
3842 int num_items) 3877 int num_items)
@@ -3877,23 +3912,18 @@ int btrfs_orphan_reserve_metadata(struct btrfs_trans_handle *trans,
3877 struct btrfs_block_rsv *dst_rsv = root->orphan_block_rsv; 3912 struct btrfs_block_rsv *dst_rsv = root->orphan_block_rsv;
3878 3913
3879 /* 3914 /*
3880 * one for deleting orphan item, one for updating inode and 3915 * We need to hold space in order to delete our orphan item once we've
3881 * two for calling btrfs_truncate_inode_items. 3916 * added it, so this takes the reservation so we can release it later
3882 * 3917 * when we are truly done with the orphan item.
3883 * btrfs_truncate_inode_items is a delete operation, it frees
3884 * more space than it uses in most cases. So two units of
3885 * metadata space should be enough for calling it many times.
3886 * If all of the metadata space is used, we can commit
3887 * transaction and use space it freed.
3888 */ 3918 */
3889 u64 num_bytes = btrfs_calc_trans_metadata_size(root, 4); 3919 u64 num_bytes = btrfs_calc_trans_metadata_size(root, 1);
3890 return block_rsv_migrate_bytes(src_rsv, dst_rsv, num_bytes); 3920 return block_rsv_migrate_bytes(src_rsv, dst_rsv, num_bytes);
3891} 3921}
3892 3922
3893void btrfs_orphan_release_metadata(struct inode *inode) 3923void btrfs_orphan_release_metadata(struct inode *inode)
3894{ 3924{
3895 struct btrfs_root *root = BTRFS_I(inode)->root; 3925 struct btrfs_root *root = BTRFS_I(inode)->root;
3896 u64 num_bytes = btrfs_calc_trans_metadata_size(root, 4); 3926 u64 num_bytes = btrfs_calc_trans_metadata_size(root, 1);
3897 btrfs_block_rsv_release(root, root->orphan_block_rsv, num_bytes); 3927 btrfs_block_rsv_release(root, root->orphan_block_rsv, num_bytes);
3898} 3928}
3899 3929
@@ -4987,6 +5017,15 @@ have_block_group:
4987 if (unlikely(block_group->ro)) 5017 if (unlikely(block_group->ro))
4988 goto loop; 5018 goto loop;
4989 5019
5020 spin_lock(&block_group->free_space_ctl->tree_lock);
5021 if (cached &&
5022 block_group->free_space_ctl->free_space <
5023 num_bytes + empty_size) {
5024 spin_unlock(&block_group->free_space_ctl->tree_lock);
5025 goto loop;
5026 }
5027 spin_unlock(&block_group->free_space_ctl->tree_lock);
5028
4990 /* 5029 /*
4991 * Ok we want to try and use the cluster allocator, so lets look 5030 * Ok we want to try and use the cluster allocator, so lets look
4992 * there, unless we are on LOOP_NO_EMPTY_SIZE, since we will 5031 * there, unless we are on LOOP_NO_EMPTY_SIZE, since we will
@@ -5150,6 +5189,7 @@ checks:
5150 btrfs_add_free_space(block_group, offset, 5189 btrfs_add_free_space(block_group, offset,
5151 search_start - offset); 5190 search_start - offset);
5152 BUG_ON(offset > search_start); 5191 BUG_ON(offset > search_start);
5192 btrfs_put_block_group(block_group);
5153 break; 5193 break;
5154loop: 5194loop:
5155 failed_cluster_refill = false; 5195 failed_cluster_refill = false;
@@ -5242,14 +5282,7 @@ loop:
5242 ret = -ENOSPC; 5282 ret = -ENOSPC;
5243 } else if (!ins->objectid) { 5283 } else if (!ins->objectid) {
5244 ret = -ENOSPC; 5284 ret = -ENOSPC;
5245 } 5285 } else if (ins->objectid) {
5246
5247 /* we found what we needed */
5248 if (ins->objectid) {
5249 if (!(data & BTRFS_BLOCK_GROUP_DATA))
5250 trans->block_group = block_group->key.objectid;
5251
5252 btrfs_put_block_group(block_group);
5253 ret = 0; 5286 ret = 0;
5254 } 5287 }
5255 5288
@@ -6526,7 +6559,7 @@ int btrfs_set_block_group_ro(struct btrfs_root *root,
6526 6559
6527 BUG_ON(cache->ro); 6560 BUG_ON(cache->ro);
6528 6561
6529 trans = btrfs_join_transaction(root, 1); 6562 trans = btrfs_join_transaction(root);
6530 BUG_ON(IS_ERR(trans)); 6563 BUG_ON(IS_ERR(trans));
6531 6564
6532 alloc_flags = update_block_group_flags(root, cache->flags); 6565 alloc_flags = update_block_group_flags(root, cache->flags);
@@ -6882,6 +6915,7 @@ int btrfs_read_block_groups(struct btrfs_root *root)
6882 path = btrfs_alloc_path(); 6915 path = btrfs_alloc_path();
6883 if (!path) 6916 if (!path)
6884 return -ENOMEM; 6917 return -ENOMEM;
6918 path->reada = 1;
6885 6919
6886 cache_gen = btrfs_super_cache_generation(&root->fs_info->super_copy); 6920 cache_gen = btrfs_super_cache_generation(&root->fs_info->super_copy);
6887 if (cache_gen != 0 && 6921 if (cache_gen != 0 &&