Lines Matching full:root
78 * map address of tree root to tree
130 /* map start of tree root to corresponding reloc tree */
179 * walk up backref nodes until reach node presents tree root
290 static bool reloc_root_is_dead(struct btrfs_root *root) in reloc_root_is_dead() argument
298 if (test_bit(BTRFS_ROOT_DEAD_RELOC_TREE, &root->state)) in reloc_root_is_dead()
307 * This is enough for most callers, as they don't distinguish dead reloc root
308 * from no reloc root. But btrfs_should_ignore_reloc_root() below is a
311 static bool have_reloc_root(struct btrfs_root *root) in have_reloc_root() argument
313 if (reloc_root_is_dead(root)) in have_reloc_root()
315 if (!root->reloc_root) in have_reloc_root()
320 int btrfs_should_ignore_reloc_root(struct btrfs_root *root) in btrfs_should_ignore_reloc_root() argument
324 if (!test_bit(BTRFS_ROOT_SHAREABLE, &root->state)) in btrfs_should_ignore_reloc_root()
327 /* This root has been merged with its reloc tree, we can ignore it */ in btrfs_should_ignore_reloc_root()
328 if (reloc_root_is_dead(root)) in btrfs_should_ignore_reloc_root()
331 reloc_root = root->reloc_root; in btrfs_should_ignore_reloc_root()
336 root->fs_info->running_transaction->transid) in btrfs_should_ignore_reloc_root()
341 * so backref node for the fs tree root is useless for in btrfs_should_ignore_reloc_root()
348 * find reloc tree by address of tree root
355 struct btrfs_root *root = NULL; in find_reloc_root() local
362 root = (struct btrfs_root *)node->data; in find_reloc_root()
365 return btrfs_grab_root(root); in find_reloc_root()
395 /* Only tree root nodes can be added to @useless_nodes */ in handle_useless_nodes()
443 * Build backref tree for a given tree block. Root of the backref tree
449 * these upper level blocks recursively. The recursion stops when tree root is
533 * corresponds to root of source tree
580 new_node->root = btrfs_grab_root(dest); in clone_backref_node()
581 ASSERT(new_node->root); in clone_backref_node()
620 * helper to add 'address of tree root -> reloc tree' mapping
622 static int __must_check __add_reloc_root(struct btrfs_root *root) in __add_reloc_root() argument
624 struct btrfs_fs_info *fs_info = root->fs_info; in __add_reloc_root()
633 node->bytenr = root->commit_root->start; in __add_reloc_root()
634 node->data = root; in __add_reloc_root()
642 "Duplicate root found for start=%llu while inserting into relocation tree", in __add_reloc_root()
646 list_add_tail(&root->root_list, &rc->reloc_roots); in __add_reloc_root()
651 * helper to delete the 'address of tree root -> reloc tree'
654 static void __del_reloc_root(struct btrfs_root *root) in __del_reloc_root() argument
656 struct btrfs_fs_info *fs_info = root->fs_info; in __del_reloc_root()
662 if (rc && root->node) { in __del_reloc_root()
665 root->commit_root->start); in __del_reloc_root()
672 ASSERT(!node || (struct btrfs_root *)node->data == root); in __del_reloc_root()
676 * We only put the reloc root here if it's on the list. There's a lot in __del_reloc_root()
678 * the reloc roots, and then add the reloc root back onto in __del_reloc_root()
684 if (!list_empty(&root->root_list)) { in __del_reloc_root()
686 list_del_init(&root->root_list); in __del_reloc_root()
690 btrfs_put_root(root); in __del_reloc_root()
695 * helper to update the 'address of tree root -> reloc tree'
698 static int __update_reloc_root(struct btrfs_root *root) in __update_reloc_root() argument
700 struct btrfs_fs_info *fs_info = root->fs_info; in __update_reloc_root()
707 root->commit_root->start); in __update_reloc_root()
716 BUG_ON((struct btrfs_root *)node->data != root); in __update_reloc_root()
719 node->bytenr = root->node->start; in __update_reloc_root()
729 struct btrfs_root *root, u64 objectid) in create_reloc_root() argument
731 struct btrfs_fs_info *fs_info = root->fs_info; in create_reloc_root()
747 if (root->root_key.objectid == objectid) { in create_reloc_root()
751 ret = btrfs_copy_root(trans, root, root->commit_root, &eb, in create_reloc_root()
758 * root - like this ctree.c:btrfs_block_can_be_shared() behaves in create_reloc_root()
759 * correctly (returns true) when the relocation root is created in create_reloc_root()
764 commit_root_gen = btrfs_header_generation(root->commit_root); in create_reloc_root()
765 btrfs_set_root_last_snapshot(&root->root_item, commit_root_gen); in create_reloc_root()
774 ret = btrfs_copy_root(trans, root, root->node, &eb, in create_reloc_root()
786 memcpy(root_item, &root->root_item, sizeof(*root_item)); in create_reloc_root()
791 if (root->root_key.objectid == objectid) { in create_reloc_root()
826 * snapshot of the fs tree with special root objectid.
829 * root->reloc_root, and another for being on the rc->reloc_roots list.
832 struct btrfs_root *root) in btrfs_init_reloc_root() argument
834 struct btrfs_fs_info *fs_info = root->fs_info; in btrfs_init_reloc_root()
848 if (reloc_root_is_dead(root)) in btrfs_init_reloc_root()
854 * corresponding fs root, and then here we update the last trans for the in btrfs_init_reloc_root()
855 * reloc root. This means that we have to do this for the entire life in btrfs_init_reloc_root()
856 * of the reloc root, regardless of which stage of the relocation we are in btrfs_init_reloc_root()
859 if (root->reloc_root) { in btrfs_init_reloc_root()
860 reloc_root = root->reloc_root; in btrfs_init_reloc_root()
870 root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) in btrfs_init_reloc_root()
878 reloc_root = create_reloc_root(trans, root, root->root_key.objectid); in btrfs_init_reloc_root()
884 root->reloc_root = btrfs_grab_root(reloc_root); in btrfs_init_reloc_root()
889 * update root item of reloc tree
892 struct btrfs_root *root) in btrfs_update_reloc_root() argument
894 struct btrfs_fs_info *fs_info = root->fs_info; in btrfs_update_reloc_root()
899 if (!have_reloc_root(root)) in btrfs_update_reloc_root()
902 reloc_root = root->reloc_root; in btrfs_update_reloc_root()
907 * the root. We have the ref for root->reloc_root, but just in case in btrfs_update_reloc_root()
908 * hold it while we update the reloc root. in btrfs_update_reloc_root()
912 /* root->reloc_root will stay until current relocation finished */ in btrfs_update_reloc_root()
915 set_bit(BTRFS_ROOT_DEAD_RELOC_TREE, &root->state); in btrfs_update_reloc_root()
941 static struct inode *find_next_inode(struct btrfs_root *root, u64 objectid) in find_next_inode() argument
948 spin_lock(&root->inode_lock); in find_next_inode()
950 node = root->inode_tree.rb_node; in find_next_inode()
977 spin_unlock(&root->inode_lock); in find_next_inode()
982 if (cond_resched_lock(&root->inode_lock)) in find_next_inode()
987 spin_unlock(&root->inode_lock); in find_next_inode()
997 struct btrfs_root *root = BTRFS_I(reloc_inode)->root; in get_new_location() local
1008 ret = btrfs_lookup_file_extent(NULL, root, path, in get_new_location()
1045 struct btrfs_root *root, in replace_file_extents() argument
1048 struct btrfs_fs_info *fs_info = root->fs_info; in replace_file_extents()
1067 if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) in replace_file_extents()
1096 if (root->root_key.objectid != BTRFS_TREE_RELOC_OBJECTID) { in replace_file_extents()
1098 inode = find_next_inode(root, key.objectid); in replace_file_extents()
1102 inode = find_next_inode(root, key.objectid); in replace_file_extents()
1139 ref.real_root = root->root_key.objectid; in replace_file_extents()
1150 ref.real_root = root->root_key.objectid; in replace_file_extents()
1337 * CoW on the subtree root node before transaction commit. in replace_path()
1399 int walk_up_reloc_tree(struct btrfs_root *root, struct btrfs_path *path, in walk_up_reloc_tree() argument
1407 last_snapshot = btrfs_root_last_snapshot(&root->root_item); in walk_up_reloc_tree()
1436 int walk_down_reloc_tree(struct btrfs_root *root, struct btrfs_path *path, in walk_down_reloc_tree() argument
1439 struct btrfs_fs_info *fs_info = root->fs_info; in walk_down_reloc_tree()
1447 last_snapshot = btrfs_root_last_snapshot(&root->root_item); in walk_down_reloc_tree()
1492 static int invalidate_extent_cache(struct btrfs_root *root, in invalidate_extent_cache() argument
1496 struct btrfs_fs_info *fs_info = root->fs_info; in invalidate_extent_cache()
1510 inode = find_next_inode(root, objectid); in invalidate_extent_cache()
1584 struct btrfs_root *root) in insert_dirty_subvol() argument
1586 struct btrfs_root *reloc_root = root->reloc_root; in insert_dirty_subvol()
1589 /* @root must be a subvolume tree root with a valid reloc tree */ in insert_dirty_subvol()
1590 ASSERT(root->root_key.objectid != BTRFS_TREE_RELOC_OBJECTID); in insert_dirty_subvol()
1598 btrfs_update_reloc_root(trans, root); in insert_dirty_subvol()
1600 if (list_empty(&root->reloc_dirty_list)) { in insert_dirty_subvol()
1601 btrfs_grab_root(root); in insert_dirty_subvol()
1602 list_add_tail(&root->reloc_dirty_list, &rc->dirty_subvol_roots); in insert_dirty_subvol()
1608 struct btrfs_root *root; in clean_dirty_subvols() local
1613 list_for_each_entry_safe(root, next, &rc->dirty_subvol_roots, in clean_dirty_subvols()
1615 if (root->root_key.objectid != BTRFS_TREE_RELOC_OBJECTID) { in clean_dirty_subvols()
1616 /* Merged subvolume, cleanup its reloc root */ in clean_dirty_subvols()
1617 struct btrfs_root *reloc_root = root->reloc_root; in clean_dirty_subvols()
1619 list_del_init(&root->reloc_dirty_list); in clean_dirty_subvols()
1620 root->reloc_root = NULL; in clean_dirty_subvols()
1623 * root->reloc_root = NULL. Pairs with have_reloc_root. in clean_dirty_subvols()
1626 clear_bit(BTRFS_ROOT_DEAD_RELOC_TREE, &root->state); in clean_dirty_subvols()
1640 btrfs_put_root(root); in clean_dirty_subvols()
1643 ret2 = btrfs_drop_snapshot(root, 0, 1); in clean_dirty_subvols()
1645 btrfs_put_root(root); in clean_dirty_subvols()
1659 struct btrfs_root *root) in merge_reloc_root() argument
1682 reloc_root = root->reloc_root; in merge_reloc_root()
1713 * block COW, we COW at most from level 1 to root level for each tree. in merge_reloc_root()
1723 ret = btrfs_block_rsv_refill(root, rc->block_rsv, min_reserved, in merge_reloc_root()
1729 trans = btrfs_start_transaction(root, 0); in merge_reloc_root()
1743 * btrfs_update_reloc_root() and update our root item in merge_reloc_root()
1764 ret = replace_path(trans, rc, root, reloc_root, path, in merge_reloc_root()
1786 * this is OK since root refs == 1 in this case. in merge_reloc_root()
1798 invalidate_extent_cache(root, &key, &next_key); in merge_reloc_root()
1803 * relocated and the block is tree root. in merge_reloc_root()
1805 leaf = btrfs_lock_root_node(root); in merge_reloc_root()
1806 ret = btrfs_cow_block(trans, root, leaf, NULL, 0, &leaf, in merge_reloc_root()
1816 insert_dirty_subvol(trans, rc, root); in merge_reloc_root()
1824 invalidate_extent_cache(root, &key, &next_key); in merge_reloc_root()
1832 struct btrfs_root *root = rc->extent_root; in prepare_to_merge() local
1833 struct btrfs_fs_info *fs_info = root->fs_info; in prepare_to_merge()
1848 ret = btrfs_block_rsv_add(root, rc->block_rsv, num_bytes, in prepare_to_merge()
1878 root = btrfs_get_fs_root(fs_info, reloc_root->root_key.offset, in prepare_to_merge()
1880 BUG_ON(IS_ERR(root)); in prepare_to_merge()
1881 BUG_ON(root->reloc_root != reloc_root); in prepare_to_merge()
1889 btrfs_update_reloc_root(trans, root); in prepare_to_merge()
1892 btrfs_put_root(root); in prepare_to_merge()
1917 struct btrfs_root *root; in merge_reloc_roots() local
1923 root = rc->extent_root; in merge_reloc_roots()
1940 root = btrfs_get_fs_root(fs_info, reloc_root->root_key.offset, in merge_reloc_roots()
1943 BUG_ON(IS_ERR(root)); in merge_reloc_roots()
1944 BUG_ON(root->reloc_root != reloc_root); in merge_reloc_roots()
1945 ret = merge_reloc_root(rc, root); in merge_reloc_roots()
1946 btrfs_put_root(root); in merge_reloc_roots()
1954 if (!IS_ERR(root)) { in merge_reloc_roots()
1955 if (root->reloc_root == reloc_root) { in merge_reloc_roots()
1956 root->reloc_root = NULL; in merge_reloc_roots()
1960 &root->state); in merge_reloc_roots()
1961 btrfs_put_root(root); in merge_reloc_roots()
1965 /* Don't forget to queue this reloc root for cleanup */ in merge_reloc_roots()
1980 /* new reloc root may be added */ in merge_reloc_roots()
1995 * fine because we're bailing here, and we hold a reference on the root in merge_reloc_roots()
1997 * do the reloc_dirty_list afterwards. Meanwhile the root->reloc_root in merge_reloc_roots()
2019 struct btrfs_root *root; in record_reloc_root_in_trans() local
2025 root = btrfs_get_fs_root(fs_info, reloc_root->root_key.offset, false); in record_reloc_root_in_trans()
2026 BUG_ON(IS_ERR(root)); in record_reloc_root_in_trans()
2027 BUG_ON(root->reloc_root != reloc_root); in record_reloc_root_in_trans()
2028 ret = btrfs_record_root_in_trans(trans, root); in record_reloc_root_in_trans()
2029 btrfs_put_root(root); in record_reloc_root_in_trans()
2041 struct btrfs_root *root; in select_reloc_root() local
2048 root = next->root; in select_reloc_root()
2049 BUG_ON(!root); in select_reloc_root()
2050 BUG_ON(!test_bit(BTRFS_ROOT_SHAREABLE, &root->state)); in select_reloc_root()
2052 if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) { in select_reloc_root()
2053 record_reloc_root_in_trans(trans, root); in select_reloc_root()
2057 btrfs_record_root_in_trans(trans, root); in select_reloc_root()
2058 root = root->reloc_root; in select_reloc_root()
2060 if (next->new_bytenr != root->node->start) { in select_reloc_root()
2063 next->new_bytenr = root->node->start; in select_reloc_root()
2064 btrfs_put_root(next->root); in select_reloc_root()
2065 next->root = btrfs_grab_root(root); in select_reloc_root()
2066 ASSERT(next->root); in select_reloc_root()
2074 root = NULL; in select_reloc_root()
2079 if (!root) in select_reloc_root()
2090 return root; in select_reloc_root()
2094 * Select a tree root for relocation.
2099 * Return a tree root pointer if the block is shareable.
2100 * Return -ENOENT if the block is root of reloc tree.
2106 struct btrfs_root *root; in select_one_root() local
2115 root = next->root; in select_one_root()
2116 BUG_ON(!root); in select_one_root()
2119 if (!test_bit(BTRFS_ROOT_SHAREABLE, &root->state)) in select_one_root()
2120 return root; in select_one_root()
2122 if (root->root_key.objectid != BTRFS_TREE_RELOC_OBJECTID) in select_one_root()
2123 fs_root = root; in select_one_root()
2176 struct btrfs_root *root = rc->extent_root; in reserve_metadata_space() local
2177 struct btrfs_fs_info *fs_info = root->fs_info; in reserve_metadata_space()
2192 ret = btrfs_block_rsv_refill(root, rc->block_rsv, num_bytes, in reserve_metadata_space()
2230 struct btrfs_root *root; in do_relocation() local
2250 root = select_reloc_root(trans, rc, upper, edges); in do_relocation()
2251 BUG_ON(!root); in do_relocation()
2269 ret = btrfs_search_slot(trans, root, key, path, 0, 1); in do_relocation()
2304 btrfs_err(root->fs_info, in do_relocation()
2316 blocksize = root->fs_info->nodesize; in do_relocation()
2333 ret = btrfs_cow_block(trans, root, eb, upper->eb, in do_relocation()
2352 ref.real_root = root->root_key.objectid; in do_relocation()
2358 ret = btrfs_drop_subtree(trans, root, eb, upper->eb); in do_relocation()
2493 struct btrfs_root *root; in relocate_tree_block() local
2508 root = select_one_root(node); in relocate_tree_block()
2509 if (root == ERR_PTR(-ENOENT)) { in relocate_tree_block()
2514 if (root) { in relocate_tree_block()
2515 if (test_bit(BTRFS_ROOT_SHAREABLE, &root->state)) { in relocate_tree_block()
2518 btrfs_record_root_in_trans(trans, root); in relocate_tree_block()
2519 root = root->reloc_root; in relocate_tree_block()
2520 node->new_bytenr = root->node->start; in relocate_tree_block()
2521 btrfs_put_root(node->root); in relocate_tree_block()
2522 node->root = btrfs_grab_root(root); in relocate_tree_block()
2523 ASSERT(node->root); in relocate_tree_block()
2527 ret = btrfs_search_slot(trans, root, key, path, 0, 1); in relocate_tree_block()
2647 btrfs_free_reserved_data_space_noquota(inode->root->fs_info, in prealloc_file_extent_cluster()
2997 struct btrfs_root *root = fs_info->tree_root; in delete_block_group_cache() local
3004 inode = btrfs_iget(fs_info->sb, ino, root); in delete_block_group_cache()
3014 trans = btrfs_join_transaction(root); in delete_block_group_cache()
3030 * Locate the free space cache EXTENT_DATA in root tree leaf and delete the
3457 struct btrfs_root *root, u64 objectid) in __insert_orphan_inode() argument
3468 ret = btrfs_insert_empty_inode(trans, root, path, objectid); in __insert_orphan_inode()
3496 struct btrfs_root *root; in create_reloc_inode() local
3500 root = btrfs_grab_root(fs_info->data_reloc_root); in create_reloc_inode()
3501 trans = btrfs_start_transaction(root, 6); in create_reloc_inode()
3503 btrfs_put_root(root); in create_reloc_inode()
3507 err = btrfs_find_free_objectid(root, &objectid); in create_reloc_inode()
3511 err = __insert_orphan_inode(trans, root, objectid); in create_reloc_inode()
3514 inode = btrfs_iget(fs_info->sb, objectid, root); in create_reloc_inode()
3520 btrfs_put_root(root); in create_reloc_inode()
3708 static noinline_for_stack int mark_garbage_root(struct btrfs_root *root) in mark_garbage_root() argument
3710 struct btrfs_fs_info *fs_info = root->fs_info; in mark_garbage_root()
3718 memset(&root->root_item.drop_progress, 0, in mark_garbage_root()
3719 sizeof(root->root_item.drop_progress)); in mark_garbage_root()
3720 root->root_item.drop_level = 0; in mark_garbage_root()
3721 btrfs_set_root_refs(&root->root_item, 0); in mark_garbage_root()
3723 &root->root_key, &root->root_item); in mark_garbage_root()
3737 int btrfs_recover_relocation(struct btrfs_root *root) in btrfs_recover_relocation() argument
3739 struct btrfs_fs_info *fs_info = root->fs_info; in btrfs_recover_relocation()
3780 reloc_root = btrfs_read_tree_root(root, &key); in btrfs_recover_relocation()
3906 struct btrfs_fs_info *fs_info = inode->root->fs_info; in btrfs_reloc_clone_csums()
3950 struct btrfs_root *root, struct extent_buffer *buf, in btrfs_reloc_cow_block() argument
3953 struct btrfs_fs_info *fs_info = root->fs_info; in btrfs_reloc_cow_block()
3965 root->root_key.objectid == BTRFS_DATA_RELOC_TREE_OBJECTID); in btrfs_reloc_cow_block()
3969 btrfs_root_last_snapshot(&root->root_item)) in btrfs_reloc_cow_block()
3972 if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID && in btrfs_reloc_cow_block()
3999 ret = replace_file_extents(trans, rc, root, cow); in btrfs_reloc_cow_block()
4010 struct btrfs_root *root = pending->root; in btrfs_reloc_pre_snapshot() local
4011 struct reloc_control *rc = root->fs_info->reloc_ctl; in btrfs_reloc_pre_snapshot()
4013 if (!rc || !have_reloc_root(root)) in btrfs_reloc_pre_snapshot()
4019 root = root->reloc_root; in btrfs_reloc_pre_snapshot()
4020 BUG_ON(btrfs_root_refs(&root->root_item) == 0); in btrfs_reloc_pre_snapshot()
4036 * and create reloc root for the newly created snapshot
4039 * references held on the reloc_root, one for root->reloc_root and one for
4045 struct btrfs_root *root = pending->root; in btrfs_reloc_post_snapshot() local
4048 struct reloc_control *rc = root->fs_info->reloc_ctl; in btrfs_reloc_post_snapshot()
4051 if (!rc || !have_reloc_root(root)) in btrfs_reloc_post_snapshot()
4054 rc = root->fs_info->reloc_ctl; in btrfs_reloc_post_snapshot()
4066 reloc_root = create_reloc_root(trans, root->reloc_root, in btrfs_reloc_post_snapshot()
4076 ret = clone_backref_node(trans, rc, root, reloc_root); in btrfs_reloc_post_snapshot()