Lines Matching refs:root

54 static void btrfs_destroy_ordered_extents(struct btrfs_root *root);
57 static void btrfs_destroy_delalloc_inodes(struct btrfs_root *root);
208 struct btrfs_fs_info *fs_info = inode->root->fs_info; in btree_get_extent()
596 struct btrfs_root *root = BTRFS_I(page->mapping->host)->root; in btree_readpage_end_io_hook() local
597 struct btrfs_fs_info *fs_info = root->fs_info; in btree_readpage_end_io_hook()
855 struct btrfs_root *root; in btree_csum_one_bio() local
861 root = BTRFS_I(bvec->bv_page->mapping->host)->root; in btree_csum_one_bio()
862 ret = csum_dirty_buffer(root->fs_info, bvec->bv_page); in btree_csum_one_bio()
966 fs_info = BTRFS_I(mapping->host)->root->fs_info; in btree_writepages()
1000 btrfs_warn(BTRFS_I(page->mapping->host)->root->fs_info, in btree_invalidatepage()
1133 static void __setup_root(struct btrfs_root *root, struct btrfs_fs_info *fs_info, in __setup_root() argument
1137 root->node = NULL; in __setup_root()
1138 root->commit_root = NULL; in __setup_root()
1139 root->state = 0; in __setup_root()
1140 root->orphan_cleanup_state = 0; in __setup_root()
1142 root->last_trans = 0; in __setup_root()
1143 root->highest_objectid = 0; in __setup_root()
1144 root->nr_delalloc_inodes = 0; in __setup_root()
1145 root->nr_ordered_extents = 0; in __setup_root()
1146 root->inode_tree = RB_ROOT; in __setup_root()
1147 INIT_RADIX_TREE(&root->delayed_nodes_tree, GFP_ATOMIC); in __setup_root()
1148 root->block_rsv = NULL; in __setup_root()
1150 INIT_LIST_HEAD(&root->dirty_list); in __setup_root()
1151 INIT_LIST_HEAD(&root->root_list); in __setup_root()
1152 INIT_LIST_HEAD(&root->delalloc_inodes); in __setup_root()
1153 INIT_LIST_HEAD(&root->delalloc_root); in __setup_root()
1154 INIT_LIST_HEAD(&root->ordered_extents); in __setup_root()
1155 INIT_LIST_HEAD(&root->ordered_root); in __setup_root()
1156 INIT_LIST_HEAD(&root->reloc_dirty_list); in __setup_root()
1157 INIT_LIST_HEAD(&root->logged_list[0]); in __setup_root()
1158 INIT_LIST_HEAD(&root->logged_list[1]); in __setup_root()
1159 spin_lock_init(&root->inode_lock); in __setup_root()
1160 spin_lock_init(&root->delalloc_lock); in __setup_root()
1161 spin_lock_init(&root->ordered_extent_lock); in __setup_root()
1162 spin_lock_init(&root->accounting_lock); in __setup_root()
1163 spin_lock_init(&root->log_extents_lock[0]); in __setup_root()
1164 spin_lock_init(&root->log_extents_lock[1]); in __setup_root()
1165 spin_lock_init(&root->qgroup_meta_rsv_lock); in __setup_root()
1166 mutex_init(&root->objectid_mutex); in __setup_root()
1167 mutex_init(&root->log_mutex); in __setup_root()
1168 mutex_init(&root->ordered_extent_mutex); in __setup_root()
1169 mutex_init(&root->delalloc_mutex); in __setup_root()
1170 init_waitqueue_head(&root->log_writer_wait); in __setup_root()
1171 init_waitqueue_head(&root->log_commit_wait[0]); in __setup_root()
1172 init_waitqueue_head(&root->log_commit_wait[1]); in __setup_root()
1173 INIT_LIST_HEAD(&root->log_ctxs[0]); in __setup_root()
1174 INIT_LIST_HEAD(&root->log_ctxs[1]); in __setup_root()
1175 atomic_set(&root->log_commit[0], 0); in __setup_root()
1176 atomic_set(&root->log_commit[1], 0); in __setup_root()
1177 atomic_set(&root->log_writers, 0); in __setup_root()
1178 atomic_set(&root->log_batch, 0); in __setup_root()
1179 refcount_set(&root->refs, 1); in __setup_root()
1180 atomic_set(&root->will_be_snapshotted, 0); in __setup_root()
1181 atomic_set(&root->snapshot_force_cow, 0); in __setup_root()
1182 atomic_set(&root->nr_swapfiles, 0); in __setup_root()
1183 root->log_transid = 0; in __setup_root()
1184 root->log_transid_committed = -1; in __setup_root()
1185 root->last_log_commit = 0; in __setup_root()
1187 extent_io_tree_init(fs_info, &root->dirty_log_pages, in __setup_root()
1190 memset(&root->root_key, 0, sizeof(root->root_key)); in __setup_root()
1191 memset(&root->root_item, 0, sizeof(root->root_item)); in __setup_root()
1192 memset(&root->defrag_progress, 0, sizeof(root->defrag_progress)); in __setup_root()
1194 root->defrag_trans_start = fs_info->generation; in __setup_root()
1196 root->defrag_trans_start = 0; in __setup_root()
1197 root->root_key.objectid = objectid; in __setup_root()
1198 root->anon_dev = 0; in __setup_root()
1200 spin_lock_init(&root->root_item_lock); in __setup_root()
1201 btrfs_qgroup_init_swapped_blocks(&root->swapped_blocks); in __setup_root()
1207 struct btrfs_root *root = kzalloc(sizeof(*root), flags); in btrfs_alloc_root() local
1208 if (root) in btrfs_alloc_root()
1209 root->fs_info = fs_info; in btrfs_alloc_root()
1210 return root; in btrfs_alloc_root()
1217 struct btrfs_root *root; in btrfs_alloc_dummy_root() local
1222 root = btrfs_alloc_root(fs_info, GFP_KERNEL); in btrfs_alloc_dummy_root()
1223 if (!root) in btrfs_alloc_dummy_root()
1227 __setup_root(root, fs_info, BTRFS_ROOT_TREE_OBJECTID); in btrfs_alloc_dummy_root()
1228 root->alloc_bytenr = 0; in btrfs_alloc_dummy_root()
1230 return root; in btrfs_alloc_dummy_root()
1240 struct btrfs_root *root; in btrfs_create_tree() local
1251 root = btrfs_alloc_root(fs_info, GFP_KERNEL); in btrfs_create_tree()
1253 if (!root) in btrfs_create_tree()
1256 __setup_root(root, fs_info, objectid); in btrfs_create_tree()
1257 root->root_key.objectid = objectid; in btrfs_create_tree()
1258 root->root_key.type = BTRFS_ROOT_ITEM_KEY; in btrfs_create_tree()
1259 root->root_key.offset = 0; in btrfs_create_tree()
1261 leaf = btrfs_alloc_tree_block(trans, root, 0, objectid, NULL, 0, 0, 0); in btrfs_create_tree()
1268 root->node = leaf; in btrfs_create_tree()
1271 root->commit_root = btrfs_root_node(root); in btrfs_create_tree()
1272 set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state); in btrfs_create_tree()
1274 root->root_item.flags = 0; in btrfs_create_tree()
1275 root->root_item.byte_limit = 0; in btrfs_create_tree()
1276 btrfs_set_root_bytenr(&root->root_item, leaf->start); in btrfs_create_tree()
1277 btrfs_set_root_generation(&root->root_item, trans->transid); in btrfs_create_tree()
1278 btrfs_set_root_level(&root->root_item, 0); in btrfs_create_tree()
1279 btrfs_set_root_refs(&root->root_item, 1); in btrfs_create_tree()
1280 btrfs_set_root_used(&root->root_item, leaf->len); in btrfs_create_tree()
1281 btrfs_set_root_last_snapshot(&root->root_item, 0); in btrfs_create_tree()
1282 btrfs_set_root_dirid(&root->root_item, 0); in btrfs_create_tree()
1285 memcpy(root->root_item.uuid, uuid.b, BTRFS_UUID_SIZE); in btrfs_create_tree()
1286 root->root_item.drop_level = 0; in btrfs_create_tree()
1291 ret = btrfs_insert_root(trans, tree_root, &key, &root->root_item); in btrfs_create_tree()
1297 return root; in btrfs_create_tree()
1302 free_extent_buffer(root->commit_root); in btrfs_create_tree()
1305 kfree(root); in btrfs_create_tree()
1313 struct btrfs_root *root; in alloc_log_tree() local
1316 root = btrfs_alloc_root(fs_info, GFP_NOFS); in alloc_log_tree()
1317 if (!root) in alloc_log_tree()
1320 __setup_root(root, fs_info, BTRFS_TREE_LOG_OBJECTID); in alloc_log_tree()
1322 root->root_key.objectid = BTRFS_TREE_LOG_OBJECTID; in alloc_log_tree()
1323 root->root_key.type = BTRFS_ROOT_ITEM_KEY; in alloc_log_tree()
1324 root->root_key.offset = BTRFS_TREE_LOG_OBJECTID; in alloc_log_tree()
1335 leaf = btrfs_alloc_tree_block(trans, root, 0, BTRFS_TREE_LOG_OBJECTID, in alloc_log_tree()
1338 kfree(root); in alloc_log_tree()
1342 root->node = leaf; in alloc_log_tree()
1344 btrfs_mark_buffer_dirty(root->node); in alloc_log_tree()
1345 btrfs_tree_unlock(root->node); in alloc_log_tree()
1346 return root; in alloc_log_tree()
1363 struct btrfs_root *root) in btrfs_add_log_tree() argument
1365 struct btrfs_fs_info *fs_info = root->fs_info; in btrfs_add_log_tree()
1374 log_root->root_key.offset = root->root_key.objectid; in btrfs_add_log_tree()
1386 WARN_ON(root->log_root); in btrfs_add_log_tree()
1387 root->log_root = log_root; in btrfs_add_log_tree()
1388 root->log_transid = 0; in btrfs_add_log_tree()
1389 root->log_transid_committed = -1; in btrfs_add_log_tree()
1390 root->last_log_commit = 0; in btrfs_add_log_tree()
1397 struct btrfs_root *root; in btrfs_read_tree_root() local
1408 root = btrfs_alloc_root(fs_info, GFP_NOFS); in btrfs_read_tree_root()
1409 if (!root) { in btrfs_read_tree_root()
1414 __setup_root(root, fs_info, key->objectid); in btrfs_read_tree_root()
1417 &root->root_item, &root->root_key); in btrfs_read_tree_root()
1424 generation = btrfs_root_generation(&root->root_item); in btrfs_read_tree_root()
1425 level = btrfs_root_level(&root->root_item); in btrfs_read_tree_root()
1426 root->node = read_tree_block(fs_info, in btrfs_read_tree_root()
1427 btrfs_root_bytenr(&root->root_item), in btrfs_read_tree_root()
1429 if (IS_ERR(root->node)) { in btrfs_read_tree_root()
1430 ret = PTR_ERR(root->node); in btrfs_read_tree_root()
1432 } else if (!btrfs_buffer_uptodate(root->node, generation, 0)) { in btrfs_read_tree_root()
1434 free_extent_buffer(root->node); in btrfs_read_tree_root()
1437 root->commit_root = btrfs_root_node(root); in btrfs_read_tree_root()
1440 return root; in btrfs_read_tree_root()
1443 kfree(root); in btrfs_read_tree_root()
1445 root = ERR_PTR(ret); in btrfs_read_tree_root()
1452 struct btrfs_root *root; in btrfs_read_fs_root() local
1454 root = btrfs_read_tree_root(tree_root, location); in btrfs_read_fs_root()
1455 if (IS_ERR(root)) in btrfs_read_fs_root()
1456 return root; in btrfs_read_fs_root()
1458 if (root->root_key.objectid != BTRFS_TREE_LOG_OBJECTID) { in btrfs_read_fs_root()
1459 set_bit(BTRFS_ROOT_REF_COWS, &root->state); in btrfs_read_fs_root()
1460 btrfs_check_and_init_root_item(&root->root_item); in btrfs_read_fs_root()
1463 return root; in btrfs_read_fs_root()
1466 int btrfs_init_fs_root(struct btrfs_root *root) in btrfs_init_fs_root() argument
1471 root->free_ino_ctl = kzalloc(sizeof(*root->free_ino_ctl), GFP_NOFS); in btrfs_init_fs_root()
1472 root->free_ino_pinned = kzalloc(sizeof(*root->free_ino_pinned), in btrfs_init_fs_root()
1474 if (!root->free_ino_pinned || !root->free_ino_ctl) { in btrfs_init_fs_root()
1484 root->subv_writers = writers; in btrfs_init_fs_root()
1486 btrfs_init_free_ino_ctl(root); in btrfs_init_fs_root()
1487 spin_lock_init(&root->ino_cache_lock); in btrfs_init_fs_root()
1488 init_waitqueue_head(&root->ino_cache_wait); in btrfs_init_fs_root()
1490 ret = get_anon_bdev(&root->anon_dev); in btrfs_init_fs_root()
1494 mutex_lock(&root->objectid_mutex); in btrfs_init_fs_root()
1495 ret = btrfs_find_highest_objectid(root, in btrfs_init_fs_root()
1496 &root->highest_objectid); in btrfs_init_fs_root()
1498 mutex_unlock(&root->objectid_mutex); in btrfs_init_fs_root()
1502 ASSERT(root->highest_objectid <= BTRFS_LAST_FREE_OBJECTID); in btrfs_init_fs_root()
1504 mutex_unlock(&root->objectid_mutex); in btrfs_init_fs_root()
1515 struct btrfs_root *root; in btrfs_lookup_fs_root() local
1518 root = radix_tree_lookup(&fs_info->fs_roots_radix, in btrfs_lookup_fs_root()
1521 return root; in btrfs_lookup_fs_root()
1525 struct btrfs_root *root) in btrfs_insert_fs_root() argument
1535 (unsigned long)root->root_key.objectid, in btrfs_insert_fs_root()
1536 root); in btrfs_insert_fs_root()
1538 set_bit(BTRFS_ROOT_IN_RADIX, &root->state); in btrfs_insert_fs_root()
1549 struct btrfs_root *root; in btrfs_get_fs_root() local
1574 root = btrfs_lookup_fs_root(fs_info, location->objectid); in btrfs_get_fs_root()
1575 if (root) { in btrfs_get_fs_root()
1576 if (check_ref && btrfs_root_refs(&root->root_item) == 0) in btrfs_get_fs_root()
1578 return root; in btrfs_get_fs_root()
1581 root = btrfs_read_fs_root(fs_info->tree_root, location); in btrfs_get_fs_root()
1582 if (IS_ERR(root)) in btrfs_get_fs_root()
1583 return root; in btrfs_get_fs_root()
1585 if (check_ref && btrfs_root_refs(&root->root_item) == 0) { in btrfs_get_fs_root()
1590 ret = btrfs_init_fs_root(root); in btrfs_get_fs_root()
1608 set_bit(BTRFS_ROOT_ORPHAN_ITEM_INSERTED, &root->state); in btrfs_get_fs_root()
1610 ret = btrfs_insert_fs_root(fs_info, root); in btrfs_get_fs_root()
1613 btrfs_free_fs_root(root); in btrfs_get_fs_root()
1618 return root; in btrfs_get_fs_root()
1620 btrfs_free_fs_root(root); in btrfs_get_fs_root()
1666 struct btrfs_root *root = arg; in cleaner_kthread() local
1667 struct btrfs_fs_info *fs_info = root->fs_info; in cleaner_kthread()
1700 again = btrfs_clean_one_deleted_snapshot(root); in cleaner_kthread()
1734 struct btrfs_root *root = arg; in transaction_kthread() local
1735 struct btrfs_fs_info *fs_info = root->fs_info; in transaction_kthread()
1768 trans = btrfs_attach_transaction(root); in transaction_kthread()
2020 static void free_root_extent_buffers(struct btrfs_root *root) in free_root_extent_buffers() argument
2022 if (root) { in free_root_extent_buffers()
2023 free_extent_buffer(root->node); in free_root_extent_buffers()
2024 free_extent_buffer(root->commit_root); in free_root_extent_buffers()
2025 root->node = NULL; in free_root_extent_buffers()
2026 root->commit_root = NULL; in free_root_extent_buffers()
2124 BTRFS_I(inode)->root = fs_info->tree_root; in btrfs_init_btree_inode()
2312 struct btrfs_root *root; in btrfs_read_roots() local
2322 root = btrfs_read_tree_root(tree_root, &location); in btrfs_read_roots()
2323 if (IS_ERR(root)) { in btrfs_read_roots()
2324 ret = PTR_ERR(root); in btrfs_read_roots()
2327 set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state); in btrfs_read_roots()
2328 fs_info->extent_root = root; in btrfs_read_roots()
2331 root = btrfs_read_tree_root(tree_root, &location); in btrfs_read_roots()
2332 if (IS_ERR(root)) { in btrfs_read_roots()
2333 ret = PTR_ERR(root); in btrfs_read_roots()
2336 set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state); in btrfs_read_roots()
2337 fs_info->dev_root = root; in btrfs_read_roots()
2341 root = btrfs_read_tree_root(tree_root, &location); in btrfs_read_roots()
2342 if (IS_ERR(root)) { in btrfs_read_roots()
2343 ret = PTR_ERR(root); in btrfs_read_roots()
2346 set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state); in btrfs_read_roots()
2347 fs_info->csum_root = root; in btrfs_read_roots()
2350 root = btrfs_read_tree_root(tree_root, &location); in btrfs_read_roots()
2351 if (!IS_ERR(root)) { in btrfs_read_roots()
2352 set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state); in btrfs_read_roots()
2354 fs_info->quota_root = root; in btrfs_read_roots()
2358 root = btrfs_read_tree_root(tree_root, &location); in btrfs_read_roots()
2359 if (IS_ERR(root)) { in btrfs_read_roots()
2360 ret = PTR_ERR(root); in btrfs_read_roots()
2364 set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state); in btrfs_read_roots()
2365 fs_info->uuid_root = root; in btrfs_read_roots()
2370 root = btrfs_read_tree_root(tree_root, &location); in btrfs_read_roots()
2371 if (IS_ERR(root)) { in btrfs_read_roots()
2372 ret = PTR_ERR(root); in btrfs_read_roots()
2375 set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state); in btrfs_read_roots()
2376 fs_info->free_space_root = root; in btrfs_read_roots()
3864 struct btrfs_root *root) in btrfs_drop_and_free_fs_root() argument
3868 (unsigned long)root->root_key.objectid); in btrfs_drop_and_free_fs_root()
3871 if (btrfs_root_refs(&root->root_item) == 0) in btrfs_drop_and_free_fs_root()
3875 btrfs_free_log(NULL, root); in btrfs_drop_and_free_fs_root()
3876 if (root->reloc_root) { in btrfs_drop_and_free_fs_root()
3877 free_extent_buffer(root->reloc_root->node); in btrfs_drop_and_free_fs_root()
3878 free_extent_buffer(root->reloc_root->commit_root); in btrfs_drop_and_free_fs_root()
3879 btrfs_put_fs_root(root->reloc_root); in btrfs_drop_and_free_fs_root()
3880 root->reloc_root = NULL; in btrfs_drop_and_free_fs_root()
3884 if (root->free_ino_pinned) in btrfs_drop_and_free_fs_root()
3885 __btrfs_remove_free_space_cache(root->free_ino_pinned); in btrfs_drop_and_free_fs_root()
3886 if (root->free_ino_ctl) in btrfs_drop_and_free_fs_root()
3887 __btrfs_remove_free_space_cache(root->free_ino_ctl); in btrfs_drop_and_free_fs_root()
3888 btrfs_free_fs_root(root); in btrfs_drop_and_free_fs_root()
3891 void btrfs_free_fs_root(struct btrfs_root *root) in btrfs_free_fs_root() argument
3893 iput(root->ino_cache_inode); in btrfs_free_fs_root()
3894 WARN_ON(!RB_EMPTY_ROOT(&root->inode_tree)); in btrfs_free_fs_root()
3895 if (root->anon_dev) in btrfs_free_fs_root()
3896 free_anon_bdev(root->anon_dev); in btrfs_free_fs_root()
3897 if (root->subv_writers) in btrfs_free_fs_root()
3898 btrfs_free_subvolume_writers(root->subv_writers); in btrfs_free_fs_root()
3899 free_extent_buffer(root->node); in btrfs_free_fs_root()
3900 free_extent_buffer(root->commit_root); in btrfs_free_fs_root()
3901 kfree(root->free_ino_ctl); in btrfs_free_fs_root()
3902 kfree(root->free_ino_pinned); in btrfs_free_fs_root()
3903 btrfs_put_fs_root(root); in btrfs_free_fs_root()
3959 struct btrfs_root *root = fs_info->tree_root; in btrfs_commit_super() local
3971 trans = btrfs_join_transaction(root); in btrfs_commit_super()
4108 struct btrfs_root *root; in btrfs_mark_buffer_dirty() local
4121 root = BTRFS_I(buf->pages[0]->mapping->host)->root; in btrfs_mark_buffer_dirty()
4122 fs_info = root->fs_info; in btrfs_mark_buffer_dirty()
4199 static void btrfs_destroy_ordered_extents(struct btrfs_root *root) in btrfs_destroy_ordered_extents() argument
4203 spin_lock(&root->ordered_extent_lock); in btrfs_destroy_ordered_extents()
4208 list_for_each_entry(ordered, &root->ordered_extents, in btrfs_destroy_ordered_extents()
4211 spin_unlock(&root->ordered_extent_lock); in btrfs_destroy_ordered_extents()
4216 struct btrfs_root *root; in btrfs_destroy_all_ordered_extents() local
4224 root = list_first_entry(&splice, struct btrfs_root, in btrfs_destroy_all_ordered_extents()
4226 list_move_tail(&root->ordered_root, in btrfs_destroy_all_ordered_extents()
4230 btrfs_destroy_ordered_extents(root); in btrfs_destroy_all_ordered_extents()
4307 static void btrfs_destroy_delalloc_inodes(struct btrfs_root *root) in btrfs_destroy_delalloc_inodes() argument
4314 spin_lock(&root->delalloc_lock); in btrfs_destroy_delalloc_inodes()
4315 list_splice_init(&root->delalloc_inodes, &splice); in btrfs_destroy_delalloc_inodes()
4321 __btrfs_del_delalloc_inode(root, btrfs_inode); in btrfs_destroy_delalloc_inodes()
4322 spin_unlock(&root->delalloc_lock); in btrfs_destroy_delalloc_inodes()
4333 spin_lock(&root->delalloc_lock); in btrfs_destroy_delalloc_inodes()
4335 spin_unlock(&root->delalloc_lock); in btrfs_destroy_delalloc_inodes()
4340 struct btrfs_root *root; in btrfs_destroy_all_delalloc_inodes() local
4348 root = list_first_entry(&splice, struct btrfs_root, in btrfs_destroy_all_delalloc_inodes()
4350 root = btrfs_grab_fs_root(root); in btrfs_destroy_all_delalloc_inodes()
4351 BUG_ON(!root); in btrfs_destroy_all_delalloc_inodes()
4354 btrfs_destroy_delalloc_inodes(root); in btrfs_destroy_all_delalloc_inodes()
4355 btrfs_put_fs_root(root); in btrfs_destroy_all_delalloc_inodes()