Linux Test Project
 help / color / mirror / Atom feed
From: Petr Vorel <pvorel@suse.cz>
To: Zhao Gongyi <zhaogongyi@huawei.com>
Cc: Matthew Bobrowski <mbobrowski@mbobrowski.org>,
	Jan Kara <jack@suse.cz>,
	ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v2] fanotify/fanotify04: Bugfix for running with option of "-i 500"
Date: Wed, 9 Feb 2022 09:19:43 +0100	[thread overview]
Message-ID: <YgN5HyxYj/YMJgzY@pevik> (raw)
In-Reply-To: <20220209080510.167709-1-zhaogongyi@huawei.com>

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");
>  	}

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

  reply	other threads:[~2022-02-09  8:20 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-09  8:05 [LTP] [PATCH v2] fanotify/fanotify04: Bugfix for running with option of "-i 500" Zhao Gongyi via ltp
2022-02-09  8:19 ` Petr Vorel [this message]
2022-02-09 11:23 ` Jan Kara
2022-03-09 12:43   ` Cyril Hrubis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YgN5HyxYj/YMJgzY@pevik \
    --to=pvorel@suse.cz \
    --cc=jack@suse.cz \
    --cc=ltp@lists.linux.it \
    --cc=mbobrowski@mbobrowski.org \
    --cc=zhaogongyi@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox