Lines Matching refs: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()
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()
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()
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()
580 new_node->root = btrfs_grab_root(dest); in clone_backref_node()
581 ASSERT(new_node->root); in clone_backref_node()
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()
646 list_add_tail(&root->root_list, &rc->reloc_roots); in __add_reloc_root()
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()
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()
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()
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()
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()
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()
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()
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()
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()
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()
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()
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()
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()
1764 ret = replace_path(trans, rc, root, reloc_root, path, in merge_reloc_root()
1798 invalidate_extent_cache(root, &key, &next_key); 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()
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()
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()
3463 struct btrfs_root *root, u64 objectid) in __insert_orphan_inode() argument
3474 ret = btrfs_insert_empty_inode(trans, root, path, objectid); in __insert_orphan_inode()
3502 struct btrfs_root *root; in create_reloc_inode() local
3506 root = btrfs_grab_root(fs_info->data_reloc_root); in create_reloc_inode()
3507 trans = btrfs_start_transaction(root, 6); in create_reloc_inode()
3509 btrfs_put_root(root); in create_reloc_inode()
3513 err = btrfs_find_free_objectid(root, &objectid); in create_reloc_inode()
3517 err = __insert_orphan_inode(trans, root, objectid); in create_reloc_inode()
3520 inode = btrfs_iget(fs_info->sb, objectid, root); in create_reloc_inode()
3526 btrfs_put_root(root); in create_reloc_inode()
3714 static noinline_for_stack int mark_garbage_root(struct btrfs_root *root) in mark_garbage_root() argument
3716 struct btrfs_fs_info *fs_info = root->fs_info; in mark_garbage_root()
3724 memset(&root->root_item.drop_progress, 0, in mark_garbage_root()
3725 sizeof(root->root_item.drop_progress)); in mark_garbage_root()
3726 root->root_item.drop_level = 0; in mark_garbage_root()
3727 btrfs_set_root_refs(&root->root_item, 0); in mark_garbage_root()
3729 &root->root_key, &root->root_item); in mark_garbage_root()
3743 int btrfs_recover_relocation(struct btrfs_root *root) in btrfs_recover_relocation() argument
3745 struct btrfs_fs_info *fs_info = root->fs_info; in btrfs_recover_relocation()
3786 reloc_root = btrfs_read_tree_root(root, &key); in btrfs_recover_relocation()
3912 struct btrfs_fs_info *fs_info = inode->root->fs_info; in btrfs_reloc_clone_csums()
3956 struct btrfs_root *root, struct extent_buffer *buf, in btrfs_reloc_cow_block() argument
3959 struct btrfs_fs_info *fs_info = root->fs_info; in btrfs_reloc_cow_block()
3971 root->root_key.objectid == BTRFS_DATA_RELOC_TREE_OBJECTID); in btrfs_reloc_cow_block()
3975 btrfs_root_last_snapshot(&root->root_item)) in btrfs_reloc_cow_block()
3978 if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID && in btrfs_reloc_cow_block()
4005 ret = replace_file_extents(trans, rc, root, cow); in btrfs_reloc_cow_block()
4016 struct btrfs_root *root = pending->root; in btrfs_reloc_pre_snapshot() local
4017 struct reloc_control *rc = root->fs_info->reloc_ctl; in btrfs_reloc_pre_snapshot()
4019 if (!rc || !have_reloc_root(root)) in btrfs_reloc_pre_snapshot()
4025 root = root->reloc_root; in btrfs_reloc_pre_snapshot()
4026 BUG_ON(btrfs_root_refs(&root->root_item) == 0); in btrfs_reloc_pre_snapshot()
4051 struct btrfs_root *root = pending->root; in btrfs_reloc_post_snapshot() local
4054 struct reloc_control *rc = root->fs_info->reloc_ctl; in btrfs_reloc_post_snapshot()
4057 if (!rc || !have_reloc_root(root)) in btrfs_reloc_post_snapshot()
4060 rc = root->fs_info->reloc_ctl; in btrfs_reloc_post_snapshot()
4072 reloc_root = create_reloc_root(trans, root->reloc_root, in btrfs_reloc_post_snapshot()
4082 ret = clone_backref_node(trans, rc, root, reloc_root); in btrfs_reloc_post_snapshot()