aboutsummaryrefslogtreecommitdiffstats
path: root/disk-io.c
diff options
context:
space:
mode:
authorZach Brown <zab@zabbo.net>2014-10-15 16:14:21 -0700
committerDavid Sterba <dsterba@suse.cz>2014-11-03 18:35:30 +0100
commit34ed841dcdeaab301be89feebe2632a8f74ee2c0 (patch)
treec0b50d0bcb809a98cd587173b6f3b52bee0418d9 /disk-io.c
parent85d67ac1450ff245af79ac907092fa55eb52fb32 (diff)
downloadbtrfs-progs-34ed841dcdeaab301be89feebe2632a8f74ee2c0.tar.gz
btrfs-progs-34ed841dcdeaab301be89feebe2632a8f74ee2c0.tar.xz
btrfs-progs-34ed841dcdeaab301be89feebe2632a8f74ee2c0.zip
btrfs-progs: fix csum root copy-n-paste error
btrfs_setup_all_roots() had some copy and pasted code for trying to setup a root and then creating a blank node if that failed. The copy for the csum_root created the blank node in the extent_root. So we create a function to use a consistent root. Signed-off-by: Zach Brown <zab@zabbo.net> Signed-off-by: David Sterba <dsterba@suse.cz>
Diffstat (limited to 'disk-io.c')
-rw-r--r--disk-io.c67
1 files changed, 37 insertions, 30 deletions
diff --git a/disk-io.c b/disk-io.c
index 77fc610..d2d29e1 100644
--- a/disk-io.c
+++ b/disk-io.c
@@ -834,6 +834,35 @@ static int find_best_backup_root(struct btrfs_super_block *super)
return best_index;
}
+static int setup_root_or_create_block(struct btrfs_fs_info *fs_info,
+ enum btrfs_open_ctree_flags flags,
+ struct btrfs_root *info_root,
+ u64 objectid, char *str)
+{
+ struct btrfs_super_block *sb = fs_info->super_copy;
+ struct btrfs_root *root = fs_info->tree_root;
+ u32 leafsize = btrfs_super_leafsize(sb);
+ int ret;
+
+ ret = find_and_setup_root(root, fs_info, objectid, info_root);
+ if (ret) {
+ printk("Couldn't setup %s tree\n", str);
+ if (!(flags & OPEN_CTREE_PARTIAL))
+ return -EIO;
+ /*
+ * Need a blank node here just so we don't screw up in the
+ * million of places that assume a root has a valid ->node
+ */
+ info_root->node =
+ btrfs_find_create_tree_block(info_root, 0, leafsize);
+ if (!info_root->node)
+ return -ENOMEM;
+ clear_extent_buffer_uptodate(NULL, info_root->node);
+ }
+
+ return 0;
+}
+
int btrfs_setup_all_roots(struct btrfs_fs_info *fs_info, u64 root_tree_bytenr,
enum btrfs_open_ctree_flags flags)
{
@@ -880,22 +909,10 @@ int btrfs_setup_all_roots(struct btrfs_fs_info *fs_info, u64 root_tree_bytenr,
return -EIO;
}
- ret = find_and_setup_root(root, fs_info, BTRFS_EXTENT_TREE_OBJECTID,
- fs_info->extent_root);
- if (ret) {
- printk("Couldn't setup extent tree\n");
- if (!(flags & OPEN_CTREE_PARTIAL))
- return -EIO;
- /* Need a blank node here just so we don't screw up in the
- * million of places that assume a root has a valid ->node
- */
- fs_info->extent_root->node =
- btrfs_find_create_tree_block(fs_info->extent_root, 0,
- leafsize);
- if (!fs_info->extent_root->node)
- return -ENOMEM;
- clear_extent_buffer_uptodate(NULL, fs_info->extent_root->node);
- }
+ ret = setup_root_or_create_block(fs_info, flags, fs_info->extent_root,
+ BTRFS_EXTENT_TREE_OBJECTID, "extent");
+ if (ret)
+ return ret;
fs_info->extent_root->track_dirty = 1;
ret = find_and_setup_root(root, fs_info, BTRFS_DEV_TREE_OBJECTID,
@@ -906,20 +923,10 @@ int btrfs_setup_all_roots(struct btrfs_fs_info *fs_info, u64 root_tree_bytenr,
}
fs_info->dev_root->track_dirty = 1;
- ret = find_and_setup_root(root, fs_info, BTRFS_CSUM_TREE_OBJECTID,
- fs_info->csum_root);
- if (ret) {
- printk("Couldn't setup csum tree\n");
- if (!(flags & OPEN_CTREE_PARTIAL))
- return -EIO;
- /* do the same thing as extent tree rebuilding */
- fs_info->csum_root->node =
- btrfs_find_create_tree_block(fs_info->extent_root, 0,
- leafsize);
- if (!fs_info->csum_root->node)
- return -ENOMEM;
- clear_extent_buffer_uptodate(NULL, fs_info->csum_root->node);
- }
+ ret = setup_root_or_create_block(fs_info, flags, fs_info->csum_root,
+ BTRFS_CSUM_TREE_OBJECTID, "csum");
+ if (ret)
+ return ret;
fs_info->csum_root->track_dirty = 1;
ret = find_and_setup_root(root, fs_info, BTRFS_QUOTA_TREE_OBJECTID,