[LTP] [PATCH] syscalls/io_submit: Flush IO completion queue

Martin Doucha mdoucha@suse.cz
Mon Apr 11 11:44:24 CEST 2022


Running io_submit01 or io_submit02 with high number of iterations
(e.g. io_submit01 -i 200) would result in bogus errors because the kernel
queue will get clogged with completed requests. Fix this by calling
io_getevents() to flush the completion queue.

Signed-off-by: Martin Doucha <mdoucha@suse.cz>
---
 testcases/kernel/syscalls/io_submit/io_submit01.c | 8 +++++++-
 testcases/kernel/syscalls/io_submit/io_submit02.c | 9 +++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/testcases/kernel/syscalls/io_submit/io_submit01.c b/testcases/kernel/syscalls/io_submit/io_submit01.c
index 28d93d7f1..db541fc01 100644
--- a/testcases/kernel/syscalls/io_submit/io_submit01.c
+++ b/testcases/kernel/syscalls/io_submit/io_submit01.c
@@ -114,13 +114,19 @@ static const char *errno_name(int err)
 static void verify_io_submit(unsigned int n)
 {
 	struct tcase *t = &tcases[n];
-	int ret;
+	struct io_event evbuf;
+	struct timespec timeout = { .tv_sec = 1 };
+	int i, ret;
 
 	ret = io_submit(*t->ctx, t->nr, t->iocbs);
 
 	if (ret == t->exp_errno) {
 		tst_res(TPASS, "io_submit() with %s failed with %s",
 			t->desc, errno_name(t->exp_errno));
+
+		for (i = 0; i < ret; i++)
+			io_getevents(*t->ctx, 1, 1, &evbuf, &timeout);
+
 		return;
 	}
 
diff --git a/testcases/kernel/syscalls/io_submit/io_submit02.c b/testcases/kernel/syscalls/io_submit/io_submit02.c
index acb42cb8f..38b8555d8 100644
--- a/testcases/kernel/syscalls/io_submit/io_submit02.c
+++ b/testcases/kernel/syscalls/io_submit/io_submit02.c
@@ -70,12 +70,21 @@ static void cleanup(void)
 
 static void run(unsigned int i)
 {
+	struct io_event evbuf;
+	struct timespec timeout = { .tv_sec = 1 };
+	long j;
+
 	TEST(tst_syscall(__NR_io_submit, *tc[i].ctx, tc[i].nr, tc[i].iocbs));
 
 	if (TST_RET == tc[i].nr)
 		tst_res(TPASS, "io_submit() %s", tc[i].desc);
 	else
 		tst_res(TFAIL, "io_submit() returns %ld, expected %ld", TST_RET, tc[i].nr);
+
+	for (j = 0; j < TST_RET; j++) {
+		tst_syscall(__NR_io_getevents, *tc[i].ctx, 1, 1, &evbuf,
+			&timeout);
+	}
 }
 
 static struct tst_test test = {
-- 
2.35.1



More information about the ltp mailing list