@@ -3683,6 +3683,56 @@ static void open_ctree_chunk_tree_exit(struct btrfs_fs_info *fs_info)
btrfs_mapping_tree_free(&fs_info->mapping_tree);
}
+static int open_ctree_tree_roots_init(struct btrfs_fs_info *fs_info)
+{
+ int ret;
+
+ ret = init_tree_roots(fs_info);
+ if (ret)
+ goto error;
+
+ /*
+ * Get zone type information of zoned block devices. This will also
+ * handle emulation of a zoned filesystem if a regular device has the
+ * zoned incompat feature flag set.
+ */
+ ret = btrfs_get_dev_zone_info_all_devices(fs_info);
+ if (ret) {
+ btrfs_err(fs_info,
+ "zoned: failed to read device zone info: %d",
+ ret);
+ goto error;
+ }
+
+ /*
+ * If we have a uuid root and we're not being told to rescan we need to
+ * check the generation here so we can set the
+ * BTRFS_FS_UPDATE_UUID_TREE_GEN bit. Otherwise we could commit the
+ * transaction during a balance or the log replay without updating the
+ * uuid generation, and then if we crash we would rescan the uuid tree,
+ * even though it was perfectly fine.
+ */
+ if (fs_info->uuid_root && !btrfs_test_opt(fs_info, RESCAN_UUID_TREE) &&
+ fs_info->generation ==
+ btrfs_super_uuid_tree_generation(fs_info->super_copy))
+ set_bit(BTRFS_FS_UPDATE_UUID_TREE_GEN, &fs_info->flags);
+
+ return 0;
+
+error:
+ if (fs_info->data_reloc_root)
+ btrfs_drop_and_free_fs_root(fs_info, fs_info->data_reloc_root);
+ free_root_pointers(fs_info, true);
+ return ret;
+}
+
+static void open_ctree_tree_roots_exit(struct btrfs_fs_info *fs_info)
+{
+ if (fs_info->data_reloc_root)
+ btrfs_drop_and_free_fs_root(fs_info, fs_info->data_reloc_root);
+ free_root_pointers(fs_info, true);
+}
+
struct init_sequence {
int (*init_func)(struct btrfs_fs_info *fs_info);
void (*exit_func)(struct btrfs_fs_info *fs_info);
@@ -3704,6 +3754,9 @@ static const struct init_sequence open_ctree_seq[] = {
}, {
.init_func = open_ctree_chunk_tree_init,
.exit_func = open_ctree_chunk_tree_exit,
+ }, {
+ .init_func = open_ctree_tree_roots_init,
+ .exit_func = open_ctree_tree_roots_exit,
}
};
@@ -3729,36 +3782,6 @@ int __cold open_ctree(struct super_block *sb, char *options)
open_ctree_res[i] = true;
}
- ret = init_tree_roots(fs_info);
- if (ret)
- goto fail_tree_roots;
-
- /*
- * Get zone type information of zoned block devices. This will also
- * handle emulation of a zoned filesystem if a regular device has the
- * zoned incompat feature flag set.
- */
- ret = btrfs_get_dev_zone_info_all_devices(fs_info);
- if (ret) {
- btrfs_err(fs_info,
- "zoned: failed to read device zone info: %d",
- ret);
- goto fail_block_groups;
- }
-
- /*
- * If we have a uuid root and we're not being told to rescan we need to
- * check the generation here so we can set the
- * BTRFS_FS_UPDATE_UUID_TREE_GEN bit. Otherwise we could commit the
- * transaction during a balance or the log replay without updating the
- * uuid generation, and then if we crash we would rescan the uuid tree,
- * even though it was perfectly fine.
- */
- if (fs_info->uuid_root && !btrfs_test_opt(fs_info, RESCAN_UUID_TREE) &&
- fs_info->generation ==
- btrfs_super_uuid_tree_generation(fs_info->super_copy))
- set_bit(BTRFS_FS_UPDATE_UUID_TREE_GEN, &fs_info->flags);
-
ret = btrfs_verify_dev_extents(fs_info);
if (ret) {
btrfs_err(fs_info,
@@ -3918,11 +3941,6 @@ int __cold open_ctree(struct super_block *sb, char *options)
fail_block_groups:
btrfs_put_block_group_cache(fs_info);
-
-fail_tree_roots:
- if (fs_info->data_reloc_root)
- btrfs_drop_and_free_fs_root(fs_info, fs_info->data_reloc_root);
- free_root_pointers(fs_info, true);
btrfs_free_block_groups(fs_info);
fail:
for (i = ARRAY_SIZE(open_ctree_seq) - 1; i >= 0; i--) {
No functional change, but one special thing to notice: - No need to cleanup zone info As we call btrfs_close_devices() at error path to cleanup all zone device info, thus we don't need to handle it at open_ctree_tree_roots_init(). This is a break of the init/exit layer, but since devices info is not per-device, but shared for the whole btrfs module, such break should still be acceptable. Signed-off-by: Qu Wenruo <wqu@suse.com> --- fs/btrfs/disk-io.c | 88 ++++++++++++++++++++++++++++------------------ 1 file changed, 53 insertions(+), 35 deletions(-)