Lines Matching defs: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)
298 if (test_bit(BTRFS_ROOT_DEAD_RELOC_TREE, &root->state))
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)
313 if (reloc_root_is_dead(root))
315 if (!root->reloc_root)
320 int btrfs_should_ignore_reloc_root(struct btrfs_root *root)
324 if (!test_bit(BTRFS_ROOT_SHAREABLE, &root->state))
327 /* This root has been merged with its reloc tree, we can ignore it */
328 if (reloc_root_is_dead(root))
331 reloc_root = root->reloc_root;
336 root->fs_info->running_transaction->transid)
341 * so backref node for the fs tree root is useless for
348 * find reloc tree by address of tree root
355 struct btrfs_root *root = NULL;
362 root = (struct btrfs_root *)node->data;
365 return btrfs_grab_root(root);
395 /* Only tree root nodes can be added to @useless_nodes */
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);
581 ASSERT(new_node->root);
620 * helper to add 'address of tree root -> reloc tree' mapping
622 static int __must_check __add_reloc_root(struct btrfs_root *root)
624 struct btrfs_fs_info *fs_info = root->fs_info;
633 node->bytenr = root->commit_root->start;
634 node->data = root;
642 "Duplicate root found for start=%llu while inserting into relocation tree",
646 list_add_tail(&root->root_list, &rc->reloc_roots);
651 * helper to delete the 'address of tree root -> reloc tree'
654 static void __del_reloc_root(struct btrfs_root *root)
656 struct btrfs_fs_info *fs_info = root->fs_info;
662 if (rc && root->node) {
665 root->commit_root->start);
672 ASSERT(!node || (struct btrfs_root *)node->data == root);
676 * We only put the reloc root here if it's on the list. There's a lot
678 * the reloc roots, and then add the reloc root back onto
684 if (!list_empty(&root->root_list)) {
686 list_del_init(&root->root_list);
690 btrfs_put_root(root);
695 * helper to update the 'address of tree root -> reloc tree'
698 static int __update_reloc_root(struct btrfs_root *root)
700 struct btrfs_fs_info *fs_info = root->fs_info;
707 root->commit_root->start);
716 BUG_ON((struct btrfs_root *)node->data != root);
719 node->bytenr = root->node->start;
729 struct btrfs_root *root, u64 objectid)
731 struct btrfs_fs_info *fs_info = root->fs_info;
747 if (root->root_key.objectid == objectid) {
751 ret = btrfs_copy_root(trans, root, root->commit_root, &eb,
758 * root - like this ctree.c:btrfs_block_can_be_shared() behaves
759 * correctly (returns true) when the relocation root is created
764 commit_root_gen = btrfs_header_generation(root->commit_root);
765 btrfs_set_root_last_snapshot(&root->root_item, commit_root_gen);
774 ret = btrfs_copy_root(trans, root, root->node, &eb,
786 memcpy(root_item, &root->root_item, sizeof(*root_item));
791 if (root->root_key.objectid == objectid) {
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)
834 struct btrfs_fs_info *fs_info = root->fs_info;
848 if (reloc_root_is_dead(root))
854 * corresponding fs root, and then here we update the last trans for the
855 * reloc root. This means that we have to do this for the entire life
856 * of the reloc root, regardless of which stage of the relocation we are
859 if (root->reloc_root) {
860 reloc_root = root->reloc_root;
870 root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
878 reloc_root = create_reloc_root(trans, root, root->root_key.objectid);
884 root->reloc_root = btrfs_grab_root(reloc_root);
889 * update root item of reloc tree
892 struct btrfs_root *root)
894 struct btrfs_fs_info *fs_info = root->fs_info;
899 if (!have_reloc_root(root))
902 reloc_root = root->reloc_root;
907 * the root. We have the ref for root->reloc_root, but just in case
908 * hold it while we update the reloc root.
912 /* root->reloc_root will stay until current relocation finished */
915 set_bit(BTRFS_ROOT_DEAD_RELOC_TREE, &root->state);
941 static struct inode *find_next_inode(struct btrfs_root *root, u64 objectid)
948 spin_lock(&root->inode_lock);
950 node = root->inode_tree.rb_node;
977 spin_unlock(&root->inode_lock);
982 if (cond_resched_lock(&root->inode_lock))
987 spin_unlock(&root->inode_lock);
997 struct btrfs_root *root = BTRFS_I(reloc_inode)->root;
1008 ret = btrfs_lookup_file_extent(NULL, root, path,
1045 struct btrfs_root *root,
1048 struct btrfs_fs_info *fs_info = root->fs_info;
1067 if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
1096 if (root->root_key.objectid != BTRFS_TREE_RELOC_OBJECTID) {
1098 inode = find_next_inode(root, key.objectid);
1102 inode = find_next_inode(root, key.objectid);
1139 ref.real_root = root->root_key.objectid;
1150 ref.real_root = root->root_key.objectid;
1337 * CoW on the subtree root node before transaction commit.
1399 int walk_up_reloc_tree(struct btrfs_root *root, struct btrfs_path *path,
1407 last_snapshot = btrfs_root_last_snapshot(&root->root_item);
1436 int walk_down_reloc_tree(struct btrfs_root *root, struct btrfs_path *path,
1439 struct btrfs_fs_info *fs_info = root->fs_info;
1447 last_snapshot = btrfs_root_last_snapshot(&root->root_item);
1492 static int invalidate_extent_cache(struct btrfs_root *root,
1496 struct btrfs_fs_info *fs_info = root->fs_info;
1510 inode = find_next_inode(root, objectid);
1584 struct btrfs_root *root)
1586 struct btrfs_root *reloc_root = root->reloc_root;
1589 /* @root must be a subvolume tree root with a valid reloc tree */
1590 ASSERT(root->root_key.objectid != BTRFS_TREE_RELOC_OBJECTID);
1598 btrfs_update_reloc_root(trans, root);
1600 if (list_empty(&root->reloc_dirty_list)) {
1601 btrfs_grab_root(root);
1602 list_add_tail(&root->reloc_dirty_list, &rc->dirty_subvol_roots);
1608 struct btrfs_root *root;
1613 list_for_each_entry_safe(root, next, &rc->dirty_subvol_roots,
1615 if (root->root_key.objectid != BTRFS_TREE_RELOC_OBJECTID) {
1616 /* Merged subvolume, cleanup its reloc root */
1617 struct btrfs_root *reloc_root = root->reloc_root;
1619 list_del_init(&root->reloc_dirty_list);
1620 root->reloc_root = NULL;
1623 * root->reloc_root = NULL. Pairs with have_reloc_root.
1626 clear_bit(BTRFS_ROOT_DEAD_RELOC_TREE, &root->state);
1640 btrfs_put_root(root);
1643 ret2 = btrfs_drop_snapshot(root, 0, 1);
1645 btrfs_put_root(root);
1659 struct btrfs_root *root)
1682 reloc_root = root->reloc_root;
1713 * block COW, we COW at most from level 1 to root level for each tree.
1723 ret = btrfs_block_rsv_refill(root, rc->block_rsv, min_reserved,
1729 trans = btrfs_start_transaction(root, 0);
1743 * btrfs_update_reloc_root() and update our root item
1764 ret = replace_path(trans, rc, root, reloc_root, path,
1786 * this is OK since root refs == 1 in this case.
1798 invalidate_extent_cache(root, &key, &next_key);
1803 * relocated and the block is tree root.
1805 leaf = btrfs_lock_root_node(root);
1806 ret = btrfs_cow_block(trans, root, leaf, NULL, 0, &leaf,
1816 insert_dirty_subvol(trans, rc, root);
1824 invalidate_extent_cache(root, &key, &next_key);
1832 struct btrfs_root *root = rc->extent_root;
1833 struct btrfs_fs_info *fs_info = root->fs_info;
1848 ret = btrfs_block_rsv_add(root, rc->block_rsv, num_bytes,
1878 root = btrfs_get_fs_root(fs_info, reloc_root->root_key.offset,
1880 BUG_ON(IS_ERR(root));
1881 BUG_ON(root->reloc_root != reloc_root);
1889 btrfs_update_reloc_root(trans, root);
1892 btrfs_put_root(root);
1917 struct btrfs_root *root;
1923 root = rc->extent_root;
1940 root = btrfs_get_fs_root(fs_info, reloc_root->root_key.offset,
1943 BUG_ON(IS_ERR(root));
1944 BUG_ON(root->reloc_root != reloc_root);
1945 ret = merge_reloc_root(rc, root);
1946 btrfs_put_root(root);
1954 if (!IS_ERR(root)) {
1955 if (root->reloc_root == reloc_root) {
1956 root->reloc_root = NULL;
1960 &root->state);
1961 btrfs_put_root(root);
1965 /* Don't forget to queue this reloc root for cleanup */
1980 /* new reloc root may be added */
1995 * fine because we're bailing here, and we hold a reference on the root
1997 * do the reloc_dirty_list afterwards. Meanwhile the root->reloc_root
2019 struct btrfs_root *root;
2025 root = btrfs_get_fs_root(fs_info, reloc_root->root_key.offset, false);
2026 BUG_ON(IS_ERR(root));
2027 BUG_ON(root->reloc_root != reloc_root);
2028 ret = btrfs_record_root_in_trans(trans, root);
2029 btrfs_put_root(root);
2041 struct btrfs_root *root;
2048 root = next->root;
2049 BUG_ON(!root);
2050 BUG_ON(!test_bit(BTRFS_ROOT_SHAREABLE, &root->state));
2052 if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
2053 record_reloc_root_in_trans(trans, root);
2057 btrfs_record_root_in_trans(trans, root);
2058 root = root->reloc_root;
2060 if (next->new_bytenr != root->node->start) {
2063 next->new_bytenr = root->node->start;
2064 btrfs_put_root(next->root);
2065 next->root = btrfs_grab_root(root);
2066 ASSERT(next->root);
2074 root = NULL;
2079 if (!root)
2090 return 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;
2115 root = next->root;
2116 BUG_ON(!root);
2119 if (!test_bit(BTRFS_ROOT_SHAREABLE, &root->state))
2120 return root;
2122 if (root->root_key.objectid != BTRFS_TREE_RELOC_OBJECTID)
2123 fs_root = root;
2176 struct btrfs_root *root = rc->extent_root;
2177 struct btrfs_fs_info *fs_info = root->fs_info;
2192 ret = btrfs_block_rsv_refill(root, rc->block_rsv, num_bytes,
2230 struct btrfs_root *root;
2250 root = select_reloc_root(trans, rc, upper, edges);
2251 BUG_ON(!root);
2269 ret = btrfs_search_slot(trans, root, key, path, 0, 1);
2304 btrfs_err(root->fs_info,
2316 blocksize = root->fs_info->nodesize;
2333 ret = btrfs_cow_block(trans, root, eb, upper->eb,
2352 ref.real_root = root->root_key.objectid;
2358 ret = btrfs_drop_subtree(trans, root, eb, upper->eb);
2493 struct btrfs_root *root;
2508 root = select_one_root(node);
2509 if (root == ERR_PTR(-ENOENT)) {
2514 if (root) {
2515 if (test_bit(BTRFS_ROOT_SHAREABLE, &root->state)) {
2518 btrfs_record_root_in_trans(trans, root);
2519 root = root->reloc_root;
2520 node->new_bytenr = root->node->start;
2521 btrfs_put_root(node->root);
2522 node->root = btrfs_grab_root(root);
2523 ASSERT(node->root);
2527 ret = btrfs_search_slot(trans, root, key, path, 0, 1);
2647 btrfs_free_reserved_data_space_noquota(inode->root->fs_info,
2997 struct btrfs_root *root = fs_info->tree_root;
3004 inode = btrfs_iget(fs_info->sb, ino, root);
3014 trans = btrfs_join_transaction(root);
3030 * Locate the free space cache EXTENT_DATA in root tree leaf and delete the
3463 struct btrfs_root *root, u64 objectid)
3474 ret = btrfs_insert_empty_inode(trans, root, path, objectid);
3502 struct btrfs_root *root;
3506 root = btrfs_grab_root(fs_info->data_reloc_root);
3507 trans = btrfs_start_transaction(root, 6);
3509 btrfs_put_root(root);
3513 err = btrfs_find_free_objectid(root, &objectid);
3517 err = __insert_orphan_inode(trans, root, objectid);
3520 inode = btrfs_iget(fs_info->sb, objectid, root);
3526 btrfs_put_root(root);
3714 static noinline_for_stack int mark_garbage_root(struct btrfs_root *root)
3716 struct btrfs_fs_info *fs_info = root->fs_info;
3724 memset(&root->root_item.drop_progress, 0,
3725 sizeof(root->root_item.drop_progress));
3726 root->root_item.drop_level = 0;
3727 btrfs_set_root_refs(&root->root_item, 0);
3729 &root->root_key, &root->root_item);
3743 int btrfs_recover_relocation(struct btrfs_root *root)
3745 struct btrfs_fs_info *fs_info = root->fs_info;
3786 reloc_root = btrfs_read_tree_root(root, &key);
3912 struct btrfs_fs_info *fs_info = inode->root->fs_info;
3956 struct btrfs_root *root, struct extent_buffer *buf,
3959 struct btrfs_fs_info *fs_info = root->fs_info;
3971 root->root_key.objectid == BTRFS_DATA_RELOC_TREE_OBJECTID);
3975 btrfs_root_last_snapshot(&root->root_item))
3978 if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID &&
4005 ret = replace_file_extents(trans, rc, root, cow);
4016 struct btrfs_root *root = pending->root;
4017 struct reloc_control *rc = root->fs_info->reloc_ctl;
4019 if (!rc || !have_reloc_root(root))
4025 root = root->reloc_root;
4026 BUG_ON(btrfs_root_refs(&root->root_item) == 0);
4042 * and create reloc root for the newly created snapshot
4045 * references held on the reloc_root, one for root->reloc_root and one for
4051 struct btrfs_root *root = pending->root;
4054 struct reloc_control *rc = root->fs_info->reloc_ctl;
4057 if (!rc || !have_reloc_root(root))
4060 rc = root->fs_info->reloc_ctl;
4072 reloc_root = create_reloc_root(trans, root->reloc_root,
4082 ret = clone_backref_node(trans, rc, root, reloc_root);