Skip to contentSkip to conversation

fanotify: Make feature tests operate against tested path

PATCH New Jan Kara 2 participants 10 messages Nov 30, 2023

lore
Share & tools
lore

Jan Kara

author
#0 lore raw

v2 cover fanotify: Make feature tests operate against tested path

Hello,

some of the fanotify features are not available across all filesystems. Thus depending on which path is used for placing fanotify mark the feature may or may not be available. This leads to test failures when some feature is supported in tmpdir but not on the tested filesystem. Convert all of the fanotify feature tests to be performed on the path actually being used for testing.

Changes since v1:
* Added Amir's reviewed by
* Fixed up bug in patch 1 leading to incorrect feature availability detection
* Added patch to print more details in error messages
* Changed FAN_CLASS_CONTENT to FAN_CLASS_NOTIF when testing whether a mark type is supported.

Honza
Previous versions:

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
author
#1 lore raw

PATCH v2 1/7 fanotify: Generalize helper fanotify_flags_supported_on_fs()

From: Amir Goldstein <[email protected]>

The helper fanotify_init_flags_supported_on_fs() is used to check if fanotify init flags (usually FAN_REPORT_FID) are supported by kernel and on a specific filesystem.

The helper fanotify_mark_supported_by_kernel() does not check for support on a specific filesystem.

There are now specific filesystems (e.g. overlayfs, fuse) that do not support FAN_REPORT_FID, but not with filesystem and mount mark types.

Generelize the helper fanotify_init_flags_supported_on_fs() to be used to check also support for mark flags and event flags on a specific filesystem.

The helper fanotify_init_flags_err_msg() was also renamed to reflect the fact that it is already used to report an error message for mark flags and handle flags, not only init flags.

---
 testcases/kernel/syscalls/fanotify/fanotify.h | 55 +++++++++++--------
 1 file changed, 33 insertions(+), 22 deletions(-)
testcases/kernel/syscalls/fanotify/fanotify.h +33 -22
index 32b510cdc178..f34440e0bd41 100644
@@ -176,35 +176,38 @@ static inline int fanotify_events_supported_by_kernel(uint64_t mask,
 }
 
 /*
- * @return  0: fanotify supported both in kernel and on tested filesystem
- * @return -1: @flags not supported in kernel
- * @return -2: @flags not supported on tested filesystem (tested if @fname is not NULL)
- * @return -3: @flags not supported on overlayfs (tested if @fname == OVL_MNT)
+ * @return  0: fanotify flags supported both in kernel and on tested filesystem
+ * @return -1: @init_flags not supported in kernel
+ * @return -2: @mark_flags not supported on tested filesystem (tested if @fname is not NULL)
+ * @return -3: @mark_flags not supported on overlayfs (tested if @fname == OVL_MNT)
  */
