Lines Matching refs:root

302 static bool reloc_root_is_dead(struct btrfs_root *root)  in reloc_root_is_dead()  argument
310 if (test_bit(BTRFS_ROOT_DEAD_RELOC_TREE, &root->state)) in reloc_root_is_dead()
323 static bool have_reloc_root(struct btrfs_root *root) in have_reloc_root() argument
325 if (reloc_root_is_dead(root)) in have_reloc_root()
327 if (!root->reloc_root) in have_reloc_root()
332 int btrfs_should_ignore_reloc_root(struct btrfs_root *root) in btrfs_should_ignore_reloc_root() argument
336 if (!test_bit(BTRFS_ROOT_SHAREABLE, &root->state)) in btrfs_should_ignore_reloc_root()
340 if (reloc_root_is_dead(root)) in btrfs_should_ignore_reloc_root()
343 reloc_root = root->reloc_root; in btrfs_should_ignore_reloc_root()
348 root->fs_info->running_transaction->transid) in btrfs_should_ignore_reloc_root()
367 struct btrfs_root *root = NULL; in find_reloc_root() local
374 root = node->data; in find_reloc_root()
377 return btrfs_grab_root(root); in find_reloc_root()
593 new_node->root = btrfs_grab_root(dest); in clone_backref_node()
594 ASSERT(new_node->root); in clone_backref_node()
635 static int __must_check __add_reloc_root(struct btrfs_root *root) in __add_reloc_root() argument
637 struct btrfs_fs_info *fs_info = root->fs_info; in __add_reloc_root()
646 node->bytenr = root->commit_root->start; in __add_reloc_root()
647 node->data = root; in __add_reloc_root()
660 list_add_tail(&root->root_list, &rc->reloc_roots); in __add_reloc_root()
668 static void __del_reloc_root(struct btrfs_root *root) in __del_reloc_root() argument
670 struct btrfs_fs_info *fs_info = root->fs_info; in __del_reloc_root()
676 if (rc && root->node) { in __del_reloc_root()
679 root->commit_root->start); in __del_reloc_root()
686 ASSERT(!node || (struct btrfs_root *)node->data == root); in __del_reloc_root()
698 if (!list_empty(&root->root_list)) { in __del_reloc_root()
700 list_del_init(&root->root_list); in __del_reloc_root()
704 btrfs_put_root(root); in __del_reloc_root()
712 static int __update_reloc_root(struct btrfs_root *root) in __update_reloc_root() argument
714 struct btrfs_fs_info *fs_info = root->fs_info; in __update_reloc_root()
721 root->commit_root->start); in __update_reloc_root()
730 BUG_ON((struct btrfs_root *)node->data != root); in __update_reloc_root()
733 node->bytenr = root->node->start; in __update_reloc_root()
743 struct btrfs_root *root, u64 objectid) in create_reloc_root() argument
745 struct btrfs_fs_info *fs_info = root->fs_info; in create_reloc_root()
761 if (root->root_key.objectid == objectid) { in create_reloc_root()
765 ret = btrfs_copy_root(trans, root, root->commit_root, &eb, in create_reloc_root()
778 commit_root_gen = btrfs_header_generation(root->commit_root); in create_reloc_root()
779 btrfs_set_root_last_snapshot(&root->root_item, commit_root_gen); in create_reloc_root()
788 ret = btrfs_copy_root(trans, root, root->node, &eb, in create_reloc_root()
800 memcpy(root_item, &root->root_item, sizeof(*root_item)); in create_reloc_root()
805 if (root->root_key.objectid == objectid) { in create_reloc_root()
846 struct btrfs_root *root) in btrfs_init_reloc_root() argument
848 struct btrfs_fs_info *fs_info = root->fs_info; in btrfs_init_reloc_root()
862 if (reloc_root_is_dead(root)) in btrfs_init_reloc_root()
873 if (root->reloc_root) { in btrfs_init_reloc_root()
874 reloc_root = root->reloc_root; in btrfs_init_reloc_root()
884 root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) in btrfs_init_reloc_root()
892 reloc_root = create_reloc_root(trans, root, root->root_key.objectid); in btrfs_init_reloc_root()
905 root->reloc_root = btrfs_grab_root(reloc_root); in btrfs_init_reloc_root()
913 struct btrfs_root *root) in btrfs_update_reloc_root() argument
915 struct btrfs_fs_info *fs_info = root->fs_info; in btrfs_update_reloc_root()
920 if (!have_reloc_root(root)) in btrfs_update_reloc_root()
923 reloc_root = root->reloc_root; in btrfs_update_reloc_root()
936 set_bit(BTRFS_ROOT_DEAD_RELOC_TREE, &root->state); in btrfs_update_reloc_root()
962 static struct inode *find_next_inode(struct btrfs_root *root, u64 objectid) in find_next_inode() argument
969 spin_lock(&root->inode_lock); in find_next_inode()
971 node = root->inode_tree.rb_node; in find_next_inode()
998 spin_unlock(&root->inode_lock); in find_next_inode()
1003 if (cond_resched_lock(&root->inode_lock)) in find_next_inode()
1008 spin_unlock(&root->inode_lock); in find_next_inode()
1018 struct btrfs_root *root = BTRFS_I(reloc_inode)->root; in get_new_location() local
1029 ret = btrfs_lookup_file_extent(NULL, root, path, in get_new_location()
1066 struct btrfs_root *root, in replace_file_extents() argument
1069 struct btrfs_fs_info *fs_info = root->fs_info; in replace_file_extents()
1088 if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) in replace_file_extents()
1117 if (root->root_key.objectid != BTRFS_TREE_RELOC_OBJECTID) { in replace_file_extents()
1119 inode = find_next_inode(root, key.objectid); in replace_file_extents()
1123 inode = find_next_inode(root, key.objectid); in replace_file_extents()
1165 root->root_key.objectid, false); in replace_file_extents()
1176 root->root_key.objectid, false); in replace_file_extents()
1438 int walk_up_reloc_tree(struct btrfs_root *root, struct btrfs_path *path, in walk_up_reloc_tree() argument
1446 last_snapshot = btrfs_root_last_snapshot(&root->root_item); in walk_up_reloc_tree()
1475 int walk_down_reloc_tree(struct btrfs_root *root, struct btrfs_path *path, in walk_down_reloc_tree() argument
1484 last_snapshot = btrfs_root_last_snapshot(&root->root_item); in walk_down_reloc_tree()
1520 static int invalidate_extent_cache(struct btrfs_root *root, in invalidate_extent_cache() argument
1524 struct btrfs_fs_info *fs_info = root->fs_info; in invalidate_extent_cache()
1540 inode = find_next_inode(root, objectid); in invalidate_extent_cache()
1614 struct btrfs_root *root) in insert_dirty_subvol() argument
1616 struct btrfs_root *reloc_root = root->reloc_root; in insert_dirty_subvol()
1621 ASSERT(root->root_key.objectid != BTRFS_TREE_RELOC_OBJECTID); in insert_dirty_subvol()
1629 ret = btrfs_update_reloc_root(trans, root); in insert_dirty_subvol()
1633 if (list_empty(&root->reloc_dirty_list)) { in insert_dirty_subvol()
1634 btrfs_grab_root(root); in insert_dirty_subvol()
1635 list_add_tail(&root->reloc_dirty_list, &rc->dirty_subvol_roots); in insert_dirty_subvol()
1643 struct btrfs_root *root; in clean_dirty_subvols() local
1648 list_for_each_entry_safe(root, next, &rc->dirty_subvol_roots, in clean_dirty_subvols()
1650 if (root->root_key.objectid != BTRFS_TREE_RELOC_OBJECTID) { in clean_dirty_subvols()
1652 struct btrfs_root *reloc_root = root->reloc_root; in clean_dirty_subvols()
1654 list_del_init(&root->reloc_dirty_list); in clean_dirty_subvols()
1655 root->reloc_root = NULL; in clean_dirty_subvols()
1661 clear_bit(BTRFS_ROOT_DEAD_RELOC_TREE, &root->state); in clean_dirty_subvols()
1675 btrfs_put_root(root); in clean_dirty_subvols()
1678 ret2 = btrfs_drop_snapshot(root, 0, 1); in clean_dirty_subvols()
1680 btrfs_put_root(root); in clean_dirty_subvols()
1694 struct btrfs_root *root) in merge_reloc_root() argument
1716 reloc_root = root->reloc_root; in merge_reloc_root()
1762 trans = btrfs_start_transaction(root, 0); in merge_reloc_root()
1795 ret = replace_path(trans, rc, root, reloc_root, path, in merge_reloc_root()
1826 invalidate_extent_cache(root, &key, &next_key); in merge_reloc_root()
1833 leaf = btrfs_lock_root_node(root); in merge_reloc_root()
1834 ret = btrfs_cow_block(trans, root, leaf, NULL, 0, &leaf, in merge_reloc_root()
1842 ret = insert_dirty_subvol(trans, rc, root); in merge_reloc_root()
1853 invalidate_extent_cache(root, &key, &next_key); in merge_reloc_root()
1861 struct btrfs_root *root = rc->extent_root; in prepare_to_merge() local
1862 struct btrfs_fs_info *fs_info = root->fs_info; in prepare_to_merge()
1907 root = btrfs_get_fs_root(fs_info, reloc_root->root_key.offset, in prepare_to_merge()
1909 if (IS_ERR(root)) { in prepare_to_merge()
1915 btrfs_abort_transaction(trans, (int)PTR_ERR(root)); in prepare_to_merge()
1917 err = PTR_ERR(root); in prepare_to_merge()
1921 if (unlikely(root->reloc_root != reloc_root)) { in prepare_to_merge()
1922 if (root->reloc_root) { in prepare_to_merge()
1925 root->root_key.objectid, in prepare_to_merge()
1926 root->reloc_root->root_key.objectid, in prepare_to_merge()
1927 root->reloc_root->root_key.type, in prepare_to_merge()
1928 root->reloc_root->root_key.offset, in prepare_to_merge()
1930 &root->reloc_root->root_item), in prepare_to_merge()
1939 root->root_key.objectid, in prepare_to_merge()
1947 btrfs_put_root(root); in prepare_to_merge()
1960 ret = btrfs_update_reloc_root(trans, root); in prepare_to_merge()
1967 btrfs_put_root(root); in prepare_to_merge()
1999 struct btrfs_root *root; in merge_reloc_roots() local
2005 root = rc->extent_root; in merge_reloc_roots()
2022 root = btrfs_get_fs_root(fs_info, reloc_root->root_key.offset, in merge_reloc_roots()
2025 if (WARN_ON(IS_ERR(root))) { in merge_reloc_roots()
2034 ret = PTR_ERR(root); in merge_reloc_roots()
2037 if (WARN_ON(root->reloc_root != reloc_root)) { in merge_reloc_roots()
2045 ret = merge_reloc_root(rc, root); in merge_reloc_roots()
2046 btrfs_put_root(root); in merge_reloc_roots()
2054 if (!IS_ERR(root)) { in merge_reloc_roots()
2055 if (root->reloc_root == reloc_root) { in merge_reloc_roots()
2056 root->reloc_root = NULL; in merge_reloc_roots()
2060 &root->state); in merge_reloc_roots()
2061 btrfs_put_root(root); in merge_reloc_roots()
2119 struct btrfs_root *root; in record_reloc_root_in_trans() local
2125 root = btrfs_get_fs_root(fs_info, reloc_root->root_key.offset, false); in record_reloc_root_in_trans()
2135 if (IS_ERR(root)) { in record_reloc_root_in_trans()
2137 return PTR_ERR(root); in record_reloc_root_in_trans()
2139 if (root->reloc_root != reloc_root) { in record_reloc_root_in_trans()
2144 btrfs_put_root(root); in record_reloc_root_in_trans()
2147 ret = btrfs_record_root_in_trans(trans, root); in record_reloc_root_in_trans()
2148 btrfs_put_root(root); in record_reloc_root_in_trans()
2160 struct btrfs_root *root; in select_reloc_root() local
2168 root = next->root; in select_reloc_root()
2182 if (!root) { in select_reloc_root()
2189 if (!test_bit(BTRFS_ROOT_SHAREABLE, &root->state)) { in select_reloc_root()
2197 if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) { in select_reloc_root()
2198 ret = record_reloc_root_in_trans(trans, root); in select_reloc_root()
2204 ret = btrfs_record_root_in_trans(trans, root); in select_reloc_root()
2207 root = root->reloc_root; in select_reloc_root()
2213 if (!root) in select_reloc_root()
2216 if (next->new_bytenr != root->node->start) { in select_reloc_root()
2233 next->new_bytenr = root->node->start; in select_reloc_root()
2234 btrfs_put_root(next->root); in select_reloc_root()
2235 next->root = btrfs_grab_root(root); in select_reloc_root()
2236 ASSERT(next->root); in select_reloc_root()
2244 root = NULL; in select_reloc_root()
2249 if (!root) { in select_reloc_root()
2266 return root; in select_reloc_root()
2282 struct btrfs_root *root; in select_one_root() local
2291 root = next->root; in select_one_root()
2297 if (!root) in select_one_root()
2301 if (!test_bit(BTRFS_ROOT_SHAREABLE, &root->state)) in select_one_root()
2302 return root; in select_one_root()
2304 if (root->root_key.objectid != BTRFS_TREE_RELOC_OBJECTID) in select_one_root()
2305 fs_root = root; in select_one_root()
2358 struct btrfs_root *root = rc->extent_root; in reserve_metadata_space() local
2359 struct btrfs_fs_info *fs_info = root->fs_info; in reserve_metadata_space()
2411 struct btrfs_root *root; in do_relocation() local
2432 root = select_reloc_root(trans, rc, upper, edges); in do_relocation()
2433 if (IS_ERR(root)) { in do_relocation()
2434 ret = PTR_ERR(root); in do_relocation()
2452 ret = btrfs_search_slot(trans, root, key, path, 0, 1); in do_relocation()
2483 btrfs_err(root->fs_info, in do_relocation()
2495 blocksize = root->fs_info->nodesize; in do_relocation()
2504 ret = btrfs_cow_block(trans, root, eb, upper->eb, in do_relocation()
2527 root->root_key.objectid, false); in do_relocation()
2530 ret = btrfs_drop_subtree(trans, root, eb, in do_relocation()
2676 struct btrfs_root *root; in relocate_tree_block() local
2691 root = select_one_root(node); in relocate_tree_block()
2692 if (IS_ERR(root)) { in relocate_tree_block()
2693 ret = PTR_ERR(root); in relocate_tree_block()
2704 if (root) { in relocate_tree_block()
2705 if (test_bit(BTRFS_ROOT_SHAREABLE, &root->state)) { in relocate_tree_block()
2722 btrfs_err(root->fs_info, in relocate_tree_block()
2728 ret = btrfs_record_root_in_trans(trans, root); in relocate_tree_block()
2735 if (!root->reloc_root) { in relocate_tree_block()
2739 root = root->reloc_root; in relocate_tree_block()
2740 node->new_bytenr = root->node->start; in relocate_tree_block()
2741 btrfs_put_root(node->root); in relocate_tree_block()
2742 node->root = btrfs_grab_root(root); in relocate_tree_block()
2743 ASSERT(node->root); in relocate_tree_block()
2747 if (root == root->fs_info->chunk_root) in relocate_tree_block()
2749 ret = btrfs_search_slot(trans, root, key, path, 0, 1); in relocate_tree_block()
2751 if (root == root->fs_info->chunk_root) in relocate_tree_block()
2860 struct btrfs_fs_info *fs_info = inode->root->fs_info; in prealloc_file_extent_cluster()
2935 btrfs_free_reserved_data_space_noquota(inode->root->fs_info, in prealloc_file_extent_cluster()
3370 struct btrfs_root *root = fs_info->tree_root; in delete_block_group_cache() local
3377 inode = btrfs_iget(fs_info->sb, ino, root); in delete_block_group_cache()
3387 trans = btrfs_join_transaction(root); in delete_block_group_cache()
3815 struct btrfs_root *root, u64 objectid) in __insert_orphan_inode() argument
3826 ret = btrfs_insert_empty_inode(trans, root, path, objectid); in __insert_orphan_inode()
3845 struct btrfs_root *root, u64 objectid) in delete_orphan_inode() argument
3860 ret = btrfs_search_slot(trans, root, &key, path, -1, 1); in delete_orphan_inode()
3866 ret = btrfs_del_item(trans, root, path); in delete_orphan_inode()
3883 struct btrfs_root *root; in create_reloc_inode() local
3887 root = btrfs_grab_root(fs_info->data_reloc_root); in create_reloc_inode()
3888 trans = btrfs_start_transaction(root, 6); in create_reloc_inode()
3890 btrfs_put_root(root); in create_reloc_inode()
3894 err = btrfs_get_free_objectid(root, &objectid); in create_reloc_inode()
3898 err = __insert_orphan_inode(trans, root, objectid); in create_reloc_inode()
3902 inode = btrfs_iget(fs_info->sb, objectid, root); in create_reloc_inode()
3904 delete_orphan_inode(trans, root, objectid); in create_reloc_inode()
3913 btrfs_put_root(root); in create_reloc_inode()
4175 static noinline_for_stack int mark_garbage_root(struct btrfs_root *root) in mark_garbage_root() argument
4177 struct btrfs_fs_info *fs_info = root->fs_info; in mark_garbage_root()
4185 memset(&root->root_item.drop_progress, 0, in mark_garbage_root()
4186 sizeof(root->root_item.drop_progress)); in mark_garbage_root()
4187 btrfs_set_root_drop_level(&root->root_item, 0); in mark_garbage_root()
4188 btrfs_set_root_refs(&root->root_item, 0); in mark_garbage_root()
4190 &root->root_key, &root->root_item); in mark_garbage_root()
4387 struct btrfs_fs_info *fs_info = inode->root->fs_info; in btrfs_reloc_clone_csums()
4425 struct btrfs_root *root, struct extent_buffer *buf, in btrfs_reloc_cow_block() argument
4428 struct btrfs_fs_info *fs_info = root->fs_info; in btrfs_reloc_cow_block()
4439 BUG_ON(rc->stage == UPDATE_DATA_PTRS && btrfs_is_data_reloc_root(root)); in btrfs_reloc_cow_block()
4443 btrfs_root_last_snapshot(&root->root_item)) in btrfs_reloc_cow_block()
4446 if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID && in btrfs_reloc_cow_block()
4473 ret = replace_file_extents(trans, rc, root, cow); in btrfs_reloc_cow_block()
4484 struct btrfs_root *root = pending->root; in btrfs_reloc_pre_snapshot() local
4485 struct reloc_control *rc = root->fs_info->reloc_ctl; in btrfs_reloc_pre_snapshot()
4487 if (!rc || !have_reloc_root(root)) in btrfs_reloc_pre_snapshot()
4493 root = root->reloc_root; in btrfs_reloc_pre_snapshot()
4494 BUG_ON(btrfs_root_refs(&root->root_item) == 0); in btrfs_reloc_pre_snapshot()
4519 struct btrfs_root *root = pending->root; in btrfs_reloc_post_snapshot() local
4522 struct reloc_control *rc = root->fs_info->reloc_ctl; in btrfs_reloc_post_snapshot()
4525 if (!rc || !have_reloc_root(root)) in btrfs_reloc_post_snapshot()
4528 rc = root->fs_info->reloc_ctl; in btrfs_reloc_post_snapshot()
4540 reloc_root = create_reloc_root(trans, root->reloc_root, in btrfs_reloc_post_snapshot()
4555 ret = clone_backref_node(trans, rc, root, reloc_root); in btrfs_reloc_post_snapshot()