Skip to contentSkip to conversation

scsi_debug/tlibio: lio_[read, write]_buffer() is to return total amount of read/written bytes

PATCH In review Konstantin Khorenko via ltp 2 participants 4 messages May 18, 2023 – Jul 17, 2023 Library code

lore
Share & tools
lore
#0 lore raw

v2 cover scsi_debug/tlibio: lio_[read, write]_buffer() is to return total amount of read/written bytes

v2 changes:
- code comments were switched to multiline ones

Konstantin Khorenko (2):
scsi_debug/tlibio/lio_write_buffer: Always return total amount of
written bytes
scsi_debug/tlibio/lio_read_buffer: Always return total amount of read
bytes

 lib/tlibio.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
Signature · 5 lines
2.31.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

PATCH v2 1/2 scsi_debug/tlibio/lio_write_buffer: Always return total amount of written bytes

Sometimes we got failures like:
growfiles(gf217): 65884 growfiles.c/2262: 104203 tlibio.c/744 write(3, buf, 5000) returned=2288 growfiles(gf217): 65884 growfiles.c/1765: 104203 Hit max errors value of 1
gf217 1 TFAIL : growfiles.c:134: Test failed

Which looked strange as partial write is something usual and valid. It turned out that lio_write_buffer() has the code cycle writes in case of a partial write happens, but it anyway returns the amount of bytes written by the LAST write.

And upper growfile() consider the returned amount from lio_write_buffer() to be less than it tried to write and fails the testcase.

Fix lio_write_buffer() to always return total bytes written, even in case partial writes.

---
 lib/tlibio.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
lib/tlibio.c +6 -1
index 79883913a..b029e5883 100644
@@ -539,6 +539,10 @@ int lio_write_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 writes in case of partial writes, we have to report up
+	 * total bytes written
+	 */
+	int totally_written = 0;
 	char *io_type;		/* Holds string of type of io */
 	int omethod = method;
 	int listio_cmd;		/* Holds the listio/lio_listio cmd */
@@ -745,13 +749,14 @@ int lio_write_buffer(int fd,		/* open file descriptor */
 						fd, size, ret);
 					size -= ret;
 					buffer += ret;
+					totally_written += ret;
 				} else {
 					if (Debug_level > 1)
 						printf
 						    ("DEBUG %s/%d: write completed without error (ret %d)\n",
 						     __FILE__, __LINE__, ret);
 
-					return ret;
+					return totally_written + ret;
 				}
 			}
 			wait4sync_io(fd, 0);
Signature · 5 lines
2.31.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw

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

In reply to Konstantin Khorenko via ltp

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.

---
 lib/tlibio.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
lib/tlibio.c +6 -1
index b029e5883..2ecdbb42a 100644
@@ -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);
Signature · 5 lines
2.31.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw

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

Hi Konstantin,

patchset merged, thank you!

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp