[LTP] [PATCH v2] fanotify/fanotify04: Bugfix for running with option of "-i 500"

Petr Vorel pvorel@suse.cz
Wed Feb 9 09:19:43 CET 2022


Hi Zhao,

> When we running the testcase with option of "-i 500", the test
> will fail:
> ...
> fanotify04.c:163: TPASS: No event as expected
> fanotify04.c:71: TPASS: fanotify_mark (3, FAN_MARK_ADD | 0, FAN_OPEN, AT_FDCWD, 'symlink_160172') succeeded
> fanotify04.c:127: TPASS: event generated properly for type 100000
> fanotify04.c:113: TBROK: read(3,0x55c783185280,0) failed, returned -1: EINVAL (22)
> ...

[ Cc: kernel also Amir and Matthew ]
https://lore.kernel.org/ltp/20220209080510.167709-1-zhaogongyi@huawei.com/T/#u

Reviewed-by: Petr Vorel <pvorel@suse.cz>

LGTM, works as expected, I don't see any performance impact.
Also don't think buffer containing all events was important for testing and can
be replaced with buffer for just single event. But please correct me if I'm
wrong.

> Signed-off-by: Zhao Gongyi <zhaogongyi@huawei.com>
> ---
> v1->v2: Clear the compile warnings.
Thanks! I was going to send a diff, not only because the warnings, but also
patch didn't apply.

Kind regards,
Petr

>  .../kernel/syscalls/fanotify/fanotify04.c     | 21 ++++++-------------
>  1 file changed, 6 insertions(+), 15 deletions(-)

> diff --git a/testcases/kernel/syscalls/fanotify/fanotify04.c b/testcases/kernel/syscalls/fanotify/fanotify04.c
> index b23d7a9a3..8c3c179b1 100644
> --- a/testcases/kernel/syscalls/fanotify/fanotify04.c
> +++ b/testcases/kernel/syscalls/fanotify/fanotify04.c
> @@ -24,11 +24,8 @@
>  #ifdef HAVE_SYS_FANOTIFY_H
>  #include "fanotify.h"

> -#define EVENT_MAX 1024
>  /* size of the event structure, not counting name */
>  #define EVENT_SIZE  (sizeof (struct fanotify_event_metadata))
> -/* reasonable guess as to size of 1024 events */
> -#define EVENT_BUF_LEN        (EVENT_MAX * EVENT_SIZE)

>  #define BUF_SIZE 256
>  #define TST_TOTAL 9
> @@ -37,9 +34,7 @@ static char fname[BUF_SIZE];
>  static char sname[BUF_SIZE];
>  static char dir[BUF_SIZE];
>  static int fd_notify;
> -
> -static int len;
> -static char event_buf[EVENT_BUF_LEN];
> +static char event_buf[EVENT_SIZE];

>  static char *expect_str_fail(int expect)
>  {
> @@ -104,16 +99,12 @@ static void open_dir(char *file)

>  static void verify_event(int mask)
>  {
> -	int ret;
>  	struct fanotify_event_metadata *event;
>  	struct stat st;

>  	/* Read the event */
> -	ret = SAFE_READ(0, fd_notify, event_buf + len,
> -			EVENT_BUF_LEN - len);
> -	event = (struct fanotify_event_metadata *)&event_buf[len];
> -	len += ret;
> -
> +	SAFE_READ(0, fd_notify, event_buf, EVENT_SIZE);
> +	event = (struct fanotify_event_metadata *)&event_buf;
>  	if (event->mask != FAN_OPEN) {
>  		tst_res(TFAIL, "got unexpected event %llx",
>  			(unsigned long long)event->mask);
> @@ -146,11 +137,11 @@ static void verify_no_event(void)
>  {
>  	int ret;

> -	ret = read(fd_notify, event_buf + len, EVENT_BUF_LEN - len);
> +	ret = read(fd_notify, event_buf, EVENT_SIZE);
>  	if (ret != -1) {
>  		struct fanotify_event_metadata *event;

> -		event = (struct fanotify_event_metadata *)&event_buf[len];
> +		event = (struct fanotify_event_metadata *)&event_buf;
>  		tst_res(TFAIL, "seen unexpected event (mask %llx)",
>  			(unsigned long long)event->mask);
>  		/* Cleanup fd from the event */
> @@ -158,7 +149,7 @@ static void verify_no_event(void)
>  			SAFE_CLOSE(event->fd);
>  	} else if (errno != EAGAIN) {
>  		tst_res(TFAIL | TERRNO, "read(%d, buf, %zu) failed", fd_notify,
> -			EVENT_BUF_LEN);
> +			EVENT_SIZE);
>  	} else {
>  		tst_res(TPASS, "No event as expected");
>  	}


More information about the ltp mailing list