All of lore.kernel.org
 help / color / mirror / Atom feed
From: Amir Goldstein <amir73il@gmail.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH 08/10] syscalls/fanotify09: Add test case with parent and subdir marks
Date: Wed,  9 Sep 2020 20:57:05 +0300	[thread overview]
Message-ID: <20200909175707.10670-9-amir73il@gmail.com> (raw)
In-Reply-To: <20200909175707.10670-1-amir73il@gmail.com>

This test checks handling of events with both parent and mount marks.
Generalize the test, and add test case of both parent and subdir marks.

Verified that existing test cases still fail on old kernels without the
relevant fix commits.

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
 .../kernel/syscalls/fanotify/fanotify09.c     | 57 ++++++++++++-------
 1 file changed, 35 insertions(+), 22 deletions(-)

diff --git a/testcases/kernel/syscalls/fanotify/fanotify09.c b/testcases/kernel/syscalls/fanotify/fanotify09.c
index 4336f498f..83210bc1c 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify09.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify09.c
@@ -6,17 +6,17 @@
  *
  * DESCRIPTION
  *     Check that fanotify handles events on children correctly when
- *     both inode and mountpoint marks exist.
+ *     both parent and subdir or mountpoint marks exist.
  *
  * This is a regression test for commit 54a307ba8d3c:
  *
  *      fanotify: fix logic of events on child
  *
- * Test case #2 is a regression test for commit b469e7e47c8a:
+ * Test case #1 is a regression test for commit b469e7e47c8a:
  *
  *      fanotify: fix handling of events on child sub-directory
  *
- * Test case #3 is a regression test for commit 55bf882c7f13:
+ * Test case #2 is a regression test for commit 55bf882c7f13:
  *
  *      fanotify: fix merging marks masks with FAN_ONDIR
  */
@@ -60,33 +60,45 @@ static int mount_created;
 
 static struct tcase {
 	const char *tname;
+	struct fanotify_mark_type mark;
 	unsigned int ondir;
 	const char *testdir;
 	int nevents;
 } tcases[] = {
 	{
-		"Events on children with both inode and mount marks",
+		"Events on non-dir child with both parent and mount marks",
+		INIT_FANOTIFY_MARK_TYPE(MOUNT),
 		0,
 		DIR_NAME,
 		1,
 	},
 	{
-		"Events on children and subdirs with both inode and mount marks",
+		"Events on non-dir child and subdir with both parent and mount marks",
+		INIT_FANOTIFY_MARK_TYPE(MOUNT),
 		FAN_ONDIR,
 		DIR_NAME,
 		2,
 	},
 	{
-		"Events on files and dirs with both inode and mount marks",
+		"Events on non-dir child and parent with both parent and mount marks",
+		INIT_FANOTIFY_MARK_TYPE(MOUNT),
 		FAN_ONDIR,
 		".",
 		2,
 	},
+	{
+		"Events on non-dir child and subdir with both parent and subdir marks",
+		INIT_FANOTIFY_MARK_TYPE(INODE),
+		FAN_ONDIR,
+		DIR_NAME,
+		2,
+	},
 };
 
