Lines Matching refs:root
235 static bool reloc_root_is_dead(const struct btrfs_root *root) in reloc_root_is_dead() argument
243 if (test_bit(BTRFS_ROOT_DEAD_RELOC_TREE, &root->state)) in reloc_root_is_dead()
256 static bool have_reloc_root(const struct btrfs_root *root) in have_reloc_root() argument
258 if (reloc_root_is_dead(root)) in have_reloc_root()
260 if (!root->reloc_root) in have_reloc_root()
265 bool btrfs_should_ignore_reloc_root(const struct btrfs_root *root) in btrfs_should_ignore_reloc_root() argument
269 if (!test_bit(BTRFS_ROOT_SHAREABLE, &root->state)) in btrfs_should_ignore_reloc_root()
273 if (reloc_root_is_dead(root)) in btrfs_should_ignore_reloc_root()
276 reloc_root = root->reloc_root; in btrfs_should_ignore_reloc_root()
281 root->fs_info->running_transaction->transid) in btrfs_should_ignore_reloc_root()
299 struct btrfs_root *root = NULL; in find_reloc_root() local
306 root = node->data; in find_reloc_root()
309 return btrfs_grab_root(root); in find_reloc_root()
519 new_node->root = btrfs_grab_root(dest); in clone_backref_node()
520 ASSERT(new_node->root); in clone_backref_node()
561 static int __add_reloc_root(struct btrfs_root *root) in __add_reloc_root() argument
563 struct btrfs_fs_info *fs_info = root->fs_info; in __add_reloc_root()
572 node->bytenr = root->commit_root->start; in __add_reloc_root()
573 node->data = root; in __add_reloc_root()
586 list_add_tail(&root->root_list, &rc->reloc_roots); in __add_reloc_root()
594 static void __del_reloc_root(struct btrfs_root *root) in __del_reloc_root() argument
596 struct btrfs_fs_info *fs_info = root->fs_info; in __del_reloc_root()
602 if (rc && root->node) { in __del_reloc_root()
605 root->commit_root->start); in __del_reloc_root()
612 ASSERT(!node || (struct btrfs_root *)node->data == root); in __del_reloc_root()
624 if (!list_empty(&root->root_list)) { in __del_reloc_root()
626 list_del_init(&root->root_list); in __del_reloc_root()
630 btrfs_put_root(root); in __del_reloc_root()
638 static int __update_reloc_root(struct btrfs_root *root) in __update_reloc_root() argument
640 struct btrfs_fs_info *fs_info = root->fs_info; in __update_reloc_root()
647 root->commit_root->start); in __update_reloc_root()
656 BUG_ON((struct btrfs_root *)node->data != root); in __update_reloc_root()
659 node->bytenr = root->node->start; in __update_reloc_root()
669 struct btrfs_root *root, u64 objectid) in create_reloc_root() argument
671 struct btrfs_fs_info *fs_info = root->fs_info; in create_reloc_root()
687 if (btrfs_root_id(root) == objectid) { in create_reloc_root()
691 ret = btrfs_copy_root(trans, root, root->commit_root, &eb, in create_reloc_root()
704 commit_root_gen = btrfs_header_generation(root->commit_root); in create_reloc_root()
705 btrfs_set_root_last_snapshot(&root->root_item, commit_root_gen); in create_reloc_root()
714 ret = btrfs_copy_root(trans, root, root->node, &eb, in create_reloc_root()
726 memcpy(root_item, &root->root_item, sizeof(*root_item)); in create_reloc_root()
731 if (btrfs_root_id(root) == objectid) { in create_reloc_root()
772 struct btrfs_root *root) in btrfs_init_reloc_root() argument
774 struct btrfs_fs_info *fs_info = root->fs_info; in btrfs_init_reloc_root()
788 if (reloc_root_is_dead(root)) in btrfs_init_reloc_root()
799 if (root->reloc_root) { in btrfs_init_reloc_root()
800 reloc_root = root->reloc_root; in btrfs_init_reloc_root()
809 if (!rc->create_reloc_tree || btrfs_root_id(root) == BTRFS_TREE_RELOC_OBJECTID) in btrfs_init_reloc_root()
817 reloc_root = create_reloc_root(trans, root, btrfs_root_id(root)); in btrfs_init_reloc_root()
830 root->reloc_root = btrfs_grab_root(reloc_root); in btrfs_init_reloc_root()
838 struct btrfs_root *root) in btrfs_update_reloc_root() argument
840 struct btrfs_fs_info *fs_info = root->fs_info; in btrfs_update_reloc_root()
845 if (!have_reloc_root(root)) in btrfs_update_reloc_root()
848 reloc_root = root->reloc_root; in btrfs_update_reloc_root()
861 set_bit(BTRFS_ROOT_DEAD_RELOC_TREE, &root->state); in btrfs_update_reloc_root()
889 struct btrfs_root *root = BTRFS_I(reloc_inode)->root; in get_new_location() local
900 ret = btrfs_lookup_file_extent(NULL, root, path, in get_new_location()
937 struct btrfs_root *root, in replace_file_extents() argument
940 struct btrfs_fs_info *fs_info = root->fs_info; in replace_file_extents()
959 if (btrfs_root_id(root) == BTRFS_TREE_RELOC_OBJECTID) in replace_file_extents()
988 if (btrfs_root_id(root) != BTRFS_TREE_RELOC_OBJECTID) { in replace_file_extents()
990 inode = btrfs_find_first_inode(root, key.objectid); in replace_file_extents()
994 inode = btrfs_find_first_inode(root, key.objectid); in replace_file_extents()
1040 ref.owning_root = btrfs_root_id(root); in replace_file_extents()
1043 btrfs_root_id(root), false); in replace_file_extents()
1054 ref.owning_root = btrfs_root_id(root); in replace_file_extents()
1057 btrfs_root_id(root), false); in replace_file_extents()
1334 int walk_up_reloc_tree(struct btrfs_root *root, struct btrfs_path *path, in walk_up_reloc_tree() argument
1342 last_snapshot = btrfs_root_last_snapshot(&root->root_item); in walk_up_reloc_tree()
1371 int walk_down_reloc_tree(struct btrfs_root *root, struct btrfs_path *path, in walk_down_reloc_tree() argument
1380 last_snapshot = btrfs_root_last_snapshot(&root->root_item); in walk_down_reloc_tree()
1416 static int invalidate_extent_cache(struct btrfs_root *root, in invalidate_extent_cache() argument
1420 struct btrfs_fs_info *fs_info = root->fs_info; in invalidate_extent_cache()
1437 inode = btrfs_find_first_inode(root, objectid); in invalidate_extent_cache()
1511 struct btrfs_root *root) in insert_dirty_subvol() argument
1513 struct btrfs_root *reloc_root = root->reloc_root; in insert_dirty_subvol()
1518 ASSERT(btrfs_root_id(root) != BTRFS_TREE_RELOC_OBJECTID); in insert_dirty_subvol()
1526 ret = btrfs_update_reloc_root(trans, root); in insert_dirty_subvol()
1530 if (list_empty(&root->reloc_dirty_list)) { in insert_dirty_subvol()
1531 btrfs_grab_root(root); in insert_dirty_subvol()
1532 list_add_tail(&root->reloc_dirty_list, &rc->dirty_subvol_roots); in insert_dirty_subvol()
1540 struct btrfs_root *root; in clean_dirty_subvols() local
1545 list_for_each_entry_safe(root, next, &rc->dirty_subvol_roots, in clean_dirty_subvols()
1547 if (btrfs_root_id(root) != BTRFS_TREE_RELOC_OBJECTID) { in clean_dirty_subvols()
1549 struct btrfs_root *reloc_root = root->reloc_root; in clean_dirty_subvols()
1551 list_del_init(&root->reloc_dirty_list); in clean_dirty_subvols()
1552 root->reloc_root = NULL; in clean_dirty_subvols()
1558 clear_bit(BTRFS_ROOT_DEAD_RELOC_TREE, &root->state); in clean_dirty_subvols()
1572 btrfs_put_root(root); in clean_dirty_subvols()
1575 ret2 = btrfs_drop_snapshot(root, 0, 1); in clean_dirty_subvols()
1577 btrfs_put_root(root); in clean_dirty_subvols()
1591 struct btrfs_root *root) in merge_reloc_root() argument
1613 reloc_root = root->reloc_root; in merge_reloc_root()
1659 trans = btrfs_start_transaction(root, 0); in merge_reloc_root()
1692 ret = replace_path(trans, rc, root, reloc_root, path, in merge_reloc_root()
1723 invalidate_extent_cache(root, &key, &next_key); in merge_reloc_root()
1730 leaf = btrfs_lock_root_node(root); in merge_reloc_root()
1731 ret = btrfs_cow_block(trans, root, leaf, NULL, 0, &leaf, in merge_reloc_root()
1739 ret = insert_dirty_subvol(trans, rc, root); in merge_reloc_root()
1750 invalidate_extent_cache(root, &key, &next_key); in merge_reloc_root()
1758 struct btrfs_root *root = rc->extent_root; in prepare_to_merge() local
1759 struct btrfs_fs_info *fs_info = root->fs_info; in prepare_to_merge()
1804 root = btrfs_get_fs_root(fs_info, reloc_root->root_key.offset, in prepare_to_merge()
1806 if (IS_ERR(root)) { in prepare_to_merge()
1812 btrfs_abort_transaction(trans, (int)PTR_ERR(root)); in prepare_to_merge()
1814 err = PTR_ERR(root); in prepare_to_merge()
1818 if (unlikely(root->reloc_root != reloc_root)) { in prepare_to_merge()
1819 if (root->reloc_root) { in prepare_to_merge()
1822 btrfs_root_id(root), in prepare_to_merge()
1823 btrfs_root_id(root->reloc_root), in prepare_to_merge()
1824 root->reloc_root->root_key.type, in prepare_to_merge()
1825 root->reloc_root->root_key.offset, in prepare_to_merge()
1827 &root->reloc_root->root_item), in prepare_to_merge()
1836 btrfs_root_id(root), in prepare_to_merge()
1844 btrfs_put_root(root); in prepare_to_merge()
1857 ret = btrfs_update_reloc_root(trans, root); in prepare_to_merge()
1864 btrfs_put_root(root); in prepare_to_merge()
1896 struct btrfs_root *root; in merge_reloc_roots() local
1902 root = rc->extent_root; in merge_reloc_roots()
1919 root = btrfs_get_fs_root(fs_info, reloc_root->root_key.offset, in merge_reloc_roots()
1922 if (WARN_ON(IS_ERR(root))) { in merge_reloc_roots()
1931 ret = PTR_ERR(root); in merge_reloc_roots()
1934 if (WARN_ON(root->reloc_root != reloc_root)) { in merge_reloc_roots()
1942 ret = merge_reloc_root(rc, root); in merge_reloc_roots()
1943 btrfs_put_root(root); in merge_reloc_roots()
1951 if (!IS_ERR(root)) { in merge_reloc_roots()
1952 if (root->reloc_root == reloc_root) { in merge_reloc_roots()
1953 root->reloc_root = NULL; in merge_reloc_roots()
1957 &root->state); in merge_reloc_roots()
1958 btrfs_put_root(root); in merge_reloc_roots()
2016 struct btrfs_root *root; in record_reloc_root_in_trans() local
2022 root = btrfs_get_fs_root(fs_info, reloc_root->root_key.offset, false); in record_reloc_root_in_trans()
2032 if (IS_ERR(root)) { in record_reloc_root_in_trans()
2034 return PTR_ERR(root); in record_reloc_root_in_trans()
2036 if (root->reloc_root != reloc_root) { in record_reloc_root_in_trans()
2041 btrfs_put_root(root); in record_reloc_root_in_trans()
2044 ret = btrfs_record_root_in_trans(trans, root); in record_reloc_root_in_trans()
2045 btrfs_put_root(root); in record_reloc_root_in_trans()
2057 struct btrfs_root *root; in select_reloc_root() local
2065 root = next->root; in select_reloc_root()
2079 if (!root) { in select_reloc_root()
2086 if (!test_bit(BTRFS_ROOT_SHAREABLE, &root->state)) { in select_reloc_root()
2094 if (btrfs_root_id(root) == BTRFS_TREE_RELOC_OBJECTID) { in select_reloc_root()
2095 ret = record_reloc_root_in_trans(trans, root); in select_reloc_root()
2101 ret = btrfs_record_root_in_trans(trans, root); in select_reloc_root()
2104 root = root->reloc_root; in select_reloc_root()
2110 if (!root) in select_reloc_root()
2113 if (next->new_bytenr != root->node->start) { in select_reloc_root()
2130 next->new_bytenr = root->node->start; in select_reloc_root()
2131 btrfs_put_root(next->root); in select_reloc_root()
2132 next->root = btrfs_grab_root(root); in select_reloc_root()
2133 ASSERT(next->root); in select_reloc_root()
2141 root = NULL; in select_reloc_root()
2146 if (!root) { in select_reloc_root()
2163 return root; in select_reloc_root()
2179 struct btrfs_root *root; in select_one_root() local
2188 root = next->root; in select_one_root()
2194 if (!root) in select_one_root()
2198 if (!test_bit(BTRFS_ROOT_SHAREABLE, &root->state)) in select_one_root()
2199 return root; in select_one_root()
2201 if (btrfs_root_id(root) != BTRFS_TREE_RELOC_OBJECTID) in select_one_root()
2202 fs_root = root; in select_one_root()
2254 struct btrfs_root *root = rc->extent_root; in reserve_metadata_space() local
2255 struct btrfs_fs_info *fs_info = root->fs_info; in reserve_metadata_space()
2307 struct btrfs_root *root; in do_relocation() local
2326 root = select_reloc_root(trans, rc, upper, edges); in do_relocation()
2327 if (IS_ERR(root)) { in do_relocation()
2328 ret = PTR_ERR(root); in do_relocation()
2346 ret = btrfs_search_slot(trans, root, key, path, 0, 1); in do_relocation()
2377 btrfs_err(root->fs_info, in do_relocation()
2389 blocksize = root->fs_info->nodesize; in do_relocation()
2398 ret = btrfs_cow_block(trans, root, eb, upper->eb, in do_relocation()
2426 btrfs_root_id(root), false); in do_relocation()
2429 ret = btrfs_drop_subtree(trans, root, eb, in do_relocation()
2575 struct btrfs_root *root; in relocate_tree_block() local
2590 root = select_one_root(node); in relocate_tree_block()
2591 if (IS_ERR(root)) { in relocate_tree_block()
2592 ret = PTR_ERR(root); in relocate_tree_block()
2603 if (root) { in relocate_tree_block()
2604 if (test_bit(BTRFS_ROOT_SHAREABLE, &root->state)) { in relocate_tree_block()
2621 btrfs_err(root->fs_info, in relocate_tree_block()
2627 ret = btrfs_record_root_in_trans(trans, root); in relocate_tree_block()
2634 if (!root->reloc_root) { in relocate_tree_block()
2638 root = root->reloc_root; in relocate_tree_block()
2639 node->new_bytenr = root->node->start; in relocate_tree_block()
2640 btrfs_put_root(node->root); in relocate_tree_block()
2641 node->root = btrfs_grab_root(root); in relocate_tree_block()
2642 ASSERT(node->root); in relocate_tree_block()
2646 if (root == root->fs_info->chunk_root) in relocate_tree_block()
2648 ret = btrfs_search_slot(trans, root, key, path, 0, 1); in relocate_tree_block()
2650 if (root == root->fs_info->chunk_root) in relocate_tree_block()
2756 struct btrfs_fs_info *fs_info = inode->root->fs_info; in prealloc_file_extent_cluster()
2831 btrfs_free_reserved_data_space_noquota(inode->root->fs_info, in prealloc_file_extent_cluster()
3083 struct btrfs_root *root = BTRFS_I(inode)->root; in relocate_data_extent() local
3103 if (cluster->nr > 0 && cluster->owning_root != root->relocation_src_root) { in relocate_data_extent()
3104 u64 tmp = root->relocation_src_root; in relocate_data_extent()
3111 root->relocation_src_root = cluster->owning_root; in relocate_data_extent()
3117 root->relocation_src_root = tmp; in relocate_data_extent()
3122 cluster->owning_root = root->relocation_src_root; in relocate_data_extent()
3318 struct btrfs_root *root = fs_info->tree_root; in delete_block_group_cache() local
3325 inode = btrfs_iget(ino, root); in delete_block_group_cache()
3335 trans = btrfs_join_transaction(root); in delete_block_group_cache()
3657 struct btrfs_root *root = BTRFS_I(rc->data_inode)->root; in relocate_block_group() local
3662 root->relocation_src_root = owning_root_id; in relocate_block_group()
3773 struct btrfs_root *root, u64 objectid) in __insert_orphan_inode() argument
3784 ret = btrfs_insert_empty_inode(trans, root, path, objectid); in __insert_orphan_inode()
3803 struct btrfs_root *root, u64 objectid) in delete_orphan_inode() argument
3818 ret = btrfs_search_slot(trans, root, &key, path, -1, 1); in delete_orphan_inode()
3824 ret = btrfs_del_item(trans, root, path); in delete_orphan_inode()
3841 struct btrfs_root *root; in create_reloc_inode() local
3845 root = btrfs_grab_root(fs_info->data_reloc_root); in create_reloc_inode()
3846 trans = btrfs_start_transaction(root, 6); in create_reloc_inode()
3848 btrfs_put_root(root); in create_reloc_inode()
3852 ret = btrfs_get_free_objectid(root, &objectid); in create_reloc_inode()
3856 ret = __insert_orphan_inode(trans, root, objectid); in create_reloc_inode()
3860 inode = btrfs_iget(objectid, root); in create_reloc_inode()
3862 delete_orphan_inode(trans, root, objectid); in create_reloc_inode()
3871 btrfs_put_root(root); in create_reloc_inode()
4130 static noinline_for_stack int mark_garbage_root(struct btrfs_root *root) in mark_garbage_root() argument
4132 struct btrfs_fs_info *fs_info = root->fs_info; in mark_garbage_root()
4140 memset(&root->root_item.drop_progress, 0, in mark_garbage_root()
4141 sizeof(root->root_item.drop_progress)); in mark_garbage_root()
4142 btrfs_set_root_drop_level(&root->root_item, 0); in mark_garbage_root()
4143 btrfs_set_root_refs(&root->root_item, 0); in mark_garbage_root()
4145 &root->root_key, &root->root_item); in mark_garbage_root()
4336 struct btrfs_fs_info *fs_info = inode->root->fs_info; in btrfs_reloc_clone_csums()
4376 struct btrfs_root *root, in btrfs_reloc_cow_block() argument
4380 struct btrfs_fs_info *fs_info = root->fs_info; in btrfs_reloc_cow_block()
4391 BUG_ON(rc->stage == UPDATE_DATA_PTRS && btrfs_is_data_reloc_root(root)); in btrfs_reloc_cow_block()
4395 btrfs_root_last_snapshot(&root->root_item)) in btrfs_reloc_cow_block()
4398 if (btrfs_root_id(root) == BTRFS_TREE_RELOC_OBJECTID && rc->create_reloc_tree) { in btrfs_reloc_cow_block()
4424 ret = replace_file_extents(trans, rc, root, cow); in btrfs_reloc_cow_block()
4435 struct btrfs_root *root = pending->root; in btrfs_reloc_pre_snapshot() local
4436 struct reloc_control *rc = root->fs_info->reloc_ctl; in btrfs_reloc_pre_snapshot()
4438 if (!rc || !have_reloc_root(root)) in btrfs_reloc_pre_snapshot()
4444 root = root->reloc_root; in btrfs_reloc_pre_snapshot()
4445 BUG_ON(btrfs_root_refs(&root->root_item) == 0); in btrfs_reloc_pre_snapshot()
4470 struct btrfs_root *root = pending->root; in btrfs_reloc_post_snapshot() local
4473 struct reloc_control *rc = root->fs_info->reloc_ctl; in btrfs_reloc_post_snapshot()
4476 if (!rc || !have_reloc_root(root)) in btrfs_reloc_post_snapshot()
4479 rc = root->fs_info->reloc_ctl; in btrfs_reloc_post_snapshot()
4491 reloc_root = create_reloc_root(trans, root->reloc_root, btrfs_root_id(new_root)); in btrfs_reloc_post_snapshot()
4505 ret = clone_backref_node(trans, rc, root, reloc_root); in btrfs_reloc_post_snapshot()