-static inline int fanotify_init_flags_supported_on_fs(unsigned int flags, const char *fname)
+static inline int fanotify_flags_supported_on_fs(unsigned int init_flags,
+						 unsigned int mark_flags,
+						 uint64_t event_flags,
+						 const char *fname)
 {
 	int fd;
 	int rval = 0;
 
-	fd = fanotify_init(flags, O_RDONLY);
+	fd = fanotify_init(init_flags, O_RDONLY);
 
 	if (fd < 0) {
 		if (errno == ENOSYS)
 			tst_brk(TCONF, "fanotify not configured in kernel");
-
-		if (errno == EINVAL)
-			return -1;
-
-		tst_brk(TBROK | TERRNO, "fanotify_init() failed");
+		if (errno != EINVAL)
+			tst_brk(TBROK | TERRNO, "fanotify_init() failed");
+		return -1;
 	}
 
-	if (fname && fanotify_mark(fd, FAN_MARK_ADD, FAN_ACCESS, AT_FDCWD, fname) < 0) {
+	if (fname && fanotify_mark(fd, FAN_MARK_ADD | mark_flags, event_flags, AT_FDCWD, fname) < 0) {
 		if (errno == ENODEV || errno == EOPNOTSUPP || errno == EXDEV) {
 			rval = strcmp(fname, OVL_MNT) ? -2 : -3;
-		} else {
+		} else if (errno != EINVAL) {
 			tst_brk(TBROK | TERRNO,
 				"fanotify_mark (%d, FAN_MARK_ADD, ..., AT_FDCWD, %s) failed",
 				fd, fname);
+		} else {
+			rval = -1;
 		}
 	}
 
@@ -213,6 +216,11 @@ static inline int fanotify_init_flags_supported_on_fs(unsigned int flags, const
 	return rval;
 }
 
+static inline int fanotify_init_flags_supported_on_fs(unsigned int flags, const char *fname)
+{
+	return fanotify_flags_supported_on_fs(flags, FAN_MARK_INODE, FAN_ACCESS, fname);
+}
+
 static inline int fanotify_init_flags_supported_by_kernel(unsigned int flags)
 {
 	return fanotify_init_flags_supported_on_fs(flags, NULL);
@@ -264,7 +272,7 @@ static inline unsigned int fanotify_get_supported_init_flags(unsigned int flags,
 typedef void (*tst_res_func_t)(const char *file, const int lineno,
 			       int ttype, const char *fmt, ...);
 
-static inline void fanotify_init_flags_err_msg(const char *flags_str,
+static inline void fanotify_flags_err_msg(const char *flags_str,
 	const char *file, const int lineno, tst_res_func_t res_func, int fail)
 {
 	if (fail == -1)
@@ -278,14 +286,17 @@ static inline void fanotify_init_flags_err_msg(const char *flags_str,
 }
 
 #define FANOTIFY_INIT_FLAGS_ERR_MSG(flags, fail) \
-	fanotify_init_flags_err_msg(#flags, __FILE__, __LINE__, tst_res_, (fail))
+	fanotify_flags_err_msg(#flags, __FILE__, __LINE__, tst_res_, (fail))
+
+#define FANOTIFY_MARK_FLAGS_ERR_MSG(mark, fail) \
+	fanotify_flags_err_msg((mark)->name, __FILE__, __LINE__, tst_res_, (fail))
 
 #define REQUIRE_FANOTIFY_INIT_FLAGS_SUPPORTED_ON_FS(flags, fname) \
-	fanotify_init_flags_err_msg(#flags, __FILE__, __LINE__, tst_brk_, \
+	fanotify_flags_err_msg(#flags, __FILE__, __LINE__, tst_brk_, \
 		fanotify_init_flags_supported_on_fs(flags, fname))
 
 #define REQUIRE_FANOTIFY_INIT_FLAGS_SUPPORTED_BY_KERNEL(flags) \
-	fanotify_init_flags_err_msg(#flags, __FILE__, __LINE__, tst_brk_, \
+	fanotify_flags_err_msg(#flags, __FILE__, __LINE__, tst_brk_, \
 		fanotify_init_flags_supported_by_kernel(flags))
 
 static inline int fanotify_mark_supported_by_kernel(uint64_t flag)
@@ -323,19 +334,19 @@ static inline int fanotify_handle_supported_by_kernel(int flag)
 }
 
 #define REQUIRE_MARK_TYPE_SUPPORTED_BY_KERNEL(mark_type) \
-	fanotify_init_flags_err_msg(#mark_type, __FILE__, __LINE__, tst_brk_, \
-				    fanotify_mark_supported_by_kernel(mark_type))
+	fanotify_flags_err_msg(#mark_type, __FILE__, __LINE__, tst_brk_, \
+		fanotify_mark_supported_by_kernel(mark_type))
 
 #define REQUIRE_HANDLE_TYPE_SUPPORTED_BY_KERNEL(handle_type) \
-	fanotify_init_flags_err_msg(#handle_type, __FILE__, __LINE__, tst_brk_, \
-				    fanotify_handle_supported_by_kernel(handle_type))
+	fanotify_flags_err_msg(#handle_type, __FILE__, __LINE__, tst_brk_, \
+		fanotify_handle_supported_by_kernel(handle_type))
 
 #define REQUIRE_FANOTIFY_EVENTS_SUPPORTED_ON_FS(init_flags, mark_type, mask, fname) do { \
 	if (mark_type)							\
 		REQUIRE_MARK_TYPE_SUPPORTED_BY_KERNEL(mark_type);	\
 	if (init_flags)							\
 		REQUIRE_FANOTIFY_INIT_FLAGS_SUPPORTED_ON_FS(init_flags, fname); \
-	fanotify_init_flags_err_msg(#mask, __FILE__, __LINE__, tst_brk_, \
+	fanotify_flags_err_msg(#mask, __FILE__, __LINE__, tst_brk_, \
 		fanotify_events_supported_by_kernel(mask, init_flags, mark_type)); \
 } while (0)
 
Signature · 5 lines
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
author
#2 lore raw

PATCH v2 2/7 fanotify: Print more details on error from fanotify_flags_supported_on_fs()

In reply to Jan Kara

Print more details about failing calls from
fanotify_flags_supported_on_fs().

---
 testcases/kernel/syscalls/fanotify/fanotify.h | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
testcases/kernel/syscalls/fanotify/fanotify.h +6 -3
index f34440e0bd41..3b8838e8dd68 100644
@@ -195,7 +195,9 @@ static inline int fanotify_flags_supported_on_fs(unsigned int init_flags,
 		if (errno == ENOSYS)
 			tst_brk(TCONF, "fanotify not configured in kernel");
 		if (errno != EINVAL)
-			tst_brk(TBROK | TERRNO, "fanotify_init() failed");
+			tst_brk(TBROK | TERRNO,
+				"fanotify_init(%x, O_RDONLY) failed",
+				init_flags);
 		return -1;
 	}
 
@@ -204,8 +206,9 @@ static inline int fanotify_flags_supported_on_fs(unsigned int init_flags,
 			rval = strcmp(fname, OVL_MNT) ? -2 : -3;
 		} else if (errno != EINVAL) {
 			tst_brk(TBROK | TERRNO,
-				"fanotify_mark (%d, FAN_MARK_ADD, ..., AT_FDCWD, %s) failed",
-				fd, fname);
+				"fanotify_mark (%d, FAN_MARK_ADD | %x, %llx, AT_FDCWD, %s) failed",
+				fd, mark_flags, (unsigned long long)event_flags,
+				fname);
 		} else {
 			rval = -1;
 		}
Signature · 5 lines
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v2 2/7
#3 lore raw

Re: [LTP] [PATCH v2 2/7] fanotify: Print more details on error from fanotify_flags_supported_on_fs()

Quoted 5 lines · Jan Kara

Print more details about failing calls from
fanotify_flags_supported_on_fs().

Quoted 34 lines
---
 testcases/kernel/syscalls/fanotify/fanotify.h | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
testcases/kernel/syscalls/fanotify/fanotify.h +6 -4
index f34440e0bd41..3b8838e8dd68 100644
@@ -195,7 +195,9 @@ static inline int fanotify_flags_supported_on_fs(unsigned int init_flags,
                if (errno == ENOSYS)
                        tst_brk(TCONF, "fanotify not configured in kernel");
                if (errno != EINVAL)
-                       tst_brk(TBROK | TERRNO, "fanotify_init() failed");
+                       tst_brk(TBROK | TERRNO,
+                               "fanotify_init(%x, O_RDONLY) failed",
+                               init_flags);
                return -1;
        }
 
@@ -204,8 +206,9 @@ static inline int fanotify_flags_supported_on_fs(unsigned int init_flags,
                        rval = strcmp(fname, OVL_MNT) ? -2 : -3;
                } else if (errno != EINVAL) {
                        tst_brk(TBROK | TERRNO,
-                               "fanotify_mark (%d, FAN_MARK_ADD, ..., AT_FDCWD, %s) failed",
-                               fd, fname);
+                               "fanotify_mark (%d, FAN_MARK_ADD | %x, %llx, AT_FDCWD, %s) failed",
+                               fd, mark_flags, (unsigned long long)event_flags,
+                               fname);
                } else {
                        rval = -1;
                }
--

2.35.3

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
author
#4 lore raw

PATCH v2 3/7 fanotify: Provide fanotify_mark_supported_on_fs()

In reply to Jan Kara

Provide helper checking whether a mark is supported on a filesystem since some marks need not be available on all filesystems (e.g. btrfs subvolumes). Also convert REQUIRE_MARK_TYPE_SUPPORTED_BY_KERNEL() and its only user to use this new function.

---
 testcases/kernel/syscalls/fanotify/fanotify.h   | 11 ++++++++---
 testcases/kernel/syscalls/fanotify/fanotify23.c |  2 +-
 2 files changed, 9 insertions(+), 4 deletions(-)
testcases/kernel/syscalls/fanotify/fanotify.h +8 -3
index 3b8838e8dd68..597ed96e0313 100644
@@ -229,6 +229,11 @@ static inline int fanotify_init_flags_supported_by_kernel(unsigned int flags)
 	return fanotify_init_flags_supported_on_fs(flags, NULL);
 }
 
+static inline int fanotify_mark_supported_on_fs(uint64_t flag, const char *fname)
+{
+	return fanotify_flags_supported_on_fs(FAN_CLASS_NOTIF, flag, FAN_ACCESS, fname);
+}
+
 #define TST_FANOTIFY_INIT_KNOWN_FLAGS                                      \
 	(FAN_REPORT_DFID_NAME_TARGET | FAN_REPORT_TID | FAN_REPORT_PIDFD | \
 	FAN_CLASS_NOTIF | FAN_CLASS_CONTENT | FAN_CLASS_PRE_CONTENT)
@@ -336,9 +341,9 @@ static inline int fanotify_handle_supported_by_kernel(int flag)
 	return 0;
 }
 
-#define REQUIRE_MARK_TYPE_SUPPORTED_BY_KERNEL(mark_type) \
+#define REQUIRE_MARK_TYPE_SUPPORTED_ON_FS(mark_type, fname) \
 	fanotify_flags_err_msg(#mark_type, __FILE__, __LINE__, tst_brk_, \
-		fanotify_mark_supported_by_kernel(mark_type))
+		fanotify_mark_supported_on_fs(mark_type, fname))
 
 #define REQUIRE_HANDLE_TYPE_SUPPORTED_BY_KERNEL(handle_type) \
 	fanotify_flags_err_msg(#handle_type, __FILE__, __LINE__, tst_brk_, \
@@ -346,7 +351,7 @@ static inline int fanotify_handle_supported_by_kernel(int flag)
 
 #define REQUIRE_FANOTIFY_EVENTS_SUPPORTED_ON_FS(init_flags, mark_type, mask, fname) do { \
 	if (mark_type)							\
-		REQUIRE_MARK_TYPE_SUPPORTED_BY_KERNEL(mark_type);	\
+		REQUIRE_MARK_TYPE_SUPPORTED_ON_FS(mark_type, fname);	\
 	if (init_flags)							\
 		REQUIRE_FANOTIFY_INIT_FLAGS_SUPPORTED_ON_FS(init_flags, fname); \
 	fanotify_flags_err_msg(#mask, __FILE__, __LINE__, tst_brk_, \
testcases/kernel/syscalls/fanotify/fanotify23.c +1 -1
index fb812c51e34e..5a03503e952a 100644
@@ -230,7 +230,7 @@ static void setup(void)
 {
 	SAFE_TOUCH(TEST_FILE, 0666, NULL);
 
-	REQUIRE_MARK_TYPE_SUPPORTED_BY_KERNEL(FAN_MARK_EVICTABLE);
+	REQUIRE_MARK_TYPE_SUPPORTED_ON_FS(FAN_MARK_EVICTABLE, ".");
 	REQUIRE_FANOTIFY_EVENTS_SUPPORTED_ON_FS(FAN_CLASS_NOTIF|FAN_REPORT_FID,
 						FAN_MARK_FILESYSTEM,
 						FAN_ATTRIB, ".");
Signature · 5 lines
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v2 3/7
#5 lore raw

Re: [LTP] [PATCH v2 3/7] fanotify: Provide fanotify_mark_supported_on_fs()

Quoted 7 lines · Jan Kara

Provide helper checking whether a mark is supported on a filesystem since some marks need not be available on all filesystems (e.g. btrfs subvolumes). Also convert REQUIRE_MARK_TYPE_SUPPORTED_BY_KERNEL() and its only user to use this new function.

Quoted 58 lines
---
 testcases/kernel/syscalls/fanotify/fanotify.h   | 11 ++++++++---
 testcases/kernel/syscalls/fanotify/fanotify23.c |  2 +-
 2 files changed, 9 insertions(+), 4 deletions(-)
testcases/kernel/syscalls/fanotify/fanotify.h +8 -3
index 3b8838e8dd68..597ed96e0313 100644
@@ -229,6 +229,11 @@ static inline int fanotify_init_flags_supported_by_kernel(unsigned int flags)
        return fanotify_init_flags_supported_on_fs(flags, NULL);
 }
 
+static inline int fanotify_mark_supported_on_fs(uint64_t flag, const char *fname)
+{
+       return fanotify_flags_supported_on_fs(FAN_CLASS_NOTIF, flag, FAN_ACCESS, fname);
+}
+
 #define TST_FANOTIFY_INIT_KNOWN_FLAGS                                      \
        (FAN_REPORT_DFID_NAME_TARGET | FAN_REPORT_TID | FAN_REPORT_PIDFD | \
        FAN_CLASS_NOTIF | FAN_CLASS_CONTENT | FAN_CLASS_PRE_CONTENT)
@@ -336,9 +341,9 @@ static inline int fanotify_handle_supported_by_kernel(int flag)
        return 0;
 }
 
-#define REQUIRE_MARK_TYPE_SUPPORTED_BY_KERNEL(mark_type) \
+#define REQUIRE_MARK_TYPE_SUPPORTED_ON_FS(mark_type, fname) \
        fanotify_flags_err_msg(#mark_type, __FILE__, __LINE__, tst_brk_, \
-               fanotify_mark_supported_by_kernel(mark_type))
+               fanotify_mark_supported_on_fs(mark_type, fname))
 
 #define REQUIRE_HANDLE_TYPE_SUPPORTED_BY_KERNEL(handle_type) \
        fanotify_flags_err_msg(#handle_type, __FILE__, __LINE__, tst_brk_, \
@@ -346,7 +351,7 @@ static inline int fanotify_handle_supported_by_kernel(int flag)
 
 #define REQUIRE_FANOTIFY_EVENTS_SUPPORTED_ON_FS(init_flags, mark_type, mask, fname) do { \
        if (mark_type)                                                  \
-               REQUIRE_MARK_TYPE_SUPPORTED_BY_KERNEL(mark_type);       \
+               REQUIRE_MARK_TYPE_SUPPORTED_ON_FS(mark_type, fname);    \
        if (init_flags)                                                 \
                REQUIRE_FANOTIFY_INIT_FLAGS_SUPPORTED_ON_FS(init_flags, fname); \
        fanotify_flags_err_msg(#mask, __FILE__, __LINE__, tst_brk_, \
testcases/kernel/syscalls/fanotify/fanotify23.c +1 -2
index fb812c51e34e..5a03503e952a 100644
@@ -230,7 +230,7 @@ static void setup(void)
 {
        SAFE_TOUCH(TEST_FILE, 0666, NULL);
 
-       REQUIRE_MARK_TYPE_SUPPORTED_BY_KERNEL(FAN_MARK_EVICTABLE);
+       REQUIRE_MARK_TYPE_SUPPORTED_ON_FS(FAN_MARK_EVICTABLE, ".");
        REQUIRE_FANOTIFY_EVENTS_SUPPORTED_ON_FS(FAN_CLASS_NOTIF|FAN_REPORT_FID,
                                                FAN_MARK_FILESYSTEM,
                                                FAN_ATTRIB, ".");
--

2.35.3

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
author
#6 lore raw

PATCH v2 4/7 fanotify: Switch event and mark tests to *_on_fs() variant

In reply to Jan Kara

Switch event availability and mark type availability tests to be performed on the filesystem actually used for testing instead of on the current directory. This is more reliable as not all filesystems support the same set of features.

---
 testcases/kernel/syscalls/fanotify/fanotify.h   |  2 +-
 testcases/kernel/syscalls/fanotify/fanotify01.c |  2 +-
 testcases/kernel/syscalls/fanotify/fanotify03.c |  7 ++++---
 testcases/kernel/syscalls/fanotify/fanotify09.c |  3 ++-
 testcases/kernel/syscalls/fanotify/fanotify10.c | 13 ++++++++-----
 testcases/kernel/syscalls/fanotify/fanotify11.c |  2 +-
 testcases/kernel/syscalls/fanotify/fanotify12.c |  5 ++---
 testcases/kernel/syscalls/fanotify/fanotify13.c |  3 ++-
 testcases/kernel/syscalls/fanotify/fanotify14.c |  3 ++-
 testcases/kernel/syscalls/fanotify/fanotify16.c |  3 ++-
 10 files changed, 25 insertions(+), 18 deletions(-)
testcases/kernel/syscalls/fanotify/fanotify.h +1 -1
index 597ed96e0313..1c30a0bcab2a 100644
@@ -355,7 +355,7 @@ static inline int fanotify_handle_supported_by_kernel(int flag)
 	if (init_flags)							\
 		REQUIRE_FANOTIFY_INIT_FLAGS_SUPPORTED_ON_FS(init_flags, fname); \
 	fanotify_flags_err_msg(#mask, __FILE__, __LINE__, tst_brk_, \
-		fanotify_events_supported_by_kernel(mask, init_flags, mark_type)); \
+		fanotify_flags_supported_on_fs(init_flags, mark_type, mask, fname)); \
 } while (0)
 
 static inline struct fanotify_event_info_header *get_event_info(
testcases/kernel/syscalls/fanotify/fanotify01.c +1 -1
index 3538335c9ab0..5ce1dc76ac8c 100644
@@ -341,7 +341,7 @@ static void setup(void)
 	SAFE_FILE_PRINTF(fname, "1");
 
 	fan_report_fid_unsupported = fanotify_init_flags_supported_on_fs(FAN_REPORT_FID, fname);
-	filesystem_mark_unsupported = fanotify_mark_supported_by_kernel(FAN_MARK_FILESYSTEM);
+	filesystem_mark_unsupported = fanotify_mark_supported_on_fs(FAN_MARK_FILESYSTEM, fname);
 }
 
 static void cleanup(void)
testcases/kernel/syscalls/fanotify/fanotify03.c +4 -3
index 0bd61587a9eb..343ba857e1ae 100644
@@ -322,12 +322,13 @@ static void setup(void)
 {
 	require_fanotify_access_permissions_supported_by_kernel();
 
-	filesystem_mark_unsupported = fanotify_mark_supported_by_kernel(FAN_MARK_FILESYSTEM);
-	exec_events_unsupported = fanotify_events_supported_by_kernel(FAN_OPEN_EXEC_PERM,
-								      FAN_CLASS_CONTENT, 0);
 	sprintf(fname, MOUNT_PATH"/fname_%d", getpid());
 	SAFE_FILE_PRINTF(fname, "1");
 
+	filesystem_mark_unsupported = fanotify_mark_supported_on_fs(FAN_MARK_FILESYSTEM, fname);
+	exec_events_unsupported = fanotify_flags_supported_on_fs(FAN_CLASS_CONTENT,
+					0, FAN_OPEN_EXEC_PERM, fname);
+
 	SAFE_CP(TEST_APP, FILE_EXEC_PATH);
 }
 
testcases/kernel/syscalls/fanotify/fanotify09.c +2 -1
index 3f2db47093c8..6bb1b9e7036f 100644
@@ -482,7 +482,8 @@ static void setup(void)
 {
 	fan_report_dfid_unsupported = fanotify_init_flags_supported_on_fs(FAN_REPORT_DFID_NAME,
 									  MOUNT_PATH);
-	ignore_mark_unsupported = fanotify_mark_supported_by_kernel(FAN_MARK_IGNORE_SURV);
+	ignore_mark_unsupported = fanotify_mark_supported_on_fs(FAN_MARK_IGNORE_SURV,
+								MOUNT_PATH);
 
 	SAFE_MKDIR(MOUNT_NAME, 0755);
 	SAFE_MOUNT(MOUNT_PATH, MOUNT_NAME, "none", MS_BIND, NULL);
testcases/kernel/syscalls/fanotify/fanotify10.c +8 -5
index d0e9194e7a58..f30eba9ecbfb 100644
@@ -874,11 +874,14 @@ static void setup(void)
 {
 	int i;
 
-	exec_events_unsupported = fanotify_events_supported_by_kernel(FAN_OPEN_EXEC,
-								      FAN_CLASS_CONTENT, 0);
-	filesystem_mark_unsupported = fanotify_mark_supported_by_kernel(FAN_MARK_FILESYSTEM);
-	evictable_mark_unsupported = fanotify_mark_supported_by_kernel(FAN_MARK_EVICTABLE);
-	ignore_mark_unsupported = fanotify_mark_supported_by_kernel(FAN_MARK_IGNORE_SURV);
+	exec_events_unsupported = fanotify_flags_supported_on_fs(FAN_CLASS_CONTENT,
+					0, FAN_OPEN_EXEC, MOUNT_PATH);
+	filesystem_mark_unsupported = fanotify_mark_supported_on_fs(FAN_MARK_FILESYSTEM,
+								    MOUNT_PATH);
+	evictable_mark_unsupported = fanotify_mark_supported_on_fs(FAN_MARK_EVICTABLE,
+								   MOUNT_PATH);
+	ignore_mark_unsupported = fanotify_mark_supported_on_fs(FAN_MARK_IGNORE_SURV,
+								MOUNT_PATH);
 	fan_report_dfid_unsupported = fanotify_init_flags_supported_on_fs(FAN_REPORT_DFID_NAME,
 									  MOUNT_PATH);
 	if (fan_report_dfid_unsupported) {
testcases/kernel/syscalls/fanotify/fanotify11.c +1 -1
index 03583d84be9b..ce46913b179e 100644
@@ -94,7 +94,7 @@ static void test01(unsigned int i)
 
 static void setup(void)
 {
-	fan_report_tid_unsupported = fanotify_init_flags_supported_by_kernel(FAN_REPORT_TID);
+	fan_report_tid_unsupported = fanotify_init_flags_supported_on_fs(FAN_REPORT_TID, ".");
 }
 
 static struct tst_test test = {
testcases/kernel/syscalls/fanotify/fanotify12.c +2 -3
index 7f8e97b178bc..42ba08800ccf 100644
@@ -222,11 +222,10 @@ cleanup:
 
 static void do_setup(void)
 {
-	exec_events_unsupported = fanotify_events_supported_by_kernel(FAN_OPEN_EXEC,
-								      FAN_CLASS_NOTIF, 0);
-
 	sprintf(fname, "fname_%d", getpid());
 	SAFE_FILE_PRINTF(fname, "1");
+	exec_events_unsupported = fanotify_flags_supported_on_fs(FAN_CLASS_NOTIF,
+					0, FAN_OPEN_EXEC, fname);
 }
 
 static void do_cleanup(void)
testcases/kernel/syscalls/fanotify/fanotify13.c +2 -1
index 421a3636f834..fdde3b10d1dd 100644
@@ -325,7 +325,8 @@ static void do_setup(void)
 	SAFE_MOUNT(mnt, MOUNT_PATH, "none", MS_BIND, NULL);
 	bind_mounted = 1;
 
-	filesystem_mark_unsupported = fanotify_mark_supported_by_kernel(FAN_MARK_FILESYSTEM);
+	filesystem_mark_unsupported = fanotify_mark_supported_on_fs(FAN_MARK_FILESYSTEM,
+								    MOUNT_PATH);
 
 	nofid_fd = SAFE_FANOTIFY_INIT(FAN_CLASS_NOTIF, O_RDONLY);
 
testcases/kernel/syscalls/fanotify/fanotify14.c +2 -1
index 0bb78918824b..0e24e0335ae3 100644
@@ -325,7 +325,8 @@ static void do_setup(void)
 	supported_init_flags = fanotify_get_supported_init_flags(all_init_flags,
 		MNTPOINT);
 
-	ignore_mark_unsupported = fanotify_mark_supported_by_kernel(FAN_MARK_IGNORE_SURV);
+	ignore_mark_unsupported = fanotify_mark_supported_on_fs(FAN_MARK_IGNORE_SURV,
+								MNTPOINT);
 
 	/* Create temporary test file to place marks on */
 	SAFE_FILE_PRINTF(FILE1, "0");
testcases/kernel/syscalls/fanotify/fanotify16.c +2 -1
index d45270a9a06e..dfa4edf0319e 100644
@@ -766,7 +766,8 @@ static void setup(void)
 	fan_report_target_fid_unsupported =
 		fanotify_init_flags_supported_on_fs(FAN_REPORT_DFID_NAME_TARGET, MOUNT_PATH);
 	rename_events_unsupported =
-		fanotify_events_supported_by_kernel(FAN_RENAME, FAN_REPORT_DFID_NAME, 0);
+		fanotify_flags_supported_on_fs(FAN_REPORT_DFID_NAME, 0,
+					       FAN_RENAME, MOUNT_PATH);
 
 	SAFE_MKDIR(TEMP_DIR, 0755);
 	sprintf(dname1, "%s/%s", MOUNT_PATH, DIR_NAME1);
Signature · 5 lines
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
author
#7 lore raw

PATCH v2 5/7 fanotify: Drop unused feature test macros

In reply to Jan Kara

Drop now unused feature test macros
fanotify_events_supported_by_kernel() and
fanotify_mark_supported_by_kernel().

---
 testcases/kernel/syscalls/fanotify/fanotify.h | 44 -------------------
 1 file changed, 44 deletions(-)
testcases/kernel/syscalls/fanotify/fanotify.h +0 -44
index 1c30a0bcab2a..d49966810381 100644
@@ -152,29 +152,6 @@ static inline void require_fanotify_access_permissions_supported_by_kernel(void)
 	SAFE_CLOSE(fd);
 }
 
-static inline int fanotify_events_supported_by_kernel(uint64_t mask,
-						      unsigned int init_flags,
-						      unsigned int mark_flags)
-{
-	int fd;
-	int rval = 0;
-
-	fd = SAFE_FANOTIFY_INIT(init_flags, O_RDONLY);
-
-	if (fanotify_mark(fd, FAN_MARK_ADD | mark_flags, mask, AT_FDCWD, ".") < 0) {
-		if (errno == EINVAL) {
-			rval = -1;
-		} else {
-			tst_brk(TBROK | TERRNO,
-				"fanotify_mark (%d, FAN_MARK_ADD, ..., AT_FDCWD, \".\") failed", fd);
-		}
-	}
-
-	SAFE_CLOSE(fd);
-
-	return rval;
-}
-
 /*
  * @return  0: fanotify flags supported both in kernel and on tested filesystem
  * @return -1: @init_flags not supported in kernel
@@ -307,27 +284,6 @@ static inline void fanotify_flags_err_msg(const char *flags_str,
 	fanotify_flags_err_msg(#flags, __FILE__, __LINE__, tst_brk_, \
 		fanotify_init_flags_supported_by_kernel(flags))
 
-static inline int fanotify_mark_supported_by_kernel(uint64_t flag)
-{
-	int fd;
-	int rval = 0;
-
-	fd = SAFE_FANOTIFY_INIT(FAN_CLASS_CONTENT, O_RDONLY);
-
-	if (fanotify_mark(fd, FAN_MARK_ADD | flag, FAN_ACCESS, AT_FDCWD, ".") < 0) {
-		if (errno == EINVAL) {
-			rval = -1;
-		} else {
-			tst_brk(TBROK | TERRNO,
-				"fanotify_mark (%d, FAN_MARK_ADD, ..., FAN_ACCESS, AT_FDCWD, \".\") failed", fd);
-		}
-	}
-
-	SAFE_CLOSE(fd);
-
-	return rval;
-}
-
 static inline int fanotify_handle_supported_by_kernel(int flag)
 {
 	/*
Signature · 5 lines
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
author
#8 lore raw

PATCH v2 6/7 fanotify: Convert remaining init_flags tests to be performed on target fs

In reply to Jan Kara

Convert remaining tests using REQUIRE_FANOTIFY_INIT_FLAGS_SUPPORTED_BY_KERNEL to be performed on target filesystem using REQUIRE_FANOTIFY_INIT_FLAGS_SUPPORTED_ON_FS and remove the now unused macro and functions.

---
 testcases/kernel/syscalls/fanotify/fanotify.h   | 9 ---------
 testcases/kernel/syscalls/fanotify/fanotify20.c | 3 ++-
 testcases/kernel/syscalls/fanotify/fanotify21.c | 3 ++-
 3 files changed, 4 insertions(+), 11 deletions(-)
testcases/kernel/syscalls/fanotify/fanotify.h +0 -9
index d49966810381..66b1b5e4141a 100644
@@ -201,11 +201,6 @@ static inline int fanotify_init_flags_supported_on_fs(unsigned int flags, const
 	return fanotify_flags_supported_on_fs(flags, FAN_MARK_INODE, FAN_ACCESS, fname);
 }
 
-static inline int fanotify_init_flags_supported_by_kernel(unsigned int flags)
-{
-	return fanotify_init_flags_supported_on_fs(flags, NULL);
-}
-
 static inline int fanotify_mark_supported_on_fs(uint64_t flag, const char *fname)
 {
 	return fanotify_flags_supported_on_fs(FAN_CLASS_NOTIF, flag, FAN_ACCESS, fname);
@@ -280,10 +275,6 @@ static inline void fanotify_flags_err_msg(const char *flags_str,
 	fanotify_flags_err_msg(#flags, __FILE__, __LINE__, tst_brk_, \
 		fanotify_init_flags_supported_on_fs(flags, fname))
 
-#define REQUIRE_FANOTIFY_INIT_FLAGS_SUPPORTED_BY_KERNEL(flags) \
-	fanotify_flags_err_msg(#flags, __FILE__, __LINE__, tst_brk_, \
-		fanotify_init_flags_supported_by_kernel(flags))
-
 static inline int fanotify_handle_supported_by_kernel(int flag)
 {
 	/*
testcases/kernel/syscalls/fanotify/fanotify20.c +2 -1
index 71310fb86e9e..1d249ac9cfcc 100644
@@ -50,7 +50,8 @@ static void do_setup(void)
 	 * An explicit check for FAN_REPORT_PIDFD is performed early on in the
 	 * test initialization as it's a prerequisite for all test cases.
 	 */
-	REQUIRE_FANOTIFY_INIT_FLAGS_SUPPORTED_BY_KERNEL(FAN_REPORT_PIDFD);
+	REQUIRE_FANOTIFY_INIT_FLAGS_SUPPORTED_ON_FS(FAN_REPORT_PIDFD,
+						    MOUNT_PATH);
 }
 
 static void do_test(unsigned int i)
testcases/kernel/syscalls/fanotify/fanotify21.c +2 -1
index 8a1028086237..d54930f05161 100644
@@ -119,7 +119,8 @@ static void do_setup(void)
 	 * on in the test initialization as it's a prerequisite for
 	 * all test cases.
 	 */
-	REQUIRE_FANOTIFY_INIT_FLAGS_SUPPORTED_BY_KERNEL(FAN_REPORT_PIDFD);
+	REQUIRE_FANOTIFY_INIT_FLAGS_SUPPORTED_ON_FS(FAN_REPORT_PIDFD,
+						    TEST_FILE);
 
 	fanotify_fd = SAFE_FANOTIFY_INIT(FAN_REPORT_PIDFD, O_RDONLY);
 	SAFE_FANOTIFY_MARK(fanotify_fd, FAN_MARK_ADD, FAN_OPEN, AT_FDCWD,
Signature · 5 lines
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
author
#9 lore raw

PATCH v2 7/7 fanotify: Convert permission events feature check to be performed on fs

In reply to Jan Kara

Convert feature check for availability of permission events to be performed on the tested filesystem.

---
 testcases/kernel/syscalls/fanotify/fanotify.h   | 5 +++--
 testcases/kernel/syscalls/fanotify/fanotify03.c | 3 +--
 testcases/kernel/syscalls/fanotify/fanotify07.c | 3 +--
 3 files changed, 5 insertions(+), 6 deletions(-)
testcases/kernel/syscalls/fanotify/fanotify.h +3 -2
index 66b1b5e4141a..e0d178bcc7b3 100644
@@ -133,13 +133,14 @@ static inline int fanotify_save_fid(const char *path,
 #define INIT_FANOTIFY_MARK_TYPE(t) \
 	{ FAN_MARK_ ## t, "FAN_MARK_" #t }
 
-static inline void require_fanotify_access_permissions_supported_by_kernel(void)
+static inline void require_fanotify_access_permissions_supported_on_fs(
+							const char *fname)
 {
 	int fd;
 
 	fd = SAFE_FANOTIFY_INIT(FAN_CLASS_CONTENT, O_RDONLY);
 
-	if (fanotify_mark(fd, FAN_MARK_ADD, FAN_ACCESS_PERM, AT_FDCWD, ".") < 0) {
+	if (fanotify_mark(fd, FAN_MARK_ADD, FAN_ACCESS_PERM, AT_FDCWD, fname) < 0) {
 		if (errno == EINVAL) {
 			tst_brk(TCONF | TERRNO,
 				"CONFIG_FANOTIFY_ACCESS_PERMISSIONS not configured in kernel?");
testcases/kernel/syscalls/fanotify/fanotify03.c +1 -2
index 343ba857e1ae..028da742c76c 100644
@@ -320,11 +320,10 @@ static void test_fanotify(unsigned int n)
 
 static void setup(void)
 {
-	require_fanotify_access_permissions_supported_by_kernel();
-
 	sprintf(fname, MOUNT_PATH"/fname_%d", getpid());
 	SAFE_FILE_PRINTF(fname, "1");
 
+	require_fanotify_access_permissions_supported_on_fs(fname);
 	filesystem_mark_unsupported = fanotify_mark_supported_on_fs(FAN_MARK_FILESYSTEM, fname);
 	exec_events_unsupported = fanotify_flags_supported_on_fs(FAN_CLASS_CONTENT,
 					0, FAN_OPEN_EXEC_PERM, fname);
testcases/kernel/syscalls/fanotify/fanotify07.c +1 -2
index 396c8490eeda..34aa810c7dac 100644
@@ -189,10 +189,9 @@ static void test_fanotify(void)
 
 static void setup(void)
 {
-	require_fanotify_access_permissions_supported_by_kernel();
-
 	sprintf(fname, "fname_%d", getpid());
 	SAFE_FILE_PRINTF(fname, "%s", fname);
+	require_fanotify_access_permissions_supported_on_fs(fname);
 }
 
 static void cleanup(void)
Signature · 5 lines
2.35.3


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