Lines Matching refs:root
59 static void free_fs_root(struct btrfs_root *root);
62 static void btrfs_destroy_ordered_extents(struct btrfs_root *root);
64 struct btrfs_root *root);
65 static void btrfs_destroy_delalloc_inodes(struct btrfs_root *root);
66 static int btrfs_destroy_marked_extents(struct btrfs_root *root,
69 static int btrfs_destroy_pinned_extent(struct btrfs_root *root,
71 static int btrfs_cleanup_transaction(struct btrfs_root *root);
72 static void btrfs_error_commit_super(struct btrfs_root *root);
229 BTRFS_I(inode)->root->fs_info->fs_devices->latest_bdev; in btree_get_extent()
244 em->bdev = BTRFS_I(inode)->root->fs_info->fs_devices->latest_bdev; in btree_get_extent()
437 static int btree_read_extent_buffer_pages(struct btrfs_root *root, in btree_read_extent_buffer_pages() argument
449 io_tree = &BTRFS_I(root->fs_info->btree_inode)->io_tree; in btree_read_extent_buffer_pages()
470 num_copies = btrfs_num_copies(root->fs_info, in btree_read_extent_buffer_pages()
489 repair_eb_io_failure(root, eb, failed_mirror); in btree_read_extent_buffer_pages()
533 #define CORRUPT(reason, eb, root, slot) \ argument
534 btrfs_crit(root->fs_info, "corrupt leaf, %s: block=%llu," \
536 btrfs_header_bytenr(eb), root->objectid, slot)
538 static noinline int check_leaf(struct btrfs_root *root, in check_leaf() argument
551 BTRFS_LEAF_DATA_SIZE(root)) { in check_leaf()
552 CORRUPT("invalid item offset size pair", leaf, root, 0); in check_leaf()
569 CORRUPT("bad key order", leaf, root, slot); in check_leaf()
580 CORRUPT("slot offset bad", leaf, root, slot); in check_leaf()
590 BTRFS_LEAF_DATA_SIZE(root)) { in check_leaf()
591 CORRUPT("slot end outside of leaf", leaf, root, slot); in check_leaf()
606 struct btrfs_root *root = BTRFS_I(page->mapping->host)->root; in btree_readpage_end_io_hook() local
638 if (check_tree_block_fsid(root->fs_info, eb)) { in btree_readpage_end_io_hook()
646 btrfs_err(root->fs_info, "bad tree block level %d", in btree_readpage_end_io_hook()
655 ret = csum_tree_block(root->fs_info, eb, 1); in btree_readpage_end_io_hook()
666 if (found_level == 0 && check_leaf(root, eb)) { in btree_readpage_end_io_hook()
676 btree_readahead_hook(root, eb, eb->start, ret); in btree_readpage_end_io_hook()
695 struct btrfs_root *root = BTRFS_I(page->mapping->host)->root; in btree_io_failed_hook() local
702 btree_readahead_hook(root, eb, eb->start, -EIO); in btree_io_failed_hook()
800 fs_info = BTRFS_I(async->inode)->root->fs_info; in run_one_async_done()
875 struct btrfs_root *root; in btree_csum_one_bio() local
879 root = BTRFS_I(bvec->bv_page->mapping->host)->root; in btree_csum_one_bio()
880 ret = csum_dirty_buffer(root->fs_info, bvec->bv_page); in btree_csum_one_bio()
910 ret = btrfs_map_bio(BTRFS_I(inode)->root, rw, bio, mirror_num, 1); in __btree_submit_bio_done()
939 ret = btrfs_bio_wq_end_io(BTRFS_I(inode)->root->fs_info, in btree_submit_bio_hook()
943 ret = btrfs_map_bio(BTRFS_I(inode)->root, rw, bio, in btree_submit_bio_hook()
949 ret = btrfs_map_bio(BTRFS_I(inode)->root, rw, bio, in btree_submit_bio_hook()
956 ret = btrfs_wq_submit_bio(BTRFS_I(inode)->root->fs_info, in btree_submit_bio_hook()
1004 fs_info = BTRFS_I(mapping->host)->root->fs_info; in btree_writepages()
1037 btrfs_warn(BTRFS_I(page->mapping->host)->root->fs_info, in btree_invalidatepage()
1072 void readahead_tree_block(struct btrfs_root *root, u64 bytenr) in readahead_tree_block() argument
1075 struct inode *btree_inode = root->fs_info->btree_inode; in readahead_tree_block()
1077 buf = btrfs_find_create_tree_block(root, bytenr); in readahead_tree_block()
1085 int reada_tree_block_flagged(struct btrfs_root *root, u64 bytenr, in reada_tree_block_flagged() argument
1089 struct inode *btree_inode = root->fs_info->btree_inode; in reada_tree_block_flagged()
1093 buf = btrfs_find_create_tree_block(root, bytenr); in reada_tree_block_flagged()
1123 struct extent_buffer *btrfs_find_create_tree_block(struct btrfs_root *root, in btrfs_find_create_tree_block() argument
1126 if (btrfs_test_is_dummy_root(root)) in btrfs_find_create_tree_block()
1127 return alloc_test_extent_buffer(root->fs_info, bytenr); in btrfs_find_create_tree_block()
1128 return alloc_extent_buffer(root->fs_info, bytenr); in btrfs_find_create_tree_block()
1144 struct extent_buffer *read_tree_block(struct btrfs_root *root, u64 bytenr, in read_tree_block() argument
1150 buf = btrfs_find_create_tree_block(root, bytenr); in read_tree_block()
1154 ret = btree_read_extent_buffer_pages(root, buf, 0, parent_transid); in read_tree_block()
1209 struct btrfs_root *root, struct btrfs_fs_info *fs_info, in __setup_root() argument
1212 root->node = NULL; in __setup_root()
1213 root->commit_root = NULL; in __setup_root()
1214 root->sectorsize = sectorsize; in __setup_root()
1215 root->nodesize = nodesize; in __setup_root()
1216 root->stripesize = stripesize; in __setup_root()
1217 root->state = 0; in __setup_root()
1218 root->orphan_cleanup_state = 0; in __setup_root()
1220 root->objectid = objectid; in __setup_root()
1221 root->last_trans = 0; in __setup_root()
1222 root->highest_objectid = 0; in __setup_root()
1223 root->nr_delalloc_inodes = 0; in __setup_root()
1224 root->nr_ordered_extents = 0; in __setup_root()
1225 root->name = NULL; in __setup_root()
1226 root->inode_tree = RB_ROOT; in __setup_root()
1227 INIT_RADIX_TREE(&root->delayed_nodes_tree, GFP_ATOMIC); in __setup_root()
1228 root->block_rsv = NULL; in __setup_root()
1229 root->orphan_block_rsv = NULL; in __setup_root()
1231 INIT_LIST_HEAD(&root->dirty_list); in __setup_root()
1232 INIT_LIST_HEAD(&root->root_list); in __setup_root()
1233 INIT_LIST_HEAD(&root->delalloc_inodes); in __setup_root()
1234 INIT_LIST_HEAD(&root->delalloc_root); in __setup_root()
1235 INIT_LIST_HEAD(&root->ordered_extents); in __setup_root()
1236 INIT_LIST_HEAD(&root->ordered_root); in __setup_root()
1237 INIT_LIST_HEAD(&root->logged_list[0]); in __setup_root()
1238 INIT_LIST_HEAD(&root->logged_list[1]); in __setup_root()
1239 spin_lock_init(&root->orphan_lock); in __setup_root()
1240 spin_lock_init(&root->inode_lock); in __setup_root()
1241 spin_lock_init(&root->delalloc_lock); in __setup_root()
1242 spin_lock_init(&root->ordered_extent_lock); in __setup_root()
1243 spin_lock_init(&root->accounting_lock); in __setup_root()
1244 spin_lock_init(&root->log_extents_lock[0]); in __setup_root()
1245 spin_lock_init(&root->log_extents_lock[1]); in __setup_root()
1246 mutex_init(&root->objectid_mutex); in __setup_root()
1247 mutex_init(&root->log_mutex); in __setup_root()
1248 mutex_init(&root->ordered_extent_mutex); in __setup_root()
1249 mutex_init(&root->delalloc_mutex); in __setup_root()
1250 init_waitqueue_head(&root->log_writer_wait); in __setup_root()
1251 init_waitqueue_head(&root->log_commit_wait[0]); in __setup_root()
1252 init_waitqueue_head(&root->log_commit_wait[1]); in __setup_root()
1253 INIT_LIST_HEAD(&root->log_ctxs[0]); in __setup_root()
1254 INIT_LIST_HEAD(&root->log_ctxs[1]); in __setup_root()
1255 atomic_set(&root->log_commit[0], 0); in __setup_root()
1256 atomic_set(&root->log_commit[1], 0); in __setup_root()
1257 atomic_set(&root->log_writers, 0); in __setup_root()
1258 atomic_set(&root->log_batch, 0); in __setup_root()
1259 atomic_set(&root->orphan_inodes, 0); in __setup_root()
1260 atomic_set(&root->refs, 1); in __setup_root()
1261 atomic_set(&root->will_be_snapshoted, 0); in __setup_root()
1262 root->log_transid = 0; in __setup_root()
1263 root->log_transid_committed = -1; in __setup_root()
1264 root->last_log_commit = 0; in __setup_root()
1266 extent_io_tree_init(&root->dirty_log_pages, in __setup_root()
1269 memset(&root->root_key, 0, sizeof(root->root_key)); in __setup_root()
1270 memset(&root->root_item, 0, sizeof(root->root_item)); in __setup_root()
1271 memset(&root->defrag_progress, 0, sizeof(root->defrag_progress)); in __setup_root()
1273 root->defrag_trans_start = fs_info->generation; in __setup_root()
1275 root->defrag_trans_start = 0; in __setup_root()
1276 root->root_key.objectid = objectid; in __setup_root()
1277 root->anon_dev = 0; in __setup_root()
1279 spin_lock_init(&root->root_item_lock); in __setup_root()
1284 struct btrfs_root *root = kzalloc(sizeof(*root), GFP_NOFS); in btrfs_alloc_root() local
1285 if (root) in btrfs_alloc_root()
1286 root->fs_info = fs_info; in btrfs_alloc_root()
1287 return root; in btrfs_alloc_root()
1294 struct btrfs_root *root; in btrfs_alloc_dummy_root() local
1296 root = btrfs_alloc_root(NULL); in btrfs_alloc_dummy_root()
1297 if (!root) in btrfs_alloc_dummy_root()
1299 __setup_root(4096, 4096, 4096, root, NULL, 1); in btrfs_alloc_dummy_root()
1300 set_bit(BTRFS_ROOT_DUMMY_ROOT, &root->state); in btrfs_alloc_dummy_root()
1301 root->alloc_bytenr = 0; in btrfs_alloc_dummy_root()
1303 return root; in btrfs_alloc_dummy_root()
1313 struct btrfs_root *root; in btrfs_create_tree() local
1318 root = btrfs_alloc_root(fs_info); in btrfs_create_tree()
1319 if (!root) in btrfs_create_tree()
1323 tree_root->stripesize, root, fs_info, objectid); in btrfs_create_tree()
1324 root->root_key.objectid = objectid; in btrfs_create_tree()
1325 root->root_key.type = BTRFS_ROOT_ITEM_KEY; in btrfs_create_tree()
1326 root->root_key.offset = 0; in btrfs_create_tree()
1328 leaf = btrfs_alloc_tree_block(trans, root, 0, objectid, NULL, 0, 0, 0); in btrfs_create_tree()
1340 root->node = leaf; in btrfs_create_tree()
1349 root->commit_root = btrfs_root_node(root); in btrfs_create_tree()
1350 set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state); in btrfs_create_tree()
1352 root->root_item.flags = 0; in btrfs_create_tree()
1353 root->root_item.byte_limit = 0; in btrfs_create_tree()
1354 btrfs_set_root_bytenr(&root->root_item, leaf->start); in btrfs_create_tree()
1355 btrfs_set_root_generation(&root->root_item, trans->transid); in btrfs_create_tree()
1356 btrfs_set_root_level(&root->root_item, 0); in btrfs_create_tree()
1357 btrfs_set_root_refs(&root->root_item, 1); in btrfs_create_tree()
1358 btrfs_set_root_used(&root->root_item, leaf->len); in btrfs_create_tree()
1359 btrfs_set_root_last_snapshot(&root->root_item, 0); in btrfs_create_tree()
1360 btrfs_set_root_dirid(&root->root_item, 0); in btrfs_create_tree()
1362 memcpy(root->root_item.uuid, uuid.b, BTRFS_UUID_SIZE); in btrfs_create_tree()
1363 root->root_item.drop_level = 0; in btrfs_create_tree()
1368 ret = btrfs_insert_root(trans, tree_root, &key, &root->root_item); in btrfs_create_tree()
1374 return root; in btrfs_create_tree()
1379 free_extent_buffer(root->commit_root); in btrfs_create_tree()
1382 kfree(root); in btrfs_create_tree()
1390 struct btrfs_root *root; in alloc_log_tree() local
1394 root = btrfs_alloc_root(fs_info); in alloc_log_tree()
1395 if (!root) in alloc_log_tree()
1399 tree_root->stripesize, root, fs_info, in alloc_log_tree()
1402 root->root_key.objectid = BTRFS_TREE_LOG_OBJECTID; in alloc_log_tree()
1403 root->root_key.type = BTRFS_ROOT_ITEM_KEY; in alloc_log_tree()
1404 root->root_key.offset = BTRFS_TREE_LOG_OBJECTID; in alloc_log_tree()
1415 leaf = btrfs_alloc_tree_block(trans, root, 0, BTRFS_TREE_LOG_OBJECTID, in alloc_log_tree()
1418 kfree(root); in alloc_log_tree()
1427 root->node = leaf; in alloc_log_tree()
1429 write_extent_buffer(root->node, root->fs_info->fsid, in alloc_log_tree()
1431 btrfs_mark_buffer_dirty(root->node); in alloc_log_tree()
1432 btrfs_tree_unlock(root->node); in alloc_log_tree()
1433 return root; in alloc_log_tree()
1450 struct btrfs_root *root) in btrfs_add_log_tree() argument
1455 log_root = alloc_log_tree(trans, root->fs_info); in btrfs_add_log_tree()
1460 log_root->root_key.offset = root->root_key.objectid; in btrfs_add_log_tree()
1466 btrfs_set_stack_inode_nbytes(inode_item, root->nodesize); in btrfs_add_log_tree()
1471 WARN_ON(root->log_root); in btrfs_add_log_tree()
1472 root->log_root = log_root; in btrfs_add_log_tree()
1473 root->log_transid = 0; in btrfs_add_log_tree()
1474 root->log_transid_committed = -1; in btrfs_add_log_tree()
1475 root->last_log_commit = 0; in btrfs_add_log_tree()
1482 struct btrfs_root *root; in btrfs_read_tree_root() local
1492 root = btrfs_alloc_root(fs_info); in btrfs_read_tree_root()
1493 if (!root) { in btrfs_read_tree_root()
1499 tree_root->stripesize, root, fs_info, key->objectid); in btrfs_read_tree_root()
1502 &root->root_item, &root->root_key); in btrfs_read_tree_root()
1509 generation = btrfs_root_generation(&root->root_item); in btrfs_read_tree_root()
1510 root->node = read_tree_block(root, btrfs_root_bytenr(&root->root_item), in btrfs_read_tree_root()
1512 if (!root->node) { in btrfs_read_tree_root()
1515 } else if (!btrfs_buffer_uptodate(root->node, generation, 0)) { in btrfs_read_tree_root()
1519 root->commit_root = btrfs_root_node(root); in btrfs_read_tree_root()
1522 return root; in btrfs_read_tree_root()
1525 free_extent_buffer(root->node); in btrfs_read_tree_root()
1527 kfree(root); in btrfs_read_tree_root()
1529 root = ERR_PTR(ret); in btrfs_read_tree_root()
1536 struct btrfs_root *root; in btrfs_read_fs_root() local
1538 root = btrfs_read_tree_root(tree_root, location); in btrfs_read_fs_root()
1539 if (IS_ERR(root)) in btrfs_read_fs_root()
1540 return root; in btrfs_read_fs_root()
1542 if (root->root_key.objectid != BTRFS_TREE_LOG_OBJECTID) { in btrfs_read_fs_root()
1543 set_bit(BTRFS_ROOT_REF_COWS, &root->state); in btrfs_read_fs_root()
1544 btrfs_check_and_init_root_item(&root->root_item); in btrfs_read_fs_root()
1547 return root; in btrfs_read_fs_root()
1550 int btrfs_init_fs_root(struct btrfs_root *root) in btrfs_init_fs_root() argument
1555 root->free_ino_ctl = kzalloc(sizeof(*root->free_ino_ctl), GFP_NOFS); in btrfs_init_fs_root()
1556 root->free_ino_pinned = kzalloc(sizeof(*root->free_ino_pinned), in btrfs_init_fs_root()
1558 if (!root->free_ino_pinned || !root->free_ino_ctl) { in btrfs_init_fs_root()
1568 root->subv_writers = writers; in btrfs_init_fs_root()
1570 btrfs_init_free_ino_ctl(root); in btrfs_init_fs_root()
1571 spin_lock_init(&root->ino_cache_lock); in btrfs_init_fs_root()
1572 init_waitqueue_head(&root->ino_cache_wait); in btrfs_init_fs_root()
1574 ret = get_anon_bdev(&root->anon_dev); in btrfs_init_fs_root()
1578 mutex_lock(&root->objectid_mutex); in btrfs_init_fs_root()
1579 ret = btrfs_find_highest_objectid(root, in btrfs_init_fs_root()
1580 &root->highest_objectid); in btrfs_init_fs_root()
1582 mutex_unlock(&root->objectid_mutex); in btrfs_init_fs_root()
1586 ASSERT(root->highest_objectid <= BTRFS_LAST_FREE_OBJECTID); in btrfs_init_fs_root()
1588 mutex_unlock(&root->objectid_mutex); in btrfs_init_fs_root()
1593 free_anon_bdev(root->anon_dev); in btrfs_init_fs_root()
1595 btrfs_free_subvolume_writers(root->subv_writers); in btrfs_init_fs_root()
1597 kfree(root->free_ino_ctl); in btrfs_init_fs_root()
1598 kfree(root->free_ino_pinned); in btrfs_init_fs_root()
1605 struct btrfs_root *root; in btrfs_lookup_fs_root() local
1608 root = radix_tree_lookup(&fs_info->fs_roots_radix, in btrfs_lookup_fs_root()
1611 return root; in btrfs_lookup_fs_root()
1615 struct btrfs_root *root) in btrfs_insert_fs_root() argument
1625 (unsigned long)root->root_key.objectid, in btrfs_insert_fs_root()
1626 root); in btrfs_insert_fs_root()
1628 set_bit(BTRFS_ROOT_IN_RADIX, &root->state); in btrfs_insert_fs_root()
1639 struct btrfs_root *root; in btrfs_get_fs_root() local
1661 root = btrfs_lookup_fs_root(fs_info, location->objectid); in btrfs_get_fs_root()
1662 if (root) { in btrfs_get_fs_root()
1663 if (check_ref && btrfs_root_refs(&root->root_item) == 0) in btrfs_get_fs_root()
1665 return root; in btrfs_get_fs_root()
1668 root = btrfs_read_fs_root(fs_info->tree_root, location); in btrfs_get_fs_root()
1669 if (IS_ERR(root)) in btrfs_get_fs_root()
1670 return root; in btrfs_get_fs_root()
1672 if (check_ref && btrfs_root_refs(&root->root_item) == 0) { in btrfs_get_fs_root()
1677 ret = btrfs_init_fs_root(root); in btrfs_get_fs_root()
1695 set_bit(BTRFS_ROOT_ORPHAN_ITEM_INSERTED, &root->state); in btrfs_get_fs_root()
1697 ret = btrfs_insert_fs_root(fs_info, root); in btrfs_get_fs_root()
1700 free_fs_root(root); in btrfs_get_fs_root()
1705 return root; in btrfs_get_fs_root()
1707 free_fs_root(root); in btrfs_get_fs_root()
1768 struct btrfs_root *root = arg; in cleaner_kthread() local
1775 if (btrfs_need_cleaner_sleep(root)) in cleaner_kthread()
1778 if (!mutex_trylock(&root->fs_info->cleaner_mutex)) in cleaner_kthread()
1785 if (btrfs_need_cleaner_sleep(root)) { in cleaner_kthread()
1786 mutex_unlock(&root->fs_info->cleaner_mutex); in cleaner_kthread()
1790 mutex_lock(&root->fs_info->cleaner_delayed_iput_mutex); in cleaner_kthread()
1791 btrfs_run_delayed_iputs(root); in cleaner_kthread()
1792 btrfs_delete_unused_bgs(root->fs_info); in cleaner_kthread()
1793 mutex_unlock(&root->fs_info->cleaner_delayed_iput_mutex); in cleaner_kthread()
1795 again = btrfs_clean_one_deleted_snapshot(root); in cleaner_kthread()
1796 mutex_unlock(&root->fs_info->cleaner_mutex); in cleaner_kthread()
1802 btrfs_run_defrag_inodes(root->fs_info); in cleaner_kthread()
1816 struct btrfs_root *root = arg; in transaction_kthread() local
1826 delay = HZ * root->fs_info->commit_interval; in transaction_kthread()
1827 mutex_lock(&root->fs_info->transaction_kthread_mutex); in transaction_kthread()
1829 spin_lock(&root->fs_info->trans_lock); in transaction_kthread()
1830 cur = root->fs_info->running_transaction; in transaction_kthread()
1832 spin_unlock(&root->fs_info->trans_lock); in transaction_kthread()
1839 now - cur->start_time < root->fs_info->commit_interval)) { in transaction_kthread()
1840 spin_unlock(&root->fs_info->trans_lock); in transaction_kthread()
1845 spin_unlock(&root->fs_info->trans_lock); in transaction_kthread()
1848 trans = btrfs_attach_transaction(root); in transaction_kthread()
1855 btrfs_commit_transaction(trans, root); in transaction_kthread()
1857 btrfs_end_transaction(trans, root); in transaction_kthread()
1860 wake_up_process(root->fs_info->cleaner_kthread); in transaction_kthread()
1861 mutex_unlock(&root->fs_info->transaction_kthread_mutex); in transaction_kthread()
1864 &root->fs_info->fs_state))) in transaction_kthread()
1865 btrfs_cleanup_transaction(root); in transaction_kthread()
1869 (!btrfs_transaction_blocked(root->fs_info) || in transaction_kthread()
2100 static void free_root_extent_buffers(struct btrfs_root *root) in free_root_extent_buffers() argument
2102 if (root) { in free_root_extent_buffers()
2103 free_extent_buffer(root->node); in free_root_extent_buffers()
2104 free_extent_buffer(root->commit_root); in free_root_extent_buffers()
2105 root->node = NULL; in free_root_extent_buffers()
2106 root->commit_root = NULL; in free_root_extent_buffers()
2204 BTRFS_I(fs_info->btree_inode)->root = tree_root; in btrfs_init_btree_inode()
2370 struct btrfs_root *root; in btrfs_read_roots() local
2378 root = btrfs_read_tree_root(tree_root, &location); in btrfs_read_roots()
2379 if (IS_ERR(root)) in btrfs_read_roots()
2380 return PTR_ERR(root); in btrfs_read_roots()
2381 set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state); in btrfs_read_roots()
2382 fs_info->extent_root = root; in btrfs_read_roots()
2385 root = btrfs_read_tree_root(tree_root, &location); in btrfs_read_roots()
2386 if (IS_ERR(root)) in btrfs_read_roots()
2387 return PTR_ERR(root); in btrfs_read_roots()
2388 set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state); in btrfs_read_roots()
2389 fs_info->dev_root = root; in btrfs_read_roots()
2393 root = btrfs_read_tree_root(tree_root, &location); in btrfs_read_roots()
2394 if (IS_ERR(root)) in btrfs_read_roots()
2395 return PTR_ERR(root); in btrfs_read_roots()
2396 set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state); in btrfs_read_roots()
2397 fs_info->csum_root = root; in btrfs_read_roots()
2400 root = btrfs_read_tree_root(tree_root, &location); in btrfs_read_roots()
2401 if (!IS_ERR(root)) { in btrfs_read_roots()
2402 set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state); in btrfs_read_roots()
2405 fs_info->quota_root = root; in btrfs_read_roots()
2409 root = btrfs_read_tree_root(tree_root, &location); in btrfs_read_roots()
2410 if (IS_ERR(root)) { in btrfs_read_roots()
2411 ret = PTR_ERR(root); in btrfs_read_roots()
2415 set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state); in btrfs_read_roots()
2416 fs_info->uuid_root = root; in btrfs_read_roots()
3501 static int write_all_supers(struct btrfs_root *root, int max_mirrors) in write_all_supers() argument
3513 do_barriers = !btrfs_test_opt(root, NOBARRIER); in write_all_supers()
3514 backup_super_roots(root->fs_info); in write_all_supers()
3516 sb = root->fs_info->super_for_commit; in write_all_supers()
3519 mutex_lock(&root->fs_info->fs_devices->device_list_mutex); in write_all_supers()
3520 head = &root->fs_info->fs_devices->devices; in write_all_supers()
3521 max_errors = btrfs_super_num_devices(root->fs_info->super_copy) - 1; in write_all_supers()
3524 ret = barrier_all_devices(root->fs_info); in write_all_supers()
3527 &root->fs_info->fs_devices->device_list_mutex); in write_all_supers()
3528 btrfs_error(root->fs_info, ret, in write_all_supers()
3563 btrfs_err(root->fs_info, "%d errors while writing supers", in write_all_supers()
3565 mutex_unlock(&root->fs_info->fs_devices->device_list_mutex); in write_all_supers()
3568 btrfs_error(root->fs_info, -EIO, in write_all_supers()
3584 mutex_unlock(&root->fs_info->fs_devices->device_list_mutex); in write_all_supers()
3586 btrfs_error(root->fs_info, -EIO, in write_all_supers()
3594 struct btrfs_root *root, int max_mirrors) in write_ctree_super() argument
3596 return write_all_supers(root, max_mirrors); in write_ctree_super()
3601 struct btrfs_root *root) in btrfs_drop_and_free_fs_root() argument
3605 (unsigned long)root->root_key.objectid); in btrfs_drop_and_free_fs_root()
3608 if (btrfs_root_refs(&root->root_item) == 0) in btrfs_drop_and_free_fs_root()
3612 btrfs_free_log(NULL, root); in btrfs_drop_and_free_fs_root()
3614 if (root->free_ino_pinned) in btrfs_drop_and_free_fs_root()
3615 __btrfs_remove_free_space_cache(root->free_ino_pinned); in btrfs_drop_and_free_fs_root()
3616 if (root->free_ino_ctl) in btrfs_drop_and_free_fs_root()
3617 __btrfs_remove_free_space_cache(root->free_ino_ctl); in btrfs_drop_and_free_fs_root()
3618 free_fs_root(root); in btrfs_drop_and_free_fs_root()
3621 static void free_fs_root(struct btrfs_root *root) in free_fs_root() argument
3623 iput(root->ino_cache_inode); in free_fs_root()
3624 WARN_ON(!RB_EMPTY_ROOT(&root->inode_tree)); in free_fs_root()
3625 btrfs_free_block_rsv(root, root->orphan_block_rsv); in free_fs_root()
3626 root->orphan_block_rsv = NULL; in free_fs_root()
3627 if (root->anon_dev) in free_fs_root()
3628 free_anon_bdev(root->anon_dev); in free_fs_root()
3629 if (root->subv_writers) in free_fs_root()
3630 btrfs_free_subvolume_writers(root->subv_writers); in free_fs_root()
3631 free_extent_buffer(root->node); in free_fs_root()
3632 free_extent_buffer(root->commit_root); in free_fs_root()
3633 kfree(root->free_ino_ctl); in free_fs_root()
3634 kfree(root->free_ino_pinned); in free_fs_root()
3635 kfree(root->name); in free_fs_root()
3636 btrfs_put_fs_root(root); in free_fs_root()
3639 void btrfs_free_fs_root(struct btrfs_root *root) in btrfs_free_fs_root() argument
3641 free_fs_root(root); in btrfs_free_fs_root()
3695 int btrfs_commit_super(struct btrfs_root *root) in btrfs_commit_super() argument
3699 mutex_lock(&root->fs_info->cleaner_mutex); in btrfs_commit_super()
3700 btrfs_run_delayed_iputs(root); in btrfs_commit_super()
3701 mutex_unlock(&root->fs_info->cleaner_mutex); in btrfs_commit_super()
3702 wake_up_process(root->fs_info->cleaner_kthread); in btrfs_commit_super()
3705 down_write(&root->fs_info->cleanup_work_sem); in btrfs_commit_super()
3706 up_write(&root->fs_info->cleanup_work_sem); in btrfs_commit_super()
3708 trans = btrfs_join_transaction(root); in btrfs_commit_super()
3711 return btrfs_commit_transaction(trans, root); in btrfs_commit_super()
3714 void close_ctree(struct btrfs_root *root) in close_ctree() argument
3716 struct btrfs_fs_info *fs_info = root->fs_info; in close_ctree()
3744 ret = btrfs_commit_super(root); in close_ctree()
3750 btrfs_error_commit_super(root); in close_ctree()
3786 if (btrfs_test_opt(root, CHECK_INTEGRITY)) in close_ctree()
3787 btrfsic_unmount(root, fs_info->fs_devices); in close_ctree()
3801 __btrfs_free_block_rsv(root->orphan_block_rsv); in close_ctree()
3802 root->orphan_block_rsv = NULL; in close_ctree()
3804 lock_chunks(root); in close_ctree()
3813 unlock_chunks(root); in close_ctree()
3840 struct btrfs_root *root; in btrfs_mark_buffer_dirty() local
3853 root = BTRFS_I(buf->pages[0]->mapping->host)->root; in btrfs_mark_buffer_dirty()
3855 if (transid != root->fs_info->generation) in btrfs_mark_buffer_dirty()
3858 buf->start, transid, root->fs_info->generation); in btrfs_mark_buffer_dirty()
3861 __percpu_counter_add(&root->fs_info->dirty_metadata_bytes, in btrfs_mark_buffer_dirty()
3863 root->fs_info->dirty_metadata_batch); in btrfs_mark_buffer_dirty()
3865 if (btrfs_header_level(buf) == 0 && check_leaf(root, buf)) { in btrfs_mark_buffer_dirty()
3866 btrfs_print_leaf(root, buf); in btrfs_mark_buffer_dirty()
3872 static void __btrfs_btree_balance_dirty(struct btrfs_root *root, in __btrfs_btree_balance_dirty() argument
3885 btrfs_balance_delayed_items(root); in __btrfs_btree_balance_dirty()
3887 ret = percpu_counter_compare(&root->fs_info->dirty_metadata_bytes, in __btrfs_btree_balance_dirty()
3891 root->fs_info->btree_inode->i_mapping); in __btrfs_btree_balance_dirty()
3896 void btrfs_btree_balance_dirty(struct btrfs_root *root) in btrfs_btree_balance_dirty() argument
3898 __btrfs_btree_balance_dirty(root, 1); in btrfs_btree_balance_dirty()
3901 void btrfs_btree_balance_dirty_nodelay(struct btrfs_root *root) in btrfs_btree_balance_dirty_nodelay() argument
3903 __btrfs_btree_balance_dirty(root, 0); in btrfs_btree_balance_dirty_nodelay()
3908 struct btrfs_root *root = BTRFS_I(buf->pages[0]->mapping->host)->root; in btrfs_read_buffer() local
3909 return btree_read_extent_buffer_pages(root, buf, 0, parent_transid); in btrfs_read_buffer()
4023 static void btrfs_error_commit_super(struct btrfs_root *root) in btrfs_error_commit_super() argument
4025 mutex_lock(&root->fs_info->cleaner_mutex); in btrfs_error_commit_super()
4026 btrfs_run_delayed_iputs(root); in btrfs_error_commit_super()
4027 mutex_unlock(&root->fs_info->cleaner_mutex); in btrfs_error_commit_super()
4029 down_write(&root->fs_info->cleanup_work_sem); in btrfs_error_commit_super()
4030 up_write(&root->fs_info->cleanup_work_sem); in btrfs_error_commit_super()
4033 btrfs_cleanup_transaction(root); in btrfs_error_commit_super()
4036 static void btrfs_destroy_ordered_extents(struct btrfs_root *root) in btrfs_destroy_ordered_extents() argument
4040 spin_lock(&root->ordered_extent_lock); in btrfs_destroy_ordered_extents()
4045 list_for_each_entry(ordered, &root->ordered_extents, in btrfs_destroy_ordered_extents()
4048 spin_unlock(&root->ordered_extent_lock); in btrfs_destroy_ordered_extents()
4053 struct btrfs_root *root; in btrfs_destroy_all_ordered_extents() local
4061 root = list_first_entry(&splice, struct btrfs_root, in btrfs_destroy_all_ordered_extents()
4063 list_move_tail(&root->ordered_root, in btrfs_destroy_all_ordered_extents()
4067 btrfs_destroy_ordered_extents(root); in btrfs_destroy_all_ordered_extents()
4076 struct btrfs_root *root) in btrfs_destroy_delayed_refs() argument
4088 btrfs_info(root->fs_info, "delayed_refs has NO entry"); in btrfs_destroy_delayed_refs()
4131 btrfs_pin_extent(root, head->node.bytenr, in btrfs_destroy_delayed_refs()
4143 static void btrfs_destroy_delalloc_inodes(struct btrfs_root *root) in btrfs_destroy_delalloc_inodes() argument
4150 spin_lock(&root->delalloc_lock); in btrfs_destroy_delalloc_inodes()
4151 list_splice_init(&root->delalloc_inodes, &splice); in btrfs_destroy_delalloc_inodes()
4160 spin_unlock(&root->delalloc_lock); in btrfs_destroy_delalloc_inodes()
4162 btrfs_invalidate_inodes(btrfs_inode->root); in btrfs_destroy_delalloc_inodes()
4164 spin_lock(&root->delalloc_lock); in btrfs_destroy_delalloc_inodes()
4167 spin_unlock(&root->delalloc_lock); in btrfs_destroy_delalloc_inodes()
4172 struct btrfs_root *root; in btrfs_destroy_all_delalloc_inodes() local
4180 root = list_first_entry(&splice, struct btrfs_root, in btrfs_destroy_all_delalloc_inodes()
4182 list_del_init(&root->delalloc_root); in btrfs_destroy_all_delalloc_inodes()
4183 root = btrfs_grab_fs_root(root); in btrfs_destroy_all_delalloc_inodes()
4184 BUG_ON(!root); in btrfs_destroy_all_delalloc_inodes()
4187 btrfs_destroy_delalloc_inodes(root); in btrfs_destroy_all_delalloc_inodes()
4188 btrfs_put_fs_root(root); in btrfs_destroy_all_delalloc_inodes()
4195 static int btrfs_destroy_marked_extents(struct btrfs_root *root, in btrfs_destroy_marked_extents() argument
4212 eb = btrfs_find_tree_block(root->fs_info, start); in btrfs_destroy_marked_extents()
4213 start += root->nodesize; in btrfs_destroy_marked_extents()
4228 static int btrfs_destroy_pinned_extent(struct btrfs_root *root, in btrfs_destroy_pinned_extent() argument
4246 btrfs_error_unpin_extent_range(root, start, end); in btrfs_destroy_pinned_extent()
4251 if (unpin == &root->fs_info->freed_extents[0]) in btrfs_destroy_pinned_extent()
4252 unpin = &root->fs_info->freed_extents[1]; in btrfs_destroy_pinned_extent()
4254 unpin = &root->fs_info->freed_extents[0]; in btrfs_destroy_pinned_extent()
4282 struct btrfs_root *root) in btrfs_cleanup_one_transaction() argument
4284 btrfs_destroy_delayed_refs(cur_trans, root); in btrfs_cleanup_one_transaction()
4287 wake_up(&root->fs_info->transaction_blocked_wait); in btrfs_cleanup_one_transaction()
4290 wake_up(&root->fs_info->transaction_wait); in btrfs_cleanup_one_transaction()
4292 btrfs_free_pending_ordered(cur_trans, root->fs_info); in btrfs_cleanup_one_transaction()
4293 btrfs_destroy_delayed_inodes(root); in btrfs_cleanup_one_transaction()
4294 btrfs_assert_delayed_root_empty(root); in btrfs_cleanup_one_transaction()
4296 btrfs_destroy_marked_extents(root, &cur_trans->dirty_pages, in btrfs_cleanup_one_transaction()
4298 btrfs_destroy_pinned_extent(root, in btrfs_cleanup_one_transaction()
4299 root->fs_info->pinned_extents); in btrfs_cleanup_one_transaction()
4310 static int btrfs_cleanup_transaction(struct btrfs_root *root) in btrfs_cleanup_transaction() argument
4314 mutex_lock(&root->fs_info->transaction_kthread_mutex); in btrfs_cleanup_transaction()
4316 spin_lock(&root->fs_info->trans_lock); in btrfs_cleanup_transaction()
4317 while (!list_empty(&root->fs_info->trans_list)) { in btrfs_cleanup_transaction()
4318 t = list_first_entry(&root->fs_info->trans_list, in btrfs_cleanup_transaction()
4322 spin_unlock(&root->fs_info->trans_lock); in btrfs_cleanup_transaction()
4323 btrfs_wait_for_commit(root, t->transid); in btrfs_cleanup_transaction()
4325 spin_lock(&root->fs_info->trans_lock); in btrfs_cleanup_transaction()
4328 if (t == root->fs_info->running_transaction) { in btrfs_cleanup_transaction()
4330 spin_unlock(&root->fs_info->trans_lock); in btrfs_cleanup_transaction()
4338 spin_unlock(&root->fs_info->trans_lock); in btrfs_cleanup_transaction()
4340 btrfs_cleanup_one_transaction(t, root); in btrfs_cleanup_transaction()
4342 spin_lock(&root->fs_info->trans_lock); in btrfs_cleanup_transaction()
4343 if (t == root->fs_info->running_transaction) in btrfs_cleanup_transaction()
4344 root->fs_info->running_transaction = NULL; in btrfs_cleanup_transaction()
4346 spin_unlock(&root->fs_info->trans_lock); in btrfs_cleanup_transaction()
4349 trace_btrfs_transaction_commit(root); in btrfs_cleanup_transaction()
4350 spin_lock(&root->fs_info->trans_lock); in btrfs_cleanup_transaction()
4352 spin_unlock(&root->fs_info->trans_lock); in btrfs_cleanup_transaction()
4353 btrfs_destroy_all_ordered_extents(root->fs_info); in btrfs_cleanup_transaction()
4354 btrfs_destroy_delayed_inodes(root); in btrfs_cleanup_transaction()
4355 btrfs_assert_delayed_root_empty(root); in btrfs_cleanup_transaction()
4356 btrfs_destroy_pinned_extent(root, root->fs_info->pinned_extents); in btrfs_cleanup_transaction()
4357 btrfs_destroy_all_delalloc_inodes(root->fs_info); in btrfs_cleanup_transaction()
4358 mutex_unlock(&root->fs_info->transaction_kthread_mutex); in btrfs_cleanup_transaction()