Skip to content

Commit

Permalink
tlibio: Always return total amount of read bytes
Browse files Browse the repository at this point in the history
This issue behind this patch is noticed while fixing the
lio_write_buffer().

Here in lio_read_buffer() we have similar situation: in case of a
partial read, we cycle, but lio_read_buffer() returns back the amount of
bytes read during the last read() call while it's expected to return the
whole amount of read bytes.

Reviewed-by: Petr Vorel <pvorel@suse.cz>
Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>
  • Loading branch information
finist0 authored and pevik committed Jul 17, 2023
1 parent fdba85a commit 7f08552
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/tlibio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1114,6 +1114,10 @@ int lio_read_buffer(int fd, /* open file descriptor */
long wrd) /* to allow future features, use zero for now */
{
int ret = 0; /* syscall return or used to get random method */
/* as we cycle reads in case of partial reads, we have to report up
* total bytes read
*/
int totally_read = 0;
char *io_type; /* Holds string of type of io */
int listio_cmd; /* Holds the listio/lio_listio cmd */
int omethod = method;
Expand Down Expand Up @@ -1325,13 +1329,14 @@ int lio_read_buffer(int fd, /* open file descriptor */
fd, size, ret);
size -= ret;
buffer += ret;
totally_read += ret;
} else {
if (Debug_level > 1)
printf
("DEBUG %s/%d: read completed without error (ret %d)\n",
__FILE__, __LINE__, ret);

return ret;
return totally_read + ret;
}
}
wait4sync_io(fd, 1);
Expand Down

0 comments on commit 7f08552

Please sign in to comment.