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
637 if (check_tree_block_fsid(root->fs_info, eb)) { in btree_readpage_end_io_hook()
645 btrfs_err(root->fs_info, "bad tree block level %d", in btree_readpage_end_io_hook()
654 ret = csum_tree_block(root->fs_info, eb, 1); in btree_readpage_end_io_hook()
665 if (found_level == 0 && check_leaf(root, eb)) { in btree_readpage_end_io_hook()
675 btree_readahead_hook(root, eb, eb->start, ret); in btree_readpage_end_io_hook()
694 struct btrfs_root *root = BTRFS_I(page->mapping->host)->root; in btree_io_failed_hook() local
701 btree_readahead_hook(root, eb, eb->start, -EIO); in btree_io_failed_hook()
799 fs_info = BTRFS_I(async->inode)->root->fs_info; in run_one_async_done()
878 struct btrfs_root *root; in btree_csum_one_bio() local
882 root = BTRFS_I(bvec->bv_page->mapping->host)->root; in btree_csum_one_bio()
883 ret = csum_dirty_buffer(root->fs_info, bvec->bv_page); in btree_csum_one_bio()
913 ret = btrfs_map_bio(BTRFS_I(inode)->root, rw, bio, mirror_num, 1); in __btree_submit_bio_done()
944 ret = btrfs_bio_wq_end_io(BTRFS_I(inode)->root->fs_info, in btree_submit_bio_hook()
948 ret = btrfs_map_bio(BTRFS_I(inode)->root, rw, bio, in btree_submit_bio_hook()
954 ret = btrfs_map_bio(BTRFS_I(inode)->root, rw, bio, in btree_submit_bio_hook()
961 ret = btrfs_wq_submit_bio(BTRFS_I(inode)->root->fs_info, in btree_submit_bio_hook()
1012 fs_info = BTRFS_I(mapping->host)->root->fs_info; in btree_writepages()
1045 btrfs_warn(BTRFS_I(page->mapping->host)->root->fs_info, in btree_invalidatepage()
1080 void readahead_tree_block(struct btrfs_root *root, u64 bytenr) in readahead_tree_block() argument
1083 struct inode *btree_inode = root->fs_info->btree_inode; in readahead_tree_block()
1085 buf = btrfs_find_create_tree_block(root, bytenr); in readahead_tree_block()
1093 int reada_tree_block_flagged(struct btrfs_root *root, u64 bytenr, in reada_tree_block_flagged() argument
1097 struct inode *btree_inode = root->fs_info->btree_inode; in reada_tree_block_flagged()
1101 buf = btrfs_find_create_tree_block(root, bytenr); in reada_tree_block_flagged()
1131 struct extent_buffer *btrfs_find_create_tree_block(struct btrfs_root *root, in btrfs_find_create_tree_block() argument
1134 if (btrfs_test_is_dummy_root(root)) in btrfs_find_create_tree_block()
1135 return alloc_test_extent_buffer(root->fs_info, bytenr); in btrfs_find_create_tree_block()
1136 return alloc_extent_buffer(root->fs_info, bytenr); in btrfs_find_create_tree_block()
1152 struct extent_buffer *read_tree_block(struct btrfs_root *root, u64 bytenr, in read_tree_block() argument
1158 buf = btrfs_find_create_tree_block(root, bytenr); in read_tree_block()
1162 ret = btree_read_extent_buffer_pages(root, buf, 0, parent_transid); in read_tree_block()
1217 struct btrfs_root *root, struct btrfs_fs_info *fs_info, in __setup_root() argument
1220 root->node = NULL; in __setup_root()
1221 root->commit_root = NULL; in __setup_root()
1222 root->sectorsize = sectorsize; in __setup_root()
1223 root->nodesize = nodesize; in __setup_root()
1224 root->stripesize = stripesize; in __setup_root()
1225 root->state = 0; in __setup_root()
1226 root->orphan_cleanup_state = 0; in __setup_root()
1228 root->objectid = objectid; in __setup_root()
1229 root->last_trans = 0; in __setup_root()
1230 root->highest_objectid = 0; in __setup_root()
1231 root->nr_delalloc_inodes = 0; in __setup_root()
1232 root->nr_ordered_extents = 0; in __setup_root()
1233 root->name = NULL; in __setup_root()
1234 root->inode_tree = RB_ROOT; in __setup_root()
1235 INIT_RADIX_TREE(&root->delayed_nodes_tree, GFP_ATOMIC); in __setup_root()
1236 root->block_rsv = NULL; in __setup_root()
1237 root->orphan_block_rsv = NULL; in __setup_root()
1239 INIT_LIST_HEAD(&root->dirty_list); in __setup_root()
1240 INIT_LIST_HEAD(&root->root_list); in __setup_root()
1241 INIT_LIST_HEAD(&root->delalloc_inodes); in __setup_root()
1242 INIT_LIST_HEAD(&root->delalloc_root); in __setup_root()
1243 INIT_LIST_HEAD(&root->ordered_extents); in __setup_root()
1244 INIT_LIST_HEAD(&root->ordered_root); in __setup_root()
1245 INIT_LIST_HEAD(&root->logged_list[0]); in __setup_root()
1246 INIT_LIST_HEAD(&root->logged_list[1]); in __setup_root()
1247 spin_lock_init(&root->orphan_lock); in __setup_root()
1248 spin_lock_init(&root->inode_lock); in __setup_root()
1249 spin_lock_init(&root->delalloc_lock); in __setup_root()
1250 spin_lock_init(&root->ordered_extent_lock); in __setup_root()
1251 spin_lock_init(&root->accounting_lock); in __setup_root()
1252 spin_lock_init(&root->log_extents_lock[0]); in __setup_root()
1253 spin_lock_init(&root->log_extents_lock[1]); in __setup_root()
1254 mutex_init(&root->objectid_mutex); in __setup_root()
1255 mutex_init(&root->log_mutex); in __setup_root()
1256 mutex_init(&root->ordered_extent_mutex); in __setup_root()
1257 mutex_init(&root->delalloc_mutex); in __setup_root()
1258 init_waitqueue_head(&root->log_writer_wait); in __setup_root()
1259 init_waitqueue_head(&root->log_commit_wait[0]); in __setup_root()
1260 init_waitqueue_head(&root->log_commit_wait[1]); in __setup_root()
1261 INIT_LIST_HEAD(&root->log_ctxs[0]); in __setup_root()
1262 INIT_LIST_HEAD(&root->log_ctxs[1]); in __setup_root()
1263 atomic_set(&root->log_commit[0], 0); in __setup_root()
1264 atomic_set(&root->log_commit[1], 0); in __setup_root()
1265 atomic_set(&root->log_writers, 0); in __setup_root()
1266 atomic_set(&root->log_batch, 0); in __setup_root()
1267 atomic_set(&root->orphan_inodes, 0); in __setup_root()
1268 atomic_set(&root->refs, 1); in __setup_root()
1269 atomic_set(&root->will_be_snapshoted, 0); in __setup_root()
1270 atomic_set(&root->qgroup_meta_rsv, 0); in __setup_root()
1271 root->log_transid = 0; in __setup_root()
1272 root->log_transid_committed = -1; in __setup_root()
1273 root->last_log_commit = 0; in __setup_root()
1275 extent_io_tree_init(&root->dirty_log_pages, in __setup_root()
1278 memset(&root->root_key, 0, sizeof(root->root_key)); in __setup_root()
1279 memset(&root->root_item, 0, sizeof(root->root_item)); in __setup_root()
1280 memset(&root->defrag_progress, 0, sizeof(root->defrag_progress)); in __setup_root()
1282 root->defrag_trans_start = fs_info->generation; in __setup_root()
1284 root->defrag_trans_start = 0; in __setup_root()
1285 root->root_key.objectid = objectid; in __setup_root()
1286 root->anon_dev = 0; in __setup_root()
1288 spin_lock_init(&root->root_item_lock); in __setup_root()
1293 struct btrfs_root *root = kzalloc(sizeof(*root), GFP_NOFS); in btrfs_alloc_root() local
1294 if (root) in btrfs_alloc_root()
1295 root->fs_info = fs_info; in btrfs_alloc_root()
1296 return root; in btrfs_alloc_root()
1303 struct btrfs_root *root; in btrfs_alloc_dummy_root() local
1305 root = btrfs_alloc_root(NULL); in btrfs_alloc_dummy_root()
1306 if (!root) in btrfs_alloc_dummy_root()
1308 __setup_root(4096, 4096, 4096, root, NULL, 1); in btrfs_alloc_dummy_root()
1309 set_bit(BTRFS_ROOT_DUMMY_ROOT, &root->state); in btrfs_alloc_dummy_root()
1310 root->alloc_bytenr = 0; in btrfs_alloc_dummy_root()
1312 return root; in btrfs_alloc_dummy_root()
1322 struct btrfs_root *root; in btrfs_create_tree() local
1327 root = btrfs_alloc_root(fs_info); in btrfs_create_tree()
1328 if (!root) in btrfs_create_tree()
1332 tree_root->stripesize, root, fs_info, objectid); in btrfs_create_tree()
1333 root->root_key.objectid = objectid; in btrfs_create_tree()
1334 root->root_key.type = BTRFS_ROOT_ITEM_KEY; in btrfs_create_tree()
1335 root->root_key.offset = 0; in btrfs_create_tree()
1337 leaf = btrfs_alloc_tree_block(trans, root, 0, objectid, NULL, 0, 0, 0); in btrfs_create_tree()
1349 root->node = leaf; in btrfs_create_tree()
1358 root->commit_root = btrfs_root_node(root); in btrfs_create_tree()
1359 set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state); in btrfs_create_tree()
1361 root->root_item.flags = 0; in btrfs_create_tree()
1362 root->root_item.byte_limit = 0; in btrfs_create_tree()
1363 btrfs_set_root_bytenr(&root->root_item, leaf->start); in btrfs_create_tree()
1364 btrfs_set_root_generation(&root->root_item, trans->transid); in btrfs_create_tree()
1365 btrfs_set_root_level(&root->root_item, 0); in btrfs_create_tree()
1366 btrfs_set_root_refs(&root->root_item, 1); in btrfs_create_tree()
1367 btrfs_set_root_used(&root->root_item, leaf->len); in btrfs_create_tree()
1368 btrfs_set_root_last_snapshot(&root->root_item, 0); in btrfs_create_tree()
1369 btrfs_set_root_dirid(&root->root_item, 0); in btrfs_create_tree()
1371 memcpy(root->root_item.uuid, uuid.b, BTRFS_UUID_SIZE); in btrfs_create_tree()
1372 root->root_item.drop_level = 0; in btrfs_create_tree()
1377 ret = btrfs_insert_root(trans, tree_root, &key, &root->root_item); in btrfs_create_tree()
1383 return root; in btrfs_create_tree()
1388 free_extent_buffer(root->commit_root); in btrfs_create_tree()
1391 kfree(root); in btrfs_create_tree()
1399 struct btrfs_root *root; in alloc_log_tree() local
1403 root = btrfs_alloc_root(fs_info); in alloc_log_tree()
1404 if (!root) in alloc_log_tree()
1408 tree_root->stripesize, root, fs_info, in alloc_log_tree()
1411 root->root_key.objectid = BTRFS_TREE_LOG_OBJECTID; in alloc_log_tree()
1412 root->root_key.type = BTRFS_ROOT_ITEM_KEY; in alloc_log_tree()
1413 root->root_key.offset = BTRFS_TREE_LOG_OBJECTID; in alloc_log_tree()
1424 leaf = btrfs_alloc_tree_block(trans, root, 0, BTRFS_TREE_LOG_OBJECTID, in alloc_log_tree()
1427 kfree(root); in alloc_log_tree()
1436 root->node = leaf; in alloc_log_tree()
1438 write_extent_buffer(root->node, root->fs_info->fsid, in alloc_log_tree()
1440 btrfs_mark_buffer_dirty(root->node); in alloc_log_tree()
1441 btrfs_tree_unlock(root->node); in alloc_log_tree()
1442 return root; in alloc_log_tree()
1459 struct btrfs_root *root) in btrfs_add_log_tree() argument
1464 log_root = alloc_log_tree(trans, root->fs_info); in btrfs_add_log_tree()
1469 log_root->root_key.offset = root->root_key.objectid; in btrfs_add_log_tree()
1475 btrfs_set_stack_inode_nbytes(inode_item, root->nodesize); in btrfs_add_log_tree()
1480 WARN_ON(root->log_root); in btrfs_add_log_tree()
1481 root->log_root = log_root; in btrfs_add_log_tree()
1482 root->log_transid = 0; in btrfs_add_log_tree()
1483 root->log_transid_committed = -1; in btrfs_add_log_tree()
1484 root->last_log_commit = 0; in btrfs_add_log_tree()
1491 struct btrfs_root *root; in btrfs_read_tree_root() local
1501 root = btrfs_alloc_root(fs_info); in btrfs_read_tree_root()
1502 if (!root) { in btrfs_read_tree_root()
1508 tree_root->stripesize, root, fs_info, key->objectid); in btrfs_read_tree_root()
1511 &root->root_item, &root->root_key); in btrfs_read_tree_root()
1518 generation = btrfs_root_generation(&root->root_item); in btrfs_read_tree_root()
1519 root->node = read_tree_block(root, btrfs_root_bytenr(&root->root_item), in btrfs_read_tree_root()
1521 if (IS_ERR(root->node)) { in btrfs_read_tree_root()
1522 ret = PTR_ERR(root->node); in btrfs_read_tree_root()
1524 } else if (!btrfs_buffer_uptodate(root->node, generation, 0)) { in btrfs_read_tree_root()
1526 free_extent_buffer(root->node); in btrfs_read_tree_root()
1529 root->commit_root = btrfs_root_node(root); in btrfs_read_tree_root()
1532 return root; in btrfs_read_tree_root()
1535 kfree(root); in btrfs_read_tree_root()
1537 root = ERR_PTR(ret); in btrfs_read_tree_root()
1544 struct btrfs_root *root; in btrfs_read_fs_root() local
1546 root = btrfs_read_tree_root(tree_root, location); in btrfs_read_fs_root()
1547 if (IS_ERR(root)) in btrfs_read_fs_root()
1548 return root; in btrfs_read_fs_root()
1550 if (root->root_key.objectid != BTRFS_TREE_LOG_OBJECTID) { in btrfs_read_fs_root()
1551 set_bit(BTRFS_ROOT_REF_COWS, &root->state); in btrfs_read_fs_root()
1552 btrfs_check_and_init_root_item(&root->root_item); in btrfs_read_fs_root()
1555 return root; in btrfs_read_fs_root()
1558 int btrfs_init_fs_root(struct btrfs_root *root) in btrfs_init_fs_root() argument
1563 root->free_ino_ctl = kzalloc(sizeof(*root->free_ino_ctl), GFP_NOFS); in btrfs_init_fs_root()
1564 root->free_ino_pinned = kzalloc(sizeof(*root->free_ino_pinned), in btrfs_init_fs_root()
1566 if (!root->free_ino_pinned || !root->free_ino_ctl) { in btrfs_init_fs_root()
1576 root->subv_writers = writers; in btrfs_init_fs_root()
1578 btrfs_init_free_ino_ctl(root); in btrfs_init_fs_root()
1579 spin_lock_init(&root->ino_cache_lock); in btrfs_init_fs_root()
1580 init_waitqueue_head(&root->ino_cache_wait); in btrfs_init_fs_root()
1582 ret = get_anon_bdev(&root->anon_dev); in btrfs_init_fs_root()
1586 mutex_lock(&root->objectid_mutex); in btrfs_init_fs_root()
1587 ret = btrfs_find_highest_objectid(root, in btrfs_init_fs_root()
1588 &root->highest_objectid); in btrfs_init_fs_root()
1590 mutex_unlock(&root->objectid_mutex); in btrfs_init_fs_root()
1594 ASSERT(root->highest_objectid <= BTRFS_LAST_FREE_OBJECTID); in btrfs_init_fs_root()
1596 mutex_unlock(&root->objectid_mutex); in btrfs_init_fs_root()
1601 free_anon_bdev(root->anon_dev); in btrfs_init_fs_root()
1603 btrfs_free_subvolume_writers(root->subv_writers); in btrfs_init_fs_root()
1605 kfree(root->free_ino_ctl); in btrfs_init_fs_root()
1606 kfree(root->free_ino_pinned); in btrfs_init_fs_root()
1613 struct btrfs_root *root; in btrfs_lookup_fs_root() local
1616 root = radix_tree_lookup(&fs_info->fs_roots_radix, in btrfs_lookup_fs_root()
1619 return root; in btrfs_lookup_fs_root()
1623 struct btrfs_root *root) in btrfs_insert_fs_root() argument
1633 (unsigned long)root->root_key.objectid, in btrfs_insert_fs_root()
1634 root); in btrfs_insert_fs_root()
1636 set_bit(BTRFS_ROOT_IN_RADIX, &root->state); in btrfs_insert_fs_root()
1647 struct btrfs_root *root; in btrfs_get_fs_root() local
1669 root = btrfs_lookup_fs_root(fs_info, location->objectid); in btrfs_get_fs_root()
1670 if (root) { in btrfs_get_fs_root()
1671 if (check_ref && btrfs_root_refs(&root->root_item) == 0) in btrfs_get_fs_root()
1673 return root; in btrfs_get_fs_root()
1676 root = btrfs_read_fs_root(fs_info->tree_root, location); in btrfs_get_fs_root()
1677 if (IS_ERR(root)) in btrfs_get_fs_root()
1678 return root; in btrfs_get_fs_root()
1680 if (check_ref && btrfs_root_refs(&root->root_item) == 0) { in btrfs_get_fs_root()
1685 ret = btrfs_init_fs_root(root); in btrfs_get_fs_root()
1703 set_bit(BTRFS_ROOT_ORPHAN_ITEM_INSERTED, &root->state); in btrfs_get_fs_root()
1705 ret = btrfs_insert_fs_root(fs_info, root); in btrfs_get_fs_root()
1708 free_fs_root(root); in btrfs_get_fs_root()
1713 return root; in btrfs_get_fs_root()
1715 free_fs_root(root); in btrfs_get_fs_root()
1776 struct btrfs_root *root = arg; in cleaner_kthread() local
1784 if (btrfs_need_cleaner_sleep(root)) in cleaner_kthread()
1787 if (!mutex_trylock(&root->fs_info->cleaner_mutex)) in cleaner_kthread()
1794 if (btrfs_need_cleaner_sleep(root)) { in cleaner_kthread()
1795 mutex_unlock(&root->fs_info->cleaner_mutex); in cleaner_kthread()
1799 mutex_lock(&root->fs_info->cleaner_delayed_iput_mutex); in cleaner_kthread()
1800 btrfs_run_delayed_iputs(root); in cleaner_kthread()
1801 mutex_unlock(&root->fs_info->cleaner_delayed_iput_mutex); in cleaner_kthread()
1803 again = btrfs_clean_one_deleted_snapshot(root); in cleaner_kthread()
1804 mutex_unlock(&root->fs_info->cleaner_mutex); in cleaner_kthread()
1810 btrfs_run_defrag_inodes(root->fs_info); in cleaner_kthread()
1820 btrfs_delete_unused_bgs(root->fs_info); in cleaner_kthread()
1841 trans = btrfs_attach_transaction(root); in cleaner_kthread()
1844 btrfs_err(root->fs_info, in cleaner_kthread()
1850 ret = btrfs_commit_transaction(trans, root); in cleaner_kthread()
1852 btrfs_err(root->fs_info, in cleaner_kthread()
1862 struct btrfs_root *root = arg; in transaction_kthread() local
1872 delay = HZ * root->fs_info->commit_interval; in transaction_kthread()
1873 mutex_lock(&root->fs_info->transaction_kthread_mutex); in transaction_kthread()
1875 spin_lock(&root->fs_info->trans_lock); in transaction_kthread()
1876 cur = root->fs_info->running_transaction; in transaction_kthread()
1878 spin_unlock(&root->fs_info->trans_lock); in transaction_kthread()
1885 now - cur->start_time < root->fs_info->commit_interval)) { in transaction_kthread()
1886 spin_unlock(&root->fs_info->trans_lock); in transaction_kthread()
1891 spin_unlock(&root->fs_info->trans_lock); in transaction_kthread()
1894 trans = btrfs_attach_transaction(root); in transaction_kthread()
1901 btrfs_commit_transaction(trans, root); in transaction_kthread()
1903 btrfs_end_transaction(trans, root); in transaction_kthread()
1906 wake_up_process(root->fs_info->cleaner_kthread); in transaction_kthread()
1907 mutex_unlock(&root->fs_info->transaction_kthread_mutex); in transaction_kthread()
1910 &root->fs_info->fs_state))) in transaction_kthread()
1911 btrfs_cleanup_transaction(root); in transaction_kthread()
1915 (!btrfs_transaction_blocked(root->fs_info) || in transaction_kthread()
2146 static void free_root_extent_buffers(struct btrfs_root *root) in free_root_extent_buffers() argument
2148 if (root) { in free_root_extent_buffers()
2149 free_extent_buffer(root->node); in free_root_extent_buffers()
2150 free_extent_buffer(root->commit_root); in free_root_extent_buffers()
2151 root->node = NULL; in free_root_extent_buffers()
2152 root->commit_root = NULL; in free_root_extent_buffers()
2250 BTRFS_I(fs_info->btree_inode)->root = tree_root; in btrfs_init_btree_inode()
2419 struct btrfs_root *root; in btrfs_read_roots() local
2427 root = btrfs_read_tree_root(tree_root, &location); in btrfs_read_roots()
2428 if (IS_ERR(root)) in btrfs_read_roots()
2429 return PTR_ERR(root); in btrfs_read_roots()
2430 set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state); in btrfs_read_roots()
2431 fs_info->extent_root = root; in btrfs_read_roots()
2434 root = btrfs_read_tree_root(tree_root, &location); in btrfs_read_roots()
2435 if (IS_ERR(root)) in btrfs_read_roots()
2436 return PTR_ERR(root); in btrfs_read_roots()
2437 set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state); in btrfs_read_roots()
2438 fs_info->dev_root = root; in btrfs_read_roots()
2442 root = btrfs_read_tree_root(tree_root, &location); in btrfs_read_roots()
2443 if (IS_ERR(root)) in btrfs_read_roots()
2444 return PTR_ERR(root); in btrfs_read_roots()
2445 set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state); in btrfs_read_roots()
2446 fs_info->csum_root = root; in btrfs_read_roots()
2449 root = btrfs_read_tree_root(tree_root, &location); in btrfs_read_roots()
2450 if (!IS_ERR(root)) { in btrfs_read_roots()
2451 set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state); in btrfs_read_roots()
2454 fs_info->quota_root = root; in btrfs_read_roots()
2458 root = btrfs_read_tree_root(tree_root, &location); in btrfs_read_roots()
2459 if (IS_ERR(root)) { in btrfs_read_roots()
2460 ret = PTR_ERR(root); in btrfs_read_roots()
2464 set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state); in btrfs_read_roots()
2465 fs_info->uuid_root = root; in btrfs_read_roots()
3592 static int write_all_supers(struct btrfs_root *root, int max_mirrors) in write_all_supers() argument
3604 do_barriers = !btrfs_test_opt(root, NOBARRIER); in write_all_supers()
3605 backup_super_roots(root->fs_info); in write_all_supers()
3607 sb = root->fs_info->super_for_commit; in write_all_supers()
3610 mutex_lock(&root->fs_info->fs_devices->device_list_mutex); in write_all_supers()
3611 head = &root->fs_info->fs_devices->devices; in write_all_supers()
3612 max_errors = btrfs_super_num_devices(root->fs_info->super_copy) - 1; in write_all_supers()
3615 ret = barrier_all_devices(root->fs_info); in write_all_supers()
3618 &root->fs_info->fs_devices->device_list_mutex); in write_all_supers()
3619 btrfs_std_error(root->fs_info, ret, in write_all_supers()
3654 btrfs_err(root->fs_info, "%d errors while writing supers", in write_all_supers()
3656 mutex_unlock(&root->fs_info->fs_devices->device_list_mutex); in write_all_supers()
3659 btrfs_std_error(root->fs_info, -EIO, in write_all_supers()
3675 mutex_unlock(&root->fs_info->fs_devices->device_list_mutex); in write_all_supers()
3677 btrfs_std_error(root->fs_info, -EIO, in write_all_supers()
3685 struct btrfs_root *root, int max_mirrors) in write_ctree_super() argument
3687 return write_all_supers(root, max_mirrors); in write_ctree_super()
3692 struct btrfs_root *root) in btrfs_drop_and_free_fs_root() argument
3696 (unsigned long)root->root_key.objectid); in btrfs_drop_and_free_fs_root()
3699 if (btrfs_root_refs(&root->root_item) == 0) in btrfs_drop_and_free_fs_root()
3703 btrfs_free_log(NULL, root); in btrfs_drop_and_free_fs_root()
3705 if (root->free_ino_pinned) in btrfs_drop_and_free_fs_root()
3706 __btrfs_remove_free_space_cache(root->free_ino_pinned); in btrfs_drop_and_free_fs_root()
3707 if (root->free_ino_ctl) in btrfs_drop_and_free_fs_root()
3708 __btrfs_remove_free_space_cache(root->free_ino_ctl); in btrfs_drop_and_free_fs_root()
3709 free_fs_root(root); in btrfs_drop_and_free_fs_root()
3712 static void free_fs_root(struct btrfs_root *root) in free_fs_root() argument
3714 iput(root->ino_cache_inode); in free_fs_root()
3715 WARN_ON(!RB_EMPTY_ROOT(&root->inode_tree)); in free_fs_root()
3716 btrfs_free_block_rsv(root, root->orphan_block_rsv); in free_fs_root()
3717 root->orphan_block_rsv = NULL; in free_fs_root()
3718 if (root->anon_dev) in free_fs_root()
3719 free_anon_bdev(root->anon_dev); in free_fs_root()
3720 if (root->subv_writers) in free_fs_root()
3721 btrfs_free_subvolume_writers(root->subv_writers); in free_fs_root()
3722 free_extent_buffer(root->node); in free_fs_root()
3723 free_extent_buffer(root->commit_root); in free_fs_root()
3724 kfree(root->free_ino_ctl); in free_fs_root()
3725 kfree(root->free_ino_pinned); in free_fs_root()
3726 kfree(root->name); in free_fs_root()
3727 btrfs_put_fs_root(root); in free_fs_root()
3730 void btrfs_free_fs_root(struct btrfs_root *root) in btrfs_free_fs_root() argument
3732 free_fs_root(root); in btrfs_free_fs_root()
3786 int btrfs_commit_super(struct btrfs_root *root) in btrfs_commit_super() argument
3790 mutex_lock(&root->fs_info->cleaner_mutex); in btrfs_commit_super()
3791 btrfs_run_delayed_iputs(root); in btrfs_commit_super()
3792 mutex_unlock(&root->fs_info->cleaner_mutex); in btrfs_commit_super()
3793 wake_up_process(root->fs_info->cleaner_kthread); in btrfs_commit_super()
3796 down_write(&root->fs_info->cleanup_work_sem); in btrfs_commit_super()
3797 up_write(&root->fs_info->cleanup_work_sem); in btrfs_commit_super()
3799 trans = btrfs_join_transaction(root); in btrfs_commit_super()
3802 return btrfs_commit_transaction(trans, root); in btrfs_commit_super()
3805 void close_ctree(struct btrfs_root *root) in close_ctree() argument
3807 struct btrfs_fs_info *fs_info = root->fs_info; in close_ctree()
3843 btrfs_delete_unused_bgs(root->fs_info); in close_ctree()
3845 ret = btrfs_commit_super(root); in close_ctree()
3851 btrfs_error_commit_super(root); in close_ctree()
3888 if (btrfs_test_opt(root, CHECK_INTEGRITY)) in close_ctree()
3889 btrfsic_unmount(root, fs_info->fs_devices); in close_ctree()
3903 __btrfs_free_block_rsv(root->orphan_block_rsv); in close_ctree()
3904 root->orphan_block_rsv = NULL; in close_ctree()
3906 lock_chunks(root); in close_ctree()
3915 unlock_chunks(root); in close_ctree()
3942 struct btrfs_root *root; in btrfs_mark_buffer_dirty() local
3955 root = BTRFS_I(buf->pages[0]->mapping->host)->root; in btrfs_mark_buffer_dirty()
3957 if (transid != root->fs_info->generation) in btrfs_mark_buffer_dirty()
3960 buf->start, transid, root->fs_info->generation); in btrfs_mark_buffer_dirty()
3963 __percpu_counter_add(&root->fs_info->dirty_metadata_bytes, in btrfs_mark_buffer_dirty()
3965 root->fs_info->dirty_metadata_batch); in btrfs_mark_buffer_dirty()
3967 if (btrfs_header_level(buf) == 0 && check_leaf(root, buf)) { in btrfs_mark_buffer_dirty()
3968 btrfs_print_leaf(root, buf); in btrfs_mark_buffer_dirty()
3974 static void __btrfs_btree_balance_dirty(struct btrfs_root *root, in __btrfs_btree_balance_dirty() argument
3987 btrfs_balance_delayed_items(root); in __btrfs_btree_balance_dirty()
3989 ret = percpu_counter_compare(&root->fs_info->dirty_metadata_bytes, in __btrfs_btree_balance_dirty()
3993 root->fs_info->btree_inode->i_mapping); in __btrfs_btree_balance_dirty()
3998 void btrfs_btree_balance_dirty(struct btrfs_root *root) in btrfs_btree_balance_dirty() argument
4000 __btrfs_btree_balance_dirty(root, 1); in btrfs_btree_balance_dirty()
4003 void btrfs_btree_balance_dirty_nodelay(struct btrfs_root *root) in btrfs_btree_balance_dirty_nodelay() argument
4005 __btrfs_btree_balance_dirty(root, 0); in btrfs_btree_balance_dirty_nodelay()
4010 struct btrfs_root *root = BTRFS_I(buf->pages[0]->mapping->host)->root; in btrfs_read_buffer() local
4011 return btree_read_extent_buffer_pages(root, buf, 0, parent_transid); in btrfs_read_buffer()
4125 static void btrfs_error_commit_super(struct btrfs_root *root) in btrfs_error_commit_super() argument
4127 mutex_lock(&root->fs_info->cleaner_mutex); in btrfs_error_commit_super()
4128 btrfs_run_delayed_iputs(root); in btrfs_error_commit_super()
4129 mutex_unlock(&root->fs_info->cleaner_mutex); in btrfs_error_commit_super()
4131 down_write(&root->fs_info->cleanup_work_sem); in btrfs_error_commit_super()
4132 up_write(&root->fs_info->cleanup_work_sem); in btrfs_error_commit_super()
4135 btrfs_cleanup_transaction(root); in btrfs_error_commit_super()
4138 static void btrfs_destroy_ordered_extents(struct btrfs_root *root) in btrfs_destroy_ordered_extents() argument
4142 spin_lock(&root->ordered_extent_lock); in btrfs_destroy_ordered_extents()
4147 list_for_each_entry(ordered, &root->ordered_extents, in btrfs_destroy_ordered_extents()
4150 spin_unlock(&root->ordered_extent_lock); in btrfs_destroy_ordered_extents()
4155 struct btrfs_root *root; in btrfs_destroy_all_ordered_extents() local
4163 root = list_first_entry(&splice, struct btrfs_root, in btrfs_destroy_all_ordered_extents()
4165 list_move_tail(&root->ordered_root, in btrfs_destroy_all_ordered_extents()
4169 btrfs_destroy_ordered_extents(root); in btrfs_destroy_all_ordered_extents()
4178 struct btrfs_root *root) in btrfs_destroy_delayed_refs() argument
4190 btrfs_info(root->fs_info, "delayed_refs has NO entry"); in btrfs_destroy_delayed_refs()
4233 btrfs_pin_extent(root, head->node.bytenr, in btrfs_destroy_delayed_refs()
4245 static void btrfs_destroy_delalloc_inodes(struct btrfs_root *root) in btrfs_destroy_delalloc_inodes() argument
4252 spin_lock(&root->delalloc_lock); in btrfs_destroy_delalloc_inodes()
4253 list_splice_init(&root->delalloc_inodes, &splice); in btrfs_destroy_delalloc_inodes()
4262 spin_unlock(&root->delalloc_lock); in btrfs_destroy_delalloc_inodes()
4264 btrfs_invalidate_inodes(btrfs_inode->root); in btrfs_destroy_delalloc_inodes()
4266 spin_lock(&root->delalloc_lock); in btrfs_destroy_delalloc_inodes()
4269 spin_unlock(&root->delalloc_lock); in btrfs_destroy_delalloc_inodes()
4274 struct btrfs_root *root; in btrfs_destroy_all_delalloc_inodes() local
4282 root = list_first_entry(&splice, struct btrfs_root, in btrfs_destroy_all_delalloc_inodes()
4284 list_del_init(&root->delalloc_root); in btrfs_destroy_all_delalloc_inodes()
4285 root = btrfs_grab_fs_root(root); in btrfs_destroy_all_delalloc_inodes()
4286 BUG_ON(!root); in btrfs_destroy_all_delalloc_inodes()
4289 btrfs_destroy_delalloc_inodes(root); in btrfs_destroy_all_delalloc_inodes()
4290 btrfs_put_fs_root(root); in btrfs_destroy_all_delalloc_inodes()
4297 static int btrfs_destroy_marked_extents(struct btrfs_root *root, in btrfs_destroy_marked_extents() argument
4314 eb = btrfs_find_tree_block(root->fs_info, start); in btrfs_destroy_marked_extents()
4315 start += root->nodesize; in btrfs_destroy_marked_extents()
4330 static int btrfs_destroy_pinned_extent(struct btrfs_root *root, in btrfs_destroy_pinned_extent() argument
4348 btrfs_error_unpin_extent_range(root, start, end); in btrfs_destroy_pinned_extent()
4353 if (unpin == &root->fs_info->freed_extents[0]) in btrfs_destroy_pinned_extent()
4354 unpin = &root->fs_info->freed_extents[1]; in btrfs_destroy_pinned_extent()
4356 unpin = &root->fs_info->freed_extents[0]; in btrfs_destroy_pinned_extent()
4365 struct btrfs_root *root) in btrfs_cleanup_one_transaction() argument
4367 btrfs_destroy_delayed_refs(cur_trans, root); in btrfs_cleanup_one_transaction()
4370 wake_up(&root->fs_info->transaction_blocked_wait); in btrfs_cleanup_one_transaction()
4373 wake_up(&root->fs_info->transaction_wait); in btrfs_cleanup_one_transaction()
4375 btrfs_destroy_delayed_inodes(root); in btrfs_cleanup_one_transaction()
4376 btrfs_assert_delayed_root_empty(root); in btrfs_cleanup_one_transaction()
4378 btrfs_destroy_marked_extents(root, &cur_trans->dirty_pages, in btrfs_cleanup_one_transaction()
4380 btrfs_destroy_pinned_extent(root, in btrfs_cleanup_one_transaction()
4381 root->fs_info->pinned_extents); in btrfs_cleanup_one_transaction()
4392 static int btrfs_cleanup_transaction(struct btrfs_root *root) in btrfs_cleanup_transaction() argument
4396 mutex_lock(&root->fs_info->transaction_kthread_mutex); in btrfs_cleanup_transaction()
4398 spin_lock(&root->fs_info->trans_lock); in btrfs_cleanup_transaction()
4399 while (!list_empty(&root->fs_info->trans_list)) { in btrfs_cleanup_transaction()
4400 t = list_first_entry(&root->fs_info->trans_list, in btrfs_cleanup_transaction()
4404 spin_unlock(&root->fs_info->trans_lock); in btrfs_cleanup_transaction()
4405 btrfs_wait_for_commit(root, t->transid); in btrfs_cleanup_transaction()
4407 spin_lock(&root->fs_info->trans_lock); in btrfs_cleanup_transaction()
4410 if (t == root->fs_info->running_transaction) { in btrfs_cleanup_transaction()
4412 spin_unlock(&root->fs_info->trans_lock); in btrfs_cleanup_transaction()
4420 spin_unlock(&root->fs_info->trans_lock); in btrfs_cleanup_transaction()
4422 btrfs_cleanup_one_transaction(t, root); in btrfs_cleanup_transaction()
4424 spin_lock(&root->fs_info->trans_lock); in btrfs_cleanup_transaction()
4425 if (t == root->fs_info->running_transaction) in btrfs_cleanup_transaction()
4426 root->fs_info->running_transaction = NULL; in btrfs_cleanup_transaction()
4428 spin_unlock(&root->fs_info->trans_lock); in btrfs_cleanup_transaction()
4431 trace_btrfs_transaction_commit(root); in btrfs_cleanup_transaction()
4432 spin_lock(&root->fs_info->trans_lock); in btrfs_cleanup_transaction()
4434 spin_unlock(&root->fs_info->trans_lock); in btrfs_cleanup_transaction()
4435 btrfs_destroy_all_ordered_extents(root->fs_info); in btrfs_cleanup_transaction()
4436 btrfs_destroy_delayed_inodes(root); in btrfs_cleanup_transaction()
4437 btrfs_assert_delayed_root_empty(root); in btrfs_cleanup_transaction()
4438 btrfs_destroy_pinned_extent(root, root->fs_info->pinned_extents); in btrfs_cleanup_transaction()
4439 btrfs_destroy_all_delalloc_inodes(root->fs_info); in btrfs_cleanup_transaction()
4440 mutex_unlock(&root->fs_info->transaction_kthread_mutex); in btrfs_cleanup_transaction()