2013-11-25 23:58:13 +01:00
|
|
|
From 4469ed43b26b6e7d5ad5cfea45e99708e39de4a6 Mon Sep 17 00:00:00 2001
|
|
|
|
From: David Marcin <djmarcin@google.com>
|
|
|
|
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 <djmarcin@google.com>
|
|
|
|
---
|
|
|
|
btrfs-find-root.c | 13 ++++++++++++-
|
|
|
|
1 file changed, 12 insertions(+), 1 deletion(-)
|
|
|
|
|
2014-04-08 13:58:43 +02:00
|
|
|
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 *
|
2013-11-25 23:58:13 +01:00
|
|
|
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)) {
|
2014-04-08 13:58:43 +02:00
|
|
|
@@ -246,9 +248,11 @@ static int find_root(struct btrfs_root *
|
|
|
|
}
|
|
|
|
offset = metadata_offset;
|
2013-11-25 23:58:13 +01:00
|
|
|
}
|
|
|
|
+ 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;
|
2014-04-08 13:58:43 +02:00
|
|
|
@@ -267,9 +271,16 @@ static int find_root(struct btrfs_root *
|
2013-11-25 23:58:13 +01:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|