btrfs-progs: check read extent errors when mapping

coverity barked out a warning that btrfs-map-logical was storing but
ignoring errors from read_extent_from_disk().   So don't ignore 'em.  I
made extent reading errors fatal to match the fatal errors from mapping
mirrors above.

And while we're at it have read_extent_from_disk() return -errno pread
errors instead of -EIO or -1 (-EPERM).  The only other caller who tests
errors clobbers them with -EIO.

Signed-off-by: Zach Brown <zab@zabbo.net>
Signed-off-by: David Sterba <dsterba@suse.cz>
This commit is contained in:
Zach Brown 2014-10-15 16:14:19 -07:00 committed by David Sterba
parent 9662864435
commit 85d67ac145
2 changed files with 14 additions and 2 deletions

View File

@ -76,8 +76,18 @@ static struct extent_buffer * debug_read_block(struct btrfs_root *root,
(unsigned long long)eb->dev_bytenr, device->name); (unsigned long long)eb->dev_bytenr, device->name);
kfree(multi); kfree(multi);
if (!copy || mirror_num == copy) if (!copy || mirror_num == copy) {
ret = read_extent_from_disk(eb, 0, eb->len); ret = read_extent_from_disk(eb, 0, eb->len);
if (ret) {
fprintf(info_file,
"Error: failed to read extent: mirror %d logical %llu: %s\n",
mirror_num, (unsigned long long)eb->start,
strerror(-ret));
free_extent_buffer(eb);
eb = NULL;
break;
}
}
num_copies = btrfs_num_copies(&root->fs_info->mapping_tree, num_copies = btrfs_num_copies(&root->fs_info->mapping_tree,
eb->start, eb->len); eb->start, eb->len);

View File

@ -666,8 +666,10 @@ int read_extent_from_disk(struct extent_buffer *eb,
{ {
int ret; int ret;
ret = pread(eb->fd, eb->data + offset, len, eb->dev_bytenr); ret = pread(eb->fd, eb->data + offset, len, eb->dev_bytenr);
if (ret < 0) if (ret < 0) {
ret = -errno;
goto out; goto out;
}
if (ret != len) { if (ret != len) {
ret = -EIO; ret = -EIO;
goto out; goto out;