aboutsummaryrefslogtreecommitdiffstats
path: root/btrfs-find-root.c
diff options
context:
space:
mode:
authorQu Wenruo <quwenruo@cn.fujitsu.com>2016-02-22 14:59:56 +0800
committerDavid Sterba <dsterba@suse.com>2016-02-26 17:27:58 +0100
commitc8c3715969a1e9d3af39863583cfbe4025db11d5 (patch)
treeed610203b2668861d064b60275c57c1a039d0e9b /btrfs-find-root.c
parent9db13dca2f00b8a7cfd31fb737cfd0e73ad48abf (diff)
downloadbtrfs-progs-c8c3715969a1e9d3af39863583cfbe4025db11d5.tar.gz
btrfs-progs-c8c3715969a1e9d3af39863583cfbe4025db11d5.tar.xz
btrfs-progs-c8c3715969a1e9d3af39863583cfbe4025db11d5.zip
btrfs-progs: find-root: Allow btrfs-find-root to search chunk root even chunk root is corrupted
Since now open_ctree_fs_info() can even return a valid fs_info with only system chunk mapping from super block, use this ability to do chunk root search for heavily damanged fs. As an fast alternative for time consuming and buggy chunk-recovery. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'btrfs-find-root.c')
-rw-r--r--btrfs-find-root.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/btrfs-find-root.c b/btrfs-find-root.c
index fc3812c..2d5bbb2 100644
--- a/btrfs-find-root.c
+++ b/btrfs-find-root.c
@@ -69,7 +69,6 @@ static void get_root_gen_and_level(u64 objectid, struct btrfs_fs_info *fs_info,
case BTRFS_CHUNK_TREE_OBJECTID:
level = btrfs_super_chunk_root_level(super);
gen = btrfs_super_chunk_root_generation(super);
- printf("Search for chunk root is not supported yet\n");
break;
case BTRFS_TREE_LOG_OBJECTID:
level = btrfs_super_log_root_level(super);
@@ -145,7 +144,7 @@ static void print_find_root_result(struct cache_tree *result,
int main(int argc, char **argv)
{
- struct btrfs_root *root;
+ struct btrfs_fs_info *fs_info;
struct btrfs_find_root_filter filter = {0};
struct cache_tree result;
struct cache_extent *found;
@@ -192,16 +191,18 @@ int main(int argc, char **argv)
exit(1);
}
- root = open_ctree(argv[optind], 0, OPEN_CTREE_CHUNK_ROOT_ONLY);
- if (!root) {
- fprintf(stderr, "Open ctree failed\n");
+ fs_info = open_ctree_fs_info(argv[optind], 0, 0,
+ OPEN_CTREE_CHUNK_ROOT_ONLY |
+ OPEN_CTREE_IGNORE_CHUNK_TREE_ERROR);
+ if (!fs_info) {
+ error("open ctree failed");
exit(1);
}
cache_tree_init(&result);
- get_root_gen_and_level(filter.objectid, root->fs_info,
+ get_root_gen_and_level(filter.objectid, fs_info,
&filter.match_gen, &filter.match_level);
- ret = btrfs_find_root_search(root, &filter, &result, &found);
+ ret = btrfs_find_root_search(fs_info, &filter, &result, &found);
if (ret < 0) {
fprintf(stderr, "Fail to search the tree root: %s\n",
strerror(-ret));
@@ -215,7 +216,7 @@ int main(int argc, char **argv)
print_find_root_result(&result, &filter);
out:
btrfs_find_root_free(&result);
- close_ctree(root);
+ close_ctree_fs_info(fs_info);
btrfs_close_all_devices();
return ret;
}