From: Amir Goldstein <amir73il@gmail.com>
To: Petr Vorel <pvorel@suse.cz>
Cc: Jan Kara <jack@suse.cz>, ltp@lists.linux.it
Subject: [LTP] [PATCH 3/5] fanotify05: Test reporting overflow event with FAN_REPORT_FD_ERROR
Date: Wed, 22 Jan 2025 18:24:38 +0100 [thread overview]
Message-ID: <20250122172440.506677-4-amir73il@gmail.com> (raw)
In-Reply-To: <20250122172440.506677-1-amir73il@gmail.com>
Expecting to get -EBADF instead of FAN_NOFD.
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
include/lapi/fanotify.h | 4 ++++
testcases/kernel/syscalls/fanotify/fanotify.h | 1 +
.../kernel/syscalls/fanotify/fanotify05.c | 18 ++++++++++++++++--
3 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/include/lapi/fanotify.h b/include/lapi/fanotify.h
index 424514625..40ea7ead7 100644
--- a/include/lapi/fanotify.h
+++ b/include/lapi/fanotify.h
@@ -32,6 +32,10 @@
#define FAN_REPORT_DFID_NAME_TARGET (FAN_REPORT_DFID_NAME | \
FAN_REPORT_FID | FAN_REPORT_TARGET_FID)
#endif
+#ifndef FAN_REPORT_FD_ERROR
+#define FAN_REPORT_FD_ERROR 0x00002000
+#endif
+
/* Non-uapi convenience macros */
#ifndef FAN_REPORT_DFID_NAME_FID
diff --git a/testcases/kernel/syscalls/fanotify/fanotify.h b/testcases/kernel/syscalls/fanotify/fanotify.h
index 554940a7e..48a44cc7e 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify.h
+++ b/testcases/kernel/syscalls/fanotify/fanotify.h
@@ -213,6 +213,7 @@ static inline int fanotify_mark_supported_on_fs(uint64_t flag, const char *fname
#define TST_FANOTIFY_INIT_KNOWN_FLAGS \
(FAN_REPORT_DFID_NAME_TARGET | FAN_REPORT_TID | FAN_REPORT_PIDFD | \
+ FAN_REPORT_FD_ERROR | \
FAN_CLASS_NOTIF | FAN_CLASS_CONTENT | FAN_CLASS_PRE_CONTENT)
/*
diff --git a/testcases/kernel/syscalls/fanotify/fanotify05.c b/testcases/kernel/syscalls/fanotify/fanotify05.c
index 12c240881..f1a132cbf 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify05.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify05.c
@@ -51,6 +51,10 @@ static struct tcase {
"Limited queue",
FAN_CLASS_NOTIF,
},
+ {
+ "Limited queue (FAN_REPORT_FD_ERROR)",
+ FAN_CLASS_NOTIF | FAN_REPORT_FD_ERROR,
+ },
{
"Unlimited queue",
FAN_CLASS_NOTIF | FAN_UNLIMITED_QUEUE,
@@ -63,6 +67,8 @@ static char symlnk[BUF_SIZE];
static char fdpath[BUF_SIZE];
static int fd, fd_notify;
+static int fd_error_unsupported;
+
static struct fanotify_event_metadata event;
static void event_res(struct fanotify_event_metadata *event, int i)
@@ -110,9 +116,15 @@ static void test_fanotify(unsigned int n)
int len, nevents = 0, got_overflow = 0;
int num_files = max_events + 1;
int expect_overflow = !(tc->init_flags & FAN_UNLIMITED_QUEUE);
+ int nofd_err = tc->init_flags & FAN_REPORT_FD_ERROR ? -EBADF : FAN_NOFD;
tst_res(TINFO, "Test #%d: %s", n, tc->tname);
+ if (fd_error_unsupported && (tc->init_flags & FAN_REPORT_FD_ERROR)) {
+ FANOTIFY_INIT_FLAGS_ERR_MSG(FAN_REPORT_FD_ERROR, fd_error_unsupported);
+ return;
+ }
+
fd_notify = SAFE_FANOTIFY_INIT(tc->init_flags | FAN_NONBLOCK, O_RDONLY);
SAFE_FANOTIFY_MARK(fd_notify, FAN_MARK_MOUNT | FAN_MARK_ADD, FAN_OPEN,
@@ -142,7 +154,7 @@ static void test_fanotify(unsigned int n)
tst_res(expect_overflow ? TFAIL : TPASS, "Overflow event not generated!\n");
break;
}
- if (event.fd != FAN_NOFD) {
+ if (event.fd >= 0) {
/*
* Verify that events generated on unique files
* are received by the same order they were generated.
@@ -166,7 +178,7 @@ static void test_fanotify(unsigned int n)
break;
}
if (event.mask == FAN_Q_OVERFLOW) {
- if (got_overflow || event.fd != FAN_NOFD) {
+ if (got_overflow || event.fd != nofd_err) {
tst_res(TFAIL,
"%s overflow event: mask=%llx pid=%u fd=%d",
got_overflow ? "unexpected" : "invalid",
@@ -193,6 +205,8 @@ static void setup(void)
fd = SAFE_FANOTIFY_INIT(FAN_CLASS_NOTIF, O_RDONLY);
SAFE_CLOSE(fd);
+ fd_error_unsupported = fanotify_init_flags_supported_on_fs(FAN_REPORT_FD_ERROR, ".");
+
/* In older kernels this limit is fixed in kernel */
if (access(SYSFS_MAX_EVENTS, F_OK) && errno == ENOENT)
max_events = DEFAULT_MAX_EVENTS;
--
2.34.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2025-01-22 17:25 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-22 17:24 [LTP] [PATCH 0/5] LTP fanotify tests for v6.13 Amir Goldstein
2025-01-22 17:24 ` [LTP] [PATCH 1/5] fanotify13: Verify that we did not get an extra event Amir Goldstein
2025-01-23 17:18 ` Petr Vorel
2025-01-24 10:11 ` Petr Vorel
2025-01-24 10:33 ` Amir Goldstein
2025-01-24 12:45 ` Petr Vorel
2025-01-22 17:24 ` [LTP] [PATCH 2/5] fanotify13: Add test case for FAN_DELETE_SELF Amir Goldstein
2025-01-22 17:24 ` Amir Goldstein [this message]
2025-01-24 7:44 ` [LTP] [PATCH 3/5] fanotify05: Test reporting overflow event with FAN_REPORT_FD_ERROR Petr Vorel
2025-01-22 17:24 ` [LTP] [PATCH 4/5] fanotify21: Test reporting event with RDWR fd on RO mount Amir Goldstein
2025-01-24 8:01 ` Petr Vorel
2025-01-22 17:24 ` [LTP] [PATCH 5/5] fanotify21: Test reporting fd open errors with FAN_REPORT_FD_ERROR Amir Goldstein
2025-01-24 8:09 ` Petr Vorel
2025-01-22 20:50 ` [LTP] [PATCH 0/5] LTP fanotify tests for v6.13 Petr Vorel
2025-01-23 13:09 ` Amir Goldstein
2025-01-23 13:31 ` Cyril Hrubis
2025-01-24 10:46 ` Cyril Hrubis
2025-01-24 11:32 ` Petr Vorel
2025-01-30 20:07 ` Petr Vorel
2025-01-31 14:16 ` Amir Goldstein
2025-01-31 16:42 ` 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=20250122172440.506677-4-amir73il@gmail.com \
--to=amir73il@gmail.com \
--cc=jack@suse.cz \
--cc=ltp@lists.linux.it \
--cc=pvorel@suse.cz \
/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