All of lore.kernel.org
 help / color / mirror / Atom feed
From: Amir Goldstein <amir73il@gmail.com>
To: Petr Vorel <pvorel@suse.cz>
Cc: Matthew Bobrowski <repnop@google.com>, Jan Kara <jack@suse.cz>,
	ltp@lists.linux.it
Subject: [LTP] [PATCH 9/9] syscalls/fanotify10: Test FAN_MARK_IGNORE with FAN_ONDIR
Date: Mon,  5 Sep 2022 18:42:39 +0300	[thread overview]
Message-ID: <20220905154239.2652169-10-amir73il@gmail.com> (raw)
In-Reply-To: <20220905154239.2652169-1-amir73il@gmail.com>

Verify correct behavior with FAN_MARK_IGNORE when the FAN_ONDIR flag
is set in ignore mask and not in mask and when the flag is set in
mask and not in ignore mask.

These test cases are skipped for the FAN_MARK_IGNORED_MASK variant
where ignore mask is always applied to directories regardless of
FAN_ONDIR flag in mask or ignore mask.

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
 testcases/kernel/syscalls/fanotify/fanotify.h |  3 +
 .../kernel/syscalls/fanotify/fanotify10.c     | 56 ++++++++++++++++---
 2 files changed, 52 insertions(+), 7 deletions(-)

