diff options
Diffstat (limited to 'fs/btrfs/relocation.c')
-rw-r--r-- | fs/btrfs/relocation.c | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 59bb1764273d..cfb55434a469 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c | |||
@@ -1174,6 +1174,8 @@ static int clone_backref_node(struct btrfs_trans_handle *trans, | |||
1174 | list_add_tail(&new_edge->list[UPPER], | 1174 | list_add_tail(&new_edge->list[UPPER], |
1175 | &new_node->lower); | 1175 | &new_node->lower); |
1176 | } | 1176 | } |
1177 | } else { | ||
1178 | list_add_tail(&new_node->lower, &cache->leaves); | ||
1177 | } | 1179 | } |
1178 | 1180 | ||
1179 | rb_node = tree_insert(&cache->rb_root, new_node->bytenr, | 1181 | rb_node = tree_insert(&cache->rb_root, new_node->bytenr, |
@@ -2041,8 +2043,7 @@ static noinline_for_stack int merge_reloc_root(struct reloc_control *rc, | |||
2041 | BUG_ON(IS_ERR(trans)); | 2043 | BUG_ON(IS_ERR(trans)); |
2042 | trans->block_rsv = rc->block_rsv; | 2044 | trans->block_rsv = rc->block_rsv; |
2043 | 2045 | ||
2044 | ret = btrfs_block_rsv_check(trans, root, rc->block_rsv, | 2046 | ret = btrfs_block_rsv_refill(root, rc->block_rsv, min_reserved); |
2045 | min_reserved, 0); | ||
2046 | if (ret) { | 2047 | if (ret) { |
2047 | BUG_ON(ret != -EAGAIN); | 2048 | BUG_ON(ret != -EAGAIN); |
2048 | ret = btrfs_commit_transaction(trans, root); | 2049 | ret = btrfs_commit_transaction(trans, root); |
@@ -2152,8 +2153,7 @@ int prepare_to_merge(struct reloc_control *rc, int err) | |||
2152 | again: | 2153 | again: |
2153 | if (!err) { | 2154 | if (!err) { |
2154 | num_bytes = rc->merging_rsv_size; | 2155 | num_bytes = rc->merging_rsv_size; |
2155 | ret = btrfs_block_rsv_add(NULL, root, rc->block_rsv, | 2156 | ret = btrfs_block_rsv_add(root, rc->block_rsv, num_bytes); |
2156 | num_bytes); | ||
2157 | if (ret) | 2157 | if (ret) |
2158 | err = ret; | 2158 | err = ret; |
2159 | } | 2159 | } |
@@ -2427,7 +2427,7 @@ static int reserve_metadata_space(struct btrfs_trans_handle *trans, | |||
2427 | num_bytes = calcu_metadata_size(rc, node, 1) * 2; | 2427 | num_bytes = calcu_metadata_size(rc, node, 1) * 2; |
2428 | 2428 | ||
2429 | trans->block_rsv = rc->block_rsv; | 2429 | trans->block_rsv = rc->block_rsv; |
2430 | ret = btrfs_block_rsv_add(trans, root, rc->block_rsv, num_bytes); | 2430 | ret = btrfs_block_rsv_add(root, rc->block_rsv, num_bytes); |
2431 | if (ret) { | 2431 | if (ret) { |
2432 | if (ret == -EAGAIN) | 2432 | if (ret == -EAGAIN) |
2433 | rc->commit_transaction = 1; | 2433 | rc->commit_transaction = 1; |
@@ -2922,6 +2922,7 @@ static int relocate_file_extent_cluster(struct inode *inode, | |||
2922 | unsigned long last_index; | 2922 | unsigned long last_index; |
2923 | struct page *page; | 2923 | struct page *page; |
2924 | struct file_ra_state *ra; | 2924 | struct file_ra_state *ra; |
2925 | gfp_t mask = btrfs_alloc_write_mask(inode->i_mapping); | ||
2925 | int nr = 0; | 2926 | int nr = 0; |
2926 | int ret = 0; | 2927 | int ret = 0; |
2927 | 2928 | ||
@@ -2946,7 +2947,9 @@ static int relocate_file_extent_cluster(struct inode *inode, | |||
2946 | index = (cluster->start - offset) >> PAGE_CACHE_SHIFT; | 2947 | index = (cluster->start - offset) >> PAGE_CACHE_SHIFT; |
2947 | last_index = (cluster->end - offset) >> PAGE_CACHE_SHIFT; | 2948 | last_index = (cluster->end - offset) >> PAGE_CACHE_SHIFT; |
2948 | while (index <= last_index) { | 2949 | while (index <= last_index) { |
2950 | mutex_lock(&inode->i_mutex); | ||
2949 | ret = btrfs_delalloc_reserve_metadata(inode, PAGE_CACHE_SIZE); | 2951 | ret = btrfs_delalloc_reserve_metadata(inode, PAGE_CACHE_SIZE); |
2952 | mutex_unlock(&inode->i_mutex); | ||
2950 | if (ret) | 2953 | if (ret) |
2951 | goto out; | 2954 | goto out; |
2952 | 2955 | ||
@@ -2956,7 +2959,7 @@ static int relocate_file_extent_cluster(struct inode *inode, | |||
2956 | ra, NULL, index, | 2959 | ra, NULL, index, |
2957 | last_index + 1 - index); | 2960 | last_index + 1 - index); |
2958 | page = find_or_create_page(inode->i_mapping, index, | 2961 | page = find_or_create_page(inode->i_mapping, index, |
2959 | GFP_NOFS); | 2962 | mask); |
2960 | if (!page) { | 2963 | if (!page) { |
2961 | btrfs_delalloc_release_metadata(inode, | 2964 | btrfs_delalloc_release_metadata(inode, |
2962 | PAGE_CACHE_SIZE); | 2965 | PAGE_CACHE_SIZE); |
@@ -3323,8 +3326,11 @@ static int find_data_references(struct reloc_control *rc, | |||
3323 | } | 3326 | } |
3324 | 3327 | ||
3325 | key.objectid = ref_objectid; | 3328 | key.objectid = ref_objectid; |
3326 | key.offset = ref_offset; | ||
3327 | key.type = BTRFS_EXTENT_DATA_KEY; | 3329 | key.type = BTRFS_EXTENT_DATA_KEY; |
3330 | if (ref_offset > ((u64)-1 << 32)) | ||
3331 | key.offset = 0; | ||
3332 | else | ||
3333 | key.offset = ref_offset; | ||
3328 | 3334 | ||
3329 | path->search_commit_root = 1; | 3335 | path->search_commit_root = 1; |
3330 | path->skip_locking = 1; | 3336 | path->skip_locking = 1; |
@@ -3645,14 +3651,11 @@ int prepare_to_relocate(struct reloc_control *rc) | |||
3645 | * btrfs_init_reloc_root will use them when there | 3651 | * btrfs_init_reloc_root will use them when there |
3646 | * is no reservation in transaction handle. | 3652 | * is no reservation in transaction handle. |
3647 | */ | 3653 | */ |
3648 | ret = btrfs_block_rsv_add(NULL, rc->extent_root, rc->block_rsv, | 3654 | ret = btrfs_block_rsv_add(rc->extent_root, rc->block_rsv, |
3649 | rc->extent_root->nodesize * 256); | 3655 | rc->extent_root->nodesize * 256); |
3650 | if (ret) | 3656 | if (ret) |
3651 | return ret; | 3657 | return ret; |
3652 | 3658 | ||
3653 | rc->block_rsv->refill_used = 1; | ||
3654 | btrfs_add_durable_block_rsv(rc->extent_root->fs_info, rc->block_rsv); | ||
3655 | |||
3656 | memset(&rc->cluster, 0, sizeof(rc->cluster)); | 3659 | memset(&rc->cluster, 0, sizeof(rc->cluster)); |
3657 | rc->search_start = rc->block_group->key.objectid; | 3660 | rc->search_start = rc->block_group->key.objectid; |
3658 | rc->extents_found = 0; | 3661 | rc->extents_found = 0; |
@@ -3777,8 +3780,7 @@ restart: | |||
3777 | } | 3780 | } |
3778 | } | 3781 | } |
3779 | 3782 | ||
3780 | ret = btrfs_block_rsv_check(trans, rc->extent_root, | 3783 | ret = btrfs_block_rsv_check(rc->extent_root, rc->block_rsv, 5); |
3781 | rc->block_rsv, 0, 5); | ||
3782 | if (ret < 0) { | 3784 | if (ret < 0) { |
3783 | if (ret != -EAGAIN) { | 3785 | if (ret != -EAGAIN) { |
3784 | err = ret; | 3786 | err = ret; |