Lines Matching refs:fs_info

57 				      struct btrfs_fs_info *fs_info);
59 static int btrfs_destroy_marked_extents(struct btrfs_fs_info *fs_info,
62 static int btrfs_destroy_pinned_extent(struct btrfs_fs_info *fs_info,
64 static int btrfs_cleanup_transaction(struct btrfs_fs_info *fs_info);
65 static void btrfs_error_commit_super(struct btrfs_fs_info *fs_info);
209 struct btrfs_fs_info *fs_info = inode->root->fs_info; in btree_get_extent() local
217 em->bdev = fs_info->fs_devices->latest_bdev; in btree_get_extent()
232 em->bdev = fs_info->fs_devices->latest_bdev; in btree_get_extent()
265 static int csum_tree_block(struct btrfs_fs_info *fs_info, in csum_tree_block() argument
269 u16 csum_size = btrfs_super_csum_size(fs_info->super_copy); in csum_tree_block()
303 btrfs_warn_rl(fs_info, in csum_tree_block()
305 fs_info->sb->s_id, buf->start, in csum_tree_block()
348 btrfs_err_rl(eb->fs_info, in verify_parent_transid()
376 static int btrfs_check_super_csum(struct btrfs_fs_info *fs_info, in btrfs_check_super_csum() argument
402 btrfs_err(fs_info, "unsupported checksum algorithm %u", in btrfs_check_super_csum()
410 static int verify_level_key(struct btrfs_fs_info *fs_info, in verify_level_key() argument
422 btrfs_err(fs_info, in verify_level_key()
438 if (btrfs_header_generation(eb) > fs_info->last_trans_committed) in verify_level_key()
449 btrfs_err(fs_info, in verify_level_key()
468 static int btree_read_extent_buffer_pages(struct btrfs_fs_info *fs_info, in btree_read_extent_buffer_pages() argument
481 io_tree = &BTRFS_I(fs_info->btree_inode)->io_tree; in btree_read_extent_buffer_pages()
489 else if (verify_level_key(fs_info, eb, level, in btree_read_extent_buffer_pages()
505 num_copies = btrfs_num_copies(fs_info, in btree_read_extent_buffer_pages()
524 repair_eb_io_failure(fs_info, eb, failed_mirror); in btree_read_extent_buffer_pages()
534 static int csum_dirty_buffer(struct btrfs_fs_info *fs_info, struct page *page) in csum_dirty_buffer() argument
554 ASSERT(memcmp_extent_buffer(eb, fs_info->fsid, in csum_dirty_buffer()
557 return csum_tree_block(fs_info, eb, 0); in csum_dirty_buffer()
560 static int check_tree_block_fsid(struct btrfs_fs_info *fs_info, in check_tree_block_fsid() argument
563 struct btrfs_fs_devices *fs_devices = fs_info->fs_devices; in check_tree_block_fsid()
586 struct btrfs_fs_info *fs_info = root->fs_info; in btree_readpage_end_io_hook() local
612 btrfs_err_rl(fs_info, "bad tree block start, want %llu have %llu", in btree_readpage_end_io_hook()
617 if (check_tree_block_fsid(fs_info, eb)) { in btree_readpage_end_io_hook()
618 btrfs_err_rl(fs_info, "bad fsid on block %llu", in btree_readpage_end_io_hook()
625 btrfs_err(fs_info, "bad tree block level %d on %llu", in btree_readpage_end_io_hook()
634 ret = csum_tree_block(fs_info, eb, 1); in btree_readpage_end_io_hook()
643 if (found_level == 0 && btrfs_check_leaf_full(fs_info, eb)) { in btree_readpage_end_io_hook()
648 if (found_level > 0 && btrfs_check_node(fs_info, eb)) in btree_readpage_end_io_hook()
688 struct btrfs_fs_info *fs_info; in end_workqueue_bio() local
692 fs_info = end_io_wq->info; in end_workqueue_bio()
697 wq = fs_info->endio_meta_write_workers; in end_workqueue_bio()
700 wq = fs_info->endio_freespace_worker; in end_workqueue_bio()
703 wq = fs_info->endio_raid56_workers; in end_workqueue_bio()
706 wq = fs_info->endio_write_workers; in end_workqueue_bio()
712 wq = fs_info->endio_repair_workers; in end_workqueue_bio()
715 wq = fs_info->endio_raid56_workers; in end_workqueue_bio()
718 wq = fs_info->endio_meta_workers; in end_workqueue_bio()
721 wq = fs_info->endio_workers; in end_workqueue_bio()
787 blk_status_t btrfs_wq_submit_bio(struct btrfs_fs_info *fs_info, struct bio *bio, in btrfs_wq_submit_bio() argument
813 btrfs_queue_work(fs_info->workers, &async->work); in btrfs_wq_submit_bio()
826 ret = csum_dirty_buffer(root->fs_info, bvec->bv_page); in btree_csum_one_bio()
860 struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); in btree_submit_bio_hook() local
869 ret = btrfs_bio_wq_end_io(fs_info, bio, in btree_submit_bio_hook()
873 ret = btrfs_map_bio(fs_info, bio, mirror_num, 0); in btree_submit_bio_hook()
878 ret = btrfs_map_bio(fs_info, bio, mirror_num, 0); in btree_submit_bio_hook()
884 ret = btrfs_wq_submit_bio(fs_info, bio, mirror_num, 0, in btree_submit_bio_hook()
925 struct btrfs_fs_info *fs_info; in btree_writepages() local
933 fs_info = BTRFS_I(mapping->host)->root->fs_info; in btree_writepages()
935 ret = __percpu_counter_compare(&fs_info->dirty_metadata_bytes, in btree_writepages()
937 fs_info->dirty_metadata_batch); in btree_writepages()
967 btrfs_warn(BTRFS_I(page->mapping->host)->root->fs_info, in btree_invalidatepage()
1002 void readahead_tree_block(struct btrfs_fs_info *fs_info, u64 bytenr) in readahead_tree_block() argument
1005 struct inode *btree_inode = fs_info->btree_inode; in readahead_tree_block()
1007 buf = btrfs_find_create_tree_block(fs_info, bytenr); in readahead_tree_block()
1015 int reada_tree_block_flagged(struct btrfs_fs_info *fs_info, u64 bytenr, in reada_tree_block_flagged() argument
1019 struct inode *btree_inode = fs_info->btree_inode; in reada_tree_block_flagged()
1023 buf = btrfs_find_create_tree_block(fs_info, bytenr); in reada_tree_block_flagged()
1048 struct btrfs_fs_info *fs_info, in btrfs_find_create_tree_block() argument
1051 if (btrfs_is_testing(fs_info)) in btrfs_find_create_tree_block()
1052 return alloc_test_extent_buffer(fs_info, bytenr); in btrfs_find_create_tree_block()
1053 return alloc_extent_buffer(fs_info, bytenr); in btrfs_find_create_tree_block()
1077 struct extent_buffer *read_tree_block(struct btrfs_fs_info *fs_info, u64 bytenr, in read_tree_block() argument
1084 buf = btrfs_find_create_tree_block(fs_info, bytenr); in read_tree_block()
1088 ret = btree_read_extent_buffer_pages(fs_info, buf, parent_transid, in read_tree_block()
1098 void clean_tree_block(struct btrfs_fs_info *fs_info, in clean_tree_block() argument
1102 fs_info->running_transaction->transid) { in clean_tree_block()
1106 percpu_counter_add_batch(&fs_info->dirty_metadata_bytes, in clean_tree_block()
1108 fs_info->dirty_metadata_batch); in clean_tree_block()
1142 static void __setup_root(struct btrfs_root *root, struct btrfs_fs_info *fs_info, in __setup_root() argument
1145 bool dummy = test_bit(BTRFS_FS_STATE_DUMMY_FS_INFO, &fs_info->fs_state); in __setup_root()
1201 root->defrag_trans_start = fs_info->generation; in __setup_root()
1210 static struct btrfs_root *btrfs_alloc_root(struct btrfs_fs_info *fs_info, in btrfs_alloc_root() argument
1215 root->fs_info = fs_info; in btrfs_alloc_root()
1221 struct btrfs_root *btrfs_alloc_dummy_root(struct btrfs_fs_info *fs_info) in btrfs_alloc_dummy_root() argument
1225 if (!fs_info) in btrfs_alloc_dummy_root()
1228 root = btrfs_alloc_root(fs_info, GFP_KERNEL); in btrfs_alloc_dummy_root()
1233 __setup_root(root, fs_info, BTRFS_ROOT_TREE_OBJECTID); in btrfs_alloc_dummy_root()
1241 struct btrfs_fs_info *fs_info, in btrfs_create_tree() argument
1245 struct btrfs_root *tree_root = fs_info->tree_root; in btrfs_create_tree()
1251 root = btrfs_alloc_root(fs_info, GFP_KERNEL); in btrfs_create_tree()
1255 __setup_root(root, fs_info, objectid); in btrfs_create_tree()
1310 struct btrfs_fs_info *fs_info) in alloc_log_tree() argument
1315 root = btrfs_alloc_root(fs_info, GFP_NOFS); in alloc_log_tree()
1319 __setup_root(root, fs_info, BTRFS_TREE_LOG_OBJECTID); in alloc_log_tree()
1349 struct btrfs_fs_info *fs_info) in btrfs_init_log_root_tree() argument
1353 log_root = alloc_log_tree(trans, fs_info); in btrfs_init_log_root_tree()
1356 WARN_ON(fs_info->log_root_tree); in btrfs_init_log_root_tree()
1357 fs_info->log_root_tree = log_root; in btrfs_init_log_root_tree()
1364 struct btrfs_fs_info *fs_info = root->fs_info; in btrfs_add_log_tree() local
1368 log_root = alloc_log_tree(trans, fs_info); in btrfs_add_log_tree()
1380 fs_info->nodesize); in btrfs_add_log_tree()
1397 struct btrfs_fs_info *fs_info = tree_root->fs_info; in btrfs_read_tree_root() local
1407 root = btrfs_alloc_root(fs_info, GFP_NOFS); in btrfs_read_tree_root()
1413 __setup_root(root, fs_info, key->objectid); in btrfs_read_tree_root()
1425 root->node = read_tree_block(fs_info, in btrfs_read_tree_root()
1511 struct btrfs_root *btrfs_lookup_fs_root(struct btrfs_fs_info *fs_info, in btrfs_lookup_fs_root() argument
1516 spin_lock(&fs_info->fs_roots_radix_lock); in btrfs_lookup_fs_root()
1517 root = radix_tree_lookup(&fs_info->fs_roots_radix, in btrfs_lookup_fs_root()
1519 spin_unlock(&fs_info->fs_roots_radix_lock); in btrfs_lookup_fs_root()
1523 int btrfs_insert_fs_root(struct btrfs_fs_info *fs_info, in btrfs_insert_fs_root() argument
1532 spin_lock(&fs_info->fs_roots_radix_lock); in btrfs_insert_fs_root()
1533 ret = radix_tree_insert(&fs_info->fs_roots_radix, in btrfs_insert_fs_root()
1538 spin_unlock(&fs_info->fs_roots_radix_lock); in btrfs_insert_fs_root()
1544 struct btrfs_root *btrfs_get_fs_root(struct btrfs_fs_info *fs_info, in btrfs_get_fs_root() argument
1554 return fs_info->tree_root; in btrfs_get_fs_root()
1556 return fs_info->extent_root; in btrfs_get_fs_root()
1558 return fs_info->chunk_root; in btrfs_get_fs_root()
1560 return fs_info->dev_root; in btrfs_get_fs_root()
1562 return fs_info->csum_root; in btrfs_get_fs_root()
1564 return fs_info->quota_root ? fs_info->quota_root : in btrfs_get_fs_root()
1567 return fs_info->uuid_root ? fs_info->uuid_root : in btrfs_get_fs_root()
1570 return fs_info->free_space_root ? fs_info->free_space_root : in btrfs_get_fs_root()
1573 root = btrfs_lookup_fs_root(fs_info, location->objectid); in btrfs_get_fs_root()
1580 root = btrfs_read_fs_root(fs_info->tree_root, location); in btrfs_get_fs_root()
1602 ret = btrfs_search_slot(NULL, fs_info->tree_root, &key, path, 0, 0); in btrfs_get_fs_root()
1609 ret = btrfs_insert_fs_root(fs_info, root); in btrfs_get_fs_root()
1666 struct btrfs_fs_info *fs_info = root->fs_info; in cleaner_kthread() local
1674 if (btrfs_need_cleaner_sleep(fs_info)) in cleaner_kthread()
1681 if (!test_bit(BTRFS_FS_OPEN, &fs_info->flags)) in cleaner_kthread()
1684 if (!mutex_trylock(&fs_info->cleaner_mutex)) in cleaner_kthread()
1691 if (btrfs_need_cleaner_sleep(fs_info)) { in cleaner_kthread()
1692 mutex_unlock(&fs_info->cleaner_mutex); in cleaner_kthread()
1696 mutex_lock(&fs_info->cleaner_delayed_iput_mutex); in cleaner_kthread()
1697 btrfs_run_delayed_iputs(fs_info); in cleaner_kthread()
1698 mutex_unlock(&fs_info->cleaner_delayed_iput_mutex); in cleaner_kthread()
1701 mutex_unlock(&fs_info->cleaner_mutex); in cleaner_kthread()
1707 btrfs_run_defrag_inodes(fs_info); in cleaner_kthread()
1717 btrfs_delete_unused_bgs(fs_info); in cleaner_kthread()
1741 btrfs_err(fs_info, in cleaner_kthread()
1749 btrfs_err(fs_info, in cleaner_kthread()
1760 struct btrfs_fs_info *fs_info = root->fs_info; in transaction_kthread() local
1770 delay = HZ * fs_info->commit_interval; in transaction_kthread()
1771 mutex_lock(&fs_info->transaction_kthread_mutex); in transaction_kthread()
1773 spin_lock(&fs_info->trans_lock); in transaction_kthread()
1774 cur = fs_info->running_transaction; in transaction_kthread()
1776 spin_unlock(&fs_info->trans_lock); in transaction_kthread()
1782 !test_bit(BTRFS_FS_NEED_ASYNC_COMMIT, &fs_info->flags) && in transaction_kthread()
1784 now - cur->start_time < fs_info->commit_interval)) { in transaction_kthread()
1785 spin_unlock(&fs_info->trans_lock); in transaction_kthread()
1790 spin_unlock(&fs_info->trans_lock); in transaction_kthread()
1805 wake_up_process(fs_info->cleaner_kthread); in transaction_kthread()
1806 mutex_unlock(&fs_info->transaction_kthread_mutex); in transaction_kthread()
1809 &fs_info->fs_state))) in transaction_kthread()
1810 btrfs_cleanup_transaction(fs_info); in transaction_kthread()
1812 (!btrfs_transaction_blocked(fs_info) || in transaction_kthread()
2019 static void btrfs_stop_all_workers(struct btrfs_fs_info *fs_info) in btrfs_stop_all_workers() argument
2021 btrfs_destroy_workqueue(fs_info->fixup_workers); in btrfs_stop_all_workers()
2022 btrfs_destroy_workqueue(fs_info->delalloc_workers); in btrfs_stop_all_workers()
2023 btrfs_destroy_workqueue(fs_info->workers); in btrfs_stop_all_workers()
2024 btrfs_destroy_workqueue(fs_info->endio_workers); in btrfs_stop_all_workers()
2025 btrfs_destroy_workqueue(fs_info->endio_raid56_workers); in btrfs_stop_all_workers()
2026 btrfs_destroy_workqueue(fs_info->endio_repair_workers); in btrfs_stop_all_workers()
2027 btrfs_destroy_workqueue(fs_info->rmw_workers); in btrfs_stop_all_workers()
2028 btrfs_destroy_workqueue(fs_info->endio_write_workers); in btrfs_stop_all_workers()
2029 btrfs_destroy_workqueue(fs_info->endio_freespace_worker); in btrfs_stop_all_workers()
2030 btrfs_destroy_workqueue(fs_info->submit_workers); in btrfs_stop_all_workers()
2031 btrfs_destroy_workqueue(fs_info->delayed_workers); in btrfs_stop_all_workers()
2032 btrfs_destroy_workqueue(fs_info->caching_workers); in btrfs_stop_all_workers()
2033 btrfs_destroy_workqueue(fs_info->readahead_workers); in btrfs_stop_all_workers()
2034 btrfs_destroy_workqueue(fs_info->flush_workers); in btrfs_stop_all_workers()
2035 btrfs_destroy_workqueue(fs_info->qgroup_rescan_workers); in btrfs_stop_all_workers()
2036 btrfs_destroy_workqueue(fs_info->extent_workers); in btrfs_stop_all_workers()
2042 btrfs_destroy_workqueue(fs_info->endio_meta_workers); in btrfs_stop_all_workers()
2043 btrfs_destroy_workqueue(fs_info->endio_meta_write_workers); in btrfs_stop_all_workers()
2071 void btrfs_free_fs_roots(struct btrfs_fs_info *fs_info) in btrfs_free_fs_roots() argument
2077 while (!list_empty(&fs_info->dead_roots)) { in btrfs_free_fs_roots()
2078 gang[0] = list_entry(fs_info->dead_roots.next, in btrfs_free_fs_roots()
2083 btrfs_drop_and_free_fs_root(fs_info, gang[0]); in btrfs_free_fs_roots()
2092 ret = radix_tree_gang_lookup(&fs_info->fs_roots_radix, in btrfs_free_fs_roots()
2098 btrfs_drop_and_free_fs_root(fs_info, gang[i]); in btrfs_free_fs_roots()
2101 if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) { in btrfs_free_fs_roots()
2102 btrfs_free_log_root_tree(NULL, fs_info); in btrfs_free_fs_roots()
2103 btrfs_destroy_pinned_extent(fs_info, fs_info->pinned_extents); in btrfs_free_fs_roots()
2107 static void btrfs_init_scrub(struct btrfs_fs_info *fs_info) in btrfs_init_scrub() argument
2109 mutex_init(&fs_info->scrub_lock); in btrfs_init_scrub()
2110 atomic_set(&fs_info->scrubs_running, 0); in btrfs_init_scrub()
2111 atomic_set(&fs_info->scrub_pause_req, 0); in btrfs_init_scrub()
2112 atomic_set(&fs_info->scrubs_paused, 0); in btrfs_init_scrub()
2113 atomic_set(&fs_info->scrub_cancel_req, 0); in btrfs_init_scrub()
2114 init_waitqueue_head(&fs_info->scrub_pause_wait); in btrfs_init_scrub()
2115 fs_info->scrub_workers_refcnt = 0; in btrfs_init_scrub()
2118 static void btrfs_init_balance(struct btrfs_fs_info *fs_info) in btrfs_init_balance() argument
2120 spin_lock_init(&fs_info->balance_lock); in btrfs_init_balance()
2121 mutex_init(&fs_info->balance_mutex); in btrfs_init_balance()
2122 atomic_set(&fs_info->balance_pause_req, 0); in btrfs_init_balance()
2123 atomic_set(&fs_info->balance_cancel_req, 0); in btrfs_init_balance()
2124 fs_info->balance_ctl = NULL; in btrfs_init_balance()
2125 init_waitqueue_head(&fs_info->balance_wait_q); in btrfs_init_balance()
2128 static void btrfs_init_btree_inode(struct btrfs_fs_info *fs_info) in btrfs_init_btree_inode() argument
2130 struct inode *inode = fs_info->btree_inode; in btrfs_init_btree_inode()
2149 BTRFS_I(inode)->root = fs_info->tree_root; in btrfs_init_btree_inode()
2155 static void btrfs_init_dev_replace_locks(struct btrfs_fs_info *fs_info) in btrfs_init_dev_replace_locks() argument
2157 mutex_init(&fs_info->dev_replace.lock_finishing_cancel_unmount); in btrfs_init_dev_replace_locks()
2158 rwlock_init(&fs_info->dev_replace.lock); in btrfs_init_dev_replace_locks()
2159 atomic_set(&fs_info->dev_replace.read_locks, 0); in btrfs_init_dev_replace_locks()
2160 atomic_set(&fs_info->dev_replace.blocking_readers, 0); in btrfs_init_dev_replace_locks()
2161 init_waitqueue_head(&fs_info->replace_wait); in btrfs_init_dev_replace_locks()
2162 init_waitqueue_head(&fs_info->dev_replace.read_lock_wq); in btrfs_init_dev_replace_locks()
2165 static void btrfs_init_qgroup(struct btrfs_fs_info *fs_info) in btrfs_init_qgroup() argument
2167 spin_lock_init(&fs_info->qgroup_lock); in btrfs_init_qgroup()
2168 mutex_init(&fs_info->qgroup_ioctl_lock); in btrfs_init_qgroup()
2169 fs_info->qgroup_tree = RB_ROOT; in btrfs_init_qgroup()
2170 fs_info->qgroup_op_tree = RB_ROOT; in btrfs_init_qgroup()
2171 INIT_LIST_HEAD(&fs_info->dirty_qgroups); in btrfs_init_qgroup()
2172 fs_info->qgroup_seq = 1; in btrfs_init_qgroup()
2173 fs_info->qgroup_ulist = NULL; in btrfs_init_qgroup()
2174 fs_info->qgroup_rescan_running = false; in btrfs_init_qgroup()
2175 mutex_init(&fs_info->qgroup_rescan_lock); in btrfs_init_qgroup()
2178 static int btrfs_init_workqueues(struct btrfs_fs_info *fs_info, in btrfs_init_workqueues() argument
2181 u32 max_active = fs_info->thread_pool_size; in btrfs_init_workqueues()
2184 fs_info->workers = in btrfs_init_workqueues()
2185 btrfs_alloc_workqueue(fs_info, "worker", in btrfs_init_workqueues()
2188 fs_info->delalloc_workers = in btrfs_init_workqueues()
2189 btrfs_alloc_workqueue(fs_info, "delalloc", in btrfs_init_workqueues()
2192 fs_info->flush_workers = in btrfs_init_workqueues()
2193 btrfs_alloc_workqueue(fs_info, "flush_delalloc", in btrfs_init_workqueues()
2196 fs_info->caching_workers = in btrfs_init_workqueues()
2197 btrfs_alloc_workqueue(fs_info, "cache", flags, max_active, 0); in btrfs_init_workqueues()
2204 fs_info->submit_workers = in btrfs_init_workqueues()
2205 btrfs_alloc_workqueue(fs_info, "submit", flags, in btrfs_init_workqueues()
2209 fs_info->fixup_workers = in btrfs_init_workqueues()
2210 btrfs_alloc_workqueue(fs_info, "fixup", flags, 1, 0); in btrfs_init_workqueues()
2216 fs_info->endio_workers = in btrfs_init_workqueues()
2217 btrfs_alloc_workqueue(fs_info, "endio", flags, max_active, 4); in btrfs_init_workqueues()
2218 fs_info->endio_meta_workers = in btrfs_init_workqueues()
2219 btrfs_alloc_workqueue(fs_info, "endio-meta", flags, in btrfs_init_workqueues()
2221 fs_info->endio_meta_write_workers = in btrfs_init_workqueues()
2222 btrfs_alloc_workqueue(fs_info, "endio-meta-write", flags, in btrfs_init_workqueues()
2224 fs_info->endio_raid56_workers = in btrfs_init_workqueues()
2225 btrfs_alloc_workqueue(fs_info, "endio-raid56", flags, in btrfs_init_workqueues()
2227 fs_info->endio_repair_workers = in btrfs_init_workqueues()
2228 btrfs_alloc_workqueue(fs_info, "endio-repair", flags, 1, 0); in btrfs_init_workqueues()
2229 fs_info->rmw_workers = in btrfs_init_workqueues()
2230 btrfs_alloc_workqueue(fs_info, "rmw", flags, max_active, 2); in btrfs_init_workqueues()
2231 fs_info->endio_write_workers = in btrfs_init_workqueues()
2232 btrfs_alloc_workqueue(fs_info, "endio-write", flags, in btrfs_init_workqueues()
2234 fs_info->endio_freespace_worker = in btrfs_init_workqueues()
2235 btrfs_alloc_workqueue(fs_info, "freespace-write", flags, in btrfs_init_workqueues()
2237 fs_info->delayed_workers = in btrfs_init_workqueues()
2238 btrfs_alloc_workqueue(fs_info, "delayed-meta", flags, in btrfs_init_workqueues()
2240 fs_info->readahead_workers = in btrfs_init_workqueues()
2241 btrfs_alloc_workqueue(fs_info, "readahead", flags, in btrfs_init_workqueues()
2243 fs_info->qgroup_rescan_workers = in btrfs_init_workqueues()
2244 btrfs_alloc_workqueue(fs_info, "qgroup-rescan", flags, 1, 0); in btrfs_init_workqueues()
2245 fs_info->extent_workers = in btrfs_init_workqueues()
2246 btrfs_alloc_workqueue(fs_info, "extent-refs", flags, in btrfs_init_workqueues()
2250 if (!(fs_info->workers && fs_info->delalloc_workers && in btrfs_init_workqueues()
2251 fs_info->submit_workers && fs_info->flush_workers && in btrfs_init_workqueues()
2252 fs_info->endio_workers && fs_info->endio_meta_workers && in btrfs_init_workqueues()
2253 fs_info->endio_meta_write_workers && in btrfs_init_workqueues()
2254 fs_info->endio_repair_workers && in btrfs_init_workqueues()
2255 fs_info->endio_write_workers && fs_info->endio_raid56_workers && in btrfs_init_workqueues()
2256 fs_info->endio_freespace_worker && fs_info->rmw_workers && in btrfs_init_workqueues()
2257 fs_info->caching_workers && fs_info->readahead_workers && in btrfs_init_workqueues()
2258 fs_info->fixup_workers && fs_info->delayed_workers && in btrfs_init_workqueues()
2259 fs_info->extent_workers && in btrfs_init_workqueues()
2260 fs_info->qgroup_rescan_workers)) { in btrfs_init_workqueues()
2267 static int btrfs_replay_log(struct btrfs_fs_info *fs_info, in btrfs_replay_log() argument
2272 struct btrfs_super_block *disk_super = fs_info->super_copy; in btrfs_replay_log()
2277 btrfs_warn(fs_info, "log replay required on RO media"); in btrfs_replay_log()
2281 log_tree_root = btrfs_alloc_root(fs_info, GFP_KERNEL); in btrfs_replay_log()
2285 __setup_root(log_tree_root, fs_info, BTRFS_TREE_LOG_OBJECTID); in btrfs_replay_log()
2287 log_tree_root->node = read_tree_block(fs_info, bytenr, in btrfs_replay_log()
2288 fs_info->generation + 1, in btrfs_replay_log()
2291 btrfs_warn(fs_info, "failed to read log tree"); in btrfs_replay_log()
2296 btrfs_err(fs_info, "failed to read log tree"); in btrfs_replay_log()
2304 btrfs_handle_fs_error(fs_info, ret, in btrfs_replay_log()
2311 if (sb_rdonly(fs_info->sb)) { in btrfs_replay_log()
2312 ret = btrfs_commit_super(fs_info); in btrfs_replay_log()
2320 static int btrfs_read_roots(struct btrfs_fs_info *fs_info) in btrfs_read_roots() argument
2322 struct btrfs_root *tree_root = fs_info->tree_root; in btrfs_read_roots()
2327 BUG_ON(!fs_info->tree_root); in btrfs_read_roots()
2339 fs_info->extent_root = root; in btrfs_read_roots()
2348 fs_info->dev_root = root; in btrfs_read_roots()
2349 btrfs_init_devices_late(fs_info); in btrfs_read_roots()
2358 fs_info->csum_root = root; in btrfs_read_roots()
2364 set_bit(BTRFS_FS_QUOTA_ENABLED, &fs_info->flags); in btrfs_read_roots()
2365 fs_info->quota_root = root; in btrfs_read_roots()
2376 fs_info->uuid_root = root; in btrfs_read_roots()
2379 if (btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE)) { in btrfs_read_roots()
2387 fs_info->free_space_root = root; in btrfs_read_roots()
2392 btrfs_warn(fs_info, "failed to read root (objectid=%llu): %d", in btrfs_read_roots()
2407 static int validate_super(struct btrfs_fs_info *fs_info, in validate_super() argument
2415 btrfs_err(fs_info, "no valid FS found"); in validate_super()
2419 btrfs_err(fs_info, "unrecognized or unsupported super flag: %llu", in validate_super()
2424 btrfs_err(fs_info, "tree_root level too big: %d >= %d", in validate_super()
2429 btrfs_err(fs_info, "chunk_root level too big: %d >= %d", in validate_super()
2434 btrfs_err(fs_info, "log_root level too big: %d >= %d", in validate_super()
2445 btrfs_err(fs_info, "invalid sectorsize %llu", sectorsize); in validate_super()
2450 btrfs_err(fs_info, in validate_super()
2457 btrfs_err(fs_info, "invalid nodesize %llu", nodesize); in validate_super()
2461 btrfs_err(fs_info, "invalid leafsize %u, should be %llu", in validate_super()
2468 btrfs_warn(fs_info, "tree_root block unaligned: %llu", in validate_super()
2473 btrfs_warn(fs_info, "chunk_root block unaligned: %llu", in validate_super()
2478 btrfs_warn(fs_info, "log_root block unaligned: %llu", in validate_super()
2483 if (memcmp(fs_info->fsid, sb->dev_item.fsid, BTRFS_FSID_SIZE) != 0) { in validate_super()
2484 btrfs_err(fs_info, in validate_super()
2486 fs_info->fsid, sb->dev_item.fsid); in validate_super()
2495 btrfs_err(fs_info, "bytes_used is too small %llu", in validate_super()
2500 btrfs_err(fs_info, "invalid stripesize %u", in validate_super()
2505 btrfs_warn(fs_info, "suspicious number of devices: %llu", in validate_super()
2508 btrfs_err(fs_info, "number of devices is 0"); in validate_super()
2514 btrfs_err(fs_info, "super offset mismatch %llu != %u", in validate_super()
2524 btrfs_err(fs_info, "system chunk array too big %u > %u", in validate_super()
2531 btrfs_err(fs_info, "system chunk array too small %u < %zu", in validate_super()
2543 btrfs_warn(fs_info, in validate_super()
2549 btrfs_warn(fs_info, in validate_super()
2562 static int btrfs_validate_mount_super(struct btrfs_fs_info *fs_info) in btrfs_validate_mount_super() argument
2564 return validate_super(fs_info, fs_info->super_copy, 0); in btrfs_validate_mount_super()
2573 static int btrfs_validate_write_super(struct btrfs_fs_info *fs_info, in btrfs_validate_write_super() argument
2578 ret = validate_super(fs_info, sb, -1); in btrfs_validate_write_super()
2583 btrfs_err(fs_info, "invalid csum type, has %u want %u", in btrfs_validate_write_super()
2589 btrfs_err(fs_info, in btrfs_validate_write_super()
2597 btrfs_err(fs_info, in btrfs_validate_write_super()
2614 struct btrfs_fs_info *fs_info = btrfs_sb(sb); in open_ctree() local
2624 tree_root = fs_info->tree_root = btrfs_alloc_root(fs_info, GFP_KERNEL); in open_ctree()
2625 chunk_root = fs_info->chunk_root = btrfs_alloc_root(fs_info, GFP_KERNEL); in open_ctree()
2631 ret = init_srcu_struct(&fs_info->subvol_srcu); in open_ctree()
2637 ret = percpu_counter_init(&fs_info->dirty_metadata_bytes, 0, GFP_KERNEL); in open_ctree()
2642 fs_info->dirty_metadata_batch = PAGE_SIZE * in open_ctree()
2645 ret = percpu_counter_init(&fs_info->delalloc_bytes, 0, GFP_KERNEL); in open_ctree()
2651 ret = percpu_counter_init(&fs_info->bio_counter, 0, GFP_KERNEL); in open_ctree()
2657 INIT_RADIX_TREE(&fs_info->fs_roots_radix, GFP_ATOMIC); in open_ctree()
2658 INIT_RADIX_TREE(&fs_info->buffer_radix, GFP_ATOMIC); in open_ctree()
2659 INIT_LIST_HEAD(&fs_info->trans_list); in open_ctree()
2660 INIT_LIST_HEAD(&fs_info->dead_roots); in open_ctree()
2661 INIT_LIST_HEAD(&fs_info->delayed_iputs); in open_ctree()
2662 INIT_LIST_HEAD(&fs_info->delalloc_roots); in open_ctree()
2663 INIT_LIST_HEAD(&fs_info->caching_block_groups); in open_ctree()
2664 INIT_LIST_HEAD(&fs_info->pending_raid_kobjs); in open_ctree()
2665 spin_lock_init(&fs_info->pending_raid_kobjs_lock); in open_ctree()
2666 spin_lock_init(&fs_info->delalloc_root_lock); in open_ctree()
2667 spin_lock_init(&fs_info->trans_lock); in open_ctree()
2668 spin_lock_init(&fs_info->fs_roots_radix_lock); in open_ctree()
2669 spin_lock_init(&fs_info->delayed_iput_lock); in open_ctree()
2670 spin_lock_init(&fs_info->defrag_inodes_lock); in open_ctree()
2671 spin_lock_init(&fs_info->tree_mod_seq_lock); in open_ctree()
2672 spin_lock_init(&fs_info->super_lock); in open_ctree()
2673 spin_lock_init(&fs_info->qgroup_op_lock); in open_ctree()
2674 spin_lock_init(&fs_info->buffer_lock); in open_ctree()
2675 spin_lock_init(&fs_info->unused_bgs_lock); in open_ctree()
2676 rwlock_init(&fs_info->tree_mod_log_lock); in open_ctree()
2677 mutex_init(&fs_info->unused_bg_unpin_mutex); in open_ctree()
2678 mutex_init(&fs_info->delete_unused_bgs_mutex); in open_ctree()
2679 mutex_init(&fs_info->reloc_mutex); in open_ctree()
2680 mutex_init(&fs_info->delalloc_root_mutex); in open_ctree()
2681 mutex_init(&fs_info->cleaner_delayed_iput_mutex); in open_ctree()
2682 seqlock_init(&fs_info->profiles_lock); in open_ctree()
2684 INIT_LIST_HEAD(&fs_info->dirty_cowonly_roots); in open_ctree()
2685 INIT_LIST_HEAD(&fs_info->space_info); in open_ctree()
2686 INIT_LIST_HEAD(&fs_info->tree_mod_seq_list); in open_ctree()
2687 INIT_LIST_HEAD(&fs_info->unused_bgs); in open_ctree()
2688 btrfs_mapping_init(&fs_info->mapping_tree); in open_ctree()
2689 btrfs_init_block_rsv(&fs_info->global_block_rsv, in open_ctree()
2691 btrfs_init_block_rsv(&fs_info->trans_block_rsv, BTRFS_BLOCK_RSV_TRANS); in open_ctree()
2692 btrfs_init_block_rsv(&fs_info->chunk_block_rsv, BTRFS_BLOCK_RSV_CHUNK); in open_ctree()
2693 btrfs_init_block_rsv(&fs_info->empty_block_rsv, BTRFS_BLOCK_RSV_EMPTY); in open_ctree()
2694 btrfs_init_block_rsv(&fs_info->delayed_block_rsv, in open_ctree()
2696 atomic_set(&fs_info->async_delalloc_pages, 0); in open_ctree()
2697 atomic_set(&fs_info->defrag_running, 0); in open_ctree()
2698 atomic_set(&fs_info->qgroup_op_seq, 0); in open_ctree()
2699 atomic_set(&fs_info->reada_works_cnt, 0); in open_ctree()
2700 atomic64_set(&fs_info->tree_mod_seq, 0); in open_ctree()
2701 fs_info->sb = sb; in open_ctree()
2702 fs_info->max_inline = BTRFS_DEFAULT_MAX_INLINE; in open_ctree()
2703 fs_info->metadata_ratio = 0; in open_ctree()
2704 fs_info->defrag_inodes = RB_ROOT; in open_ctree()
2705 atomic64_set(&fs_info->free_chunk_space, 0); in open_ctree()
2706 fs_info->tree_mod_log = RB_ROOT; in open_ctree()
2707 fs_info->commit_interval = BTRFS_DEFAULT_COMMIT_INTERVAL; in open_ctree()
2708 fs_info->avg_delayed_ref_runtime = NSEC_PER_SEC >> 6; /* div by 64 */ in open_ctree()
2710 INIT_RADIX_TREE(&fs_info->reada_tree, GFP_NOFS & ~__GFP_DIRECT_RECLAIM); in open_ctree()
2711 spin_lock_init(&fs_info->reada_lock); in open_ctree()
2712 btrfs_init_ref_verify(fs_info); in open_ctree()
2714 fs_info->thread_pool_size = min_t(unsigned long, in open_ctree()
2717 INIT_LIST_HEAD(&fs_info->ordered_roots); in open_ctree()
2718 spin_lock_init(&fs_info->ordered_root_lock); in open_ctree()
2720 fs_info->btree_inode = new_inode(sb); in open_ctree()
2721 if (!fs_info->btree_inode) { in open_ctree()
2725 mapping_set_gfp_mask(fs_info->btree_inode->i_mapping, GFP_NOFS); in open_ctree()
2727 fs_info->delayed_root = kmalloc(sizeof(struct btrfs_delayed_root), in open_ctree()
2729 if (!fs_info->delayed_root) { in open_ctree()
2733 btrfs_init_delayed_root(fs_info->delayed_root); in open_ctree()
2735 btrfs_init_scrub(fs_info); in open_ctree()
2737 fs_info->check_integrity_print_mask = 0; in open_ctree()
2739 btrfs_init_balance(fs_info); in open_ctree()
2740 btrfs_init_async_reclaim_work(&fs_info->async_reclaim_work); in open_ctree()
2745 btrfs_init_btree_inode(fs_info); in open_ctree()
2747 spin_lock_init(&fs_info->block_group_cache_lock); in open_ctree()
2748 fs_info->block_group_cache_tree = RB_ROOT; in open_ctree()
2749 fs_info->first_logical_byte = (u64)-1; in open_ctree()
2751 extent_io_tree_init(&fs_info->freed_extents[0], NULL); in open_ctree()
2752 extent_io_tree_init(&fs_info->freed_extents[1], NULL); in open_ctree()
2753 fs_info->pinned_extents = &fs_info->freed_extents[0]; in open_ctree()
2754 set_bit(BTRFS_FS_BARRIER, &fs_info->flags); in open_ctree()
2756 mutex_init(&fs_info->ordered_operations_mutex); in open_ctree()
2757 mutex_init(&fs_info->tree_log_mutex); in open_ctree()
2758 mutex_init(&fs_info->chunk_mutex); in open_ctree()
2759 mutex_init(&fs_info->transaction_kthread_mutex); in open_ctree()
2760 mutex_init(&fs_info->cleaner_mutex); in open_ctree()
2761 mutex_init(&fs_info->ro_block_group_mutex); in open_ctree()
2762 init_rwsem(&fs_info->commit_root_sem); in open_ctree()
2763 init_rwsem(&fs_info->cleanup_work_sem); in open_ctree()
2764 init_rwsem(&fs_info->subvol_sem); in open_ctree()
2765 sema_init(&fs_info->uuid_tree_rescan_sem, 1); in open_ctree()
2767 btrfs_init_dev_replace_locks(fs_info); in open_ctree()
2768 btrfs_init_qgroup(fs_info); in open_ctree()
2770 btrfs_init_free_cluster(&fs_info->meta_alloc_cluster); in open_ctree()
2771 btrfs_init_free_cluster(&fs_info->data_alloc_cluster); in open_ctree()
2773 init_waitqueue_head(&fs_info->transaction_throttle); in open_ctree()
2774 init_waitqueue_head(&fs_info->transaction_wait); in open_ctree()
2775 init_waitqueue_head(&fs_info->transaction_blocked_wait); in open_ctree()
2776 init_waitqueue_head(&fs_info->async_submit_wait); in open_ctree()
2778 INIT_LIST_HEAD(&fs_info->pinned_chunks); in open_ctree()
2781 fs_info->nodesize = 4096; in open_ctree()
2782 fs_info->sectorsize = 4096; in open_ctree()
2783 fs_info->stripesize = 4096; in open_ctree()
2785 ret = btrfs_alloc_stripe_hash_table(fs_info); in open_ctree()
2791 __setup_root(tree_root, fs_info, BTRFS_ROOT_TREE_OBJECTID); in open_ctree()
2808 if (btrfs_check_super_csum(fs_info, bh->b_data)) { in open_ctree()
2809 btrfs_err(fs_info, "superblock checksum mismatch"); in open_ctree()
2820 memcpy(fs_info->super_copy, bh->b_data, sizeof(*fs_info->super_copy)); in open_ctree()
2821 memcpy(fs_info->super_for_commit, fs_info->super_copy, in open_ctree()
2822 sizeof(*fs_info->super_for_commit)); in open_ctree()
2825 memcpy(fs_info->fsid, fs_info->super_copy->fsid, BTRFS_FSID_SIZE); in open_ctree()
2827 ret = btrfs_validate_mount_super(fs_info); in open_ctree()
2829 btrfs_err(fs_info, "superblock contains fatal errors"); in open_ctree()
2834 disk_super = fs_info->super_copy; in open_ctree()
2840 set_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state); in open_ctree()
2847 find_oldest_super_backup(fs_info, generation); in open_ctree()
2853 fs_info->compress_type = BTRFS_COMPRESS_ZLIB; in open_ctree()
2855 ret = btrfs_parse_options(fs_info, options, sb->s_flags); in open_ctree()
2864 btrfs_err(fs_info, in open_ctree()
2873 if (fs_info->compress_type == BTRFS_COMPRESS_LZO) in open_ctree()
2875 else if (fs_info->compress_type == BTRFS_COMPRESS_ZSTD) in open_ctree()
2879 btrfs_info(fs_info, "has skinny extents"); in open_ctree()
2887 btrfs_info(fs_info, in open_ctree()
2895 fs_info->dirty_metadata_batch = nodesize * (1 + ilog2(nr_cpu_ids)); in open_ctree()
2896 fs_info->delalloc_batch = sectorsize * 512 * (1 + ilog2(nr_cpu_ids)); in open_ctree()
2899 fs_info->nodesize = nodesize; in open_ctree()
2900 fs_info->sectorsize = sectorsize; in open_ctree()
2901 fs_info->stripesize = stripesize; in open_ctree()
2909 btrfs_err(fs_info, in open_ctree()
2924 btrfs_err(fs_info, in open_ctree()
2931 ret = btrfs_init_workqueues(fs_info, fs_devices); in open_ctree()
2938 sb->s_bdi->congested_data = fs_info; in open_ctree()
2946 memcpy(&sb->s_uuid, fs_info->fsid, BTRFS_FSID_SIZE); in open_ctree()
2948 mutex_lock(&fs_info->chunk_mutex); in open_ctree()
2949 ret = btrfs_read_sys_array(fs_info); in open_ctree()
2950 mutex_unlock(&fs_info->chunk_mutex); in open_ctree()
2952 btrfs_err(fs_info, "failed to read the system array: %d", ret); in open_ctree()
2959 __setup_root(chunk_root, fs_info, BTRFS_CHUNK_TREE_OBJECTID); in open_ctree()
2961 chunk_root->node = read_tree_block(fs_info, in open_ctree()
2966 btrfs_err(fs_info, "failed to read chunk root"); in open_ctree()
2975 read_extent_buffer(chunk_root->node, fs_info->chunk_tree_uuid, in open_ctree()
2978 ret = btrfs_read_chunk_tree(fs_info); in open_ctree()
2980 btrfs_err(fs_info, "failed to read chunk tree: %d", ret); in open_ctree()
2991 btrfs_err(fs_info, "failed to read devices"); in open_ctree()
2999 tree_root->node = read_tree_block(fs_info, in open_ctree()
3004 btrfs_warn(fs_info, "failed to read tree root"); in open_ctree()
3027 ret = btrfs_read_roots(fs_info); in open_ctree()
3031 fs_info->generation = generation; in open_ctree()
3032 fs_info->last_trans_committed = generation; in open_ctree()
3034 ret = btrfs_verify_dev_extents(fs_info); in open_ctree()
3036 btrfs_err(fs_info, in open_ctree()
3041 ret = btrfs_recover_balance(fs_info); in open_ctree()
3043 btrfs_err(fs_info, "failed to recover balance: %d", ret); in open_ctree()
3047 ret = btrfs_init_dev_stats(fs_info); in open_ctree()
3049 btrfs_err(fs_info, "failed to init dev_stats: %d", ret); in open_ctree()
3053 ret = btrfs_init_dev_replace(fs_info); in open_ctree()
3055 btrfs_err(fs_info, "failed to init dev_replace: %d", ret); in open_ctree()
3063 btrfs_err(fs_info, "failed to init sysfs fsid interface: %d", in open_ctree()
3070 btrfs_err(fs_info, "failed to init sysfs device interface: %d", in open_ctree()
3075 ret = btrfs_sysfs_add_mounted(fs_info); in open_ctree()
3077 btrfs_err(fs_info, "failed to init sysfs interface: %d", ret); in open_ctree()
3081 ret = btrfs_init_space_info(fs_info); in open_ctree()
3083 btrfs_err(fs_info, "failed to initialize space info: %d", ret); in open_ctree()
3087 ret = btrfs_read_block_groups(fs_info); in open_ctree()
3089 btrfs_err(fs_info, "failed to read block groups: %d", ret); in open_ctree()
3093 if (!sb_rdonly(sb) && !btrfs_check_rw_degradable(fs_info, NULL)) { in open_ctree()
3094 btrfs_warn(fs_info, in open_ctree()
3099 fs_info->cleaner_kthread = kthread_run(cleaner_kthread, tree_root, in open_ctree()
3101 if (IS_ERR(fs_info->cleaner_kthread)) in open_ctree()
3104 fs_info->transaction_kthread = kthread_run(transaction_kthread, in open_ctree()
3107 if (IS_ERR(fs_info->transaction_kthread)) in open_ctree()
3110 if (!btrfs_test_opt(fs_info, NOSSD) && in open_ctree()
3111 !fs_info->fs_devices->rotating) { in open_ctree()
3112 btrfs_set_and_info(fs_info, SSD, "enabling ssd optimizations"); in open_ctree()
3119 btrfs_apply_pending_changes(fs_info); in open_ctree()
3122 if (btrfs_test_opt(fs_info, CHECK_INTEGRITY)) { in open_ctree()
3123 ret = btrfsic_mount(fs_info, fs_devices, in open_ctree()
3124 btrfs_test_opt(fs_info, in open_ctree()
3127 fs_info->check_integrity_print_mask); in open_ctree()
3129 btrfs_warn(fs_info, in open_ctree()
3134 ret = btrfs_read_qgroup_config(fs_info); in open_ctree()
3138 if (btrfs_build_ref_tree(fs_info)) in open_ctree()
3139 btrfs_err(fs_info, "couldn't build ref tree"); in open_ctree()
3143 !btrfs_test_opt(fs_info, NOLOGREPLAY)) { in open_ctree()
3144 ret = btrfs_replay_log(fs_info, fs_devices); in open_ctree()
3151 ret = btrfs_find_orphan_roots(fs_info); in open_ctree()
3156 ret = btrfs_cleanup_fs_roots(fs_info); in open_ctree()
3160 mutex_lock(&fs_info->cleaner_mutex); in open_ctree()
3162 mutex_unlock(&fs_info->cleaner_mutex); in open_ctree()
3164 btrfs_warn(fs_info, "failed to recover relocation: %d", in open_ctree()
3175 fs_info->fs_root = btrfs_read_fs_root_no_name(fs_info, &location); in open_ctree()
3176 if (IS_ERR(fs_info->fs_root)) { in open_ctree()
3177 err = PTR_ERR(fs_info->fs_root); in open_ctree()
3178 btrfs_warn(fs_info, "failed to read fs tree: %d", err); in open_ctree()
3185 if (btrfs_test_opt(fs_info, CLEAR_CACHE) && in open_ctree()
3186 btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE)) { in open_ctree()
3188 } else if (btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE) && in open_ctree()
3189 !btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE_VALID)) { in open_ctree()
3190 btrfs_warn(fs_info, "free space tree is invalid"); in open_ctree()
3195 btrfs_info(fs_info, "clearing free space tree"); in open_ctree()
3196 ret = btrfs_clear_free_space_tree(fs_info); in open_ctree()
3198 btrfs_warn(fs_info, in open_ctree()
3200 close_ctree(fs_info); in open_ctree()
3205 if (btrfs_test_opt(fs_info, FREE_SPACE_TREE) && in open_ctree()
3206 !btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE)) { in open_ctree()
3207 btrfs_info(fs_info, "creating free space tree"); in open_ctree()
3208 ret = btrfs_create_free_space_tree(fs_info); in open_ctree()
3210 btrfs_warn(fs_info, in open_ctree()
3212 close_ctree(fs_info); in open_ctree()
3217 down_read(&fs_info->cleanup_work_sem); in open_ctree()
3218 if ((ret = btrfs_orphan_cleanup(fs_info->fs_root)) || in open_ctree()
3219 (ret = btrfs_orphan_cleanup(fs_info->tree_root))) { in open_ctree()
3220 up_read(&fs_info->cleanup_work_sem); in open_ctree()
3221 close_ctree(fs_info); in open_ctree()
3224 up_read(&fs_info->cleanup_work_sem); in open_ctree()
3226 ret = btrfs_resume_balance_async(fs_info); in open_ctree()
3228 btrfs_warn(fs_info, "failed to resume balance: %d", ret); in open_ctree()
3229 close_ctree(fs_info); in open_ctree()
3233 ret = btrfs_resume_dev_replace_async(fs_info); in open_ctree()
3235 btrfs_warn(fs_info, "failed to resume device replace: %d", ret); in open_ctree()
3236 close_ctree(fs_info); in open_ctree()
3240 btrfs_qgroup_rescan_resume(fs_info); in open_ctree()
3242 if (!fs_info->uuid_root) { in open_ctree()
3243 btrfs_info(fs_info, "creating UUID tree"); in open_ctree()
3244 ret = btrfs_create_uuid_tree(fs_info); in open_ctree()
3246 btrfs_warn(fs_info, in open_ctree()
3248 close_ctree(fs_info); in open_ctree()
3251 } else if (btrfs_test_opt(fs_info, RESCAN_UUID_TREE) || in open_ctree()
3252 fs_info->generation != in open_ctree()
3254 btrfs_info(fs_info, "checking UUID tree"); in open_ctree()
3255 ret = btrfs_check_uuid_tree(fs_info); in open_ctree()
3257 btrfs_warn(fs_info, in open_ctree()
3259 close_ctree(fs_info); in open_ctree()
3263 set_bit(BTRFS_FS_UPDATE_UUID_TREE_GEN, &fs_info->flags); in open_ctree()
3265 set_bit(BTRFS_FS_OPEN, &fs_info->flags); in open_ctree()
3271 btrfs_clear_opt(fs_info->mount_opt, USEBACKUPROOT); in open_ctree()
3276 btrfs_free_qgroup_config(fs_info); in open_ctree()
3278 kthread_stop(fs_info->transaction_kthread); in open_ctree()
3279 btrfs_cleanup_transaction(fs_info); in open_ctree()
3280 btrfs_free_fs_roots(fs_info); in open_ctree()
3282 kthread_stop(fs_info->cleaner_kthread); in open_ctree()
3288 filemap_write_and_wait(fs_info->btree_inode->i_mapping); in open_ctree()
3291 btrfs_sysfs_remove_mounted(fs_info); in open_ctree()
3294 btrfs_sysfs_remove_fsid(fs_info->fs_devices); in open_ctree()
3297 btrfs_put_block_group_cache(fs_info); in open_ctree()
3300 free_root_pointers(fs_info, 1); in open_ctree()
3301 invalidate_inode_pages2(fs_info->btree_inode->i_mapping); in open_ctree()
3304 btrfs_stop_all_workers(fs_info); in open_ctree()
3305 btrfs_free_block_groups(fs_info); in open_ctree()
3308 btrfs_mapping_tree_free(&fs_info->mapping_tree); in open_ctree()
3310 iput(fs_info->btree_inode); in open_ctree()
3312 percpu_counter_destroy(&fs_info->bio_counter); in open_ctree()
3314 percpu_counter_destroy(&fs_info->delalloc_bytes); in open_ctree()
3316 percpu_counter_destroy(&fs_info->dirty_metadata_bytes); in open_ctree()
3318 cleanup_srcu_struct(&fs_info->subvol_srcu); in open_ctree()
3320 btrfs_free_stripe_hash_table(fs_info); in open_ctree()
3321 btrfs_close_devices(fs_info->fs_devices); in open_ctree()
3325 if (!btrfs_test_opt(fs_info, USEBACKUPROOT)) in open_ctree()
3328 free_root_pointers(fs_info, 0); in open_ctree()
3334 btrfs_set_opt(fs_info->mount_opt, CLEAR_CACHE); in open_ctree()
3336 ret = next_root_backup(fs_info, fs_info->super_copy, in open_ctree()
3352 btrfs_warn_rl_in_rcu(device->fs_info, in btrfs_end_buffer_write_sync()
3473 btrfs_err(device->fs_info, in write_dev_supers()
3495 if (i == 0 && !btrfs_test_opt(device->fs_info, NOBARRIER)) in write_dev_supers()
3553 btrfs_err(device->fs_info, "error writing primary super block to device %llu", in wait_dev_supers()
3609 static int check_barrier_error(struct btrfs_fs_info *fs_info) in check_barrier_error() argument
3611 if (!btrfs_check_rw_degradable(fs_info, NULL)) in check_barrier_error()
3704 int write_all_supers(struct btrfs_fs_info *fs_info, int max_mirrors) in write_all_supers() argument
3716 do_barriers = !btrfs_test_opt(fs_info, NOBARRIER); in write_all_supers()
3724 backup_super_roots(fs_info); in write_all_supers()
3726 sb = fs_info->super_for_commit; in write_all_supers()
3729 mutex_lock(&fs_info->fs_devices->device_list_mutex); in write_all_supers()
3730 head = &fs_info->fs_devices->devices; in write_all_supers()
3731 max_errors = btrfs_super_num_devices(fs_info->super_copy) - 1; in write_all_supers()
3734 ret = barrier_all_devices(fs_info); in write_all_supers()
3737 &fs_info->fs_devices->device_list_mutex); in write_all_supers()
3738 btrfs_handle_fs_error(fs_info, ret, in write_all_supers()
3769 ret = btrfs_validate_write_super(fs_info, sb); in write_all_supers()
3771 mutex_unlock(&fs_info->fs_devices->device_list_mutex); in write_all_supers()
3772 btrfs_handle_fs_error(fs_info, -EUCLEAN, in write_all_supers()
3782 btrfs_err(fs_info, "%d errors while writing supers", in write_all_supers()
3784 mutex_unlock(&fs_info->fs_devices->device_list_mutex); in write_all_supers()
3787 btrfs_handle_fs_error(fs_info, -EIO, in write_all_supers()
3805 mutex_unlock(&fs_info->fs_devices->device_list_mutex); in write_all_supers()
3807 btrfs_handle_fs_error(fs_info, -EIO, in write_all_supers()
3816 void btrfs_drop_and_free_fs_root(struct btrfs_fs_info *fs_info, in btrfs_drop_and_free_fs_root() argument
3819 spin_lock(&fs_info->fs_roots_radix_lock); in btrfs_drop_and_free_fs_root()
3820 radix_tree_delete(&fs_info->fs_roots_radix, in btrfs_drop_and_free_fs_root()
3822 spin_unlock(&fs_info->fs_roots_radix_lock); in btrfs_drop_and_free_fs_root()
3825 synchronize_srcu(&fs_info->subvol_srcu); in btrfs_drop_and_free_fs_root()
3827 if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) { in btrfs_drop_and_free_fs_root()
3859 int btrfs_cleanup_fs_roots(struct btrfs_fs_info *fs_info) in btrfs_cleanup_fs_roots() argument
3869 index = srcu_read_lock(&fs_info->subvol_srcu); in btrfs_cleanup_fs_roots()
3870 ret = radix_tree_gang_lookup(&fs_info->fs_roots_radix, in btrfs_cleanup_fs_roots()
3874 srcu_read_unlock(&fs_info->subvol_srcu, index); in btrfs_cleanup_fs_roots()
3888 srcu_read_unlock(&fs_info->subvol_srcu, index); in btrfs_cleanup_fs_roots()
3910 int btrfs_commit_super(struct btrfs_fs_info *fs_info) in btrfs_commit_super() argument
3912 struct btrfs_root *root = fs_info->tree_root; in btrfs_commit_super()
3915 mutex_lock(&fs_info->cleaner_mutex); in btrfs_commit_super()
3916 btrfs_run_delayed_iputs(fs_info); in btrfs_commit_super()
3917 mutex_unlock(&fs_info->cleaner_mutex); in btrfs_commit_super()
3918 wake_up_process(fs_info->cleaner_kthread); in btrfs_commit_super()
3921 down_write(&fs_info->cleanup_work_sem); in btrfs_commit_super()
3922 up_write(&fs_info->cleanup_work_sem); in btrfs_commit_super()
3930 void close_ctree(struct btrfs_fs_info *fs_info) in close_ctree() argument
3934 set_bit(BTRFS_FS_CLOSING_START, &fs_info->flags); in close_ctree()
3937 btrfs_qgroup_wait_for_completion(fs_info, false); in close_ctree()
3940 down(&fs_info->uuid_tree_rescan_sem); in close_ctree()
3942 up(&fs_info->uuid_tree_rescan_sem); in close_ctree()
3945 btrfs_pause_balance(fs_info); in close_ctree()
3947 btrfs_dev_replace_suspend_for_unmount(fs_info); in close_ctree()
3949 btrfs_scrub_cancel(fs_info); in close_ctree()
3952 wait_event(fs_info->transaction_wait, in close_ctree()
3953 (atomic_read(&fs_info->defrag_running) == 0)); in close_ctree()
3956 btrfs_cleanup_defrag_inodes(fs_info); in close_ctree()
3958 cancel_work_sync(&fs_info->async_reclaim_work); in close_ctree()
3960 if (!sb_rdonly(fs_info->sb)) { in close_ctree()
3966 btrfs_delete_unused_bgs(fs_info); in close_ctree()
3968 ret = btrfs_commit_super(fs_info); in close_ctree()
3970 btrfs_err(fs_info, "commit super ret %d", ret); in close_ctree()
3973 if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state) || in close_ctree()
3974 test_bit(BTRFS_FS_STATE_TRANS_ABORTED, &fs_info->fs_state)) in close_ctree()
3975 btrfs_error_commit_super(fs_info); in close_ctree()
3977 kthread_stop(fs_info->transaction_kthread); in close_ctree()
3978 kthread_stop(fs_info->cleaner_kthread); in close_ctree()
3980 set_bit(BTRFS_FS_CLOSING_DONE, &fs_info->flags); in close_ctree()
3982 btrfs_free_qgroup_config(fs_info); in close_ctree()
3983 ASSERT(list_empty(&fs_info->delalloc_roots)); in close_ctree()
3985 if (percpu_counter_sum(&fs_info->delalloc_bytes)) { in close_ctree()
3986 btrfs_info(fs_info, "at unmount delalloc count %lld", in close_ctree()
3987 percpu_counter_sum(&fs_info->delalloc_bytes)); in close_ctree()
3990 btrfs_sysfs_remove_mounted(fs_info); in close_ctree()
3991 btrfs_sysfs_remove_fsid(fs_info->fs_devices); in close_ctree()
3993 btrfs_free_fs_roots(fs_info); in close_ctree()
3995 btrfs_put_block_group_cache(fs_info); in close_ctree()
4001 invalidate_inode_pages2(fs_info->btree_inode->i_mapping); in close_ctree()
4002 btrfs_stop_all_workers(fs_info); in close_ctree()
4004 btrfs_free_block_groups(fs_info); in close_ctree()
4006 clear_bit(BTRFS_FS_OPEN, &fs_info->flags); in close_ctree()
4007 free_root_pointers(fs_info, 1); in close_ctree()
4009 iput(fs_info->btree_inode); in close_ctree()
4012 if (btrfs_test_opt(fs_info, CHECK_INTEGRITY)) in close_ctree()
4013 btrfsic_unmount(fs_info->fs_devices); in close_ctree()
4016 btrfs_close_devices(fs_info->fs_devices); in close_ctree()
4017 btrfs_mapping_tree_free(&fs_info->mapping_tree); in close_ctree()
4019 percpu_counter_destroy(&fs_info->dirty_metadata_bytes); in close_ctree()
4020 percpu_counter_destroy(&fs_info->delalloc_bytes); in close_ctree()
4021 percpu_counter_destroy(&fs_info->bio_counter); in close_ctree()
4022 cleanup_srcu_struct(&fs_info->subvol_srcu); in close_ctree()
4024 btrfs_free_stripe_hash_table(fs_info); in close_ctree()
4025 btrfs_free_ref_cache(fs_info); in close_ctree()
4027 while (!list_empty(&fs_info->pinned_chunks)) { in close_ctree()
4030 em = list_first_entry(&fs_info->pinned_chunks, in close_ctree()
4056 struct btrfs_fs_info *fs_info; in btrfs_mark_buffer_dirty() local
4071 fs_info = root->fs_info; in btrfs_mark_buffer_dirty()
4073 if (transid != fs_info->generation) in btrfs_mark_buffer_dirty()
4075 buf->start, transid, fs_info->generation); in btrfs_mark_buffer_dirty()
4078 percpu_counter_add_batch(&fs_info->dirty_metadata_bytes, in btrfs_mark_buffer_dirty()
4080 fs_info->dirty_metadata_batch); in btrfs_mark_buffer_dirty()
4088 btrfs_check_leaf_relaxed(fs_info, buf)) { in btrfs_mark_buffer_dirty()
4095 static void __btrfs_btree_balance_dirty(struct btrfs_fs_info *fs_info, in __btrfs_btree_balance_dirty() argument
4108 btrfs_balance_delayed_items(fs_info); in __btrfs_btree_balance_dirty()
4110 ret = __percpu_counter_compare(&fs_info->dirty_metadata_bytes, in __btrfs_btree_balance_dirty()
4112 fs_info->dirty_metadata_batch); in __btrfs_btree_balance_dirty()
4114 balance_dirty_pages_ratelimited(fs_info->btree_inode->i_mapping); in __btrfs_btree_balance_dirty()
4118 void btrfs_btree_balance_dirty(struct btrfs_fs_info *fs_info) in btrfs_btree_balance_dirty() argument
4120 __btrfs_btree_balance_dirty(fs_info, 1); in btrfs_btree_balance_dirty()
4123 void btrfs_btree_balance_dirty_nodelay(struct btrfs_fs_info *fs_info) in btrfs_btree_balance_dirty_nodelay() argument
4125 __btrfs_btree_balance_dirty(fs_info, 0); in btrfs_btree_balance_dirty_nodelay()
4132 struct btrfs_fs_info *fs_info = root->fs_info; in btrfs_read_buffer() local
4134 return btree_read_extent_buffer_pages(fs_info, buf, parent_transid, in btrfs_read_buffer()
4138 static void btrfs_error_commit_super(struct btrfs_fs_info *fs_info) in btrfs_error_commit_super() argument
4141 btrfs_cleanup_transaction(fs_info); in btrfs_error_commit_super()
4143 mutex_lock(&fs_info->cleaner_mutex); in btrfs_error_commit_super()
4144 btrfs_run_delayed_iputs(fs_info); in btrfs_error_commit_super()
4145 mutex_unlock(&fs_info->cleaner_mutex); in btrfs_error_commit_super()
4147 down_write(&fs_info->cleanup_work_sem); in btrfs_error_commit_super()
4148 up_write(&fs_info->cleanup_work_sem); in btrfs_error_commit_super()
4166 static void btrfs_destroy_all_ordered_extents(struct btrfs_fs_info *fs_info) in btrfs_destroy_all_ordered_extents() argument
4173 spin_lock(&fs_info->ordered_root_lock); in btrfs_destroy_all_ordered_extents()
4174 list_splice_init(&fs_info->ordered_roots, &splice); in btrfs_destroy_all_ordered_extents()
4179 &fs_info->ordered_roots); in btrfs_destroy_all_ordered_extents()
4181 spin_unlock(&fs_info->ordered_root_lock); in btrfs_destroy_all_ordered_extents()
4185 spin_lock(&fs_info->ordered_root_lock); in btrfs_destroy_all_ordered_extents()
4187 spin_unlock(&fs_info->ordered_root_lock); in btrfs_destroy_all_ordered_extents()
4191 struct btrfs_fs_info *fs_info) in btrfs_destroy_delayed_refs() argument
4203 btrfs_info(fs_info, "delayed_refs has NO entry"); in btrfs_destroy_delayed_refs()
4250 btrfs_pin_extent(fs_info, head->bytenr, in btrfs_destroy_delayed_refs()
4293 static void btrfs_destroy_all_delalloc_inodes(struct btrfs_fs_info *fs_info) in btrfs_destroy_all_delalloc_inodes() argument
4300 spin_lock(&fs_info->delalloc_root_lock); in btrfs_destroy_all_delalloc_inodes()
4301 list_splice_init(&fs_info->delalloc_roots, &splice); in btrfs_destroy_all_delalloc_inodes()
4307 spin_unlock(&fs_info->delalloc_root_lock); in btrfs_destroy_all_delalloc_inodes()
4312 spin_lock(&fs_info->delalloc_root_lock); in btrfs_destroy_all_delalloc_inodes()
4314 spin_unlock(&fs_info->delalloc_root_lock); in btrfs_destroy_all_delalloc_inodes()
4317 static int btrfs_destroy_marked_extents(struct btrfs_fs_info *fs_info, in btrfs_destroy_marked_extents() argument
4334 eb = find_extent_buffer(fs_info, start); in btrfs_destroy_marked_extents()
4335 start += fs_info->nodesize; in btrfs_destroy_marked_extents()
4350 static int btrfs_destroy_pinned_extent(struct btrfs_fs_info *fs_info, in btrfs_destroy_pinned_extent() argument
4368 btrfs_error_unpin_extent_range(fs_info, start, end); in btrfs_destroy_pinned_extent()
4373 if (unpin == &fs_info->freed_extents[0]) in btrfs_destroy_pinned_extent()
4374 unpin = &fs_info->freed_extents[1]; in btrfs_destroy_pinned_extent()
4376 unpin = &fs_info->freed_extents[0]; in btrfs_destroy_pinned_extent()
4399 struct btrfs_fs_info *fs_info) in btrfs_cleanup_dirty_bgs() argument
4445 struct btrfs_fs_info *fs_info) in btrfs_cleanup_one_transaction() argument
4447 btrfs_cleanup_dirty_bgs(cur_trans, fs_info); in btrfs_cleanup_one_transaction()
4451 btrfs_destroy_delayed_refs(cur_trans, fs_info); in btrfs_cleanup_one_transaction()
4454 wake_up(&fs_info->transaction_blocked_wait); in btrfs_cleanup_one_transaction()
4457 wake_up(&fs_info->transaction_wait); in btrfs_cleanup_one_transaction()
4459 btrfs_destroy_delayed_inodes(fs_info); in btrfs_cleanup_one_transaction()
4460 btrfs_assert_delayed_root_empty(fs_info); in btrfs_cleanup_one_transaction()
4462 btrfs_destroy_marked_extents(fs_info, &cur_trans->dirty_pages, in btrfs_cleanup_one_transaction()
4464 btrfs_destroy_pinned_extent(fs_info, in btrfs_cleanup_one_transaction()
4465 fs_info->pinned_extents); in btrfs_cleanup_one_transaction()
4471 static int btrfs_cleanup_transaction(struct btrfs_fs_info *fs_info) in btrfs_cleanup_transaction() argument
4475 mutex_lock(&fs_info->transaction_kthread_mutex); in btrfs_cleanup_transaction()
4477 spin_lock(&fs_info->trans_lock); in btrfs_cleanup_transaction()
4478 while (!list_empty(&fs_info->trans_list)) { in btrfs_cleanup_transaction()
4479 t = list_first_entry(&fs_info->trans_list, in btrfs_cleanup_transaction()
4483 spin_unlock(&fs_info->trans_lock); in btrfs_cleanup_transaction()
4484 btrfs_wait_for_commit(fs_info, t->transid); in btrfs_cleanup_transaction()
4486 spin_lock(&fs_info->trans_lock); in btrfs_cleanup_transaction()
4489 if (t == fs_info->running_transaction) { in btrfs_cleanup_transaction()
4491 spin_unlock(&fs_info->trans_lock); in btrfs_cleanup_transaction()
4499 spin_unlock(&fs_info->trans_lock); in btrfs_cleanup_transaction()
4501 btrfs_cleanup_one_transaction(t, fs_info); in btrfs_cleanup_transaction()
4503 spin_lock(&fs_info->trans_lock); in btrfs_cleanup_transaction()
4504 if (t == fs_info->running_transaction) in btrfs_cleanup_transaction()
4505 fs_info->running_transaction = NULL; in btrfs_cleanup_transaction()
4507 spin_unlock(&fs_info->trans_lock); in btrfs_cleanup_transaction()
4510 trace_btrfs_transaction_commit(fs_info->tree_root); in btrfs_cleanup_transaction()
4511 spin_lock(&fs_info->trans_lock); in btrfs_cleanup_transaction()
4513 spin_unlock(&fs_info->trans_lock); in btrfs_cleanup_transaction()
4514 btrfs_destroy_all_ordered_extents(fs_info); in btrfs_cleanup_transaction()
4515 btrfs_destroy_delayed_inodes(fs_info); in btrfs_cleanup_transaction()
4516 btrfs_assert_delayed_root_empty(fs_info); in btrfs_cleanup_transaction()
4517 btrfs_destroy_pinned_extent(fs_info, fs_info->pinned_extents); in btrfs_cleanup_transaction()
4518 btrfs_destroy_all_delalloc_inodes(fs_info); in btrfs_cleanup_transaction()
4519 mutex_unlock(&fs_info->transaction_kthread_mutex); in btrfs_cleanup_transaction()