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>
device = multi->stripes[0].dev;
- if (device->fd == 0) {
+ if (device->fd <= 0) {
fprintf(stderr,
"Device we need to read from is not open\n");
free(multi);
}
device = multi->stripes[0].dev;
- if (device->fd == 0) {
+ if (device->fd <= 0) {
kfree(multi);
return -EIO;
}
}
device = multi->stripes[0].dev;
- if (device->fd == 0)
+ if (device->fd <= 0)
goto err;
if (*len > max_len)
*len = max_len;
device = multi->stripes[0].dev;
read_len = min(bytes_left, read_len);
- if (device->fd == 0) {
+ if (device->fd <= 0) {
kfree(multi);
return -EIO;
}
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;
}