Skip to contentSkip to conversation

io_submit04: Add test case for RWF_NOWAIT flag

PATCH In review Wei Gao via ltp 5 participants 33 messages Oct 29, 2023 – May 13

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 io_submit04: Add test case for RWF_NOWAIT flag

Fixs: #467

---
 runtest/syscalls                              |   1 +
 .../kernel/syscalls/io_submit/.gitignore      |   1 +
 testcases/kernel/syscalls/io_submit/Makefile  |   1 +
 .../kernel/syscalls/io_submit/io_submit04.c   | 178 ++++++++++++++++++
 4 files changed, 181 insertions(+)
 create mode 100644 testcases/kernel/syscalls/io_submit/io_submit04.c
runtest/syscalls +1 -0
index c7a0b2301..5e7fa0403 100644
@@ -656,6 +656,7 @@ io_setup02 io_setup02
 io_submit01 io_submit01
 io_submit02 io_submit02
 io_submit03 io_submit03
+io_submit04 io_submit04
 
 keyctl01 keyctl01
 keyctl02 keyctl02
testcases/kernel/syscalls/io_submit/.gitignore +1 -0
index 60b07970a..abe962e1c 100644
@@ -1,3 +1,4 @@
 /io_submit01
 /io_submit02
 /io_submit03
+/io_submit04
testcases/kernel/syscalls/io_submit/Makefile +1 -0
index ce4f13b72..c29d2060c 100644
@@ -6,5 +6,6 @@ top_srcdir		?= ../../../..
 include $(top_srcdir)/include/mk/testcases.mk
 
 LDLIBS			+= $(AIO_LIBS)
+LDFLAGS			+= -pthread
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/io_submit/io_submit04.c new file +178 -0

178 lines not on this page · raw message

Signature · 5 lines
2.35.3


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

Hi Wei,

Quoted 1 line

Fixs: #467

Fixes #467

+++ b/testcases/kernel/syscalls/io_submit/Makefile
@@ -6,5 +6,6 @@ top_srcdir ?= ../../../..
include $(top_srcdir)/include/mk/testcases.mk

LDLIBS += $(AIO_LIBS)

BTW Only io_submit01.c uses libaio, but all files are linked against -laio because Makefile does not prefix that setup with io_submit01.

+LDFLAGS += -pthread

So for the same reason I would prefix this for this test only:
io_submit04: LDFLAGS += -pthread
...

testcases/kernel/syscalls/io_submit/io_submit04.c line 9

Quoted 11 lines

+++ b/testcases/kernel/syscalls/io_submit/io_submit04.c

testcases/kernel/syscalls/io_submit/io_submit04.c new file +9 -0
@@ -0,0 +1,178 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2023 Wei Gao <[email protected]>
+ */
+
+/*\
+ * [Description]
+ *
+ * Similarily to the preadv2, this is a basic test for io_submit

s/Similarily/Similarly/

But I would remove "Similarily to the preadv2"

testcases/kernel/syscalls/io_submit/io_submit04.c line 12

Quoted 3 lines
testcases/kernel/syscalls/io_submit/io_submit04.c new file +3 -0
+ * RWF_NOWAIT flag, we are attempting to force io_submit return
+ * EAGAIN with thread concurently running threads.
+ *

nit: empty blank line.

Quoted 1 line
(quoted diff) +1 -0
+ */

...

Quoted 24 lines
testcases/kernel/syscalls/io_submit/io_submit04.c new file +24 -0
+static void *writer_thread(void *unused)
+{
+	while (!stop)
+		write_test();
+
+	return unused;
+}
+
+static void drop_caches(void)
+{
+	SAFE_FILE_PRINTF("/proc/sys/vm/drop_caches", "3");
+}
+
+static void *cache_dropper(void *unused)
+{
+	unsigned int drop_cnt = 0;
+
+	while (!stop) {
+		drop_caches();
+		drop_cnt++;
+	}
+
+	tst_res(TINFO, "Cache dropped %u times", drop_cnt);
+

testcases/kernel/syscalls/io_submit/io_submit04.c line 85

Quoted 10 lines
testcases/kernel/syscalls/io_submit/io_submit04.c new file +9 -0
+	return unused;
+}
+
+static unsigned int io_submit(void)
+{
+	struct io_event evbuf;
+	struct timespec timeout = { .tv_sec = 1 };
 
+
+	TST_EXP_VAL_SILENT(tst_syscall(__NR_io_submit, ctx, 1, iocbs), 1);

It fails with EOPNOTSUPP on TMPDIR on tmpfs (e.g. on Tumbleweed).

# ./io_submit04
...
tst_supported_fs_types.c:49: TINFO: mkfs is not needed for tmpfs
tst_test.c:1701: TINFO: === Testing on ext2 ===
tst_test.c:1117: TINFO: Formatting /dev/loop0 with ext2 opts='' extra opts=''
mke2fs 1.47.0 (5-Feb-2023)
tst_test.c:1131: TINFO: Mounting /dev/loop0 to /tmp/LTP_io_bhotMR/mntpoint fstyp=ext2 flags=0
io_submit04.c:85: TFAIL: tst_syscall(__NR_io_submit, ctx, 1, iocbs) retval -1 != 1: EOPNOTSUPP (95)

io_submit04.c:87: TFAIL: tst_syscall(__NR_io_getevents, ctx, 1, 1, &evbuf, &timeout) retval 0 != 1: SUCCESS (0) io_submit04.c:85: TFAIL: tst_syscall(__NR_io_submit, ctx, 1, iocbs) retval -1 != 1: EOPNOTSUPP (95) io_submit04.c:87: TFAIL: tst_syscall(__NR_io_getevents, ctx, 1, 1, &evbuf, &timeout) retval 0 != 1: SUCCESS (0) io_submit04.c:85: TFAIL: tst_syscall(__NR_io_submit, ctx, 1, iocbs) retval -1 != 1: EOPNOTSUPP (95) io_submit04.c:87: TFAIL: tst_syscall(__NR_io_getevents, ctx, 1, 1, &evbuf, &timeout) retval 0 != 1: SUCCESS (0)

First, it would make sense to quit this filesystem test on first error, because it does not make sense to run test 100x when it fails. But that will need to redesign way how you test it, otherwise cleanup breaks.

Why? Because .mntpoint = MNTPOINT does not mean it will cd into the directory.

You need to add:

	SAFE_CHDIR(MNTPOINT);

(This need is a bit confusing, I don't remember the reason why test does not do it.)

And if you add it, you finds that it fails on various filesystems, you need to add:

	.skip_filesystems = (const char *const[]) {
		"vfat",
		"exfat",
		"ntfs",
		"tmpfs",
		NULL
	},

Maybe even fuse would be problematic, but not sure (on my system ntfs was actually tested via fuse).

And make check warning:

$ make check-io_submit04
CHECK testcases/kernel/syscalls/io_submit/io_submit04.c
io_submit04.c:63: WARNING: Prefer using '"%s...", __func__' to using 'drop_caches', this function's name, in a string
make: [../../../../include/mk/rules.mk:56: check-io_submit04] Error 1 (ignored)

testcases/kernel/syscalls/io_submit/io_submit04.c line 93

Quoted 8 lines
testcases/kernel/syscalls/io_submit/io_submit04.c new file +8 -0
+
+	TST_EXP_VAL_SILENT(tst_syscall(__NR_io_getevents, ctx, 1, 1, &evbuf,
+			&timeout), 1);
+
+	if (evbuf.res == -EAGAIN)
+		return 1;
+	else
+		return 0;

nit: return evbuf.res == -EAGAIN

Quoted 1 line

+}

...

testcases/kernel/syscalls/io_submit/io_submit04.c line 41

Quoted 7 lines
testcases/kernel/syscalls/io_submit/io_submit04.c new file +7 -0
+static inline void io_prep_option(struct iocb *cb, int fd, void *buf,
+			size_t count, long long offset, unsigned int opcode)
+{
+	memset(cb, 0, sizeof(*cb));
+	cb->aio_fildes = fd;
+	cb->aio_lio_opcode = opcode;
+	cb->aio_buf = (uint64_t)r_buf;

Compile warning (I guess it's not a first time I ask to pay attention to the compile warnings):

io_submit04.c: In function ‘io_prep_option’:
io_submit04.c:35:66: warning: unused parameter ‘buf’ [-Wunused-parameter]
35 | static inline void io_prep_option(struct iocb *cb, int fd, void *buf,

=> maybe use actually the parameter buf, instead of using the static r_buf?

	cb->aio_buf = (uint64_t)buf;

Or, you may just remove void *buf, as r_buf is static anyway and used in the setup.

Quoted 5 lines
testcases/kernel/syscalls/io_submit/io_submit04.c new file +5 -0
+	cb->aio_offset = offset;
+	cb->aio_nbytes = count;
+	cb->aio_rw_flags = RWF_NOWAIT;
+}
+

...

testcases/kernel/syscalls/io_submit/io_submit04.c line 111

Quoted 3 lines
testcases/kernel/syscalls/io_submit/io_submit04.c new file +3 -0
+static void setup(void)
+{
+

nit: empty line ^

testcases/kernel/syscalls/io_submit/io_submit04.c line 112

Quoted 1 line
testcases/kernel/syscalls/io_submit/io_submit04.c new file +1 -0
+	TST_EXP_PASS_SILENT(tst_syscall(__NR_io_setup, 1, &ctx));

I guess this should tst_brk() if failed, right?

Therefore just:
if (!tst_syscall(__NR_io_setup, 1, &ctx))

	tst_brk(TBROK, ...);

testcases/kernel/syscalls/io_submit/io_submit04.c line 119

Quoted 7 lines
testcases/kernel/syscalls/io_submit/io_submit04.c new file +7 -0
+
+	fd = SAFE_OPEN(TEST_FILE, O_RDWR | O_CREAT, MODE);
+
+	memset(w_buf, 'a', BUF_LEN);
+	memset(r_buf, 'b', BUF_LEN);
+
+	io_prep_option(&iocb, fd, r_buf, BUF_LEN, 0, IOCB_CMD_PREAD);

NOTE: Here you pass r_buf

testcases/kernel/syscalls/io_submit/io_submit04.c line 128

Quoted 9 lines
testcases/kernel/syscalls/io_submit/io_submit04.c new file +9 -0
+}
+
+static void cleanup(void)
+{
+	if (fd > 0)
+		SAFE_CLOSE(fd);
+
+	if (tst_syscall(__NR_io_destroy, ctx))
+		tst_brk(TBROK | TERRNO, "io_destroy() failed");

Maybe just tst_res(TWARN | TERRNO, ...) because it's in a cleanup function?

Quoted 9 lines
testcases/kernel/syscalls/io_submit/io_submit04.c new file +9 -0
+}
+
+
+static void run(void)
+{
+
+	pthread_t reader, dropper, writer;
+	void *eagains;
+

testcases/kernel/syscalls/io_submit/io_submit04.c line 147

Quoted 10 lines
testcases/kernel/syscalls/io_submit/io_submit04.c new file +10 -0
+	stop = 0;
+
+	SAFE_PTHREAD_CREATE(&dropper, NULL, cache_dropper, NULL);
+	SAFE_PTHREAD_CREATE(&reader, NULL, nowait_reader, NULL);
+	SAFE_PTHREAD_CREATE(&writer, NULL, writer_thread, NULL);
+
+	while (!stop && tst_remaining_runtime())
+		usleep(100000);
+
+	stop = 1;

I'm not really sure about this stop = 1 setup, which is done also on nowait_reader(). This is probably obvious to the other reviewers.

Quoted 11 lines
testcases/kernel/syscalls/io_submit/io_submit04.c new file +11 -0
+
+	SAFE_PTHREAD_JOIN(reader, &eagains);
+	SAFE_PTHREAD_JOIN(dropper, NULL);
+	SAFE_PTHREAD_JOIN(writer, NULL);
+
+	if (eagains)
+		tst_res(TPASS, "Got some EAGAIN");
+	else
+		tst_res(TFAIL, "Haven't got EAGAIN");
+
+}
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw

PATCH v2 1/1 io_submit04: Add test case for RWF_NOWAIT flag

In reply to Wei Gao via ltp
Fixes #467
---
 runtest/syscalls                              |  1 +
 .../kernel/syscalls/io_submit/.gitignore      |  1 +
 .../kernel/syscalls/io_submit/io_submit04.c   | 87 +++++++++++++++++++
 3 files changed, 89 insertions(+)
 create mode 100644 testcases/kernel/syscalls/io_submit/io_submit04.c
runtest/syscalls +1 -0
index 4b284f279..655a46e91 100644
@@ -693,6 +693,7 @@ io_setup02 io_setup02
 io_submit01 io_submit01
 io_submit02 io_submit02
 io_submit03 io_submit03
+io_submit04 io_submit04
 
 keyctl01 keyctl01
 keyctl02 keyctl02
testcases/kernel/syscalls/io_submit/.gitignore +1 -0
index 60b07970a..abe962e1c 100644
@@ -1,3 +1,4 @@
 /io_submit01
 /io_submit02
 /io_submit03
+/io_submit04
testcases/kernel/syscalls/io_submit/io_submit04.c new file +87 -0

87 lines not on this page · raw message

Signature · 5 lines
2.51.0


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

PATCH v3 1/1 io_submit04: Add test case for RWF_NOWAIT flag

In reply to Wei Gao via ltp
Fixes #467
---
 configure.ac                                  |  1 +
 include/lapi/aio_abi.h                        | 44 ++++++++++
 runtest/syscalls                              |  1 +
 .../kernel/syscalls/io_submit/.gitignore      |  1 +
 .../kernel/syscalls/io_submit/io_submit04.c   | 86 +++++++++++++++++++
 5 files changed, 133 insertions(+)
 create mode 100644 include/lapi/aio_abi.h
 create mode 100644 testcases/kernel/syscalls/io_submit/io_submit04.c
configure.ac +1 -0
index a0ebbb34d..ee46e3f24 100644
@@ -172,6 +172,7 @@ AC_CHECK_FUNCS_ONCE([ \
 ])
 AC_CHECK_FUNCS(mkdtemp,[],AC_MSG_ERROR(mkdtemp() not found!))
 
+AC_CHECK_MEMBERS([struct iocb.aio_rw_flags],,,[#include <linux/aio_abi.h>])
 AC_CHECK_MEMBERS([struct fanotify_event_info_fid.fsid.__val],,,[#include <sys/fanotify.h>])
 AC_CHECK_MEMBERS([struct perf_event_mmap_page.aux_head],,,[#include <linux/perf_event.h>])
 AC_CHECK_MEMBERS([struct sigaction.sa_sigaction],[],[],[#include <signal.h>])
include/lapi/aio_abi.h new file +44 -0

44 lines not on this page · raw message

runtest/syscalls +1 -0
index a1ef7548b..18182a2d6 100644
@@ -696,6 +696,7 @@ io_setup02 io_setup02
 io_submit01 io_submit01
 io_submit02 io_submit02
 io_submit03 io_submit03
+io_submit04 io_submit04
 
 keyctl01 keyctl01
 keyctl02 keyctl02
testcases/kernel/syscalls/io_submit/.gitignore +1 -0
index 60b07970a..abe962e1c 100644
@@ -1,3 +1,4 @@
 /io_submit01
 /io_submit02
 /io_submit03
+/io_submit04
testcases/kernel/syscalls/io_submit/io_submit04.c new file +86 -0

86 lines not on this page · raw message

Signature · 5 lines
2.52.0


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

Hi!

Quoted 101 lines · Wei Gao
Fixes #467
---
 configure.ac                                  |  1 +
 include/lapi/aio_abi.h                        | 44 ++++++++++
 runtest/syscalls                              |  1 +
 .../kernel/syscalls/io_submit/.gitignore      |  1 +
 .../kernel/syscalls/io_submit/io_submit04.c   | 86 +++++++++++++++++++
 5 files changed, 133 insertions(+)
 create mode 100644 include/lapi/aio_abi.h
 create mode 100644 testcases/kernel/syscalls/io_submit/io_submit04.c
configure.ac +1 -0
index a0ebbb34d..ee46e3f24 100644
@@ -172,6 +172,7 @@ AC_CHECK_FUNCS_ONCE([ \
 ])
 AC_CHECK_FUNCS(mkdtemp,[],AC_MSG_ERROR(mkdtemp() not found!))
 
+AC_CHECK_MEMBERS([struct iocb.aio_rw_flags],,,[#include <linux/aio_abi.h>])
 AC_CHECK_MEMBERS([struct fanotify_event_info_fid.fsid.__val],,,[#include <sys/fanotify.h>])
 AC_CHECK_MEMBERS([struct perf_event_mmap_page.aux_head],,,[#include <linux/perf_event.h>])
 AC_CHECK_MEMBERS([struct sigaction.sa_sigaction],[],[],[#include <signal.h>])
include/lapi/aio_abi.h new file +44 -0
new file mode 100644
index 000000000..bd8c2965b
@@ -0,0 +1,44 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2025 Wei Gao <[email protected]>
+ */
+
+#ifndef LAPI_AIO_ABI_H__
+#define LAPI_AIO_ABI_H__
+
+#include <endian.h>
+#include <linux/aio_abi.h>
+
+#ifndef RWF_NOWAIT
+# define RWF_NOWAIT 0x00000008
+#endif
+
+struct iocb_fallback {
+        uint64_t aio_data;
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+        uint32_t   aio_key;
+        uint32_t aio_rw_flags;
+#elif __BYTE_ORDER == __BIG_ENDIAN
+        uint32_t aio_rw_flags;
+        uint32_t   aio_key;
+#else
+#error edit for your odd byteorder.
+#endif
+        uint16_t   aio_lio_opcode;
+        int16_t   aio_reqprio;
+        uint32_t   aio_fildes;
+        uint64_t   aio_buf;
+        uint64_t   aio_nbytes;
+        int64_t   aio_offset;
+        uint64_t   aio_reserved2;
+        uint32_t   aio_flags;
+        uint32_t   aio_resfd;
+};
+
+#ifndef HAVE_STRUCT_IOCB_AIO_RW_FLAGS
+typedef struct iocb_fallback iocb;
+#else
+typedef struct iocb iocb;
+#endif
+
+#endif /* LAPI_AIO_ABI_H__ */
runtest/syscalls +1 -0
index a1ef7548b..18182a2d6 100644
@@ -696,6 +696,7 @@ io_setup02 io_setup02
 io_submit01 io_submit01
 io_submit02 io_submit02
 io_submit03 io_submit03
+io_submit04 io_submit04
 
 keyctl01 keyctl01
 keyctl02 keyctl02
testcases/kernel/syscalls/io_submit/.gitignore +1 -0
index 60b07970a..abe962e1c 100644
@@ -1,3 +1,4 @@
 /io_submit01
 /io_submit02
 /io_submit03
+/io_submit04
testcases/kernel/syscalls/io_submit/io_submit04.c new file +0 -0
new file mode 100644
index 000000000..bae89828a

testcases/kernel/syscalls/io_submit/io_submit04.c line 10

Quoted 10 lines
testcases/kernel/syscalls/io_submit/io_submit04.c new file +10 -0
@@ -0,0 +1,86 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2025 Wei Gao <[email protected]>
+ */
+
+/*\
+ * Test iocb RWF_* flags support: RWF_NOWAIT
+ *
+ * Checks if an asynchronous read operation with RWF_NOWAIT on a blocking
+ * resource (empty pipe) fails immediately with -EAGAIN.

We can write it better:

/*\
* Test RWF_NOWAIT support in io_submit(), verifying that an
* asynchronous read operation on a blocking resource (empty pipe)
* will cause -EAGAIN. This is done by checking that io_getevents()
* syscall returns immediately and io_event.res is equal to -EAGAIN. */

testcases/kernel/syscalls/io_submit/io_submit04.c line 23

Quoted 13 lines
testcases/kernel/syscalls/io_submit/io_submit04.c new file +13 -0
+ */
+
+#include "config.h"
+#include "tst_test.h"
+#include "lapi/syscalls.h"
+#include "lapi/aio_abi.h"
+
+static int fd[2];
+static char buf[100];
+
+static aio_context_t ctx;
+static iocb cb;
+static iocb *iocbs[] = {&cb};

Data that is passed to syscalls should be initialized via tst_test.bufs

Quoted 34 lines
testcases/kernel/syscalls/io_submit/io_submit04.c new file +34 -0
+
+static inline void io_prep_option(iocb *cb, int fd, void *buf,
+			size_t count, long long offset, unsigned int opcode)
+{
+	memset(cb, 0, sizeof(*cb));
+	cb->aio_fildes = fd;
+	cb->aio_lio_opcode = opcode;
+	cb->aio_buf = (uint64_t)buf;
+	cb->aio_offset = offset;
+	cb->aio_nbytes = count;
+	cb->aio_rw_flags = RWF_NOWAIT;
+}
+
+static void setup(void)
+{
+	TST_EXP_PASS_SILENT(tst_syscall(__NR_io_setup, 1, &ctx));
+	SAFE_PIPE(fd);
+	io_prep_option(&cb, fd[0], buf, sizeof(buf), 0, IOCB_CMD_PREAD);
+}
+
+static void cleanup(void)
+{
+	if (fd[0])
+		SAFE_CLOSE(fd[0]);
+
+	if (fd[1])
+		SAFE_CLOSE(fd[1]);
+
+	if (tst_syscall(__NR_io_destroy, ctx))
+		tst_brk(TBROK | TERRNO, "io_destroy() failed");
+}
+
+static void run(void)
+{

testcases/kernel/syscalls/io_submit/io_submit04.c line 67

Quoted 10 lines
testcases/kernel/syscalls/io_submit/io_submit04.c new file +10 -0
+	struct io_event evbuf;
+	struct timespec timeout = { .tv_sec = 1 };
+	long nr = 1;
+
+	TEST(tst_syscall(__NR_io_submit, ctx, nr, iocbs));
+
+	if (TST_RET == nr)
+		tst_res(TPASS, "io_submit() pass");
+	else
+		tst_res(TFAIL | TTERRNO, "io_submit() returns %ld, expected %ld", TST_RET, nr);

Our goal is to verify that io_getevents() returns EAGAIN, so we can just:

if (TST_RET != nr) {
	tst_res(TBROK | TTERRNO, "io_submit() returns %ld, expected %ld", TST_RET, nr);
	return;
}

We return because if io_submit() fails there's nothing to do more.

testcases/kernel/syscalls/io_submit/io_submit04.c line 72

Quoted 5 lines
testcases/kernel/syscalls/io_submit/io_submit04.c new file +5 -0
+
+	tst_syscall(__NR_io_getevents, ctx, 1, 1, &evbuf, &timeout);
+
+	if (evbuf.res == -EAGAIN)
+		tst_res(TINFO, "io_submit RWF_NOWAIT flag check pass");

Why TINFO if we are testing this feature? Also the message is not giving any information of io_getevents(). We can just (look below)...

testcases/kernel/syscalls/io_submit/io_submit04.c line 76

Quoted 4 lines
testcases/kernel/syscalls/io_submit/io_submit04.c new file +4 -0
+	else
+		tst_res(TFAIL | TTERRNO, "io_submit expect EAGAIN, but get %s", strerror(-evbuf.res));
+
+}

if (evbuf.res == -EAGAIN)

	tst_res(TPASS, "io_getevents() returned EAGAIN on read event");
else
	tst_res(TFAIL | TTERRNO, "io_getevents() returned with %s instead of EAGAIN", strerror(-evbuf.res));
Quoted 10 lines
testcases/kernel/syscalls/io_submit/io_submit04.c new file +10 -0
+
+static struct tst_test test = {
+	.test_all = run,
+	.needs_kconfigs = (const char *[]) {
+		"CONFIG_AIO=y",
+		NULL
+	},
+	.setup = setup,
+	.cleanup = cleanup,
+};
Signature · 7 lines
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#6 lore raw
Quoted 187 lines · Andrea Cervesato

Hi!

Quoted 101 lines · Wei Gao
Fixes #467
---
 configure.ac                                  |  1 +
 include/lapi/aio_abi.h                        | 44 ++++++++++
 runtest/syscalls                              |  1 +
 .../kernel/syscalls/io_submit/.gitignore      |  1 +
 .../kernel/syscalls/io_submit/io_submit04.c   | 86 +++++++++++++++++++
 5 files changed, 133 insertions(+)
 create mode 100644 include/lapi/aio_abi.h
 create mode 100644 testcases/kernel/syscalls/io_submit/io_submit04.c
configure.ac +1 -0
index a0ebbb34d..ee46e3f24 100644
@@ -172,6 +172,7 @@ AC_CHECK_FUNCS_ONCE([ \
 ])
 AC_CHECK_FUNCS(mkdtemp,[],AC_MSG_ERROR(mkdtemp() not found!))
 
+AC_CHECK_MEMBERS([struct iocb.aio_rw_flags],,,[#include <linux/aio_abi.h>])
 AC_CHECK_MEMBERS([struct fanotify_event_info_fid.fsid.__val],,,[#include <sys/fanotify.h>])
 AC_CHECK_MEMBERS([struct perf_event_mmap_page.aux_head],,,[#include <linux/perf_event.h>])
 AC_CHECK_MEMBERS([struct sigaction.sa_sigaction],[],[],[#include <signal.h>])
include/lapi/aio_abi.h new file +44 -0
new file mode 100644
index 000000000..bd8c2965b
@@ -0,0 +1,44 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2025 Wei Gao <[email protected]>
+ */
+
+#ifndef LAPI_AIO_ABI_H__
+#define LAPI_AIO_ABI_H__
+
+#include <endian.h>
+#include <linux/aio_abi.h>
+
+#ifndef RWF_NOWAIT
+# define RWF_NOWAIT 0x00000008
+#endif
+
+struct iocb_fallback {
+        uint64_t aio_data;
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+        uint32_t   aio_key;
+        uint32_t aio_rw_flags;
+#elif __BYTE_ORDER == __BIG_ENDIAN
+        uint32_t aio_rw_flags;
+        uint32_t   aio_key;
+#else
+#error edit for your odd byteorder.
+#endif
+        uint16_t   aio_lio_opcode;
+        int16_t   aio_reqprio;
+        uint32_t   aio_fildes;
+        uint64_t   aio_buf;
+        uint64_t   aio_nbytes;
+        int64_t   aio_offset;
+        uint64_t   aio_reserved2;
+        uint32_t   aio_flags;
+        uint32_t   aio_resfd;
+};
+
+#ifndef HAVE_STRUCT_IOCB_AIO_RW_FLAGS
+typedef struct iocb_fallback iocb;
+#else
+typedef struct iocb iocb;
+#endif
+
+#endif /* LAPI_AIO_ABI_H__ */
runtest/syscalls +1 -0
index a1ef7548b..18182a2d6 100644
@@ -696,6 +696,7 @@ io_setup02 io_setup02
 io_submit01 io_submit01
 io_submit02 io_submit02
 io_submit03 io_submit03
+io_submit04 io_submit04
 
 keyctl01 keyctl01
 keyctl02 keyctl02
testcases/kernel/syscalls/io_submit/.gitignore +1 -0
index 60b07970a..abe962e1c 100644
@@ -1,3 +1,4 @@
 /io_submit01
 /io_submit02
 /io_submit03
+/io_submit04
testcases/kernel/syscalls/io_submit/io_submit04.c new file +0 -0
new file mode 100644
index 000000000..bae89828a

testcases/kernel/syscalls/io_submit/io_submit04.c line 10

Quoted 10 lines
testcases/kernel/syscalls/io_submit/io_submit04.c new file +10 -0
@@ -0,0 +1,86 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2025 Wei Gao <[email protected]>
+ */
+
+/*\
+ * Test iocb RWF_* flags support: RWF_NOWAIT
+ *
+ * Checks if an asynchronous read operation with RWF_NOWAIT on a blocking
+ * resource (empty pipe) fails immediately with -EAGAIN.

We can write it better:

/*\
* Test RWF_NOWAIT support in io_submit(), verifying that an
* asynchronous read operation on a blocking resource (empty pipe)
* will cause -EAGAIN. This is done by checking that io_getevents()
* syscall returns immediately and io_event.res is equal to -EAGAIN. */

testcases/kernel/syscalls/io_submit/io_submit04.c line 23

Quoted 13 lines
testcases/kernel/syscalls/io_submit/io_submit04.c new file +13 -0
+ */
+
+#include "config.h"
+#include "tst_test.h"
+#include "lapi/syscalls.h"
+#include "lapi/aio_abi.h"
+
+static int fd[2];
+static char buf[100];
+
+static aio_context_t ctx;
+static iocb cb;
+static iocb *iocbs[] = {&cb};

Data that is passed to syscalls should be initialized via tst_test.bufs

Quoted 34 lines
testcases/kernel/syscalls/io_submit/io_submit04.c new file +34 -0
+
+static inline void io_prep_option(iocb *cb, int fd, void *buf,
+			size_t count, long long offset, unsigned int opcode)
+{
+	memset(cb, 0, sizeof(*cb));
+	cb->aio_fildes = fd;
+	cb->aio_lio_opcode = opcode;
+	cb->aio_buf = (uint64_t)buf;
+	cb->aio_offset = offset;
+	cb->aio_nbytes = count;
+	cb->aio_rw_flags = RWF_NOWAIT;
+}
+
+static void setup(void)
+{
+	TST_EXP_PASS_SILENT(tst_syscall(__NR_io_setup, 1, &ctx));
+	SAFE_PIPE(fd);
+	io_prep_option(&cb, fd[0], buf, sizeof(buf), 0, IOCB_CMD_PREAD);
+}
+
+static void cleanup(void)
+{
+	if (fd[0])
+		SAFE_CLOSE(fd[0]);
+
+	if (fd[1])
+		SAFE_CLOSE(fd[1]);
+
+	if (tst_syscall(__NR_io_destroy, ctx))
+		tst_brk(TBROK | TERRNO, "io_destroy() failed");
+}
+
+static void run(void)
+{

testcases/kernel/syscalls/io_submit/io_submit04.c line 67

Quoted 10 lines
testcases/kernel/syscalls/io_submit/io_submit04.c new file +10 -0
+	struct io_event evbuf;
+	struct timespec timeout = { .tv_sec = 1 };
+	long nr = 1;
+
+	TEST(tst_syscall(__NR_io_submit, ctx, nr, iocbs));
+
+	if (TST_RET == nr)
+		tst_res(TPASS, "io_submit() pass");
+	else
+		tst_res(TFAIL | TTERRNO, "io_submit() returns %ld, expected %ld", TST_RET, nr);

Our goal is to verify that io_getevents() returns EAGAIN, so we can just:

Quoted 6 lines
if (TST_RET != nr) {
	tst_res(TBROK | TTERRNO, "io_submit() returns %ld, expected %ld", TST_RET, nr);
	return;
}

We return because if io_submit() fails there's nothing to do more.

tst_res(TBROK will trigger error such as :
make[1]: Leaving directory '/home/wegao/ltp/lib' In file included from ../../../../include/tst_test.h:20,

                 from io_submit04.c:14:

io_submit04.c: In function ‘run’:
../../../../include/tst_common.h:80:32: error: size of unnamed array is negative
80 | do { ((void)sizeof(char[1 - 2 * !!(condition)])); } while (0)
| ^
../../../../include/tst_common.h:83:9: note: in expansion of macro ‘TST_BUILD_BUG_ON’

   83 |         TST_BUILD_BUG_ON(condition)
      |         ^~~~~~~~~~~~~~~~
../../../../include/tst_test.h:71:17: note: in expansion of macro ‘TST_RES_SUPPORTS_TCONF_TDEBUG_TFAIL_TINFO_TPASS_TWARN’
   71 |                 TST_RES_SUPPORTS_TCONF_TDEBUG_TFAIL_TINFO_TPASS_TWARN(\
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
io_submit04.c:63:17: note: in expansion of macro ‘tst_res’
   63 |                 tst_res(TBROK | TTERRNO, "io_submit() returns %ld, expected %ld",
      |                 ^~~~~~~

make: *** [../../../../include/mk/rules.mk:48: io_submit04] Error 1 -bash: ./io_submit04: No such file or directory

So i suppose we need use "tst_brk(TBROK" without return, correct?

Quoted 36 lines

testcases/kernel/syscalls/io_submit/io_submit04.c line 72

Quoted 6 lines
testcases/kernel/syscalls/io_submit/io_submit04.c new file +5 -0
+
+	tst_syscall(__NR_io_getevents, ctx, 1, 1, &evbuf, &timeout);
+
+	if (evbuf.res == -EAGAIN)
+		tst_res(TINFO, "io_submit RWF_NOWAIT flag check pass");

Why TINFO if we are testing this feature? Also the message is not giving any information of io_getevents(). We can just (look below)...

testcases/kernel/syscalls/io_submit/io_submit04.c line 76

Quoted 4 lines
testcases/kernel/syscalls/io_submit/io_submit04.c new file +4 -0
+	else
+		tst_res(TFAIL | TTERRNO, "io_submit expect EAGAIN, but get %s", strerror(-evbuf.res));
+
+}

if (evbuf.res == -EAGAIN)

	tst_res(TPASS, "io_getevents() returned EAGAIN on read event");
else
	tst_res(TFAIL | TTERRNO, "io_getevents() returned with %s instead of EAGAIN", strerror(-evbuf.res));
Quoted 10 lines
testcases/kernel/syscalls/io_submit/io_submit04.c new file +10 -0
+
+static struct tst_test test = {
+	.test_all = run,
+	.needs_kconfigs = (const char *[]) {
+		"CONFIG_AIO=y",
+		NULL
+	},
+	.setup = setup,
+	.cleanup = cleanup,
+};
Signature · 3 lines
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#7 lore raw

Hi!

Quoted 18 lines
Quoted 1 line

We return because if io_submit() fails there's nothing to do more.

tst_res(TBROK will trigger error such as :
make[1]: Leaving directory '/home/wegao/ltp/lib' In file included from ../../../../include/tst_test.h:20,

                 from io_submit04.c:14:

io_submit04.c: In function ‘run’:
../../../../include/tst_common.h:80:32: error: size of unnamed array is negative
80 | do { ((void)sizeof(char[1 - 2 * !!(condition)])); } while (0)
| ^
../../../../include/tst_common.h:83:9: note: in expansion of macro ‘TST_BUILD_BUG_ON’

   83 |         TST_BUILD_BUG_ON(condition)
      |         ^~~~~~~~~~~~~~~~
../../../../include/tst_test.h:71:17: note: in expansion of macro ‘TST_RES_SUPPORTS_TCONF_TDEBUG_TFAIL_TINFO_TPASS_TWARN’
   71 |                 TST_RES_SUPPORTS_TCONF_TDEBUG_TFAIL_TINFO_TPASS_TWARN(\
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
io_submit04.c:63:17: note: in expansion of macro ‘tst_res’
   63 |                 tst_res(TBROK | TTERRNO, "io_submit() returns %ld, expected %ld",
      |                 ^~~~~~~
Quoted 4 lines

make: *** [../../../../include/mk/rules.mk:48: io_submit04] Error 1 -bash: ./io_submit04: No such file or directory

So i suppose we need use "tst_brk(TBROK" without return, correct?

Yes, sorry, christmas vacation is hitting :-)

Signature · 7 lines
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#8 lore raw
In reply to Wei Gao via ltp

Hi all,

...

Quoted 38 lines
Quoted 15 lines

testcases/kernel/syscalls/io_submit/io_submit04.c line 67

Quoted 12 lines
testcases/kernel/syscalls/io_submit/io_submit04.c new file +12 -0
+static void run(void)
+{
+	struct io_event evbuf;
+	struct timespec timeout = { .tv_sec = 1 };
+	long nr = 1;
+
+	TEST(tst_syscall(__NR_io_submit, ctx, nr, iocbs));
+
+	if (TST_RET == nr)
+		tst_res(TPASS, "io_submit() pass");
+	else
+		tst_res(TFAIL | TTERRNO, "io_submit() returns %ld, expected %ld", TST_RET, nr);

Our goal is to verify that io_getevents() returns EAGAIN, so we can just:

Quoted 6 lines
if (TST_RET != nr) {
	tst_res(TBROK | TTERRNO, "io_submit() returns %ld, expected %ld", TST_RET, nr);
	return;
}

We return because if io_submit() fails there's nothing to do more.

tst_res(TBROK will trigger error such as :
make[1]: Leaving directory '/home/wegao/ltp/lib' In file included from ../../../../include/tst_test.h:20,

                 from io_submit04.c:14:

io_submit04.c: In function ‘run’:
../../../../include/tst_common.h:80:32: error: size of unnamed array is negative
80 | do { ((void)sizeof(char[1 - 2 * !!(condition)])); } while (0)
| ^
../../../../include/tst_common.h:83:9: note: in expansion of macro ‘TST_BUILD_BUG_ON’

   83 |         TST_BUILD_BUG_ON(condition)
      |         ^~~~~~~~~~~~~~~~
../../../../include/tst_test.h:71:17: note: in expansion of macro ‘TST_RES_SUPPORTS_TCONF_TDEBUG_TFAIL_TINFO_TPASS_TWARN’
   71 |                 TST_RES_SUPPORTS_TCONF_TDEBUG_TFAIL_TINFO_TPASS_TWARN(\
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
io_submit04.c:63:17: note: in expansion of macro ‘tst_res’
   63 |                 tst_res(TBROK | TTERRNO, "io_submit() returns %ld, expected %ld",
      |                 ^~~~~~~
Quoted 4 lines

make: *** [../../../../include/mk/rules.mk:48: io_submit04] Error 1 -bash: ./io_submit04: No such file or directory

So i suppose we need use "tst_brk(TBROK" without return, correct?

Yes, that's a macro which enforces using TBROK only with tst_brk().

@Cyril @Li @Jan I wonder if we still need this enforcement after Cyril's change a1f82704c2 ("lib/tst_test.c: Fix tst_brk() handling")

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#9 lore raw
Quoted 45 lines · Petr Vorel

Hi all,

...

Quoted 40 lines
Quoted 15 lines

testcases/kernel/syscalls/io_submit/io_submit04.c line 67

Quoted 12 lines
testcases/kernel/syscalls/io_submit/io_submit04.c new file +12 -0
+static void run(void)
+{
+ struct io_event evbuf;
+ struct timespec timeout = { .tv_sec = 1 };
+ long nr = 1;
+
+ TEST(tst_syscall(__NR_io_submit, ctx, nr, iocbs));
+
+ if (TST_RET == nr)
+         tst_res(TPASS, "io_submit() pass");
+ else
+         tst_res(TFAIL | TTERRNO, "io_submit() returns %ld, expected %ld", TST_RET, nr);

Our goal is to verify that io_getevents() returns EAGAIN, so we can just:

Quoted 6 lines
if (TST_RET != nr) {
    tst_res(TBROK | TTERRNO, "io_submit() returns %ld, expected %ld", TST_RET, nr);
    return;
}

We return because if io_submit() fails there's nothing to do more.

tst_res(TBROK will trigger error such as :
make[1]: Leaving directory '/home/wegao/ltp/lib' In file included from ../../../../include/tst_test.h:20,

                 from io_submit04.c:14:

io_submit04.c: In function ‘run’:
../../../../include/tst_common.h:80:32: error: size of unnamed array is negative
80 | do { ((void)sizeof(char[1 - 2 * !!(condition)])); } while (0)
| ^
../../../../include/tst_common.h:83:9: note: in expansion of macro ‘TST_BUILD_BUG_ON’

   83 |         TST_BUILD_BUG_ON(condition)
      |         ^~~~~~~~~~~~~~~~
../../../../include/tst_test.h:71:17: note: in expansion of macro ‘TST_RES_SUPPORTS_TCONF_TDEBUG_TFAIL_TINFO_TPASS_TWARN’
   71 |                 TST_RES_SUPPORTS_TCONF_TDEBUG_TFAIL_TINFO_TPASS_TWARN(\
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
io_submit04.c:63:17: note: in expansion of macro ‘tst_res’
   63 |                 tst_res(TBROK | TTERRNO, "io_submit() returns %ld, expected %ld",
      |                 ^~~~~~~

make: *** [../../../../include/mk/rules.mk:48: io_submit04] Error 1 -bash: ./io_submit04: No such file or directory

Quoted 6 lines
Quoted 1 line

So i suppose we need use "tst_brk(TBROK" without return, correct?

Yes, that's a macro which enforces using TBROK only with tst_brk().

@Cyril @Li @Jan I wonder if we still need this enforcement after Cyril's change a1f82704c2 ("lib/tst_test.c: Fix tst_brk() handling")

Looking at differences between tst_res_() and tst_vbrk_() , vbrk_ has some additional cleanup calls
so they don't look to be exactly identical. I'd keep it to encourage usage of tst_brk() if you need
to abort the test (from any context: library, test, test children).

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

PATCH v4 1/1 io_submit04: Add test case for RWF_NOWAIT flag

In reply to Wei Gao via ltp
Fixes #467
---
 configure.ac                                  |  1 +
 include/lapi/aio_abi.h                        | 44 +++++++++
 runtest/syscalls                              |  1 +
 .../kernel/syscalls/io_submit/.gitignore      |  1 +
 .../kernel/syscalls/io_submit/io_submit04.c   | 94 +++++++++++++++++++
 5 files changed, 141 insertions(+)
 create mode 100644 include/lapi/aio_abi.h
 create mode 100644 testcases/kernel/syscalls/io_submit/io_submit04.c
configure.ac +1 -0
index a0ebbb34d..ee46e3f24 100644
@@ -172,6 +172,7 @@ AC_CHECK_FUNCS_ONCE([ \
 ])
 AC_CHECK_FUNCS(mkdtemp,[],AC_MSG_ERROR(mkdtemp() not found!))
 
+AC_CHECK_MEMBERS([struct iocb.aio_rw_flags],,,[#include <linux/aio_abi.h>])
 AC_CHECK_MEMBERS([struct fanotify_event_info_fid.fsid.__val],,,[#include <sys/fanotify.h>])
 AC_CHECK_MEMBERS([struct perf_event_mmap_page.aux_head],,,[#include <linux/perf_event.h>])
 AC_CHECK_MEMBERS([struct sigaction.sa_sigaction],[],[],[#include <signal.h>])
include/lapi/aio_abi.h new file +44 -0

44 lines not on this page · raw message

runtest/syscalls +1 -0
index a1ef7548b..18182a2d6 100644
@@ -696,6 +696,7 @@ io_setup02 io_setup02
 io_submit01 io_submit01
 io_submit02 io_submit02
 io_submit03 io_submit03
+io_submit04 io_submit04
 
 keyctl01 keyctl01
 keyctl02 keyctl02
testcases/kernel/syscalls/io_submit/.gitignore +1 -0
index 60b07970a..abe962e1c 100644
@@ -1,3 +1,4 @@
 /io_submit01
 /io_submit02
 /io_submit03
+/io_submit04
testcases/kernel/syscalls/io_submit/io_submit04.c new file +94 -0

94 lines not on this page · raw message

Signature · 5 lines
2.52.0


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

Hi!

Quoted 56 lines · Wei Gao
Fixes #467
---
 configure.ac                                  |  1 +
 include/lapi/aio_abi.h                        | 44 +++++++++
 runtest/syscalls                              |  1 +
 .../kernel/syscalls/io_submit/.gitignore      |  1 +
 .../kernel/syscalls/io_submit/io_submit04.c   | 94 +++++++++++++++++++
 5 files changed, 141 insertions(+)
 create mode 100644 include/lapi/aio_abi.h
 create mode 100644 testcases/kernel/syscalls/io_submit/io_submit04.c
configure.ac +1 -0
index a0ebbb34d..ee46e3f24 100644
@@ -172,6 +172,7 @@ AC_CHECK_FUNCS_ONCE([ \
 ])
 AC_CHECK_FUNCS(mkdtemp,[],AC_MSG_ERROR(mkdtemp() not found!))
 
+AC_CHECK_MEMBERS([struct iocb.aio_rw_flags],,,[#include <linux/aio_abi.h>])
 AC_CHECK_MEMBERS([struct fanotify_event_info_fid.fsid.__val],,,[#include <sys/fanotify.h>])
 AC_CHECK_MEMBERS([struct perf_event_mmap_page.aux_head],,,[#include <linux/perf_event.h>])
 AC_CHECK_MEMBERS([struct sigaction.sa_sigaction],[],[],[#include <signal.h>])
include/lapi/aio_abi.h new file +26 -0
new file mode 100644
index 000000000..bd8c2965b
@@ -0,0 +1,44 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2025 Wei Gao <[email protected]>
+ */
+
+#ifndef LAPI_AIO_ABI_H__
+#define LAPI_AIO_ABI_H__
+
+#include <endian.h>
+#include <linux/aio_abi.h>
+
+#ifndef RWF_NOWAIT
+# define RWF_NOWAIT 0x00000008
+#endif
+
+struct iocb_fallback {
+        uint64_t aio_data;
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+        uint32_t   aio_key;
+        uint32_t aio_rw_flags;
+#elif __BYTE_ORDER == __BIG_ENDIAN
+        uint32_t aio_rw_flags;
+        uint32_t   aio_key;
+#else
+#error edit for your odd byteorder.
+#endif

include/lapi/aio_abi.h line 36

Quoted 10 lines
include/lapi/aio_abi.h new file +10 -0
+        uint16_t   aio_lio_opcode;
+        int16_t   aio_reqprio;
+        uint32_t   aio_fildes;
+        uint64_t   aio_buf;
+        uint64_t   aio_nbytes;
+        int64_t   aio_offset;
+        uint64_t   aio_reserved2;
+        uint32_t   aio_flags;
+        uint32_t   aio_resfd;
+};

checkpatch.pl reports you are using too many spaces for indentation in here.

include/lapi/aio_abi.h line 39

Quoted 3 lines
include/lapi/aio_abi.h new file +3 -0
+
+#ifndef HAVE_STRUCT_IOCB_AIO_RW_FLAGS
+typedef struct iocb_fallback iocb;

Why not just define here the iocb, instead of having iocb_fallback defined before?

include/lapi/aio_abi.h line 41

Quoted 2 lines
include/lapi/aio_abi.h new file +2 -0
+#else
+typedef struct iocb iocb;

And this would not be needed then.

Quoted 38 lines
include/lapi/aio_abi.h new file +3 -0
+#endif
+
+#endif /* LAPI_AIO_ABI_H__ */
runtest/syscalls +1 -0
index a1ef7548b..18182a2d6 100644
@@ -696,6 +696,7 @@ io_setup02 io_setup02
 io_submit01 io_submit01
 io_submit02 io_submit02
 io_submit03 io_submit03
+io_submit04 io_submit04
 
 keyctl01 keyctl01
 keyctl02 keyctl02
testcases/kernel/syscalls/io_submit/.gitignore +1 -0
index 60b07970a..abe962e1c 100644
@@ -1,3 +1,4 @@
 /io_submit01
 /io_submit02
 /io_submit03
+/io_submit04
testcases/kernel/syscalls/io_submit/io_submit04.c new file +8 -0
new file mode 100644
index 000000000..d085d3238
@@ -0,0 +1,94 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2025 Wei Gao <[email protected]>
+ */
+
+/*\
+ * Test RWF_NOWAIT support in io_submit(), verifying that an
+ * asynchronous read operation on a blocking resource (empty pipe)

testcases/kernel/syscalls/io_submit/io_submit04.c line 18

Quoted 10 lines
testcases/kernel/syscalls/io_submit/io_submit04.c new file +10 -0
+ * will cause -EAGAIN. This is done by checking that io_getevents()
+ * syscall returns immediately and io_event.res is equal to -EAGAIN.
+ */
+
+#include "config.h"
+#include "tst_test.h"
+#include "lapi/syscalls.h"
+#include "lapi/aio_abi.h"
+
+

nit: double blank-line is not needed.

testcases/kernel/syscalls/io_submit/io_submit04.c line 21

Quoted 3 lines
testcases/kernel/syscalls/io_submit/io_submit04.c new file +3 -0
+#define BUF_SIZE 100
+
+static int fd[2];

fd should be initialized to -1 and compared to this value in the cleanup() before closing. zero is a valid value for file descriptors (stdin).

testcases/kernel/syscalls/io_submit/io_submit04.c line 30

Quoted 9 lines
testcases/kernel/syscalls/io_submit/io_submit04.c new file +9 -0
+
+static aio_context_t ctx;
+static char *buf;
+static iocb *cb;
+static iocb **iocbs;
+
+static void setup(void)
+{
+	TST_EXP_PASS_SILENT(tst_syscall(__NR_io_setup, 1, &ctx));

We need to break the test here if io_setup fails. Silently failing it will keep test running.

Quoted 31 lines
testcases/kernel/syscalls/io_submit/io_submit04.c new file +31 -0
+	SAFE_PIPE(fd);
+
+	cb->aio_fildes = fd[0];
+	cb->aio_lio_opcode = IOCB_CMD_PREAD;
+	cb->aio_buf = (uint64_t)buf;
+	cb->aio_offset = 0;
+	cb->aio_nbytes = BUF_SIZE;
+	cb->aio_rw_flags = RWF_NOWAIT;
+
+	iocbs[0] = cb;
+}
+
+static void cleanup(void)
+{
+	if (fd[0])
+		SAFE_CLOSE(fd[0]);
+
+	if (fd[1])
+		SAFE_CLOSE(fd[1]);
+
+	if (ctx)
+		if (tst_syscall(__NR_io_destroy, ctx))
+			tst_brk(TBROK | TERRNO, "io_destroy() failed");
+}
+
+static void run(void)
+{
+	struct io_event evbuf;
+	struct timespec timeout = { .tv_sec = 1 };
+	long nr = 1;
+

testcases/kernel/syscalls/io_submit/io_submit04.c line 71

Quoted 10 lines
testcases/kernel/syscalls/io_submit/io_submit04.c new file +10 -0
+	TEST(tst_syscall(__NR_io_submit, ctx, nr, iocbs));
+
+	if (TST_RET == -1 && errno == EOPNOTSUPP) {
+		tst_brk(TCONF, "RWF_NOWAIT not supported by kernel");
+	} else if (TST_RET != nr) {
+		tst_brk(TBROK | TTERRNO, "io_submit() returns %ld, expected %ld",
+				TST_RET, nr);
+	}
+
+	tst_syscall(__NR_io_getevents, ctx, 1, 1, &evbuf, &timeout);

Return value is ignored.

testcases/kernel/syscalls/io_submit/io_submit04.c line 76

Quoted 5 lines
testcases/kernel/syscalls/io_submit/io_submit04.c new file +5 -0
+
+	if (evbuf.res == -EAGAIN)
+		tst_res(TPASS, "io_getevents() returned EAGAIN on read event");
+	else
+		tst_res(TFAIL | TTERRNO, "io_getevents() returned with %s instead of EAGAIN",

TTERRNO is not needed.

Quoted 18 lines
testcases/kernel/syscalls/io_submit/io_submit04.c new file +18 -0
+			strerror(-evbuf.res));
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_kconfigs = (const char *[]) {
+		"CONFIG_AIO=y",
+		NULL
+	},
+	.bufs = (struct tst_buffers []) {
+		{&buf, .size = BUF_SIZE},
+		{&cb, .size = sizeof(iocb)},
+		{&iocbs, .size = sizeof(iocb *)},
+		{},
+	}
+};
Signature · 7 lines
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#12 lore raw
Quoted 7 lines · Andrea Cervesato

Hi!

Quoted 3 lines · Wei Gao
Fixes #467

---

Quoted 6 lines

include/lapi/aio_abi.h line 39

Quoted 3 lines
include/lapi/aio_abi.h new file +3 -0
+
+#ifndef HAVE_STRUCT_IOCB_AIO_RW_FLAGS
+typedef struct iocb_fallback iocb;

Why not just define here the iocb, instead of having iocb_fallback defined before?

This way can avoid complie failure on old system such as:
https://github.com/coolgw/ltp/actions/runs/22699554704/job/65813365426
make[4]: *** [io_submit04] Error 1
make[4]: *** Waiting for unfinished jobs.... ../../../../include/mk/rules.mk:48: recipe for target 'io_submit04' failed CC testcases/kernel/syscalls/io_submit/io_submit01
CC testcases/kernel/syscalls/io_submit/io_submit02
CC testcases/kernel/syscalls/io_submit/io_submit03
make[3]: *** [all] Error 2 ../../../include/mk/generic_trunk_target.inc:92: recipe for target 'all' failed make[2]: *** [all] Error 2 ../../include/mk/generic_trunk_target.inc:92: recipe for target 'all' failed make[1]: *** [all] Error 2 ../include/mk/generic_trunk_target.inc:92: recipe for target 'all' failed make[1]: Leaving directory '/__w/ltp/ltp/testcases'
Makefile:85: recipe for target 'testcases-all' failed
make: *** [testcases-all] Error 2
Error: Process completed with exit code 2

This kind of fallback also mentioned/used in following patch:
https://patchwork.ozlabs.org/project/ltp/patch/[email protected]/

Quoted 157 lines

Review

Quoted 3 lines
(quoted diff) +2 -0
+#else
+typedef struct iocb iocb;

And this would not be needed then.

Quoted 38 lines
include/lapi/aio_abi.h new file +3 -0
+#endif
+
+#endif /* LAPI_AIO_ABI_H__ */
runtest/syscalls +1 -0
index a1ef7548b..18182a2d6 100644
@@ -696,6 +696,7 @@ io_setup02 io_setup02
 io_submit01 io_submit01
 io_submit02 io_submit02
 io_submit03 io_submit03
+io_submit04 io_submit04
 
 keyctl01 keyctl01
 keyctl02 keyctl02
testcases/kernel/syscalls/io_submit/.gitignore +1 -0
index 60b07970a..abe962e1c 100644
@@ -1,3 +1,4 @@
 /io_submit01
 /io_submit02
 /io_submit03
+/io_submit04
testcases/kernel/syscalls/io_submit/io_submit04.c new file +8 -0
new file mode 100644
index 000000000..d085d3238
@@ -0,0 +1,94 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2025 Wei Gao <[email protected]>
+ */
+
+/*\
+ * Test RWF_NOWAIT support in io_submit(), verifying that an
+ * asynchronous read operation on a blocking resource (empty pipe)

testcases/kernel/syscalls/io_submit/io_submit04.c line 18

Quoted 10 lines
testcases/kernel/syscalls/io_submit/io_submit04.c new file +10 -0
+ * will cause -EAGAIN. This is done by checking that io_getevents()
+ * syscall returns immediately and io_event.res is equal to -EAGAIN.
+ */
+
+#include "config.h"
+#include "tst_test.h"
+#include "lapi/syscalls.h"
+#include "lapi/aio_abi.h"
+
+

nit: double blank-line is not needed.

testcases/kernel/syscalls/io_submit/io_submit04.c line 21

Quoted 3 lines
testcases/kernel/syscalls/io_submit/io_submit04.c new file +3 -0
+#define BUF_SIZE 100
+
+static int fd[2];

fd should be initialized to -1 and compared to this value in the cleanup() before closing. zero is a valid value for file descriptors (stdin).

testcases/kernel/syscalls/io_submit/io_submit04.c line 30

Quoted 9 lines
testcases/kernel/syscalls/io_submit/io_submit04.c new file +9 -0
+
+static aio_context_t ctx;
+static char *buf;
+static iocb *cb;
+static iocb **iocbs;
+
+static void setup(void)
+{
+	TST_EXP_PASS_SILENT(tst_syscall(__NR_io_setup, 1, &ctx));

We need to break the test here if io_setup fails. Silently failing it will keep test running.

Quoted 31 lines
testcases/kernel/syscalls/io_submit/io_submit04.c new file +31 -0
+	SAFE_PIPE(fd);
+
+	cb->aio_fildes = fd[0];
+	cb->aio_lio_opcode = IOCB_CMD_PREAD;
+	cb->aio_buf = (uint64_t)buf;
+	cb->aio_offset = 0;
+	cb->aio_nbytes = BUF_SIZE;
+	cb->aio_rw_flags = RWF_NOWAIT;
+
+	iocbs[0] = cb;
+}
+
+static void cleanup(void)
+{
+	if (fd[0])
+		SAFE_CLOSE(fd[0]);
+
+	if (fd[1])
+		SAFE_CLOSE(fd[1]);
+
+	if (ctx)
+		if (tst_syscall(__NR_io_destroy, ctx))
+			tst_brk(TBROK | TERRNO, "io_destroy() failed");
+}
+
+static void run(void)
+{
+	struct io_event evbuf;
+	struct timespec timeout = { .tv_sec = 1 };
+	long nr = 1;
+

testcases/kernel/syscalls/io_submit/io_submit04.c line 71

Quoted 10 lines
testcases/kernel/syscalls/io_submit/io_submit04.c new file +10 -0
+	TEST(tst_syscall(__NR_io_submit, ctx, nr, iocbs));
+
+	if (TST_RET == -1 && errno == EOPNOTSUPP) {
+		tst_brk(TCONF, "RWF_NOWAIT not supported by kernel");
+	} else if (TST_RET != nr) {
+		tst_brk(TBROK | TTERRNO, "io_submit() returns %ld, expected %ld",
+				TST_RET, nr);
+	}
+
+	tst_syscall(__NR_io_getevents, ctx, 1, 1, &evbuf, &timeout);

Return value is ignored.

testcases/kernel/syscalls/io_submit/io_submit04.c line 76

Quoted 5 lines
testcases/kernel/syscalls/io_submit/io_submit04.c new file +5 -0
+
+	if (evbuf.res == -EAGAIN)
+		tst_res(TPASS, "io_getevents() returned EAGAIN on read event");
+	else
+		tst_res(TFAIL | TTERRNO, "io_getevents() returned with %s instead of EAGAIN",

TTERRNO is not needed.

Quoted 18 lines
testcases/kernel/syscalls/io_submit/io_submit04.c new file +18 -0
+			strerror(-evbuf.res));
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_kconfigs = (const char *[]) {
+		"CONFIG_AIO=y",
+		NULL
+	},
+	.bufs = (struct tst_buffers []) {
+		{&buf, .size = BUF_SIZE},
+		{&cb, .size = sizeof(iocb)},
+		{&iocbs, .size = sizeof(iocb *)},
+		{},
+	}
+};
Signature · 3 lines
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#13 lore raw

PATCH v5 1/1 io_submit04: Add test case for RWF_NOWAIT flag

In reply to Wei Gao via ltp

v4->v5:
- Initialize fd to -1
- Replaces silent macros with explicit error checks
- Verifies that io_getevents actually returns the expected event
- Remove duplicate TTERRNO

Fixes #467
---
 configure.ac                                  |  1 +
 include/lapi/aio_abi.h                        | 44 +++++++++
 runtest/syscalls                              |  1 +
 .../kernel/syscalls/io_submit/.gitignore      |  1 +
 .../kernel/syscalls/io_submit/io_submit04.c   | 99 +++++++++++++++++++
 5 files changed, 146 insertions(+)
 create mode 100644 include/lapi/aio_abi.h
 create mode 100644 testcases/kernel/syscalls/io_submit/io_submit04.c
configure.ac +1 -0
index 7fa614dcb..61462d192 100644
@@ -172,6 +172,7 @@ AC_CHECK_FUNCS_ONCE([ \
 ])
 AC_CHECK_FUNCS(mkdtemp,[],AC_MSG_ERROR(mkdtemp() not found!))
 
+AC_CHECK_MEMBERS([struct iocb.aio_rw_flags],,,[#include <linux/aio_abi.h>])
 AC_CHECK_MEMBERS([struct fanotify_event_info_fid.fsid.__val],,,[#include <sys/fanotify.h>])
 AC_CHECK_MEMBERS([struct perf_event_mmap_page.aux_head],,,[#include <linux/perf_event.h>])
 AC_CHECK_MEMBERS([struct sigaction.sa_sigaction],[],[],[#include <signal.h>])
include/lapi/aio_abi.h new file +44 -0

44 lines not on this page · raw message

runtest/syscalls +1 -0
index 2179e007c..9812b1bfe 100644
@@ -699,6 +699,7 @@ io_setup02 io_setup02
 io_submit01 io_submit01
 io_submit02 io_submit02
 io_submit03 io_submit03
+io_submit04 io_submit04
 
 keyctl01 keyctl01
 keyctl02 keyctl02
testcases/kernel/syscalls/io_submit/.gitignore +1 -0
index 60b07970a..abe962e1c 100644
@@ -1,3 +1,4 @@
 /io_submit01
 /io_submit02
 /io_submit03
+/io_submit04
testcases/kernel/syscalls/io_submit/io_submit04.c new file +99 -0

99 lines not on this page · raw message

Signature · 5 lines
2.52.0


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

Hi Wei,

Thanks for the patch. I have a few issues to address before this can be merged.

include/lapi/aio_abi.h line 20

Quoted 6 lines
include/lapi/aio_abi.h +5 -0
+struct iocb_fallback {
+        uint64_t aio_data;
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+        uint32_t   aio_key;
+        uint32_t aio_rw_flags;

The struct body uses spaces for indentation instead of tabs. Please convert to tabs to match the kernel coding style used in other lapi headers.

include/lapi/aio_abi.h

Quoted 7 lines
include/lapi/aio_abi.h +7 -0
+static void cleanup(void)
+{
+   if (fd[0])
+           SAFE_CLOSE(fd[0]);
+
+   if (fd[1])
+           SAFE_CLOSE(fd[1]);

fd is initialised to {-1, -1}. The check if (fd[0]) is truthy for -1, so if setup() aborts before SAFE_PIPE() (e.g. io_setup fails), cleanup will call SAFE_CLOSE(-1) which fails with EBADF and triggers a spurious TBROK. Use the standard LTP pattern:

    if (fd[0] != -1)
        SAFE_CLOSE(fd[0]);

    if (fd[1] != -1)
        SAFE_CLOSE(fd[1]);

include/lapi/aio_abi.h

Quoted 3 lines
include/lapi/aio_abi.h +3 -0
+   TEST(tst_syscall(__NR_io_submit, ctx, nr, iocbs));
+
+   if (TST_RET == -1 && errno == EOPNOTSUPP) {

After the TEST() macro, use TST_ERR instead of bare errno:

    if (TST_RET == -1 && TST_ERR == EOPNOTSUPP) {

Regards,
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]

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

PATCH v6 1/1 io_submit04: Add test case for RWF_NOWAIT flag

In reply to Wei Gao via ltp

v5-v6:
- Changed fd checks to != -1 in cleanup function
- Replaced errno with TST_ERR for LTP macro consistency
- cleanup format issue for aio_abi.h

Fixes #467
---
 configure.ac                                  |  1 +
 include/lapi/aio_abi.h                        | 44 +++++++++
 runtest/syscalls                              |  1 +
 .../kernel/syscalls/io_submit/.gitignore      |  1 +
 .../kernel/syscalls/io_submit/io_submit04.c   | 99 +++++++++++++++++++
 5 files changed, 146 insertions(+)
 create mode 100644 include/lapi/aio_abi.h
 create mode 100644 testcases/kernel/syscalls/io_submit/io_submit04.c
configure.ac +1 -0
index 7fa614dcb..61462d192 100644
@@ -172,6 +172,7 @@ AC_CHECK_FUNCS_ONCE([ \
 ])
 AC_CHECK_FUNCS(mkdtemp,[],AC_MSG_ERROR(mkdtemp() not found!))
 
+AC_CHECK_MEMBERS([struct iocb.aio_rw_flags],,,[#include <linux/aio_abi.h>])
 AC_CHECK_MEMBERS([struct fanotify_event_info_fid.fsid.__val],,,[#include <sys/fanotify.h>])
 AC_CHECK_MEMBERS([struct perf_event_mmap_page.aux_head],,,[#include <linux/perf_event.h>])
 AC_CHECK_MEMBERS([struct sigaction.sa_sigaction],[],[],[#include <signal.h>])
include/lapi/aio_abi.h new file +44 -0

44 lines not on this page · raw message

runtest/syscalls +1 -0
index 2179e007c..9812b1bfe 100644
@@ -699,6 +699,7 @@ io_setup02 io_setup02
 io_submit01 io_submit01
 io_submit02 io_submit02
 io_submit03 io_submit03
+io_submit04 io_submit04
 
 keyctl01 keyctl01
 keyctl02 keyctl02
testcases/kernel/syscalls/io_submit/.gitignore +1 -0
index 60b07970a..abe962e1c 100644
@@ -1,3 +1,4 @@
 /io_submit01
 /io_submit02
 /io_submit03
+/io_submit04
testcases/kernel/syscalls/io_submit/io_submit04.c new file +99 -0

99 lines not on this page · raw message

Signature · 5 lines
2.52.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
author Reviewed-by Andrea Cervesato on v6 1/1
#16 lore raw

Hi!

Quoted 4 lines

v5-v6:
- Changed fd checks to != -1 in cleanup function
- Replaced errno with TST_ERR for LTP macro consistency
- cleanup format issue for aio_abi.h

This can't be the body of the commit. It should be after --- as a patch comment. We can fix the commit message once patch merged.

Regards,
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#17 lore raw
In reply to Wei Gao via ltp

Hi Wei, all,

configure.ac AC_CHECK_FUNCS_ONCE([ \ · line 175

Quoted 6 lines

+++ b/configure.ac

configure.ac +1 -0
@@ -172,6 +172,7 @@ AC_CHECK_FUNCS_ONCE([ \
 ])
 AC_CHECK_FUNCS(mkdtemp,[],AC_MSG_ERROR(mkdtemp() not found!))
 
+AC_CHECK_MEMBERS([struct iocb.aio_rw_flags],,,[#include <linux/aio_abi.h>])

FYI I double checked this is from 4.13 9830f4be159b2 ("fs: Use RWF_* flags for AIO operations")

So we need it, but it'd be worth to double check how the test run on 4.4 (if it TCONF). Also maybe add a comment in the code or at least mention it in the commit message. When we drop old SLES we will be able to remove this.

@Andrea: any hint for your agents to check supported versions
https://linux-test-project.readthedocs.io/en/latest/users/supported_systems.html#kernel-version
and whether it needs to have fallback in lapi and configure.ac? Also we may ask not to add .min_kver which would be too old.

Quoted 12 lines
configure.ac +0 -0
 AC_CHECK_MEMBERS([struct fanotify_event_info_fid.fsid.__val],,,[#include <sys/fanotify.h>])
 AC_CHECK_MEMBERS([struct perf_event_mmap_page.aux_head],,,[#include <linux/perf_event.h>])
 AC_CHECK_MEMBERS([struct sigaction.sa_sigaction],[],[],[#include <signal.h>])
include/lapi/aio_abi.h new file +3 -0
new file mode 100644
index 000000000..ac78e5500
@@ -0,0 +1,44 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2025 Wei Gao <[email protected]>

include/lapi/aio_abi.h line 13

Quoted 10 lines
include/lapi/aio_abi.h new file +10 -0
+ */
+
+#ifndef LAPI_AIO_ABI_H__
+#define LAPI_AIO_ABI_H__
+
+#include <endian.h>
+#include <linux/aio_abi.h>
+
+#ifndef RWF_NOWAIT
+# define RWF_NOWAIT 0x00000008

And this as well.
b745fafaf70c0 ("fs: Introduce RWF_NOWAIT and FMODE_AIO_NOWAIT")

Quoted 31 lines
include/lapi/aio_abi.h new file +31 -0
+#endif
+
+struct iocb_fallback {
+	uint64_t aio_data;
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+	uint32_t   aio_key;
+	uint32_t aio_rw_flags;
+#elif __BYTE_ORDER == __BIG_ENDIAN
+	uint32_t aio_rw_flags;
+	uint32_t   aio_key;
+#else
+#error edit for your odd byteorder.
+#endif
+	uint16_t   aio_lio_opcode;
+	int16_t   aio_reqprio;
+	uint32_t   aio_fildes;
+	uint64_t   aio_buf;
+	uint64_t   aio_nbytes;
+	int64_t   aio_offset;
+	uint64_t   aio_reserved2;
+	uint32_t   aio_flags;
+	uint32_t   aio_resfd;
+};
+
+#ifndef HAVE_STRUCT_IOCB_AIO_RW_FLAGS
+typedef struct iocb_fallback iocb;
+#else
+typedef struct iocb iocb;
+#endif
+
+#endif /* LAPI_AIO_ABI_H__ */

...

include/lapi/aio_abi.h line 9

Quoted 11 lines

+++ b/testcases/kernel/syscalls/io_submit/io_submit04.c

include/lapi/aio_abi.h new file +9 -0
@@ -0,0 +1,99 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2025 Wei Gao <[email protected]>
+ */
+
+/*\
+ * Test RWF_NOWAIT support in io_submit(), verifying that an
+ * asynchronous read operation on a blocking resource (empty pipe)
+ * will cause -EAGAIN. This is done by checking that io_getevents()

Please :manpage:io_getevents(2)
(to have link to https://man7.org/linux/man-pages/man2/io_getevents.2.html in docs).

@Andrea: ^ to agents?

include/lapi/aio_abi.h line 20

Quoted 11 lines
include/lapi/aio_abi.h new file +11 -0
+ * syscall returns immediately and io_event.res is equal to -EAGAIN.
+ */
+
+#include "config.h"
+#include "tst_test.h"
+#include "lapi/syscalls.h"
+#include "lapi/aio_abi.h"
+
+#define BUF_SIZE 100
+
+static int fd[2] = {-1, -1};

nit: Andrea (I guess you asked for it), because we hardly close STDOUT in the test 0 is always used. I see it a bit overkill using -1 (using 0 as the default would almost always work).

Quoted 23 lines
include/lapi/aio_abi.h new file +23 -0
+static aio_context_t ctx;
+static char *buf;
+static iocb *cb;
+static iocb **iocbs;
+
+static void setup(void)
+{
+	if (tst_syscall(__NR_io_setup, 1, &ctx))
+		tst_brk(TBROK | TERRNO, "io_setup failed");
+
+	SAFE_PIPE(fd);
+
+	cb->aio_fildes = fd[0];
+	cb->aio_lio_opcode = IOCB_CMD_PREAD;
+	cb->aio_buf = (uint64_t)buf;
+	cb->aio_offset = 0;
+	cb->aio_nbytes = BUF_SIZE;
+	cb->aio_rw_flags = RWF_NOWAIT;
+
+	iocbs[0] = cb;
+}
+
+static void cleanup(void)

include/lapi/aio_abi.h line 53

Quoted 10 lines
include/lapi/aio_abi.h new file +10 -0
+{
+	if (fd[0] != -1)
+		SAFE_CLOSE(fd[0]);
+
+	if (fd[1] != -1)
+		SAFE_CLOSE(fd[1]);
+
+	if (ctx)
+		if (tst_syscall(__NR_io_destroy, ctx))
+			tst_brk(TBROK | TERRNO, "io_destroy() failed");

Upper if would require { } brackets, but let's simplify:

	if (ctx && tst_syscall(__NR_io_destroy, ctx))
		tst_brk(TBROK | TERRNO, "io_destroy() failed");
Quoted 6 lines
include/lapi/aio_abi.h new file +6 -0
+}
+
+static void run(void)
+{
+	struct io_event evbuf;
+	struct timespec timeout = { .tv_sec = 1 };

include/lapi/aio_abi.h line 69

Quoted 10 lines
include/lapi/aio_abi.h new file +10 -0
+	long nr = 1;
+
+	TEST(tst_syscall(__NR_io_submit, ctx, nr, iocbs));
+
+	if (TST_RET == -1 && TST_ERR == EOPNOTSUPP) {
+		tst_brk(TCONF, "RWF_NOWAIT not supported by kernel");
+	} else if (TST_RET != nr) {
+		tst_brk(TBROK | TTERRNO, "io_submit() returns %ld, expected %ld",
+				TST_RET, nr);
+	}

Maybe move this to setup()?

include/lapi/aio_abi.h line 78

Quoted 9 lines
include/lapi/aio_abi.h new file +9 -0
+
+	TEST(tst_syscall(__NR_io_getevents, ctx, 1, 1, &evbuf, &timeout));
+
+	if (TST_RET != 1) {
+		tst_res(TFAIL | TTERRNO, "io_getevents() failed to get 1 event");
+		return;
+	}
+
+	if (evbuf.res == -EAGAIN)

Did you please check this on 32bit?

include/lapi/aio_abi.h line 83

Quoted 5 lines
include/lapi/aio_abi.h new file +5 -0
+		tst_res(TPASS, "io_getevents() returned EAGAIN on read event");
+	else
+		tst_res(TFAIL, "io_getevents() returned with %s instead of EAGAIN",
+			strerror(-evbuf.res));
+}

The rest LGTM.

Kind regards,
Petr

Quoted 16 lines
include/lapi/aio_abi.h new file +16 -0
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_kconfigs = (const char *[]) {
+		"CONFIG_AIO=y",
+		NULL
+	},
+	.bufs = (struct tst_buffers []) {
+		{&buf, .size = BUF_SIZE},
+		{&cb, .size = sizeof(iocb)},
+		{&iocbs, .size = sizeof(iocb *)},
+		{},
+	}
+};
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#18 lore raw
Quoted 7 lines · Petr Vorel

Hi Wei, all,

Quoted 4 lines

+++ b/configure.ac

configure.ac +0 -0
@@ -172,6 +172,7 @@ AC_CHECK_FUNCS_ONCE([ \
 ])
 AC_CHECK_FUNCS(mkdtemp,[],AC_MSG_ERROR(mkdtemp() not found!))
Quoted 7 lines

configure.ac AC_CHECK_FUNCS_ONCE([ \ · line 175

Quoted 1 line
configure.ac +1 -0
+AC_CHECK_MEMBERS([struct iocb.aio_rw_flags],,,[#include <linux/aio_abi.h>])

FYI I double checked this is from 4.13 9830f4be159b2 ("fs: Use RWF_* flags for AIO operations")

So we need it, but it'd be worth to double check how the test run on 4.4 (if it TCONF). Also maybe add a comment in the code or at least mention it in the commit message. When we drop old SLES we will be able to remove this.

I found a 12-SP5 JeOS old img with kernel 4.12, the test result show TCONF, i think 4.4 also can show TCONF.
https://download.opensuse.org/repositories/SUSE:/Templates:/Images:/SLE-12-SP5/images/SLES12-SP5-JeOS.x86_64-12.5-kvm-and-xen-Build1.614.qcow2

linux:~/ltp/testcases/kernel/syscalls/io_submit # uname -r
4.12.14-122.231-default
linux:~/ltp/testcases/kernel/syscalls/io_submit # cat /etc/os-release
NAME="SLES"
VERSION="12-SP5"
VERSION_ID="12.5"
PRETTY_NAME="SUSE Linux Enterprise Server 12 SP5"
ID="sles"
ANSI_COLOR="0;32"
CPE_NAME="cpe:/o:suse:sles:12:sp5"
linux:~/ltp/testcases/kernel/syscalls/io_submit # ./io_submit04
tst_kconfig.c:88: TINFO: Parsing kernel config '/proc/config.gz'
tst_buffers.c:57: TINFO: Test is using guarded buffers
tst_test.c:2059: TINFO: LTP version: 20260130
tst_test.c:2062: TINFO: Tested kernel: 4.12.14-122.231-default #1 SMP Wed Oct 2 17:30:21 UTC 2024 (5f0ddca) x86_64 tst_kconfig.c:88: TINFO: Parsing kernel config '/proc/config.gz'
tst_kconfig.c:678: TINFO: CONFIG_FAULT_INJECTION kernel option detected which might slow the execution tst_test.c:1889: TINFO: Overall timeout per run is 0h 02m 00s
io_submit04.c:65: TCONF: RWF_NOWAIT not supported by kernel

Quoted 81 lines

@Andrea: any hint for your agents to check supported versions
https://linux-test-project.readthedocs.io/en/latest/users/supported_systems.html#kernel-version
and whether it needs to have fallback in lapi and configure.ac? Also we may ask not to add .min_kver which would be too old.

Quoted 12 lines
configure.ac +0 -0
 AC_CHECK_MEMBERS([struct fanotify_event_info_fid.fsid.__val],,,[#include <sys/fanotify.h>])
 AC_CHECK_MEMBERS([struct perf_event_mmap_page.aux_head],,,[#include <linux/perf_event.h>])
 AC_CHECK_MEMBERS([struct sigaction.sa_sigaction],[],[],[#include <signal.h>])
include/lapi/aio_abi.h new file +3 -0
new file mode 100644
index 000000000..ac78e5500
@@ -0,0 +1,44 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2025 Wei Gao <[email protected]>

include/lapi/aio_abi.h line 13

Quoted 10 lines
include/lapi/aio_abi.h new file +10 -0
+ */
+
+#ifndef LAPI_AIO_ABI_H__
+#define LAPI_AIO_ABI_H__
+
+#include <endian.h>
+#include <linux/aio_abi.h>
+
+#ifndef RWF_NOWAIT
+# define RWF_NOWAIT 0x00000008

And this as well.
b745fafaf70c0 ("fs: Introduce RWF_NOWAIT and FMODE_AIO_NOWAIT")

Quoted 31 lines
include/lapi/aio_abi.h new file +31 -0
+#endif
+
+struct iocb_fallback {
+	uint64_t aio_data;
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+	uint32_t   aio_key;
+	uint32_t aio_rw_flags;
+#elif __BYTE_ORDER == __BIG_ENDIAN
+	uint32_t aio_rw_flags;
+	uint32_t   aio_key;
+#else
+#error edit for your odd byteorder.
+#endif
+	uint16_t   aio_lio_opcode;
+	int16_t   aio_reqprio;
+	uint32_t   aio_fildes;
+	uint64_t   aio_buf;
+	uint64_t   aio_nbytes;
+	int64_t   aio_offset;
+	uint64_t   aio_reserved2;
+	uint32_t   aio_flags;
+	uint32_t   aio_resfd;
+};
+
+#ifndef HAVE_STRUCT_IOCB_AIO_RW_FLAGS
+typedef struct iocb_fallback iocb;
+#else
+typedef struct iocb iocb;
+#endif
+
+#endif /* LAPI_AIO_ABI_H__ */

...

include/lapi/aio_abi.h line 9

Quoted 11 lines

+++ b/testcases/kernel/syscalls/io_submit/io_submit04.c

include/lapi/aio_abi.h new file +9 -0
@@ -0,0 +1,99 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2025 Wei Gao <[email protected]>
+ */
+
+/*\
+ * Test RWF_NOWAIT support in io_submit(), verifying that an
+ * asynchronous read operation on a blocking resource (empty pipe)
+ * will cause -EAGAIN. This is done by checking that io_getevents()

Please :manpage:io_getevents(2)
(to have link to https://man7.org/linux/man-pages/man2/io_getevents.2.html in docs).

@Andrea: ^ to agents?

Quoted 15 lines

include/lapi/aio_abi.h line 20

Quoted 11 lines
include/lapi/aio_abi.h new file +11 -0
+ * syscall returns immediately and io_event.res is equal to -EAGAIN.
+ */
+
+#include "config.h"
+#include "tst_test.h"
+#include "lapi/syscalls.h"
+#include "lapi/aio_abi.h"
+
+#define BUF_SIZE 100
+
+static int fd[2] = {-1, -1};

nit: Andrea (I guess you asked for it), because we hardly close STDOUT in the test 0 is always used. I see it a bit overkill using -1 (using 0 as the default would almost always work).

Though is nit, i need final decision, @Petr @Andrea

Quoted 57 lines
Quoted 23 lines
include/lapi/aio_abi.h new file +23 -0
+static aio_context_t ctx;
+static char *buf;
+static iocb *cb;
+static iocb **iocbs;
+
+static void setup(void)
+{
+	if (tst_syscall(__NR_io_setup, 1, &ctx))
+		tst_brk(TBROK | TERRNO, "io_setup failed");
+
+	SAFE_PIPE(fd);
+
+	cb->aio_fildes = fd[0];
+	cb->aio_lio_opcode = IOCB_CMD_PREAD;
+	cb->aio_buf = (uint64_t)buf;
+	cb->aio_offset = 0;
+	cb->aio_nbytes = BUF_SIZE;
+	cb->aio_rw_flags = RWF_NOWAIT;
+
+	iocbs[0] = cb;
+}
+
+static void cleanup(void)

include/lapi/aio_abi.h line 53

Quoted 10 lines
include/lapi/aio_abi.h new file +10 -0
+{
+	if (fd[0] != -1)
+		SAFE_CLOSE(fd[0]);
+
+	if (fd[1] != -1)
+		SAFE_CLOSE(fd[1]);
+
+	if (ctx)
+		if (tst_syscall(__NR_io_destroy, ctx))
+			tst_brk(TBROK | TERRNO, "io_destroy() failed");

Upper if would require { } brackets, but let's simplify:

	if (ctx && tst_syscall(__NR_io_destroy, ctx))
		tst_brk(TBROK | TERRNO, "io_destroy() failed");
Quoted 6 lines
include/lapi/aio_abi.h new file +6 -0
+}
+
+static void run(void)
+{
+	struct io_event evbuf;
+	struct timespec timeout = { .tv_sec = 1 };

include/lapi/aio_abi.h line 69

Quoted 10 lines
include/lapi/aio_abi.h new file +10 -0
+	long nr = 1;
+
+	TEST(tst_syscall(__NR_io_submit, ctx, nr, iocbs));
+
+	if (TST_RET == -1 && TST_ERR == EOPNOTSUPP) {
+		tst_brk(TCONF, "RWF_NOWAIT not supported by kernel");
+	} else if (TST_RET != nr) {
+		tst_brk(TBROK | TTERRNO, "io_submit() returns %ld, expected %ld",
+				TST_RET, nr);
+	}

Maybe move this to setup()?

Quoted 10 lines

include/lapi/aio_abi.h line 78

Quoted 9 lines
include/lapi/aio_abi.h new file +9 -0
+
+	TEST(tst_syscall(__NR_io_getevents, ctx, 1, 1, &evbuf, &timeout));
+
+	if (TST_RET != 1) {
+		tst_res(TFAIL | TTERRNO, "io_getevents() failed to get 1 event");
+		return;
+	}
+
+	if (evbuf.res == -EAGAIN)

Did you please check this on 32bit?

Test on 32bit compat mode show error, this need further invetigation why

root@wintermute:~/ltp32/testcases/kernel/syscalls/io_submit# ./io_submit04
tst_buffers.c:57: TINFO: Test is using guarded buffers
tst_test.c:2025: TINFO: LTP version: 20250130-546-g13dbd838c
tst_test.c:2028: TINFO: Tested kernel: 7.0.0-rc2-g5ee8dbf54602 #32 SMP PREEMPT_DYNAMIC Tue Mar 24 17:42:54 CST 2026 x86_64
tst_kconfig.c:71: TINFO: Couldn't locate kernel config!
tst_test.c:1846: TINFO: Overall timeout per run is 0h 00m 30s
io_submit04.c:67: TBROK: io_submit() returns -1, expected 1: EFAULT (14)
Quoted 28 lines

include/lapi/aio_abi.h line 83

Quoted 6 lines
include/lapi/aio_abi.h new file +5 -0
+		tst_res(TPASS, "io_getevents() returned EAGAIN on read event");
+	else
+		tst_res(TFAIL, "io_getevents() returned with %s instead of EAGAIN",
+			strerror(-evbuf.res));
+}

The rest LGTM.

Kind regards,
Petr

Quoted 16 lines
include/lapi/aio_abi.h new file +16 -0
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_kconfigs = (const char *[]) {
+		"CONFIG_AIO=y",
+		NULL
+	},
+	.bufs = (struct tst_buffers []) {
+		{&buf, .size = BUF_SIZE},
+		{&cb, .size = sizeof(iocb)},
+		{&iocbs, .size = sizeof(iocb *)},
+		{},
+	}
+};
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#19 lore raw
In reply to Petr Vorel
Quoted 15 lines · Petr Vorel

Hi Wei, all,

testcases/kernel/syscalls/io_submit/io_submit04.c line 69

Quoted 11 lines
testcases/kernel/syscalls/io_submit/io_submit04.c new file +11 -0
+	struct timespec timeout = { .tv_sec = 1 };
+	long nr = 1;
+
+	TEST(tst_syscall(__NR_io_submit, ctx, nr, iocbs));
+
+	if (TST_RET == -1 && TST_ERR == EOPNOTSUPP) {
+		tst_brk(TCONF, "RWF_NOWAIT not supported by kernel");
+	} else if (TST_RET != nr) {
+		tst_brk(TBROK | TTERRNO, "io_submit() returns %ld, expected %ld",
+				TST_RET, nr);
+	}

Maybe move this to setup()?

Moving io_submit() to setup() breaks multi-iteration testing. Since io_getevents() reaps the request, we should call io_submit() inside the run() loop to re-queue the operation for the next pass.

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

PATCH v7 1/1 fanotify22.c: handle multiple asynchronous error events

In reply to Wei Gao via ltp

Since the introduction of the asynchronous fserror reporting framework (kernel commit 81d2e13a57c9), fanotify22 has encountered sporadic failures due to the non-deterministic nature of event delivery and merging:

1) tcase3 failure: A race condition occurs when the test reads the notification fd between two events. Use a poll() and read() loop to wait until the expected event.

2) tcase4 failure: The kernel may deliver errors as independent events instead of a single merged event, since different worker kthread can end up generating each event so they won't be merged. As suggested by Jan Kara, this patch introduces a consolidate_events() helper. It iterates through the event buffer, accumulates the error_count from all independent events, and updates the first event's count in-place.

---
v6->v7:
- validation check to accept either error or error2 in check_error_event_info_error

 .../kernel/syscalls/fanotify/fanotify22.c     | 113 +++++++++++++++---
 1 file changed, 96 insertions(+), 17 deletions(-)
testcases/kernel/syscalls/fanotify/fanotify22.c +96 -17
index e8002b160..f5d59b99d 100644
@@ -28,6 +28,7 @@
 #include "tst_test.h"
 #include <sys/fanotify.h>
 #include <sys/types.h>
+#include <poll.h>
 
 #ifdef HAVE_SYS_FANOTIFY_H
 #include "fanotify.h"
@@ -88,7 +89,6 @@ static void trigger_bad_link_lookup(void)
 			ret, BAD_LINK, errno, EUCLEAN);
 }
 
-
 static void tcase3_trigger(void)
 {
 	trigger_bad_link_lookup();
@@ -104,6 +104,7 @@ static void tcase4_trigger(void)
 static struct test_case {
 	char *name;
 	int error;
+	int error2;
 	unsigned int error_count;
 	struct fanotify_fid_t *fid;
 	void (*trigger_error)(void);
@@ -134,37 +135,79 @@ static struct test_case {
 		.trigger_error = &tcase4_trigger,
 		.error_count = 2,
 		.error = EFSCORRUPTED,
+		.error2 = ESHUTDOWN,
 		.fid = &bad_file_fid,
 	}
 };
 
+static size_t consolidate_events(char *buf, size_t len, const struct test_case *ex)
+{
+	struct fanotify_event_metadata *metadata, *first = NULL;
+	struct fanotify_event_info_error *first_info = NULL;
+	unsigned int total_count = 0;
+	int event_num = 0;
+
+	for (metadata = (struct fanotify_event_metadata *)buf;
+			FAN_EVENT_OK(metadata, len);
+			metadata = FAN_EVENT_NEXT(metadata, len)) {
+
+		event_num++;
+		struct fanotify_event_info_error *info = get_event_info_error(metadata);
+
+		if (!info) {
+			tst_res(TFAIL, "Event [%d] missing error info", event_num);
+			continue;
+		}
+
+		if (info->error != ex->error && (ex->error2 == 0 || info->error != ex->error2)) {
+			tst_res(TFAIL, "Event [%d] unexpected errno (%d)",
+					event_num, info->error);
+			continue;
+		}
+
+		if (!first) {
+			first = metadata;
+			first_info = info;
+		}
+		total_count += info->error_count;
+
+		tst_res(TINFO, "Event [%d]: errno=%d, error_count=%d",
+				event_num, info->error, info->error_count);
+	}
+
+	if (first_info)
+		first_info->error_count = total_count;
+
+	return (first) ? first->event_len : 0;
+}
+
 static int check_error_event_info_fid(struct fanotify_event_info_fid *fid,
 				 const struct test_case *ex)
 {
 	struct file_handle *fh = (struct file_handle *) &fid->handle;
 
 	if (memcmp(&fid->fsid, &ex->fid->fsid, sizeof(fid->fsid))) {
-		tst_res(TFAIL, "%s: Received bad FSID type (%x...!=%x...)",
-			ex->name, FSID_VAL_MEMBER(fid->fsid, 0),
+		tst_res(TFAIL, "Received bad FSID type (%x...!=%x...)",
+			FSID_VAL_MEMBER(fid->fsid, 0),
 			ex->fid->fsid.val[0]);
 
 		return 1;
 	}
 	if (fh->handle_type != ex->fid->handle.handle_type) {
-		tst_res(TFAIL, "%s: Received bad file_handle type (%d!=%d)",
-			ex->name, fh->handle_type, ex->fid->handle.handle_type);
+		tst_res(TFAIL, "Received bad file_handle type (%d!=%d)",
+			fh->handle_type, ex->fid->handle.handle_type);
 		return 1;
 	}
 
 	if (fh->handle_bytes != ex->fid->handle.handle_bytes) {
-		tst_res(TFAIL, "%s: Received bad file_handle len (%d!=%d)",
-			ex->name, fh->handle_bytes, ex->fid->handle.handle_bytes);
+		tst_res(TFAIL, "Received bad file_handle len (%d!=%d)",
+			fh->handle_bytes, ex->fid->handle.handle_bytes);
 		return 1;
 	}
 
 	if (memcmp(fh->f_handle, ex->fid->handle.f_handle, fh->handle_bytes)) {
-		tst_res(TFAIL, "%s: Received wrong handle. "
-			"Expected (%x...) got (%x...) ", ex->name,
+		tst_res(TFAIL, "Received wrong handle. "
+			"Expected (%x...) got (%x...) ",
 			*(int *)ex->fid->handle.f_handle, *(int *)fh->f_handle);
 		return 1;
 	}
@@ -177,14 +220,15 @@ static int check_error_event_info_error(struct fanotify_event_info_error *info_e
 	int fail = 0;
 
 	if (info_error->error_count != ex->error_count) {
-		tst_res(TFAIL, "%s: Unexpected error_count (%d!=%d)",
-			ex->name, info_error->error_count, ex->error_count);
+		tst_res(TFAIL, "Unexpected error_count (%d!=%d)",
+			info_error->error_count, ex->error_count);
 		fail++;
 	}
 
-	if (info_error->error != ex->error) {
-		tst_res(TFAIL, "%s: Unexpected error code value (%d!=%d)",
-			ex->name, info_error->error, ex->error);
+	if (info_error->error != ex->error &&
+	    (ex->error2 == 0 || info_error->error != ex->error2)) {
+		tst_res(TFAIL, "Unexpected error code value (%d!=%d)",
+			info_error->error, ex->error);
 		fail++;
 	}
 
@@ -248,19 +292,54 @@ static void check_event(char *buf, size_t len, const struct test_case *ex)
 static void do_test(unsigned int i)
 {
 	const struct test_case *tcase = &testcases[i];
-	size_t read_len;
+	size_t read_len = 0;
+	struct pollfd pfd;
+	unsigned int accumulated_count = 0;
+
+	tst_res(TINFO, "Test case: %s", tcase->name);
 
 	SAFE_FANOTIFY_MARK(fd_notify, FAN_MARK_ADD|FAN_MARK_FILESYSTEM,
 			   FAN_FS_ERROR, AT_FDCWD, MOUNT_PATH);
 
 	tcase->trigger_error();
 
-	read_len = SAFE_READ(0, fd_notify, event_buf, BUF_SIZE);
+	pfd.fd = fd_notify;
+	pfd.events = POLLIN;
+
+	while (accumulated_count < tcase->error_count) {
+		if (poll(&pfd, 1, 5000) <= 0) {
+			tst_res(TFAIL, "Timeout waiting for events");
+			goto out;
+		}
+
+		if (BUF_SIZE - read_len < FAN_EVENT_METADATA_LEN)
+			tst_brk(TBROK, "Insufficient buffer space for next event");
+
+		char *current_pos = event_buf + read_len;
+		ssize_t ret = SAFE_READ(0, fd_notify, current_pos, BUF_SIZE - read_len);
+
+		struct fanotify_event_metadata *m =
+			(struct fanotify_event_metadata *)current_pos;
+		while (FAN_EVENT_OK(m, ret)) {
+			struct fanotify_event_info_error *e = get_event_info_error(m);
+
+			if (e)
+				accumulated_count += e->error_count;
+
+			read_len += m->event_len;
+			m = FAN_EVENT_NEXT(m, ret);
+		}
+	}
+
+	read_len = consolidate_events(event_buf, read_len, tcase);
+
+	check_event(event_buf, read_len, tcase);
+
+out:
 
 	SAFE_FANOTIFY_MARK(fd_notify, FAN_MARK_REMOVE|FAN_MARK_FILESYSTEM,
 			   FAN_FS_ERROR, AT_FDCWD, MOUNT_PATH);
 
-	check_event(event_buf, read_len, tcase);
 	/* Unmount and mount the filesystem to get it out of the error state */
 	SAFE_UMOUNT(MOUNT_PATH);
 	SAFE_MOUNT(tst_device->dev, MOUNT_PATH, tst_device->fs_type, 0, NULL);
Signature · 5 lines
2.52.0


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

Re: [LTP] fanotify22.c: handle multiple asynchronous error events

Hi Wei,

Quoted 5 lines · Wei Gao

fanotify22.c: handle multiple asynchronous error events

This fixes a known sporadic failure; please add a Fixes: tag referencing the LTP commit that introduced fanotify22.

testcases/kernel/syscalls/fanotify/fanotify22.c static struct test_case { · line 155

Quoted 6 lines
testcases/kernel/syscalls/fanotify/fanotify22.c +6 -0
+	for (metadata = (struct fanotify_event_metadata *)buf;
+			FAN_EVENT_OK(metadata, len);
+			metadata = FAN_EVENT_NEXT(metadata, len)) {
+
+		event_num++;
+		struct fanotify_event_info_error *info = get_event_info_error(metadata);

Declaration after statement. Move info to the top of the for-loop block. Same issue with current_pos, ret, and m inside the while loop in do_test(). Kernel coding style requires declarations at the top of each block.

testcases/kernel/syscalls/fanotify/fanotify22.c static struct test_case { · line 171

Quoted 9 lines
testcases/kernel/syscalls/fanotify/fanotify22.c +9 -0
+		if (info->error != ex->error && (ex->error2 == 0 || info->error != ex->error2)) {
+			...
+			continue;
+		}
+
+		if (!first) {
+			first = metadata;
+			first_info = info;
+		}

Logic bug: first is set to the first valid event in buffer order, which may be the error2 (ESHUTDOWN) event with null_fid. check_event() then validates that event's FID against ex->fid (bad_file_fid) and fails. Set first only when info->error == ex->error so the event with the expected FID is always selected.

---
Note:

Our agent completed the review of the patch.

The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.

Regards,
LTP AI Reviewer

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

Re: [LTP] fanotify22.c: handle multiple asynchronous error events

Quoted 11 lines · On Wed, Apr 29, 2026 at 02:51:32PM +0000, [email protected]…

Hi Wei,

Quoted 5 lines · Wei Gao

fanotify22.c: handle multiple asynchronous error events

This fixes a known sporadic failure; please add a Fixes: tag referencing the LTP commit that introduced fanotify22.

LTP test was technically correct for the kernel behavior at the time it was written, so no need add Fixes tag.

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

PATCH v8 1/1 fanotify22.c: handle multiple asynchronous error events

In reply to Wei Gao via ltp

Since the introduction of the asynchronous fserror reporting framework (kernel commit 81d2e13a57c9), fanotify22 has encountered sporadic failures due to the non-deterministic nature of event delivery and merging:

1) tcase3 failure: A race condition occurs when the test reads the notification fd between two events. Use a poll() and read() loop to wait until the expected events are delivered.

2) tcase4 failure: The kernel may deliver errors as independent events instead of a single merged event, as different worker kthreads can end up generating each event. As suggested by Jan Kara, this patch introduces a consolidate_events() helper. It iterates through the event buffer, identifies the primary event matching the expected error, accumulates the error_count from all independent events, and updates the primary event's count in-place for validation.

---
v7->v8:
- Fix a logic bug where the test would fail if a secondary error (like ESHUTDOWN) was the first event in the buffer
- Move variable declarations to the top of blocks to follow the preferred LTP coding style

 .../kernel/syscalls/fanotify/fanotify22.c     | 119 +++++++++++++++---
 1 file changed, 102 insertions(+), 17 deletions(-)
testcases/kernel/syscalls/fanotify/fanotify22.c +102 -17
index e8002b160..c124e1904 100644
@@ -28,6 +28,7 @@
 #include "tst_test.h"
 #include <sys/fanotify.h>
 #include <sys/types.h>
+#include <poll.h>
 
 #ifdef HAVE_SYS_FANOTIFY_H
 #include "fanotify.h"
@@ -88,7 +89,6 @@ static void trigger_bad_link_lookup(void)
 			ret, BAD_LINK, errno, EUCLEAN);
 }
 
-
 static void tcase3_trigger(void)
 {
 	trigger_bad_link_lookup();
@@ -104,6 +104,7 @@ static void tcase4_trigger(void)
 static struct test_case {
 	char *name;
 	int error;
+	int error2;
 	unsigned int error_count;
 	struct fanotify_fid_t *fid;
 	void (*trigger_error)(void);
@@ -134,37 +135,79 @@ static struct test_case {
 		.trigger_error = &tcase4_trigger,
 		.error_count = 2,
 		.error = EFSCORRUPTED,
+		.error2 = ESHUTDOWN,
 		.fid = &bad_file_fid,
 	}
 };
 
+static struct fanotify_event_metadata *consolidate_events(char *buf, size_t len, const struct test_case *ex)
+{
+	struct fanotify_event_metadata *metadata, *primary = NULL;
+	struct fanotify_event_info_error *info, *primary_info = NULL;
+	unsigned int total_count = 0;
+	int event_num = 0;
+
+	for (metadata = (struct fanotify_event_metadata *)buf;
+			FAN_EVENT_OK(metadata, len);
+			metadata = FAN_EVENT_NEXT(metadata, len)) {
+
+		event_num++;
+		info = get_event_info_error(metadata);
+
+		if (!info) {
+			tst_res(TFAIL, "Event [%d] missing error info", event_num);
+			continue;
+		}
+
+		if (info->error != ex->error && (ex->error2 == 0 || info->error != ex->error2)) {
+			tst_res(TFAIL, "Event [%d] unexpected errno (%d)",
+					event_num, info->error);
+			continue;
+		}
+
+		if (!primary && info->error == ex->error) {
+			primary = metadata;
+			primary_info = info;
+		}
+		total_count += info->error_count;
+
+		tst_res(TINFO, "Event [%d]: errno=%d, error_count=%d",
+				event_num, info->error, info->error_count);
+	}
+
+	if (primary_info)
+		primary_info->error_count = total_count;
+
+	return primary;
+}
+
 static int check_error_event_info_fid(struct fanotify_event_info_fid *fid,
 				 const struct test_case *ex)
 {
 	struct file_handle *fh = (struct file_handle *) &fid->handle;
 
 	if (memcmp(&fid->fsid, &ex->fid->fsid, sizeof(fid->fsid))) {
-		tst_res(TFAIL, "%s: Received bad FSID type (%x...!=%x...)",
-			ex->name, FSID_VAL_MEMBER(fid->fsid, 0),
+		tst_res(TFAIL, "Received bad FSID type (%x...!=%x...)",
+			FSID_VAL_MEMBER(fid->fsid, 0),
 			ex->fid->fsid.val[0]);
 
 		return 1;
 	}
 	if (fh->handle_type != ex->fid->handle.handle_type) {
-		tst_res(TFAIL, "%s: Received bad file_handle type (%d!=%d)",
-			ex->name, fh->handle_type, ex->fid->handle.handle_type);
+		tst_res(TFAIL, "Received bad file_handle type (%d!=%d)",
+			fh->handle_type, ex->fid->handle.handle_type);
 		return 1;
 	}
 
 	if (fh->handle_bytes != ex->fid->handle.handle_bytes) {
-		tst_res(TFAIL, "%s: Received bad file_handle len (%d!=%d)",
-			ex->name, fh->handle_bytes, ex->fid->handle.handle_bytes);
+		tst_res(TFAIL, "Received bad file_handle len (%d!=%d)",
+			fh->handle_bytes, ex->fid->handle.handle_bytes);
 		return 1;
 	}
 
 	if (memcmp(fh->f_handle, ex->fid->handle.f_handle, fh->handle_bytes)) {
-		tst_res(TFAIL, "%s: Received wrong handle. "
-			"Expected (%x...) got (%x...) ", ex->name,
+		tst_res(TFAIL, "Received wrong handle. "
+			"Expected (%x...) got (%x...) ",
 			*(int *)ex->fid->handle.f_handle, *(int *)fh->f_handle);
 		return 1;
 	}
@@ -177,14 +220,15 @@ static int check_error_event_info_error(struct fanotify_event_info_error *info_e
 	int fail = 0;
 
 	if (info_error->error_count != ex->error_count) {
-		tst_res(TFAIL, "%s: Unexpected error_count (%d!=%d)",
-			ex->name, info_error->error_count, ex->error_count);
+		tst_res(TFAIL, "Unexpected error_count (%d!=%d)",
+			info_error->error_count, ex->error_count);
 		fail++;
 	}
 
-	if (info_error->error != ex->error) {
-		tst_res(TFAIL, "%s: Unexpected error code value (%d!=%d)",
-			ex->name, info_error->error, ex->error);
+	if (info_error->error != ex->error &&
+	    (ex->error2 == 0 || info_error->error != ex->error2)) {
+		tst_res(TFAIL, "Unexpected error code value (%d!=%d)",
+			info_error->error, ex->error);
 		fail++;
 	}
 
@@ -248,19 +292,60 @@ static void check_event(char *buf, size_t len, const struct test_case *ex)
 static void do_test(unsigned int i)
 {
 	const struct test_case *tcase = &testcases[i];
-	size_t read_len;
+	struct fanotify_event_metadata *m, *primary;
+	struct fanotify_event_info_error *e;
+	char *current_pos;
+	ssize_t ret;
+	size_t read_len = 0;
+	struct pollfd pfd;
+	unsigned int accumulated_count = 0;
+
+	tst_res(TINFO, "Test case: %s", tcase->name);
 
 	SAFE_FANOTIFY_MARK(fd_notify, FAN_MARK_ADD|FAN_MARK_FILESYSTEM,
 			   FAN_FS_ERROR, AT_FDCWD, MOUNT_PATH);
 
 	tcase->trigger_error();
 
-	read_len = SAFE_READ(0, fd_notify, event_buf, BUF_SIZE);
+	pfd.fd = fd_notify;
+	pfd.events = POLLIN;
+
+	while (accumulated_count < tcase->error_count) {
+		if (poll(&pfd, 1, 5000) <= 0) {
+			tst_res(TFAIL, "Timeout waiting for events");
+			goto out;
+		}
+
+		if (BUF_SIZE - read_len < FAN_EVENT_METADATA_LEN)
+			tst_brk(TBROK, "Insufficient buffer space for next event");
+
+		current_pos = event_buf + read_len;
+		ret = SAFE_READ(0, fd_notify, current_pos, BUF_SIZE - read_len);
+
+		m = (struct fanotify_event_metadata *)current_pos;
+		while (FAN_EVENT_OK(m, ret)) {
+			e = get_event_info_error(m);
+
+			if (e)
+				accumulated_count += e->error_count;
+
+			read_len += m->event_len;
+			m = FAN_EVENT_NEXT(m, ret);
+		}
+	}
+
+	primary = consolidate_events(event_buf, read_len, tcase);
+
+	if (primary)
+		check_event((char *)primary, primary->event_len, tcase);
+	else
+		tst_res(TFAIL, "No primary error event found");
+
+out:
 
 	SAFE_FANOTIFY_MARK(fd_notify, FAN_MARK_REMOVE|FAN_MARK_FILESYSTEM,
 			   FAN_FS_ERROR, AT_FDCWD, MOUNT_PATH);
 
-	check_event(event_buf, read_len, tcase);
 	/* Unmount and mount the filesystem to get it out of the error state */
 	SAFE_UMOUNT(MOUNT_PATH);
 	SAFE_MOUNT(tst_device->dev, MOUNT_PATH, tst_device->fs_type, 0, NULL);
Signature · 5 lines
2.52.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by LTP AI Reviewer on v8 1/1
#24 lore raw

Re: [LTP] fanotify22.c: handle multiple asynchronous error events

Hi Wei,

Quoted 1 line · Wei Gao

fanotify22.c: handle multiple asynchronous error events

Pre-existing issues noticed in the surrounding code (not introduced by this patch):

- fanotify22.c:do_test — poll() returning -1 (e.g. EINTR) is treated identically to a timeout, producing a misleading "Timeout waiting for events" TFAIL message.

---
Note:

Our agent completed the review of the patch.

The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.

Regards,
LTP AI Reviewer

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v8 1/1
#26 lore raw

Re: [LTP] [PATCH v8] fanotify22.c: handle multiple asynchronous error events

In reply to Wei Gao via ltp
Quoted 16 lines · Wei Gao

Since the introduction of the asynchronous fserror reporting framework (kernel commit 81d2e13a57c9), fanotify22 has encountered sporadic failures due to the non-deterministic nature of event delivery and merging:

1) tcase3 failure: A race condition occurs when the test reads the notification fd between two events. Use a poll() and read() loop to wait until the expected events are delivered.

2) tcase4 failure: The kernel may deliver errors as independent events instead of a single merged event, as different worker kthreads can end up generating each event. As suggested by Jan Kara, this patch introduces a consolidate_events() helper. It iterates through the event buffer, identifies the primary event matching the expected error, accumulates the error_count from all independent events, and updates the primary event's count in-place for validation.

Quoted 4 lines

Looks good to me. Feel free to add:

Honza

Quoted 211 lines

---
v7->v8:
- Fix a logic bug where the test would fail if a secondary error (like ESHUTDOWN) was the first event in the buffer
- Move variable declarations to the top of blocks to follow the preferred LTP coding style

 .../kernel/syscalls/fanotify/fanotify22.c     | 119 +++++++++++++++---
 1 file changed, 102 insertions(+), 17 deletions(-)
testcases/kernel/syscalls/fanotify/fanotify22.c +102 -17
index e8002b160..c124e1904 100644
@@ -28,6 +28,7 @@
 #include "tst_test.h"
 #include <sys/fanotify.h>
 #include <sys/types.h>
+#include <poll.h>
 
 #ifdef HAVE_SYS_FANOTIFY_H
 #include "fanotify.h"
@@ -88,7 +89,6 @@ static void trigger_bad_link_lookup(void)
 			ret, BAD_LINK, errno, EUCLEAN);
 }
 
-
 static void tcase3_trigger(void)
 {
 	trigger_bad_link_lookup();
@@ -104,6 +104,7 @@ static void tcase4_trigger(void)
 static struct test_case {
 	char *name;
 	int error;
+	int error2;
 	unsigned int error_count;
 	struct fanotify_fid_t *fid;
 	void (*trigger_error)(void);
@@ -134,37 +135,79 @@ static struct test_case {
 		.trigger_error = &tcase4_trigger,
 		.error_count = 2,
 		.error = EFSCORRUPTED,
+		.error2 = ESHUTDOWN,
 		.fid = &bad_file_fid,
 	}
 };
 
+static struct fanotify_event_metadata *consolidate_events(char *buf, size_t len, const struct test_case *ex)
+{
+	struct fanotify_event_metadata *metadata, *primary = NULL;
+	struct fanotify_event_info_error *info, *primary_info = NULL;
+	unsigned int total_count = 0;
+	int event_num = 0;
+
+	for (metadata = (struct fanotify_event_metadata *)buf;
+			FAN_EVENT_OK(metadata, len);
+			metadata = FAN_EVENT_NEXT(metadata, len)) {
+
+		event_num++;
+		info = get_event_info_error(metadata);
+
+		if (!info) {
+			tst_res(TFAIL, "Event [%d] missing error info", event_num);
+			continue;
+		}
+
+		if (info->error != ex->error && (ex->error2 == 0 || info->error != ex->error2)) {
+			tst_res(TFAIL, "Event [%d] unexpected errno (%d)",
+					event_num, info->error);
+			continue;
+		}
+
+		if (!primary && info->error == ex->error) {
+			primary = metadata;
+			primary_info = info;
+		}
+		total_count += info->error_count;
+
+		tst_res(TINFO, "Event [%d]: errno=%d, error_count=%d",
+				event_num, info->error, info->error_count);
+	}
+
+	if (primary_info)
+		primary_info->error_count = total_count;
+
+	return primary;
+}
+
 static int check_error_event_info_fid(struct fanotify_event_info_fid *fid,
 				 const struct test_case *ex)
 {
 	struct file_handle *fh = (struct file_handle *) &fid->handle;
 
 	if (memcmp(&fid->fsid, &ex->fid->fsid, sizeof(fid->fsid))) {
-		tst_res(TFAIL, "%s: Received bad FSID type (%x...!=%x...)",
-			ex->name, FSID_VAL_MEMBER(fid->fsid, 0),
+		tst_res(TFAIL, "Received bad FSID type (%x...!=%x...)",
+			FSID_VAL_MEMBER(fid->fsid, 0),
 			ex->fid->fsid.val[0]);
 
 		return 1;
 	}
 	if (fh->handle_type != ex->fid->handle.handle_type) {
-		tst_res(TFAIL, "%s: Received bad file_handle type (%d!=%d)",
-			ex->name, fh->handle_type, ex->fid->handle.handle_type);
+		tst_res(TFAIL, "Received bad file_handle type (%d!=%d)",
+			fh->handle_type, ex->fid->handle.handle_type);
 		return 1;
 	}
 
 	if (fh->handle_bytes != ex->fid->handle.handle_bytes) {
-		tst_res(TFAIL, "%s: Received bad file_handle len (%d!=%d)",
-			ex->name, fh->handle_bytes, ex->fid->handle.handle_bytes);
+		tst_res(TFAIL, "Received bad file_handle len (%d!=%d)",
+			fh->handle_bytes, ex->fid->handle.handle_bytes);
 		return 1;
 	}
 
 	if (memcmp(fh->f_handle, ex->fid->handle.f_handle, fh->handle_bytes)) {
-		tst_res(TFAIL, "%s: Received wrong handle. "
-			"Expected (%x...) got (%x...) ", ex->name,
+		tst_res(TFAIL, "Received wrong handle. "
+			"Expected (%x...) got (%x...) ",
 			*(int *)ex->fid->handle.f_handle, *(int *)fh->f_handle);
 		return 1;
 	}
@@ -177,14 +220,15 @@ static int check_error_event_info_error(struct fanotify_event_info_error *info_e
 	int fail = 0;
 
 	if (info_error->error_count != ex->error_count) {
-		tst_res(TFAIL, "%s: Unexpected error_count (%d!=%d)",
-			ex->name, info_error->error_count, ex->error_count);
+		tst_res(TFAIL, "Unexpected error_count (%d!=%d)",
+			info_error->error_count, ex->error_count);
 		fail++;
 	}
 
-	if (info_error->error != ex->error) {
-		tst_res(TFAIL, "%s: Unexpected error code value (%d!=%d)",
-			ex->name, info_error->error, ex->error);
+	if (info_error->error != ex->error &&
+	    (ex->error2 == 0 || info_error->error != ex->error2)) {
+		tst_res(TFAIL, "Unexpected error code value (%d!=%d)",
+			info_error->error, ex->error);
 		fail++;
 	}
 
@@ -248,19 +292,60 @@ static void check_event(char *buf, size_t len, const struct test_case *ex)
 static void do_test(unsigned int i)
 {
 	const struct test_case *tcase = &testcases[i];
-	size_t read_len;
+	struct fanotify_event_metadata *m, *primary;
+	struct fanotify_event_info_error *e;
+	char *current_pos;
+	ssize_t ret;
+	size_t read_len = 0;
+	struct pollfd pfd;
+	unsigned int accumulated_count = 0;
+
+	tst_res(TINFO, "Test case: %s", tcase->name);
 
 	SAFE_FANOTIFY_MARK(fd_notify, FAN_MARK_ADD|FAN_MARK_FILESYSTEM,
 			   FAN_FS_ERROR, AT_FDCWD, MOUNT_PATH);
 
 	tcase->trigger_error();
 
-	read_len = SAFE_READ(0, fd_notify, event_buf, BUF_SIZE);
+	pfd.fd = fd_notify;
+	pfd.events = POLLIN;
+
+	while (accumulated_count < tcase->error_count) {
+		if (poll(&pfd, 1, 5000) <= 0) {
+			tst_res(TFAIL, "Timeout waiting for events");
+			goto out;
+		}
+
+		if (BUF_SIZE - read_len < FAN_EVENT_METADATA_LEN)
+			tst_brk(TBROK, "Insufficient buffer space for next event");
+
+		current_pos = event_buf + read_len;
+		ret = SAFE_READ(0, fd_notify, current_pos, BUF_SIZE - read_len);
+
+		m = (struct fanotify_event_metadata *)current_pos;
+		while (FAN_EVENT_OK(m, ret)) {
+			e = get_event_info_error(m);
+
+			if (e)
+				accumulated_count += e->error_count;
+
+			read_len += m->event_len;
+			m = FAN_EVENT_NEXT(m, ret);
+		}
+	}
+
+	primary = consolidate_events(event_buf, read_len, tcase);
+
+	if (primary)
+		check_event((char *)primary, primary->event_len, tcase);
+	else
+		tst_res(TFAIL, "No primary error event found");
+
+out:
 
 	SAFE_FANOTIFY_MARK(fd_notify, FAN_MARK_REMOVE|FAN_MARK_FILESYSTEM,
 			   FAN_FS_ERROR, AT_FDCWD, MOUNT_PATH);
 
-	check_event(event_buf, read_len, tcase);
 	/* Unmount and mount the filesystem to get it out of the error state */
 	SAFE_UMOUNT(MOUNT_PATH);
 	SAFE_MOUNT(tst_device->dev, MOUNT_PATH, tst_device->fs_type, 0, NULL);
Signature · 1 line
2.52.0
Signature · 5 lines
Jan Kara <[email protected]>
SUSE Labs, CR

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

Re: [LTP] [PATCH v8] fanotify22.c: handle multiple asynchronous error events

In reply to Wei Gao via ltp

Hi all,

...

testcases/kernel/syscalls/fanotify/fanotify22.c static struct test_case { · line 192

Quoted 6 lines
testcases/kernel/syscalls/fanotify/fanotify22.c +2 -2
 	if (memcmp(&fid->fsid, &ex->fid->fsid, sizeof(fid->fsid))) {
-		tst_res(TFAIL, "%s: Received bad FSID type (%x...!=%x...)",
-			ex->name, FSID_VAL_MEMBER(fid->fsid, 0),
+		tst_res(TFAIL, "Received bad FSID type (%x...!=%x...)",
+			FSID_VAL_MEMBER(fid->fsid, 0),
 			ex->fid->fsid.val[0]);

I dared to factor out this unrelated change to a separated commit and merge the patchset.

Removing ex->name which is ~ 50% of changes is completely unrelated. When Andrea suggested it [1] it was for a new additions. Although this this change is not a complicated, fanotify tests are quite complex, that's why it's better to separate non-related change.

Thanks Jan for helping with the review.

Kind regards,
Petr

[1] https://lore.kernel.org/ltp/[email protected]/

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

PATCH v7 1/1 io_submit04: Add test case for RWF_NOWAIT flag

In reply to Wei Gao via ltp
Fixes #467

---
v6->v7:
- Fix 32bit issue, use TST_PTR_TO_UINT convert buf
- Updated the comment header to use the :manpage:
- Simplify logic in cleanup()

 configure.ac                                  |  1 +
 include/lapi/aio_abi.h                        | 44 +++++++++
 runtest/syscalls                              |  1 +
 .../kernel/syscalls/io_submit/.gitignore      |  1 +
 .../kernel/syscalls/io_submit/io_submit04.c   | 99 +++++++++++++++++++
 5 files changed, 146 insertions(+)
 create mode 100644 include/lapi/aio_abi.h
 create mode 100644 testcases/kernel/syscalls/io_submit/io_submit04.c
configure.ac +1 -0
index e5d3ce063..812f17d8b 100644
@@ -173,6 +173,7 @@ AC_CHECK_FUNCS_ONCE([ \
 ])
 AC_CHECK_FUNCS(mkdtemp,[],AC_MSG_ERROR(mkdtemp() not found!))
 
+AC_CHECK_MEMBERS([struct iocb.aio_rw_flags],,,[#include <linux/aio_abi.h>])
 AC_CHECK_MEMBERS([struct fanotify_event_info_fid.fsid.__val],,,[#include <sys/fanotify.h>])
 AC_CHECK_MEMBERS([struct perf_event_mmap_page.aux_head],,,[#include <linux/perf_event.h>])
 AC_CHECK_MEMBERS([struct sigaction.sa_sigaction],[],[],[#include <signal.h>])
include/lapi/aio_abi.h new file +44 -0

44 lines not on this page · raw message

runtest/syscalls +1 -0
index 6ba0227a8..d72fceb5e 100644
@@ -699,6 +699,7 @@ io_setup02 io_setup02
 io_submit01 io_submit01
 io_submit02 io_submit02
 io_submit03 io_submit03
+io_submit04 io_submit04
 
 keyctl01 keyctl01
 keyctl02 keyctl02
testcases/kernel/syscalls/io_submit/.gitignore +1 -0
index 60b07970a..abe962e1c 100644
@@ -1,3 +1,4 @@
 /io_submit01
 /io_submit02
 /io_submit03
+/io_submit04
testcases/kernel/syscalls/io_submit/io_submit04.c new file +99 -0

99 lines not on this page · raw message

Signature · 5 lines
2.52.0


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

Hi!

Quoted 23 lines
testcases/kernel/syscalls/io_submit/io_submit04.c new file +20 -0
@@ -0,0 +1,99 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2025 Wei Gao <[email protected]>
+ */
+
+/*\
+ * Test RWF_NOWAIT support in io_submit(), verifying that an
+ * asynchronous read operation on a blocking resource (empty pipe)
+ * will cause -EAGAIN. This is done by checking that io_getevents()
+ * :manpage:`io_getevents(2)` syscall returns immediately and
+ * io_event.res is equal to -EAGAIN.
+ */
+
+#include "config.h"
+#include "tst_test.h"
+#include "lapi/syscalls.h"
+#include "lapi/aio_abi.h"
+
+#define BUF_SIZE 100
+

testcases/kernel/syscalls/io_submit/io_submit04.c line 30

Quoted 10 lines
testcases/kernel/syscalls/io_submit/io_submit04.c new file +10 -0
+static int fd[2] = {-1, -1};
+static aio_context_t ctx;
+static char *buf;
+static iocb *cb;
+static iocb **iocbs;
+
+static void setup(void)
+{
+	if (tst_syscall(__NR_io_setup, 1, &ctx))
+		tst_brk(TBROK | TERRNO, "io_setup failed");

Sorry if that was asked in previous reviews. Why are we using tst_syscall() instead of the libaio functions like we do in the rest of the tests?

Quoted 41 lines
testcases/kernel/syscalls/io_submit/io_submit04.c new file +41 -0
+	SAFE_PIPE(fd);
+
+	cb->aio_fildes = fd[0];
+	cb->aio_lio_opcode = IOCB_CMD_PREAD;
+	cb->aio_buf = TST_PTR_TO_UINT(buf);
+	cb->aio_offset = 0;
+	cb->aio_nbytes = BUF_SIZE;
+	cb->aio_rw_flags = RWF_NOWAIT;
+
+	iocbs[0] = cb;
+}
+
+static void cleanup(void)
+{
+	if (fd[0] != -1)
+		SAFE_CLOSE(fd[0]);
+
+	if (fd[1] != -1)
+		SAFE_CLOSE(fd[1]);
+
+	if (ctx && tst_syscall(__NR_io_destroy, ctx))
+		tst_brk(TBROK | TERRNO, "io_destroy() failed");
+}
+
+static void run(void)
+{
+	struct io_event evbuf;
+	struct timespec timeout = { .tv_sec = 1 };
+	long nr = 1;
+
+	TEST(tst_syscall(__NR_io_submit, ctx, nr, iocbs));
+
+	if (TST_RET == -1 && TST_ERR == EOPNOTSUPP) {
+		tst_brk(TCONF, "RWF_NOWAIT not supported by kernel");
+	} else if (TST_RET != nr) {
+		tst_brk(TBROK | TTERRNO, "io_submit() returns %ld, expected %ld",
+				TST_RET, nr);
+	}
+
+	TEST(tst_syscall(__NR_io_getevents, ctx, 1, 1, &evbuf, &timeout));
+

testcases/kernel/syscalls/io_submit/io_submit04.c line 82

Quoted 10 lines
testcases/kernel/syscalls/io_submit/io_submit04.c new file +10 -0
+	if (TST_RET != 1) {
+		tst_res(TFAIL | TTERRNO, "io_getevents() failed to get 1 event");
+		return;
+	}
+
+	if (evbuf.res == -EAGAIN)
+		tst_res(TPASS, "io_getevents() returned EAGAIN on read event");
+	else
+		tst_res(TFAIL, "io_getevents() returned with %s instead of EAGAIN",
+			strerror(-evbuf.res));
                            ^
			    tst_strerrno()

Other than these two minor issues I do not see any problems in the code, the rest looks fine.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#30 lore raw
Quoted 30 lines · Cyril Hrubis

Hi!

Quoted 29 lines
testcases/kernel/syscalls/io_submit/io_submit04.c new file +26 -0
@@ -0,0 +1,99 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2025 Wei Gao <[email protected]>
+ */
+
+/*\
+ * Test RWF_NOWAIT support in io_submit(), verifying that an
+ * asynchronous read operation on a blocking resource (empty pipe)
+ * will cause -EAGAIN. This is done by checking that io_getevents()
+ * :manpage:`io_getevents(2)` syscall returns immediately and
+ * io_event.res is equal to -EAGAIN.
+ */
+
+#include "config.h"
+#include "tst_test.h"
+#include "lapi/syscalls.h"
+#include "lapi/aio_abi.h"
+
+#define BUF_SIZE 100
+
+static int fd[2] = {-1, -1};
+static aio_context_t ctx;
+static char *buf;
+static iocb *cb;
+static iocb **iocbs;
+
Quoted 8 lines

testcases/kernel/syscalls/io_submit/io_submit04.c line 30

Quoted 4 lines
testcases/kernel/syscalls/io_submit/io_submit04.c new file +4 -0
+static void setup(void)
+{
+	if (tst_syscall(__NR_io_setup, 1, &ctx))
+		tst_brk(TBROK | TERRNO, "io_setup failed");

Sorry if that was asked in previous reviews. Why are we using tst_syscall() instead of the libaio functions like we do in the rest of the tests?

No one asked in previous reviews.

For io_submit0* test group, ONLY io_submit01.c use libaio function, io_submit02.c and io_submit03.c use tst_syscall. I guess io_submit01.c is explicitly designed to test the libaio library wrapper. Its documentation states:
"Test io_submit() invoked via libaio".

I prefer io_submit04.c use tst_syscall instead of libaio since no dependency with libaio-devel and makes the test more portable.

If you are agree then i will send next patch with s/strerror/tst_strerrno fix. Thanks.

Quoted 61 lines
Quoted 42 lines
testcases/kernel/syscalls/io_submit/io_submit04.c new file +41 -0
+	SAFE_PIPE(fd);
+
+	cb->aio_fildes = fd[0];
+	cb->aio_lio_opcode = IOCB_CMD_PREAD;
+	cb->aio_buf = TST_PTR_TO_UINT(buf);
+	cb->aio_offset = 0;
+	cb->aio_nbytes = BUF_SIZE;
+	cb->aio_rw_flags = RWF_NOWAIT;
+
+	iocbs[0] = cb;
+}
+
+static void cleanup(void)
+{
+	if (fd[0] != -1)
+		SAFE_CLOSE(fd[0]);
+
+	if (fd[1] != -1)
+		SAFE_CLOSE(fd[1]);
+
+	if (ctx && tst_syscall(__NR_io_destroy, ctx))
+		tst_brk(TBROK | TERRNO, "io_destroy() failed");
+}
+
+static void run(void)
+{
+	struct io_event evbuf;
+	struct timespec timeout = { .tv_sec = 1 };
+	long nr = 1;
+
+	TEST(tst_syscall(__NR_io_submit, ctx, nr, iocbs));
+
+	if (TST_RET == -1 && TST_ERR == EOPNOTSUPP) {
+		tst_brk(TCONF, "RWF_NOWAIT not supported by kernel");
+	} else if (TST_RET != nr) {
+		tst_brk(TBROK | TTERRNO, "io_submit() returns %ld, expected %ld",
+				TST_RET, nr);
+	}
+
+	TEST(tst_syscall(__NR_io_getevents, ctx, 1, 1, &evbuf, &timeout));
+

testcases/kernel/syscalls/io_submit/io_submit04.c line 82

Quoted 10 lines
testcases/kernel/syscalls/io_submit/io_submit04.c new file +10 -0
+	if (TST_RET != 1) {
+		tst_res(TFAIL | TTERRNO, "io_getevents() failed to get 1 event");
+		return;
+	}
+
+	if (evbuf.res == -EAGAIN)
+		tst_res(TPASS, "io_getevents() returned EAGAIN on read event");
+	else
+		tst_res(TFAIL, "io_getevents() returned with %s instead of EAGAIN",
+			strerror(-evbuf.res));
                            ^
			    tst_strerrno()

Other than these two minor issues I do not see any problems in the code, the rest looks fine.

Signature · 2 lines
Cyril Hrubis
[email protected]
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#31 lore raw

Hi!

Quoted 2 lines

If you are agree then i will send next patch with s/strerror/tst_strerrno fix. Thanks.

No need to send another revision. I can fix that before applying the patch.

Signature · 5 lines
Cyril Hrubis
[email protected]

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

Hi!

Quoted 5 lines
Quoted 2 lines

If you are agree then i will send next patch with s/strerror/tst_strerrno fix. Thanks.

No need to send another revision. I can fix that before applying the patch.

Pushed with two adjustements.

- changed strerror() to tst_strerrno()
- used full link for the Fixes tag

Thanks.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp