From c0f32c54a3de142201847cbcbf83ae83a4b76fd2 Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Fri, 21 Aug 2015 11:21:26 +0800 Subject: 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 Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- extent_io.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'extent_io.c') diff --git a/extent_io.c b/extent_io.c index 5d49710..07695ef 100644 --- a/extent_io.c +++ b/extent_io.c @@ -714,7 +714,7 @@ int read_data_from_disk(struct btrfs_fs_info *info, void *buf, u64 offset, device = multi->stripes[0].dev; read_len = min(bytes_left, read_len); - if (device->fd == 0) { + if (device->fd <= 0) { kfree(multi); return -EIO; } @@ -790,7 +790,7 @@ int write_data_to_disk(struct btrfs_fs_info *info, void *buf, u64 offset, raid_map = NULL; } else while (dev_nr < multi->num_stripes) { device = multi->stripes[dev_nr].dev; - if (device->fd == 0) { + if (device->fd <= 0) { kfree(multi); return -EIO; } -- cgit v1.2.1