From 7f085523c6f1929566162e61bdb1eeb10a73379e Mon Sep 17 00:00:00 2001 From: Konstantin Khorenko Date: Thu, 18 May 2023 10:59:31 +0300 Subject: [PATCH] tlibio: Always return total amount of read bytes 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 Signed-off-by: Konstantin Khorenko --- lib/tlibio.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/tlibio.c b/lib/tlibio.c index b029e588363..2ecdbb42a0d 100644 --- a/lib/tlibio.c +++ b/lib/tlibio.c @@ -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; @@ -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);