db07609875
segfaults from bnc#710486 due to unchecked usage of return value of open_ctree() [fixed compilation warnings] - pull upstream, replace existing patches, spec update - update 'restore' utility - lzo support - tools may now take earlies superblock when opening the fs - other fixes - pull integration-20111030 branch - mkfs: force mkfs if desired - other fixes - add btrfs-dump-super to mkinitrd - other fixes - skip non-existent devices or without media - documentation updates - scrubbing single device - graceful error handling when opening fs fails - updated mkinitrd script to scan devices before mount (bnc#727383) OBS-URL: https://build.opensuse.org/package/show/filesystems/btrfsprogs?expand=0&rev=115
55 lines
1.4 KiB
Diff
55 lines
1.4 KiB
Diff
From 16073605bb947e6acfa3b13b6280a90fed9b717a Mon Sep 17 00:00:00 2001
|
|
From: David Marcin <djmarcin@google.com>
|
|
Date: Wed, 9 Nov 2011 13:23:28 -0800
|
|
Subject: [PATCH 20/35] btrfs-progs: Fix error handling for failed reads in
|
|
restore tool when mirrors exist
|
|
|
|
---
|
|
restore.c | 11 +++++++----
|
|
1 files changed, 7 insertions(+), 4 deletions(-)
|
|
|
|
diff --git a/restore.c b/restore.c
|
|
index 4dabae2..389b107 100644
|
|
--- a/restore.c
|
|
+++ b/restore.c
|
|
@@ -197,7 +197,7 @@ static int copy_one_extent(struct btrfs_root *root, int fd,
|
|
int compress;
|
|
int ret;
|
|
int dev_fd;
|
|
- int mirror_num = 0;
|
|
+ int mirror_num = 1;
|
|
int num_copies;
|
|
|
|
compress = btrfs_file_extent_compression(leaf, fi);
|
|
@@ -240,14 +240,15 @@ again:
|
|
|
|
if (size_left < length)
|
|
length = size_left;
|
|
- size_left -= length;
|
|
|
|
done = pread(dev_fd, inbuf+count, length, dev_bytenr);
|
|
- if (done < length) {
|
|
+ /* Need both checks, or we miss negative values due to u64 conversion */
|
|
+ if (done < 0 || done < length) {
|
|
num_copies = btrfs_num_copies(&root->fs_info->mapping_tree,
|
|
bytenr, length);
|
|
mirror_num++;
|
|
- if (mirror_num >= num_copies) {
|
|
+ /* mirror_num is 1-indexed, so num_copies is a valid mirror. */
|
|
+ if (mirror_num > num_copies) {
|
|
ret = -1;
|
|
fprintf(stderr, "Exhausted mirrors trying to read\n");
|
|
goto out;
|
|
@@ -256,6 +257,8 @@ again:
|
|
goto again;
|
|
}
|
|
|
|
+ mirror_num = 1;
|
|
+ size_left -= length;
|
|
count += length;
|
|
bytenr += length;
|
|
if (size_left)
|
|
--
|
|
1.7.6.233.gd79bc
|
|
|