Skip to content

Commit 5647a1f

Browse files
amir73ilpevik
authored andcommitted
fanotify05: Test reporting overflow event with FAN_REPORT_FD_ERROR
Expecting to get -EBADF instead of FAN_NOFD. Link: https://lore.kernel.org/ltp/[email protected]/ Reviewed-by: Petr Vorel <[email protected]> Signed-off-by: Amir Goldstein <[email protected]>
1 parent a88612f commit 5647a1f

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

include/lapi/fanotify.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
#define FAN_REPORT_DFID_NAME_TARGET (FAN_REPORT_DFID_NAME | \
3333
FAN_REPORT_FID | FAN_REPORT_TARGET_FID)
3434
#endif
35+
#ifndef FAN_REPORT_FD_ERROR
36+
#define FAN_REPORT_FD_ERROR 0x00002000
37+
#endif
38+
3539

3640
/* Non-uapi convenience macros */
3741
#ifndef FAN_REPORT_DFID_NAME_FID

testcases/kernel/syscalls/fanotify/fanotify.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ static inline int fanotify_mark_supported_on_fs(uint64_t flag, const char *fname
213213

214214
#define TST_FANOTIFY_INIT_KNOWN_FLAGS \
215215
(FAN_REPORT_DFID_NAME_TARGET | FAN_REPORT_TID | FAN_REPORT_PIDFD | \
216+
FAN_REPORT_FD_ERROR | \
216217
FAN_CLASS_NOTIF | FAN_CLASS_CONTENT | FAN_CLASS_PRE_CONTENT)
217218

218219
/*

testcases/kernel/syscalls/fanotify/fanotify05.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ static struct tcase {
5151
"Limited queue",
5252
FAN_CLASS_NOTIF,
5353
},
54+
{
55+
"Limited queue (FAN_REPORT_FD_ERROR)",
56+
FAN_CLASS_NOTIF | FAN_REPORT_FD_ERROR,
57+
},
5458
{
5559
"Unlimited queue",
5660
FAN_CLASS_NOTIF | FAN_UNLIMITED_QUEUE,
@@ -63,6 +67,8 @@ static char symlnk[BUF_SIZE];
6367
static char fdpath[BUF_SIZE];
6468
static int fd, fd_notify;
6569

70+
static int fd_error_unsupported;
71+
6672
static struct fanotify_event_metadata event;
6773

6874
static void event_res(struct fanotify_event_metadata *event, int i)
@@ -110,9 +116,15 @@ static void test_fanotify(unsigned int n)
110116
int len, nevents = 0, got_overflow = 0;
111117
int num_files = max_events + 1;
112118
int expect_overflow = !(tc->init_flags & FAN_UNLIMITED_QUEUE);
119+
int nofd_err = tc->init_flags & FAN_REPORT_FD_ERROR ? -EBADF : FAN_NOFD;
113120

114121
tst_res(TINFO, "Test #%d: %s", n, tc->tname);
115122

123+
if (fd_error_unsupported && (tc->init_flags & FAN_REPORT_FD_ERROR)) {
124+
FANOTIFY_INIT_FLAGS_ERR_MSG(FAN_REPORT_FD_ERROR, fd_error_unsupported);
125+
return;
126+
}
127+
116128
fd_notify = SAFE_FANOTIFY_INIT(tc->init_flags | FAN_NONBLOCK, O_RDONLY);
117129

118130
SAFE_FANOTIFY_MARK(fd_notify, FAN_MARK_MOUNT | FAN_MARK_ADD, FAN_OPEN,
@@ -142,7 +154,7 @@ static void test_fanotify(unsigned int n)
142154
tst_res(expect_overflow ? TFAIL : TPASS, "Overflow event not generated!\n");
143155
break;
144156
}
145-
if (event.fd != FAN_NOFD) {
157+
if (event.fd >= 0) {
146158
/*
147159
* Verify that events generated on unique files
148160
* are received by the same order they were generated.
@@ -166,7 +178,7 @@ static void test_fanotify(unsigned int n)
166178
break;
167179
}
168180
if (event.mask == FAN_Q_OVERFLOW) {
169-
if (got_overflow || event.fd != FAN_NOFD) {
181+
if (got_overflow || event.fd != nofd_err) {
170182
tst_res(TFAIL,
171183
"%s overflow event: mask=%llx pid=%u fd=%d",
172184
got_overflow ? "unexpected" : "invalid",
@@ -193,6 +205,8 @@ static void setup(void)
193205
fd = SAFE_FANOTIFY_INIT(FAN_CLASS_NOTIF, O_RDONLY);
194206
SAFE_CLOSE(fd);
195207

208+
fd_error_unsupported = fanotify_init_flags_supported_on_fs(FAN_REPORT_FD_ERROR, ".");
209+
196210
/* In older kernels this limit is fixed in kernel */
197211
if (access(SYSFS_MAX_EVENTS, F_OK) && errno == ENOENT)
198212
max_events = DEFAULT_MAX_EVENTS;

0 commit comments

Comments
 (0)