Lines Matching refs:fs_info
56 struct btrfs_fs_info *fs_info);
58 static int btrfs_destroy_marked_extents(struct btrfs_fs_info *fs_info,
61 static int btrfs_destroy_pinned_extent(struct btrfs_fs_info *fs_info,
63 static int btrfs_cleanup_transaction(struct btrfs_fs_info *fs_info);
64 static void btrfs_error_commit_super(struct btrfs_fs_info *fs_info);
100 static void btrfs_free_csum_hash(struct btrfs_fs_info *fs_info) in btrfs_free_csum_hash() argument
102 if (fs_info->csum_shash) in btrfs_free_csum_hash()
103 crypto_free_shash(fs_info->csum_shash); in btrfs_free_csum_hash()
211 struct btrfs_fs_info *fs_info = buf->fs_info; in csum_tree_block() local
212 const int num_pages = fs_info->nodesize >> PAGE_SHIFT; in csum_tree_block()
213 SHASH_DESC_ON_STACK(shash, fs_info->csum_shash); in csum_tree_block()
217 shash->tfm = fs_info->csum_shash; in csum_tree_block()
263 btrfs_err_rl(eb->fs_info, in verify_parent_transid()
304 static int btrfs_check_super_csum(struct btrfs_fs_info *fs_info, in btrfs_check_super_csum() argument
310 SHASH_DESC_ON_STACK(shash, fs_info->csum_shash); in btrfs_check_super_csum()
312 shash->tfm = fs_info->csum_shash; in btrfs_check_super_csum()
331 struct btrfs_fs_info *fs_info = eb->fs_info; in btrfs_verify_level_key() local
340 btrfs_err(fs_info, in btrfs_verify_level_key()
355 if (btrfs_header_generation(eb) > fs_info->last_trans_committed) in btrfs_verify_level_key()
360 btrfs_err(fs_info, in btrfs_verify_level_key()
376 btrfs_err(fs_info, in btrfs_verify_level_key()
398 struct btrfs_fs_info *fs_info = eb->fs_info; in btree_read_extent_buffer_pages() local
406 io_tree = &BTRFS_I(fs_info->btree_inode)->io_tree; in btree_read_extent_buffer_pages()
421 num_copies = btrfs_num_copies(fs_info, in btree_read_extent_buffer_pages()
450 static int csum_dirty_buffer(struct btrfs_fs_info *fs_info, struct page *page) in csum_dirty_buffer() argument
455 u16 csum_size = btrfs_super_csum_size(fs_info->super_copy); in csum_dirty_buffer()
473 ASSERT(memcmp_extent_buffer(eb, fs_info->fs_devices->metadata_uuid, in csum_dirty_buffer()
486 btrfs_err(fs_info, in csum_dirty_buffer()
499 struct btrfs_fs_info *fs_info = eb->fs_info; in check_tree_block_fsid() local
500 struct btrfs_fs_devices *fs_devices = fs_info->fs_devices, *seed_devs; in check_tree_block_fsid()
511 if (btrfs_fs_incompat(fs_info, METADATA_UUID)) in check_tree_block_fsid()
533 struct btrfs_fs_info *fs_info; in btrfs_validate_metadata_buffer() local
543 fs_info = eb->fs_info; in btrfs_validate_metadata_buffer()
544 csum_size = btrfs_super_csum_size(fs_info->super_copy); in btrfs_validate_metadata_buffer()
563 btrfs_err_rl(fs_info, "bad tree block start, want %llu have %llu", in btrfs_validate_metadata_buffer()
569 btrfs_err_rl(fs_info, "bad fsid on block %llu", in btrfs_validate_metadata_buffer()
576 btrfs_err(fs_info, "bad tree block level %d on %llu", in btrfs_validate_metadata_buffer()
591 btrfs_warn_rl(fs_info, in btrfs_validate_metadata_buffer()
593 fs_info->sb->s_id, eb->start, in btrfs_validate_metadata_buffer()
617 btrfs_err(fs_info, in btrfs_validate_metadata_buffer()
642 struct btrfs_fs_info *fs_info; in end_workqueue_bio() local
645 fs_info = end_io_wq->info; in end_workqueue_bio()
650 wq = fs_info->endio_meta_write_workers; in end_workqueue_bio()
652 wq = fs_info->endio_freespace_worker; in end_workqueue_bio()
654 wq = fs_info->endio_raid56_workers; in end_workqueue_bio()
656 wq = fs_info->endio_write_workers; in end_workqueue_bio()
659 wq = fs_info->endio_raid56_workers; in end_workqueue_bio()
661 wq = fs_info->endio_meta_workers; in end_workqueue_bio()
663 wq = fs_info->endio_workers; in end_workqueue_bio()
748 blk_status_t btrfs_wq_submit_bio(struct btrfs_fs_info *fs_info, struct bio *bio, in btrfs_wq_submit_bio() argument
774 btrfs_queue_work(fs_info->workers, &async->work); in btrfs_wq_submit_bio()
788 ret = csum_dirty_buffer(root->fs_info, bvec->bv_page); in btree_csum_one_bio()
806 static int check_async_write(struct btrfs_fs_info *fs_info, in check_async_write() argument
811 if (test_bit(BTRFS_FS_CSUM_IMPL_FAST, &fs_info->flags)) in check_async_write()
819 struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); in btrfs_submit_metadata_bio() local
820 int async = check_async_write(fs_info, BTRFS_I(inode)); in btrfs_submit_metadata_bio()
828 ret = btrfs_bio_wq_end_io(fs_info, bio, in btrfs_submit_metadata_bio()
832 ret = btrfs_map_bio(fs_info, bio, mirror_num); in btrfs_submit_metadata_bio()
837 ret = btrfs_map_bio(fs_info, bio, mirror_num); in btrfs_submit_metadata_bio()
843 ret = btrfs_wq_submit_bio(fs_info, bio, mirror_num, 0, in btrfs_submit_metadata_bio()
883 struct btrfs_fs_info *fs_info; in btree_writepages() local
891 fs_info = BTRFS_I(mapping->host)->root->fs_info; in btree_writepages()
893 ret = __percpu_counter_compare(&fs_info->dirty_metadata_bytes, in btree_writepages()
895 fs_info->dirty_metadata_batch); in btree_writepages()
918 btrfs_warn(BTRFS_I(page->mapping->host)->root->fs_info, in btree_invalidatepage()
950 void readahead_tree_block(struct btrfs_fs_info *fs_info, u64 bytenr) in readahead_tree_block() argument
955 buf = btrfs_find_create_tree_block(fs_info, bytenr); in readahead_tree_block()
967 struct btrfs_fs_info *fs_info, in btrfs_find_create_tree_block() argument
970 if (btrfs_is_testing(fs_info)) in btrfs_find_create_tree_block()
971 return alloc_test_extent_buffer(fs_info, bytenr); in btrfs_find_create_tree_block()
972 return alloc_extent_buffer(fs_info, bytenr); in btrfs_find_create_tree_block()
983 struct extent_buffer *read_tree_block(struct btrfs_fs_info *fs_info, u64 bytenr, in read_tree_block() argument
990 buf = btrfs_find_create_tree_block(fs_info, bytenr); in read_tree_block()
1006 struct btrfs_fs_info *fs_info = buf->fs_info; in btrfs_clean_tree_block() local
1008 fs_info->running_transaction->transid) { in btrfs_clean_tree_block()
1012 percpu_counter_add_batch(&fs_info->dirty_metadata_bytes, in btrfs_clean_tree_block()
1014 fs_info->dirty_metadata_batch); in btrfs_clean_tree_block()
1022 static void __setup_root(struct btrfs_root *root, struct btrfs_fs_info *fs_info, in __setup_root() argument
1025 bool dummy = test_bit(BTRFS_FS_STATE_DUMMY_FS_INFO, &fs_info->fs_state); in __setup_root()
1026 root->fs_info = fs_info; in __setup_root()
1077 extent_io_tree_init(fs_info, &root->dirty_log_pages, in __setup_root()
1079 extent_io_tree_init(fs_info, &root->log_csum_range, in __setup_root()
1093 spin_lock(&fs_info->fs_roots_radix_lock); in __setup_root()
1094 list_add_tail(&root->leak_list, &fs_info->allocated_roots); in __setup_root()
1095 spin_unlock(&fs_info->fs_roots_radix_lock); in __setup_root()
1099 static struct btrfs_root *btrfs_alloc_root(struct btrfs_fs_info *fs_info, in btrfs_alloc_root() argument
1104 __setup_root(root, fs_info, objectid); in btrfs_alloc_root()
1110 struct btrfs_root *btrfs_alloc_dummy_root(struct btrfs_fs_info *fs_info) in btrfs_alloc_dummy_root() argument
1114 if (!fs_info) in btrfs_alloc_dummy_root()
1117 root = btrfs_alloc_root(fs_info, BTRFS_ROOT_TREE_OBJECTID, GFP_KERNEL); in btrfs_alloc_dummy_root()
1131 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_create_tree() local
1133 struct btrfs_root *tree_root = fs_info->tree_root; in btrfs_create_tree()
1144 root = btrfs_alloc_root(fs_info, objectid, GFP_KERNEL); in btrfs_create_tree()
1202 struct btrfs_fs_info *fs_info) in alloc_log_tree() argument
1207 root = btrfs_alloc_root(fs_info, BTRFS_TREE_LOG_OBJECTID, GFP_NOFS); in alloc_log_tree()
1240 struct btrfs_fs_info *fs_info) in btrfs_init_log_root_tree() argument
1244 log_root = alloc_log_tree(trans, fs_info); in btrfs_init_log_root_tree()
1247 WARN_ON(fs_info->log_root_tree); in btrfs_init_log_root_tree()
1248 fs_info->log_root_tree = log_root; in btrfs_init_log_root_tree()
1255 struct btrfs_fs_info *fs_info = root->fs_info; in btrfs_add_log_tree() local
1259 log_root = alloc_log_tree(trans, fs_info); in btrfs_add_log_tree()
1271 fs_info->nodesize); in btrfs_add_log_tree()
1289 struct btrfs_fs_info *fs_info = tree_root->fs_info; in read_tree_root_path() local
1294 root = btrfs_alloc_root(fs_info, key->objectid, GFP_NOFS); in read_tree_root_path()
1308 root->node = read_tree_block(fs_info, in read_tree_root_path()
1412 static struct btrfs_root *btrfs_lookup_fs_root(struct btrfs_fs_info *fs_info, in btrfs_lookup_fs_root() argument
1417 spin_lock(&fs_info->fs_roots_radix_lock); in btrfs_lookup_fs_root()
1418 root = radix_tree_lookup(&fs_info->fs_roots_radix, in btrfs_lookup_fs_root()
1422 spin_unlock(&fs_info->fs_roots_radix_lock); in btrfs_lookup_fs_root()
1426 static struct btrfs_root *btrfs_get_global_root(struct btrfs_fs_info *fs_info, in btrfs_get_global_root() argument
1430 return btrfs_grab_root(fs_info->tree_root); in btrfs_get_global_root()
1432 return btrfs_grab_root(fs_info->extent_root); in btrfs_get_global_root()
1434 return btrfs_grab_root(fs_info->chunk_root); in btrfs_get_global_root()
1436 return btrfs_grab_root(fs_info->dev_root); in btrfs_get_global_root()
1438 return btrfs_grab_root(fs_info->csum_root); in btrfs_get_global_root()
1440 return btrfs_grab_root(fs_info->quota_root) ? in btrfs_get_global_root()
1441 fs_info->quota_root : ERR_PTR(-ENOENT); in btrfs_get_global_root()
1443 return btrfs_grab_root(fs_info->uuid_root) ? in btrfs_get_global_root()
1444 fs_info->uuid_root : ERR_PTR(-ENOENT); in btrfs_get_global_root()
1446 return btrfs_grab_root(fs_info->free_space_root) ? in btrfs_get_global_root()
1447 fs_info->free_space_root : ERR_PTR(-ENOENT); in btrfs_get_global_root()
1451 int btrfs_insert_fs_root(struct btrfs_fs_info *fs_info, in btrfs_insert_fs_root() argument
1460 spin_lock(&fs_info->fs_roots_radix_lock); in btrfs_insert_fs_root()
1461 ret = radix_tree_insert(&fs_info->fs_roots_radix, in btrfs_insert_fs_root()
1468 spin_unlock(&fs_info->fs_roots_radix_lock); in btrfs_insert_fs_root()
1474 void btrfs_check_leaked_roots(struct btrfs_fs_info *fs_info) in btrfs_check_leaked_roots() argument
1479 while (!list_empty(&fs_info->allocated_roots)) { in btrfs_check_leaked_roots()
1482 root = list_first_entry(&fs_info->allocated_roots, in btrfs_check_leaked_roots()
1484 btrfs_err(fs_info, "leaked root %s refcount %d", in btrfs_check_leaked_roots()
1494 void btrfs_free_fs_info(struct btrfs_fs_info *fs_info) in btrfs_free_fs_info() argument
1496 percpu_counter_destroy(&fs_info->dirty_metadata_bytes); in btrfs_free_fs_info()
1497 percpu_counter_destroy(&fs_info->delalloc_bytes); in btrfs_free_fs_info()
1498 percpu_counter_destroy(&fs_info->dio_bytes); in btrfs_free_fs_info()
1499 percpu_counter_destroy(&fs_info->dev_replace.bio_counter); in btrfs_free_fs_info()
1500 btrfs_free_csum_hash(fs_info); in btrfs_free_fs_info()
1501 btrfs_free_stripe_hash_table(fs_info); in btrfs_free_fs_info()
1502 btrfs_free_ref_cache(fs_info); in btrfs_free_fs_info()
1503 kfree(fs_info->balance_ctl); in btrfs_free_fs_info()
1504 kfree(fs_info->delayed_root); in btrfs_free_fs_info()
1505 btrfs_put_root(fs_info->extent_root); in btrfs_free_fs_info()
1506 btrfs_put_root(fs_info->tree_root); in btrfs_free_fs_info()
1507 btrfs_put_root(fs_info->chunk_root); in btrfs_free_fs_info()
1508 btrfs_put_root(fs_info->dev_root); in btrfs_free_fs_info()
1509 btrfs_put_root(fs_info->csum_root); in btrfs_free_fs_info()
1510 btrfs_put_root(fs_info->quota_root); in btrfs_free_fs_info()
1511 btrfs_put_root(fs_info->uuid_root); in btrfs_free_fs_info()
1512 btrfs_put_root(fs_info->free_space_root); in btrfs_free_fs_info()
1513 btrfs_put_root(fs_info->fs_root); in btrfs_free_fs_info()
1514 btrfs_put_root(fs_info->data_reloc_root); in btrfs_free_fs_info()
1515 btrfs_check_leaked_roots(fs_info); in btrfs_free_fs_info()
1516 btrfs_extent_buffer_leak_debug_check(fs_info); in btrfs_free_fs_info()
1517 kfree(fs_info->super_copy); in btrfs_free_fs_info()
1518 kfree(fs_info->super_for_commit); in btrfs_free_fs_info()
1519 kvfree(fs_info); in btrfs_free_fs_info()
1541 static struct btrfs_root *btrfs_get_root_ref(struct btrfs_fs_info *fs_info, in btrfs_get_root_ref() argument
1550 root = btrfs_get_global_root(fs_info, objectid); in btrfs_get_root_ref()
1554 root = btrfs_lookup_fs_root(fs_info, objectid); in btrfs_get_root_ref()
1568 root = btrfs_read_tree_root(fs_info->tree_root, &key); in btrfs_get_root_ref()
1590 ret = btrfs_search_slot(NULL, fs_info->tree_root, &key, path, 0, 0); in btrfs_get_root_ref()
1597 ret = btrfs_insert_fs_root(fs_info, root); in btrfs_get_root_ref()
1625 struct btrfs_root *btrfs_get_fs_root(struct btrfs_fs_info *fs_info, in btrfs_get_fs_root() argument
1628 return btrfs_get_root_ref(fs_info, objectid, 0, check_ref); in btrfs_get_fs_root()
1639 struct btrfs_root *btrfs_get_new_fs_root(struct btrfs_fs_info *fs_info, in btrfs_get_new_fs_root() argument
1642 return btrfs_get_root_ref(fs_info, objectid, anon_dev, true); in btrfs_get_new_fs_root()
1659 struct btrfs_root *btrfs_get_fs_root_commit_root(struct btrfs_fs_info *fs_info, in btrfs_get_fs_root_commit_root() argument
1674 root = btrfs_get_global_root(fs_info, objectid); in btrfs_get_fs_root_commit_root()
1678 root = btrfs_lookup_fs_root(fs_info, objectid); in btrfs_get_fs_root_commit_root()
1685 root = read_tree_root_path(fs_info->tree_root, path, &key); in btrfs_get_fs_root_commit_root()
1713 struct btrfs_fs_info *fs_info = root->fs_info; in cleaner_kthread() local
1719 set_bit(BTRFS_FS_CLEANER_RUNNING, &fs_info->flags); in cleaner_kthread()
1722 if (btrfs_need_cleaner_sleep(fs_info)) in cleaner_kthread()
1729 if (!test_bit(BTRFS_FS_OPEN, &fs_info->flags)) in cleaner_kthread()
1732 if (!mutex_trylock(&fs_info->cleaner_mutex)) in cleaner_kthread()
1739 if (btrfs_need_cleaner_sleep(fs_info)) { in cleaner_kthread()
1740 mutex_unlock(&fs_info->cleaner_mutex); in cleaner_kthread()
1744 btrfs_run_delayed_iputs(fs_info); in cleaner_kthread()
1747 mutex_unlock(&fs_info->cleaner_mutex); in cleaner_kthread()
1753 btrfs_run_defrag_inodes(fs_info); in cleaner_kthread()
1763 btrfs_delete_unused_bgs(fs_info); in cleaner_kthread()
1765 clear_bit(BTRFS_FS_CLEANER_RUNNING, &fs_info->flags); in cleaner_kthread()
1781 struct btrfs_fs_info *fs_info = root->fs_info; in transaction_kthread() local
1791 delay = HZ * fs_info->commit_interval; in transaction_kthread()
1792 mutex_lock(&fs_info->transaction_kthread_mutex); in transaction_kthread()
1794 spin_lock(&fs_info->trans_lock); in transaction_kthread()
1795 cur = fs_info->running_transaction; in transaction_kthread()
1797 spin_unlock(&fs_info->trans_lock); in transaction_kthread()
1804 now - cur->start_time < fs_info->commit_interval)) { in transaction_kthread()
1805 spin_unlock(&fs_info->trans_lock); in transaction_kthread()
1810 spin_unlock(&fs_info->trans_lock); in transaction_kthread()
1825 wake_up_process(fs_info->cleaner_kthread); in transaction_kthread()
1826 mutex_unlock(&fs_info->transaction_kthread_mutex); in transaction_kthread()
1829 &fs_info->fs_state))) in transaction_kthread()
1830 btrfs_cleanup_transaction(fs_info); in transaction_kthread()
1832 (!btrfs_transaction_blocked(fs_info) || in transaction_kthread()
1954 static int read_backup_root(struct btrfs_fs_info *fs_info, u8 priority) in read_backup_root() argument
1956 int backup_index = find_newest_super_backup(fs_info); in read_backup_root()
1957 struct btrfs_super_block *super = fs_info->super_copy; in read_backup_root()
1990 static void btrfs_stop_all_workers(struct btrfs_fs_info *fs_info) in btrfs_stop_all_workers() argument
1992 btrfs_destroy_workqueue(fs_info->fixup_workers); in btrfs_stop_all_workers()
1993 btrfs_destroy_workqueue(fs_info->delalloc_workers); in btrfs_stop_all_workers()
1994 btrfs_destroy_workqueue(fs_info->workers); in btrfs_stop_all_workers()
1995 btrfs_destroy_workqueue(fs_info->endio_workers); in btrfs_stop_all_workers()
1996 btrfs_destroy_workqueue(fs_info->endio_raid56_workers); in btrfs_stop_all_workers()
1997 btrfs_destroy_workqueue(fs_info->rmw_workers); in btrfs_stop_all_workers()
1998 btrfs_destroy_workqueue(fs_info->endio_write_workers); in btrfs_stop_all_workers()
1999 btrfs_destroy_workqueue(fs_info->endio_freespace_worker); in btrfs_stop_all_workers()
2000 btrfs_destroy_workqueue(fs_info->delayed_workers); in btrfs_stop_all_workers()
2001 btrfs_destroy_workqueue(fs_info->caching_workers); in btrfs_stop_all_workers()
2002 btrfs_destroy_workqueue(fs_info->readahead_workers); in btrfs_stop_all_workers()
2003 btrfs_destroy_workqueue(fs_info->flush_workers); in btrfs_stop_all_workers()
2004 btrfs_destroy_workqueue(fs_info->qgroup_rescan_workers); in btrfs_stop_all_workers()
2005 if (fs_info->discard_ctl.discard_workers) in btrfs_stop_all_workers()
2006 destroy_workqueue(fs_info->discard_ctl.discard_workers); in btrfs_stop_all_workers()
2012 btrfs_destroy_workqueue(fs_info->endio_meta_workers); in btrfs_stop_all_workers()
2013 btrfs_destroy_workqueue(fs_info->endio_meta_write_workers); in btrfs_stop_all_workers()
2058 spin_lock(&root->fs_info->fs_roots_radix_lock); in btrfs_put_root()
2060 spin_unlock(&root->fs_info->fs_roots_radix_lock); in btrfs_put_root()
2066 void btrfs_free_fs_roots(struct btrfs_fs_info *fs_info) in btrfs_free_fs_roots() argument
2072 while (!list_empty(&fs_info->dead_roots)) { in btrfs_free_fs_roots()
2073 gang[0] = list_entry(fs_info->dead_roots.next, in btrfs_free_fs_roots()
2078 btrfs_drop_and_free_fs_root(fs_info, gang[0]); in btrfs_free_fs_roots()
2083 ret = radix_tree_gang_lookup(&fs_info->fs_roots_radix, in btrfs_free_fs_roots()
2089 btrfs_drop_and_free_fs_root(fs_info, gang[i]); in btrfs_free_fs_roots()
2093 static void btrfs_init_scrub(struct btrfs_fs_info *fs_info) in btrfs_init_scrub() argument
2095 mutex_init(&fs_info->scrub_lock); in btrfs_init_scrub()
2096 atomic_set(&fs_info->scrubs_running, 0); in btrfs_init_scrub()
2097 atomic_set(&fs_info->scrub_pause_req, 0); in btrfs_init_scrub()
2098 atomic_set(&fs_info->scrubs_paused, 0); in btrfs_init_scrub()
2099 atomic_set(&fs_info->scrub_cancel_req, 0); in btrfs_init_scrub()
2100 init_waitqueue_head(&fs_info->scrub_pause_wait); in btrfs_init_scrub()
2101 refcount_set(&fs_info->scrub_workers_refcnt, 0); in btrfs_init_scrub()
2104 static void btrfs_init_balance(struct btrfs_fs_info *fs_info) in btrfs_init_balance() argument
2106 spin_lock_init(&fs_info->balance_lock); in btrfs_init_balance()
2107 mutex_init(&fs_info->balance_mutex); in btrfs_init_balance()
2108 atomic_set(&fs_info->balance_pause_req, 0); in btrfs_init_balance()
2109 atomic_set(&fs_info->balance_cancel_req, 0); in btrfs_init_balance()
2110 fs_info->balance_ctl = NULL; in btrfs_init_balance()
2111 init_waitqueue_head(&fs_info->balance_wait_q); in btrfs_init_balance()
2114 static void btrfs_init_btree_inode(struct btrfs_fs_info *fs_info) in btrfs_init_btree_inode() argument
2116 struct inode *inode = fs_info->btree_inode; in btrfs_init_btree_inode()
2129 extent_io_tree_init(fs_info, &BTRFS_I(inode)->io_tree, in btrfs_init_btree_inode()
2134 BTRFS_I(inode)->root = btrfs_grab_root(fs_info->tree_root); in btrfs_init_btree_inode()
2140 static void btrfs_init_dev_replace_locks(struct btrfs_fs_info *fs_info) in btrfs_init_dev_replace_locks() argument
2142 mutex_init(&fs_info->dev_replace.lock_finishing_cancel_unmount); in btrfs_init_dev_replace_locks()
2143 init_rwsem(&fs_info->dev_replace.rwsem); in btrfs_init_dev_replace_locks()
2144 init_waitqueue_head(&fs_info->dev_replace.replace_wait); in btrfs_init_dev_replace_locks()
2147 static void btrfs_init_qgroup(struct btrfs_fs_info *fs_info) in btrfs_init_qgroup() argument
2149 spin_lock_init(&fs_info->qgroup_lock); in btrfs_init_qgroup()
2150 mutex_init(&fs_info->qgroup_ioctl_lock); in btrfs_init_qgroup()
2151 fs_info->qgroup_tree = RB_ROOT; in btrfs_init_qgroup()
2152 INIT_LIST_HEAD(&fs_info->dirty_qgroups); in btrfs_init_qgroup()
2153 fs_info->qgroup_seq = 1; in btrfs_init_qgroup()
2154 fs_info->qgroup_ulist = NULL; in btrfs_init_qgroup()
2155 fs_info->qgroup_rescan_running = false; in btrfs_init_qgroup()
2156 mutex_init(&fs_info->qgroup_rescan_lock); in btrfs_init_qgroup()
2159 static int btrfs_init_workqueues(struct btrfs_fs_info *fs_info, in btrfs_init_workqueues() argument
2162 u32 max_active = fs_info->thread_pool_size; in btrfs_init_workqueues()
2165 fs_info->workers = in btrfs_init_workqueues()
2166 btrfs_alloc_workqueue(fs_info, "worker", in btrfs_init_workqueues()
2169 fs_info->delalloc_workers = in btrfs_init_workqueues()
2170 btrfs_alloc_workqueue(fs_info, "delalloc", in btrfs_init_workqueues()
2173 fs_info->flush_workers = in btrfs_init_workqueues()
2174 btrfs_alloc_workqueue(fs_info, "flush_delalloc", in btrfs_init_workqueues()
2177 fs_info->caching_workers = in btrfs_init_workqueues()
2178 btrfs_alloc_workqueue(fs_info, "cache", flags, max_active, 0); in btrfs_init_workqueues()
2180 fs_info->fixup_workers = in btrfs_init_workqueues()
2181 btrfs_alloc_workqueue(fs_info, "fixup", flags, 1, 0); in btrfs_init_workqueues()
2187 fs_info->endio_workers = in btrfs_init_workqueues()
2188 btrfs_alloc_workqueue(fs_info, "endio", flags, max_active, 4); in btrfs_init_workqueues()
2189 fs_info->endio_meta_workers = in btrfs_init_workqueues()
2190 btrfs_alloc_workqueue(fs_info, "endio-meta", flags, in btrfs_init_workqueues()
2192 fs_info->endio_meta_write_workers = in btrfs_init_workqueues()
2193 btrfs_alloc_workqueue(fs_info, "endio-meta-write", flags, in btrfs_init_workqueues()
2195 fs_info->endio_raid56_workers = in btrfs_init_workqueues()
2196 btrfs_alloc_workqueue(fs_info, "endio-raid56", flags, in btrfs_init_workqueues()
2198 fs_info->rmw_workers = in btrfs_init_workqueues()
2199 btrfs_alloc_workqueue(fs_info, "rmw", flags, max_active, 2); in btrfs_init_workqueues()
2200 fs_info->endio_write_workers = in btrfs_init_workqueues()
2201 btrfs_alloc_workqueue(fs_info, "endio-write", flags, in btrfs_init_workqueues()
2203 fs_info->endio_freespace_worker = in btrfs_init_workqueues()
2204 btrfs_alloc_workqueue(fs_info, "freespace-write", flags, in btrfs_init_workqueues()
2206 fs_info->delayed_workers = in btrfs_init_workqueues()
2207 btrfs_alloc_workqueue(fs_info, "delayed-meta", flags, in btrfs_init_workqueues()
2209 fs_info->readahead_workers = in btrfs_init_workqueues()
2210 btrfs_alloc_workqueue(fs_info, "readahead", flags, in btrfs_init_workqueues()
2212 fs_info->qgroup_rescan_workers = in btrfs_init_workqueues()
2213 btrfs_alloc_workqueue(fs_info, "qgroup-rescan", flags, 1, 0); in btrfs_init_workqueues()
2214 fs_info->discard_ctl.discard_workers = in btrfs_init_workqueues()
2217 if (!(fs_info->workers && fs_info->delalloc_workers && in btrfs_init_workqueues()
2218 fs_info->flush_workers && in btrfs_init_workqueues()
2219 fs_info->endio_workers && fs_info->endio_meta_workers && in btrfs_init_workqueues()
2220 fs_info->endio_meta_write_workers && in btrfs_init_workqueues()
2221 fs_info->endio_write_workers && fs_info->endio_raid56_workers && in btrfs_init_workqueues()
2222 fs_info->endio_freespace_worker && fs_info->rmw_workers && in btrfs_init_workqueues()
2223 fs_info->caching_workers && fs_info->readahead_workers && in btrfs_init_workqueues()
2224 fs_info->fixup_workers && fs_info->delayed_workers && in btrfs_init_workqueues()
2225 fs_info->qgroup_rescan_workers && in btrfs_init_workqueues()
2226 fs_info->discard_ctl.discard_workers)) { in btrfs_init_workqueues()
2233 static int btrfs_init_csum_hash(struct btrfs_fs_info *fs_info, u16 csum_type) in btrfs_init_csum_hash() argument
2241 btrfs_err(fs_info, "error allocating %s hash for checksum", in btrfs_init_csum_hash()
2246 fs_info->csum_shash = csum_shash; in btrfs_init_csum_hash()
2251 static int btrfs_replay_log(struct btrfs_fs_info *fs_info, in btrfs_replay_log() argument
2256 struct btrfs_super_block *disk_super = fs_info->super_copy; in btrfs_replay_log()
2261 btrfs_warn(fs_info, "log replay required on RO media"); in btrfs_replay_log()
2265 log_tree_root = btrfs_alloc_root(fs_info, BTRFS_TREE_LOG_OBJECTID, in btrfs_replay_log()
2270 log_tree_root->node = read_tree_block(fs_info, bytenr, in btrfs_replay_log()
2271 fs_info->generation + 1, in btrfs_replay_log()
2274 btrfs_warn(fs_info, "failed to read log tree"); in btrfs_replay_log()
2280 btrfs_err(fs_info, "failed to read log tree"); in btrfs_replay_log()
2287 btrfs_handle_fs_error(fs_info, ret, in btrfs_replay_log()
2293 if (sb_rdonly(fs_info->sb)) { in btrfs_replay_log()
2294 ret = btrfs_commit_super(fs_info); in btrfs_replay_log()
2302 static int btrfs_read_roots(struct btrfs_fs_info *fs_info) in btrfs_read_roots() argument
2304 struct btrfs_root *tree_root = fs_info->tree_root; in btrfs_read_roots()
2309 BUG_ON(!fs_info->tree_root); in btrfs_read_roots()
2321 fs_info->extent_root = root; in btrfs_read_roots()
2330 fs_info->dev_root = root; in btrfs_read_roots()
2331 btrfs_init_devices_late(fs_info); in btrfs_read_roots()
2340 fs_info->csum_root = root; in btrfs_read_roots()
2346 root = btrfs_get_fs_root(tree_root->fs_info, in btrfs_read_roots()
2353 fs_info->data_reloc_root = root; in btrfs_read_roots()
2359 set_bit(BTRFS_FS_QUOTA_ENABLED, &fs_info->flags); in btrfs_read_roots()
2360 fs_info->quota_root = root; in btrfs_read_roots()
2371 fs_info->uuid_root = root; in btrfs_read_roots()
2374 if (btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE)) { in btrfs_read_roots()
2382 fs_info->free_space_root = root; in btrfs_read_roots()
2387 btrfs_warn(fs_info, "failed to read root (objectid=%llu): %d", in btrfs_read_roots()
2402 static int validate_super(struct btrfs_fs_info *fs_info, in validate_super() argument
2410 btrfs_err(fs_info, "no valid FS found"); in validate_super()
2414 btrfs_err(fs_info, "unrecognized or unsupported super flag: %llu", in validate_super()
2419 btrfs_err(fs_info, "tree_root level too big: %d >= %d", in validate_super()
2424 btrfs_err(fs_info, "chunk_root level too big: %d >= %d", in validate_super()
2429 btrfs_err(fs_info, "log_root level too big: %d >= %d", in validate_super()
2440 btrfs_err(fs_info, "invalid sectorsize %llu", sectorsize); in validate_super()
2445 btrfs_err(fs_info, in validate_super()
2452 btrfs_err(fs_info, "invalid nodesize %llu", nodesize); in validate_super()
2456 btrfs_err(fs_info, "invalid leafsize %u, should be %llu", in validate_super()
2463 btrfs_warn(fs_info, "tree_root block unaligned: %llu", in validate_super()
2468 btrfs_warn(fs_info, "chunk_root block unaligned: %llu", in validate_super()
2473 btrfs_warn(fs_info, "log_root block unaligned: %llu", in validate_super()
2478 if (memcmp(fs_info->fs_devices->fsid, fs_info->super_copy->fsid, in validate_super()
2480 btrfs_err(fs_info, in validate_super()
2482 fs_info->super_copy->fsid, fs_info->fs_devices->fsid); in validate_super()
2486 if (btrfs_fs_incompat(fs_info, METADATA_UUID) && in validate_super()
2487 memcmp(fs_info->fs_devices->metadata_uuid, in validate_super()
2488 fs_info->super_copy->metadata_uuid, BTRFS_FSID_SIZE)) { in validate_super()
2489 btrfs_err(fs_info, in validate_super()
2491 fs_info->super_copy->metadata_uuid, in validate_super()
2492 fs_info->fs_devices->metadata_uuid); in validate_super()
2496 if (memcmp(fs_info->fs_devices->metadata_uuid, sb->dev_item.fsid, in validate_super()
2498 btrfs_err(fs_info, in validate_super()
2500 fs_info->fs_devices->metadata_uuid, sb->dev_item.fsid); in validate_super()
2509 btrfs_err(fs_info, "bytes_used is too small %llu", in validate_super()
2514 btrfs_err(fs_info, "invalid stripesize %u", in validate_super()
2519 btrfs_warn(fs_info, "suspicious number of devices: %llu", in validate_super()
2522 btrfs_err(fs_info, "number of devices is 0"); in validate_super()
2528 btrfs_err(fs_info, "super offset mismatch %llu != %u", in validate_super()
2538 btrfs_err(fs_info, "system chunk array too big %u > %u", in validate_super()
2545 btrfs_err(fs_info, "system chunk array too small %u < %zu", in validate_super()
2557 btrfs_warn(fs_info, in validate_super()
2563 btrfs_warn(fs_info, in validate_super()
2576 static int btrfs_validate_mount_super(struct btrfs_fs_info *fs_info) in btrfs_validate_mount_super() argument
2578 return validate_super(fs_info, fs_info->super_copy, 0); in btrfs_validate_mount_super()
2587 static int btrfs_validate_write_super(struct btrfs_fs_info *fs_info, in btrfs_validate_write_super() argument
2592 ret = validate_super(fs_info, sb, -1); in btrfs_validate_write_super()
2597 btrfs_err(fs_info, "invalid csum type, has %u want %u", in btrfs_validate_write_super()
2603 btrfs_err(fs_info, in btrfs_validate_write_super()
2611 btrfs_err(fs_info, in btrfs_validate_write_super()
2616 static int __cold init_tree_roots(struct btrfs_fs_info *fs_info) in init_tree_roots() argument
2618 int backup_index = find_newest_super_backup(fs_info); in init_tree_roots()
2619 struct btrfs_super_block *sb = fs_info->super_copy; in init_tree_roots()
2620 struct btrfs_root *tree_root = fs_info->tree_root; in init_tree_roots()
2634 if (!btrfs_test_opt(fs_info, USEBACKUPROOT)) in init_tree_roots()
2637 free_root_pointers(fs_info, 0); in init_tree_roots()
2646 btrfs_set_opt(fs_info->mount_opt, CLEAR_CACHE); in init_tree_roots()
2648 ret = read_backup_root(fs_info, i); in init_tree_roots()
2655 tree_root->node = read_tree_block(fs_info, btrfs_super_root(sb), in init_tree_roots()
2661 btrfs_warn(fs_info, "couldn't read tree root"); in init_tree_roots()
2667 btrfs_warn(fs_info, "error while reading tree root"); in init_tree_roots()
2688 ret = btrfs_read_roots(fs_info); in init_tree_roots()
2695 fs_info->generation = generation; in init_tree_roots()
2696 fs_info->last_trans_committed = generation; in init_tree_roots()
2700 fs_info->backup_root_index = 0; in init_tree_roots()
2702 fs_info->backup_root_index = backup_index + 1; in init_tree_roots()
2703 fs_info->backup_root_index %= BTRFS_NUM_BACKUP_ROOTS; in init_tree_roots()
2711 void btrfs_init_fs_info(struct btrfs_fs_info *fs_info) in btrfs_init_fs_info() argument
2713 INIT_RADIX_TREE(&fs_info->fs_roots_radix, GFP_ATOMIC); in btrfs_init_fs_info()
2714 INIT_RADIX_TREE(&fs_info->buffer_radix, GFP_ATOMIC); in btrfs_init_fs_info()
2715 INIT_LIST_HEAD(&fs_info->trans_list); in btrfs_init_fs_info()
2716 INIT_LIST_HEAD(&fs_info->dead_roots); in btrfs_init_fs_info()
2717 INIT_LIST_HEAD(&fs_info->delayed_iputs); in btrfs_init_fs_info()
2718 INIT_LIST_HEAD(&fs_info->delalloc_roots); in btrfs_init_fs_info()
2719 INIT_LIST_HEAD(&fs_info->caching_block_groups); in btrfs_init_fs_info()
2720 spin_lock_init(&fs_info->delalloc_root_lock); in btrfs_init_fs_info()
2721 spin_lock_init(&fs_info->trans_lock); in btrfs_init_fs_info()
2722 spin_lock_init(&fs_info->fs_roots_radix_lock); in btrfs_init_fs_info()
2723 spin_lock_init(&fs_info->delayed_iput_lock); in btrfs_init_fs_info()
2724 spin_lock_init(&fs_info->defrag_inodes_lock); in btrfs_init_fs_info()
2725 spin_lock_init(&fs_info->super_lock); in btrfs_init_fs_info()
2726 spin_lock_init(&fs_info->buffer_lock); in btrfs_init_fs_info()
2727 spin_lock_init(&fs_info->unused_bgs_lock); in btrfs_init_fs_info()
2728 rwlock_init(&fs_info->tree_mod_log_lock); in btrfs_init_fs_info()
2729 mutex_init(&fs_info->unused_bg_unpin_mutex); in btrfs_init_fs_info()
2730 mutex_init(&fs_info->delete_unused_bgs_mutex); in btrfs_init_fs_info()
2731 mutex_init(&fs_info->reloc_mutex); in btrfs_init_fs_info()
2732 mutex_init(&fs_info->delalloc_root_mutex); in btrfs_init_fs_info()
2733 seqlock_init(&fs_info->profiles_lock); in btrfs_init_fs_info()
2735 INIT_LIST_HEAD(&fs_info->dirty_cowonly_roots); in btrfs_init_fs_info()
2736 INIT_LIST_HEAD(&fs_info->space_info); in btrfs_init_fs_info()
2737 INIT_LIST_HEAD(&fs_info->tree_mod_seq_list); in btrfs_init_fs_info()
2738 INIT_LIST_HEAD(&fs_info->unused_bgs); in btrfs_init_fs_info()
2740 INIT_LIST_HEAD(&fs_info->allocated_roots); in btrfs_init_fs_info()
2741 INIT_LIST_HEAD(&fs_info->allocated_ebs); in btrfs_init_fs_info()
2742 spin_lock_init(&fs_info->eb_leak_lock); in btrfs_init_fs_info()
2744 extent_map_tree_init(&fs_info->mapping_tree); in btrfs_init_fs_info()
2745 btrfs_init_block_rsv(&fs_info->global_block_rsv, in btrfs_init_fs_info()
2747 btrfs_init_block_rsv(&fs_info->trans_block_rsv, BTRFS_BLOCK_RSV_TRANS); in btrfs_init_fs_info()
2748 btrfs_init_block_rsv(&fs_info->chunk_block_rsv, BTRFS_BLOCK_RSV_CHUNK); in btrfs_init_fs_info()
2749 btrfs_init_block_rsv(&fs_info->empty_block_rsv, BTRFS_BLOCK_RSV_EMPTY); in btrfs_init_fs_info()
2750 btrfs_init_block_rsv(&fs_info->delayed_block_rsv, in btrfs_init_fs_info()
2752 btrfs_init_block_rsv(&fs_info->delayed_refs_rsv, in btrfs_init_fs_info()
2755 atomic_set(&fs_info->async_delalloc_pages, 0); in btrfs_init_fs_info()
2756 atomic_set(&fs_info->defrag_running, 0); in btrfs_init_fs_info()
2757 atomic_set(&fs_info->reada_works_cnt, 0); in btrfs_init_fs_info()
2758 atomic_set(&fs_info->nr_delayed_iputs, 0); in btrfs_init_fs_info()
2759 atomic64_set(&fs_info->tree_mod_seq, 0); in btrfs_init_fs_info()
2760 fs_info->max_inline = BTRFS_DEFAULT_MAX_INLINE; in btrfs_init_fs_info()
2761 fs_info->metadata_ratio = 0; in btrfs_init_fs_info()
2762 fs_info->defrag_inodes = RB_ROOT; in btrfs_init_fs_info()
2763 atomic64_set(&fs_info->free_chunk_space, 0); in btrfs_init_fs_info()
2764 fs_info->tree_mod_log = RB_ROOT; in btrfs_init_fs_info()
2765 fs_info->commit_interval = BTRFS_DEFAULT_COMMIT_INTERVAL; in btrfs_init_fs_info()
2766 fs_info->avg_delayed_ref_runtime = NSEC_PER_SEC >> 6; /* div by 64 */ in btrfs_init_fs_info()
2768 INIT_RADIX_TREE(&fs_info->reada_tree, GFP_NOFS & ~__GFP_DIRECT_RECLAIM); in btrfs_init_fs_info()
2769 spin_lock_init(&fs_info->reada_lock); in btrfs_init_fs_info()
2770 btrfs_init_ref_verify(fs_info); in btrfs_init_fs_info()
2772 fs_info->thread_pool_size = min_t(unsigned long, in btrfs_init_fs_info()
2775 INIT_LIST_HEAD(&fs_info->ordered_roots); in btrfs_init_fs_info()
2776 spin_lock_init(&fs_info->ordered_root_lock); in btrfs_init_fs_info()
2778 btrfs_init_scrub(fs_info); in btrfs_init_fs_info()
2780 fs_info->check_integrity_print_mask = 0; in btrfs_init_fs_info()
2782 btrfs_init_balance(fs_info); in btrfs_init_fs_info()
2783 btrfs_init_async_reclaim_work(fs_info); in btrfs_init_fs_info()
2785 spin_lock_init(&fs_info->block_group_cache_lock); in btrfs_init_fs_info()
2786 fs_info->block_group_cache_tree = RB_ROOT; in btrfs_init_fs_info()
2787 fs_info->first_logical_byte = (u64)-1; in btrfs_init_fs_info()
2789 extent_io_tree_init(fs_info, &fs_info->excluded_extents, in btrfs_init_fs_info()
2791 set_bit(BTRFS_FS_BARRIER, &fs_info->flags); in btrfs_init_fs_info()
2793 mutex_init(&fs_info->ordered_operations_mutex); in btrfs_init_fs_info()
2794 mutex_init(&fs_info->tree_log_mutex); in btrfs_init_fs_info()
2795 mutex_init(&fs_info->chunk_mutex); in btrfs_init_fs_info()
2796 mutex_init(&fs_info->transaction_kthread_mutex); in btrfs_init_fs_info()
2797 mutex_init(&fs_info->cleaner_mutex); in btrfs_init_fs_info()
2798 mutex_init(&fs_info->ro_block_group_mutex); in btrfs_init_fs_info()
2799 init_rwsem(&fs_info->commit_root_sem); in btrfs_init_fs_info()
2800 init_rwsem(&fs_info->cleanup_work_sem); in btrfs_init_fs_info()
2801 init_rwsem(&fs_info->subvol_sem); in btrfs_init_fs_info()
2802 sema_init(&fs_info->uuid_tree_rescan_sem, 1); in btrfs_init_fs_info()
2804 btrfs_init_dev_replace_locks(fs_info); in btrfs_init_fs_info()
2805 btrfs_init_qgroup(fs_info); in btrfs_init_fs_info()
2806 btrfs_discard_init(fs_info); in btrfs_init_fs_info()
2808 btrfs_init_free_cluster(&fs_info->meta_alloc_cluster); in btrfs_init_fs_info()
2809 btrfs_init_free_cluster(&fs_info->data_alloc_cluster); in btrfs_init_fs_info()
2811 init_waitqueue_head(&fs_info->transaction_throttle); in btrfs_init_fs_info()
2812 init_waitqueue_head(&fs_info->transaction_wait); in btrfs_init_fs_info()
2813 init_waitqueue_head(&fs_info->transaction_blocked_wait); in btrfs_init_fs_info()
2814 init_waitqueue_head(&fs_info->async_submit_wait); in btrfs_init_fs_info()
2815 init_waitqueue_head(&fs_info->delayed_iputs_wait); in btrfs_init_fs_info()
2818 fs_info->nodesize = 4096; in btrfs_init_fs_info()
2819 fs_info->sectorsize = 4096; in btrfs_init_fs_info()
2820 fs_info->stripesize = 4096; in btrfs_init_fs_info()
2822 spin_lock_init(&fs_info->swapfile_pins_lock); in btrfs_init_fs_info()
2823 fs_info->swapfile_pins = RB_ROOT; in btrfs_init_fs_info()
2825 fs_info->send_in_progress = 0; in btrfs_init_fs_info()
2828 static int init_mount_fs_info(struct btrfs_fs_info *fs_info, struct super_block *sb) in init_mount_fs_info() argument
2832 fs_info->sb = sb; in init_mount_fs_info()
2836 ret = percpu_counter_init(&fs_info->dio_bytes, 0, GFP_KERNEL); in init_mount_fs_info()
2840 ret = percpu_counter_init(&fs_info->dirty_metadata_bytes, 0, GFP_KERNEL); in init_mount_fs_info()
2844 fs_info->dirty_metadata_batch = PAGE_SIZE * in init_mount_fs_info()
2847 ret = percpu_counter_init(&fs_info->delalloc_bytes, 0, GFP_KERNEL); in init_mount_fs_info()
2851 ret = percpu_counter_init(&fs_info->dev_replace.bio_counter, 0, in init_mount_fs_info()
2856 fs_info->delayed_root = kmalloc(sizeof(struct btrfs_delayed_root), in init_mount_fs_info()
2858 if (!fs_info->delayed_root) in init_mount_fs_info()
2860 btrfs_init_delayed_root(fs_info->delayed_root); in init_mount_fs_info()
2862 return btrfs_alloc_stripe_hash_table(fs_info); in init_mount_fs_info()
2867 struct btrfs_fs_info *fs_info = (struct btrfs_fs_info *)data; in btrfs_uuid_rescan_kthread() local
2875 ret = btrfs_uuid_tree_iterate(fs_info); in btrfs_uuid_rescan_kthread()
2878 btrfs_warn(fs_info, "iterating uuid_tree failed %d", in btrfs_uuid_rescan_kthread()
2880 up(&fs_info->uuid_tree_rescan_sem); in btrfs_uuid_rescan_kthread()
2886 static int btrfs_check_uuid_tree(struct btrfs_fs_info *fs_info) in btrfs_check_uuid_tree() argument
2890 down(&fs_info->uuid_tree_rescan_sem); in btrfs_check_uuid_tree()
2891 task = kthread_run(btrfs_uuid_rescan_kthread, fs_info, "btrfs-uuid"); in btrfs_check_uuid_tree()
2894 btrfs_warn(fs_info, "failed to start uuid_rescan task"); in btrfs_check_uuid_tree()
2895 up(&fs_info->uuid_tree_rescan_sem); in btrfs_check_uuid_tree()
2912 struct btrfs_fs_info *fs_info = btrfs_sb(sb); in open_ctree() local
2920 ret = init_mount_fs_info(fs_info, sb); in open_ctree()
2927 tree_root = btrfs_alloc_root(fs_info, BTRFS_ROOT_TREE_OBJECTID, in open_ctree()
2929 fs_info->tree_root = tree_root; in open_ctree()
2930 chunk_root = btrfs_alloc_root(fs_info, BTRFS_CHUNK_TREE_OBJECTID, in open_ctree()
2932 fs_info->chunk_root = chunk_root; in open_ctree()
2938 fs_info->btree_inode = new_inode(sb); in open_ctree()
2939 if (!fs_info->btree_inode) { in open_ctree()
2943 mapping_set_gfp_mask(fs_info->btree_inode->i_mapping, GFP_NOFS); in open_ctree()
2944 btrfs_init_btree_inode(fs_info); in open_ctree()
2963 btrfs_err(fs_info, "unsupported checksum algorithm: %u", in open_ctree()
2970 ret = btrfs_init_csum_hash(fs_info, csum_type); in open_ctree()
2981 if (btrfs_check_super_csum(fs_info, (u8 *)disk_super)) { in open_ctree()
2982 btrfs_err(fs_info, "superblock checksum mismatch"); in open_ctree()
2993 memcpy(fs_info->super_copy, disk_super, sizeof(*fs_info->super_copy)); in open_ctree()
2996 disk_super = fs_info->super_copy; in open_ctree()
3003 btrfs_info(fs_info, in open_ctree()
3007 memcpy(fs_info->super_for_commit, fs_info->super_copy, in open_ctree()
3008 sizeof(*fs_info->super_for_commit)); in open_ctree()
3010 ret = btrfs_validate_mount_super(fs_info); in open_ctree()
3012 btrfs_err(fs_info, "superblock contains fatal errors"); in open_ctree()
3022 set_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state); in open_ctree()
3028 fs_info->compress_type = BTRFS_COMPRESS_ZLIB; in open_ctree()
3036 btrfs_info(fs_info, in open_ctree()
3045 fs_info->dirty_metadata_batch = nodesize * (1 + ilog2(nr_cpu_ids)); in open_ctree()
3046 fs_info->delalloc_batch = sectorsize * 512 * (1 + ilog2(nr_cpu_ids)); in open_ctree()
3049 fs_info->nodesize = nodesize; in open_ctree()
3050 fs_info->sectorsize = sectorsize; in open_ctree()
3051 fs_info->stripesize = stripesize; in open_ctree()
3053 ret = btrfs_parse_options(fs_info, options, sb->s_flags); in open_ctree()
3062 btrfs_err(fs_info, in open_ctree()
3071 if (fs_info->compress_type == BTRFS_COMPRESS_LZO) in open_ctree()
3073 else if (fs_info->compress_type == BTRFS_COMPRESS_ZSTD) in open_ctree()
3077 btrfs_info(fs_info, "has skinny extents"); in open_ctree()
3085 btrfs_err(fs_info, in open_ctree()
3100 btrfs_err(fs_info, in open_ctree()
3107 ret = btrfs_init_workqueues(fs_info, fs_devices); in open_ctree()
3118 memcpy(&sb->s_uuid, fs_info->fs_devices->fsid, BTRFS_FSID_SIZE); in open_ctree()
3120 mutex_lock(&fs_info->chunk_mutex); in open_ctree()
3121 ret = btrfs_read_sys_array(fs_info); in open_ctree()
3122 mutex_unlock(&fs_info->chunk_mutex); in open_ctree()
3124 btrfs_err(fs_info, "failed to read the system array: %d", ret); in open_ctree()
3131 chunk_root->node = read_tree_block(fs_info, in open_ctree()
3136 btrfs_err(fs_info, "failed to read chunk root"); in open_ctree()
3145 read_extent_buffer(chunk_root->node, fs_info->chunk_tree_uuid, in open_ctree()
3149 ret = btrfs_read_chunk_tree(fs_info); in open_ctree()
3151 btrfs_err(fs_info, "failed to read chunk tree: %d", ret); in open_ctree()
3162 btrfs_err(fs_info, "failed to read devices"); in open_ctree()
3166 ret = init_tree_roots(fs_info); in open_ctree()
3178 if (fs_info->uuid_root && !btrfs_test_opt(fs_info, RESCAN_UUID_TREE) && in open_ctree()
3179 fs_info->generation == btrfs_super_uuid_tree_generation(disk_super)) in open_ctree()
3180 set_bit(BTRFS_FS_UPDATE_UUID_TREE_GEN, &fs_info->flags); in open_ctree()
3182 ret = btrfs_verify_dev_extents(fs_info); in open_ctree()
3184 btrfs_err(fs_info, in open_ctree()
3189 ret = btrfs_recover_balance(fs_info); in open_ctree()
3191 btrfs_err(fs_info, "failed to recover balance: %d", ret); in open_ctree()
3195 ret = btrfs_init_dev_stats(fs_info); in open_ctree()
3197 btrfs_err(fs_info, "failed to init dev_stats: %d", ret); in open_ctree()
3201 ret = btrfs_init_dev_replace(fs_info); in open_ctree()
3203 btrfs_err(fs_info, "failed to init dev_replace: %d", ret); in open_ctree()
3211 btrfs_err(fs_info, "failed to init sysfs fsid interface: %d", in open_ctree()
3216 ret = btrfs_sysfs_add_mounted(fs_info); in open_ctree()
3218 btrfs_err(fs_info, "failed to init sysfs interface: %d", ret); in open_ctree()
3222 ret = btrfs_init_space_info(fs_info); in open_ctree()
3224 btrfs_err(fs_info, "failed to initialize space info: %d", ret); in open_ctree()
3228 ret = btrfs_read_block_groups(fs_info); in open_ctree()
3230 btrfs_err(fs_info, "failed to read block groups: %d", ret); in open_ctree()
3234 if (!sb_rdonly(sb) && fs_info->fs_devices->missing_devices && in open_ctree()
3235 !btrfs_check_rw_degradable(fs_info, NULL)) { in open_ctree()
3236 btrfs_warn(fs_info, in open_ctree()
3241 fs_info->cleaner_kthread = kthread_run(cleaner_kthread, tree_root, in open_ctree()
3243 if (IS_ERR(fs_info->cleaner_kthread)) in open_ctree()
3246 fs_info->transaction_kthread = kthread_run(transaction_kthread, in open_ctree()
3249 if (IS_ERR(fs_info->transaction_kthread)) in open_ctree()
3252 if (!btrfs_test_opt(fs_info, NOSSD) && in open_ctree()
3253 !fs_info->fs_devices->rotating) { in open_ctree()
3254 btrfs_set_and_info(fs_info, SSD, "enabling ssd optimizations"); in open_ctree()
3261 btrfs_apply_pending_changes(fs_info); in open_ctree()
3264 if (btrfs_test_opt(fs_info, CHECK_INTEGRITY)) { in open_ctree()
3265 ret = btrfsic_mount(fs_info, fs_devices, in open_ctree()
3266 btrfs_test_opt(fs_info, in open_ctree()
3269 fs_info->check_integrity_print_mask); in open_ctree()
3271 btrfs_warn(fs_info, in open_ctree()
3276 ret = btrfs_read_qgroup_config(fs_info); in open_ctree()
3280 if (btrfs_build_ref_tree(fs_info)) in open_ctree()
3281 btrfs_err(fs_info, "couldn't build ref tree"); in open_ctree()
3285 !btrfs_test_opt(fs_info, NOLOGREPLAY)) { in open_ctree()
3286 btrfs_info(fs_info, "start tree-log replay"); in open_ctree()
3287 ret = btrfs_replay_log(fs_info, fs_devices); in open_ctree()
3294 ret = btrfs_find_orphan_roots(fs_info); in open_ctree()
3299 ret = btrfs_cleanup_fs_roots(fs_info); in open_ctree()
3303 mutex_lock(&fs_info->cleaner_mutex); in open_ctree()
3305 mutex_unlock(&fs_info->cleaner_mutex); in open_ctree()
3307 btrfs_warn(fs_info, "failed to recover relocation: %d", in open_ctree()
3314 fs_info->fs_root = btrfs_get_fs_root(fs_info, BTRFS_FS_TREE_OBJECTID, true); in open_ctree()
3315 if (IS_ERR(fs_info->fs_root)) { in open_ctree()
3316 err = PTR_ERR(fs_info->fs_root); in open_ctree()
3317 btrfs_warn(fs_info, "failed to read fs tree: %d", err); in open_ctree()
3318 fs_info->fs_root = NULL; in open_ctree()
3325 if (btrfs_test_opt(fs_info, CLEAR_CACHE) && in open_ctree()
3326 btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE)) { in open_ctree()
3328 } else if (btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE) && in open_ctree()
3329 !btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE_VALID)) { in open_ctree()
3330 btrfs_warn(fs_info, "free space tree is invalid"); in open_ctree()
3335 btrfs_info(fs_info, "clearing free space tree"); in open_ctree()
3336 ret = btrfs_clear_free_space_tree(fs_info); in open_ctree()
3338 btrfs_warn(fs_info, in open_ctree()
3340 close_ctree(fs_info); in open_ctree()
3345 if (btrfs_test_opt(fs_info, FREE_SPACE_TREE) && in open_ctree()
3346 !btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE)) { in open_ctree()
3347 btrfs_info(fs_info, "creating free space tree"); in open_ctree()
3348 ret = btrfs_create_free_space_tree(fs_info); in open_ctree()
3350 btrfs_warn(fs_info, in open_ctree()
3352 close_ctree(fs_info); in open_ctree()
3357 down_read(&fs_info->cleanup_work_sem); in open_ctree()
3358 if ((ret = btrfs_orphan_cleanup(fs_info->fs_root)) || in open_ctree()
3359 (ret = btrfs_orphan_cleanup(fs_info->tree_root))) { in open_ctree()
3360 up_read(&fs_info->cleanup_work_sem); in open_ctree()
3361 close_ctree(fs_info); in open_ctree()
3364 up_read(&fs_info->cleanup_work_sem); in open_ctree()
3366 ret = btrfs_resume_balance_async(fs_info); in open_ctree()
3368 btrfs_warn(fs_info, "failed to resume balance: %d", ret); in open_ctree()
3369 close_ctree(fs_info); in open_ctree()
3373 ret = btrfs_resume_dev_replace_async(fs_info); in open_ctree()
3375 btrfs_warn(fs_info, "failed to resume device replace: %d", ret); in open_ctree()
3376 close_ctree(fs_info); in open_ctree()
3380 btrfs_qgroup_rescan_resume(fs_info); in open_ctree()
3381 btrfs_discard_resume(fs_info); in open_ctree()
3383 if (!fs_info->uuid_root) { in open_ctree()
3384 btrfs_info(fs_info, "creating UUID tree"); in open_ctree()
3385 ret = btrfs_create_uuid_tree(fs_info); in open_ctree()
3387 btrfs_warn(fs_info, in open_ctree()
3389 close_ctree(fs_info); in open_ctree()
3392 } else if (btrfs_test_opt(fs_info, RESCAN_UUID_TREE) || in open_ctree()
3393 fs_info->generation != in open_ctree()
3395 btrfs_info(fs_info, "checking UUID tree"); in open_ctree()
3396 ret = btrfs_check_uuid_tree(fs_info); in open_ctree()
3398 btrfs_warn(fs_info, in open_ctree()
3400 close_ctree(fs_info); in open_ctree()
3404 set_bit(BTRFS_FS_OPEN, &fs_info->flags); in open_ctree()
3410 btrfs_clear_opt(fs_info->mount_opt, USEBACKUPROOT); in open_ctree()
3415 btrfs_free_qgroup_config(fs_info); in open_ctree()
3417 kthread_stop(fs_info->transaction_kthread); in open_ctree()
3418 btrfs_cleanup_transaction(fs_info); in open_ctree()
3419 btrfs_free_fs_roots(fs_info); in open_ctree()
3421 kthread_stop(fs_info->cleaner_kthread); in open_ctree()
3427 filemap_write_and_wait(fs_info->btree_inode->i_mapping); in open_ctree()
3430 btrfs_sysfs_remove_mounted(fs_info); in open_ctree()
3433 btrfs_sysfs_remove_fsid(fs_info->fs_devices); in open_ctree()
3436 btrfs_put_block_group_cache(fs_info); in open_ctree()
3439 if (fs_info->data_reloc_root) in open_ctree()
3440 btrfs_drop_and_free_fs_root(fs_info, fs_info->data_reloc_root); in open_ctree()
3441 free_root_pointers(fs_info, true); in open_ctree()
3442 invalidate_inode_pages2(fs_info->btree_inode->i_mapping); in open_ctree()
3445 btrfs_stop_all_workers(fs_info); in open_ctree()
3446 btrfs_free_block_groups(fs_info); in open_ctree()
3448 btrfs_mapping_tree_free(&fs_info->mapping_tree); in open_ctree()
3450 iput(fs_info->btree_inode); in open_ctree()
3452 btrfs_close_devices(fs_info->fs_devices); in open_ctree()
3468 btrfs_warn_rl_in_rcu(device->fs_info, in btrfs_end_super_write()
3559 struct btrfs_fs_info *fs_info = device->fs_info; in write_dev_supers() local
3561 SHASH_DESC_ON_STACK(shash, fs_info->csum_shash); in write_dev_supers()
3569 shash->tfm = fs_info->csum_shash; in write_dev_supers()
3590 btrfs_err(device->fs_info, in write_dev_supers()
3622 if (i == 0 && !btrfs_test_opt(device->fs_info, NOBARRIER)) in write_dev_supers()
3680 btrfs_err(device->fs_info, "error writing primary super block to device %llu", in wait_dev_supers()
3748 static int check_barrier_error(struct btrfs_fs_info *fs_info) in check_barrier_error() argument
3750 if (!btrfs_check_rw_degradable(fs_info, NULL)) in check_barrier_error()
3843 int write_all_supers(struct btrfs_fs_info *fs_info, int max_mirrors) in write_all_supers() argument
3855 do_barriers = !btrfs_test_opt(fs_info, NOBARRIER); in write_all_supers()
3863 backup_super_roots(fs_info); in write_all_supers()
3865 sb = fs_info->super_for_commit; in write_all_supers()
3868 mutex_lock(&fs_info->fs_devices->device_list_mutex); in write_all_supers()
3869 head = &fs_info->fs_devices->devices; in write_all_supers()
3870 max_errors = btrfs_super_num_devices(fs_info->super_copy) - 1; in write_all_supers()
3873 ret = barrier_all_devices(fs_info); in write_all_supers()
3876 &fs_info->fs_devices->device_list_mutex); in write_all_supers()
3877 btrfs_handle_fs_error(fs_info, ret, in write_all_supers()
3909 ret = btrfs_validate_write_super(fs_info, sb); in write_all_supers()
3911 mutex_unlock(&fs_info->fs_devices->device_list_mutex); in write_all_supers()
3912 btrfs_handle_fs_error(fs_info, -EUCLEAN, in write_all_supers()
3922 btrfs_err(fs_info, "%d errors while writing supers", in write_all_supers()
3924 mutex_unlock(&fs_info->fs_devices->device_list_mutex); in write_all_supers()
3927 btrfs_handle_fs_error(fs_info, -EIO, in write_all_supers()
3945 mutex_unlock(&fs_info->fs_devices->device_list_mutex); in write_all_supers()
3947 btrfs_handle_fs_error(fs_info, -EIO, in write_all_supers()
3956 void btrfs_drop_and_free_fs_root(struct btrfs_fs_info *fs_info, in btrfs_drop_and_free_fs_root() argument
3961 spin_lock(&fs_info->fs_roots_radix_lock); in btrfs_drop_and_free_fs_root()
3962 radix_tree_delete(&fs_info->fs_roots_radix, in btrfs_drop_and_free_fs_root()
3966 spin_unlock(&fs_info->fs_roots_radix_lock); in btrfs_drop_and_free_fs_root()
3968 if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) { in btrfs_drop_and_free_fs_root()
3988 int btrfs_cleanup_fs_roots(struct btrfs_fs_info *fs_info) in btrfs_cleanup_fs_roots() argument
3997 spin_lock(&fs_info->fs_roots_radix_lock); in btrfs_cleanup_fs_roots()
3998 ret = radix_tree_gang_lookup(&fs_info->fs_roots_radix, in btrfs_cleanup_fs_roots()
4002 spin_unlock(&fs_info->fs_roots_radix_lock); in btrfs_cleanup_fs_roots()
4016 spin_unlock(&fs_info->fs_roots_radix_lock); in btrfs_cleanup_fs_roots()
4038 int btrfs_commit_super(struct btrfs_fs_info *fs_info) in btrfs_commit_super() argument
4040 struct btrfs_root *root = fs_info->tree_root; in btrfs_commit_super()
4043 mutex_lock(&fs_info->cleaner_mutex); in btrfs_commit_super()
4044 btrfs_run_delayed_iputs(fs_info); in btrfs_commit_super()
4045 mutex_unlock(&fs_info->cleaner_mutex); in btrfs_commit_super()
4046 wake_up_process(fs_info->cleaner_kthread); in btrfs_commit_super()
4049 down_write(&fs_info->cleanup_work_sem); in btrfs_commit_super()
4050 up_write(&fs_info->cleanup_work_sem); in btrfs_commit_super()
4058 void __cold close_ctree(struct btrfs_fs_info *fs_info) in close_ctree() argument
4062 set_bit(BTRFS_FS_CLOSING_START, &fs_info->flags); in close_ctree()
4069 kthread_park(fs_info->cleaner_kthread); in close_ctree()
4072 btrfs_qgroup_wait_for_completion(fs_info, false); in close_ctree()
4075 down(&fs_info->uuid_tree_rescan_sem); in close_ctree()
4077 up(&fs_info->uuid_tree_rescan_sem); in close_ctree()
4080 btrfs_pause_balance(fs_info); in close_ctree()
4082 btrfs_dev_replace_suspend_for_unmount(fs_info); in close_ctree()
4084 btrfs_scrub_cancel(fs_info); in close_ctree()
4087 wait_event(fs_info->transaction_wait, in close_ctree()
4088 (atomic_read(&fs_info->defrag_running) == 0)); in close_ctree()
4091 btrfs_cleanup_defrag_inodes(fs_info); in close_ctree()
4093 cancel_work_sync(&fs_info->async_reclaim_work); in close_ctree()
4094 cancel_work_sync(&fs_info->async_data_reclaim_work); in close_ctree()
4097 btrfs_discard_cleanup(fs_info); in close_ctree()
4099 if (!sb_rdonly(fs_info->sb)) { in close_ctree()
4104 btrfs_delete_unused_bgs(fs_info); in close_ctree()
4117 btrfs_flush_workqueue(fs_info->delayed_workers); in close_ctree()
4119 ret = btrfs_commit_super(fs_info); in close_ctree()
4121 btrfs_err(fs_info, "commit super ret %d", ret); in close_ctree()
4124 if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state) || in close_ctree()
4125 test_bit(BTRFS_FS_STATE_TRANS_ABORTED, &fs_info->fs_state)) in close_ctree()
4126 btrfs_error_commit_super(fs_info); in close_ctree()
4128 kthread_stop(fs_info->transaction_kthread); in close_ctree()
4129 kthread_stop(fs_info->cleaner_kthread); in close_ctree()
4131 ASSERT(list_empty(&fs_info->delayed_iputs)); in close_ctree()
4132 set_bit(BTRFS_FS_CLOSING_DONE, &fs_info->flags); in close_ctree()
4134 if (btrfs_check_quota_leak(fs_info)) { in close_ctree()
4136 btrfs_err(fs_info, "qgroup reserved space leaked"); in close_ctree()
4139 btrfs_free_qgroup_config(fs_info); in close_ctree()
4140 ASSERT(list_empty(&fs_info->delalloc_roots)); in close_ctree()
4142 if (percpu_counter_sum(&fs_info->delalloc_bytes)) { in close_ctree()
4143 btrfs_info(fs_info, "at unmount delalloc count %lld", in close_ctree()
4144 percpu_counter_sum(&fs_info->delalloc_bytes)); in close_ctree()
4147 if (percpu_counter_sum(&fs_info->dio_bytes)) in close_ctree()
4148 btrfs_info(fs_info, "at unmount dio bytes count %lld", in close_ctree()
4149 percpu_counter_sum(&fs_info->dio_bytes)); in close_ctree()
4151 btrfs_sysfs_remove_mounted(fs_info); in close_ctree()
4152 btrfs_sysfs_remove_fsid(fs_info->fs_devices); in close_ctree()
4154 btrfs_put_block_group_cache(fs_info); in close_ctree()
4160 invalidate_inode_pages2(fs_info->btree_inode->i_mapping); in close_ctree()
4161 btrfs_stop_all_workers(fs_info); in close_ctree()
4163 clear_bit(BTRFS_FS_OPEN, &fs_info->flags); in close_ctree()
4164 free_root_pointers(fs_info, true); in close_ctree()
4165 btrfs_free_fs_roots(fs_info); in close_ctree()
4174 btrfs_free_block_groups(fs_info); in close_ctree()
4176 iput(fs_info->btree_inode); in close_ctree()
4179 if (btrfs_test_opt(fs_info, CHECK_INTEGRITY)) in close_ctree()
4180 btrfsic_unmount(fs_info->fs_devices); in close_ctree()
4183 btrfs_mapping_tree_free(&fs_info->mapping_tree); in close_ctree()
4184 btrfs_close_devices(fs_info->fs_devices); in close_ctree()
4206 struct btrfs_fs_info *fs_info; in btrfs_mark_buffer_dirty() local
4221 fs_info = root->fs_info; in btrfs_mark_buffer_dirty()
4223 if (transid != fs_info->generation) in btrfs_mark_buffer_dirty()
4225 buf->start, transid, fs_info->generation); in btrfs_mark_buffer_dirty()
4228 percpu_counter_add_batch(&fs_info->dirty_metadata_bytes, in btrfs_mark_buffer_dirty()
4230 fs_info->dirty_metadata_batch); in btrfs_mark_buffer_dirty()
4245 static void __btrfs_btree_balance_dirty(struct btrfs_fs_info *fs_info, in __btrfs_btree_balance_dirty() argument
4258 btrfs_balance_delayed_items(fs_info); in __btrfs_btree_balance_dirty()
4260 ret = __percpu_counter_compare(&fs_info->dirty_metadata_bytes, in __btrfs_btree_balance_dirty()
4262 fs_info->dirty_metadata_batch); in __btrfs_btree_balance_dirty()
4264 balance_dirty_pages_ratelimited(fs_info->btree_inode->i_mapping); in __btrfs_btree_balance_dirty()
4268 void btrfs_btree_balance_dirty(struct btrfs_fs_info *fs_info) in btrfs_btree_balance_dirty() argument
4270 __btrfs_btree_balance_dirty(fs_info, 1); in btrfs_btree_balance_dirty()
4273 void btrfs_btree_balance_dirty_nodelay(struct btrfs_fs_info *fs_info) in btrfs_btree_balance_dirty_nodelay() argument
4275 __btrfs_btree_balance_dirty(fs_info, 0); in btrfs_btree_balance_dirty_nodelay()
4285 static void btrfs_error_commit_super(struct btrfs_fs_info *fs_info) in btrfs_error_commit_super() argument
4288 btrfs_cleanup_transaction(fs_info); in btrfs_error_commit_super()
4290 mutex_lock(&fs_info->cleaner_mutex); in btrfs_error_commit_super()
4291 btrfs_run_delayed_iputs(fs_info); in btrfs_error_commit_super()
4292 mutex_unlock(&fs_info->cleaner_mutex); in btrfs_error_commit_super()
4294 down_write(&fs_info->cleanup_work_sem); in btrfs_error_commit_super()
4295 up_write(&fs_info->cleanup_work_sem); in btrfs_error_commit_super()
4298 static void btrfs_drop_all_logs(struct btrfs_fs_info *fs_info) in btrfs_drop_all_logs() argument
4304 spin_lock(&fs_info->fs_roots_radix_lock); in btrfs_drop_all_logs()
4305 while ((ret = radix_tree_gang_lookup(&fs_info->fs_roots_radix, in btrfs_drop_all_logs()
4312 spin_unlock(&fs_info->fs_roots_radix_lock); in btrfs_drop_all_logs()
4322 spin_lock(&fs_info->fs_roots_radix_lock); in btrfs_drop_all_logs()
4324 spin_unlock(&fs_info->fs_roots_radix_lock); in btrfs_drop_all_logs()
4325 btrfs_free_log_root_tree(NULL, fs_info); in btrfs_drop_all_logs()
4343 static void btrfs_destroy_all_ordered_extents(struct btrfs_fs_info *fs_info) in btrfs_destroy_all_ordered_extents() argument
4350 spin_lock(&fs_info->ordered_root_lock); in btrfs_destroy_all_ordered_extents()
4351 list_splice_init(&fs_info->ordered_roots, &splice); in btrfs_destroy_all_ordered_extents()
4356 &fs_info->ordered_roots); in btrfs_destroy_all_ordered_extents()
4358 spin_unlock(&fs_info->ordered_root_lock); in btrfs_destroy_all_ordered_extents()
4362 spin_lock(&fs_info->ordered_root_lock); in btrfs_destroy_all_ordered_extents()
4364 spin_unlock(&fs_info->ordered_root_lock); in btrfs_destroy_all_ordered_extents()
4372 btrfs_wait_ordered_roots(fs_info, U64_MAX, 0, (u64)-1); in btrfs_destroy_all_ordered_extents()
4376 struct btrfs_fs_info *fs_info) in btrfs_destroy_delayed_refs() argument
4388 btrfs_debug(fs_info, "delayed_refs has NO entry"); in btrfs_destroy_delayed_refs()
4425 cache = btrfs_lookup_block_group(fs_info, head->bytenr); in btrfs_destroy_delayed_refs()
4431 btrfs_space_info_update_bytes_pinned(fs_info, in btrfs_destroy_delayed_refs()
4443 btrfs_error_unpin_extent_range(fs_info, head->bytenr, in btrfs_destroy_delayed_refs()
4446 btrfs_cleanup_ref_head_accounting(fs_info, delayed_refs, head); in btrfs_destroy_delayed_refs()
4489 static void btrfs_destroy_all_delalloc_inodes(struct btrfs_fs_info *fs_info) in btrfs_destroy_all_delalloc_inodes() argument
4496 spin_lock(&fs_info->delalloc_root_lock); in btrfs_destroy_all_delalloc_inodes()
4497 list_splice_init(&fs_info->delalloc_roots, &splice); in btrfs_destroy_all_delalloc_inodes()
4503 spin_unlock(&fs_info->delalloc_root_lock); in btrfs_destroy_all_delalloc_inodes()
4508 spin_lock(&fs_info->delalloc_root_lock); in btrfs_destroy_all_delalloc_inodes()
4510 spin_unlock(&fs_info->delalloc_root_lock); in btrfs_destroy_all_delalloc_inodes()
4513 static int btrfs_destroy_marked_extents(struct btrfs_fs_info *fs_info, in btrfs_destroy_marked_extents() argument
4530 eb = find_extent_buffer(fs_info, start); in btrfs_destroy_marked_extents()
4531 start += fs_info->nodesize; in btrfs_destroy_marked_extents()
4546 static int btrfs_destroy_pinned_extent(struct btrfs_fs_info *fs_info, in btrfs_destroy_pinned_extent() argument
4562 mutex_lock(&fs_info->unused_bg_unpin_mutex); in btrfs_destroy_pinned_extent()
4566 mutex_unlock(&fs_info->unused_bg_unpin_mutex); in btrfs_destroy_pinned_extent()
4572 btrfs_error_unpin_extent_range(fs_info, start, end); in btrfs_destroy_pinned_extent()
4573 mutex_unlock(&fs_info->unused_bg_unpin_mutex); in btrfs_destroy_pinned_extent()
4596 struct btrfs_fs_info *fs_info) in btrfs_cleanup_dirty_bgs() argument
4620 btrfs_delayed_refs_rsv_release(fs_info, 1); in btrfs_cleanup_dirty_bgs()
4643 struct btrfs_fs_info *fs_info) in btrfs_cleanup_one_transaction() argument
4647 btrfs_cleanup_dirty_bgs(cur_trans, fs_info); in btrfs_cleanup_one_transaction()
4656 btrfs_destroy_delayed_refs(cur_trans, fs_info); in btrfs_cleanup_one_transaction()
4659 wake_up(&fs_info->transaction_blocked_wait); in btrfs_cleanup_one_transaction()
4662 wake_up(&fs_info->transaction_wait); in btrfs_cleanup_one_transaction()
4664 btrfs_destroy_delayed_inodes(fs_info); in btrfs_cleanup_one_transaction()
4666 btrfs_destroy_marked_extents(fs_info, &cur_trans->dirty_pages, in btrfs_cleanup_one_transaction()
4668 btrfs_destroy_pinned_extent(fs_info, &cur_trans->pinned_extents); in btrfs_cleanup_one_transaction()
4674 static int btrfs_cleanup_transaction(struct btrfs_fs_info *fs_info) in btrfs_cleanup_transaction() argument
4678 mutex_lock(&fs_info->transaction_kthread_mutex); in btrfs_cleanup_transaction()
4680 spin_lock(&fs_info->trans_lock); in btrfs_cleanup_transaction()
4681 while (!list_empty(&fs_info->trans_list)) { in btrfs_cleanup_transaction()
4682 t = list_first_entry(&fs_info->trans_list, in btrfs_cleanup_transaction()
4686 spin_unlock(&fs_info->trans_lock); in btrfs_cleanup_transaction()
4687 btrfs_wait_for_commit(fs_info, t->transid); in btrfs_cleanup_transaction()
4689 spin_lock(&fs_info->trans_lock); in btrfs_cleanup_transaction()
4692 if (t == fs_info->running_transaction) { in btrfs_cleanup_transaction()
4694 spin_unlock(&fs_info->trans_lock); in btrfs_cleanup_transaction()
4702 spin_unlock(&fs_info->trans_lock); in btrfs_cleanup_transaction()
4704 btrfs_cleanup_one_transaction(t, fs_info); in btrfs_cleanup_transaction()
4706 spin_lock(&fs_info->trans_lock); in btrfs_cleanup_transaction()
4707 if (t == fs_info->running_transaction) in btrfs_cleanup_transaction()
4708 fs_info->running_transaction = NULL; in btrfs_cleanup_transaction()
4710 spin_unlock(&fs_info->trans_lock); in btrfs_cleanup_transaction()
4713 trace_btrfs_transaction_commit(fs_info->tree_root); in btrfs_cleanup_transaction()
4714 spin_lock(&fs_info->trans_lock); in btrfs_cleanup_transaction()
4716 spin_unlock(&fs_info->trans_lock); in btrfs_cleanup_transaction()
4717 btrfs_destroy_all_ordered_extents(fs_info); in btrfs_cleanup_transaction()
4718 btrfs_destroy_delayed_inodes(fs_info); in btrfs_cleanup_transaction()
4719 btrfs_assert_delayed_root_empty(fs_info); in btrfs_cleanup_transaction()
4720 btrfs_destroy_all_delalloc_inodes(fs_info); in btrfs_cleanup_transaction()
4721 btrfs_drop_all_logs(fs_info); in btrfs_cleanup_transaction()
4722 mutex_unlock(&fs_info->transaction_kthread_mutex); in btrfs_cleanup_transaction()