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()
674 BUG_ON((struct btrfs_root *)node->data != root); in __del_reloc_root()
678 * We only put the reloc root here if it's on the list. There's a lot in __del_reloc_root()
680 * the reloc roots, and then add the reloc root back onto in __del_reloc_root()
686 if (!list_empty(&root->root_list)) { in __del_reloc_root()
688 list_del_init(&root->root_list); in __del_reloc_root()
692 btrfs_put_root(root); in __del_reloc_root()
697 * helper to update the 'address of tree root -> reloc tree'
700 static int __update_reloc_root(struct btrfs_root *root) in __update_reloc_root() argument
702 struct btrfs_fs_info *fs_info = root->fs_info; in __update_reloc_root()
709 root->commit_root->start); in __update_reloc_root()
718 BUG_ON((struct btrfs_root *)node->data != root); in __update_reloc_root()
721 node->bytenr = root->node->start; in __update_reloc_root()
731 struct btrfs_root *root, u64 objectid) in create_reloc_root() argument
733 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()
756 * root - like this ctree.c:btrfs_block_can_be_shared() behaves in create_reloc_root()
757 * correctly (returns true) when the relocation root is created in create_reloc_root()
762 commit_root_gen = btrfs_header_generation(root->commit_root); in create_reloc_root()
763 btrfs_set_root_last_snapshot(&root->root_item, commit_root_gen); in create_reloc_root()
772 ret = btrfs_copy_root(trans, root, root->node, &eb, in create_reloc_root()
777 memcpy(root_item, &root->root_item, sizeof(*root_item)); in create_reloc_root()
782 if (root->root_key.objectid == objectid) { in create_reloc_root()
806 * snapshot of the fs tree with special root objectid.
809 * root->reloc_root, and another for being on the rc->reloc_roots list.
812 struct btrfs_root *root) in btrfs_init_reloc_root() argument
814 struct btrfs_fs_info *fs_info = root->fs_info; in btrfs_init_reloc_root()
828 if (reloc_root_is_dead(root)) in btrfs_init_reloc_root()
834 * corresponding fs root, and then here we update the last trans for the in btrfs_init_reloc_root()
835 * reloc root. This means that we have to do this for the entire life in btrfs_init_reloc_root()
836 * of the reloc root, regardless of which stage of the relocation we are in btrfs_init_reloc_root()
839 if (root->reloc_root) { in btrfs_init_reloc_root()
840 reloc_root = root->reloc_root; in btrfs_init_reloc_root()
850 root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) in btrfs_init_reloc_root()
858 reloc_root = create_reloc_root(trans, root, root->root_key.objectid); in btrfs_init_reloc_root()
864 root->reloc_root = btrfs_grab_root(reloc_root); in btrfs_init_reloc_root()
869 * update root item of reloc tree
872 struct btrfs_root *root) in btrfs_update_reloc_root() argument
874 struct btrfs_fs_info *fs_info = root->fs_info; in btrfs_update_reloc_root()
879 if (!have_reloc_root(root)) in btrfs_update_reloc_root()
882 reloc_root = root->reloc_root; in btrfs_update_reloc_root()
887 * the root. We have the ref for root->reloc_root, but just in case in btrfs_update_reloc_root()
888 * hold it while we update the reloc root. in btrfs_update_reloc_root()
892 /* root->reloc_root will stay until current relocation finished */ in btrfs_update_reloc_root()
895 set_bit(BTRFS_ROOT_DEAD_RELOC_TREE, &root->state); in btrfs_update_reloc_root()
923 static struct inode *find_next_inode(struct btrfs_root *root, u64 objectid) in find_next_inode() argument
930 spin_lock(&root->inode_lock); in find_next_inode()
932 node = root->inode_tree.rb_node; in find_next_inode()
959 spin_unlock(&root->inode_lock); in find_next_inode()
964 if (cond_resched_lock(&root->inode_lock)) in find_next_inode()
969 spin_unlock(&root->inode_lock); in find_next_inode()
979 struct btrfs_root *root = BTRFS_I(reloc_inode)->root; in get_new_location() local
990 ret = btrfs_lookup_file_extent(NULL, root, path, in get_new_location()
1027 struct btrfs_root *root, in replace_file_extents() argument
1030 struct btrfs_fs_info *fs_info = root->fs_info; in replace_file_extents()
1049 if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) in replace_file_extents()
1078 if (root->root_key.objectid != BTRFS_TREE_RELOC_OBJECTID) { in replace_file_extents()
1080 inode = find_next_inode(root, key.objectid); in replace_file_extents()
1084 inode = find_next_inode(root, key.objectid); in replace_file_extents()
1121 ref.real_root = root->root_key.objectid; in replace_file_extents()
1132 ref.real_root = root->root_key.objectid; in replace_file_extents()
1319 * CoW on the subtree root node before transaction commit. in replace_path()
1381 int walk_up_reloc_tree(struct btrfs_root *root, struct btrfs_path *path, in walk_up_reloc_tree() argument
1389 last_snapshot = btrfs_root_last_snapshot(&root->root_item); in walk_up_reloc_tree()
1418 int walk_down_reloc_tree(struct btrfs_root *root, struct btrfs_path *path, in walk_down_reloc_tree() argument
1421 struct btrfs_fs_info *fs_info = root->fs_info; in walk_down_reloc_tree()
1429 last_snapshot = btrfs_root_last_snapshot(&root->root_item); in walk_down_reloc_tree()
1474 static int invalidate_extent_cache(struct btrfs_root *root, in invalidate_extent_cache() argument
1478 struct btrfs_fs_info *fs_info = root->fs_info; in invalidate_extent_cache()
1492 inode = find_next_inode(root, objectid); in invalidate_extent_cache()
1566 struct btrfs_root *root) in insert_dirty_subvol() argument
1568 struct btrfs_root *reloc_root = root->reloc_root; in insert_dirty_subvol()
1571 /* @root must be a subvolume tree root with a valid reloc tree */ in insert_dirty_subvol()
1572 ASSERT(root->root_key.objectid != BTRFS_TREE_RELOC_OBJECTID); in insert_dirty_subvol()
1580 btrfs_update_reloc_root(trans, root); in insert_dirty_subvol()
1582 if (list_empty(&root->reloc_dirty_list)) { in insert_dirty_subvol()
1583 btrfs_grab_root(root); in insert_dirty_subvol()
1584 list_add_tail(&root->reloc_dirty_list, &rc->dirty_subvol_roots); in insert_dirty_subvol()
1590 struct btrfs_root *root; in clean_dirty_subvols() local
1595 list_for_each_entry_safe(root, next, &rc->dirty_subvol_roots, in clean_dirty_subvols()
1597 if (root->root_key.objectid != BTRFS_TREE_RELOC_OBJECTID) { in clean_dirty_subvols()
1598 /* Merged subvolume, cleanup its reloc root */ in clean_dirty_subvols()
1599 struct btrfs_root *reloc_root = root->reloc_root; in clean_dirty_subvols()
1601 list_del_init(&root->reloc_dirty_list); in clean_dirty_subvols()
1602 root->reloc_root = NULL; in clean_dirty_subvols()
1605 * root->reloc_root = NULL. Pairs with have_reloc_root. in clean_dirty_subvols()
1608 clear_bit(BTRFS_ROOT_DEAD_RELOC_TREE, &root->state); in clean_dirty_subvols()
1622 btrfs_put_root(root); in clean_dirty_subvols()
1625 ret2 = btrfs_drop_snapshot(root, 0, 1); in clean_dirty_subvols()
1627 btrfs_put_root(root); in clean_dirty_subvols()
1641 struct btrfs_root *root) in merge_reloc_root() argument
1664 reloc_root = root->reloc_root; in merge_reloc_root()
1695 * block COW, we COW at most from level 1 to root level for each tree. in merge_reloc_root()
1705 ret = btrfs_block_rsv_refill(root, rc->block_rsv, min_reserved, in merge_reloc_root()
1711 trans = btrfs_start_transaction(root, 0); in merge_reloc_root()
1725 * btrfs_update_reloc_root() and update our root item in merge_reloc_root()
1746 ret = replace_path(trans, rc, root, reloc_root, path, in merge_reloc_root()
1768 * this is OK since root refs == 1 in this case. in merge_reloc_root()
1780 invalidate_extent_cache(root, &key, &next_key); in merge_reloc_root()
1785 * relocated and the block is tree root. in merge_reloc_root()
1787 leaf = btrfs_lock_root_node(root); in merge_reloc_root()
1788 ret = btrfs_cow_block(trans, root, leaf, NULL, 0, &leaf, in merge_reloc_root()
1798 insert_dirty_subvol(trans, rc, root); in merge_reloc_root()
1806 invalidate_extent_cache(root, &key, &next_key); in merge_reloc_root()
1814 struct btrfs_root *root = rc->extent_root; in prepare_to_merge() local
1815 struct btrfs_fs_info *fs_info = root->fs_info; in prepare_to_merge()
1830 ret = btrfs_block_rsv_add(root, rc->block_rsv, num_bytes, in prepare_to_merge()
1860 root = btrfs_get_fs_root(fs_info, reloc_root->root_key.offset, in prepare_to_merge()
1862 BUG_ON(IS_ERR(root)); in prepare_to_merge()
1863 BUG_ON(root->reloc_root != reloc_root); in prepare_to_merge()
1871 btrfs_update_reloc_root(trans, root); in prepare_to_merge()
1874 btrfs_put_root(root); in prepare_to_merge()
1899 struct btrfs_root *root; in merge_reloc_roots() local
1905 root = rc->extent_root; in merge_reloc_roots()
1922 root = btrfs_get_fs_root(fs_info, reloc_root->root_key.offset, in merge_reloc_roots()
1925 BUG_ON(IS_ERR(root)); in merge_reloc_roots()
1926 BUG_ON(root->reloc_root != reloc_root); in merge_reloc_roots()
1927 ret = merge_reloc_root(rc, root); in merge_reloc_roots()
1928 btrfs_put_root(root); in merge_reloc_roots()
1936 if (!IS_ERR(root)) { in merge_reloc_roots()
1937 if (root->reloc_root == reloc_root) { in merge_reloc_roots()
1938 root->reloc_root = NULL; in merge_reloc_roots()
1942 &root->state); in merge_reloc_roots()
1943 btrfs_put_root(root); in merge_reloc_roots()
1947 /* Don't forget to queue this reloc root for cleanup */ in merge_reloc_roots()
1962 /* new reloc root may be added */ in merge_reloc_roots()
1977 * fine because we're bailing here, and we hold a reference on the root in merge_reloc_roots()
1979 * do the reloc_dirty_list afterwards. Meanwhile the root->reloc_root in merge_reloc_roots()
2001 struct btrfs_root *root; in record_reloc_root_in_trans() local
2007 root = btrfs_get_fs_root(fs_info, reloc_root->root_key.offset, false); in record_reloc_root_in_trans()
2008 BUG_ON(IS_ERR(root)); in record_reloc_root_in_trans()
2009 BUG_ON(root->reloc_root != reloc_root); in record_reloc_root_in_trans()
2010 ret = btrfs_record_root_in_trans(trans, root); in record_reloc_root_in_trans()
2011 btrfs_put_root(root); in record_reloc_root_in_trans()
2023 struct btrfs_root *root; in select_reloc_root() local
2030 root = next->root; in select_reloc_root()
2031 BUG_ON(!root); in select_reloc_root()
2032 BUG_ON(!test_bit(BTRFS_ROOT_SHAREABLE, &root->state)); in select_reloc_root()
2034 if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) { in select_reloc_root()
2035 record_reloc_root_in_trans(trans, root); in select_reloc_root()
2039 btrfs_record_root_in_trans(trans, root); in select_reloc_root()
2040 root = root->reloc_root; in select_reloc_root()
2042 if (next->new_bytenr != root->node->start) { in select_reloc_root()
2045 next->new_bytenr = root->node->start; in select_reloc_root()
2046 btrfs_put_root(next->root); in select_reloc_root()
2047 next->root = btrfs_grab_root(root); in select_reloc_root()
2048 ASSERT(next->root); in select_reloc_root()
2056 root = NULL; in select_reloc_root()
2061 if (!root) in select_reloc_root()
2072 return root; in select_reloc_root()
2076 * Select a tree root for relocation.
2081 * Return a tree root pointer if the block is shareable.
2082 * Return -ENOENT if the block is root of reloc tree.
2088 struct btrfs_root *root; in select_one_root() local
2097 root = next->root; in select_one_root()
2098 BUG_ON(!root); in select_one_root()
2101 if (!test_bit(BTRFS_ROOT_SHAREABLE, &root->state)) in select_one_root()
2102 return root; in select_one_root()
2104 if (root->root_key.objectid != BTRFS_TREE_RELOC_OBJECTID) in select_one_root()
2105 fs_root = root; in select_one_root()
2158 struct btrfs_root *root = rc->extent_root; in reserve_metadata_space() local
2159 struct btrfs_fs_info *fs_info = root->fs_info; in reserve_metadata_space()
2174 ret = btrfs_block_rsv_refill(root, rc->block_rsv, num_bytes, in reserve_metadata_space()
2212 struct btrfs_root *root; in do_relocation() local
2232 root = select_reloc_root(trans, rc, upper, edges); in do_relocation()
2233 BUG_ON(!root); in do_relocation()
2251 ret = btrfs_search_slot(trans, root, key, path, 0, 1); in do_relocation()
2286 btrfs_err(root->fs_info, in do_relocation()
2298 blocksize = root->fs_info->nodesize; in do_relocation()
2315 ret = btrfs_cow_block(trans, root, eb, upper->eb, in do_relocation()
2334 ref.real_root = root->root_key.objectid; in do_relocation()
2340 ret = btrfs_drop_subtree(trans, root, eb, upper->eb); in do_relocation()
2475 struct btrfs_root *root; in relocate_tree_block() local
2490 root = select_one_root(node); in relocate_tree_block()
2491 if (root == ERR_PTR(-ENOENT)) { in relocate_tree_block()
2496 if (root) { in relocate_tree_block()
2497 if (test_bit(BTRFS_ROOT_SHAREABLE, &root->state)) { in relocate_tree_block()
2500 btrfs_record_root_in_trans(trans, root); in relocate_tree_block()
2501 root = root->reloc_root; in relocate_tree_block()
2502 node->new_bytenr = root->node->start; in relocate_tree_block()
2503 btrfs_put_root(node->root); in relocate_tree_block()
2504 node->root = btrfs_grab_root(root); in relocate_tree_block()
2505 ASSERT(node->root); in relocate_tree_block()
2509 ret = btrfs_search_slot(trans, root, key, path, 0, 1); in relocate_tree_block()
2629 btrfs_free_reserved_data_space_noquota(inode->root->fs_info, in prealloc_file_extent_cluster()
2979 struct btrfs_root *root = fs_info->tree_root; in delete_block_group_cache() local
2986 inode = btrfs_iget(fs_info->sb, ino, root); in delete_block_group_cache()
2996 trans = btrfs_join_transaction(root); in delete_block_group_cache()
3012 * Locate the free space cache EXTENT_DATA in root tree leaf and delete the
3434 struct btrfs_root *root, u64 objectid) in __insert_orphan_inode() argument
3445 ret = btrfs_insert_empty_inode(trans, root, path, objectid); in __insert_orphan_inode()
3473 struct btrfs_root *root; in create_reloc_inode() local
3477 root = btrfs_grab_root(fs_info->data_reloc_root); in create_reloc_inode()
3478 trans = btrfs_start_transaction(root, 6); in create_reloc_inode()
3480 btrfs_put_root(root); in create_reloc_inode()
3484 err = btrfs_find_free_objectid(root, &objectid); in create_reloc_inode()
3488 err = __insert_orphan_inode(trans, root, objectid); in create_reloc_inode()
3491 inode = btrfs_iget(fs_info->sb, objectid, root); in create_reloc_inode()
3497 btrfs_put_root(root); in create_reloc_inode()
3685 static noinline_for_stack int mark_garbage_root(struct btrfs_root *root) in mark_garbage_root() argument
3687 struct btrfs_fs_info *fs_info = root->fs_info; in mark_garbage_root()
3695 memset(&root->root_item.drop_progress, 0, in mark_garbage_root()
3696 sizeof(root->root_item.drop_progress)); in mark_garbage_root()
3697 root->root_item.drop_level = 0; in mark_garbage_root()
3698 btrfs_set_root_refs(&root->root_item, 0); in mark_garbage_root()
3700 &root->root_key, &root->root_item); in mark_garbage_root()
3714 int btrfs_recover_relocation(struct btrfs_root *root) in btrfs_recover_relocation() argument
3716 struct btrfs_fs_info *fs_info = root->fs_info; in btrfs_recover_relocation()
3757 reloc_root = btrfs_read_tree_root(root, &key); in btrfs_recover_relocation()
3883 struct btrfs_fs_info *fs_info = inode->root->fs_info; in btrfs_reloc_clone_csums()
3927 struct btrfs_root *root, struct extent_buffer *buf, in btrfs_reloc_cow_block() argument
3930 struct btrfs_fs_info *fs_info = root->fs_info; in btrfs_reloc_cow_block()
3942 root->root_key.objectid == BTRFS_DATA_RELOC_TREE_OBJECTID); in btrfs_reloc_cow_block()
3946 btrfs_root_last_snapshot(&root->root_item)) in btrfs_reloc_cow_block()
3949 if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID && in btrfs_reloc_cow_block()
3976 ret = replace_file_extents(trans, rc, root, cow); in btrfs_reloc_cow_block()
3987 struct btrfs_root *root = pending->root; in btrfs_reloc_pre_snapshot() local
3988 struct reloc_control *rc = root->fs_info->reloc_ctl; in btrfs_reloc_pre_snapshot()
3990 if (!rc || !have_reloc_root(root)) in btrfs_reloc_pre_snapshot()
3996 root = root->reloc_root; in btrfs_reloc_pre_snapshot()
3997 BUG_ON(btrfs_root_refs(&root->root_item) == 0); in btrfs_reloc_pre_snapshot()
4013 * and create reloc root for the newly created snapshot
4016 * references held on the reloc_root, one for root->reloc_root and one for
4022 struct btrfs_root *root = pending->root; in btrfs_reloc_post_snapshot() local
4025 struct reloc_control *rc = root->fs_info->reloc_ctl; in btrfs_reloc_post_snapshot()
4028 if (!rc || !have_reloc_root(root)) in btrfs_reloc_post_snapshot()
4031 rc = root->fs_info->reloc_ctl; in btrfs_reloc_post_snapshot()
4043 reloc_root = create_reloc_root(trans, root->reloc_root, in btrfs_reloc_post_snapshot()
4053 ret = clone_backref_node(trans, rc, root, reloc_root); in btrfs_reloc_post_snapshot()