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

Andrea Cervesato via ltp
2026-03-24T11:56:10Z

Hi Wei,

there are still a few things to achieve before merge. Hoefully the next one
will be merged since we have Jan approval already.

> v2->v3:
> - Replaced usleep() with poll() loop
> - Added secondary error check support (error2)

This can't be added to the commit message.

> +
> + if (!info) {
> + tst_res(TFAIL, "%s: Event [%d] missing error info",
> + ex->name, event_num);
> + continue;
> + }
> +
> + if (info->error != ex->error && (ex->error2 == 0 || info->error != ex->error2)) {
> + tst_res(TFAIL, "%s: Event [%d] unexpected errno (%d)",
> + ex->name, event_num, info->error);
> + }
> +
> + if (info) {

We are already having if (!info) {.. continue; } so we don't need this.

> + pfd.fd = fd_notify;
> + pfd.events = POLLIN;
> +
> + while (accumulated_count < tcase->error_count) {
> + if (poll(&pfd, 1, 5000) <= 0) {
> + tst_res(TFAIL, "%s: Timeout waiting for events", tcase->name);
> + goto out;
> + }
> +
> + char *current_pos = event_buf + read_len;
> + int ret = read(fd_notify, current_pos, BUF_SIZE - read_len);
> +
> + if (ret < 0) {
> + tst_res(TFAIL, "%s: read failed: %s", tcase->name, strerror(errno));
> + goto out;
> + }
> +
> + struct fanotify_event_metadata *m =
> + (struct fanotify_event_metadata *)current_pos;
> + while (FAN_EVENT_OK(m, ret)) {
> + read_len += ret;

This should be moved out of the while() loop, otherwise we will grow the
read_len for multiple event.

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