summaryrefslogtreecommitdiff
path: root/cmds-restore.c
diff options
context:
space:
mode:
authorJosef Bacik <josef@redhat.com>2013-03-12 13:38:10 -0400
committerDavid Sterba <dsterba@suse.cz>2013-03-18 18:14:18 +0100
commit23bfbf0328d6d687b122ae197858ef55b96ae44d (patch)
tree02bf784a2f00e80c967bab2bcee6d64d8039a58d /cmds-restore.c
parent9969ea479db454fac29971016219b03ec2f02b9c (diff)
Btrfs-progs: try other mirrors on read failure
If we hit a bad disk and the read doesn't work, try other mirrors in case we have other disks with good copies. Thanks, Signed-off-by: Josef Bacik <josef@redhat.com>
Diffstat (limited to 'cmds-restore.c')
-rw-r--r--cmds-restore.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/cmds-restore.c b/cmds-restore.c
index 1d246919..617f5078 100644
--- a/cmds-restore.c
+++ b/cmds-restore.c
@@ -245,9 +245,16 @@ again:
done = pread(dev_fd, inbuf+count, length, dev_bytenr);
if (done < length) {
- ret = -1;
- fprintf(stderr, "Short read %d\n", errno);
- goto out;
+ num_copies = btrfs_num_copies(&root->fs_info->mapping_tree,
+ bytenr, length);
+ mirror_num++;
+ if (mirror_num >= num_copies) {
+ ret = -1;
+ fprintf(stderr, "Exhausted mirrors trying to read\n");
+ goto out;
+ }
+ fprintf(stderr, "Trying another mirror\n");
+ goto again;
}
count += length;