All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [LTP] [PATCH] syscalls/fanotify: Kill the child process before exit
@ 2021-11-05  2:22 zhaogongyi
  2021-11-05  3:01 ` Matthew Bobrowski via ltp
  2021-11-05  8:12 ` Petr Vorel
  0 siblings, 2 replies; 9+ messages in thread
From: zhaogongyi @ 2021-11-05  2:22 UTC (permalink / raw)
  To: Matthew Bobrowski, Petr Vorel; +Cc: ltp

Hi,

> 
> On Thu, Nov 04, 2021 at 07:37:35PM +0100, Petr Vorel wrote:
> > Hi all,
> >
> > > Before the main process exit abnormally, we need to kill the child
> > > process.
> >
> > Amir, Matthew, could you please have a look?
> 
> If anything, I feel as though stop_children() should probably be called from
> cleanup() as that callback will be invoked if any of the
> SAFE_FANOTIFY_* macros fail anyway, right?

It seems that calling before run_children, we need not cleanup though the SAFE_FANOTIFY_* macros fail.

> 
> I don't feel like there's a need to introduce another helper here to
> explicitly handle the cleanup case, but I could also be wrong.

When we run the testcase simultaneously, and the ulimit of open files is small, the testcase will fail and remain
many while(1) tasks in system, it makes the system very stuck.

Shall we need to cleanup it?

> 
> > > Signed-off-by: Zhao Gongyi <zhaogongyi@huawei.com>
> > > ---
> > >  .../kernel/syscalls/fanotify/fanotify07.c     | 35
> ++++++++++++++++++-
> > >  1 file changed, 34 insertions(+), 1 deletion(-)
> >
> > > diff --git a/testcases/kernel/syscalls/fanotify/fanotify07.c
> > > b/testcases/kernel/syscalls/fanotify/fanotify07.c
> > > index cc56d9019..0a0b4f1e4 100644
> > > --- a/testcases/kernel/syscalls/fanotify/fanotify07.c
> > > +++ b/testcases/kernel/syscalls/fanotify/fanotify07.c
> > > @@ -108,6 +108,39 @@ static int setup_instance(void)
> > >  	return fd;
> > >  }
> >
> > > +static int setup_another_instance(void) {
> > > +	int rval;
> > > +	int fd = fanotify_init(FAN_CLASS_CONTENT, O_RDONLY);
> > > +
> > > +	if (fd == -1) {
> > > +		stop_children();
> > > +		tst_brk(TBROK | TERRNO, "fanotify_init() failed");
> > > +	}
> > > +
> > > +	if (fd < -1) {
> > > +		stop_children();
> > > +		tst_brk(TBROK | TERRNO,
> > > +			"invalid fanotify_init() return %d", fd);
> > > +	}
> > > +
> > > +	rval = fanotify_mark(fd,
> > > +		FAN_MARK_ADD, FAN_ACCESS_PERM, AT_FDCWD, fname);
> > > +
> > > +	if (rval == -1) {
> > > +		stop_children();
> > > +		tst_brk(TBROK | TERRNO, "fanotify_mark() failed");
> > > +	}
> > > +
> > > +	if (rval < -1) {
> > > +		stop_children();
> > > +		tst_brk(TBROK | TERRNO,
> > > +			"invalid fanotify_mark() return %d", rval);
> > > +	}
> > > +
> > > +	return fd;
> > > +}
> > > +
> > >  static void loose_fanotify_events(void)  {
> > >  	int not_responded = 0;
> > > @@ -160,7 +193,7 @@ static void test_fanotify(void)
> > >  	 * Create and destroy another instance. This may hang if
> > >  	 * unanswered fanotify events block notification subsystem.
> > >  	 */
> > > -	newfd = setup_instance();
> > > +	newfd = setup_another_instance();
> >
> > >  	SAFE_CLOSE(newfd);
> 
> /M

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

^ permalink raw reply	[flat|nested] 9+ messages in thread
* Re: [LTP] [PATCH] syscalls/fanotify: Kill the child process before exit
@ 2021-11-05  9:03 zhaogongyi
  0 siblings, 0 replies; 9+ messages in thread
From: zhaogongyi @ 2021-11-05  9:03 UTC (permalink / raw)
  To: Petr Vorel, Amir Goldstein; +Cc: Matthew Bobrowski, ltp

Hi,

I have resubmit a patch as your review. Please see: https://patchwork.ozlabs.org/project/ltp/patch/20211105090200.103485-1-zhaogongyi@huawei.com/

Thanks so much!
Gongyi

> 
> Hi all,
> 
> ...
> > This would be the obvious solution.
> > But simpler to skip zero values then stop the iterator.
> +1
> > This makes the cleanup helper reenetrant:
> 
> > static int stop_children(void)
> > {
> >         int child_ret;
> >         int i, ret = 0;
> 
> >         for (i = 0; i < MAX_CHILDREN; i++) {
> >                 if (!child_pid[i]) continue;
> >                 SAFE_KILL(child_pid[i], SIGKILL);
> >         }
> >         for (i = 0; i < MAX_CHILDREN; i++) {
> >                 if (!child_pid[i]) continue;
> >                 SAFE_WAITPID(child_pid[i], &child_ret, 0);
> >                 if (!WIFSIGNALED(child_ret))
> >                         ret = 1;
> >                 child_pid[i] = 0;
> >        }
> 
> >         return ret;
> > }
> 
> Amir, thanks! Zhao, could you please test this in your setup?
> (+ please be verbose about your setup, it helps to decide in the future that
> fix is still needed).
> 
> Kind regards,
> Petr
> 
> > Thanks,
> > Amir.

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

^ permalink raw reply	[flat|nested] 9+ messages in thread
* [LTP] [PATCH] syscalls/fanotify: Kill the child process before exit
@ 2021-11-04 12:19 Zhao Gongyi
  2021-11-04 18:37 ` Petr Vorel
  0 siblings, 1 reply; 9+ messages in thread
From: Zhao Gongyi @ 2021-11-04 12:19 UTC (permalink / raw)
  To: ltp

Before the main process exit abnormally, we need to kill
the child process.

Signed-off-by: Zhao Gongyi <zhaogongyi@huawei.com>
---
 .../kernel/syscalls/fanotify/fanotify07.c     | 35 ++++++++++++++++++-
 1 file changed, 34 insertions(+), 1 deletion(-)

diff --git a/testcases/kernel/syscalls/fanotify/fanotify07.c b/testcases/kernel/syscalls/fanotify/fanotify07.c
index cc56d9019..0a0b4f1e4 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify07.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify07.c
@@ -108,6 +108,39 @@ static int setup_instance(void)
 	return fd;
 }

+static int setup_another_instance(void)
+{
+	int rval;
+	int fd = fanotify_init(FAN_CLASS_CONTENT, O_RDONLY);
+
+	if (fd == -1) {
+		stop_children();
+		tst_brk(TBROK | TERRNO, "fanotify_init() failed");
+	}
+
+	if (fd < -1) {
+		stop_children();
+		tst_brk(TBROK | TERRNO,
+			"invalid fanotify_init() return %d", fd);
+	}
+
+	rval = fanotify_mark(fd,
+		FAN_MARK_ADD, FAN_ACCESS_PERM, AT_FDCWD, fname);
+
+	if (rval == -1) {
+		stop_children();
+		tst_brk(TBROK | TERRNO, "fanotify_mark() failed");
+	}
+
+	if (rval < -1) {
+		stop_children();
+		tst_brk(TBROK | TERRNO,
+			"invalid fanotify_mark() return %d", rval);
+	}
+
+	return fd;
+}
+
 static void loose_fanotify_events(void)
 {
 	int not_responded = 0;
@@ -160,7 +193,7 @@ static void test_fanotify(void)
 	 * Create and destroy another instance. This may hang if
 	 * unanswered fanotify events block notification subsystem.
 	 */
-	newfd = setup_instance();
+	newfd = setup_another_instance();

 	SAFE_CLOSE(newfd);

--
2.17.1


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

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2021-11-05  9:03 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-05  2:22 [LTP] [PATCH] syscalls/fanotify: Kill the child process before exit zhaogongyi
2021-11-05  3:01 ` Matthew Bobrowski via ltp
2021-11-05  4:31   ` Amir Goldstein
2021-11-05  8:29     ` Petr Vorel
2021-11-05  8:12 ` Petr Vorel
  -- strict thread matches above, loose matches on Subject: below --
2021-11-05  9:03 zhaogongyi
2021-11-04 12:19 Zhao Gongyi
2021-11-04 18:37 ` Petr Vorel
2021-11-05  1:40   ` Matthew Bobrowski via ltp

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.