diff options
author | Josef Bacik <jbacik@fusionio.com> | 2013-04-16 13:13:38 -0400 |
---|---|---|
committer | David Sterba <dsterba@suse.cz> | 2013-04-23 18:56:27 +0200 |
commit | aa5f0626f8a7797278e55e9976c2e868962af8da (patch) | |
tree | 9c6107453dfc48f69352d39e3ff7113415454004 /disk-io.c | |
parent | 18ce0501ce8a6bc2d66b6bf11358d284919c5d3c (diff) |
Btrfs-progs: make restore deal with really broken file systems
All we need for restore to work is the chunk root, the tree root and the fs root
we want to restore from. So to do this we need to make a few adjustments
1) Make open_ctree_fs_info fail completely if it can't read the chunk tree.
There is no sense in continuing if we can't read the chunk tree since we won't
be able to translate logical to physical blocks.
2) Use open_ctree_fs_info in restore, and if we didn't load a tree root or
fs root go ahead and try to set those up manually ourselves.
This is related to work I did last year on restore, but it uses the
open_ctree_fs_info instead of my open coded open_ctree. Thanks,
Signed-off-by: Josef Bacik <jbacik@fusionio.com>
Diffstat (limited to 'disk-io.c')
-rw-r--r-- | disk-io.c | 37 |
1 files changed, 10 insertions, 27 deletions
@@ -945,8 +945,10 @@ static struct btrfs_fs_info *__open_ctree_fd(int fp, const char *path, if (!(btrfs_super_flags(disk_super) & BTRFS_SUPER_FLAG_METADUMP)) { ret = btrfs_read_chunk_tree(chunk_root); - if (ret) - goto out_failed; + if (ret) { + printk("Couldn't read chunk tree\n"); + goto out_chunk; + } } blocksize = btrfs_level_size(tree_root, @@ -1019,6 +1021,7 @@ out_failed: free_extent_buffer(fs_info->extent_root->node); if (fs_info->tree_root) free_extent_buffer(fs_info->tree_root->node); +out_chunk: if (fs_info->chunk_root) free_extent_buffer(fs_info->chunk_root->node); out_devices: @@ -1041,8 +1044,8 @@ out: } struct btrfs_fs_info *open_ctree_fs_info(const char *filename, - u64 sb_bytenr, int writes, - int partial) + u64 sb_bytenr, u64 root_tree_bytenr, + int writes, int partial) { int fp; struct btrfs_fs_info *info; @@ -1056,7 +1059,8 @@ struct btrfs_fs_info *open_ctree_fs_info(const char *filename, fprintf (stderr, "Could not open %s\n", filename); return NULL; } - info = __open_ctree_fd(fp, filename, sb_bytenr, 0, writes, partial); + info = __open_ctree_fd(fp, filename, sb_bytenr, root_tree_bytenr, + writes, partial); close(fp); return info; } @@ -1065,28 +1069,7 @@ struct btrfs_root *open_ctree(const char *filename, u64 sb_bytenr, int writes) { struct btrfs_fs_info *info; - info = open_ctree_fs_info(filename, sb_bytenr, writes, 0); - if (!info) - return NULL; - return info->fs_root; -} - -struct btrfs_root *open_ctree_recovery(const char *filename, u64 sb_bytenr, - u64 root_tree_bytenr) -{ - int fp; - struct btrfs_fs_info *info; - - - fp = open(filename, O_RDONLY); - if (fp < 0) { - fprintf (stderr, "Could not open %s\n", filename); - return NULL; - } - info = __open_ctree_fd(fp, filename, sb_bytenr, - root_tree_bytenr, 0, 0); - close(fp); - + info = open_ctree_fs_info(filename, sb_bytenr, 0, writes, 0); if (!info) return NULL; return info->fs_root; |