[LTP] [PATCH 2/3] aiocp: Don't use O_DIRECT when writing random file

Richard Palethorpe rpalethorpe@suse.com
Mon Jan 9 13:52:33 CET 2023


The initial write doesn't need to use O_DIRECT and could fail because
the write sizes were not aligned. This drops O_DIRECT on the initial
write.

Also it switches to using the static data from tst_rand_data. This is
better for reproducibility.

Signed-off-by: Richard Palethorpe <rpalethorpe@suse.com>
---
 testcases/kernel/io/ltp-aiodio/aiocp.c | 36 ++++++--------------------
 1 file changed, 8 insertions(+), 28 deletions(-)

diff --git a/testcases/kernel/io/ltp-aiodio/aiocp.c b/testcases/kernel/io/ltp-aiodio/aiocp.c
index 275000f3e..cace924a2 100644
--- a/testcases/kernel/io/ltp-aiodio/aiocp.c
+++ b/testcases/kernel/io/ltp-aiodio/aiocp.c
@@ -27,6 +27,8 @@
 #include <sys/stat.h>
 #include "common.h"
 
+#include "tst_rand_data.h"
+
 static const char *srcname = "srcfile.bin";
 static const char *dstname = "dstfile.bin";
 
@@ -55,35 +57,13 @@ static int iocb_free_count;
 
 static void fill_with_rand_data(int fd, long long size)
 {
-	const int bufsize = 64 * 1024;
-	const int lower = 'a';
-	const int upper = 'z';
-	char buf[bufsize];
-	long long i = 0, j;
-	long long length, towrite;
-
-	srand(time(NULL));
-
-	for (j = 0; j < bufsize; j++)
-		buf[j] = (rand() % (upper - lower + 1)) + lower;
+	long long i = size;
 
-	if (size <= bufsize) {
-		SAFE_WRITE(0, fd, buf, size);
-		return;
+	while (i > 0) {
+		SAFE_WRITE(1, fd, tst_rand_data,
+			   MIN((long long)tst_rand_data_len, i));
+		i -= tst_rand_data_len;
 	}
-
-	while (i < size) {
-		if (!tst_remaining_runtime())
-			tst_brk(TCONF, "Out of runtime!");
-
-		length = rand() % (bufsize / 2) + bufsize / 2;
-		towrite = MIN(length, size - i);
-
-		i += towrite;
-
-		SAFE_WRITE(1, fd, buf, towrite);
-	}
-
 	SAFE_FSYNC(fd);
 }
 
@@ -266,7 +246,7 @@ static void setup(void)
 
 	tst_res(TINFO, "Fill %s with random data", srcname);
 
-	srcfd = SAFE_OPEN(srcname, srcflags | O_RDWR | O_CREAT, 0666);
+	srcfd = SAFE_OPEN(srcname, (srcflags & ~O_DIRECT) | O_RDWR | O_CREAT, 0666);
 	fill_with_rand_data(srcfd, filesize);
 	SAFE_CLOSE(srcfd);
 }
-- 
2.39.0



More information about the ltp mailing list