-static void create_fanotify_groups(unsigned int ondir)
+static void create_fanotify_groups(struct tcase *tc)
 {
-	unsigned int i, onchild;
+	struct fanotify_mark_type *mark = &tc->mark;
+	unsigned int i, onchild, ondir = tc->ondir;
 	int ret;
 
 	for (i = 0; i < NUM_GROUPS; i++) {
@@ -94,22 +106,25 @@ static void create_fanotify_groups(unsigned int ondir)
 						  FAN_NONBLOCK,
 						  O_RDONLY);
 
-		/* Add mount mark for each group without MODIFY event */
+		/*
+		 * Add subdir or mount mark for each group with CLOSE event,
+		 * but only the first group requests events on dir.
+		 */
 		onchild = (i == 0) ? FAN_EVENT_ON_CHILD | ondir : 0;
 		ret = fanotify_mark(fd_notify[i],
-				    FAN_MARK_ADD | FAN_MARK_MOUNT,
+				    FAN_MARK_ADD | mark->flag,
 				    FAN_CLOSE_NOWRITE | onchild,
-				    AT_FDCWD, ".");
+				    AT_FDCWD, tc->testdir);
 		if (ret < 0) {
 			tst_brk(TBROK | TERRNO,
-				"fanotify_mark(%d, FAN_MARK_ADD | "
-				"FAN_MARK_MOUNT, FAN_MODIFY%s, AT_FDCWD,"
-				" '.') failed", fd_notify[i],
-				ondir ? " | FAN_ONDIR" : "");
+				"fanotify_mark(%d, FAN_MARK_ADD | %s, "
+				"%x, AT_FDCWD, '%s') failed",
+				fd_notify[i], mark->name,
+				FAN_CLOSE_NOWRITE | ondir, tc->testdir);
 		}
 		/*
-		 * Add inode mark on parent for each group with MODIFY
-		 * event, but only one group requests events on child.
+		 * Add inode mark on parent for each group with MODIFY event,
+		 * but only the first group requests events on child.
 		 * The one mark with FAN_EVENT_ON_CHILD is needed for
 		 * setting the DCACHE_FSNOTIFY_PARENT_WATCHED dentry
 		 * flag.
@@ -120,10 +135,8 @@ static void create_fanotify_groups(unsigned int ondir)
 		if (ret < 0) {
 			tst_brk(TBROK | TERRNO,
 				"fanotify_mark(%d, FAN_MARK_ADD, "
-				"FAN_MODIFY%s%s, AT_FDCWD, '.') failed",
-				fd_notify[i],
-				ondir ? " | FAN_ONDIR" : "",
-				onchild ? " | FAN_EVENT_ON_CHILD" : "");
+				"%x, AT_FDCWD, '.') failed",
+				fd_notify[i], FAN_MODIFY | ondir | onchild);
 		}
 	}
 }
@@ -179,7 +192,7 @@ static void test_fanotify(unsigned int n)
 
 	tst_res(TINFO, "Test #%d: %s", n, tc->tname);
 
-	create_fanotify_groups(tc->ondir);
+	create_fanotify_groups(tc);
 
 	/*
 	 * generate MODIFY event and no FAN_CLOSE_NOWRITE event.
-- 
2.17.1


  parent reply	other threads:[~2020-09-09 17:57 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-09 17:56 [LTP] [PATCH 00/10] Fanotify tests for v5.9 Amir Goldstein
2020-09-09 17:56 ` [LTP] [PATCH 01/10] syscalls/fanotify14: Test cases for FAN_REPORT_DFID_NAME Amir Goldstein
2020-09-09 17:56 ` [LTP] [PATCH 02/10] syscalls/fanotify16: Adjust test to use FAN_REPORT_DFID_NAME Amir Goldstein
2020-09-09 17:57 ` [LTP] [PATCH 03/10] syscalls/fanotify16: Test more event types with name Amir Goldstein
2020-09-09 17:57 ` [LTP] [PATCH 04/10] syscalls/fanotify16: Add test cases more init flag combinations Amir Goldstein
2020-09-09 17:57 ` [LTP] [PATCH 05/10] syscalls/fanotify16: Verify child fid info Amir Goldstein
2020-09-09 17:57 ` [LTP] [PATCH 06/10] syscalls/fcntl: New test for F_NOTIFY (dnotify) Amir Goldstein
2020-09-09 17:57 ` [LTP] [PATCH 07/10] syscalls/inotify: New test for watches on both parent and child Amir Goldstein
2020-09-09 17:57 ` Amir Goldstein [this message]
2020-09-09 17:57 ` [LTP] [PATCH 09/10] syscalls/fanotify10: Test with group flag FAN_REPORT_NAME Amir Goldstein
2020-09-09 17:57 ` [LTP] [PATCH 10/10] syscalls/fanotify10: Add test cases for merge with ignored mask on directory Amir Goldstein
2020-09-10  8:16 ` [LTP] [PATCH 00/10] Fanotify tests for v5.9 Petr Vorel
2020-09-10  8:34   ` Petr Vorel
2020-09-10 11:27 ` Petr Vorel
2020-09-10 13:36   ` Amir Goldstein
2020-09-10 13:50     ` Amir Goldstein
2020-09-10 14: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=20200909175707.10670-9-amir73il@gmail.com \
    --to=amir73il@gmail.com \
    --cc=ltp@lists.linux.it \
    /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 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.