[LTP] [PATCH v2 2/2] scsi_debug/tlibio/lio_read_buffer: Always return total amount of read bytes

Konstantin Khorenko khorenko@virtuozzo.com
Thu May 18 09:59:31 CEST 2023


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.

Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>
Reviewed-by: Petr Vorel <pvorel@suse.cz>
---
 lib/tlibio.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/lib/tlibio.c b/lib/tlibio.c
index b029e5883..2ecdbb42a 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);
-- 
2.31.1



More information about the ltp mailing list