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

Jan Kara jack@suse.cz
Mon Mar 9 12:29:36 CET 2026


On Mon 09-03-26 07:59:42, Wei Gao wrote:
> 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. Adding a short delay
>    (usleep) ensures all events are dispatched and ready before the
>    read() call.
> 
> 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.
> 
> Reported-by: kernel test robot <oliver.sang@intel.com>
> Closes: https://lore.kernel.org/oe-lkp/202602042124.87bd00e3-lkp@intel.com
> Suggested-by: Jan Kara <jack@suse.cz>
> Signed-off-by: Wei Gao <wegao@suse.com>
...
> +static size_t consolidate_events(char *buf, size_t len)
> +{
> +	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) {
> +			if (!first) {
> +				first = metadata;
> +				first_info = info;
> +			}
> +			total_count += info->error_count;

Please verify the 'error' field in the info matches before merging the
count and fail the test if it does not. Also if we get event without error
info I think we should fail the test as it currently shouldn't happen for
any of the tests.

								Honza

> +
> +			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)
>  {
> @@ -255,7 +286,11 @@ static void do_test(unsigned int i)
>  
>  	tcase->trigger_error();
>  
> +	/* Wait for asynchronous kworker threads to dispatch events */
> +	usleep(100000);
> +
>  	read_len = SAFE_READ(0, fd_notify, event_buf, BUF_SIZE);
> +	read_len = consolidate_events(event_buf, read_len);
>  
>  	SAFE_FANOTIFY_MARK(fd_notify, FAN_MARK_REMOVE|FAN_MARK_FILESYSTEM,
>  			   FAN_FS_ERROR, AT_FDCWD, MOUNT_PATH);
> -- 
> 2.52.0
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR


More information about the ltp mailing list