From 4469ed43b26b6e7d5ad5cfea45e99708e39de4a6 Mon Sep 17 00:00:00 2001 From: David Marcin Date: Wed, 16 Nov 2011 12:18:08 -0800 Subject: [PATCH 169/170] btrfs-progs: Check metadata mirrors in find-root. Signed-off-by: David Marcin --- btrfs-find-root.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) Index: btrfs-progs-v3.14/btrfs-find-root.c =================================================================== --- btrfs-progs-v3.14.orig/btrfs-find-root.c +++ btrfs-progs-v3.14/btrfs-find-root.c @@ -230,6 +230,8 @@ static int find_root(struct btrfs_root * while (1) { u64 map_length = 4096; u64 type; + int mirror_num; + int num_copies; if (offset > btrfs_super_total_bytes(root->fs_info->super_copy)) { @@ -246,9 +248,11 @@ static int find_root(struct btrfs_root * } offset = metadata_offset; } + mirror_num = 1; + again: err = __btrfs_map_block(&root->fs_info->mapping_tree, READ, offset, &map_length, &type, - &multi, 0, NULL); + &multi, mirror_num, NULL); if (err) { offset += map_length; continue; @@ -267,9 +271,16 @@ static int find_root(struct btrfs_root * err = read_physical(root, fd, offset, bytenr, map_length); if (!err) { + /* Found the root. */ ret = 0; break; } else if (err < 0) { + num_copies = btrfs_num_copies(&root->fs_info->mapping_tree, + offset, map_length); + mirror_num++; + if (mirror_num <= num_copies) + goto again; + /* Unrecoverable error in read. */ ret = err; break; }