diff --git a/testcases/kernel/syscalls/fanotify/fanotify.h b/testcases/kernel/syscalls/fanotify/fanotify.h
index 6fbd96d11..ddd365cff 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify.h
+++ b/testcases/kernel/syscalls/fanotify/fanotify.h
@@ -119,6 +119,9 @@ static inline int safe_fanotify_mark(const char *file, const int lineno,
 #ifndef FAN_MARK_PARENT
 #define FAN_MARK_PARENT		FAN_MARK_ONLYDIR
 #endif
+#ifndef FAN_MARK_SUBDIR
+#define FAN_MARK_SUBDIR		FAN_MARK_ONLYDIR
+#endif
 #ifndef FAN_MARK_TYPES
 #define FAN_MARK_TYPES (FAN_MARK_INODE | FAN_MARK_MOUNT | FAN_MARK_FILESYSTEM)
 #endif
diff --git a/testcases/kernel/syscalls/fanotify/fanotify10.c b/testcases/kernel/syscalls/fanotify/fanotify10.c
index 0095bda2a..671fbf8fd 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify10.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify10.c
@@ -80,11 +80,13 @@ static int ignore_mark_unsupported;
 #define DIR_NAME "testdir"
 #define FILE_NAME "testfile"
 #define FILE2_NAME "testfile2"
+#define SUBDIR_NAME "testdir2"
 #define TEST_APP "fanotify_child"
 #define TEST_APP2 "fanotify_child2"
 #define DIR_PATH MOUNT_PATH"/"DIR_NAME
 #define FILE_PATH DIR_PATH"/"FILE_NAME
 #define FILE2_PATH DIR_PATH"/"FILE2_NAME
+#define SUBDIR_PATH DIR_PATH"/"SUBDIR_NAME
 #define FILE_EXEC_PATH MOUNT_PATH"/"TEST_APP
 #define FILE2_EXEC_PATH MOUNT_PATH"/"TEST_APP2
 #define DIR_MNT2 MNT2_PATH"/"DIR_NAME
@@ -104,6 +106,7 @@ static unsigned int num_classes = NUM_CLASSES;
 enum {
 	FANOTIFY_INODE,
 	FANOTIFY_PARENT,
+	FANOTIFY_SUBDIR,
 	FANOTIFY_MOUNT,
 	FANOTIFY_FILESYSTEM,
 	FANOTIFY_EVICTABLE,
@@ -112,6 +115,7 @@ enum {
 static struct fanotify_mark_type fanotify_mark_types[] = {
 	INIT_FANOTIFY_MARK_TYPE(INODE),
 	INIT_FANOTIFY_MARK_TYPE(PARENT),
+	INIT_FANOTIFY_MARK_TYPE(SUBDIR),
 	INIT_FANOTIFY_MARK_TYPE(MOUNT),
 	INIT_FANOTIFY_MARK_TYPE(FILESYSTEM),
 	INIT_FANOTIFY_MARK_TYPE(EVICTABLE),
@@ -123,7 +127,7 @@ static struct tcase {
 	int mark_type;
 	const char *ignore_path;
 	int ignore_mark_type;
-	unsigned int ignored_onchild;
+	unsigned int ignored_flags;
 	const char *event_path;
 	unsigned long long expected_mask_with_ignore;
 	unsigned long long expected_mask_without_ignore;
@@ -329,6 +333,28 @@ static struct tcase {
 		FAN_EVENT_ON_CHILD,
 		FILE_PATH, FAN_OPEN, FAN_OPEN
 	},
+	/* FAN_MARK_IGNORE specific test cases */
+	{
+		"ignore events on subdir inside a parent watching subdirs",
+		SUBDIR_PATH, FANOTIFY_SUBDIR,
+		DIR_PATH, FANOTIFY_PARENT,
+		FAN_EVENT_ON_CHILD | FAN_ONDIR,
+		SUBDIR_PATH, 0, FAN_OPEN | FAN_ONDIR
+	},
+	{
+		"don't ignore events on subdir inside a parent not watching children",
+		SUBDIR_PATH, FANOTIFY_SUBDIR,
+		DIR_PATH, FANOTIFY_PARENT,
+		FAN_ONDIR,
+		SUBDIR_PATH, FAN_OPEN | FAN_ONDIR, FAN_OPEN | FAN_ONDIR
+	},
+	{
+		"don't ignore events on subdir inside a parent watching non-dir children",
+		SUBDIR_PATH, FANOTIFY_SUBDIR,
+		DIR_PATH, FANOTIFY_PARENT,
+		FAN_EVENT_ON_CHILD,
+		SUBDIR_PATH, FAN_OPEN | FAN_ONDIR, FAN_OPEN | FAN_ONDIR
+	},
 };
 
 static void show_fanotify_ignore_marks(int fd, int expected)
@@ -365,6 +391,7 @@ static int create_fanotify_groups(unsigned int n)
 	unsigned int p, i;
 	int evictable_ignored = (tc->ignore_mark_type == FANOTIFY_EVICTABLE);
 	int ignore_mark_type;
+	int ignored_onchild = tc->ignored_flags & FAN_EVENT_ON_CHILD;
 
 	mark = &fanotify_mark_types[tc->mark_type];
 	ignore_mark = &fanotify_mark_types[tc->ignore_mark_type];
@@ -387,7 +414,7 @@ static int create_fanotify_groups(unsigned int n)
 			SAFE_FANOTIFY_MARK(fd_notify[p][i],
 					    FAN_MARK_ADD | mark->flag,
 					    tc->expected_mask_without_ignore |
-					    FAN_EVENT_ON_CHILD,
+					    FAN_EVENT_ON_CHILD | FAN_ONDIR,
 					    AT_FDCWD, tc->mark_path);
 
 			/* Do not add ignore mark for first priority groups */
@@ -400,7 +427,7 @@ static int create_fanotify_groups(unsigned int n)
 			 * 2. FAN_MARK_IGNORE
 			 */
 			mark_ignored = tst_variant ? FAN_MARK_IGNORE_SURV : FAN_MARK_IGNORED_SURV;
-			mask = FAN_OPEN | tc->ignored_onchild;
+			mask = FAN_OPEN | tc->ignored_flags;
 add_mark:
 			SAFE_FANOTIFY_MARK(fd_notify[p][i],
 					    FAN_MARK_ADD | ignore_mark->flag | mark_ignored,
@@ -414,7 +441,7 @@ add_mark:
 			 * This is needed to indicate that parent ignored mask
 			 * should be applied to events on children.
 			 */
-			if (tc->ignored_onchild && mark_ignored & FAN_MARK_IGNORED_MASK) {
+			if (ignored_onchild && mark_ignored & FAN_MARK_IGNORED_MASK) {
 				mark_ignored = 0;
 				goto add_mark;
 			}
@@ -437,10 +464,12 @@ add_mark:
 			 */
 			if (mark_ignored & FAN_MARK_IGNORE &&
 			    tc->ignore_mark_type == FANOTIFY_PARENT) {
-				if (!tc->ignored_onchild)
-					mask = FAN_CLOSE_WRITE | FAN_EVENT_ON_CHILD;
+				if (!ignored_onchild)
+					mask = FAN_CLOSE_WRITE | FAN_EVENT_ON_CHILD | FAN_ONDIR;
 				else if (tc->mark_type == FANOTIFY_PARENT)
 					continue;
+				else if (tc->ignored_flags & FAN_ONDIR)
+					mask = FAN_CLOSE | ignored_onchild;
 				else
 					mask = FAN_CLOSE | FAN_ONDIR;
 				mark_ignored = 0;
@@ -497,6 +526,10 @@ static void mount_cycle(void)
 static void verify_event(int p, int group, struct fanotify_event_metadata *event,
 			 unsigned long long expected_mask)
 {
+	/* Only FAN_REPORT_FID reports the FAN_ONDIR flag in events on dirs */
+	if (!(fanotify_class[p] & FAN_REPORT_FID))
+		expected_mask &= ~FAN_ONDIR;
+
 	if (event->mask != expected_mask) {
 		tst_res(TFAIL, "group %d (%x) got event: mask %llx (expected %llx) "
 			"pid=%u fd=%u", group, fanotify_class[p],
@@ -572,12 +605,19 @@ static void test_fanotify(unsigned int n)
 		return;
 	}
 
-	if (tc->ignored_onchild && tst_kvercmp(5, 9, 0) < 0) {
+	if (tc->ignored_flags & FAN_EVENT_ON_CHILD && tst_kvercmp(5, 9, 0) < 0) {
 		tst_res(TCONF, "ignored mask in combination with flag FAN_EVENT_ON_CHILD"
 				" has undefined behavior on kernel < 5.9");
 		return;
 	}
 
+	if (tc->ignored_flags && tc->ignore_mark_type == FANOTIFY_PARENT &&
+			!tst_variant && tc->mark_type == FANOTIFY_SUBDIR) {
+		tst_res(TCONF, "flags FAN_EVENT_ON_CHILD and FAN_ONDIR do not take effect"
+				" with legacy FAN_MARK_IGNORED_MASK");
+		return;
+	}
+
 	if (create_fanotify_groups(n) != 0)
 		goto cleanup;
 
@@ -675,6 +715,7 @@ static void setup(void)
 	}
 
 	SAFE_MKDIR(DIR_PATH, 0755);
+	SAFE_MKDIR(SUBDIR_PATH, 0755);
 	SAFE_FILE_PRINTF(FILE_PATH, "1");
 	SAFE_FILE_PRINTF(FILE2_PATH, "1");
 
@@ -701,6 +742,7 @@ static void cleanup(void)
 
 	SAFE_UNLINK(FILE_PATH);
 	SAFE_UNLINK(FILE2_PATH);
+	SAFE_RMDIR(SUBDIR_PATH);
 	SAFE_RMDIR(DIR_PATH);
 	SAFE_RMDIR(MNT2_PATH);
 }
-- 
2.25.1


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

  parent reply	other threads:[~2022-09-05 15:44 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-05 15:42 [LTP] [PATCH 0/9] Fanotify tests for FAN_MARK_IGNORE Amir Goldstein
2022-09-05 15:42 ` [LTP] [PATCH 1/9] syscalls/fanotify09: Add test cases " Amir Goldstein
2022-09-05 16:04   ` Petr Vorel
2022-09-06  5:08     ` Amir Goldstein
2022-09-06  5:58       ` Petr Vorel
2022-09-05 15:42 ` [LTP] [PATCH 2/9] syscalls/fanotify14: Require FAN_REPORT_FID support for entire test Amir Goldstein
2022-09-06  6:06   ` Petr Vorel
2022-09-05 15:42 ` [LTP] [PATCH 3/9] syscalls/fanotify14: Add test cases for FAN_MARK_IGNORE Amir Goldstein
2022-09-06  9:05   ` Petr Vorel
2022-09-05 15:42 ` [LTP] [PATCH 4/9] syscalls/fanotify10: Avoid undesired event in test Amir Goldstein
2022-09-06 16:51   ` Petr Vorel
2022-09-06 17:09   ` Petr Vorel
2022-09-05 15:42 ` [LTP] [PATCH 5/9] syscalls/fanotify10: Add more verifications and debug info Amir Goldstein
2022-09-06 17:01   ` Petr Vorel
2022-09-05 15:42 ` [LTP] [PATCH 6/9] syscalls/fanotify10: Use dedicated mark type for inode mark on parent Amir Goldstein
2022-09-06 17:03   ` Petr Vorel
2022-09-05 15:42 ` [LTP] [PATCH 7/9] syscalls/fanotify10: Run tests with two ignore mask variants Amir Goldstein
2022-09-06 17:07   ` Petr Vorel
2022-09-05 15:42 ` [LTP] [PATCH 8/9] syscalls/fanotify10: Test FAN_MARK_IGNORE with FAN_EVENT_ON_CHILD Amir Goldstein
2022-09-05 15:42 ` Amir Goldstein [this message]
2022-09-06 15:38 ` [LTP] [PATCH 0/9] Fanotify tests for FAN_MARK_IGNORE Jan Kara
2022-09-06 17:28   ` Amir Goldstein
2022-09-07 10:45     ` Petr Vorel

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=20220905154239.2652169-10-amir73il@gmail.com \
    --to=amir73il@gmail.com \
    --cc=jack@suse.cz \
    --cc=ltp@lists.linux.it \
    --cc=pvorel@suse.cz \
    --cc=repnop@google.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 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.