Lines Matching refs:root
60 static void free_fs_root(struct btrfs_root *root);
63 static void btrfs_destroy_ordered_extents(struct btrfs_root *root);
65 struct btrfs_root *root);
66 static void btrfs_destroy_delalloc_inodes(struct btrfs_root *root);
67 static int btrfs_destroy_marked_extents(struct btrfs_root *root,
70 static int btrfs_destroy_pinned_extent(struct btrfs_root *root,
72 static int btrfs_cleanup_transaction(struct btrfs_root *root);
73 static void btrfs_error_commit_super(struct btrfs_root *root);
230 BTRFS_I(inode)->root->fs_info->fs_devices->latest_bdev; in btree_get_extent()
245 em->bdev = BTRFS_I(inode)->root->fs_info->fs_devices->latest_bdev; in btree_get_extent()
438 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()
463 num_copies = btrfs_num_copies(root->fs_info, in btree_read_extent_buffer_pages()
482 repair_eb_io_failure(root, eb, failed_mirror); in btree_read_extent_buffer_pages()
533 struct btrfs_root *root = BTRFS_I(page->mapping->host)->root; in btree_readpage_end_io_hook() local
564 if (check_tree_block_fsid(root->fs_info, eb)) { in btree_readpage_end_io_hook()
572 btrfs_err(root->fs_info, "bad tree block level %d", in btree_readpage_end_io_hook()
581 ret = csum_tree_block(root->fs_info, eb, 1); in btree_readpage_end_io_hook()
592 if (found_level == 0 && btrfs_check_leaf_full(root, eb)) { in btree_readpage_end_io_hook()
597 if (found_level > 0 && btrfs_check_node(root, eb)) in btree_readpage_end_io_hook()
605 btree_readahead_hook(root, eb, eb->start, ret); in btree_readpage_end_io_hook()
624 struct btrfs_root *root = BTRFS_I(page->mapping->host)->root; in btree_io_failed_hook() local
631 btree_readahead_hook(root, eb, eb->start, -EIO); in btree_io_failed_hook()
729 fs_info = BTRFS_I(async->inode)->root->fs_info; in run_one_async_done()
808 struct btrfs_root *root; in btree_csum_one_bio() local
812 root = BTRFS_I(bvec->bv_page->mapping->host)->root; in btree_csum_one_bio()
813 ret = csum_dirty_buffer(root->fs_info, bvec->bv_page); in btree_csum_one_bio()
843 ret = btrfs_map_bio(BTRFS_I(inode)->root, rw, bio, mirror_num, 1); in __btree_submit_bio_done()
874 ret = btrfs_bio_wq_end_io(BTRFS_I(inode)->root->fs_info, in btree_submit_bio_hook()
878 ret = btrfs_map_bio(BTRFS_I(inode)->root, rw, bio, in btree_submit_bio_hook()
884 ret = btrfs_map_bio(BTRFS_I(inode)->root, rw, bio, in btree_submit_bio_hook()
891 ret = btrfs_wq_submit_bio(BTRFS_I(inode)->root->fs_info, in btree_submit_bio_hook()
942 fs_info = BTRFS_I(mapping->host)->root->fs_info; in btree_writepages()
976 btrfs_warn(BTRFS_I(page->mapping->host)->root->fs_info, in btree_invalidatepage()
1011 void readahead_tree_block(struct btrfs_root *root, u64 bytenr) in readahead_tree_block() argument
1014 struct inode *btree_inode = root->fs_info->btree_inode; in readahead_tree_block()
1016 buf = btrfs_find_create_tree_block(root, bytenr); in readahead_tree_block()
1024 int reada_tree_block_flagged(struct btrfs_root *root, u64 bytenr, in reada_tree_block_flagged() argument
1028 struct inode *btree_inode = root->fs_info->btree_inode; in reada_tree_block_flagged()
1032 buf = btrfs_find_create_tree_block(root, bytenr); in reada_tree_block_flagged()
1062 struct extent_buffer *btrfs_find_create_tree_block(struct btrfs_root *root, in btrfs_find_create_tree_block() argument
1065 if (btrfs_test_is_dummy_root(root)) in btrfs_find_create_tree_block()
1066 return alloc_test_extent_buffer(root->fs_info, bytenr); in btrfs_find_create_tree_block()
1067 return alloc_extent_buffer(root->fs_info, bytenr); in btrfs_find_create_tree_block()
1083 struct extent_buffer *read_tree_block(struct btrfs_root *root, u64 bytenr, in read_tree_block() argument
1089 buf = btrfs_find_create_tree_block(root, bytenr); in read_tree_block()
1093 ret = btree_read_extent_buffer_pages(root, buf, 0, parent_transid); in read_tree_block()
1148 struct btrfs_root *root, struct btrfs_fs_info *fs_info, in __setup_root() argument
1151 root->node = NULL; in __setup_root()
1152 root->commit_root = NULL; in __setup_root()
1153 root->sectorsize = sectorsize; in __setup_root()
1154 root->nodesize = nodesize; in __setup_root()
1155 root->stripesize = stripesize; in __setup_root()
1156 root->state = 0; in __setup_root()
1157 root->orphan_cleanup_state = 0; in __setup_root()
1159 root->objectid = objectid; in __setup_root()
1160 root->last_trans = 0; in __setup_root()
1161 root->highest_objectid = 0; in __setup_root()
1162 root->nr_delalloc_inodes = 0; in __setup_root()
1163 root->nr_ordered_extents = 0; in __setup_root()
1164 root->name = NULL; in __setup_root()
1165 root->inode_tree = RB_ROOT; in __setup_root()
1166 INIT_RADIX_TREE(&root->delayed_nodes_tree, GFP_ATOMIC); in __setup_root()
1167 root->block_rsv = NULL; in __setup_root()
1168 root->orphan_block_rsv = NULL; in __setup_root()
1170 INIT_LIST_HEAD(&root->dirty_list); in __setup_root()
1171 INIT_LIST_HEAD(&root->root_list); in __setup_root()
1172 INIT_LIST_HEAD(&root->delalloc_inodes); in __setup_root()
1173 INIT_LIST_HEAD(&root->delalloc_root); in __setup_root()
1174 INIT_LIST_HEAD(&root->ordered_extents); in __setup_root()
1175 INIT_LIST_HEAD(&root->ordered_root); in __setup_root()
1176 INIT_LIST_HEAD(&root->logged_list[0]); in __setup_root()
1177 INIT_LIST_HEAD(&root->logged_list[1]); in __setup_root()
1178 spin_lock_init(&root->orphan_lock); in __setup_root()
1179 spin_lock_init(&root->inode_lock); in __setup_root()
1180 spin_lock_init(&root->delalloc_lock); in __setup_root()
1181 spin_lock_init(&root->ordered_extent_lock); in __setup_root()
1182 spin_lock_init(&root->accounting_lock); in __setup_root()
1183 spin_lock_init(&root->log_extents_lock[0]); in __setup_root()
1184 spin_lock_init(&root->log_extents_lock[1]); in __setup_root()
1185 mutex_init(&root->objectid_mutex); in __setup_root()
1186 mutex_init(&root->log_mutex); in __setup_root()
1187 mutex_init(&root->ordered_extent_mutex); in __setup_root()
1188 mutex_init(&root->delalloc_mutex); in __setup_root()
1189 init_waitqueue_head(&root->log_writer_wait); in __setup_root()
1190 init_waitqueue_head(&root->log_commit_wait[0]); in __setup_root()
1191 init_waitqueue_head(&root->log_commit_wait[1]); in __setup_root()
1192 INIT_LIST_HEAD(&root->log_ctxs[0]); in __setup_root()
1193 INIT_LIST_HEAD(&root->log_ctxs[1]); in __setup_root()
1194 atomic_set(&root->log_commit[0], 0); in __setup_root()
1195 atomic_set(&root->log_commit[1], 0); in __setup_root()
1196 atomic_set(&root->log_writers, 0); in __setup_root()
1197 atomic_set(&root->log_batch, 0); in __setup_root()
1198 atomic_set(&root->orphan_inodes, 0); in __setup_root()
1199 atomic_set(&root->refs, 1); in __setup_root()
1200 atomic_set(&root->will_be_snapshoted, 0); in __setup_root()
1201 atomic_set(&root->qgroup_meta_rsv, 0); in __setup_root()
1202 root->log_transid = 0; in __setup_root()
1203 root->log_transid_committed = -1; in __setup_root()
1204 root->last_log_commit = 0; in __setup_root()
1206 extent_io_tree_init(&root->dirty_log_pages, in __setup_root()
1209 memset(&root->root_key, 0, sizeof(root->root_key)); in __setup_root()
1210 memset(&root->root_item, 0, sizeof(root->root_item)); in __setup_root()
1211 memset(&root->defrag_progress, 0, sizeof(root->defrag_progress)); in __setup_root()
1213 root->defrag_trans_start = fs_info->generation; in __setup_root()
1215 root->defrag_trans_start = 0; in __setup_root()
1216 root->root_key.objectid = objectid; in __setup_root()
1217 root->anon_dev = 0; in __setup_root()
1219 spin_lock_init(&root->root_item_lock); in __setup_root()
1224 struct btrfs_root *root = kzalloc(sizeof(*root), GFP_NOFS); in btrfs_alloc_root() local
1225 if (root) in btrfs_alloc_root()
1226 root->fs_info = fs_info; in btrfs_alloc_root()
1227 return root; in btrfs_alloc_root()
1234 struct btrfs_root *root; in btrfs_alloc_dummy_root() local
1236 root = btrfs_alloc_root(NULL); in btrfs_alloc_dummy_root()
1237 if (!root) in btrfs_alloc_dummy_root()
1239 __setup_root(4096, 4096, 4096, root, NULL, 1); in btrfs_alloc_dummy_root()
1240 set_bit(BTRFS_ROOT_DUMMY_ROOT, &root->state); in btrfs_alloc_dummy_root()
1241 root->alloc_bytenr = 0; in btrfs_alloc_dummy_root()
1243 return root; in btrfs_alloc_dummy_root()
1253 struct btrfs_root *root; in btrfs_create_tree() local
1258 root = btrfs_alloc_root(fs_info); in btrfs_create_tree()
1259 if (!root) in btrfs_create_tree()
1263 tree_root->stripesize, root, fs_info, objectid); in btrfs_create_tree()
1264 root->root_key.objectid = objectid; in btrfs_create_tree()
1265 root->root_key.type = BTRFS_ROOT_ITEM_KEY; in btrfs_create_tree()
1266 root->root_key.offset = 0; in btrfs_create_tree()
1268 leaf = btrfs_alloc_tree_block(trans, root, 0, objectid, NULL, 0, 0, 0); in btrfs_create_tree()
1280 root->node = leaf; in btrfs_create_tree()
1289 root->commit_root = btrfs_root_node(root); in btrfs_create_tree()
1290 set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state); in btrfs_create_tree()
1292 root->root_item.flags = 0; in btrfs_create_tree()
1293 root->root_item.byte_limit = 0; in btrfs_create_tree()
1294 btrfs_set_root_bytenr(&root->root_item, leaf->start); in btrfs_create_tree()
1295 btrfs_set_root_generation(&root->root_item, trans->transid); in btrfs_create_tree()
1296 btrfs_set_root_level(&root->root_item, 0); in btrfs_create_tree()
1297 btrfs_set_root_refs(&root->root_item, 1); in btrfs_create_tree()
1298 btrfs_set_root_used(&root->root_item, leaf->len); in btrfs_create_tree()
1299 btrfs_set_root_last_snapshot(&root->root_item, 0); in btrfs_create_tree()
1300 btrfs_set_root_dirid(&root->root_item, 0); in btrfs_create_tree()
1302 memcpy(root->root_item.uuid, uuid.b, BTRFS_UUID_SIZE); in btrfs_create_tree()
1303 root->root_item.drop_level = 0; in btrfs_create_tree()
1308 ret = btrfs_insert_root(trans, tree_root, &key, &root->root_item); in btrfs_create_tree()
1314 return root; in btrfs_create_tree()
1319 free_extent_buffer(root->commit_root); in btrfs_create_tree()
1322 kfree(root); in btrfs_create_tree()
1330 struct btrfs_root *root; in alloc_log_tree() local
1334 root = btrfs_alloc_root(fs_info); in alloc_log_tree()
1335 if (!root) in alloc_log_tree()
1339 tree_root->stripesize, root, fs_info, in alloc_log_tree()
1342 root->root_key.objectid = BTRFS_TREE_LOG_OBJECTID; in alloc_log_tree()
1343 root->root_key.type = BTRFS_ROOT_ITEM_KEY; in alloc_log_tree()
1344 root->root_key.offset = BTRFS_TREE_LOG_OBJECTID; in alloc_log_tree()
1355 leaf = btrfs_alloc_tree_block(trans, root, 0, BTRFS_TREE_LOG_OBJECTID, in alloc_log_tree()
1358 kfree(root); in alloc_log_tree()
1367 root->node = leaf; in alloc_log_tree()
1369 write_extent_buffer(root->node, root->fs_info->fsid, in alloc_log_tree()
1371 btrfs_mark_buffer_dirty(root->node); in alloc_log_tree()
1372 btrfs_tree_unlock(root->node); in alloc_log_tree()
1373 return root; in alloc_log_tree()
1390 struct btrfs_root *root) in btrfs_add_log_tree() argument
1395 log_root = alloc_log_tree(trans, root->fs_info); in btrfs_add_log_tree()
1400 log_root->root_key.offset = root->root_key.objectid; in btrfs_add_log_tree()
1406 btrfs_set_stack_inode_nbytes(inode_item, root->nodesize); in btrfs_add_log_tree()
1411 WARN_ON(root->log_root); in btrfs_add_log_tree()
1412 root->log_root = log_root; in btrfs_add_log_tree()
1413 root->log_transid = 0; in btrfs_add_log_tree()
1414 root->log_transid_committed = -1; in btrfs_add_log_tree()
1415 root->last_log_commit = 0; in btrfs_add_log_tree()
1422 struct btrfs_root *root; in btrfs_read_tree_root() local
1432 root = btrfs_alloc_root(fs_info); in btrfs_read_tree_root()
1433 if (!root) { in btrfs_read_tree_root()
1439 tree_root->stripesize, root, fs_info, key->objectid); in btrfs_read_tree_root()
1442 &root->root_item, &root->root_key); in btrfs_read_tree_root()
1449 generation = btrfs_root_generation(&root->root_item); in btrfs_read_tree_root()
1450 root->node = read_tree_block(root, btrfs_root_bytenr(&root->root_item), in btrfs_read_tree_root()
1452 if (IS_ERR(root->node)) { in btrfs_read_tree_root()
1453 ret = PTR_ERR(root->node); in btrfs_read_tree_root()
1455 } else if (!btrfs_buffer_uptodate(root->node, generation, 0)) { in btrfs_read_tree_root()
1457 free_extent_buffer(root->node); in btrfs_read_tree_root()
1460 root->commit_root = btrfs_root_node(root); in btrfs_read_tree_root()
1463 return root; in btrfs_read_tree_root()
1466 kfree(root); in btrfs_read_tree_root()
1468 root = ERR_PTR(ret); in btrfs_read_tree_root()
1475 struct btrfs_root *root; in btrfs_read_fs_root() local
1477 root = btrfs_read_tree_root(tree_root, location); in btrfs_read_fs_root()
1478 if (IS_ERR(root)) in btrfs_read_fs_root()
1479 return root; in btrfs_read_fs_root()
1481 if (root->root_key.objectid != BTRFS_TREE_LOG_OBJECTID) { in btrfs_read_fs_root()
1482 set_bit(BTRFS_ROOT_REF_COWS, &root->state); in btrfs_read_fs_root()
1483 btrfs_check_and_init_root_item(&root->root_item); in btrfs_read_fs_root()
1486 return root; in btrfs_read_fs_root()
1489 int btrfs_init_fs_root(struct btrfs_root *root) in btrfs_init_fs_root() argument
1494 root->free_ino_ctl = kzalloc(sizeof(*root->free_ino_ctl), GFP_NOFS); in btrfs_init_fs_root()
1495 root->free_ino_pinned = kzalloc(sizeof(*root->free_ino_pinned), in btrfs_init_fs_root()
1497 if (!root->free_ino_pinned || !root->free_ino_ctl) { in btrfs_init_fs_root()
1507 root->subv_writers = writers; in btrfs_init_fs_root()
1509 btrfs_init_free_ino_ctl(root); in btrfs_init_fs_root()
1510 spin_lock_init(&root->ino_cache_lock); in btrfs_init_fs_root()
1511 init_waitqueue_head(&root->ino_cache_wait); in btrfs_init_fs_root()
1513 ret = get_anon_bdev(&root->anon_dev); in btrfs_init_fs_root()
1517 mutex_lock(&root->objectid_mutex); in btrfs_init_fs_root()
1518 ret = btrfs_find_highest_objectid(root, in btrfs_init_fs_root()
1519 &root->highest_objectid); in btrfs_init_fs_root()
1521 mutex_unlock(&root->objectid_mutex); in btrfs_init_fs_root()
1525 ASSERT(root->highest_objectid <= BTRFS_LAST_FREE_OBJECTID); in btrfs_init_fs_root()
1527 mutex_unlock(&root->objectid_mutex); in btrfs_init_fs_root()
1532 free_anon_bdev(root->anon_dev); in btrfs_init_fs_root()
1534 btrfs_free_subvolume_writers(root->subv_writers); in btrfs_init_fs_root()
1536 kfree(root->free_ino_ctl); in btrfs_init_fs_root()
1537 kfree(root->free_ino_pinned); in btrfs_init_fs_root()
1544 struct btrfs_root *root; in btrfs_lookup_fs_root() local
1547 root = radix_tree_lookup(&fs_info->fs_roots_radix, in btrfs_lookup_fs_root()
1550 return root; in btrfs_lookup_fs_root()
1554 struct btrfs_root *root) in btrfs_insert_fs_root() argument
1564 (unsigned long)root->root_key.objectid, in btrfs_insert_fs_root()
1565 root); in btrfs_insert_fs_root()
1567 set_bit(BTRFS_ROOT_IN_RADIX, &root->state); in btrfs_insert_fs_root()
1578 struct btrfs_root *root; in btrfs_get_fs_root() local
1600 root = btrfs_lookup_fs_root(fs_info, location->objectid); in btrfs_get_fs_root()
1601 if (root) { in btrfs_get_fs_root()
1602 if (check_ref && btrfs_root_refs(&root->root_item) == 0) in btrfs_get_fs_root()
1604 return root; in btrfs_get_fs_root()
1607 root = btrfs_read_fs_root(fs_info->tree_root, location); in btrfs_get_fs_root()
1608 if (IS_ERR(root)) in btrfs_get_fs_root()
1609 return root; in btrfs_get_fs_root()
1611 if (check_ref && btrfs_root_refs(&root->root_item) == 0) { in btrfs_get_fs_root()
1616 ret = btrfs_init_fs_root(root); in btrfs_get_fs_root()
1634 set_bit(BTRFS_ROOT_ORPHAN_ITEM_INSERTED, &root->state); in btrfs_get_fs_root()
1636 ret = btrfs_insert_fs_root(fs_info, root); in btrfs_get_fs_root()
1639 free_fs_root(root); in btrfs_get_fs_root()
1644 return root; in btrfs_get_fs_root()
1646 free_fs_root(root); in btrfs_get_fs_root()
1707 struct btrfs_root *root = arg; in cleaner_kthread() local
1715 if (btrfs_need_cleaner_sleep(root)) in cleaner_kthread()
1718 if (!mutex_trylock(&root->fs_info->cleaner_mutex)) in cleaner_kthread()
1725 if (btrfs_need_cleaner_sleep(root)) { in cleaner_kthread()
1726 mutex_unlock(&root->fs_info->cleaner_mutex); in cleaner_kthread()
1730 mutex_lock(&root->fs_info->cleaner_delayed_iput_mutex); in cleaner_kthread()
1731 btrfs_run_delayed_iputs(root); in cleaner_kthread()
1732 mutex_unlock(&root->fs_info->cleaner_delayed_iput_mutex); in cleaner_kthread()
1734 again = btrfs_clean_one_deleted_snapshot(root); in cleaner_kthread()
1735 mutex_unlock(&root->fs_info->cleaner_mutex); in cleaner_kthread()
1741 btrfs_run_defrag_inodes(root->fs_info); in cleaner_kthread()
1751 btrfs_delete_unused_bgs(root->fs_info); in cleaner_kthread()
1772 trans = btrfs_attach_transaction(root); in cleaner_kthread()
1775 btrfs_err(root->fs_info, in cleaner_kthread()
1781 ret = btrfs_commit_transaction(trans, root); in cleaner_kthread()
1783 btrfs_err(root->fs_info, in cleaner_kthread()
1793 struct btrfs_root *root = arg; in transaction_kthread() local
1803 delay = HZ * root->fs_info->commit_interval; in transaction_kthread()
1804 mutex_lock(&root->fs_info->transaction_kthread_mutex); in transaction_kthread()
1806 spin_lock(&root->fs_info->trans_lock); in transaction_kthread()
1807 cur = root->fs_info->running_transaction; in transaction_kthread()
1809 spin_unlock(&root->fs_info->trans_lock); in transaction_kthread()
1816 now - cur->start_time < root->fs_info->commit_interval)) { in transaction_kthread()
1817 spin_unlock(&root->fs_info->trans_lock); in transaction_kthread()
1822 spin_unlock(&root->fs_info->trans_lock); in transaction_kthread()
1825 trans = btrfs_attach_transaction(root); in transaction_kthread()
1832 btrfs_commit_transaction(trans, root); in transaction_kthread()
1834 btrfs_end_transaction(trans, root); in transaction_kthread()
1837 wake_up_process(root->fs_info->cleaner_kthread); in transaction_kthread()
1838 mutex_unlock(&root->fs_info->transaction_kthread_mutex); in transaction_kthread()
1841 &root->fs_info->fs_state))) in transaction_kthread()
1842 btrfs_cleanup_transaction(root); in transaction_kthread()
1846 (!btrfs_transaction_blocked(root->fs_info) || in transaction_kthread()
2077 static void free_root_extent_buffers(struct btrfs_root *root) in free_root_extent_buffers() argument
2079 if (root) { in free_root_extent_buffers()
2080 free_extent_buffer(root->node); in free_root_extent_buffers()
2081 free_extent_buffer(root->commit_root); in free_root_extent_buffers()
2082 root->node = NULL; in free_root_extent_buffers()
2083 root->commit_root = NULL; in free_root_extent_buffers()
2181 BTRFS_I(fs_info->btree_inode)->root = tree_root; in btrfs_init_btree_inode()
2351 struct btrfs_root *root; in btrfs_read_roots() local
2359 root = btrfs_read_tree_root(tree_root, &location); in btrfs_read_roots()
2360 if (IS_ERR(root)) in btrfs_read_roots()
2361 return PTR_ERR(root); in btrfs_read_roots()
2362 set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state); in btrfs_read_roots()
2363 fs_info->extent_root = root; in btrfs_read_roots()
2366 root = btrfs_read_tree_root(tree_root, &location); in btrfs_read_roots()
2367 if (IS_ERR(root)) in btrfs_read_roots()
2368 return PTR_ERR(root); in btrfs_read_roots()
2369 set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state); in btrfs_read_roots()
2370 fs_info->dev_root = root; in btrfs_read_roots()
2374 root = btrfs_read_tree_root(tree_root, &location); in btrfs_read_roots()
2375 if (IS_ERR(root)) in btrfs_read_roots()
2376 return PTR_ERR(root); in btrfs_read_roots()
2377 set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state); in btrfs_read_roots()
2378 fs_info->csum_root = root; in btrfs_read_roots()
2381 root = btrfs_read_tree_root(tree_root, &location); in btrfs_read_roots()
2382 if (!IS_ERR(root)) { in btrfs_read_roots()
2383 set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state); in btrfs_read_roots()
2386 fs_info->quota_root = root; in btrfs_read_roots()
2390 root = btrfs_read_tree_root(tree_root, &location); in btrfs_read_roots()
2391 if (IS_ERR(root)) { in btrfs_read_roots()
2392 ret = PTR_ERR(root); in btrfs_read_roots()
2396 set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state); in btrfs_read_roots()
2397 fs_info->uuid_root = root; in btrfs_read_roots()
3524 static int write_all_supers(struct btrfs_root *root, int max_mirrors) in write_all_supers() argument
3536 do_barriers = !btrfs_test_opt(root, NOBARRIER); in write_all_supers()
3537 backup_super_roots(root->fs_info); in write_all_supers()
3539 sb = root->fs_info->super_for_commit; in write_all_supers()
3542 mutex_lock(&root->fs_info->fs_devices->device_list_mutex); in write_all_supers()
3543 head = &root->fs_info->fs_devices->devices; in write_all_supers()
3544 max_errors = btrfs_super_num_devices(root->fs_info->super_copy) - 1; in write_all_supers()
3547 ret = barrier_all_devices(root->fs_info); in write_all_supers()
3550 &root->fs_info->fs_devices->device_list_mutex); in write_all_supers()
3551 btrfs_std_error(root->fs_info, ret, in write_all_supers()
3586 btrfs_err(root->fs_info, "%d errors while writing supers", in write_all_supers()
3588 mutex_unlock(&root->fs_info->fs_devices->device_list_mutex); in write_all_supers()
3591 btrfs_std_error(root->fs_info, -EIO, in write_all_supers()
3607 mutex_unlock(&root->fs_info->fs_devices->device_list_mutex); in write_all_supers()
3609 btrfs_std_error(root->fs_info, -EIO, in write_all_supers()
3617 struct btrfs_root *root, int max_mirrors) in write_ctree_super() argument
3619 return write_all_supers(root, max_mirrors); in write_ctree_super()
3624 struct btrfs_root *root) in btrfs_drop_and_free_fs_root() argument
3628 (unsigned long)root->root_key.objectid); in btrfs_drop_and_free_fs_root()
3631 if (btrfs_root_refs(&root->root_item) == 0) in btrfs_drop_and_free_fs_root()
3635 btrfs_free_log(NULL, root); in btrfs_drop_and_free_fs_root()
3637 if (root->free_ino_pinned) in btrfs_drop_and_free_fs_root()
3638 __btrfs_remove_free_space_cache(root->free_ino_pinned); in btrfs_drop_and_free_fs_root()
3639 if (root->free_ino_ctl) in btrfs_drop_and_free_fs_root()
3640 __btrfs_remove_free_space_cache(root->free_ino_ctl); in btrfs_drop_and_free_fs_root()
3641 free_fs_root(root); in btrfs_drop_and_free_fs_root()
3644 static void free_fs_root(struct btrfs_root *root) in free_fs_root() argument
3646 iput(root->ino_cache_inode); in free_fs_root()
3647 WARN_ON(!RB_EMPTY_ROOT(&root->inode_tree)); in free_fs_root()
3648 btrfs_free_block_rsv(root, root->orphan_block_rsv); in free_fs_root()
3649 root->orphan_block_rsv = NULL; in free_fs_root()
3650 if (root->anon_dev) in free_fs_root()
3651 free_anon_bdev(root->anon_dev); in free_fs_root()
3652 if (root->subv_writers) in free_fs_root()
3653 btrfs_free_subvolume_writers(root->subv_writers); in free_fs_root()
3654 free_extent_buffer(root->node); in free_fs_root()
3655 free_extent_buffer(root->commit_root); in free_fs_root()
3656 kfree(root->free_ino_ctl); in free_fs_root()
3657 kfree(root->free_ino_pinned); in free_fs_root()
3658 kfree(root->name); in free_fs_root()
3659 btrfs_put_fs_root(root); in free_fs_root()
3662 void btrfs_free_fs_root(struct btrfs_root *root) in btrfs_free_fs_root() argument
3664 free_fs_root(root); in btrfs_free_fs_root()
3718 int btrfs_commit_super(struct btrfs_root *root) in btrfs_commit_super() argument
3722 mutex_lock(&root->fs_info->cleaner_mutex); in btrfs_commit_super()
3723 btrfs_run_delayed_iputs(root); in btrfs_commit_super()
3724 mutex_unlock(&root->fs_info->cleaner_mutex); in btrfs_commit_super()
3725 wake_up_process(root->fs_info->cleaner_kthread); in btrfs_commit_super()
3728 down_write(&root->fs_info->cleanup_work_sem); in btrfs_commit_super()
3729 up_write(&root->fs_info->cleanup_work_sem); in btrfs_commit_super()
3731 trans = btrfs_join_transaction(root); in btrfs_commit_super()
3734 return btrfs_commit_transaction(trans, root); in btrfs_commit_super()
3737 void close_ctree(struct btrfs_root *root) in close_ctree() argument
3739 struct btrfs_fs_info *fs_info = root->fs_info; in close_ctree()
3775 btrfs_delete_unused_bgs(root->fs_info); in close_ctree()
3790 ret = btrfs_commit_super(root); in close_ctree()
3796 btrfs_error_commit_super(root); in close_ctree()
3833 if (btrfs_test_opt(root, CHECK_INTEGRITY)) in close_ctree()
3834 btrfsic_unmount(root, fs_info->fs_devices); in close_ctree()
3848 __btrfs_free_block_rsv(root->orphan_block_rsv); in close_ctree()
3849 root->orphan_block_rsv = NULL; in close_ctree()
3851 lock_chunks(root); in close_ctree()
3860 unlock_chunks(root); in close_ctree()
3887 struct btrfs_root *root; in btrfs_mark_buffer_dirty() local
3900 root = BTRFS_I(buf->pages[0]->mapping->host)->root; in btrfs_mark_buffer_dirty()
3902 if (transid != root->fs_info->generation) in btrfs_mark_buffer_dirty()
3905 buf->start, transid, root->fs_info->generation); in btrfs_mark_buffer_dirty()
3908 __percpu_counter_add(&root->fs_info->dirty_metadata_bytes, in btrfs_mark_buffer_dirty()
3910 root->fs_info->dirty_metadata_batch); in btrfs_mark_buffer_dirty()
3918 btrfs_check_leaf_relaxed(root, buf)) { in btrfs_mark_buffer_dirty()
3919 btrfs_print_leaf(root, buf); in btrfs_mark_buffer_dirty()
3925 static void __btrfs_btree_balance_dirty(struct btrfs_root *root, in __btrfs_btree_balance_dirty() argument
3938 btrfs_balance_delayed_items(root); in __btrfs_btree_balance_dirty()
3940 ret = __percpu_counter_compare(&root->fs_info->dirty_metadata_bytes, in __btrfs_btree_balance_dirty()
3942 root->fs_info->dirty_metadata_batch); in __btrfs_btree_balance_dirty()
3945 root->fs_info->btree_inode->i_mapping); in __btrfs_btree_balance_dirty()
3950 void btrfs_btree_balance_dirty(struct btrfs_root *root) in btrfs_btree_balance_dirty() argument
3952 __btrfs_btree_balance_dirty(root, 1); in btrfs_btree_balance_dirty()
3955 void btrfs_btree_balance_dirty_nodelay(struct btrfs_root *root) in btrfs_btree_balance_dirty_nodelay() argument
3957 __btrfs_btree_balance_dirty(root, 0); in btrfs_btree_balance_dirty_nodelay()
3962 struct btrfs_root *root = BTRFS_I(buf->pages[0]->mapping->host)->root; in btrfs_read_buffer() local
3963 return btree_read_extent_buffer_pages(root, buf, 0, parent_transid); in btrfs_read_buffer()
4077 static void btrfs_error_commit_super(struct btrfs_root *root) in btrfs_error_commit_super() argument
4079 mutex_lock(&root->fs_info->cleaner_mutex); in btrfs_error_commit_super()
4080 btrfs_run_delayed_iputs(root); in btrfs_error_commit_super()
4081 mutex_unlock(&root->fs_info->cleaner_mutex); in btrfs_error_commit_super()
4083 down_write(&root->fs_info->cleanup_work_sem); in btrfs_error_commit_super()
4084 up_write(&root->fs_info->cleanup_work_sem); in btrfs_error_commit_super()
4087 btrfs_cleanup_transaction(root); in btrfs_error_commit_super()
4090 static void btrfs_destroy_ordered_extents(struct btrfs_root *root) in btrfs_destroy_ordered_extents() argument
4094 spin_lock(&root->ordered_extent_lock); in btrfs_destroy_ordered_extents()
4099 list_for_each_entry(ordered, &root->ordered_extents, in btrfs_destroy_ordered_extents()
4102 spin_unlock(&root->ordered_extent_lock); in btrfs_destroy_ordered_extents()
4107 struct btrfs_root *root; in btrfs_destroy_all_ordered_extents() local
4115 root = list_first_entry(&splice, struct btrfs_root, in btrfs_destroy_all_ordered_extents()
4117 list_move_tail(&root->ordered_root, in btrfs_destroy_all_ordered_extents()
4121 btrfs_destroy_ordered_extents(root); in btrfs_destroy_all_ordered_extents()
4138 struct btrfs_root *root) in btrfs_destroy_delayed_refs() argument
4150 btrfs_info(root->fs_info, "delayed_refs has NO entry"); in btrfs_destroy_delayed_refs()
4193 btrfs_pin_extent(root, head->node.bytenr, in btrfs_destroy_delayed_refs()
4205 static void btrfs_destroy_delalloc_inodes(struct btrfs_root *root) in btrfs_destroy_delalloc_inodes() argument
4212 spin_lock(&root->delalloc_lock); in btrfs_destroy_delalloc_inodes()
4213 list_splice_init(&root->delalloc_inodes, &splice); in btrfs_destroy_delalloc_inodes()
4222 spin_unlock(&root->delalloc_lock); in btrfs_destroy_delalloc_inodes()
4224 btrfs_invalidate_inodes(btrfs_inode->root); in btrfs_destroy_delalloc_inodes()
4226 spin_lock(&root->delalloc_lock); in btrfs_destroy_delalloc_inodes()
4229 spin_unlock(&root->delalloc_lock); in btrfs_destroy_delalloc_inodes()
4234 struct btrfs_root *root; in btrfs_destroy_all_delalloc_inodes() local
4242 root = list_first_entry(&splice, struct btrfs_root, in btrfs_destroy_all_delalloc_inodes()
4244 list_del_init(&root->delalloc_root); in btrfs_destroy_all_delalloc_inodes()
4245 root = btrfs_grab_fs_root(root); in btrfs_destroy_all_delalloc_inodes()
4246 BUG_ON(!root); in btrfs_destroy_all_delalloc_inodes()
4249 btrfs_destroy_delalloc_inodes(root); in btrfs_destroy_all_delalloc_inodes()
4250 btrfs_put_fs_root(root); in btrfs_destroy_all_delalloc_inodes()
4257 static int btrfs_destroy_marked_extents(struct btrfs_root *root, in btrfs_destroy_marked_extents() argument
4274 eb = btrfs_find_tree_block(root->fs_info, start); in btrfs_destroy_marked_extents()
4275 start += root->nodesize; in btrfs_destroy_marked_extents()
4290 static int btrfs_destroy_pinned_extent(struct btrfs_root *root, in btrfs_destroy_pinned_extent() argument
4293 struct btrfs_fs_info *fs_info = root->fs_info; in btrfs_destroy_pinned_extent()
4318 btrfs_error_unpin_extent_range(root, start, end); in btrfs_destroy_pinned_extent()
4336 struct btrfs_root *root) in btrfs_cleanup_one_transaction() argument
4338 btrfs_destroy_delayed_refs(cur_trans, root); in btrfs_cleanup_one_transaction()
4341 wake_up(&root->fs_info->transaction_blocked_wait); in btrfs_cleanup_one_transaction()
4344 wake_up(&root->fs_info->transaction_wait); in btrfs_cleanup_one_transaction()
4346 btrfs_destroy_delayed_inodes(root); in btrfs_cleanup_one_transaction()
4347 btrfs_assert_delayed_root_empty(root); in btrfs_cleanup_one_transaction()
4349 btrfs_destroy_marked_extents(root, &cur_trans->dirty_pages, in btrfs_cleanup_one_transaction()
4351 btrfs_destroy_pinned_extent(root, in btrfs_cleanup_one_transaction()
4352 root->fs_info->pinned_extents); in btrfs_cleanup_one_transaction()
4363 static int btrfs_cleanup_transaction(struct btrfs_root *root) in btrfs_cleanup_transaction() argument
4367 mutex_lock(&root->fs_info->transaction_kthread_mutex); in btrfs_cleanup_transaction()
4369 spin_lock(&root->fs_info->trans_lock); in btrfs_cleanup_transaction()
4370 while (!list_empty(&root->fs_info->trans_list)) { in btrfs_cleanup_transaction()
4371 t = list_first_entry(&root->fs_info->trans_list, in btrfs_cleanup_transaction()
4375 spin_unlock(&root->fs_info->trans_lock); in btrfs_cleanup_transaction()
4376 btrfs_wait_for_commit(root, t->transid); in btrfs_cleanup_transaction()
4378 spin_lock(&root->fs_info->trans_lock); in btrfs_cleanup_transaction()
4381 if (t == root->fs_info->running_transaction) { in btrfs_cleanup_transaction()
4383 spin_unlock(&root->fs_info->trans_lock); in btrfs_cleanup_transaction()
4391 spin_unlock(&root->fs_info->trans_lock); in btrfs_cleanup_transaction()
4393 btrfs_cleanup_one_transaction(t, root); in btrfs_cleanup_transaction()
4395 spin_lock(&root->fs_info->trans_lock); in btrfs_cleanup_transaction()
4396 if (t == root->fs_info->running_transaction) in btrfs_cleanup_transaction()
4397 root->fs_info->running_transaction = NULL; in btrfs_cleanup_transaction()
4399 spin_unlock(&root->fs_info->trans_lock); in btrfs_cleanup_transaction()
4402 trace_btrfs_transaction_commit(root); in btrfs_cleanup_transaction()
4403 spin_lock(&root->fs_info->trans_lock); in btrfs_cleanup_transaction()
4405 spin_unlock(&root->fs_info->trans_lock); in btrfs_cleanup_transaction()
4406 btrfs_destroy_all_ordered_extents(root->fs_info); in btrfs_cleanup_transaction()
4407 btrfs_destroy_delayed_inodes(root); in btrfs_cleanup_transaction()
4408 btrfs_assert_delayed_root_empty(root); in btrfs_cleanup_transaction()
4409 btrfs_destroy_pinned_extent(root, root->fs_info->pinned_extents); in btrfs_cleanup_transaction()
4410 btrfs_destroy_all_delalloc_inodes(root->fs_info); in btrfs_cleanup_transaction()
4411 mutex_unlock(&root->fs_info->transaction_kthread_mutex); in btrfs_cleanup_transaction()