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

Andrea Cervesato via ltp
2026-03-27T09:07:56Z

Hi Wei,

> 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. uses a poll() and read() loop to wait
> until the expected.

This sentence is truncated at expected. Maybe the meaning was "Use a poll()
and read() loop to wait until the expected event".

> +
> + while (accumulated_count < tcase->error_count) {
> + if (poll(&pfd, 1, 5000) <= 0) {
> + tst_res(TFAIL, "%s: Timeout waiting for events", tcase->name);
> + goto out;
> + }
> +
> + if (read_len >= BUF_SIZE)
> + tst_brk(TBROK, "Event buffer full");
> +
> + char *current_pos = event_buf + read_len;
> + ssize_t ret = read(fd_notify, current_pos, BUF_SIZE - read_len);
> +
> + if (ret < 0) {
> + tst_brk(TBROK | TERRNO, "%s: read failed", tcase->name);
> + }

This is a bit weird. We have SAFE_READ() which is handling already the
read() syscalls errors, so we should use it. The reason why we are manually
handling the error is to show the tcase->name I guess. In this case, we
don't really need this: we usually have

tst_res(TINFO, "Test case: %s", tcase->name);

at the beginning of the do_test() function, so everything that comes later
will be related to it. At that point, also poll() TFAIL message should be
updated accordingly.

Regards,
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
andrea.cervesato@suse.com