Skip to content

Commit ff0e1b1

Browse files
author
Josef Bacik
committed
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>
1 parent 9dee07a commit ff0e1b1

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

restore.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,16 @@ static int copy_one_extent(struct btrfs_root *root, int fd,
244244

245245
done = pread(dev_fd, inbuf+count, length, dev_bytenr);
246246
if (done < length) {
247-
ret = -1;
248-
fprintf(stderr, "Short read %d\n", errno);
249-
goto out;
247+
num_copies = btrfs_num_copies(&root->fs_info->mapping_tree,
248+
bytenr, length);
249+
mirror_num++;
250+
if (mirror_num >= num_copies) {
251+
ret = -1;
252+
fprintf(stderr, "Exhausted mirrors trying to read\n");
253+
goto out;
254+
}
255+
fprintf(stderr, "Trying another mirror\n");
256+
goto again;
250257
}
251258

252259
count += length;

0 commit comments

Comments
 (0)