diff options
Diffstat (limited to 'fs/btrfs/extent-tree.c')
| -rw-r--r-- | fs/btrfs/extent-tree.c | 184 |
1 files changed, 122 insertions, 62 deletions
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 1204c8ef6f32..cfb3cf711b34 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c | |||
| @@ -113,7 +113,8 @@ static noinline int | |||
| 113 | block_group_cache_done(struct btrfs_block_group_cache *cache) | 113 | block_group_cache_done(struct btrfs_block_group_cache *cache) |
| 114 | { | 114 | { |
| 115 | smp_mb(); | 115 | smp_mb(); |
| 116 | return cache->cached == BTRFS_CACHE_FINISHED; | 116 | return cache->cached == BTRFS_CACHE_FINISHED || |
| 117 | cache->cached == BTRFS_CACHE_ERROR; | ||
| 117 | } | 118 | } |
| 118 | 119 | ||
| 119 | static int block_group_bits(struct btrfs_block_group_cache *cache, u64 bits) | 120 | static int block_group_bits(struct btrfs_block_group_cache *cache, u64 bits) |
| @@ -389,7 +390,7 @@ static noinline void caching_thread(struct btrfs_work *work) | |||
| 389 | u64 total_found = 0; | 390 | u64 total_found = 0; |
| 390 | u64 last = 0; | 391 | u64 last = 0; |
| 391 | u32 nritems; | 392 | u32 nritems; |
| 392 | int ret = 0; | 393 | int ret = -ENOMEM; |
| 393 | 394 | ||
| 394 | caching_ctl = container_of(work, struct btrfs_caching_control, work); | 395 | caching_ctl = container_of(work, struct btrfs_caching_control, work); |
| 395 | block_group = caching_ctl->block_group; | 396 | block_group = caching_ctl->block_group; |
| @@ -420,6 +421,7 @@ again: | |||
| 420 | /* need to make sure the commit_root doesn't disappear */ | 421 | /* need to make sure the commit_root doesn't disappear */ |
| 421 | down_read(&fs_info->extent_commit_sem); | 422 | down_read(&fs_info->extent_commit_sem); |
| 422 | 423 | ||
| 424 | next: | ||
| 423 | ret = btrfs_search_slot(NULL, extent_root, &key, path, 0, 0); | 425 | ret = btrfs_search_slot(NULL, extent_root, &key, path, 0, 0); |
| 424 | if (ret < 0) | 426 | if (ret < 0) |
| 425 | goto err; | 427 | goto err; |
| @@ -459,6 +461,16 @@ again: | |||
| 459 | continue; | 461 | continue; |
| 460 | } | 462 | } |
| 461 | 463 | ||
| 464 | if (key.objectid < last) { | ||
| 465 | key.objectid = last; | ||
| 466 | key.offset = 0; | ||
| 467 | key.type = BTRFS_EXTENT_ITEM_KEY; | ||
| 468 | |||
| 469 | caching_ctl->progress = last; | ||
| 470 | btrfs_release_path(path); | ||
| 471 | goto next; | ||
| 472 | } | ||
| 473 | |||
| 462 | if (key.objectid < block_group->key.objectid) { | 474 | if (key.objectid < block_group->key.objectid) { |
| 463 | path->slots[0]++; | 475 | path->slots[0]++; |
| 464 | continue; | 476 | continue; |
| @@ -506,6 +518,12 @@ err: | |||
| 506 | 518 | ||
| 507 | mutex_unlock(&caching_ctl->mutex); | 519 | mutex_unlock(&caching_ctl->mutex); |
| 508 | out: | 520 | out: |
| 521 | if (ret) { | ||
| 522 | spin_lock(&block_group->lock); | ||
| 523 | block_group->caching_ctl = NULL; | ||
| 524 | block_group->cached = BTRFS_CACHE_ERROR; | ||
| 525 | spin_unlock(&block_group->lock); | ||
| 526 | } | ||
| 509 | wake_up(&caching_ctl->wait); | 527 | wake_up(&caching_ctl->wait); |
| 510 | 528 | ||
| 511 | put_caching_control(caching_ctl); | 529 | put_caching_control(caching_ctl); |
| @@ -771,10 +789,23 @@ again: | |||
| 771 | goto out_free; | 789 | goto out_free; |
| 772 | 790 | ||
| 773 | if (ret > 0 && metadata && key.type == BTRFS_METADATA_ITEM_KEY) { | 791 | if (ret > 0 && metadata && key.type == BTRFS_METADATA_ITEM_KEY) { |
| 774 | key.type = BTRFS_EXTENT_ITEM_KEY; | 792 | metadata = 0; |
| 775 | key.offset = root->leafsize; | 793 | if (path->slots[0]) { |
| 776 | btrfs_release_path(path); | 794 | path->slots[0]--; |
| 777 | goto again; | 795 | btrfs_item_key_to_cpu(path->nodes[0], &key, |
| 796 | path->slots[0]); | ||
| 797 | if (key.objectid == bytenr && | ||
| 798 | key.type == BTRFS_EXTENT_ITEM_KEY && | ||
| 799 | key.offset == root->leafsize) | ||
| 800 | ret = 0; | ||
| 801 | } | ||
| 802 | if (ret) { | ||
| 803 | key.objectid = bytenr; | ||
| 804 | key.type = BTRFS_EXTENT_ITEM_KEY; | ||
| 805 | key.offset = root->leafsize; | ||
| 806 | btrfs_release_path(path); | ||
| 807 | goto again; | ||
| 808 | } | ||
| 778 | } | 809 | } |
| 779 | 810 | ||
| 780 | if (ret == 0) { | 811 | if (ret == 0) { |
| @@ -2011,6 +2042,8 @@ static int run_delayed_data_ref(struct btrfs_trans_handle *trans, | |||
| 2011 | ins.type = BTRFS_EXTENT_ITEM_KEY; | 2042 | ins.type = BTRFS_EXTENT_ITEM_KEY; |
| 2012 | 2043 | ||
| 2013 | ref = btrfs_delayed_node_to_data_ref(node); | 2044 | ref = btrfs_delayed_node_to_data_ref(node); |
| 2045 | trace_run_delayed_data_ref(node, ref, node->action); | ||
| 2046 | |||
| 2014 | if (node->type == BTRFS_SHARED_DATA_REF_KEY) | 2047 | if (node->type == BTRFS_SHARED_DATA_REF_KEY) |
| 2015 | parent = ref->parent; | 2048 | parent = ref->parent; |
| 2016 | else | 2049 | else |
| @@ -2154,6 +2187,8 @@ static int run_delayed_tree_ref(struct btrfs_trans_handle *trans, | |||
| 2154 | SKINNY_METADATA); | 2187 | SKINNY_METADATA); |
| 2155 | 2188 | ||
| 2156 | ref = btrfs_delayed_node_to_tree_ref(node); | 2189 | ref = btrfs_delayed_node_to_tree_ref(node); |
| 2190 | trace_run_delayed_tree_ref(node, ref, node->action); | ||
| 2191 | |||
| 2157 | if (node->type == BTRFS_SHARED_BLOCK_REF_KEY) | 2192 | if (node->type == BTRFS_SHARED_BLOCK_REF_KEY) |
| 2158 | parent = ref->parent; | 2193 | parent = ref->parent; |
| 2159 | else | 2194 | else |
| @@ -2212,6 +2247,8 @@ static int run_one_delayed_ref(struct btrfs_trans_handle *trans, | |||
| 2212 | */ | 2247 | */ |
| 2213 | BUG_ON(extent_op); | 2248 | BUG_ON(extent_op); |
| 2214 | head = btrfs_delayed_node_to_head(node); | 2249 | head = btrfs_delayed_node_to_head(node); |
| 2250 | trace_run_delayed_ref_head(node, head, node->action); | ||
| 2251 | |||
| 2215 | if (insert_reserved) { | 2252 | if (insert_reserved) { |
| 2216 | btrfs_pin_extent(root, node->bytenr, | 2253 | btrfs_pin_extent(root, node->bytenr, |
| 2217 | node->num_bytes, 1); | 2254 | node->num_bytes, 1); |
| @@ -2403,6 +2440,8 @@ static noinline int run_clustered_refs(struct btrfs_trans_handle *trans, | |||
| 2403 | default: | 2440 | default: |
| 2404 | WARN_ON(1); | 2441 | WARN_ON(1); |
| 2405 | } | 2442 | } |
| 2443 | } else { | ||
| 2444 | list_del_init(&locked_ref->cluster); | ||
| 2406 | } | 2445 | } |
| 2407 | spin_unlock(&delayed_refs->lock); | 2446 | spin_unlock(&delayed_refs->lock); |
| 2408 | 2447 | ||
| @@ -2425,7 +2464,6 @@ static noinline int run_clustered_refs(struct btrfs_trans_handle *trans, | |||
| 2425 | * list before we release it. | 2464 | * list before we release it. |
| 2426 | */ | 2465 | */ |
| 2427 | if (btrfs_delayed_ref_is_head(ref)) { | 2466 | if (btrfs_delayed_ref_is_head(ref)) { |
| 2428 | list_del_init(&locked_ref->cluster); | ||
| 2429 | btrfs_delayed_ref_unlock(locked_ref); | 2467 | btrfs_delayed_ref_unlock(locked_ref); |
| 2430 | locked_ref = NULL; | 2468 | locked_ref = NULL; |
| 2431 | } | 2469 | } |
| @@ -3799,8 +3837,12 @@ again: | |||
| 3799 | if (force < space_info->force_alloc) | 3837 | if (force < space_info->force_alloc) |
| 3800 | force = space_info->force_alloc; | 3838 | force = space_info->force_alloc; |
| 3801 | if (space_info->full) { | 3839 | if (space_info->full) { |
| 3840 | if (should_alloc_chunk(extent_root, space_info, force)) | ||
| 3841 | ret = -ENOSPC; | ||
| 3842 | else | ||
| 3843 | ret = 0; | ||
| 3802 | spin_unlock(&space_info->lock); | 3844 | spin_unlock(&space_info->lock); |
| 3803 | return 0; | 3845 | return ret; |
| 3804 | } | 3846 | } |
| 3805 | 3847 | ||
| 3806 | if (!should_alloc_chunk(extent_root, space_info, force)) { | 3848 | if (!should_alloc_chunk(extent_root, space_info, force)) { |
| @@ -4320,6 +4362,9 @@ static struct btrfs_block_rsv *get_block_rsv( | |||
| 4320 | if (root == root->fs_info->csum_root && trans->adding_csums) | 4362 | if (root == root->fs_info->csum_root && trans->adding_csums) |
| 4321 | block_rsv = trans->block_rsv; | 4363 | block_rsv = trans->block_rsv; |
| 4322 | 4364 | ||
| 4365 | if (root == root->fs_info->uuid_root) | ||
| 4366 | block_rsv = trans->block_rsv; | ||
| 4367 | |||
| 4323 | if (!block_rsv) | 4368 | if (!block_rsv) |
| 4324 | block_rsv = root->block_rsv; | 4369 | block_rsv = root->block_rsv; |
| 4325 | 4370 | ||
| @@ -4729,10 +4774,12 @@ void btrfs_orphan_release_metadata(struct inode *inode) | |||
| 4729 | int btrfs_subvolume_reserve_metadata(struct btrfs_root *root, | 4774 | int btrfs_subvolume_reserve_metadata(struct btrfs_root *root, |
| 4730 | struct btrfs_block_rsv *rsv, | 4775 | struct btrfs_block_rsv *rsv, |
| 4731 | int items, | 4776 | int items, |
| 4732 | u64 *qgroup_reserved) | 4777 | u64 *qgroup_reserved, |
| 4778 | bool use_global_rsv) | ||
| 4733 | { | 4779 | { |
| 4734 | u64 num_bytes; | 4780 | u64 num_bytes; |
| 4735 | int ret; | 4781 | int ret; |
| 4782 | struct btrfs_block_rsv *global_rsv = &root->fs_info->global_block_rsv; | ||
| 4736 | 4783 | ||
| 4737 | if (root->fs_info->quota_enabled) { | 4784 | if (root->fs_info->quota_enabled) { |
| 4738 | /* One for parent inode, two for dir entries */ | 4785 | /* One for parent inode, two for dir entries */ |
| @@ -4751,6 +4798,10 @@ int btrfs_subvolume_reserve_metadata(struct btrfs_root *root, | |||
| 4751 | BTRFS_BLOCK_GROUP_METADATA); | 4798 | BTRFS_BLOCK_GROUP_METADATA); |
| 4752 | ret = btrfs_block_rsv_add(root, rsv, num_bytes, | 4799 | ret = btrfs_block_rsv_add(root, rsv, num_bytes, |
| 4753 | BTRFS_RESERVE_FLUSH_ALL); | 4800 | BTRFS_RESERVE_FLUSH_ALL); |
| 4801 | |||
| 4802 | if (ret == -ENOSPC && use_global_rsv) | ||
| 4803 | ret = btrfs_block_rsv_migrate(global_rsv, rsv, num_bytes); | ||
| 4804 | |||
| 4754 | if (ret) { | 4805 | if (ret) { |
| 4755 | if (*qgroup_reserved) | 4806 | if (*qgroup_reserved) |
| 4756 | btrfs_qgroup_free(root, *qgroup_reserved); | 4807 | btrfs_qgroup_free(root, *qgroup_reserved); |
| @@ -5668,7 +5719,7 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans, | |||
| 5668 | 5719 | ||
| 5669 | if (ret) { | 5720 | if (ret) { |
| 5670 | btrfs_err(info, "umm, got %d back from search, was looking for %llu", | 5721 | btrfs_err(info, "umm, got %d back from search, was looking for %llu", |
| 5671 | ret, (unsigned long long)bytenr); | 5722 | ret, bytenr); |
| 5672 | if (ret > 0) | 5723 | if (ret > 0) |
| 5673 | btrfs_print_leaf(extent_root, | 5724 | btrfs_print_leaf(extent_root, |
| 5674 | path->nodes[0]); | 5725 | path->nodes[0]); |
| @@ -5684,11 +5735,8 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans, | |||
| 5684 | WARN_ON(1); | 5735 | WARN_ON(1); |
| 5685 | btrfs_err(info, | 5736 | btrfs_err(info, |
| 5686 | "unable to find ref byte nr %llu parent %llu root %llu owner %llu offset %llu", | 5737 | "unable to find ref byte nr %llu parent %llu root %llu owner %llu offset %llu", |
| 5687 | (unsigned long long)bytenr, | 5738 | bytenr, parent, root_objectid, owner_objectid, |
| 5688 | (unsigned long long)parent, | 5739 | owner_offset); |
| 5689 | (unsigned long long)root_objectid, | ||
| 5690 | (unsigned long long)owner_objectid, | ||
| 5691 | (unsigned long long)owner_offset); | ||
| 5692 | } else { | 5740 | } else { |
| 5693 | btrfs_abort_transaction(trans, extent_root, ret); | 5741 | btrfs_abort_transaction(trans, extent_root, ret); |
| 5694 | goto out; | 5742 | goto out; |
| @@ -5717,7 +5765,7 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans, | |||
| 5717 | -1, 1); | 5765 | -1, 1); |
| 5718 | if (ret) { | 5766 | if (ret) { |
| 5719 | btrfs_err(info, "umm, got %d back from search, was looking for %llu", | 5767 | btrfs_err(info, "umm, got %d back from search, was looking for %llu", |
| 5720 | ret, (unsigned long long)bytenr); | 5768 | ret, bytenr); |
| 5721 | btrfs_print_leaf(extent_root, path->nodes[0]); | 5769 | btrfs_print_leaf(extent_root, path->nodes[0]); |
| 5722 | } | 5770 | } |
| 5723 | if (ret < 0) { | 5771 | if (ret < 0) { |
| @@ -5999,8 +6047,11 @@ static u64 stripe_align(struct btrfs_root *root, | |||
| 5999 | * for our min num_bytes. Another option is to have it go ahead | 6047 | * for our min num_bytes. Another option is to have it go ahead |
| 6000 | * and look in the rbtree for a free extent of a given size, but this | 6048 | * and look in the rbtree for a free extent of a given size, but this |
| 6001 | * is a good start. | 6049 | * is a good start. |
| 6050 | * | ||
| 6051 | * Callers of this must check if cache->cached == BTRFS_CACHE_ERROR before using | ||
| 6052 | * any of the information in this block group. | ||
| 6002 | */ | 6053 | */ |
| 6003 | static noinline int | 6054 | static noinline void |
| 6004 | wait_block_group_cache_progress(struct btrfs_block_group_cache *cache, | 6055 | wait_block_group_cache_progress(struct btrfs_block_group_cache *cache, |
| 6005 | u64 num_bytes) | 6056 | u64 num_bytes) |
| 6006 | { | 6057 | { |
| @@ -6008,28 +6059,29 @@ wait_block_group_cache_progress(struct btrfs_block_group_cache *cache, | |||
| 6008 | 6059 | ||
| 6009 | caching_ctl = get_caching_control(cache); | 6060 | caching_ctl = get_caching_control(cache); |
| 6010 | if (!caching_ctl) | 6061 | if (!caching_ctl) |
| 6011 | return 0; | 6062 | return; |
| 6012 | 6063 | ||
| 6013 | wait_event(caching_ctl->wait, block_group_cache_done(cache) || | 6064 | wait_event(caching_ctl->wait, block_group_cache_done(cache) || |
| 6014 | (cache->free_space_ctl->free_space >= num_bytes)); | 6065 | (cache->free_space_ctl->free_space >= num_bytes)); |
| 6015 | 6066 | ||
| 6016 | put_caching_control(caching_ctl); | 6067 | put_caching_control(caching_ctl); |
| 6017 | return 0; | ||
| 6018 | } | 6068 | } |
| 6019 | 6069 | ||
| 6020 | static noinline int | 6070 | static noinline int |
| 6021 | wait_block_group_cache_done(struct btrfs_block_group_cache *cache) | 6071 | wait_block_group_cache_done(struct btrfs_block_group_cache *cache) |
| 6022 | { | 6072 | { |
| 6023 | struct btrfs_caching_control *caching_ctl; | 6073 | struct btrfs_caching_control *caching_ctl; |
| 6074 | int ret = 0; | ||
| 6024 | 6075 | ||
| 6025 | caching_ctl = get_caching_control(cache); | 6076 | caching_ctl = get_caching_control(cache); |
| 6026 | if (!caching_ctl) | 6077 | if (!caching_ctl) |
| 6027 | return 0; | 6078 | return (cache->cached == BTRFS_CACHE_ERROR) ? -EIO : 0; |
| 6028 | 6079 | ||
| 6029 | wait_event(caching_ctl->wait, block_group_cache_done(cache)); | 6080 | wait_event(caching_ctl->wait, block_group_cache_done(cache)); |
| 6030 | 6081 | if (cache->cached == BTRFS_CACHE_ERROR) | |
| 6082 | ret = -EIO; | ||
| 6031 | put_caching_control(caching_ctl); | 6083 | put_caching_control(caching_ctl); |
| 6032 | return 0; | 6084 | return ret; |
| 6033 | } | 6085 | } |
| 6034 | 6086 | ||
| 6035 | int __get_raid_index(u64 flags) | 6087 | int __get_raid_index(u64 flags) |
| @@ -6070,8 +6122,7 @@ enum btrfs_loop_type { | |||
| 6070 | * ins->offset == number of blocks | 6122 | * ins->offset == number of blocks |
| 6071 | * Any available blocks before search_start are skipped. | 6123 | * Any available blocks before search_start are skipped. |
| 6072 | */ | 6124 | */ |
| 6073 | static noinline int find_free_extent(struct btrfs_trans_handle *trans, | 6125 | static noinline int find_free_extent(struct btrfs_root *orig_root, |
| 6074 | struct btrfs_root *orig_root, | ||
| 6075 | u64 num_bytes, u64 empty_size, | 6126 | u64 num_bytes, u64 empty_size, |
| 6076 | u64 hint_byte, struct btrfs_key *ins, | 6127 | u64 hint_byte, struct btrfs_key *ins, |
| 6077 | u64 flags) | 6128 | u64 flags) |
| @@ -6212,6 +6263,8 @@ have_block_group: | |||
| 6212 | ret = 0; | 6263 | ret = 0; |
| 6213 | } | 6264 | } |
| 6214 | 6265 | ||
| 6266 | if (unlikely(block_group->cached == BTRFS_CACHE_ERROR)) | ||
| 6267 | goto loop; | ||
| 6215 | if (unlikely(block_group->ro)) | 6268 | if (unlikely(block_group->ro)) |
| 6216 | goto loop; | 6269 | goto loop; |
| 6217 | 6270 | ||
| @@ -6292,10 +6345,10 @@ refill_cluster: | |||
| 6292 | block_group->full_stripe_len); | 6345 | block_group->full_stripe_len); |
| 6293 | 6346 | ||
| 6294 | /* allocate a cluster in this block group */ | 6347 | /* allocate a cluster in this block group */ |
| 6295 | ret = btrfs_find_space_cluster(trans, root, | 6348 | ret = btrfs_find_space_cluster(root, block_group, |
| 6296 | block_group, last_ptr, | 6349 | last_ptr, search_start, |
| 6297 | search_start, num_bytes, | 6350 | num_bytes, |
| 6298 | aligned_cluster); | 6351 | aligned_cluster); |
| 6299 | if (ret == 0) { | 6352 | if (ret == 0) { |
| 6300 | /* | 6353 | /* |
| 6301 | * now pull our allocation out of this | 6354 | * now pull our allocation out of this |
| @@ -6426,17 +6479,28 @@ loop: | |||
| 6426 | index = 0; | 6479 | index = 0; |
| 6427 | loop++; | 6480 | loop++; |
| 6428 | if (loop == LOOP_ALLOC_CHUNK) { | 6481 | if (loop == LOOP_ALLOC_CHUNK) { |
| 6482 | struct btrfs_trans_handle *trans; | ||
| 6483 | |||
| 6484 | trans = btrfs_join_transaction(root); | ||
| 6485 | if (IS_ERR(trans)) { | ||
| 6486 | ret = PTR_ERR(trans); | ||
| 6487 | goto out; | ||
| 6488 | } | ||
| 6489 | |||
| 6429 | ret = do_chunk_alloc(trans, root, flags, | 6490 | ret = do_chunk_alloc(trans, root, flags, |
| 6430 | CHUNK_ALLOC_FORCE); | 6491 | CHUNK_ALLOC_FORCE); |
| 6431 | /* | 6492 | /* |
| 6432 | * Do not bail out on ENOSPC since we | 6493 | * Do not bail out on ENOSPC since we |
| 6433 | * can do more things. | 6494 | * can do more things. |
| 6434 | */ | 6495 | */ |
| 6435 | if (ret < 0 && ret != -ENOSPC) { | 6496 | if (ret < 0 && ret != -ENOSPC) |
| 6436 | btrfs_abort_transaction(trans, | 6497 | btrfs_abort_transaction(trans, |
| 6437 | root, ret); | 6498 | root, ret); |
| 6499 | else | ||
| 6500 | ret = 0; | ||
| 6501 | btrfs_end_transaction(trans, root); | ||
| 6502 | if (ret) | ||
| 6438 | goto out; | 6503 | goto out; |
| 6439 | } | ||
| 6440 | } | 6504 | } |
| 6441 | 6505 | ||
| 6442 | if (loop == LOOP_NO_EMPTY_SIZE) { | 6506 | if (loop == LOOP_NO_EMPTY_SIZE) { |
| @@ -6463,19 +6527,15 @@ static void dump_space_info(struct btrfs_space_info *info, u64 bytes, | |||
| 6463 | 6527 | ||
| 6464 | spin_lock(&info->lock); | 6528 | spin_lock(&info->lock); |
| 6465 | printk(KERN_INFO "space_info %llu has %llu free, is %sfull\n", | 6529 | printk(KERN_INFO "space_info %llu has %llu free, is %sfull\n", |
| 6466 | (unsigned long long)info->flags, | 6530 | info->flags, |
| 6467 | (unsigned long long)(info->total_bytes - info->bytes_used - | 6531 | info->total_bytes - info->bytes_used - info->bytes_pinned - |
| 6468 | info->bytes_pinned - info->bytes_reserved - | 6532 | info->bytes_reserved - info->bytes_readonly, |
| 6469 | info->bytes_readonly), | ||
| 6470 | (info->full) ? "" : "not "); | 6533 | (info->full) ? "" : "not "); |
| 6471 | printk(KERN_INFO "space_info total=%llu, used=%llu, pinned=%llu, " | 6534 | printk(KERN_INFO "space_info total=%llu, used=%llu, pinned=%llu, " |
| 6472 | "reserved=%llu, may_use=%llu, readonly=%llu\n", | 6535 | "reserved=%llu, may_use=%llu, readonly=%llu\n", |
| 6473 | (unsigned long long)info->total_bytes, | 6536 | info->total_bytes, info->bytes_used, info->bytes_pinned, |
| 6474 | (unsigned long long)info->bytes_used, | 6537 | info->bytes_reserved, info->bytes_may_use, |
| 6475 | (unsigned long long)info->bytes_pinned, | 6538 | info->bytes_readonly); |
| 6476 | (unsigned long long)info->bytes_reserved, | ||
| 6477 | (unsigned long long)info->bytes_may_use, | ||
| 6478 | (unsigned long long)info->bytes_readonly); | ||
| 6479 | spin_unlock(&info->lock); | 6539 | spin_unlock(&info->lock); |
| 6480 | 6540 | ||
| 6481 | if (!dump_block_groups) | 6541 | if (!dump_block_groups) |
| @@ -6486,12 +6546,9 @@ again: | |||
| 6486 | list_for_each_entry(cache, &info->block_groups[index], list) { | 6546 | list_for_each_entry(cache, &info->block_groups[index], list) { |
| 6487 | spin_lock(&cache->lock); | 6547 | spin_lock(&cache->lock); |
| 6488 | printk(KERN_INFO "block group %llu has %llu bytes, %llu used %llu pinned %llu reserved %s\n", | 6548 | printk(KERN_INFO "block group %llu has %llu bytes, %llu used %llu pinned %llu reserved %s\n", |
| 6489 | (unsigned long long)cache->key.objectid, | 6549 | cache->key.objectid, cache->key.offset, |
| 6490 | (unsigned long long)cache->key.offset, | 6550 | btrfs_block_group_used(&cache->item), cache->pinned, |
| 6491 | (unsigned long long)btrfs_block_group_used(&cache->item), | 6551 | cache->reserved, cache->ro ? "[readonly]" : ""); |
| 6492 | (unsigned long long)cache->pinned, | ||
| 6493 | (unsigned long long)cache->reserved, | ||
| 6494 | cache->ro ? "[readonly]" : ""); | ||
| 6495 | btrfs_dump_free_space(cache, bytes); | 6552 | btrfs_dump_free_space(cache, bytes); |
| 6496 | spin_unlock(&cache->lock); | 6553 | spin_unlock(&cache->lock); |
| 6497 | } | 6554 | } |
| @@ -6500,8 +6557,7 @@ again: | |||
| 6500 | up_read(&info->groups_sem); | 6557 | up_read(&info->groups_sem); |
| 6501 | } | 6558 | } |
| 6502 | 6559 | ||
| 6503 | int btrfs_reserve_extent(struct btrfs_trans_handle *trans, | 6560 | int btrfs_reserve_extent(struct btrfs_root *root, |
| 6504 | struct btrfs_root *root, | ||
| 6505 | u64 num_bytes, u64 min_alloc_size, | 6561 | u64 num_bytes, u64 min_alloc_size, |
| 6506 | u64 empty_size, u64 hint_byte, | 6562 | u64 empty_size, u64 hint_byte, |
| 6507 | struct btrfs_key *ins, int is_data) | 6563 | struct btrfs_key *ins, int is_data) |
| @@ -6513,8 +6569,8 @@ int btrfs_reserve_extent(struct btrfs_trans_handle *trans, | |||
| 6513 | flags = btrfs_get_alloc_profile(root, is_data); | 6569 | flags = btrfs_get_alloc_profile(root, is_data); |
| 6514 | again: | 6570 | again: |
| 6515 | WARN_ON(num_bytes < root->sectorsize); | 6571 | WARN_ON(num_bytes < root->sectorsize); |
| 6516 | ret = find_free_extent(trans, root, num_bytes, empty_size, | 6572 | ret = find_free_extent(root, num_bytes, empty_size, hint_byte, ins, |
| 6517 | hint_byte, ins, flags); | 6573 | flags); |
| 6518 | 6574 | ||
| 6519 | if (ret == -ENOSPC) { | 6575 | if (ret == -ENOSPC) { |
| 6520 | if (!final_tried) { | 6576 | if (!final_tried) { |
| @@ -6529,8 +6585,7 @@ again: | |||
| 6529 | 6585 | ||
| 6530 | sinfo = __find_space_info(root->fs_info, flags); | 6586 | sinfo = __find_space_info(root->fs_info, flags); |
| 6531 | btrfs_err(root->fs_info, "allocation failed flags %llu, wanted %llu", | 6587 | btrfs_err(root->fs_info, "allocation failed flags %llu, wanted %llu", |
| 6532 | (unsigned long long)flags, | 6588 | flags, num_bytes); |
| 6533 | (unsigned long long)num_bytes); | ||
| 6534 | if (sinfo) | 6589 | if (sinfo) |
| 6535 | dump_space_info(sinfo, num_bytes, 1); | 6590 | dump_space_info(sinfo, num_bytes, 1); |
| 6536 | } | 6591 | } |
| @@ -6550,7 +6605,7 @@ static int __btrfs_free_reserved_extent(struct btrfs_root *root, | |||
| 6550 | cache = btrfs_lookup_block_group(root->fs_info, start); | 6605 | cache = btrfs_lookup_block_group(root->fs_info, start); |
| 6551 | if (!cache) { | 6606 | if (!cache) { |
| 6552 | btrfs_err(root->fs_info, "Unable to find block group for %llu", | 6607 | btrfs_err(root->fs_info, "Unable to find block group for %llu", |
| 6553 | (unsigned long long)start); | 6608 | start); |
| 6554 | return -ENOSPC; | 6609 | return -ENOSPC; |
| 6555 | } | 6610 | } |
| 6556 | 6611 | ||
| @@ -6646,8 +6701,7 @@ static int alloc_reserved_file_extent(struct btrfs_trans_handle *trans, | |||
| 6646 | ret = update_block_group(root, ins->objectid, ins->offset, 1); | 6701 | ret = update_block_group(root, ins->objectid, ins->offset, 1); |
| 6647 | if (ret) { /* -ENOENT, logic error */ | 6702 | if (ret) { /* -ENOENT, logic error */ |
| 6648 | btrfs_err(fs_info, "update block group failed for %llu %llu", | 6703 | btrfs_err(fs_info, "update block group failed for %llu %llu", |
| 6649 | (unsigned long long)ins->objectid, | 6704 | ins->objectid, ins->offset); |
| 6650 | (unsigned long long)ins->offset); | ||
| 6651 | BUG(); | 6705 | BUG(); |
| 6652 | } | 6706 | } |
| 6653 | return ret; | 6707 | return ret; |
| @@ -6719,8 +6773,7 @@ static int alloc_reserved_tree_block(struct btrfs_trans_handle *trans, | |||
| 6719 | ret = update_block_group(root, ins->objectid, root->leafsize, 1); | 6773 | ret = update_block_group(root, ins->objectid, root->leafsize, 1); |
| 6720 | if (ret) { /* -ENOENT, logic error */ | 6774 | if (ret) { /* -ENOENT, logic error */ |
| 6721 | btrfs_err(fs_info, "update block group failed for %llu %llu", | 6775 | btrfs_err(fs_info, "update block group failed for %llu %llu", |
| 6722 | (unsigned long long)ins->objectid, | 6776 | ins->objectid, ins->offset); |
| 6723 | (unsigned long long)ins->offset); | ||
| 6724 | BUG(); | 6777 | BUG(); |
| 6725 | } | 6778 | } |
| 6726 | return ret; | 6779 | return ret; |
| @@ -6902,7 +6955,7 @@ struct extent_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans, | |||
| 6902 | if (IS_ERR(block_rsv)) | 6955 | if (IS_ERR(block_rsv)) |
| 6903 | return ERR_CAST(block_rsv); | 6956 | return ERR_CAST(block_rsv); |
| 6904 | 6957 | ||
| 6905 | ret = btrfs_reserve_extent(trans, root, blocksize, blocksize, | 6958 | ret = btrfs_reserve_extent(root, blocksize, blocksize, |
| 6906 | empty_size, hint, &ins, 0); | 6959 | empty_size, hint, &ins, 0); |
| 6907 | if (ret) { | 6960 | if (ret) { |
| 6908 | unuse_block_rsv(root->fs_info, block_rsv, blocksize); | 6961 | unuse_block_rsv(root->fs_info, block_rsv, blocksize); |
| @@ -7173,6 +7226,8 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans, | |||
| 7173 | next = btrfs_find_create_tree_block(root, bytenr, blocksize); | 7226 | next = btrfs_find_create_tree_block(root, bytenr, blocksize); |
| 7174 | if (!next) | 7227 | if (!next) |
| 7175 | return -ENOMEM; | 7228 | return -ENOMEM; |
| 7229 | btrfs_set_buffer_lockdep_class(root->root_key.objectid, next, | ||
| 7230 | level - 1); | ||
| 7176 | reada = 1; | 7231 | reada = 1; |
| 7177 | } | 7232 | } |
| 7178 | btrfs_tree_lock(next); | 7233 | btrfs_tree_lock(next); |
| @@ -7658,7 +7713,7 @@ out: | |||
| 7658 | * don't have it in the radix (like when we recover after a power fail | 7713 | * don't have it in the radix (like when we recover after a power fail |
| 7659 | * or unmount) so we don't leak memory. | 7714 | * or unmount) so we don't leak memory. |
| 7660 | */ | 7715 | */ |
| 7661 | if (root_dropped == false) | 7716 | if (!for_reloc && root_dropped == false) |
| 7662 | btrfs_add_dead_root(root); | 7717 | btrfs_add_dead_root(root); |
| 7663 | if (err) | 7718 | if (err) |
| 7664 | btrfs_std_error(root->fs_info, err); | 7719 | btrfs_std_error(root->fs_info, err); |
| @@ -8192,7 +8247,8 @@ int btrfs_free_block_groups(struct btrfs_fs_info *info) | |||
| 8192 | * We haven't cached this block group, which means we could | 8247 | * We haven't cached this block group, which means we could |
| 8193 | * possibly have excluded extents on this block group. | 8248 | * possibly have excluded extents on this block group. |
| 8194 | */ | 8249 | */ |
| 8195 | if (block_group->cached == BTRFS_CACHE_NO) | 8250 | if (block_group->cached == BTRFS_CACHE_NO || |
| 8251 | block_group->cached == BTRFS_CACHE_ERROR) | ||
| 8196 | free_excluded_extents(info->extent_root, block_group); | 8252 | free_excluded_extents(info->extent_root, block_group); |
| 8197 | 8253 | ||
| 8198 | btrfs_remove_free_space_cache(block_group); | 8254 | btrfs_remove_free_space_cache(block_group); |
| @@ -8409,9 +8465,13 @@ int btrfs_read_block_groups(struct btrfs_root *root) | |||
| 8409 | * avoid allocating from un-mirrored block group if there are | 8465 | * avoid allocating from un-mirrored block group if there are |
| 8410 | * mirrored block groups. | 8466 | * mirrored block groups. |
| 8411 | */ | 8467 | */ |
| 8412 | list_for_each_entry(cache, &space_info->block_groups[3], list) | 8468 | list_for_each_entry(cache, |
| 8469 | &space_info->block_groups[BTRFS_RAID_RAID0], | ||
| 8470 | list) | ||
| 8413 | set_block_group_ro(cache, 1); | 8471 | set_block_group_ro(cache, 1); |
| 8414 | list_for_each_entry(cache, &space_info->block_groups[4], list) | 8472 | list_for_each_entry(cache, |
| 8473 | &space_info->block_groups[BTRFS_RAID_SINGLE], | ||
| 8474 | list) | ||
| 8415 | set_block_group_ro(cache, 1); | 8475 | set_block_group_ro(cache, 1); |
| 8416 | } | 8476 | } |
| 8417 | 8477 | ||
