summaryrefslogtreecommitdiff
path: root/disk-io.c
diff options
context:
space:
mode:
authorQu Wenruo <quwenruo@cn.fujitsu.com>2015-08-21 11:21:26 +0800
committerDavid Sterba <dsterba@suse.com>2015-08-31 19:25:12 +0200
commitc0f32c54a3de142201847cbcbf83ae83a4b76fd2 (patch)
treea5b957f2a214d8504c94cc69bfb171ec4fe8bf17 /disk-io.c
parent919d2becc8a5a894d8d95e8e1b3ac8d7fb54035f (diff)
btrfs-progs: Avoid reading bad fd in case of missing device.
Offline btrfs tools, like btrfs-image, will infinitely loop when there is missing device. The reason is, for missing device, it's fd will be set to -1, but before we reading, we only check the fd validation by checking if it's 0. So in that case, -1 will pass the validation check, and cause pread to return 0, and loop to read. Just change the validation check from "== 0" to "<= 0" to avoid such problem. Reported-by: Timothy Normand Miller <theosib@gmail.com> Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'disk-io.c')
-rw-r--r--disk-io.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/disk-io.c b/disk-io.c
index 46a5a46d..1d488932 100644
--- a/disk-io.c
+++ b/disk-io.c
@@ -266,7 +266,7 @@ int read_whole_eb(struct btrfs_fs_info *info, struct extent_buffer *eb, int mirr
}
device = multi->stripes[0].dev;
- if (device->fd == 0) {
+ if (device->fd <= 0) {
kfree(multi);
return -EIO;
}
@@ -385,7 +385,7 @@ int read_extent_data(struct btrfs_root *root, char *data,
}
device = multi->stripes[0].dev;
- if (device->fd == 0)
+ if (device->fd <= 0)
goto err;
if (*len > max_len)
*len = max_len;