Lines Matching refs:fs_info

65 				      struct btrfs_fs_info *fs_info);
67 static int btrfs_destroy_marked_extents(struct btrfs_fs_info *fs_info,
70 static int btrfs_destroy_pinned_extent(struct btrfs_fs_info *fs_info,
72 static int btrfs_cleanup_transaction(struct btrfs_fs_info *fs_info);
73 static void btrfs_error_commit_super(struct btrfs_fs_info *fs_info);
75 static void btrfs_free_csum_hash(struct btrfs_fs_info *fs_info) in btrfs_free_csum_hash() argument
77 if (fs_info->csum_shash) in btrfs_free_csum_hash()
78 crypto_free_shash(fs_info->csum_shash); in btrfs_free_csum_hash()
86 struct btrfs_fs_info *fs_info = buf->fs_info; in csum_tree_block() local
88 const int first_page_part = min_t(u32, PAGE_SIZE, fs_info->nodesize); in csum_tree_block()
89 SHASH_DESC_ON_STACK(shash, fs_info->csum_shash); in csum_tree_block()
93 shash->tfm = fs_info->csum_shash; in csum_tree_block()
132 btrfs_err_rl(eb->fs_info, in verify_parent_transid()
161 int btrfs_check_super_csum(struct btrfs_fs_info *fs_info, in btrfs_check_super_csum() argument
165 SHASH_DESC_ON_STACK(shash, fs_info->csum_shash); in btrfs_check_super_csum()
167 shash->tfm = fs_info->csum_shash; in btrfs_check_super_csum()
177 if (memcmp(disk_sb->csum, result, fs_info->csum_size)) in btrfs_check_super_csum()
186 struct btrfs_fs_info *fs_info = eb->fs_info; in btrfs_verify_level_key() local
195 btrfs_err(fs_info, in btrfs_verify_level_key()
210 if (btrfs_header_generation(eb) > fs_info->last_trans_committed) in btrfs_verify_level_key()
215 btrfs_err(fs_info, in btrfs_verify_level_key()
231 btrfs_err(fs_info, in btrfs_verify_level_key()
244 struct btrfs_fs_info *fs_info = eb->fs_info; in btrfs_repair_eb_io_failure() local
249 if (sb_rdonly(fs_info->sb)) in btrfs_repair_eb_io_failure()
255 ret = btrfs_repair_io_failure(fs_info, 0, start, PAGE_SIZE, in btrfs_repair_eb_io_failure()
275 struct btrfs_fs_info *fs_info = eb->fs_info; in btrfs_read_extent_buffer() local
290 num_copies = btrfs_num_copies(fs_info, in btrfs_read_extent_buffer()
316 struct btrfs_fs_info *fs_info = eb->fs_info; in csum_one_extent_buffer() local
320 ASSERT(memcmp_extent_buffer(eb, fs_info->fs_devices->metadata_uuid, in csum_one_extent_buffer()
337 if (unlikely(btrfs_header_generation(eb) <= fs_info->last_trans_committed)) { in csum_one_extent_buffer()
339 btrfs_err(fs_info, in csum_one_extent_buffer()
342 fs_info->last_trans_committed); in csum_one_extent_buffer()
345 write_extent_buffer(eb, result, 0, fs_info->csum_size); in csum_one_extent_buffer()
351 btrfs_err(fs_info, "block=%llu write time tree block corruption detected", in csum_one_extent_buffer()
365 static int csum_dirty_subpage_buffers(struct btrfs_fs_info *fs_info, in csum_dirty_subpage_buffers() argument
374 cur += fs_info->nodesize) { in csum_dirty_subpage_buffers()
378 eb = find_extent_buffer(fs_info, cur); in csum_dirty_subpage_buffers()
379 uptodate = btrfs_subpage_test_uptodate(fs_info, page, cur, in csum_dirty_subpage_buffers()
380 fs_info->nodesize); in csum_dirty_subpage_buffers()
408 static int csum_dirty_buffer(struct btrfs_fs_info *fs_info, struct bio_vec *bvec) in csum_dirty_buffer() argument
415 if (fs_info->nodesize < PAGE_SIZE) in csum_dirty_buffer()
416 return csum_dirty_subpage_buffers(fs_info, bvec); in csum_dirty_buffer()
443 struct btrfs_fs_info *fs_info = bbio->inode->root->fs_info; in btree_csum_one_bio() local
449 ret = csum_dirty_buffer(fs_info, &bv); in btree_csum_one_bio()
459 struct btrfs_fs_info *fs_info = eb->fs_info; in check_tree_block_fsid() local
460 struct btrfs_fs_devices *fs_devices = fs_info->fs_devices, *seed_devs; in check_tree_block_fsid()
471 if (btrfs_fs_incompat(fs_info, METADATA_UUID)) in check_tree_block_fsid()
490 struct btrfs_fs_info *fs_info = eb->fs_info; in validate_extent_buffer() local
492 const u32 csum_size = fs_info->csum_size; in validate_extent_buffer()
502 btrfs_err_rl(fs_info, in validate_extent_buffer()
509 btrfs_err_rl(fs_info, "bad fsid on logical %llu mirror %u", in validate_extent_buffer()
516 btrfs_err(fs_info, in validate_extent_buffer()
528 btrfs_warn_rl(fs_info, in validate_extent_buffer()
539 btrfs_err(fs_info, in validate_extent_buffer()
547 btrfs_err_rl(eb->fs_info, in validate_extent_buffer()
563 btrfs_err(fs_info, in validate_extent_buffer()
596 btrfs_err(fs_info, in validate_extent_buffer()
606 struct btrfs_fs_info *fs_info = btrfs_sb(page->mapping->host->i_sb); in validate_subpage_buffer() local
617 ASSERT(end == start + fs_info->nodesize - 1); in validate_subpage_buffer()
620 eb = find_extent_buffer(fs_info, start); in validate_subpage_buffer()
728 struct btrfs_fs_info *fs_info; in btree_writepages() local
736 fs_info = BTRFS_I(mapping->host)->root->fs_info; in btree_writepages()
738 ret = __percpu_counter_compare(&fs_info->dirty_metadata_bytes, in btree_writepages()
740 fs_info->dirty_metadata_batch); in btree_writepages()
763 btrfs_warn(BTRFS_I(folio->mapping->host)->root->fs_info, in btree_invalidate_folio()
774 struct btrfs_fs_info *fs_info = btrfs_sb(mapping->host->i_sb); in btree_dirty_folio() local
780 if (fs_info->sectorsize == PAGE_SIZE) { in btree_dirty_folio()
803 cur = page_start + cur_bit * fs_info->sectorsize; in btree_dirty_folio()
805 eb = find_extent_buffer(fs_info, cur); in btree_dirty_folio()
812 cur_bit += (fs_info->nodesize >> fs_info->sectorsize_bits); in btree_dirty_folio()
829 struct btrfs_fs_info *fs_info, in btrfs_find_create_tree_block() argument
833 if (btrfs_is_testing(fs_info)) in btrfs_find_create_tree_block()
834 return alloc_test_extent_buffer(fs_info, bytenr); in btrfs_find_create_tree_block()
835 return alloc_extent_buffer(fs_info, bytenr, owner_root, level); in btrfs_find_create_tree_block()
845 struct extent_buffer *read_tree_block(struct btrfs_fs_info *fs_info, u64 bytenr, in read_tree_block() argument
853 buf = btrfs_find_create_tree_block(fs_info, bytenr, check->owner_root, in read_tree_block()
871 static void __setup_root(struct btrfs_root *root, struct btrfs_fs_info *fs_info, in __setup_root() argument
874 bool dummy = test_bit(BTRFS_FS_STATE_DUMMY_FS_INFO, &fs_info->fs_state); in __setup_root()
879 root->fs_info = fs_info; in __setup_root()
933 extent_io_tree_init(fs_info, &root->dirty_log_pages, in __setup_root()
935 extent_io_tree_init(fs_info, &root->log_csum_range, in __setup_root()
943 spin_lock(&fs_info->fs_roots_radix_lock); in __setup_root()
944 list_add_tail(&root->leak_list, &fs_info->allocated_roots); in __setup_root()
945 spin_unlock(&fs_info->fs_roots_radix_lock); in __setup_root()
949 static struct btrfs_root *btrfs_alloc_root(struct btrfs_fs_info *fs_info, in btrfs_alloc_root() argument
954 __setup_root(root, fs_info, objectid); in btrfs_alloc_root()
960 struct btrfs_root *btrfs_alloc_dummy_root(struct btrfs_fs_info *fs_info) in btrfs_alloc_dummy_root() argument
964 if (!fs_info) in btrfs_alloc_dummy_root()
967 root = btrfs_alloc_root(fs_info, BTRFS_ROOT_TREE_OBJECTID, GFP_KERNEL); in btrfs_alloc_dummy_root()
996 struct btrfs_fs_info *fs_info = root->fs_info; in btrfs_global_root_insert() local
999 write_lock(&fs_info->global_root_lock); in btrfs_global_root_insert()
1000 tmp = rb_find_add(&root->rb_node, &fs_info->global_root_tree, global_root_cmp); in btrfs_global_root_insert()
1001 write_unlock(&fs_info->global_root_lock); in btrfs_global_root_insert()
1009 struct btrfs_fs_info *fs_info = root->fs_info; in btrfs_global_root_delete() local
1011 write_lock(&fs_info->global_root_lock); in btrfs_global_root_delete()
1012 rb_erase(&root->rb_node, &fs_info->global_root_tree); in btrfs_global_root_delete()
1013 write_unlock(&fs_info->global_root_lock); in btrfs_global_root_delete()
1016 struct btrfs_root *btrfs_global_root(struct btrfs_fs_info *fs_info, in btrfs_global_root() argument
1022 read_lock(&fs_info->global_root_lock); in btrfs_global_root()
1023 node = rb_find(key, &fs_info->global_root_tree, global_root_key_cmp); in btrfs_global_root()
1026 read_unlock(&fs_info->global_root_lock); in btrfs_global_root()
1031 static u64 btrfs_global_root_id(struct btrfs_fs_info *fs_info, u64 bytenr) in btrfs_global_root_id() argument
1036 if (!btrfs_fs_incompat(fs_info, EXTENT_TREE_V2)) in btrfs_global_root_id()
1040 block_group = btrfs_lookup_block_group(fs_info, bytenr); in btrfs_global_root_id()
1042 block_group = btrfs_lookup_first_block_group(fs_info, bytenr); in btrfs_global_root_id()
1052 struct btrfs_root *btrfs_csum_root(struct btrfs_fs_info *fs_info, u64 bytenr) in btrfs_csum_root() argument
1057 .offset = btrfs_global_root_id(fs_info, bytenr), in btrfs_csum_root()
1060 return btrfs_global_root(fs_info, &key); in btrfs_csum_root()
1063 struct btrfs_root *btrfs_extent_root(struct btrfs_fs_info *fs_info, u64 bytenr) in btrfs_extent_root() argument
1068 .offset = btrfs_global_root_id(fs_info, bytenr), in btrfs_extent_root()
1071 return btrfs_global_root(fs_info, &key); in btrfs_extent_root()
1074 struct btrfs_root *btrfs_block_group_root(struct btrfs_fs_info *fs_info) in btrfs_block_group_root() argument
1076 if (btrfs_fs_compat_ro(fs_info, BLOCK_GROUP_TREE)) in btrfs_block_group_root()
1077 return fs_info->block_group_root; in btrfs_block_group_root()
1078 return btrfs_extent_root(fs_info, 0); in btrfs_block_group_root()
1084 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_create_tree() local
1086 struct btrfs_root *tree_root = fs_info->tree_root; in btrfs_create_tree()
1097 root = btrfs_alloc_root(fs_info, objectid, GFP_KERNEL); in btrfs_create_tree()
1153 struct btrfs_fs_info *fs_info) in alloc_log_tree() argument
1157 root = btrfs_alloc_root(fs_info, BTRFS_TREE_LOG_OBJECTID, GFP_NOFS); in alloc_log_tree()
1197 struct btrfs_fs_info *fs_info) in btrfs_init_log_root_tree() argument
1201 log_root = alloc_log_tree(trans, fs_info); in btrfs_init_log_root_tree()
1205 if (!btrfs_is_zoned(fs_info)) { in btrfs_init_log_root_tree()
1214 WARN_ON(fs_info->log_root_tree); in btrfs_init_log_root_tree()
1215 fs_info->log_root_tree = log_root; in btrfs_init_log_root_tree()
1222 struct btrfs_fs_info *fs_info = root->fs_info; in btrfs_add_log_tree() local
1227 log_root = alloc_log_tree(trans, fs_info); in btrfs_add_log_tree()
1245 fs_info->nodesize); in btrfs_add_log_tree()
1264 struct btrfs_fs_info *fs_info = tree_root->fs_info; in read_tree_root_path() local
1269 root = btrfs_alloc_root(fs_info, key->objectid, GFP_NOFS); in read_tree_root_path()
1286 root->node = read_tree_block(fs_info, btrfs_root_bytenr(&root->root_item), in read_tree_root_path()
1302 if (!test_bit(BTRFS_FS_STATE_DUMMY_FS_INFO, &fs_info->fs_state) && in read_tree_root_path()
1306 btrfs_crit(fs_info, in read_tree_root_path()
1394 static struct btrfs_root *btrfs_lookup_fs_root(struct btrfs_fs_info *fs_info, in btrfs_lookup_fs_root() argument
1399 spin_lock(&fs_info->fs_roots_radix_lock); in btrfs_lookup_fs_root()
1400 root = radix_tree_lookup(&fs_info->fs_roots_radix, in btrfs_lookup_fs_root()
1404 spin_unlock(&fs_info->fs_roots_radix_lock); in btrfs_lookup_fs_root()
1408 static struct btrfs_root *btrfs_get_global_root(struct btrfs_fs_info *fs_info, in btrfs_get_global_root() argument
1418 return btrfs_grab_root(fs_info->tree_root); in btrfs_get_global_root()
1420 return btrfs_grab_root(btrfs_global_root(fs_info, &key)); in btrfs_get_global_root()
1422 return btrfs_grab_root(fs_info->chunk_root); in btrfs_get_global_root()
1424 return btrfs_grab_root(fs_info->dev_root); in btrfs_get_global_root()
1426 return btrfs_grab_root(btrfs_global_root(fs_info, &key)); in btrfs_get_global_root()
1428 return btrfs_grab_root(fs_info->quota_root) ? in btrfs_get_global_root()
1429 fs_info->quota_root : ERR_PTR(-ENOENT); in btrfs_get_global_root()
1431 return btrfs_grab_root(fs_info->uuid_root) ? in btrfs_get_global_root()
1432 fs_info->uuid_root : ERR_PTR(-ENOENT); in btrfs_get_global_root()
1434 return btrfs_grab_root(fs_info->block_group_root) ? in btrfs_get_global_root()
1435 fs_info->block_group_root : ERR_PTR(-ENOENT); in btrfs_get_global_root()
1437 struct btrfs_root *root = btrfs_global_root(fs_info, &key); in btrfs_get_global_root()
1444 int btrfs_insert_fs_root(struct btrfs_fs_info *fs_info, in btrfs_insert_fs_root() argument
1453 spin_lock(&fs_info->fs_roots_radix_lock); in btrfs_insert_fs_root()
1454 ret = radix_tree_insert(&fs_info->fs_roots_radix, in btrfs_insert_fs_root()
1461 spin_unlock(&fs_info->fs_roots_radix_lock); in btrfs_insert_fs_root()
1467 void btrfs_check_leaked_roots(struct btrfs_fs_info *fs_info) in btrfs_check_leaked_roots() argument
1472 while (!list_empty(&fs_info->allocated_roots)) { in btrfs_check_leaked_roots()
1475 root = list_first_entry(&fs_info->allocated_roots, in btrfs_check_leaked_roots()
1477 btrfs_err(fs_info, "leaked root %s refcount %d", in btrfs_check_leaked_roots()
1487 static void free_global_roots(struct btrfs_fs_info *fs_info) in free_global_roots() argument
1492 while ((node = rb_first_postorder(&fs_info->global_root_tree)) != NULL) { in free_global_roots()
1494 rb_erase(&root->rb_node, &fs_info->global_root_tree); in free_global_roots()
1499 void btrfs_free_fs_info(struct btrfs_fs_info *fs_info) in btrfs_free_fs_info() argument
1501 percpu_counter_destroy(&fs_info->dirty_metadata_bytes); in btrfs_free_fs_info()
1502 percpu_counter_destroy(&fs_info->delalloc_bytes); in btrfs_free_fs_info()
1503 percpu_counter_destroy(&fs_info->ordered_bytes); in btrfs_free_fs_info()
1504 percpu_counter_destroy(&fs_info->dev_replace.bio_counter); in btrfs_free_fs_info()
1505 btrfs_free_csum_hash(fs_info); in btrfs_free_fs_info()
1506 btrfs_free_stripe_hash_table(fs_info); in btrfs_free_fs_info()
1507 btrfs_free_ref_cache(fs_info); in btrfs_free_fs_info()
1508 kfree(fs_info->balance_ctl); in btrfs_free_fs_info()
1509 kfree(fs_info->delayed_root); in btrfs_free_fs_info()
1510 free_global_roots(fs_info); in btrfs_free_fs_info()
1511 btrfs_put_root(fs_info->tree_root); in btrfs_free_fs_info()
1512 btrfs_put_root(fs_info->chunk_root); in btrfs_free_fs_info()
1513 btrfs_put_root(fs_info->dev_root); in btrfs_free_fs_info()
1514 btrfs_put_root(fs_info->quota_root); in btrfs_free_fs_info()
1515 btrfs_put_root(fs_info->uuid_root); in btrfs_free_fs_info()
1516 btrfs_put_root(fs_info->fs_root); in btrfs_free_fs_info()
1517 btrfs_put_root(fs_info->data_reloc_root); in btrfs_free_fs_info()
1518 btrfs_put_root(fs_info->block_group_root); in btrfs_free_fs_info()
1519 btrfs_check_leaked_roots(fs_info); in btrfs_free_fs_info()
1520 btrfs_extent_buffer_leak_debug_check(fs_info); in btrfs_free_fs_info()
1521 kfree(fs_info->super_copy); in btrfs_free_fs_info()
1522 kfree(fs_info->super_for_commit); in btrfs_free_fs_info()
1523 kfree(fs_info->subpage_info); in btrfs_free_fs_info()
1524 kvfree(fs_info); in btrfs_free_fs_info()
1546 static struct btrfs_root *btrfs_get_root_ref(struct btrfs_fs_info *fs_info, in btrfs_get_root_ref() argument
1555 root = btrfs_get_global_root(fs_info, objectid); in btrfs_get_root_ref()
1559 root = btrfs_lookup_fs_root(fs_info, objectid); in btrfs_get_root_ref()
1573 root = btrfs_read_tree_root(fs_info->tree_root, &key); in btrfs_get_root_ref()
1595 ret = btrfs_search_slot(NULL, fs_info->tree_root, &key, path, 0, 0); in btrfs_get_root_ref()
1602 ret = btrfs_insert_fs_root(fs_info, root); in btrfs_get_root_ref()
1631 struct btrfs_root *btrfs_get_fs_root(struct btrfs_fs_info *fs_info, in btrfs_get_fs_root() argument
1634 return btrfs_get_root_ref(fs_info, objectid, 0, check_ref); in btrfs_get_fs_root()
1645 struct btrfs_root *btrfs_get_new_fs_root(struct btrfs_fs_info *fs_info, in btrfs_get_new_fs_root() argument
1648 return btrfs_get_root_ref(fs_info, objectid, anon_dev, true); in btrfs_get_new_fs_root()
1665 struct btrfs_root *btrfs_get_fs_root_commit_root(struct btrfs_fs_info *fs_info, in btrfs_get_fs_root_commit_root() argument
1680 root = btrfs_get_global_root(fs_info, objectid); in btrfs_get_fs_root_commit_root()
1684 root = btrfs_lookup_fs_root(fs_info, objectid); in btrfs_get_fs_root_commit_root()
1691 root = read_tree_root_path(fs_info->tree_root, path, &key); in btrfs_get_fs_root_commit_root()
1699 struct btrfs_fs_info *fs_info = arg; in cleaner_kthread() local
1705 set_bit(BTRFS_FS_CLEANER_RUNNING, &fs_info->flags); in cleaner_kthread()
1708 if (btrfs_need_cleaner_sleep(fs_info)) in cleaner_kthread()
1715 if (!test_bit(BTRFS_FS_OPEN, &fs_info->flags)) in cleaner_kthread()
1718 if (!mutex_trylock(&fs_info->cleaner_mutex)) in cleaner_kthread()
1725 if (btrfs_need_cleaner_sleep(fs_info)) { in cleaner_kthread()
1726 mutex_unlock(&fs_info->cleaner_mutex); in cleaner_kthread()
1730 if (test_and_clear_bit(BTRFS_FS_FEATURE_CHANGED, &fs_info->flags)) in cleaner_kthread()
1731 btrfs_sysfs_feature_update(fs_info); in cleaner_kthread()
1733 btrfs_run_delayed_iputs(fs_info); in cleaner_kthread()
1735 again = btrfs_clean_one_deleted_snapshot(fs_info); in cleaner_kthread()
1736 mutex_unlock(&fs_info->cleaner_mutex); in cleaner_kthread()
1742 btrfs_run_defrag_inodes(fs_info); in cleaner_kthread()
1752 btrfs_delete_unused_bgs(fs_info); in cleaner_kthread()
1759 btrfs_reclaim_bgs(fs_info); in cleaner_kthread()
1761 clear_and_wake_up_bit(BTRFS_FS_CLEANER_RUNNING, &fs_info->flags); in cleaner_kthread()
1777 struct btrfs_fs_info *fs_info = root->fs_info; in transaction_kthread() local
1787 delay = msecs_to_jiffies(fs_info->commit_interval * 1000); in transaction_kthread()
1788 mutex_lock(&fs_info->transaction_kthread_mutex); in transaction_kthread()
1790 spin_lock(&fs_info->trans_lock); in transaction_kthread()
1791 cur = fs_info->running_transaction; in transaction_kthread()
1793 spin_unlock(&fs_info->trans_lock); in transaction_kthread()
1798 if (!test_and_clear_bit(BTRFS_FS_COMMIT_TRANS, &fs_info->flags) && in transaction_kthread()
1800 delta < fs_info->commit_interval) { in transaction_kthread()
1801 spin_unlock(&fs_info->trans_lock); in transaction_kthread()
1804 msecs_to_jiffies(fs_info->commit_interval * 1000)); in transaction_kthread()
1808 spin_unlock(&fs_info->trans_lock); in transaction_kthread()
1823 wake_up_process(fs_info->cleaner_kthread); in transaction_kthread()
1824 mutex_unlock(&fs_info->transaction_kthread_mutex); in transaction_kthread()
1826 if (BTRFS_FS_ERROR(fs_info)) in transaction_kthread()
1827 btrfs_cleanup_transaction(fs_info); in transaction_kthread()
1829 (!btrfs_transaction_blocked(fs_info) || in transaction_kthread()
1957 static int read_backup_root(struct btrfs_fs_info *fs_info, u8 priority) in read_backup_root() argument
1959 int backup_index = find_newest_super_backup(fs_info); in read_backup_root()
1960 struct btrfs_super_block *super = fs_info->super_copy; in read_backup_root()
1993 static void btrfs_stop_all_workers(struct btrfs_fs_info *fs_info) in btrfs_stop_all_workers() argument
1995 btrfs_destroy_workqueue(fs_info->fixup_workers); in btrfs_stop_all_workers()
1996 btrfs_destroy_workqueue(fs_info->delalloc_workers); in btrfs_stop_all_workers()
1997 btrfs_destroy_workqueue(fs_info->hipri_workers); in btrfs_stop_all_workers()
1998 btrfs_destroy_workqueue(fs_info->workers); in btrfs_stop_all_workers()
1999 if (fs_info->endio_workers) in btrfs_stop_all_workers()
2000 destroy_workqueue(fs_info->endio_workers); in btrfs_stop_all_workers()
2001 if (fs_info->rmw_workers) in btrfs_stop_all_workers()
2002 destroy_workqueue(fs_info->rmw_workers); in btrfs_stop_all_workers()
2003 if (fs_info->compressed_write_workers) in btrfs_stop_all_workers()
2004 destroy_workqueue(fs_info->compressed_write_workers); in btrfs_stop_all_workers()
2005 btrfs_destroy_workqueue(fs_info->endio_write_workers); in btrfs_stop_all_workers()
2006 btrfs_destroy_workqueue(fs_info->endio_freespace_worker); in btrfs_stop_all_workers()
2007 btrfs_destroy_workqueue(fs_info->delayed_workers); in btrfs_stop_all_workers()
2008 btrfs_destroy_workqueue(fs_info->caching_workers); in btrfs_stop_all_workers()
2009 btrfs_destroy_workqueue(fs_info->flush_workers); in btrfs_stop_all_workers()
2010 btrfs_destroy_workqueue(fs_info->qgroup_rescan_workers); in btrfs_stop_all_workers()
2011 if (fs_info->discard_ctl.discard_workers) in btrfs_stop_all_workers()
2012 destroy_workqueue(fs_info->discard_ctl.discard_workers); in btrfs_stop_all_workers()
2018 if (fs_info->endio_meta_workers) in btrfs_stop_all_workers()
2019 destroy_workqueue(fs_info->endio_meta_workers); in btrfs_stop_all_workers()
2032 static void free_global_root_pointers(struct btrfs_fs_info *fs_info) in free_global_root_pointers() argument
2037 &fs_info->global_root_tree, in free_global_root_pointers()
2071 spin_lock(&root->fs_info->fs_roots_radix_lock); in btrfs_put_root()
2073 spin_unlock(&root->fs_info->fs_roots_radix_lock); in btrfs_put_root()
2079 void btrfs_free_fs_roots(struct btrfs_fs_info *fs_info) in btrfs_free_fs_roots() argument
2085 while (!list_empty(&fs_info->dead_roots)) { in btrfs_free_fs_roots()
2086 gang[0] = list_entry(fs_info->dead_roots.next, in btrfs_free_fs_roots()
2091 btrfs_drop_and_free_fs_root(fs_info, gang[0]); in btrfs_free_fs_roots()
2096 ret = radix_tree_gang_lookup(&fs_info->fs_roots_radix, in btrfs_free_fs_roots()
2102 btrfs_drop_and_free_fs_root(fs_info, gang[i]); in btrfs_free_fs_roots()
2106 static void btrfs_init_scrub(struct btrfs_fs_info *fs_info) in btrfs_init_scrub() argument
2108 mutex_init(&fs_info->scrub_lock); in btrfs_init_scrub()
2109 atomic_set(&fs_info->scrubs_running, 0); in btrfs_init_scrub()
2110 atomic_set(&fs_info->scrub_pause_req, 0); in btrfs_init_scrub()
2111 atomic_set(&fs_info->scrubs_paused, 0); in btrfs_init_scrub()
2112 atomic_set(&fs_info->scrub_cancel_req, 0); in btrfs_init_scrub()
2113 init_waitqueue_head(&fs_info->scrub_pause_wait); in btrfs_init_scrub()
2114 refcount_set(&fs_info->scrub_workers_refcnt, 0); in btrfs_init_scrub()
2117 static void btrfs_init_balance(struct btrfs_fs_info *fs_info) in btrfs_init_balance() argument
2119 spin_lock_init(&fs_info->balance_lock); in btrfs_init_balance()
2120 mutex_init(&fs_info->balance_mutex); in btrfs_init_balance()
2121 atomic_set(&fs_info->balance_pause_req, 0); in btrfs_init_balance()
2122 atomic_set(&fs_info->balance_cancel_req, 0); in btrfs_init_balance()
2123 fs_info->balance_ctl = NULL; in btrfs_init_balance()
2124 init_waitqueue_head(&fs_info->balance_wait_q); in btrfs_init_balance()
2125 atomic_set(&fs_info->reloc_cancel_req, 0); 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()
2132 fs_info->tree_root); in btrfs_init_btree_inode()
2145 extent_io_tree_init(fs_info, &BTRFS_I(inode)->io_tree, in btrfs_init_btree_inode()
2149 BTRFS_I(inode)->root = btrfs_grab_root(fs_info->tree_root); in btrfs_init_btree_inode()
2157 static void btrfs_init_dev_replace_locks(struct btrfs_fs_info *fs_info) in btrfs_init_dev_replace_locks() argument
2159 mutex_init(&fs_info->dev_replace.lock_finishing_cancel_unmount); in btrfs_init_dev_replace_locks()
2160 init_rwsem(&fs_info->dev_replace.rwsem); in btrfs_init_dev_replace_locks()
2161 init_waitqueue_head(&fs_info->dev_replace.replace_wait); in btrfs_init_dev_replace_locks()
2164 static void btrfs_init_qgroup(struct btrfs_fs_info *fs_info) in btrfs_init_qgroup() argument
2166 spin_lock_init(&fs_info->qgroup_lock); in btrfs_init_qgroup()
2167 mutex_init(&fs_info->qgroup_ioctl_lock); in btrfs_init_qgroup()
2168 fs_info->qgroup_tree = RB_ROOT; in btrfs_init_qgroup()
2169 INIT_LIST_HEAD(&fs_info->dirty_qgroups); in btrfs_init_qgroup()
2170 fs_info->qgroup_seq = 1; in btrfs_init_qgroup()
2171 fs_info->qgroup_ulist = NULL; in btrfs_init_qgroup()
2172 fs_info->qgroup_rescan_running = false; in btrfs_init_qgroup()
2173 fs_info->qgroup_drop_subtree_thres = BTRFS_MAX_LEVEL; in btrfs_init_qgroup()
2174 mutex_init(&fs_info->qgroup_rescan_lock); in btrfs_init_qgroup()
2177 static int btrfs_init_workqueues(struct btrfs_fs_info *fs_info) in btrfs_init_workqueues() argument
2179 u32 max_active = fs_info->thread_pool_size; in btrfs_init_workqueues()
2182 fs_info->workers = in btrfs_init_workqueues()
2183 btrfs_alloc_workqueue(fs_info, "worker", flags, max_active, 16); in btrfs_init_workqueues()
2184 fs_info->hipri_workers = in btrfs_init_workqueues()
2185 btrfs_alloc_workqueue(fs_info, "worker-high", 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()
2199 fs_info->fixup_workers = in btrfs_init_workqueues()
2200 btrfs_alloc_workqueue(fs_info, "fixup", flags, 1, 0); in btrfs_init_workqueues()
2202 fs_info->endio_workers = in btrfs_init_workqueues()
2204 fs_info->endio_meta_workers = in btrfs_init_workqueues()
2206 fs_info->rmw_workers = alloc_workqueue("btrfs-rmw", flags, max_active); in btrfs_init_workqueues()
2207 fs_info->endio_write_workers = in btrfs_init_workqueues()
2208 btrfs_alloc_workqueue(fs_info, "endio-write", flags, in btrfs_init_workqueues()
2210 fs_info->compressed_write_workers = in btrfs_init_workqueues()
2212 fs_info->endio_freespace_worker = in btrfs_init_workqueues()
2213 btrfs_alloc_workqueue(fs_info, "freespace-write", flags, in btrfs_init_workqueues()
2215 fs_info->delayed_workers = in btrfs_init_workqueues()
2216 btrfs_alloc_workqueue(fs_info, "delayed-meta", flags, in btrfs_init_workqueues()
2218 fs_info->qgroup_rescan_workers = in btrfs_init_workqueues()
2219 btrfs_alloc_workqueue(fs_info, "qgroup-rescan", flags, 1, 0); in btrfs_init_workqueues()
2220 fs_info->discard_ctl.discard_workers = in btrfs_init_workqueues()
2223 if (!(fs_info->workers && fs_info->hipri_workers && in btrfs_init_workqueues()
2224 fs_info->delalloc_workers && fs_info->flush_workers && in btrfs_init_workqueues()
2225 fs_info->endio_workers && fs_info->endio_meta_workers && in btrfs_init_workqueues()
2226 fs_info->compressed_write_workers && in btrfs_init_workqueues()
2227 fs_info->endio_write_workers && in btrfs_init_workqueues()
2228 fs_info->endio_freespace_worker && fs_info->rmw_workers && in btrfs_init_workqueues()
2229 fs_info->caching_workers && fs_info->fixup_workers && in btrfs_init_workqueues()
2230 fs_info->delayed_workers && fs_info->qgroup_rescan_workers && in btrfs_init_workqueues()
2231 fs_info->discard_ctl.discard_workers)) { in btrfs_init_workqueues()
2238 static int btrfs_init_csum_hash(struct btrfs_fs_info *fs_info, u16 csum_type) in btrfs_init_csum_hash() argument
2246 btrfs_err(fs_info, "error allocating %s hash for checksum", in btrfs_init_csum_hash()
2251 fs_info->csum_shash = csum_shash; in btrfs_init_csum_hash()
2253 btrfs_info(fs_info, "using %s (%s) checksum algorithm", in btrfs_init_csum_hash()
2259 static int btrfs_replay_log(struct btrfs_fs_info *fs_info, in btrfs_replay_log() argument
2265 struct btrfs_super_block *disk_super = fs_info->super_copy; in btrfs_replay_log()
2270 btrfs_warn(fs_info, "log replay required on RO media"); in btrfs_replay_log()
2274 log_tree_root = btrfs_alloc_root(fs_info, BTRFS_TREE_LOG_OBJECTID, in btrfs_replay_log()
2280 check.transid = fs_info->generation + 1; in btrfs_replay_log()
2282 log_tree_root->node = read_tree_block(fs_info, bytenr, &check); in btrfs_replay_log()
2284 btrfs_warn(fs_info, "failed to read log tree"); in btrfs_replay_log()
2291 btrfs_err(fs_info, "failed to read log tree"); in btrfs_replay_log()
2299 btrfs_handle_fs_error(fs_info, ret, in btrfs_replay_log()
2305 if (sb_rdonly(fs_info->sb)) { in btrfs_replay_log()
2306 ret = btrfs_commit_super(fs_info); in btrfs_replay_log()
2318 struct btrfs_fs_info *fs_info = tree_root->fs_info; in load_global_roots_objectid() local
2331 btrfs_test_opt(fs_info, IGNOREDATACSUMS)) { in load_global_roots_objectid()
2332 set_bit(BTRFS_FS_STATE_NO_CSUMS, &fs_info->fs_state); in load_global_roots_objectid()
2366 if (!btrfs_test_opt(fs_info, IGNOREBADROOTS)) in load_global_roots_objectid()
2381 fs_info->nr_global_roots = max_global_id + 1; in load_global_roots_objectid()
2385 set_bit(BTRFS_FS_STATE_NO_CSUMS, &fs_info->fs_state); in load_global_roots_objectid()
2387 if (!btrfs_test_opt(fs_info, IGNOREBADROOTS)) in load_global_roots_objectid()
2391 btrfs_err(fs_info, "failed to load root %s", name); in load_global_roots_objectid()
2413 if (!btrfs_fs_compat_ro(tree_root->fs_info, FREE_SPACE_TREE)) in load_global_roots()
2423 static int btrfs_read_roots(struct btrfs_fs_info *fs_info) in btrfs_read_roots() argument
2425 struct btrfs_root *tree_root = fs_info->tree_root; in btrfs_read_roots()
2430 BUG_ON(!fs_info->tree_root); in btrfs_read_roots()
2439 if (btrfs_fs_compat_ro(fs_info, BLOCK_GROUP_TREE)) { in btrfs_read_roots()
2443 if (!btrfs_test_opt(fs_info, IGNOREBADROOTS)) { in btrfs_read_roots()
2449 fs_info->block_group_root = root; in btrfs_read_roots()
2456 if (!btrfs_test_opt(fs_info, IGNOREBADROOTS)) { in btrfs_read_roots()
2462 fs_info->dev_root = root; in btrfs_read_roots()
2465 ret = btrfs_init_devices_late(fs_info); in btrfs_read_roots()
2473 root = btrfs_get_fs_root(tree_root->fs_info, in btrfs_read_roots()
2476 if (!btrfs_test_opt(fs_info, IGNOREBADROOTS)) { in btrfs_read_roots()
2482 fs_info->data_reloc_root = root; in btrfs_read_roots()
2489 set_bit(BTRFS_FS_QUOTA_ENABLED, &fs_info->flags); in btrfs_read_roots()
2490 fs_info->quota_root = root; in btrfs_read_roots()
2496 if (!btrfs_test_opt(fs_info, IGNOREBADROOTS)) { in btrfs_read_roots()
2503 fs_info->uuid_root = root; in btrfs_read_roots()
2508 btrfs_warn(fs_info, "failed to read root (objectid=%llu): %d", in btrfs_read_roots()
2523 int btrfs_validate_super(struct btrfs_fs_info *fs_info, in btrfs_validate_super() argument
2531 btrfs_err(fs_info, "no valid FS found"); in btrfs_validate_super()
2535 btrfs_err(fs_info, "unrecognized or unsupported super flag: %llu", in btrfs_validate_super()
2540 btrfs_err(fs_info, "tree_root level too big: %d >= %d", in btrfs_validate_super()
2545 btrfs_err(fs_info, "chunk_root level too big: %d >= %d", in btrfs_validate_super()
2550 btrfs_err(fs_info, "log_root level too big: %d >= %d", in btrfs_validate_super()
2561 btrfs_err(fs_info, "invalid sectorsize %llu", sectorsize); in btrfs_validate_super()
2574 btrfs_err(fs_info, in btrfs_validate_super()
2582 btrfs_err(fs_info, "invalid nodesize %llu", nodesize); in btrfs_validate_super()
2586 btrfs_err(fs_info, "invalid leafsize %u, should be %llu", in btrfs_validate_super()
2593 btrfs_warn(fs_info, "tree_root block unaligned: %llu", in btrfs_validate_super()
2598 btrfs_warn(fs_info, "chunk_root block unaligned: %llu", in btrfs_validate_super()
2603 btrfs_warn(fs_info, "log_root block unaligned: %llu", in btrfs_validate_super()
2608 if (memcmp(fs_info->fs_devices->fsid, fs_info->super_copy->fsid, in btrfs_validate_super()
2610 btrfs_err(fs_info, in btrfs_validate_super()
2612 fs_info->super_copy->fsid, fs_info->fs_devices->fsid); in btrfs_validate_super()
2616 if (btrfs_fs_incompat(fs_info, METADATA_UUID) && in btrfs_validate_super()
2617 memcmp(fs_info->fs_devices->metadata_uuid, in btrfs_validate_super()
2618 fs_info->super_copy->metadata_uuid, BTRFS_FSID_SIZE)) { in btrfs_validate_super()
2619 btrfs_err(fs_info, in btrfs_validate_super()
2621 fs_info->super_copy->metadata_uuid, in btrfs_validate_super()
2622 fs_info->fs_devices->metadata_uuid); in btrfs_validate_super()
2630 if (btrfs_fs_compat_ro(fs_info, BLOCK_GROUP_TREE) && in btrfs_validate_super()
2631 (!btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE_VALID) || in btrfs_validate_super()
2632 !btrfs_fs_incompat(fs_info, NO_HOLES))) { in btrfs_validate_super()
2633 btrfs_err(fs_info, in btrfs_validate_super()
2638 if (memcmp(fs_info->fs_devices->metadata_uuid, sb->dev_item.fsid, in btrfs_validate_super()
2640 btrfs_err(fs_info, in btrfs_validate_super()
2642 fs_info->fs_devices->metadata_uuid, sb->dev_item.fsid); in btrfs_validate_super()
2651 btrfs_err(fs_info, "bytes_used is too small %llu", in btrfs_validate_super()
2656 btrfs_err(fs_info, "invalid stripesize %u", in btrfs_validate_super()
2661 btrfs_warn(fs_info, "suspicious number of devices: %llu", in btrfs_validate_super()
2664 btrfs_err(fs_info, "number of devices is 0"); in btrfs_validate_super()
2670 btrfs_err(fs_info, "super offset mismatch %llu != %u", in btrfs_validate_super()
2680 btrfs_err(fs_info, "system chunk array too big %u > %u", in btrfs_validate_super()
2687 btrfs_err(fs_info, "system chunk array too small %u < %zu", in btrfs_validate_super()
2699 btrfs_warn(fs_info, in btrfs_validate_super()
2705 btrfs_warn(fs_info, in btrfs_validate_super()
2718 static int btrfs_validate_mount_super(struct btrfs_fs_info *fs_info) in btrfs_validate_mount_super() argument
2720 return btrfs_validate_super(fs_info, fs_info->super_copy, 0); in btrfs_validate_mount_super()
2729 static int btrfs_validate_write_super(struct btrfs_fs_info *fs_info, in btrfs_validate_write_super() argument
2734 ret = btrfs_validate_super(fs_info, sb, -1); in btrfs_validate_write_super()
2739 btrfs_err(fs_info, "invalid csum type, has %u want %u", in btrfs_validate_write_super()
2745 btrfs_err(fs_info, in btrfs_validate_write_super()
2753 btrfs_err(fs_info, in btrfs_validate_write_super()
2767 root->node = read_tree_block(root->fs_info, bytenr, &check); in load_super_root()
2785 static int load_important_roots(struct btrfs_fs_info *fs_info) in load_important_roots() argument
2787 struct btrfs_super_block *sb = fs_info->super_copy; in load_important_roots()
2794 ret = load_super_root(fs_info->tree_root, bytenr, gen, level); in load_important_roots()
2796 btrfs_warn(fs_info, "couldn't read tree root"); in load_important_roots()
2802 static int __cold init_tree_roots(struct btrfs_fs_info *fs_info) in init_tree_roots() argument
2804 int backup_index = find_newest_super_backup(fs_info); in init_tree_roots()
2805 struct btrfs_super_block *sb = fs_info->super_copy; in init_tree_roots()
2806 struct btrfs_root *tree_root = fs_info->tree_root; in init_tree_roots()
2817 if (!btrfs_test_opt(fs_info, USEBACKUPROOT)) in init_tree_roots()
2820 free_root_pointers(fs_info, 0); in init_tree_roots()
2829 btrfs_set_opt(fs_info->mount_opt, CLEAR_CACHE); in init_tree_roots()
2831 ret = read_backup_root(fs_info, i); in init_tree_roots()
2837 ret = load_important_roots(fs_info); in init_tree_roots()
2855 ret = btrfs_read_roots(fs_info); in init_tree_roots()
2862 fs_info->generation = btrfs_header_generation(tree_root->node); in init_tree_roots()
2863 fs_info->last_trans_committed = fs_info->generation; in init_tree_roots()
2864 fs_info->last_reloc_trans = 0; in init_tree_roots()
2868 fs_info->backup_root_index = 0; in init_tree_roots()
2870 fs_info->backup_root_index = backup_index + 1; in init_tree_roots()
2871 fs_info->backup_root_index %= BTRFS_NUM_BACKUP_ROOTS; in init_tree_roots()
2879 void btrfs_init_fs_info(struct btrfs_fs_info *fs_info) in btrfs_init_fs_info() argument
2881 INIT_RADIX_TREE(&fs_info->fs_roots_radix, GFP_ATOMIC); in btrfs_init_fs_info()
2882 INIT_RADIX_TREE(&fs_info->buffer_radix, GFP_ATOMIC); in btrfs_init_fs_info()
2883 INIT_LIST_HEAD(&fs_info->trans_list); in btrfs_init_fs_info()
2884 INIT_LIST_HEAD(&fs_info->dead_roots); in btrfs_init_fs_info()
2885 INIT_LIST_HEAD(&fs_info->delayed_iputs); in btrfs_init_fs_info()
2886 INIT_LIST_HEAD(&fs_info->delalloc_roots); in btrfs_init_fs_info()
2887 INIT_LIST_HEAD(&fs_info->caching_block_groups); in btrfs_init_fs_info()
2888 spin_lock_init(&fs_info->delalloc_root_lock); in btrfs_init_fs_info()
2889 spin_lock_init(&fs_info->trans_lock); in btrfs_init_fs_info()
2890 spin_lock_init(&fs_info->fs_roots_radix_lock); in btrfs_init_fs_info()
2891 spin_lock_init(&fs_info->delayed_iput_lock); in btrfs_init_fs_info()
2892 spin_lock_init(&fs_info->defrag_inodes_lock); in btrfs_init_fs_info()
2893 spin_lock_init(&fs_info->super_lock); in btrfs_init_fs_info()
2894 spin_lock_init(&fs_info->buffer_lock); in btrfs_init_fs_info()
2895 spin_lock_init(&fs_info->unused_bgs_lock); in btrfs_init_fs_info()
2896 spin_lock_init(&fs_info->treelog_bg_lock); in btrfs_init_fs_info()
2897 spin_lock_init(&fs_info->zone_active_bgs_lock); in btrfs_init_fs_info()
2898 spin_lock_init(&fs_info->relocation_bg_lock); in btrfs_init_fs_info()
2899 rwlock_init(&fs_info->tree_mod_log_lock); in btrfs_init_fs_info()
2900 rwlock_init(&fs_info->global_root_lock); in btrfs_init_fs_info()
2901 mutex_init(&fs_info->unused_bg_unpin_mutex); in btrfs_init_fs_info()
2902 mutex_init(&fs_info->reclaim_bgs_lock); in btrfs_init_fs_info()
2903 mutex_init(&fs_info->reloc_mutex); in btrfs_init_fs_info()
2904 mutex_init(&fs_info->delalloc_root_mutex); in btrfs_init_fs_info()
2905 mutex_init(&fs_info->zoned_meta_io_lock); in btrfs_init_fs_info()
2906 mutex_init(&fs_info->zoned_data_reloc_io_lock); in btrfs_init_fs_info()
2907 seqlock_init(&fs_info->profiles_lock); in btrfs_init_fs_info()
2909 btrfs_lockdep_init_map(fs_info, btrfs_trans_num_writers); in btrfs_init_fs_info()
2910 btrfs_lockdep_init_map(fs_info, btrfs_trans_num_extwriters); in btrfs_init_fs_info()
2911 btrfs_lockdep_init_map(fs_info, btrfs_trans_pending_ordered); in btrfs_init_fs_info()
2912 btrfs_lockdep_init_map(fs_info, btrfs_ordered_extent); in btrfs_init_fs_info()
2913 btrfs_state_lockdep_init_map(fs_info, btrfs_trans_commit_start, in btrfs_init_fs_info()
2915 btrfs_state_lockdep_init_map(fs_info, btrfs_trans_unblocked, in btrfs_init_fs_info()
2917 btrfs_state_lockdep_init_map(fs_info, btrfs_trans_super_committed, in btrfs_init_fs_info()
2919 btrfs_state_lockdep_init_map(fs_info, btrfs_trans_completed, in btrfs_init_fs_info()
2922 INIT_LIST_HEAD(&fs_info->dirty_cowonly_roots); in btrfs_init_fs_info()
2923 INIT_LIST_HEAD(&fs_info->space_info); in btrfs_init_fs_info()
2924 INIT_LIST_HEAD(&fs_info->tree_mod_seq_list); in btrfs_init_fs_info()
2925 INIT_LIST_HEAD(&fs_info->unused_bgs); in btrfs_init_fs_info()
2926 INIT_LIST_HEAD(&fs_info->reclaim_bgs); in btrfs_init_fs_info()
2927 INIT_LIST_HEAD(&fs_info->zone_active_bgs); in btrfs_init_fs_info()
2929 INIT_LIST_HEAD(&fs_info->allocated_roots); in btrfs_init_fs_info()
2930 INIT_LIST_HEAD(&fs_info->allocated_ebs); in btrfs_init_fs_info()
2931 spin_lock_init(&fs_info->eb_leak_lock); in btrfs_init_fs_info()
2933 extent_map_tree_init(&fs_info->mapping_tree); in btrfs_init_fs_info()
2934 btrfs_init_block_rsv(&fs_info->global_block_rsv, in btrfs_init_fs_info()
2936 btrfs_init_block_rsv(&fs_info->trans_block_rsv, BTRFS_BLOCK_RSV_TRANS); in btrfs_init_fs_info()
2937 btrfs_init_block_rsv(&fs_info->chunk_block_rsv, BTRFS_BLOCK_RSV_CHUNK); in btrfs_init_fs_info()
2938 btrfs_init_block_rsv(&fs_info->empty_block_rsv, BTRFS_BLOCK_RSV_EMPTY); in btrfs_init_fs_info()
2939 btrfs_init_block_rsv(&fs_info->delayed_block_rsv, in btrfs_init_fs_info()
2941 btrfs_init_block_rsv(&fs_info->delayed_refs_rsv, in btrfs_init_fs_info()
2944 atomic_set(&fs_info->async_delalloc_pages, 0); in btrfs_init_fs_info()
2945 atomic_set(&fs_info->defrag_running, 0); in btrfs_init_fs_info()
2946 atomic_set(&fs_info->nr_delayed_iputs, 0); in btrfs_init_fs_info()
2947 atomic64_set(&fs_info->tree_mod_seq, 0); in btrfs_init_fs_info()
2948 fs_info->global_root_tree = RB_ROOT; in btrfs_init_fs_info()
2949 fs_info->max_inline = BTRFS_DEFAULT_MAX_INLINE; in btrfs_init_fs_info()
2950 fs_info->metadata_ratio = 0; in btrfs_init_fs_info()
2951 fs_info->defrag_inodes = RB_ROOT; in btrfs_init_fs_info()
2952 atomic64_set(&fs_info->free_chunk_space, 0); in btrfs_init_fs_info()
2953 fs_info->tree_mod_log = RB_ROOT; in btrfs_init_fs_info()
2954 fs_info->commit_interval = BTRFS_DEFAULT_COMMIT_INTERVAL; in btrfs_init_fs_info()
2955 fs_info->avg_delayed_ref_runtime = NSEC_PER_SEC >> 6; /* div by 64 */ in btrfs_init_fs_info()
2956 btrfs_init_ref_verify(fs_info); in btrfs_init_fs_info()
2958 fs_info->thread_pool_size = min_t(unsigned long, in btrfs_init_fs_info()
2961 INIT_LIST_HEAD(&fs_info->ordered_roots); in btrfs_init_fs_info()
2962 spin_lock_init(&fs_info->ordered_root_lock); in btrfs_init_fs_info()
2964 btrfs_init_scrub(fs_info); in btrfs_init_fs_info()
2966 fs_info->check_integrity_print_mask = 0; in btrfs_init_fs_info()
2968 btrfs_init_balance(fs_info); in btrfs_init_fs_info()
2969 btrfs_init_async_reclaim_work(fs_info); in btrfs_init_fs_info()
2971 rwlock_init(&fs_info->block_group_cache_lock); in btrfs_init_fs_info()
2972 fs_info->block_group_cache_tree = RB_ROOT_CACHED; in btrfs_init_fs_info()
2974 extent_io_tree_init(fs_info, &fs_info->excluded_extents, in btrfs_init_fs_info()
2977 mutex_init(&fs_info->ordered_operations_mutex); in btrfs_init_fs_info()
2978 mutex_init(&fs_info->tree_log_mutex); in btrfs_init_fs_info()
2979 mutex_init(&fs_info->chunk_mutex); in btrfs_init_fs_info()
2980 mutex_init(&fs_info->transaction_kthread_mutex); in btrfs_init_fs_info()
2981 mutex_init(&fs_info->cleaner_mutex); in btrfs_init_fs_info()
2982 mutex_init(&fs_info->ro_block_group_mutex); in btrfs_init_fs_info()
2983 init_rwsem(&fs_info->commit_root_sem); in btrfs_init_fs_info()
2984 init_rwsem(&fs_info->cleanup_work_sem); in btrfs_init_fs_info()
2985 init_rwsem(&fs_info->subvol_sem); in btrfs_init_fs_info()
2986 sema_init(&fs_info->uuid_tree_rescan_sem, 1); in btrfs_init_fs_info()
2988 btrfs_init_dev_replace_locks(fs_info); in btrfs_init_fs_info()
2989 btrfs_init_qgroup(fs_info); in btrfs_init_fs_info()
2990 btrfs_discard_init(fs_info); in btrfs_init_fs_info()
2992 btrfs_init_free_cluster(&fs_info->meta_alloc_cluster); in btrfs_init_fs_info()
2993 btrfs_init_free_cluster(&fs_info->data_alloc_cluster); in btrfs_init_fs_info()
2995 init_waitqueue_head(&fs_info->transaction_throttle); in btrfs_init_fs_info()
2996 init_waitqueue_head(&fs_info->transaction_wait); in btrfs_init_fs_info()
2997 init_waitqueue_head(&fs_info->transaction_blocked_wait); in btrfs_init_fs_info()
2998 init_waitqueue_head(&fs_info->async_submit_wait); in btrfs_init_fs_info()
2999 init_waitqueue_head(&fs_info->delayed_iputs_wait); in btrfs_init_fs_info()
3002 fs_info->nodesize = 4096; in btrfs_init_fs_info()
3003 fs_info->sectorsize = 4096; in btrfs_init_fs_info()
3004 fs_info->sectorsize_bits = ilog2(4096); in btrfs_init_fs_info()
3005 fs_info->stripesize = 4096; in btrfs_init_fs_info()
3007 fs_info->max_extent_size = BTRFS_MAX_EXTENT_SIZE; in btrfs_init_fs_info()
3009 spin_lock_init(&fs_info->swapfile_pins_lock); in btrfs_init_fs_info()
3010 fs_info->swapfile_pins = RB_ROOT; in btrfs_init_fs_info()
3012 fs_info->bg_reclaim_threshold = BTRFS_DEFAULT_RECLAIM_THRESH; in btrfs_init_fs_info()
3013 INIT_WORK(&fs_info->reclaim_bgs_work, btrfs_reclaim_bgs_work); in btrfs_init_fs_info()
3016 static int init_mount_fs_info(struct btrfs_fs_info *fs_info, struct super_block *sb) in init_mount_fs_info() argument
3020 fs_info->sb = sb; in init_mount_fs_info()
3024 ret = percpu_counter_init(&fs_info->ordered_bytes, 0, GFP_KERNEL); in init_mount_fs_info()
3028 ret = percpu_counter_init(&fs_info->dirty_metadata_bytes, 0, GFP_KERNEL); in init_mount_fs_info()
3032 fs_info->dirty_metadata_batch = PAGE_SIZE * in init_mount_fs_info()
3035 ret = percpu_counter_init(&fs_info->delalloc_bytes, 0, GFP_KERNEL); in init_mount_fs_info()
3039 ret = percpu_counter_init(&fs_info->dev_replace.bio_counter, 0, in init_mount_fs_info()
3044 fs_info->delayed_root = kmalloc(sizeof(struct btrfs_delayed_root), in init_mount_fs_info()
3046 if (!fs_info->delayed_root) in init_mount_fs_info()
3048 btrfs_init_delayed_root(fs_info->delayed_root); in init_mount_fs_info()
3051 set_bit(BTRFS_FS_STATE_RO, &fs_info->fs_state); in init_mount_fs_info()
3053 return btrfs_alloc_stripe_hash_table(fs_info); in init_mount_fs_info()
3058 struct btrfs_fs_info *fs_info = data; in btrfs_uuid_rescan_kthread() local
3066 ret = btrfs_uuid_tree_iterate(fs_info); in btrfs_uuid_rescan_kthread()
3069 btrfs_warn(fs_info, "iterating uuid_tree failed %d", in btrfs_uuid_rescan_kthread()
3071 up(&fs_info->uuid_tree_rescan_sem); in btrfs_uuid_rescan_kthread()
3077 static int btrfs_check_uuid_tree(struct btrfs_fs_info *fs_info) in btrfs_check_uuid_tree() argument
3081 down(&fs_info->uuid_tree_rescan_sem); in btrfs_check_uuid_tree()
3082 task = kthread_run(btrfs_uuid_rescan_kthread, fs_info, "btrfs-uuid"); in btrfs_check_uuid_tree()
3085 btrfs_warn(fs_info, "failed to start uuid_rescan task"); in btrfs_check_uuid_tree()
3086 up(&fs_info->uuid_tree_rescan_sem); in btrfs_check_uuid_tree()
3098 void btrfs_clear_oneshot_options(struct btrfs_fs_info *fs_info) in btrfs_clear_oneshot_options() argument
3100 btrfs_clear_opt(fs_info->mount_opt, USEBACKUPROOT); in btrfs_clear_oneshot_options()
3101 btrfs_clear_opt(fs_info->mount_opt, CLEAR_CACHE); in btrfs_clear_oneshot_options()
3108 int btrfs_start_pre_rw_mount(struct btrfs_fs_info *fs_info) in btrfs_start_pre_rw_mount() argument
3111 const bool cache_opt = btrfs_test_opt(fs_info, SPACE_CACHE); in btrfs_start_pre_rw_mount()
3114 if (btrfs_test_opt(fs_info, CLEAR_CACHE) && in btrfs_start_pre_rw_mount()
3115 btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE)) { in btrfs_start_pre_rw_mount()
3117 } else if (btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE) && in btrfs_start_pre_rw_mount()
3118 !btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE_VALID)) { in btrfs_start_pre_rw_mount()
3119 btrfs_warn(fs_info, "free space tree is invalid"); in btrfs_start_pre_rw_mount()
3124 btrfs_info(fs_info, "clearing free space tree"); in btrfs_start_pre_rw_mount()
3125 ret = btrfs_clear_free_space_tree(fs_info); in btrfs_start_pre_rw_mount()
3127 btrfs_warn(fs_info, in btrfs_start_pre_rw_mount()
3144 ret = btrfs_find_orphan_roots(fs_info); in btrfs_start_pre_rw_mount()
3148 ret = btrfs_cleanup_fs_roots(fs_info); in btrfs_start_pre_rw_mount()
3152 down_read(&fs_info->cleanup_work_sem); in btrfs_start_pre_rw_mount()
3153 if ((ret = btrfs_orphan_cleanup(fs_info->fs_root)) || in btrfs_start_pre_rw_mount()
3154 (ret = btrfs_orphan_cleanup(fs_info->tree_root))) { in btrfs_start_pre_rw_mount()
3155 up_read(&fs_info->cleanup_work_sem); in btrfs_start_pre_rw_mount()
3158 up_read(&fs_info->cleanup_work_sem); in btrfs_start_pre_rw_mount()
3160 mutex_lock(&fs_info->cleaner_mutex); in btrfs_start_pre_rw_mount()
3161 ret = btrfs_recover_relocation(fs_info); in btrfs_start_pre_rw_mount()
3162 mutex_unlock(&fs_info->cleaner_mutex); in btrfs_start_pre_rw_mount()
3164 btrfs_warn(fs_info, "failed to recover relocation: %d", ret); in btrfs_start_pre_rw_mount()
3168 if (btrfs_test_opt(fs_info, FREE_SPACE_TREE) && in btrfs_start_pre_rw_mount()
3169 !btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE)) { in btrfs_start_pre_rw_mount()
3170 btrfs_info(fs_info, "creating free space tree"); in btrfs_start_pre_rw_mount()
3171 ret = btrfs_create_free_space_tree(fs_info); in btrfs_start_pre_rw_mount()
3173 btrfs_warn(fs_info, in btrfs_start_pre_rw_mount()
3179 if (cache_opt != btrfs_free_space_cache_v1_active(fs_info)) { in btrfs_start_pre_rw_mount()
3180 ret = btrfs_set_free_space_cache_v1_active(fs_info, cache_opt); in btrfs_start_pre_rw_mount()
3185 ret = btrfs_resume_balance_async(fs_info); in btrfs_start_pre_rw_mount()
3189 ret = btrfs_resume_dev_replace_async(fs_info); in btrfs_start_pre_rw_mount()
3191 btrfs_warn(fs_info, "failed to resume dev_replace"); in btrfs_start_pre_rw_mount()
3195 btrfs_qgroup_rescan_resume(fs_info); in btrfs_start_pre_rw_mount()
3197 if (!fs_info->uuid_root) { in btrfs_start_pre_rw_mount()
3198 btrfs_info(fs_info, "creating UUID tree"); in btrfs_start_pre_rw_mount()
3199 ret = btrfs_create_uuid_tree(fs_info); in btrfs_start_pre_rw_mount()
3201 btrfs_warn(fs_info, in btrfs_start_pre_rw_mount()
3226 int btrfs_check_features(struct btrfs_fs_info *fs_info, bool is_rw_mount) in btrfs_check_features() argument
3228 struct btrfs_super_block *disk_super = fs_info->super_copy; in btrfs_check_features()
3234 btrfs_err(fs_info, in btrfs_check_features()
3242 (fs_info->sectorsize != fs_info->nodesize)) { in btrfs_check_features()
3243 btrfs_err(fs_info, in btrfs_check_features()
3245 fs_info->nodesize, fs_info->sectorsize); in btrfs_check_features()
3253 if (fs_info->compress_type == BTRFS_COMPRESS_LZO) in btrfs_check_features()
3255 else if (fs_info->compress_type == BTRFS_COMPRESS_ZSTD) in btrfs_check_features()
3266 btrfs_err(fs_info, in btrfs_check_features()
3278 !btrfs_test_opt(fs_info, NOLOGREPLAY)) { in btrfs_check_features()
3279 btrfs_err(fs_info, in btrfs_check_features()
3289 if (btrfs_fs_compat_ro(fs_info, BLOCK_GROUP_TREE) && in btrfs_check_features()
3290 (!btrfs_fs_incompat(fs_info, NO_HOLES) || in btrfs_check_features()
3291 !btrfs_test_opt(fs_info, FREE_SPACE_TREE))) { in btrfs_check_features()
3292 btrfs_err(fs_info, in btrfs_check_features()
3304 if (fs_info->sectorsize < PAGE_SIZE && btrfs_test_opt(fs_info, SPACE_CACHE)) { in btrfs_check_features()
3305 btrfs_warn(fs_info, in btrfs_check_features()
3307 PAGE_SIZE, fs_info->sectorsize); in btrfs_check_features()
3312 spin_lock(&fs_info->super_lock); in btrfs_check_features()
3314 spin_unlock(&fs_info->super_lock); in btrfs_check_features()
3329 struct btrfs_fs_info *fs_info = btrfs_sb(sb); in open_ctree() local
3336 ret = init_mount_fs_info(fs_info, sb); in open_ctree()
3343 tree_root = btrfs_alloc_root(fs_info, BTRFS_ROOT_TREE_OBJECTID, in open_ctree()
3345 fs_info->tree_root = tree_root; in open_ctree()
3346 chunk_root = btrfs_alloc_root(fs_info, BTRFS_CHUNK_TREE_OBJECTID, in open_ctree()
3348 fs_info->chunk_root = chunk_root; in open_ctree()
3354 fs_info->btree_inode = new_inode(sb); in open_ctree()
3355 if (!fs_info->btree_inode) { in open_ctree()
3359 mapping_set_gfp_mask(fs_info->btree_inode->i_mapping, GFP_NOFS); in open_ctree()
3360 btrfs_init_btree_inode(fs_info); in open_ctree()
3379 btrfs_err(fs_info, "unsupported checksum algorithm: %u", in open_ctree()
3386 fs_info->csum_size = btrfs_super_csum_size(disk_super); in open_ctree()
3388 ret = btrfs_init_csum_hash(fs_info, csum_type); in open_ctree()
3399 if (btrfs_check_super_csum(fs_info, disk_super)) { in open_ctree()
3400 btrfs_err(fs_info, "superblock checksum mismatch"); in open_ctree()
3411 memcpy(fs_info->super_copy, disk_super, sizeof(*fs_info->super_copy)); in open_ctree()
3414 disk_super = fs_info->super_copy; in open_ctree()
3421 btrfs_info(fs_info, in open_ctree()
3425 memcpy(fs_info->super_for_commit, fs_info->super_copy, in open_ctree()
3426 sizeof(*fs_info->super_for_commit)); in open_ctree()
3428 ret = btrfs_validate_mount_super(fs_info); in open_ctree()
3430 btrfs_err(fs_info, "superblock contains fatal errors"); in open_ctree()
3440 set_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state); in open_ctree()
3446 fs_info->compress_type = BTRFS_COMPRESS_ZLIB; in open_ctree()
3453 fs_info->dirty_metadata_batch = nodesize * (1 + ilog2(nr_cpu_ids)); in open_ctree()
3454 fs_info->delalloc_batch = sectorsize * 512 * (1 + ilog2(nr_cpu_ids)); in open_ctree()
3456 fs_info->nodesize = nodesize; in open_ctree()
3457 fs_info->sectorsize = sectorsize; in open_ctree()
3458 fs_info->sectorsize_bits = ilog2(sectorsize); in open_ctree()
3459 fs_info->csums_per_leaf = BTRFS_MAX_ITEM_SIZE(fs_info) / fs_info->csum_size; in open_ctree()
3460 fs_info->stripesize = stripesize; in open_ctree()
3462 ret = btrfs_parse_options(fs_info, options, sb->s_flags); in open_ctree()
3468 ret = btrfs_check_features(fs_info, !sb_rdonly(sb)); in open_ctree()
3483 btrfs_clear_opt(fs_info->mount_opt, SPACE_CACHE); in open_ctree()
3484 btrfs_set_and_info(fs_info, FREE_SPACE_TREE, in open_ctree()
3488 btrfs_warn(fs_info, in open_ctree()
3495 fs_info->subpage_info = subpage_info; in open_ctree()
3498 ret = btrfs_init_workqueues(fs_info); in open_ctree()
3509 memcpy(&sb->s_uuid, fs_info->fs_devices->fsid, BTRFS_FSID_SIZE); in open_ctree()
3511 mutex_lock(&fs_info->chunk_mutex); in open_ctree()
3512 ret = btrfs_read_sys_array(fs_info); in open_ctree()
3513 mutex_unlock(&fs_info->chunk_mutex); in open_ctree()
3515 btrfs_err(fs_info, "failed to read the system array: %d", ret); in open_ctree()
3524 btrfs_err(fs_info, "failed to read chunk root"); in open_ctree()
3528 read_extent_buffer(chunk_root->node, fs_info->chunk_tree_uuid, in open_ctree()
3532 ret = btrfs_read_chunk_tree(fs_info); in open_ctree()
3534 btrfs_err(fs_info, "failed to read chunk tree: %d", ret); in open_ctree()
3547 btrfs_err(fs_info, "failed to read devices"); in open_ctree()
3551 ret = init_tree_roots(fs_info); in open_ctree()
3560 ret = btrfs_get_dev_zone_info_all_devices(fs_info); in open_ctree()
3562 btrfs_err(fs_info, in open_ctree()
3576 if (fs_info->uuid_root && !btrfs_test_opt(fs_info, RESCAN_UUID_TREE) && in open_ctree()
3577 fs_info->generation == btrfs_super_uuid_tree_generation(disk_super)) in open_ctree()
3578 set_bit(BTRFS_FS_UPDATE_UUID_TREE_GEN, &fs_info->flags); in open_ctree()
3580 ret = btrfs_verify_dev_extents(fs_info); in open_ctree()
3582 btrfs_err(fs_info, in open_ctree()
3587 ret = btrfs_recover_balance(fs_info); in open_ctree()
3589 btrfs_err(fs_info, "failed to recover balance: %d", ret); in open_ctree()
3593 ret = btrfs_init_dev_stats(fs_info); in open_ctree()
3595 btrfs_err(fs_info, "failed to init dev_stats: %d", ret); in open_ctree()
3599 ret = btrfs_init_dev_replace(fs_info); in open_ctree()
3601 btrfs_err(fs_info, "failed to init dev_replace: %d", ret); in open_ctree()
3605 ret = btrfs_check_zoned_mode(fs_info); in open_ctree()
3607 btrfs_err(fs_info, "failed to initialize zoned mode: %d", in open_ctree()
3614 btrfs_err(fs_info, "failed to init sysfs fsid interface: %d", in open_ctree()
3619 ret = btrfs_sysfs_add_mounted(fs_info); in open_ctree()
3621 btrfs_err(fs_info, "failed to init sysfs interface: %d", ret); in open_ctree()
3625 ret = btrfs_init_space_info(fs_info); in open_ctree()
3627 btrfs_err(fs_info, "failed to initialize space info: %d", ret); in open_ctree()
3631 ret = btrfs_read_block_groups(fs_info); in open_ctree()
3633 btrfs_err(fs_info, "failed to read block groups: %d", ret); in open_ctree()
3637 btrfs_free_zone_cache(fs_info); in open_ctree()
3639 if (!sb_rdonly(sb) && fs_info->fs_devices->missing_devices && in open_ctree()
3640 !btrfs_check_rw_degradable(fs_info, NULL)) { in open_ctree()
3641 btrfs_warn(fs_info, in open_ctree()
3646 fs_info->cleaner_kthread = kthread_run(cleaner_kthread, fs_info, in open_ctree()
3648 if (IS_ERR(fs_info->cleaner_kthread)) in open_ctree()
3651 fs_info->transaction_kthread = kthread_run(transaction_kthread, in open_ctree()
3654 if (IS_ERR(fs_info->transaction_kthread)) in open_ctree()
3657 if (!btrfs_test_opt(fs_info, NOSSD) && in open_ctree()
3658 !fs_info->fs_devices->rotating) { in open_ctree()
3659 btrfs_set_and_info(fs_info, SSD, "enabling ssd optimizations"); in open_ctree()
3667 if (!(btrfs_test_opt(fs_info, DISCARD_SYNC) || in open_ctree()
3668 btrfs_test_opt(fs_info, DISCARD_ASYNC) || in open_ctree()
3669 btrfs_test_opt(fs_info, NODISCARD)) && in open_ctree()
3670 fs_info->fs_devices->discardable) { in open_ctree()
3671 btrfs_set_and_info(fs_info, DISCARD_ASYNC, in open_ctree()
3673 btrfs_clear_opt(fs_info->mount_opt, NODISCARD); in open_ctree()
3677 if (btrfs_test_opt(fs_info, CHECK_INTEGRITY)) { in open_ctree()
3678 ret = btrfsic_mount(fs_info, fs_devices, in open_ctree()
3679 btrfs_test_opt(fs_info, in open_ctree()
3681 fs_info->check_integrity_print_mask); in open_ctree()
3683 btrfs_warn(fs_info, in open_ctree()
3688 ret = btrfs_read_qgroup_config(fs_info); in open_ctree()
3692 if (btrfs_build_ref_tree(fs_info)) in open_ctree()
3693 btrfs_err(fs_info, "couldn't build ref tree"); in open_ctree()
3697 !btrfs_test_opt(fs_info, NOLOGREPLAY)) { in open_ctree()
3698 btrfs_info(fs_info, "start tree-log replay"); in open_ctree()
3699 ret = btrfs_replay_log(fs_info, fs_devices); in open_ctree()
3706 fs_info->fs_root = btrfs_get_fs_root(fs_info, BTRFS_FS_TREE_OBJECTID, true); in open_ctree()
3707 if (IS_ERR(fs_info->fs_root)) { in open_ctree()
3708 err = PTR_ERR(fs_info->fs_root); in open_ctree()
3709 btrfs_warn(fs_info, "failed to read fs tree: %d", err); in open_ctree()
3710 fs_info->fs_root = NULL; in open_ctree()
3717 ret = btrfs_start_pre_rw_mount(fs_info); in open_ctree()
3719 close_ctree(fs_info); in open_ctree()
3722 btrfs_discard_resume(fs_info); in open_ctree()
3724 if (fs_info->uuid_root && in open_ctree()
3725 (btrfs_test_opt(fs_info, RESCAN_UUID_TREE) || in open_ctree()
3726 fs_info->generation != btrfs_super_uuid_tree_generation(disk_super))) { in open_ctree()
3727 btrfs_info(fs_info, "checking UUID tree"); in open_ctree()
3728 ret = btrfs_check_uuid_tree(fs_info); in open_ctree()
3730 btrfs_warn(fs_info, in open_ctree()
3732 close_ctree(fs_info); in open_ctree()
3737 set_bit(BTRFS_FS_OPEN, &fs_info->flags); in open_ctree()
3740 if (test_bit(BTRFS_FS_UNFINISHED_DROPS, &fs_info->flags)) in open_ctree()
3741 wake_up_process(fs_info->cleaner_kthread); in open_ctree()
3744 btrfs_clear_oneshot_options(fs_info); in open_ctree()
3748 btrfs_free_qgroup_config(fs_info); in open_ctree()
3750 kthread_stop(fs_info->transaction_kthread); in open_ctree()
3751 btrfs_cleanup_transaction(fs_info); in open_ctree()
3752 btrfs_free_fs_roots(fs_info); in open_ctree()
3754 kthread_stop(fs_info->cleaner_kthread); in open_ctree()
3760 filemap_write_and_wait(fs_info->btree_inode->i_mapping); in open_ctree()
3763 btrfs_sysfs_remove_mounted(fs_info); in open_ctree()
3766 btrfs_sysfs_remove_fsid(fs_info->fs_devices); in open_ctree()
3769 btrfs_put_block_group_cache(fs_info); in open_ctree()
3772 if (fs_info->data_reloc_root) in open_ctree()
3773 btrfs_drop_and_free_fs_root(fs_info, fs_info->data_reloc_root); in open_ctree()
3774 free_root_pointers(fs_info, true); in open_ctree()
3775 invalidate_inode_pages2(fs_info->btree_inode->i_mapping); in open_ctree()
3778 btrfs_stop_all_workers(fs_info); in open_ctree()
3779 btrfs_free_block_groups(fs_info); in open_ctree()
3781 btrfs_mapping_tree_free(&fs_info->mapping_tree); in open_ctree()
3783 iput(fs_info->btree_inode); in open_ctree()
3785 btrfs_close_devices(fs_info->fs_devices); in open_ctree()
3801 btrfs_warn_rl_in_rcu(device->fs_info, in btrfs_end_super_write()
3912 struct btrfs_fs_info *fs_info = device->fs_info; in write_dev_supers() local
3914 SHASH_DESC_ON_STACK(shash, fs_info->csum_shash); in write_dev_supers()
3923 shash->tfm = fs_info->csum_shash; in write_dev_supers()
3935 btrfs_err(device->fs_info, in write_dev_supers()
3954 btrfs_err(device->fs_info, in write_dev_supers()
3986 if (i == 0 && !btrfs_test_opt(device->fs_info, NOBARRIER)) in write_dev_supers()
4057 btrfs_err(device->fs_info, "error writing primary super block to device %llu", in wait_dev_supers()
4125 static int check_barrier_error(struct btrfs_fs_info *fs_info) in check_barrier_error() argument
4127 if (!btrfs_check_rw_degradable(fs_info, NULL)) in check_barrier_error()
4220 int write_all_supers(struct btrfs_fs_info *fs_info, int max_mirrors) in write_all_supers() argument
4232 do_barriers = !btrfs_test_opt(fs_info, NOBARRIER); in write_all_supers()
4240 backup_super_roots(fs_info); in write_all_supers()
4242 sb = fs_info->super_for_commit; in write_all_supers()
4245 mutex_lock(&fs_info->fs_devices->device_list_mutex); in write_all_supers()
4246 head = &fs_info->fs_devices->devices; in write_all_supers()
4247 max_errors = btrfs_super_num_devices(fs_info->super_copy) - 1; in write_all_supers()
4250 ret = barrier_all_devices(fs_info); in write_all_supers()
4253 &fs_info->fs_devices->device_list_mutex); in write_all_supers()
4254 btrfs_handle_fs_error(fs_info, ret, in write_all_supers()
4286 ret = btrfs_validate_write_super(fs_info, sb); in write_all_supers()
4288 mutex_unlock(&fs_info->fs_devices->device_list_mutex); in write_all_supers()
4289 btrfs_handle_fs_error(fs_info, -EUCLEAN, in write_all_supers()
4299 btrfs_err(fs_info, "%d errors while writing supers", in write_all_supers()
4301 mutex_unlock(&fs_info->fs_devices->device_list_mutex); in write_all_supers()
4304 btrfs_handle_fs_error(fs_info, -EIO, in write_all_supers()
4322 mutex_unlock(&fs_info->fs_devices->device_list_mutex); in write_all_supers()
4324 btrfs_handle_fs_error(fs_info, -EIO, in write_all_supers()
4333 void btrfs_drop_and_free_fs_root(struct btrfs_fs_info *fs_info, in btrfs_drop_and_free_fs_root() argument
4338 spin_lock(&fs_info->fs_roots_radix_lock); in btrfs_drop_and_free_fs_root()
4339 radix_tree_delete(&fs_info->fs_roots_radix, in btrfs_drop_and_free_fs_root()
4343 spin_unlock(&fs_info->fs_roots_radix_lock); in btrfs_drop_and_free_fs_root()
4345 if (BTRFS_FS_ERROR(fs_info)) { in btrfs_drop_and_free_fs_root()
4357 int btrfs_cleanup_fs_roots(struct btrfs_fs_info *fs_info) in btrfs_cleanup_fs_roots() argument
4366 spin_lock(&fs_info->fs_roots_radix_lock); in btrfs_cleanup_fs_roots()
4367 ret = radix_tree_gang_lookup(&fs_info->fs_roots_radix, in btrfs_cleanup_fs_roots()
4371 spin_unlock(&fs_info->fs_roots_radix_lock); in btrfs_cleanup_fs_roots()
4385 spin_unlock(&fs_info->fs_roots_radix_lock); in btrfs_cleanup_fs_roots()
4407 int btrfs_commit_super(struct btrfs_fs_info *fs_info) in btrfs_commit_super() argument
4409 struct btrfs_root *root = fs_info->tree_root; in btrfs_commit_super()
4412 mutex_lock(&fs_info->cleaner_mutex); in btrfs_commit_super()
4413 btrfs_run_delayed_iputs(fs_info); in btrfs_commit_super()
4414 mutex_unlock(&fs_info->cleaner_mutex); in btrfs_commit_super()
4415 wake_up_process(fs_info->cleaner_kthread); in btrfs_commit_super()
4418 down_write(&fs_info->cleanup_work_sem); in btrfs_commit_super()
4419 up_write(&fs_info->cleanup_work_sem); in btrfs_commit_super()
4427 static void warn_about_uncommitted_trans(struct btrfs_fs_info *fs_info) in warn_about_uncommitted_trans() argument
4433 if (list_empty(&fs_info->trans_list)) in warn_about_uncommitted_trans()
4440 ASSERT(test_bit(BTRFS_FS_CLOSING_DONE, &fs_info->flags)); in warn_about_uncommitted_trans()
4441 list_for_each_entry_safe(trans, tmp, &fs_info->trans_list, list) { in warn_about_uncommitted_trans()
4454 btrfs_warn(fs_info, in warn_about_uncommitted_trans()
4457 btrfs_cleanup_one_transaction(trans, fs_info); in warn_about_uncommitted_trans()
4459 if (trans == fs_info->running_transaction) in warn_about_uncommitted_trans()
4460 fs_info->running_transaction = NULL; in warn_about_uncommitted_trans()
4464 trace_btrfs_transaction_commit(fs_info); in warn_about_uncommitted_trans()
4469 void __cold close_ctree(struct btrfs_fs_info *fs_info) in close_ctree() argument
4473 set_bit(BTRFS_FS_CLOSING_START, &fs_info->flags); in close_ctree()
4484 btrfs_wake_unfinished_drop(fs_info); in close_ctree()
4495 cancel_work_sync(&fs_info->reclaim_bgs_work); in close_ctree()
4502 kthread_park(fs_info->cleaner_kthread); in close_ctree()
4505 btrfs_qgroup_wait_for_completion(fs_info, false); in close_ctree()
4508 down(&fs_info->uuid_tree_rescan_sem); in close_ctree()
4510 up(&fs_info->uuid_tree_rescan_sem); in close_ctree()
4513 btrfs_pause_balance(fs_info); in close_ctree()
4515 btrfs_dev_replace_suspend_for_unmount(fs_info); in close_ctree()
4517 btrfs_scrub_cancel(fs_info); in close_ctree()
4520 wait_event(fs_info->transaction_wait, in close_ctree()
4521 (atomic_read(&fs_info->defrag_running) == 0)); in close_ctree()
4524 btrfs_cleanup_defrag_inodes(fs_info); in close_ctree()
4546 btrfs_flush_workqueue(fs_info->endio_write_workers); in close_ctree()
4548 btrfs_flush_workqueue(fs_info->endio_freespace_worker); in close_ctree()
4549 btrfs_run_delayed_iputs(fs_info); in close_ctree()
4551 cancel_work_sync(&fs_info->async_reclaim_work); in close_ctree()
4552 cancel_work_sync(&fs_info->async_data_reclaim_work); in close_ctree()
4553 cancel_work_sync(&fs_info->preempt_reclaim_work); in close_ctree()
4556 btrfs_discard_cleanup(fs_info); in close_ctree()
4558 if (!sb_rdonly(fs_info->sb)) { in close_ctree()
4563 btrfs_delete_unused_bgs(fs_info); in close_ctree()
4576 btrfs_flush_workqueue(fs_info->delayed_workers); in close_ctree()
4578 ret = btrfs_commit_super(fs_info); in close_ctree()
4580 btrfs_err(fs_info, "commit super ret %d", ret); in close_ctree()
4583 if (BTRFS_FS_ERROR(fs_info)) in close_ctree()
4584 btrfs_error_commit_super(fs_info); in close_ctree()
4586 kthread_stop(fs_info->transaction_kthread); in close_ctree()
4587 kthread_stop(fs_info->cleaner_kthread); in close_ctree()
4589 ASSERT(list_empty(&fs_info->delayed_iputs)); in close_ctree()
4590 set_bit(BTRFS_FS_CLOSING_DONE, &fs_info->flags); in close_ctree()
4592 if (btrfs_check_quota_leak(fs_info)) { in close_ctree()
4594 btrfs_err(fs_info, "qgroup reserved space leaked"); in close_ctree()
4597 btrfs_free_qgroup_config(fs_info); in close_ctree()
4598 ASSERT(list_empty(&fs_info->delalloc_roots)); in close_ctree()
4600 if (percpu_counter_sum(&fs_info->delalloc_bytes)) { in close_ctree()
4601 btrfs_info(fs_info, "at unmount delalloc count %lld", in close_ctree()
4602 percpu_counter_sum(&fs_info->delalloc_bytes)); in close_ctree()
4605 if (percpu_counter_sum(&fs_info->ordered_bytes)) in close_ctree()
4606 btrfs_info(fs_info, "at unmount dio bytes count %lld", in close_ctree()
4607 percpu_counter_sum(&fs_info->ordered_bytes)); in close_ctree()
4609 btrfs_sysfs_remove_mounted(fs_info); in close_ctree()
4610 btrfs_sysfs_remove_fsid(fs_info->fs_devices); in close_ctree()
4612 btrfs_put_block_group_cache(fs_info); in close_ctree()
4618 invalidate_inode_pages2(fs_info->btree_inode->i_mapping); in close_ctree()
4619 btrfs_stop_all_workers(fs_info); in close_ctree()
4622 warn_about_uncommitted_trans(fs_info); in close_ctree()
4624 clear_bit(BTRFS_FS_OPEN, &fs_info->flags); in close_ctree()
4625 free_root_pointers(fs_info, true); in close_ctree()
4626 btrfs_free_fs_roots(fs_info); in close_ctree()
4635 btrfs_free_block_groups(fs_info); in close_ctree()
4637 iput(fs_info->btree_inode); in close_ctree()
4640 if (btrfs_test_opt(fs_info, CHECK_INTEGRITY)) in close_ctree()
4641 btrfsic_unmount(fs_info->fs_devices); in close_ctree()
4644 btrfs_mapping_tree_free(&fs_info->mapping_tree); in close_ctree()
4645 btrfs_close_devices(fs_info->fs_devices); in close_ctree()
4667 struct btrfs_fs_info *fs_info = buf->fs_info; in btrfs_mark_buffer_dirty() local
4681 if (transid != fs_info->generation) in btrfs_mark_buffer_dirty()
4683 buf->start, transid, fs_info->generation); in btrfs_mark_buffer_dirty()
4686 percpu_counter_add_batch(&fs_info->dirty_metadata_bytes, in btrfs_mark_buffer_dirty()
4688 fs_info->dirty_metadata_batch); in btrfs_mark_buffer_dirty()
4703 static void __btrfs_btree_balance_dirty(struct btrfs_fs_info *fs_info, in __btrfs_btree_balance_dirty() argument
4716 btrfs_balance_delayed_items(fs_info); in __btrfs_btree_balance_dirty()
4718 ret = __percpu_counter_compare(&fs_info->dirty_metadata_bytes, in __btrfs_btree_balance_dirty()
4720 fs_info->dirty_metadata_batch); in __btrfs_btree_balance_dirty()
4722 balance_dirty_pages_ratelimited(fs_info->btree_inode->i_mapping); in __btrfs_btree_balance_dirty()
4726 void btrfs_btree_balance_dirty(struct btrfs_fs_info *fs_info) in btrfs_btree_balance_dirty() argument
4728 __btrfs_btree_balance_dirty(fs_info, 1); in btrfs_btree_balance_dirty()
4731 void btrfs_btree_balance_dirty_nodelay(struct btrfs_fs_info *fs_info) in btrfs_btree_balance_dirty_nodelay() argument
4733 __btrfs_btree_balance_dirty(fs_info, 0); in btrfs_btree_balance_dirty_nodelay()
4736 static void btrfs_error_commit_super(struct btrfs_fs_info *fs_info) in btrfs_error_commit_super() argument
4739 btrfs_cleanup_transaction(fs_info); in btrfs_error_commit_super()
4741 mutex_lock(&fs_info->cleaner_mutex); in btrfs_error_commit_super()
4742 btrfs_run_delayed_iputs(fs_info); in btrfs_error_commit_super()
4743 mutex_unlock(&fs_info->cleaner_mutex); in btrfs_error_commit_super()
4745 down_write(&fs_info->cleanup_work_sem); in btrfs_error_commit_super()
4746 up_write(&fs_info->cleanup_work_sem); in btrfs_error_commit_super()
4749 static void btrfs_drop_all_logs(struct btrfs_fs_info *fs_info) in btrfs_drop_all_logs() argument
4755 spin_lock(&fs_info->fs_roots_radix_lock); in btrfs_drop_all_logs()
4756 while ((ret = radix_tree_gang_lookup(&fs_info->fs_roots_radix, in btrfs_drop_all_logs()
4763 spin_unlock(&fs_info->fs_roots_radix_lock); in btrfs_drop_all_logs()
4773 spin_lock(&fs_info->fs_roots_radix_lock); in btrfs_drop_all_logs()
4775 spin_unlock(&fs_info->fs_roots_radix_lock); in btrfs_drop_all_logs()
4776 btrfs_free_log_root_tree(NULL, fs_info); in btrfs_drop_all_logs()
4794 static void btrfs_destroy_all_ordered_extents(struct btrfs_fs_info *fs_info) in btrfs_destroy_all_ordered_extents() argument
4801 spin_lock(&fs_info->ordered_root_lock); in btrfs_destroy_all_ordered_extents()
4802 list_splice_init(&fs_info->ordered_roots, &splice); in btrfs_destroy_all_ordered_extents()
4807 &fs_info->ordered_roots); in btrfs_destroy_all_ordered_extents()
4809 spin_unlock(&fs_info->ordered_root_lock); in btrfs_destroy_all_ordered_extents()
4813 spin_lock(&fs_info->ordered_root_lock); in btrfs_destroy_all_ordered_extents()
4815 spin_unlock(&fs_info->ordered_root_lock); in btrfs_destroy_all_ordered_extents()
4823 btrfs_wait_ordered_roots(fs_info, U64_MAX, 0, (u64)-1); in btrfs_destroy_all_ordered_extents()
4827 struct btrfs_fs_info *fs_info) in btrfs_destroy_delayed_refs() argument
4839 btrfs_debug(fs_info, "delayed_refs has NO entry"); in btrfs_destroy_delayed_refs()
4876 cache = btrfs_lookup_block_group(fs_info, head->bytenr); in btrfs_destroy_delayed_refs()
4882 btrfs_space_info_update_bytes_pinned(fs_info, in btrfs_destroy_delayed_refs()
4891 btrfs_error_unpin_extent_range(fs_info, head->bytenr, in btrfs_destroy_delayed_refs()
4894 btrfs_cleanup_ref_head_accounting(fs_info, delayed_refs, head); in btrfs_destroy_delayed_refs()
4937 static void btrfs_destroy_all_delalloc_inodes(struct btrfs_fs_info *fs_info) in btrfs_destroy_all_delalloc_inodes() argument
4944 spin_lock(&fs_info->delalloc_root_lock); in btrfs_destroy_all_delalloc_inodes()
4945 list_splice_init(&fs_info->delalloc_roots, &splice); in btrfs_destroy_all_delalloc_inodes()
4951 spin_unlock(&fs_info->delalloc_root_lock); in btrfs_destroy_all_delalloc_inodes()
4956 spin_lock(&fs_info->delalloc_root_lock); in btrfs_destroy_all_delalloc_inodes()
4958 spin_unlock(&fs_info->delalloc_root_lock); in btrfs_destroy_all_delalloc_inodes()
4961 static int btrfs_destroy_marked_extents(struct btrfs_fs_info *fs_info, in btrfs_destroy_marked_extents() argument
4978 eb = find_extent_buffer(fs_info, start); in btrfs_destroy_marked_extents()
4979 start += fs_info->nodesize; in btrfs_destroy_marked_extents()
4995 static int btrfs_destroy_pinned_extent(struct btrfs_fs_info *fs_info, in btrfs_destroy_pinned_extent() argument
5011 mutex_lock(&fs_info->unused_bg_unpin_mutex); in btrfs_destroy_pinned_extent()
5015 mutex_unlock(&fs_info->unused_bg_unpin_mutex); in btrfs_destroy_pinned_extent()
5021 btrfs_error_unpin_extent_range(fs_info, start, end); in btrfs_destroy_pinned_extent()
5022 mutex_unlock(&fs_info->unused_bg_unpin_mutex); in btrfs_destroy_pinned_extent()
5045 struct btrfs_fs_info *fs_info) in btrfs_cleanup_dirty_bgs() argument
5069 btrfs_delayed_refs_rsv_release(fs_info, 1); in btrfs_cleanup_dirty_bgs()
5092 struct btrfs_fs_info *fs_info) in btrfs_cleanup_one_transaction() argument
5096 btrfs_cleanup_dirty_bgs(cur_trans, fs_info); in btrfs_cleanup_one_transaction()
5105 btrfs_destroy_delayed_refs(cur_trans, fs_info); in btrfs_cleanup_one_transaction()
5108 wake_up(&fs_info->transaction_blocked_wait); in btrfs_cleanup_one_transaction()
5111 wake_up(&fs_info->transaction_wait); in btrfs_cleanup_one_transaction()
5113 btrfs_destroy_delayed_inodes(fs_info); in btrfs_cleanup_one_transaction()
5115 btrfs_destroy_marked_extents(fs_info, &cur_trans->dirty_pages, in btrfs_cleanup_one_transaction()
5117 btrfs_destroy_pinned_extent(fs_info, &cur_trans->pinned_extents); in btrfs_cleanup_one_transaction()
5125 static int btrfs_cleanup_transaction(struct btrfs_fs_info *fs_info) in btrfs_cleanup_transaction() argument
5129 mutex_lock(&fs_info->transaction_kthread_mutex); in btrfs_cleanup_transaction()
5131 spin_lock(&fs_info->trans_lock); in btrfs_cleanup_transaction()
5132 while (!list_empty(&fs_info->trans_list)) { in btrfs_cleanup_transaction()
5133 t = list_first_entry(&fs_info->trans_list, in btrfs_cleanup_transaction()
5137 spin_unlock(&fs_info->trans_lock); in btrfs_cleanup_transaction()
5138 btrfs_wait_for_commit(fs_info, t->transid); in btrfs_cleanup_transaction()
5140 spin_lock(&fs_info->trans_lock); in btrfs_cleanup_transaction()
5143 if (t == fs_info->running_transaction) { in btrfs_cleanup_transaction()
5145 spin_unlock(&fs_info->trans_lock); in btrfs_cleanup_transaction()
5153 spin_unlock(&fs_info->trans_lock); in btrfs_cleanup_transaction()
5155 btrfs_cleanup_one_transaction(t, fs_info); in btrfs_cleanup_transaction()
5157 spin_lock(&fs_info->trans_lock); in btrfs_cleanup_transaction()
5158 if (t == fs_info->running_transaction) in btrfs_cleanup_transaction()
5159 fs_info->running_transaction = NULL; in btrfs_cleanup_transaction()
5161 spin_unlock(&fs_info->trans_lock); in btrfs_cleanup_transaction()
5164 trace_btrfs_transaction_commit(fs_info); in btrfs_cleanup_transaction()
5165 spin_lock(&fs_info->trans_lock); in btrfs_cleanup_transaction()
5167 spin_unlock(&fs_info->trans_lock); in btrfs_cleanup_transaction()
5168 btrfs_destroy_all_ordered_extents(fs_info); in btrfs_cleanup_transaction()
5169 btrfs_destroy_delayed_inodes(fs_info); in btrfs_cleanup_transaction()
5170 btrfs_assert_delayed_root_empty(fs_info); in btrfs_cleanup_transaction()
5171 btrfs_destroy_all_delalloc_inodes(fs_info); in btrfs_cleanup_transaction()
5172 btrfs_drop_all_logs(fs_info); in btrfs_cleanup_transaction()
5173 mutex_unlock(&fs_info->transaction_kthread_mutex); in btrfs_cleanup_transaction()
5219 btrfs_warn(root->fs_info, in btrfs_get_free_objectid()