diff options
author | Chris Mason <chris.mason@oracle.com> | 2012-01-16 15:26:31 -0500 |
---|---|---|
committer | Chris Mason <chris.mason@oracle.com> | 2012-01-16 15:26:31 -0500 |
commit | 9785dbdf265ddc47d5c88267d89a97648c0dc14b (patch) | |
tree | 3a97a48d6f282f9e06c5446beeb886fcd86c4798 /fs/btrfs/extent-tree.c | |
parent | d756bd2d9339447c29bde950910586df8f8941ec (diff) | |
parent | 6bf7e080d5bcb0d399ee38ce3dabbfad64448192 (diff) |
Merge branch 'for-chris' of git://git.jan-o-sch.net/btrfs-unstable into integration
Diffstat (limited to 'fs/btrfs/extent-tree.c')
-rw-r--r-- | fs/btrfs/extent-tree.c | 187 |
1 files changed, 140 insertions, 47 deletions
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 1c1cf216be80..a44072a692ab 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c | |||
@@ -1871,20 +1871,24 @@ static int btrfs_discard_extent(struct btrfs_root *root, u64 bytenr, | |||
1871 | int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans, | 1871 | int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans, |
1872 | struct btrfs_root *root, | 1872 | struct btrfs_root *root, |
1873 | u64 bytenr, u64 num_bytes, u64 parent, | 1873 | u64 bytenr, u64 num_bytes, u64 parent, |
1874 | u64 root_objectid, u64 owner, u64 offset) | 1874 | u64 root_objectid, u64 owner, u64 offset, int for_cow) |
1875 | { | 1875 | { |
1876 | int ret; | 1876 | int ret; |
1877 | struct btrfs_fs_info *fs_info = root->fs_info; | ||
1878 | |||
1877 | BUG_ON(owner < BTRFS_FIRST_FREE_OBJECTID && | 1879 | BUG_ON(owner < BTRFS_FIRST_FREE_OBJECTID && |
1878 | root_objectid == BTRFS_TREE_LOG_OBJECTID); | 1880 | root_objectid == BTRFS_TREE_LOG_OBJECTID); |
1879 | 1881 | ||
1880 | if (owner < BTRFS_FIRST_FREE_OBJECTID) { | 1882 | if (owner < BTRFS_FIRST_FREE_OBJECTID) { |
1881 | ret = btrfs_add_delayed_tree_ref(trans, bytenr, num_bytes, | 1883 | ret = btrfs_add_delayed_tree_ref(fs_info, trans, bytenr, |
1884 | num_bytes, | ||
1882 | parent, root_objectid, (int)owner, | 1885 | parent, root_objectid, (int)owner, |
1883 | BTRFS_ADD_DELAYED_REF, NULL); | 1886 | BTRFS_ADD_DELAYED_REF, NULL, for_cow); |
1884 | } else { | 1887 | } else { |
1885 | ret = btrfs_add_delayed_data_ref(trans, bytenr, num_bytes, | 1888 | ret = btrfs_add_delayed_data_ref(fs_info, trans, bytenr, |
1889 | num_bytes, | ||
1886 | parent, root_objectid, owner, offset, | 1890 | parent, root_objectid, owner, offset, |
1887 | BTRFS_ADD_DELAYED_REF, NULL); | 1891 | BTRFS_ADD_DELAYED_REF, NULL, for_cow); |
1888 | } | 1892 | } |
1889 | return ret; | 1893 | return ret; |
1890 | } | 1894 | } |
@@ -2232,6 +2236,28 @@ static noinline int run_clustered_refs(struct btrfs_trans_handle *trans, | |||
2232 | } | 2236 | } |
2233 | 2237 | ||
2234 | /* | 2238 | /* |
2239 | * locked_ref is the head node, so we have to go one | ||
2240 | * node back for any delayed ref updates | ||
2241 | */ | ||
2242 | ref = select_delayed_ref(locked_ref); | ||
2243 | |||
2244 | if (ref && ref->seq && | ||
2245 | btrfs_check_delayed_seq(delayed_refs, ref->seq)) { | ||
2246 | /* | ||
2247 | * there are still refs with lower seq numbers in the | ||
2248 | * process of being added. Don't run this ref yet. | ||
2249 | */ | ||
2250 | list_del_init(&locked_ref->cluster); | ||
2251 | mutex_unlock(&locked_ref->mutex); | ||
2252 | locked_ref = NULL; | ||
2253 | delayed_refs->num_heads_ready++; | ||
2254 | spin_unlock(&delayed_refs->lock); | ||
2255 | cond_resched(); | ||
2256 | spin_lock(&delayed_refs->lock); | ||
2257 | continue; | ||
2258 | } | ||
2259 | |||
2260 | /* | ||
2235 | * record the must insert reserved flag before we | 2261 | * record the must insert reserved flag before we |
2236 | * drop the spin lock. | 2262 | * drop the spin lock. |
2237 | */ | 2263 | */ |
@@ -2241,11 +2267,6 @@ static noinline int run_clustered_refs(struct btrfs_trans_handle *trans, | |||
2241 | extent_op = locked_ref->extent_op; | 2267 | extent_op = locked_ref->extent_op; |
2242 | locked_ref->extent_op = NULL; | 2268 | locked_ref->extent_op = NULL; |
2243 | 2269 | ||
2244 | /* | ||
2245 | * locked_ref is the head node, so we have to go one | ||
2246 | * node back for any delayed ref updates | ||
2247 | */ | ||
2248 | ref = select_delayed_ref(locked_ref); | ||
2249 | if (!ref) { | 2270 | if (!ref) { |
2250 | /* All delayed refs have been processed, Go ahead | 2271 | /* All delayed refs have been processed, Go ahead |
2251 | * and send the head node to run_one_delayed_ref, | 2272 | * and send the head node to run_one_delayed_ref, |
@@ -2276,7 +2297,12 @@ static noinline int run_clustered_refs(struct btrfs_trans_handle *trans, | |||
2276 | ref->in_tree = 0; | 2297 | ref->in_tree = 0; |
2277 | rb_erase(&ref->rb_node, &delayed_refs->root); | 2298 | rb_erase(&ref->rb_node, &delayed_refs->root); |
2278 | delayed_refs->num_entries--; | 2299 | delayed_refs->num_entries--; |
2279 | 2300 | /* | |
2301 | * we modified num_entries, but as we're currently running | ||
2302 | * delayed refs, skip | ||
2303 | * wake_up(&delayed_refs->seq_wait); | ||
2304 | * here. | ||
2305 | */ | ||
2280 | spin_unlock(&delayed_refs->lock); | 2306 | spin_unlock(&delayed_refs->lock); |
2281 | 2307 | ||
2282 | ret = run_one_delayed_ref(trans, root, ref, extent_op, | 2308 | ret = run_one_delayed_ref(trans, root, ref, extent_op, |
@@ -2297,6 +2323,23 @@ next: | |||
2297 | return count; | 2323 | return count; |
2298 | } | 2324 | } |
2299 | 2325 | ||
2326 | |||
2327 | static void wait_for_more_refs(struct btrfs_delayed_ref_root *delayed_refs, | ||
2328 | unsigned long num_refs) | ||
2329 | { | ||
2330 | struct list_head *first_seq = delayed_refs->seq_head.next; | ||
2331 | |||
2332 | spin_unlock(&delayed_refs->lock); | ||
2333 | pr_debug("waiting for more refs (num %ld, first %p)\n", | ||
2334 | num_refs, first_seq); | ||
2335 | wait_event(delayed_refs->seq_wait, | ||
2336 | num_refs != delayed_refs->num_entries || | ||
2337 | delayed_refs->seq_head.next != first_seq); | ||
2338 | pr_debug("done waiting for more refs (num %ld, first %p)\n", | ||
2339 | delayed_refs->num_entries, delayed_refs->seq_head.next); | ||
2340 | spin_lock(&delayed_refs->lock); | ||
2341 | } | ||
2342 | |||
2300 | /* | 2343 | /* |
2301 | * this starts processing the delayed reference count updates and | 2344 | * this starts processing the delayed reference count updates and |
2302 | * extent insertions we have queued up so far. count can be | 2345 | * extent insertions we have queued up so far. count can be |
@@ -2312,8 +2355,11 @@ int btrfs_run_delayed_refs(struct btrfs_trans_handle *trans, | |||
2312 | struct btrfs_delayed_ref_node *ref; | 2355 | struct btrfs_delayed_ref_node *ref; |
2313 | struct list_head cluster; | 2356 | struct list_head cluster; |
2314 | int ret; | 2357 | int ret; |
2358 | u64 delayed_start; | ||
2315 | int run_all = count == (unsigned long)-1; | 2359 | int run_all = count == (unsigned long)-1; |
2316 | int run_most = 0; | 2360 | int run_most = 0; |
2361 | unsigned long num_refs = 0; | ||
2362 | int consider_waiting; | ||
2317 | 2363 | ||
2318 | if (root == root->fs_info->extent_root) | 2364 | if (root == root->fs_info->extent_root) |
2319 | root = root->fs_info->tree_root; | 2365 | root = root->fs_info->tree_root; |
@@ -2325,6 +2371,7 @@ int btrfs_run_delayed_refs(struct btrfs_trans_handle *trans, | |||
2325 | delayed_refs = &trans->transaction->delayed_refs; | 2371 | delayed_refs = &trans->transaction->delayed_refs; |
2326 | INIT_LIST_HEAD(&cluster); | 2372 | INIT_LIST_HEAD(&cluster); |
2327 | again: | 2373 | again: |
2374 | consider_waiting = 0; | ||
2328 | spin_lock(&delayed_refs->lock); | 2375 | spin_lock(&delayed_refs->lock); |
2329 | if (count == 0) { | 2376 | if (count == 0) { |
2330 | count = delayed_refs->num_entries * 2; | 2377 | count = delayed_refs->num_entries * 2; |
@@ -2341,11 +2388,35 @@ again: | |||
2341 | * of refs to process starting at the first one we are able to | 2388 | * of refs to process starting at the first one we are able to |
2342 | * lock | 2389 | * lock |
2343 | */ | 2390 | */ |
2391 | delayed_start = delayed_refs->run_delayed_start; | ||
2344 | ret = btrfs_find_ref_cluster(trans, &cluster, | 2392 | ret = btrfs_find_ref_cluster(trans, &cluster, |
2345 | delayed_refs->run_delayed_start); | 2393 | delayed_refs->run_delayed_start); |
2346 | if (ret) | 2394 | if (ret) |
2347 | break; | 2395 | break; |
2348 | 2396 | ||
2397 | if (delayed_start >= delayed_refs->run_delayed_start) { | ||
2398 | if (consider_waiting == 0) { | ||
2399 | /* | ||
2400 | * btrfs_find_ref_cluster looped. let's do one | ||
2401 | * more cycle. if we don't run any delayed ref | ||
2402 | * during that cycle (because we can't because | ||
2403 | * all of them are blocked) and if the number of | ||
2404 | * refs doesn't change, we avoid busy waiting. | ||
2405 | */ | ||
2406 | consider_waiting = 1; | ||
2407 | num_refs = delayed_refs->num_entries; | ||
2408 | } else { | ||
2409 | wait_for_more_refs(delayed_refs, num_refs); | ||
2410 | /* | ||
2411 | * after waiting, things have changed. we | ||
2412 | * dropped the lock and someone else might have | ||
2413 | * run some refs, built new clusters and so on. | ||
2414 | * therefore, we restart staleness detection. | ||
2415 | */ | ||
2416 | consider_waiting = 0; | ||
2417 | } | ||
2418 | } | ||
2419 | |||
2349 | ret = run_clustered_refs(trans, root, &cluster); | 2420 | ret = run_clustered_refs(trans, root, &cluster); |
2350 | BUG_ON(ret < 0); | 2421 | BUG_ON(ret < 0); |
2351 | 2422 | ||
@@ -2353,6 +2424,11 @@ again: | |||
2353 | 2424 | ||
2354 | if (count == 0) | 2425 | if (count == 0) |
2355 | break; | 2426 | break; |
2427 | |||
2428 | if (ret || delayed_refs->run_delayed_start == 0) { | ||
2429 | /* refs were run, let's reset staleness detection */ | ||
2430 | consider_waiting = 0; | ||
2431 | } | ||
2356 | } | 2432 | } |
2357 | 2433 | ||
2358 | if (run_all) { | 2434 | if (run_all) { |
@@ -2410,7 +2486,8 @@ int btrfs_set_disk_extent_flags(struct btrfs_trans_handle *trans, | |||
2410 | extent_op->update_key = 0; | 2486 | extent_op->update_key = 0; |
2411 | extent_op->is_data = is_data ? 1 : 0; | 2487 | extent_op->is_data = is_data ? 1 : 0; |
2412 | 2488 | ||
2413 | ret = btrfs_add_delayed_extent_op(trans, bytenr, num_bytes, extent_op); | 2489 | ret = btrfs_add_delayed_extent_op(root->fs_info, trans, bytenr, |
2490 | num_bytes, extent_op); | ||
2414 | if (ret) | 2491 | if (ret) |
2415 | kfree(extent_op); | 2492 | kfree(extent_op); |
2416 | return ret; | 2493 | return ret; |
@@ -2595,7 +2672,7 @@ out: | |||
2595 | static int __btrfs_mod_ref(struct btrfs_trans_handle *trans, | 2672 | static int __btrfs_mod_ref(struct btrfs_trans_handle *trans, |
2596 | struct btrfs_root *root, | 2673 | struct btrfs_root *root, |
2597 | struct extent_buffer *buf, | 2674 | struct extent_buffer *buf, |
2598 | int full_backref, int inc) | 2675 | int full_backref, int inc, int for_cow) |
2599 | { | 2676 | { |
2600 | u64 bytenr; | 2677 | u64 bytenr; |
2601 | u64 num_bytes; | 2678 | u64 num_bytes; |
@@ -2608,7 +2685,7 @@ static int __btrfs_mod_ref(struct btrfs_trans_handle *trans, | |||
2608 | int level; | 2685 | int level; |
2609 | int ret = 0; | 2686 | int ret = 0; |
2610 | int (*process_func)(struct btrfs_trans_handle *, struct btrfs_root *, | 2687 | int (*process_func)(struct btrfs_trans_handle *, struct btrfs_root *, |
2611 | u64, u64, u64, u64, u64, u64); | 2688 | u64, u64, u64, u64, u64, u64, int); |
2612 | 2689 | ||
2613 | ref_root = btrfs_header_owner(buf); | 2690 | ref_root = btrfs_header_owner(buf); |
2614 | nritems = btrfs_header_nritems(buf); | 2691 | nritems = btrfs_header_nritems(buf); |
@@ -2645,14 +2722,15 @@ static int __btrfs_mod_ref(struct btrfs_trans_handle *trans, | |||
2645 | key.offset -= btrfs_file_extent_offset(buf, fi); | 2722 | key.offset -= btrfs_file_extent_offset(buf, fi); |
2646 | ret = process_func(trans, root, bytenr, num_bytes, | 2723 | ret = process_func(trans, root, bytenr, num_bytes, |
2647 | parent, ref_root, key.objectid, | 2724 | parent, ref_root, key.objectid, |
2648 | key.offset); | 2725 | key.offset, for_cow); |
2649 | if (ret) | 2726 | if (ret) |
2650 | goto fail; | 2727 | goto fail; |
2651 | } else { | 2728 | } else { |
2652 | bytenr = btrfs_node_blockptr(buf, i); | 2729 | bytenr = btrfs_node_blockptr(buf, i); |
2653 | num_bytes = btrfs_level_size(root, level - 1); | 2730 | num_bytes = btrfs_level_size(root, level - 1); |
2654 | ret = process_func(trans, root, bytenr, num_bytes, | 2731 | ret = process_func(trans, root, bytenr, num_bytes, |
2655 | parent, ref_root, level - 1, 0); | 2732 | parent, ref_root, level - 1, 0, |
2733 | for_cow); | ||
2656 | if (ret) | 2734 | if (ret) |
2657 | goto fail; | 2735 | goto fail; |
2658 | } | 2736 | } |
@@ -2664,15 +2742,15 @@ fail: | |||
2664 | } | 2742 | } |
2665 | 2743 | ||
2666 | int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root, | 2744 | int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root, |
2667 | struct extent_buffer *buf, int full_backref) | 2745 | struct extent_buffer *buf, int full_backref, int for_cow) |
2668 | { | 2746 | { |
2669 | return __btrfs_mod_ref(trans, root, buf, full_backref, 1); | 2747 | return __btrfs_mod_ref(trans, root, buf, full_backref, 1, for_cow); |
2670 | } | 2748 | } |
2671 | 2749 | ||
2672 | int btrfs_dec_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root, | 2750 | int btrfs_dec_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root, |
2673 | struct extent_buffer *buf, int full_backref) | 2751 | struct extent_buffer *buf, int full_backref, int for_cow) |
2674 | { | 2752 | { |
2675 | return __btrfs_mod_ref(trans, root, buf, full_backref, 0); | 2753 | return __btrfs_mod_ref(trans, root, buf, full_backref, 0, for_cow); |
2676 | } | 2754 | } |
2677 | 2755 | ||
2678 | static int write_one_cache_group(struct btrfs_trans_handle *trans, | 2756 | static int write_one_cache_group(struct btrfs_trans_handle *trans, |
@@ -4954,6 +5032,8 @@ static noinline int check_ref_cleanup(struct btrfs_trans_handle *trans, | |||
4954 | rb_erase(&head->node.rb_node, &delayed_refs->root); | 5032 | rb_erase(&head->node.rb_node, &delayed_refs->root); |
4955 | 5033 | ||
4956 | delayed_refs->num_entries--; | 5034 | delayed_refs->num_entries--; |
5035 | if (waitqueue_active(&delayed_refs->seq_wait)) | ||
5036 | wake_up(&delayed_refs->seq_wait); | ||
4957 | 5037 | ||
4958 | /* | 5038 | /* |
4959 | * we don't take a ref on the node because we're removing it from the | 5039 | * we don't take a ref on the node because we're removing it from the |
@@ -4981,16 +5061,17 @@ out: | |||
4981 | void btrfs_free_tree_block(struct btrfs_trans_handle *trans, | 5061 | void btrfs_free_tree_block(struct btrfs_trans_handle *trans, |
4982 | struct btrfs_root *root, | 5062 | struct btrfs_root *root, |
4983 | struct extent_buffer *buf, | 5063 | struct extent_buffer *buf, |
4984 | u64 parent, int last_ref) | 5064 | u64 parent, int last_ref, int for_cow) |
4985 | { | 5065 | { |
4986 | struct btrfs_block_group_cache *cache = NULL; | 5066 | struct btrfs_block_group_cache *cache = NULL; |
4987 | int ret; | 5067 | int ret; |
4988 | 5068 | ||
4989 | if (root->root_key.objectid != BTRFS_TREE_LOG_OBJECTID) { | 5069 | if (root->root_key.objectid != BTRFS_TREE_LOG_OBJECTID) { |
4990 | ret = btrfs_add_delayed_tree_ref(trans, buf->start, buf->len, | 5070 | ret = btrfs_add_delayed_tree_ref(root->fs_info, trans, |
4991 | parent, root->root_key.objectid, | 5071 | buf->start, buf->len, |
4992 | btrfs_header_level(buf), | 5072 | parent, root->root_key.objectid, |
4993 | BTRFS_DROP_DELAYED_REF, NULL); | 5073 | btrfs_header_level(buf), |
5074 | BTRFS_DROP_DELAYED_REF, NULL, for_cow); | ||
4994 | BUG_ON(ret); | 5075 | BUG_ON(ret); |
4995 | } | 5076 | } |
4996 | 5077 | ||
@@ -5025,12 +5106,12 @@ out: | |||
5025 | btrfs_put_block_group(cache); | 5106 | btrfs_put_block_group(cache); |
5026 | } | 5107 | } |
5027 | 5108 | ||
5028 | int btrfs_free_extent(struct btrfs_trans_handle *trans, | 5109 | int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root *root, |
5029 | struct btrfs_root *root, | 5110 | u64 bytenr, u64 num_bytes, u64 parent, u64 root_objectid, |
5030 | u64 bytenr, u64 num_bytes, u64 parent, | 5111 | u64 owner, u64 offset, int for_cow) |
5031 | u64 root_objectid, u64 owner, u64 offset) | ||
5032 | { | 5112 | { |
5033 | int ret; | 5113 | int ret; |
5114 | struct btrfs_fs_info *fs_info = root->fs_info; | ||
5034 | 5115 | ||
5035 | /* | 5116 | /* |
5036 | * tree log blocks never actually go into the extent allocation | 5117 | * tree log blocks never actually go into the extent allocation |
@@ -5042,14 +5123,17 @@ int btrfs_free_extent(struct btrfs_trans_handle *trans, | |||
5042 | btrfs_pin_extent(root, bytenr, num_bytes, 1); | 5123 | btrfs_pin_extent(root, bytenr, num_bytes, 1); |
5043 | ret = 0; | 5124 | ret = 0; |
5044 | } else if (owner < BTRFS_FIRST_FREE_OBJECTID) { | 5125 | } else if (owner < BTRFS_FIRST_FREE_OBJECTID) { |
5045 | ret = btrfs_add_delayed_tree_ref(trans, bytenr, num_bytes, | 5126 | ret = btrfs_add_delayed_tree_ref(fs_info, trans, bytenr, |
5127 | num_bytes, | ||
5046 | parent, root_objectid, (int)owner, | 5128 | parent, root_objectid, (int)owner, |
5047 | BTRFS_DROP_DELAYED_REF, NULL); | 5129 | BTRFS_DROP_DELAYED_REF, NULL, for_cow); |
5048 | BUG_ON(ret); | 5130 | BUG_ON(ret); |
5049 | } else { | 5131 | } else { |
5050 | ret = btrfs_add_delayed_data_ref(trans, bytenr, num_bytes, | 5132 | ret = btrfs_add_delayed_data_ref(fs_info, trans, bytenr, |
5051 | parent, root_objectid, owner, | 5133 | num_bytes, |
5052 | offset, BTRFS_DROP_DELAYED_REF, NULL); | 5134 | parent, root_objectid, owner, |
5135 | offset, BTRFS_DROP_DELAYED_REF, | ||
5136 | NULL, for_cow); | ||
5053 | BUG_ON(ret); | 5137 | BUG_ON(ret); |
5054 | } | 5138 | } |
5055 | return ret; | 5139 | return ret; |
@@ -5877,9 +5961,10 @@ int btrfs_alloc_reserved_file_extent(struct btrfs_trans_handle *trans, | |||
5877 | 5961 | ||
5878 | BUG_ON(root_objectid == BTRFS_TREE_LOG_OBJECTID); | 5962 | BUG_ON(root_objectid == BTRFS_TREE_LOG_OBJECTID); |
5879 | 5963 | ||
5880 | ret = btrfs_add_delayed_data_ref(trans, ins->objectid, ins->offset, | 5964 | ret = btrfs_add_delayed_data_ref(root->fs_info, trans, ins->objectid, |
5881 | 0, root_objectid, owner, offset, | 5965 | ins->offset, 0, |
5882 | BTRFS_ADD_DELAYED_EXTENT, NULL); | 5966 | root_objectid, owner, offset, |
5967 | BTRFS_ADD_DELAYED_EXTENT, NULL, 0); | ||
5883 | return ret; | 5968 | return ret; |
5884 | } | 5969 | } |
5885 | 5970 | ||
@@ -6049,7 +6134,7 @@ struct extent_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans, | |||
6049 | struct btrfs_root *root, u32 blocksize, | 6134 | struct btrfs_root *root, u32 blocksize, |
6050 | u64 parent, u64 root_objectid, | 6135 | u64 parent, u64 root_objectid, |
6051 | struct btrfs_disk_key *key, int level, | 6136 | struct btrfs_disk_key *key, int level, |
6052 | u64 hint, u64 empty_size) | 6137 | u64 hint, u64 empty_size, int for_cow) |
6053 | { | 6138 | { |
6054 | struct btrfs_key ins; | 6139 | struct btrfs_key ins; |
6055 | struct btrfs_block_rsv *block_rsv; | 6140 | struct btrfs_block_rsv *block_rsv; |
@@ -6093,10 +6178,11 @@ struct extent_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans, | |||
6093 | extent_op->update_flags = 1; | 6178 | extent_op->update_flags = 1; |
6094 | extent_op->is_data = 0; | 6179 | extent_op->is_data = 0; |
6095 | 6180 | ||
6096 | ret = btrfs_add_delayed_tree_ref(trans, ins.objectid, | 6181 | ret = btrfs_add_delayed_tree_ref(root->fs_info, trans, |
6182 | ins.objectid, | ||
6097 | ins.offset, parent, root_objectid, | 6183 | ins.offset, parent, root_objectid, |
6098 | level, BTRFS_ADD_DELAYED_EXTENT, | 6184 | level, BTRFS_ADD_DELAYED_EXTENT, |
6099 | extent_op); | 6185 | extent_op, for_cow); |
6100 | BUG_ON(ret); | 6186 | BUG_ON(ret); |
6101 | } | 6187 | } |
6102 | return buf; | 6188 | return buf; |
@@ -6113,6 +6199,7 @@ struct walk_control { | |||
6113 | int keep_locks; | 6199 | int keep_locks; |
6114 | int reada_slot; | 6200 | int reada_slot; |
6115 | int reada_count; | 6201 | int reada_count; |
6202 | int for_reloc; | ||
6116 | }; | 6203 | }; |
6117 | 6204 | ||
6118 | #define DROP_REFERENCE 1 | 6205 | #define DROP_REFERENCE 1 |
@@ -6251,9 +6338,9 @@ static noinline int walk_down_proc(struct btrfs_trans_handle *trans, | |||
6251 | /* wc->stage == UPDATE_BACKREF */ | 6338 | /* wc->stage == UPDATE_BACKREF */ |
6252 | if (!(wc->flags[level] & flag)) { | 6339 | if (!(wc->flags[level] & flag)) { |
6253 | BUG_ON(!path->locks[level]); | 6340 | BUG_ON(!path->locks[level]); |
6254 | ret = btrfs_inc_ref(trans, root, eb, 1); | 6341 | ret = btrfs_inc_ref(trans, root, eb, 1, wc->for_reloc); |
6255 | BUG_ON(ret); | 6342 | BUG_ON(ret); |
6256 | ret = btrfs_dec_ref(trans, root, eb, 0); | 6343 | ret = btrfs_dec_ref(trans, root, eb, 0, wc->for_reloc); |
6257 | BUG_ON(ret); | 6344 | BUG_ON(ret); |
6258 | ret = btrfs_set_disk_extent_flags(trans, root, eb->start, | 6345 | ret = btrfs_set_disk_extent_flags(trans, root, eb->start, |
6259 | eb->len, flag, 0); | 6346 | eb->len, flag, 0); |
@@ -6397,7 +6484,7 @@ skip: | |||
6397 | } | 6484 | } |
6398 | 6485 | ||
6399 | ret = btrfs_free_extent(trans, root, bytenr, blocksize, parent, | 6486 | ret = btrfs_free_extent(trans, root, bytenr, blocksize, parent, |
6400 | root->root_key.objectid, level - 1, 0); | 6487 | root->root_key.objectid, level - 1, 0, 0); |
6401 | BUG_ON(ret); | 6488 | BUG_ON(ret); |
6402 | } | 6489 | } |
6403 | btrfs_tree_unlock(next); | 6490 | btrfs_tree_unlock(next); |
@@ -6471,9 +6558,11 @@ static noinline int walk_up_proc(struct btrfs_trans_handle *trans, | |||
6471 | if (wc->refs[level] == 1) { | 6558 | if (wc->refs[level] == 1) { |
6472 | if (level == 0) { | 6559 | if (level == 0) { |
6473 | if (wc->flags[level] & BTRFS_BLOCK_FLAG_FULL_BACKREF) | 6560 | if (wc->flags[level] & BTRFS_BLOCK_FLAG_FULL_BACKREF) |
6474 | ret = btrfs_dec_ref(trans, root, eb, 1); | 6561 | ret = btrfs_dec_ref(trans, root, eb, 1, |
6562 | wc->for_reloc); | ||
6475 | else | 6563 | else |
6476 | ret = btrfs_dec_ref(trans, root, eb, 0); | 6564 | ret = btrfs_dec_ref(trans, root, eb, 0, |
6565 | wc->for_reloc); | ||
6477 | BUG_ON(ret); | 6566 | BUG_ON(ret); |
6478 | } | 6567 | } |
6479 | /* make block locked assertion in clean_tree_block happy */ | 6568 | /* make block locked assertion in clean_tree_block happy */ |
@@ -6500,7 +6589,7 @@ static noinline int walk_up_proc(struct btrfs_trans_handle *trans, | |||
6500 | btrfs_header_owner(path->nodes[level + 1])); | 6589 | btrfs_header_owner(path->nodes[level + 1])); |
6501 | } | 6590 | } |
6502 | 6591 | ||
6503 | btrfs_free_tree_block(trans, root, eb, parent, wc->refs[level] == 1); | 6592 | btrfs_free_tree_block(trans, root, eb, parent, wc->refs[level] == 1, 0); |
6504 | out: | 6593 | out: |
6505 | wc->refs[level] = 0; | 6594 | wc->refs[level] = 0; |
6506 | wc->flags[level] = 0; | 6595 | wc->flags[level] = 0; |
@@ -6584,7 +6673,8 @@ static noinline int walk_up_tree(struct btrfs_trans_handle *trans, | |||
6584 | * blocks are properly updated. | 6673 | * blocks are properly updated. |
6585 | */ | 6674 | */ |
6586 | void btrfs_drop_snapshot(struct btrfs_root *root, | 6675 | void btrfs_drop_snapshot(struct btrfs_root *root, |
6587 | struct btrfs_block_rsv *block_rsv, int update_ref) | 6676 | struct btrfs_block_rsv *block_rsv, int update_ref, |
6677 | int for_reloc) | ||
6588 | { | 6678 | { |
6589 | struct btrfs_path *path; | 6679 | struct btrfs_path *path; |
6590 | struct btrfs_trans_handle *trans; | 6680 | struct btrfs_trans_handle *trans; |
@@ -6672,6 +6762,7 @@ void btrfs_drop_snapshot(struct btrfs_root *root, | |||
6672 | wc->stage = DROP_REFERENCE; | 6762 | wc->stage = DROP_REFERENCE; |
6673 | wc->update_ref = update_ref; | 6763 | wc->update_ref = update_ref; |
6674 | wc->keep_locks = 0; | 6764 | wc->keep_locks = 0; |
6765 | wc->for_reloc = for_reloc; | ||
6675 | wc->reada_count = BTRFS_NODEPTRS_PER_BLOCK(root); | 6766 | wc->reada_count = BTRFS_NODEPTRS_PER_BLOCK(root); |
6676 | 6767 | ||
6677 | while (1) { | 6768 | while (1) { |
@@ -6756,6 +6847,7 @@ out: | |||
6756 | * drop subtree rooted at tree block 'node'. | 6847 | * drop subtree rooted at tree block 'node'. |
6757 | * | 6848 | * |
6758 | * NOTE: this function will unlock and release tree block 'node' | 6849 | * NOTE: this function will unlock and release tree block 'node' |
6850 | * only used by relocation code | ||
6759 | */ | 6851 | */ |
6760 | int btrfs_drop_subtree(struct btrfs_trans_handle *trans, | 6852 | int btrfs_drop_subtree(struct btrfs_trans_handle *trans, |
6761 | struct btrfs_root *root, | 6853 | struct btrfs_root *root, |
@@ -6800,6 +6892,7 @@ int btrfs_drop_subtree(struct btrfs_trans_handle *trans, | |||
6800 | wc->stage = DROP_REFERENCE; | 6892 | wc->stage = DROP_REFERENCE; |
6801 | wc->update_ref = 0; | 6893 | wc->update_ref = 0; |
6802 | wc->keep_locks = 1; | 6894 | wc->keep_locks = 1; |
6895 | wc->for_reloc = 1; | ||
6803 | wc->reada_count = BTRFS_NODEPTRS_PER_BLOCK(root); | 6896 | wc->reada_count = BTRFS_NODEPTRS_PER_BLOCK(root); |
6804 | 6897 | ||
6805 | while (1) { | 6898 | while (1) { |