Lines Matching refs:root
292 static bool reloc_root_is_dead(struct btrfs_root *root) in reloc_root_is_dead() argument
300 if (test_bit(BTRFS_ROOT_DEAD_RELOC_TREE, &root->state)) in reloc_root_is_dead()
313 static bool have_reloc_root(struct btrfs_root *root) in have_reloc_root() argument
315 if (reloc_root_is_dead(root)) in have_reloc_root()
317 if (!root->reloc_root) in have_reloc_root()
322 int btrfs_should_ignore_reloc_root(struct btrfs_root *root) in btrfs_should_ignore_reloc_root() argument
326 if (!test_bit(BTRFS_ROOT_SHAREABLE, &root->state)) in btrfs_should_ignore_reloc_root()
330 if (reloc_root_is_dead(root)) in btrfs_should_ignore_reloc_root()
333 reloc_root = root->reloc_root; in btrfs_should_ignore_reloc_root()
338 root->fs_info->running_transaction->transid) in btrfs_should_ignore_reloc_root()
357 struct btrfs_root *root = NULL; in find_reloc_root() local
364 root = (struct btrfs_root *)node->data; in find_reloc_root()
367 return btrfs_grab_root(root); in find_reloc_root()
582 new_node->root = btrfs_grab_root(dest); in clone_backref_node()
583 ASSERT(new_node->root); in clone_backref_node()
624 static int __must_check __add_reloc_root(struct btrfs_root *root) in __add_reloc_root() argument
626 struct btrfs_fs_info *fs_info = root->fs_info; in __add_reloc_root()
635 node->bytenr = root->commit_root->start; in __add_reloc_root()
636 node->data = root; in __add_reloc_root()
649 list_add_tail(&root->root_list, &rc->reloc_roots); in __add_reloc_root()
657 static void __del_reloc_root(struct btrfs_root *root) in __del_reloc_root() argument
659 struct btrfs_fs_info *fs_info = root->fs_info; in __del_reloc_root()
665 if (rc && root->node) { in __del_reloc_root()
668 root->commit_root->start); in __del_reloc_root()
675 ASSERT(!node || (struct btrfs_root *)node->data == root); in __del_reloc_root()
687 if (!list_empty(&root->root_list)) { in __del_reloc_root()
689 list_del_init(&root->root_list); in __del_reloc_root()
693 btrfs_put_root(root); in __del_reloc_root()
701 static int __update_reloc_root(struct btrfs_root *root) in __update_reloc_root() argument
703 struct btrfs_fs_info *fs_info = root->fs_info; in __update_reloc_root()
710 root->commit_root->start); in __update_reloc_root()
719 BUG_ON((struct btrfs_root *)node->data != root); in __update_reloc_root()
722 node->bytenr = root->node->start; in __update_reloc_root()
732 struct btrfs_root *root, u64 objectid) in create_reloc_root() argument
734 struct btrfs_fs_info *fs_info = root->fs_info; in create_reloc_root()
750 if (root->root_key.objectid == objectid) { in create_reloc_root()
754 ret = btrfs_copy_root(trans, root, root->commit_root, &eb, in create_reloc_root()
767 commit_root_gen = btrfs_header_generation(root->commit_root); in create_reloc_root()
768 btrfs_set_root_last_snapshot(&root->root_item, commit_root_gen); in create_reloc_root()
777 ret = btrfs_copy_root(trans, root, root->node, &eb, in create_reloc_root()
789 memcpy(root_item, &root->root_item, sizeof(*root_item)); in create_reloc_root()
794 if (root->root_key.objectid == objectid) { in create_reloc_root()
835 struct btrfs_root *root) in btrfs_init_reloc_root() argument
837 struct btrfs_fs_info *fs_info = root->fs_info; in btrfs_init_reloc_root()
851 if (reloc_root_is_dead(root)) in btrfs_init_reloc_root()
862 if (root->reloc_root) { in btrfs_init_reloc_root()
863 reloc_root = root->reloc_root; in btrfs_init_reloc_root()
873 root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) in btrfs_init_reloc_root()
881 reloc_root = create_reloc_root(trans, root, root->root_key.objectid); in btrfs_init_reloc_root()
894 root->reloc_root = btrfs_grab_root(reloc_root); in btrfs_init_reloc_root()
902 struct btrfs_root *root) in btrfs_update_reloc_root() argument
904 struct btrfs_fs_info *fs_info = root->fs_info; in btrfs_update_reloc_root()
909 if (!have_reloc_root(root)) in btrfs_update_reloc_root()
912 reloc_root = root->reloc_root; in btrfs_update_reloc_root()
925 set_bit(BTRFS_ROOT_DEAD_RELOC_TREE, &root->state); in btrfs_update_reloc_root()
951 static struct inode *find_next_inode(struct btrfs_root *root, u64 objectid) in find_next_inode() argument
958 spin_lock(&root->inode_lock); in find_next_inode()
960 node = root->inode_tree.rb_node; in find_next_inode()
987 spin_unlock(&root->inode_lock); in find_next_inode()
992 if (cond_resched_lock(&root->inode_lock)) in find_next_inode()
997 spin_unlock(&root->inode_lock); in find_next_inode()
1007 struct btrfs_root *root = BTRFS_I(reloc_inode)->root; in get_new_location() local
1018 ret = btrfs_lookup_file_extent(NULL, root, path, in get_new_location()
1055 struct btrfs_root *root, in replace_file_extents() argument
1058 struct btrfs_fs_info *fs_info = root->fs_info; in replace_file_extents()
1077 if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) in replace_file_extents()
1106 if (root->root_key.objectid != BTRFS_TREE_RELOC_OBJECTID) { in replace_file_extents()
1108 inode = find_next_inode(root, key.objectid); in replace_file_extents()
1112 inode = find_next_inode(root, key.objectid); in replace_file_extents()
1151 root->root_key.objectid, false); in replace_file_extents()
1162 root->root_key.objectid, false); in replace_file_extents()
1422 int walk_up_reloc_tree(struct btrfs_root *root, struct btrfs_path *path, in walk_up_reloc_tree() argument
1430 last_snapshot = btrfs_root_last_snapshot(&root->root_item); in walk_up_reloc_tree()
1459 int walk_down_reloc_tree(struct btrfs_root *root, struct btrfs_path *path, in walk_down_reloc_tree() argument
1468 last_snapshot = btrfs_root_last_snapshot(&root->root_item); in walk_down_reloc_tree()
1504 static int invalidate_extent_cache(struct btrfs_root *root, in invalidate_extent_cache() argument
1508 struct btrfs_fs_info *fs_info = root->fs_info; in invalidate_extent_cache()
1522 inode = find_next_inode(root, objectid); in invalidate_extent_cache()
1596 struct btrfs_root *root) in insert_dirty_subvol() argument
1598 struct btrfs_root *reloc_root = root->reloc_root; in insert_dirty_subvol()
1603 ASSERT(root->root_key.objectid != BTRFS_TREE_RELOC_OBJECTID); in insert_dirty_subvol()
1611 ret = btrfs_update_reloc_root(trans, root); in insert_dirty_subvol()
1615 if (list_empty(&root->reloc_dirty_list)) { in insert_dirty_subvol()
1616 btrfs_grab_root(root); in insert_dirty_subvol()
1617 list_add_tail(&root->reloc_dirty_list, &rc->dirty_subvol_roots); in insert_dirty_subvol()
1625 struct btrfs_root *root; in clean_dirty_subvols() local
1630 list_for_each_entry_safe(root, next, &rc->dirty_subvol_roots, in clean_dirty_subvols()
1632 if (root->root_key.objectid != BTRFS_TREE_RELOC_OBJECTID) { in clean_dirty_subvols()
1634 struct btrfs_root *reloc_root = root->reloc_root; in clean_dirty_subvols()
1636 list_del_init(&root->reloc_dirty_list); in clean_dirty_subvols()
1637 root->reloc_root = NULL; in clean_dirty_subvols()
1643 clear_bit(BTRFS_ROOT_DEAD_RELOC_TREE, &root->state); in clean_dirty_subvols()
1657 btrfs_put_root(root); in clean_dirty_subvols()
1660 ret2 = btrfs_drop_snapshot(root, 0, 1); in clean_dirty_subvols()
1662 btrfs_put_root(root); in clean_dirty_subvols()
1676 struct btrfs_root *root) in merge_reloc_root() argument
1698 reloc_root = root->reloc_root; in merge_reloc_root()
1739 ret = btrfs_block_rsv_refill(root, rc->block_rsv, min_reserved, in merge_reloc_root()
1743 trans = btrfs_start_transaction(root, 0); in merge_reloc_root()
1776 ret = replace_path(trans, rc, root, reloc_root, path, in merge_reloc_root()
1807 invalidate_extent_cache(root, &key, &next_key); in merge_reloc_root()
1814 leaf = btrfs_lock_root_node(root); in merge_reloc_root()
1815 ret = btrfs_cow_block(trans, root, leaf, NULL, 0, &leaf, in merge_reloc_root()
1823 ret = insert_dirty_subvol(trans, rc, root); in merge_reloc_root()
1834 invalidate_extent_cache(root, &key, &next_key); in merge_reloc_root()
1842 struct btrfs_root *root = rc->extent_root; in prepare_to_merge() local
1843 struct btrfs_fs_info *fs_info = root->fs_info; in prepare_to_merge()
1858 ret = btrfs_block_rsv_add(root, rc->block_rsv, num_bytes, in prepare_to_merge()
1888 root = btrfs_get_fs_root(fs_info, reloc_root->root_key.offset, in prepare_to_merge()
1890 if (IS_ERR(root)) { in prepare_to_merge()
1896 btrfs_abort_transaction(trans, (int)PTR_ERR(root)); in prepare_to_merge()
1898 err = PTR_ERR(root); in prepare_to_merge()
1901 ASSERT(root->reloc_root == reloc_root); in prepare_to_merge()
1909 ret = btrfs_update_reloc_root(trans, root); in prepare_to_merge()
1916 btrfs_put_root(root); in prepare_to_merge()
1948 struct btrfs_root *root; in merge_reloc_roots() local
1954 root = rc->extent_root; in merge_reloc_roots()
1971 root = btrfs_get_fs_root(fs_info, reloc_root->root_key.offset, in merge_reloc_roots()
1974 if (IS_ERR(root)) { in merge_reloc_roots()
1984 ret = PTR_ERR(root); in merge_reloc_roots()
1987 if (root->reloc_root != reloc_root) { in merge_reloc_roots()
1997 ret = merge_reloc_root(rc, root); in merge_reloc_roots()
1998 btrfs_put_root(root); in merge_reloc_roots()
2006 if (!IS_ERR(root)) { in merge_reloc_roots()
2007 if (root->reloc_root == reloc_root) { in merge_reloc_roots()
2008 root->reloc_root = NULL; in merge_reloc_roots()
2012 &root->state); in merge_reloc_roots()
2013 btrfs_put_root(root); in merge_reloc_roots()
2071 struct btrfs_root *root; in record_reloc_root_in_trans() local
2077 root = btrfs_get_fs_root(fs_info, reloc_root->root_key.offset, false); in record_reloc_root_in_trans()
2087 if (IS_ERR(root)) { in record_reloc_root_in_trans()
2089 return PTR_ERR(root); in record_reloc_root_in_trans()
2091 if (root->reloc_root != reloc_root) { in record_reloc_root_in_trans()
2096 btrfs_put_root(root); in record_reloc_root_in_trans()
2099 ret = btrfs_record_root_in_trans(trans, root); in record_reloc_root_in_trans()
2100 btrfs_put_root(root); in record_reloc_root_in_trans()
2112 struct btrfs_root *root; in select_reloc_root() local
2120 root = next->root; in select_reloc_root()
2134 if (!root) { in select_reloc_root()
2141 if (!test_bit(BTRFS_ROOT_SHAREABLE, &root->state)) { in select_reloc_root()
2149 if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) { in select_reloc_root()
2150 ret = record_reloc_root_in_trans(trans, root); in select_reloc_root()
2156 ret = btrfs_record_root_in_trans(trans, root); in select_reloc_root()
2159 root = root->reloc_root; in select_reloc_root()
2165 if (!root) in select_reloc_root()
2168 if (next->new_bytenr != root->node->start) { in select_reloc_root()
2185 next->new_bytenr = root->node->start; in select_reloc_root()
2186 btrfs_put_root(next->root); in select_reloc_root()
2187 next->root = btrfs_grab_root(root); in select_reloc_root()
2188 ASSERT(next->root); in select_reloc_root()
2196 root = NULL; in select_reloc_root()
2201 if (!root) { in select_reloc_root()
2218 return root; in select_reloc_root()
2234 struct btrfs_root *root; in select_one_root() local
2243 root = next->root; in select_one_root()
2249 if (!root) in select_one_root()
2253 if (!test_bit(BTRFS_ROOT_SHAREABLE, &root->state)) in select_one_root()
2254 return root; in select_one_root()
2256 if (root->root_key.objectid != BTRFS_TREE_RELOC_OBJECTID) in select_one_root()
2257 fs_root = root; in select_one_root()
2310 struct btrfs_root *root = rc->extent_root; in reserve_metadata_space() local
2311 struct btrfs_fs_info *fs_info = root->fs_info; in reserve_metadata_space()
2326 ret = btrfs_block_rsv_refill(root, rc->block_rsv, num_bytes, in reserve_metadata_space()
2363 struct btrfs_root *root; in do_relocation() local
2384 root = select_reloc_root(trans, rc, upper, edges); in do_relocation()
2385 if (IS_ERR(root)) { in do_relocation()
2386 ret = PTR_ERR(root); in do_relocation()
2404 ret = btrfs_search_slot(trans, root, key, path, 0, 1); in do_relocation()
2435 btrfs_err(root->fs_info, in do_relocation()
2447 blocksize = root->fs_info->nodesize; in do_relocation()
2456 ret = btrfs_cow_block(trans, root, eb, upper->eb, in do_relocation()
2479 root->root_key.objectid, false); in do_relocation()
2482 ret = btrfs_drop_subtree(trans, root, eb, in do_relocation()
2624 struct btrfs_root *root; in relocate_tree_block() local
2639 root = select_one_root(node); in relocate_tree_block()
2640 if (IS_ERR(root)) { in relocate_tree_block()
2641 ret = PTR_ERR(root); in relocate_tree_block()
2652 if (root) { in relocate_tree_block()
2653 if (test_bit(BTRFS_ROOT_SHAREABLE, &root->state)) { in relocate_tree_block()
2670 btrfs_err(root->fs_info, in relocate_tree_block()
2676 ret = btrfs_record_root_in_trans(trans, root); in relocate_tree_block()
2683 if (!root->reloc_root) { in relocate_tree_block()
2687 root = root->reloc_root; in relocate_tree_block()
2688 node->new_bytenr = root->node->start; in relocate_tree_block()
2689 btrfs_put_root(node->root); in relocate_tree_block()
2690 node->root = btrfs_grab_root(root); in relocate_tree_block()
2691 ASSERT(node->root); in relocate_tree_block()
2695 if (root == root->fs_info->chunk_root) in relocate_tree_block()
2697 ret = btrfs_search_slot(trans, root, key, path, 0, 1); in relocate_tree_block()
2699 if (root == root->fs_info->chunk_root) in relocate_tree_block()
2808 struct btrfs_fs_info *fs_info = inode->root->fs_info; in prealloc_file_extent_cluster()
2881 btrfs_free_reserved_data_space_noquota(inode->root->fs_info, in prealloc_file_extent_cluster()
3310 struct btrfs_root *root = fs_info->tree_root; in delete_block_group_cache() local
3317 inode = btrfs_iget(fs_info->sb, ino, root); in delete_block_group_cache()
3327 trans = btrfs_join_transaction(root); in delete_block_group_cache()
3744 struct btrfs_root *root, u64 objectid) in __insert_orphan_inode() argument
3755 ret = btrfs_insert_empty_inode(trans, root, path, objectid); in __insert_orphan_inode()
3774 struct btrfs_root *root, u64 objectid) in delete_orphan_inode() argument
3789 ret = btrfs_search_slot(trans, root, &key, path, -1, 1); in delete_orphan_inode()
3795 ret = btrfs_del_item(trans, root, path); in delete_orphan_inode()
3812 struct btrfs_root *root; in create_reloc_inode() local
3816 root = btrfs_grab_root(fs_info->data_reloc_root); in create_reloc_inode()
3817 trans = btrfs_start_transaction(root, 6); in create_reloc_inode()
3819 btrfs_put_root(root); in create_reloc_inode()
3823 err = btrfs_get_free_objectid(root, &objectid); in create_reloc_inode()
3827 err = __insert_orphan_inode(trans, root, objectid); in create_reloc_inode()
3831 inode = btrfs_iget(fs_info->sb, objectid, root); in create_reloc_inode()
3833 delete_orphan_inode(trans, root, objectid); in create_reloc_inode()
3842 btrfs_put_root(root); in create_reloc_inode()
4095 static noinline_for_stack int mark_garbage_root(struct btrfs_root *root) in mark_garbage_root() argument
4097 struct btrfs_fs_info *fs_info = root->fs_info; in mark_garbage_root()
4105 memset(&root->root_item.drop_progress, 0, in mark_garbage_root()
4106 sizeof(root->root_item.drop_progress)); in mark_garbage_root()
4107 btrfs_set_root_drop_level(&root->root_item, 0); in mark_garbage_root()
4108 btrfs_set_root_refs(&root->root_item, 0); in mark_garbage_root()
4110 &root->root_key, &root->root_item); in mark_garbage_root()
4124 int btrfs_recover_relocation(struct btrfs_root *root) in btrfs_recover_relocation() argument
4126 struct btrfs_fs_info *fs_info = root->fs_info; in btrfs_recover_relocation()
4167 reloc_root = btrfs_read_tree_root(root, &key); in btrfs_recover_relocation()
4307 struct btrfs_fs_info *fs_info = inode->root->fs_info; in btrfs_reloc_clone_csums()
4351 struct btrfs_root *root, struct extent_buffer *buf, in btrfs_reloc_cow_block() argument
4354 struct btrfs_fs_info *fs_info = root->fs_info; in btrfs_reloc_cow_block()
4365 BUG_ON(rc->stage == UPDATE_DATA_PTRS && btrfs_is_data_reloc_root(root)); in btrfs_reloc_cow_block()
4369 btrfs_root_last_snapshot(&root->root_item)) in btrfs_reloc_cow_block()
4372 if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID && in btrfs_reloc_cow_block()
4399 ret = replace_file_extents(trans, rc, root, cow); in btrfs_reloc_cow_block()
4410 struct btrfs_root *root = pending->root; in btrfs_reloc_pre_snapshot() local
4411 struct reloc_control *rc = root->fs_info->reloc_ctl; in btrfs_reloc_pre_snapshot()
4413 if (!rc || !have_reloc_root(root)) in btrfs_reloc_pre_snapshot()
4419 root = root->reloc_root; in btrfs_reloc_pre_snapshot()
4420 BUG_ON(btrfs_root_refs(&root->root_item) == 0); in btrfs_reloc_pre_snapshot()
4445 struct btrfs_root *root = pending->root; in btrfs_reloc_post_snapshot() local
4448 struct reloc_control *rc = root->fs_info->reloc_ctl; in btrfs_reloc_post_snapshot()
4451 if (!rc || !have_reloc_root(root)) in btrfs_reloc_post_snapshot()
4454 rc = root->fs_info->reloc_ctl; in btrfs_reloc_post_snapshot()
4466 reloc_root = create_reloc_root(trans, root->reloc_root, in btrfs_reloc_post_snapshot()
4481 ret = clone_backref_node(trans, rc, root, reloc_root); in btrfs_reloc_post_snapshot()