Lines Matching refs:fs_info
32 static int check_tree_block(struct btrfs_fs_info *fs_info, in check_tree_block() argument
36 struct btrfs_fs_devices *fs_devices = fs_info->fs_devices; in check_tree_block()
37 u32 nodesize = fs_info->nodesize; in check_tree_block()
60 if (fs_devices == fs_info->fs_devices && in check_tree_block()
61 btrfs_fs_incompat(fs_info, METADATA_UUID)) in check_tree_block()
82 static void print_tree_block_error(struct btrfs_fs_info *fs_info, in print_tree_block_error() argument
99 uuid_unparse(fs_info->fs_devices->metadata_uuid, fs_uuid); in print_tree_block_error()
345 static int csum_tree_block(struct btrfs_fs_info *fs_info, in csum_tree_block() argument
348 u16 csum_size = btrfs_super_csum_size(fs_info->super_copy); in csum_tree_block()
349 u16 csum_type = btrfs_super_csum_type(fs_info->super_copy); in csum_tree_block()
354 struct extent_buffer *btrfs_find_tree_block(struct btrfs_fs_info *fs_info, in btrfs_find_tree_block() argument
357 return find_extent_buffer(&fs_info->extent_cache, in btrfs_find_tree_block()
362 struct btrfs_fs_info *fs_info, u64 bytenr) in btrfs_find_create_tree_block() argument
364 return alloc_extent_buffer(fs_info, bytenr, fs_info->nodesize); in btrfs_find_create_tree_block()
442 struct extent_buffer* read_tree_block(struct btrfs_fs_info *fs_info, u64 bytenr, in read_tree_block() argument
448 u32 sectorsize = fs_info->sectorsize; in read_tree_block()
467 eb = btrfs_find_create_tree_block(fs_info, bytenr); in read_tree_block()
474 num_copies = btrfs_num_copies(fs_info, eb->start, eb->len); in read_tree_block()
476 ret = read_whole_eb(fs_info, eb, mirror_num); in read_tree_block()
477 if (ret == 0 && csum_tree_block(fs_info, eb, 1) == 0 && in read_tree_block()
478 check_tree_block(fs_info, eb) == 0 && in read_tree_block()
479 verify_parent_transid(&fs_info->extent_cache, eb, in read_tree_block()
489 ret = btrfs_check_node(fs_info, NULL, eb); in read_tree_block()
491 ret = btrfs_check_leaf(fs_info, NULL, eb); in read_tree_block()
504 if (check_tree_block(fs_info, eb)) in read_tree_block()
505 print_tree_block_error(fs_info, eb, in read_tree_block()
506 check_tree_block(fs_info, eb)); in read_tree_block()
538 int read_extent_data(struct btrfs_fs_info *fs_info, char *data, u64 logical, in read_extent_data() argument
547 ret = btrfs_map_block(fs_info, READ, logical, len, &multi, mirror, in read_extent_data()
574 void btrfs_setup_root(struct btrfs_root *root, struct btrfs_fs_info *fs_info, in btrfs_setup_root() argument
580 root->fs_info = fs_info; in btrfs_setup_root()
591 struct btrfs_fs_info *fs_info, in find_and_setup_root() argument
597 btrfs_setup_root(root, fs_info, objectid); in find_and_setup_root()
604 root->node = read_tree_block(fs_info, in find_and_setup_root()
630 struct btrfs_root *btrfs_read_fs_root_no_cache(struct btrfs_fs_info *fs_info, in btrfs_read_fs_root_no_cache() argument
634 struct btrfs_root *tree_root = fs_info->tree_root; in btrfs_read_fs_root_no_cache()
644 ret = find_and_setup_root(tree_root, fs_info, in btrfs_read_fs_root_no_cache()
653 btrfs_setup_root(root, fs_info, in btrfs_read_fs_root_no_cache()
687 root->node = read_tree_block(fs_info, in btrfs_read_fs_root_no_cache()
721 struct btrfs_root *btrfs_read_fs_root(struct btrfs_fs_info *fs_info, in btrfs_read_fs_root() argument
730 return fs_info->tree_root; in btrfs_read_fs_root()
732 return fs_info->chunk_root; in btrfs_read_fs_root()
734 return fs_info->csum_root; in btrfs_read_fs_root()
737 node = rb_search(&fs_info->fs_root_tree, (void *)&objectid, in btrfs_read_fs_root()
742 root = btrfs_read_fs_root_no_cache(fs_info, location); in btrfs_read_fs_root()
746 ret = rb_insert(&fs_info->fs_root_tree, &root->rb_node, in btrfs_read_fs_root()
752 void btrfs_free_fs_info(struct btrfs_fs_info *fs_info) in btrfs_free_fs_info() argument
754 free(fs_info->tree_root); in btrfs_free_fs_info()
755 free(fs_info->chunk_root); in btrfs_free_fs_info()
756 free(fs_info->csum_root); in btrfs_free_fs_info()
757 free(fs_info->super_copy); in btrfs_free_fs_info()
758 free(fs_info); in btrfs_free_fs_info()
763 struct btrfs_fs_info *fs_info; in btrfs_new_fs_info() local
765 fs_info = calloc(1, sizeof(struct btrfs_fs_info)); in btrfs_new_fs_info()
766 if (!fs_info) in btrfs_new_fs_info()
769 fs_info->tree_root = calloc(1, sizeof(struct btrfs_root)); in btrfs_new_fs_info()
770 fs_info->chunk_root = calloc(1, sizeof(struct btrfs_root)); in btrfs_new_fs_info()
771 fs_info->csum_root = calloc(1, sizeof(struct btrfs_root)); in btrfs_new_fs_info()
772 fs_info->super_copy = calloc(1, BTRFS_SUPER_INFO_SIZE); in btrfs_new_fs_info()
774 if (!fs_info->tree_root || !fs_info->chunk_root || in btrfs_new_fs_info()
775 !fs_info->csum_root || !fs_info->super_copy) in btrfs_new_fs_info()
778 extent_io_tree_init(&fs_info->extent_cache); in btrfs_new_fs_info()
780 fs_info->fs_root_tree = RB_ROOT; in btrfs_new_fs_info()
781 cache_tree_init(&fs_info->mapping_tree.cache_tree); in btrfs_new_fs_info()
783 mutex_init(&fs_info->fs_mutex); in btrfs_new_fs_info()
785 return fs_info; in btrfs_new_fs_info()
787 btrfs_free_fs_info(fs_info); in btrfs_new_fs_info()
791 static int setup_root_or_create_block(struct btrfs_fs_info *fs_info, in setup_root_or_create_block() argument
795 struct btrfs_root *root = fs_info->tree_root; in setup_root_or_create_block()
798 ret = find_and_setup_root(root, fs_info, objectid, info_root); in setup_root_or_create_block()
807 int btrfs_setup_all_roots(struct btrfs_fs_info *fs_info) in btrfs_setup_all_roots() argument
809 struct btrfs_super_block *sb = fs_info->super_copy; in btrfs_setup_all_roots()
816 root = fs_info->tree_root; in btrfs_setup_all_roots()
817 btrfs_setup_root(root, fs_info, BTRFS_ROOT_TREE_OBJECTID); in btrfs_setup_all_roots()
822 root->node = read_tree_block(fs_info, root_tree_bytenr, generation); in btrfs_setup_all_roots()
828 ret = setup_root_or_create_block(fs_info, fs_info->csum_root, in btrfs_setup_all_roots()
832 fs_info->csum_root->track_dirty = 1; in btrfs_setup_all_roots()
834 fs_info->last_trans_committed = generation; in btrfs_setup_all_roots()
839 fs_info->fs_root = btrfs_read_fs_root(fs_info, &key); in btrfs_setup_all_roots()
841 if (IS_ERR(fs_info->fs_root)) in btrfs_setup_all_roots()
846 void btrfs_release_all_roots(struct btrfs_fs_info *fs_info) in btrfs_release_all_roots() argument
848 if (fs_info->csum_root) in btrfs_release_all_roots()
849 free_extent_buffer(fs_info->csum_root->node); in btrfs_release_all_roots()
850 if (fs_info->tree_root) in btrfs_release_all_roots()
851 free_extent_buffer(fs_info->tree_root->node); in btrfs_release_all_roots()
852 if (fs_info->chunk_root) in btrfs_release_all_roots()
853 free_extent_buffer(fs_info->chunk_root->node); in btrfs_release_all_roots()
866 void btrfs_cleanup_all_caches(struct btrfs_fs_info *fs_info) in btrfs_cleanup_all_caches() argument
868 free_mapping_cache_tree(&fs_info->mapping_tree.cache_tree); in btrfs_cleanup_all_caches()
869 extent_io_tree_cleanup(&fs_info->extent_cache); in btrfs_cleanup_all_caches()
917 static int btrfs_setup_chunk_tree_and_device_map(struct btrfs_fs_info *fs_info) in btrfs_setup_chunk_tree_and_device_map() argument
919 struct btrfs_super_block *sb = fs_info->super_copy; in btrfs_setup_chunk_tree_and_device_map()
924 btrfs_setup_root(fs_info->chunk_root, fs_info, in btrfs_setup_chunk_tree_and_device_map()
927 ret = btrfs_read_sys_array(fs_info); in btrfs_setup_chunk_tree_and_device_map()
934 fs_info->chunk_root->node = read_tree_block(fs_info, in btrfs_setup_chunk_tree_and_device_map()
937 if (!extent_buffer_uptodate(fs_info->chunk_root->node)) { in btrfs_setup_chunk_tree_and_device_map()
942 ret = btrfs_read_chunk_tree(fs_info); in btrfs_setup_chunk_tree_and_device_map()
953 struct btrfs_fs_info *fs_info; in open_ctree_fs_info() local
959 fs_info = btrfs_new_fs_info(); in open_ctree_fs_info()
960 if (!fs_info) { in open_ctree_fs_info()
969 fs_info->fs_devices = fs_devices; in open_ctree_fs_info()
975 disk_super = fs_info->super_copy; in open_ctree_fs_info()
988 if (btrfs_fs_incompat(fs_info, METADATA_UUID)) in open_ctree_fs_info()
992 fs_info->sectorsize = btrfs_super_sectorsize(disk_super); in open_ctree_fs_info()
993 fs_info->nodesize = btrfs_super_nodesize(disk_super); in open_ctree_fs_info()
994 fs_info->stripesize = btrfs_super_stripesize(disk_super); in open_ctree_fs_info()
996 ret = btrfs_check_fs_compatibility(fs_info->super_copy); in open_ctree_fs_info()
1000 ret = btrfs_setup_chunk_tree_and_device_map(fs_info); in open_ctree_fs_info()
1005 if (!fs_info->chunk_root) in open_ctree_fs_info()
1006 return fs_info; in open_ctree_fs_info()
1008 eb = fs_info->chunk_root->node; in open_ctree_fs_info()
1009 read_extent_buffer(eb, fs_info->chunk_tree_uuid, in open_ctree_fs_info()
1013 ret = btrfs_setup_all_roots(fs_info); in open_ctree_fs_info()
1017 return fs_info; in open_ctree_fs_info()
1020 btrfs_release_all_roots(fs_info); in open_ctree_fs_info()
1021 btrfs_cleanup_all_caches(fs_info); in open_ctree_fs_info()
1025 btrfs_free_fs_info(fs_info); in open_ctree_fs_info()
1029 int close_ctree_fs_info(struct btrfs_fs_info *fs_info) in close_ctree_fs_info() argument
1033 free_fs_roots_tree(&fs_info->fs_root_tree); in close_ctree_fs_info()
1035 btrfs_release_all_roots(fs_info); in close_ctree_fs_info()
1036 ret = btrfs_close_devices(fs_info->fs_devices); in close_ctree_fs_info()
1037 btrfs_cleanup_all_caches(fs_info); in close_ctree_fs_info()
1038 btrfs_free_fs_info(fs_info); in close_ctree_fs_info()
1050 ret = verify_parent_transid(&buf->fs_info->extent_cache, buf, in btrfs_buffer_uptodate()