diff options
author | Eric Sandeen <sandeen@redhat.com> | 2014-08-01 19:12:45 -0400 |
---|---|---|
committer | David Sterba <dsterba@suse.cz> | 2015-02-16 12:48:46 -0500 |
commit | 4bbcaa648d23470f04285c52a27d87c8fe906203 (patch) | |
tree | 22da036ecf497db699225752c1fffc542d7c08a3 /fs | |
parent | 63443bf54a746fada8ef2829148a29f28f07f7af (diff) |
btrfs: factor btrfs_read_roots() out of open_ctree()
Also, remove the two local variables create_uuid_tree
and check_uuid_tree; we can use the existence of
the uuid root and/or the RESCAN_UUID_TREE flag to
determine what action to take.
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/btrfs/disk-io.c | 131 |
1 files changed, 66 insertions, 65 deletions
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 954f0658dd0e..c7546d6512cc 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c | |||
@@ -2354,6 +2354,65 @@ static int btrfs_replay_log(struct btrfs_fs_info *fs_info, | |||
2354 | return 0; | 2354 | return 0; |
2355 | } | 2355 | } |
2356 | 2356 | ||
2357 | static int btrfs_read_roots(struct btrfs_fs_info *fs_info, | ||
2358 | struct btrfs_root *tree_root) | ||
2359 | { | ||
2360 | struct btrfs_root *extent_root; | ||
2361 | struct btrfs_root *dev_root; | ||
2362 | struct btrfs_root *csum_root; | ||
2363 | struct btrfs_root *quota_root; | ||
2364 | struct btrfs_root *uuid_root; | ||
2365 | struct btrfs_key location; | ||
2366 | int ret; | ||
2367 | |||
2368 | location.objectid = BTRFS_EXTENT_TREE_OBJECTID; | ||
2369 | location.type = BTRFS_ROOT_ITEM_KEY; | ||
2370 | location.offset = 0; | ||
2371 | |||
2372 | extent_root = btrfs_read_tree_root(tree_root, &location); | ||
2373 | if (IS_ERR(extent_root)) | ||
2374 | return PTR_ERR(extent_root); | ||
2375 | set_bit(BTRFS_ROOT_TRACK_DIRTY, &extent_root->state); | ||
2376 | fs_info->extent_root = extent_root; | ||
2377 | |||
2378 | location.objectid = BTRFS_DEV_TREE_OBJECTID; | ||
2379 | dev_root = btrfs_read_tree_root(tree_root, &location); | ||
2380 | if (IS_ERR(dev_root)) | ||
2381 | return PTR_ERR(dev_root); | ||
2382 | set_bit(BTRFS_ROOT_TRACK_DIRTY, &dev_root->state); | ||
2383 | fs_info->dev_root = dev_root; | ||
2384 | btrfs_init_devices_late(fs_info); | ||
2385 | |||
2386 | location.objectid = BTRFS_CSUM_TREE_OBJECTID; | ||
2387 | csum_root = btrfs_read_tree_root(tree_root, &location); | ||
2388 | if (IS_ERR(csum_root)) | ||
2389 | return PTR_ERR(csum_root); | ||
2390 | set_bit(BTRFS_ROOT_TRACK_DIRTY, &csum_root->state); | ||
2391 | fs_info->csum_root = csum_root; | ||
2392 | |||
2393 | location.objectid = BTRFS_QUOTA_TREE_OBJECTID; | ||
2394 | quota_root = btrfs_read_tree_root(tree_root, &location); | ||
2395 | if (!IS_ERR(quota_root)) { | ||
2396 | set_bit(BTRFS_ROOT_TRACK_DIRTY, "a_root->state); | ||
2397 | fs_info->quota_enabled = 1; | ||
2398 | fs_info->pending_quota_state = 1; | ||
2399 | fs_info->quota_root = quota_root; | ||
2400 | } | ||
2401 | |||
2402 | location.objectid = BTRFS_UUID_TREE_OBJECTID; | ||
2403 | uuid_root = btrfs_read_tree_root(tree_root, &location); | ||
2404 | if (IS_ERR(uuid_root)) { | ||
2405 | ret = PTR_ERR(uuid_root); | ||
2406 | if (ret != -ENOENT) | ||
2407 | return ret; | ||
2408 | } else { | ||
2409 | set_bit(BTRFS_ROOT_TRACK_DIRTY, &uuid_root->state); | ||
2410 | fs_info->uuid_root = uuid_root; | ||
2411 | } | ||
2412 | |||
2413 | return 0; | ||
2414 | } | ||
2415 | |||
2357 | int open_ctree(struct super_block *sb, | 2416 | int open_ctree(struct super_block *sb, |
2358 | struct btrfs_fs_devices *fs_devices, | 2417 | struct btrfs_fs_devices *fs_devices, |
2359 | char *options) | 2418 | char *options) |
@@ -2368,19 +2427,12 @@ int open_ctree(struct super_block *sb, | |||
2368 | struct btrfs_super_block *disk_super; | 2427 | struct btrfs_super_block *disk_super; |
2369 | struct btrfs_fs_info *fs_info = btrfs_sb(sb); | 2428 | struct btrfs_fs_info *fs_info = btrfs_sb(sb); |
2370 | struct btrfs_root *tree_root; | 2429 | struct btrfs_root *tree_root; |
2371 | struct btrfs_root *extent_root; | ||
2372 | struct btrfs_root *csum_root; | ||
2373 | struct btrfs_root *chunk_root; | 2430 | struct btrfs_root *chunk_root; |
2374 | struct btrfs_root *dev_root; | ||
2375 | struct btrfs_root *quota_root; | ||
2376 | struct btrfs_root *uuid_root; | ||
2377 | int ret; | 2431 | int ret; |
2378 | int err = -EINVAL; | 2432 | int err = -EINVAL; |
2379 | int num_backups_tried = 0; | 2433 | int num_backups_tried = 0; |
2380 | int backup_index = 0; | 2434 | int backup_index = 0; |
2381 | int max_active; | 2435 | int max_active; |
2382 | bool create_uuid_tree; | ||
2383 | bool check_uuid_tree; | ||
2384 | 2436 | ||
2385 | tree_root = fs_info->tree_root = btrfs_alloc_root(fs_info); | 2437 | tree_root = fs_info->tree_root = btrfs_alloc_root(fs_info); |
2386 | chunk_root = fs_info->chunk_root = btrfs_alloc_root(fs_info); | 2438 | chunk_root = fs_info->chunk_root = btrfs_alloc_root(fs_info); |
@@ -2804,61 +2856,9 @@ retry_root_backup: | |||
2804 | tree_root->commit_root = btrfs_root_node(tree_root); | 2856 | tree_root->commit_root = btrfs_root_node(tree_root); |
2805 | btrfs_set_root_refs(&tree_root->root_item, 1); | 2857 | btrfs_set_root_refs(&tree_root->root_item, 1); |
2806 | 2858 | ||
2807 | location.objectid = BTRFS_EXTENT_TREE_OBJECTID; | 2859 | ret = btrfs_read_roots(fs_info, tree_root); |
2808 | location.type = BTRFS_ROOT_ITEM_KEY; | 2860 | if (ret) |
2809 | location.offset = 0; | ||
2810 | |||
2811 | extent_root = btrfs_read_tree_root(tree_root, &location); | ||
2812 | if (IS_ERR(extent_root)) { | ||
2813 | ret = PTR_ERR(extent_root); | ||
2814 | goto recovery_tree_root; | ||
2815 | } | ||
2816 | set_bit(BTRFS_ROOT_TRACK_DIRTY, &extent_root->state); | ||
2817 | fs_info->extent_root = extent_root; | ||
2818 | |||
2819 | location.objectid = BTRFS_DEV_TREE_OBJECTID; | ||
2820 | dev_root = btrfs_read_tree_root(tree_root, &location); | ||
2821 | if (IS_ERR(dev_root)) { | ||
2822 | ret = PTR_ERR(dev_root); | ||
2823 | goto recovery_tree_root; | ||
2824 | } | ||
2825 | set_bit(BTRFS_ROOT_TRACK_DIRTY, &dev_root->state); | ||
2826 | fs_info->dev_root = dev_root; | ||
2827 | btrfs_init_devices_late(fs_info); | ||
2828 | |||
2829 | location.objectid = BTRFS_CSUM_TREE_OBJECTID; | ||
2830 | csum_root = btrfs_read_tree_root(tree_root, &location); | ||
2831 | if (IS_ERR(csum_root)) { | ||
2832 | ret = PTR_ERR(csum_root); | ||
2833 | goto recovery_tree_root; | 2861 | goto recovery_tree_root; |
2834 | } | ||
2835 | set_bit(BTRFS_ROOT_TRACK_DIRTY, &csum_root->state); | ||
2836 | fs_info->csum_root = csum_root; | ||
2837 | |||
2838 | location.objectid = BTRFS_QUOTA_TREE_OBJECTID; | ||
2839 | quota_root = btrfs_read_tree_root(tree_root, &location); | ||
2840 | if (!IS_ERR(quota_root)) { | ||
2841 | set_bit(BTRFS_ROOT_TRACK_DIRTY, "a_root->state); | ||
2842 | fs_info->quota_enabled = 1; | ||
2843 | fs_info->pending_quota_state = 1; | ||
2844 | fs_info->quota_root = quota_root; | ||
2845 | } | ||
2846 | |||
2847 | location.objectid = BTRFS_UUID_TREE_OBJECTID; | ||
2848 | uuid_root = btrfs_read_tree_root(tree_root, &location); | ||
2849 | if (IS_ERR(uuid_root)) { | ||
2850 | ret = PTR_ERR(uuid_root); | ||
2851 | if (ret != -ENOENT) | ||
2852 | goto recovery_tree_root; | ||
2853 | create_uuid_tree = true; | ||
2854 | check_uuid_tree = false; | ||
2855 | } else { | ||
2856 | set_bit(BTRFS_ROOT_TRACK_DIRTY, &uuid_root->state); | ||
2857 | fs_info->uuid_root = uuid_root; | ||
2858 | create_uuid_tree = false; | ||
2859 | check_uuid_tree = | ||
2860 | generation != btrfs_super_uuid_tree_generation(disk_super); | ||
2861 | } | ||
2862 | 2862 | ||
2863 | fs_info->generation = generation; | 2863 | fs_info->generation = generation; |
2864 | fs_info->last_trans_committed = generation; | 2864 | fs_info->last_trans_committed = generation; |
@@ -2896,7 +2896,7 @@ retry_root_backup: | |||
2896 | goto fail_sysfs; | 2896 | goto fail_sysfs; |
2897 | } | 2897 | } |
2898 | 2898 | ||
2899 | ret = btrfs_read_block_groups(extent_root); | 2899 | ret = btrfs_read_block_groups(fs_info->extent_root); |
2900 | if (ret) { | 2900 | if (ret) { |
2901 | printk(KERN_ERR "BTRFS: Failed to read block groups: %d\n", ret); | 2901 | printk(KERN_ERR "BTRFS: Failed to read block groups: %d\n", ret); |
2902 | goto fail_sysfs; | 2902 | goto fail_sysfs; |
@@ -3019,7 +3019,7 @@ retry_root_backup: | |||
3019 | 3019 | ||
3020 | btrfs_qgroup_rescan_resume(fs_info); | 3020 | btrfs_qgroup_rescan_resume(fs_info); |
3021 | 3021 | ||
3022 | if (create_uuid_tree) { | 3022 | if (!fs_info->uuid_root) { |
3023 | pr_info("BTRFS: creating UUID tree\n"); | 3023 | pr_info("BTRFS: creating UUID tree\n"); |
3024 | ret = btrfs_create_uuid_tree(fs_info); | 3024 | ret = btrfs_create_uuid_tree(fs_info); |
3025 | if (ret) { | 3025 | if (ret) { |
@@ -3028,8 +3028,9 @@ retry_root_backup: | |||
3028 | close_ctree(tree_root); | 3028 | close_ctree(tree_root); |
3029 | return ret; | 3029 | return ret; |
3030 | } | 3030 | } |
3031 | } else if (check_uuid_tree || | 3031 | } else if (btrfs_test_opt(tree_root, RESCAN_UUID_TREE) || |
3032 | btrfs_test_opt(tree_root, RESCAN_UUID_TREE)) { | 3032 | fs_info->generation != |
3033 | btrfs_super_uuid_tree_generation(disk_super)) { | ||
3033 | pr_info("BTRFS: checking UUID tree\n"); | 3034 | pr_info("BTRFS: checking UUID tree\n"); |
3034 | ret = btrfs_check_uuid_tree(fs_info); | 3035 | ret = btrfs_check_uuid_tree(fs_info); |
3035 | if (ret) { | 3036 | if (ret) { |