Skip to content

Commit 40abb10

Browse files
amir73ilpevik
authored andcommitted
fanotify13: Verify that we did not get an extra event
For example, verify that we did not get an event on a directory object without requesting FAN_ONDIR. Also, report a test failure if no events received at all instead of blocking on read of fanotify_fd. With this change, the test fails with overlayfs variants over btrfs, because the size of fid of overalyfs over btrfs is about 90 bytes and the events on the three objects do not all fit into a single 256 bytes buffer read. Increase the size of the events buffer to fix this failure. Link: https://lore.kernel.org/ltp/[email protected]/ Reviewed-by: Petr Vorel <[email protected]> Signed-off-by: Amir Goldstein <[email protected]>
1 parent a7c31df commit 40abb10

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

testcases/kernel/syscalls/fanotify/fanotify13.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@
3434
#include "fanotify.h"
3535

3636
#define PATH_LEN 128
37-
#define BUF_SIZE 256
37+
#define BUF_SIZE 1024
3838
#define DIR_ONE "dir_one"
3939
#define FILE_ONE "file_one"
4040
#define FILE_TWO "file_two"
4141
#define MOUNT_PATH "tstmnt"
42-
#define EVENT_MAX ARRAY_SIZE(objects)
42+
#define EVENT_MAX (ARRAY_SIZE(objects)+1)
4343
#define DIR_PATH_ONE MOUNT_PATH"/"DIR_ONE
4444
#define FILE_PATH_ONE MOUNT_PATH"/"FILE_ONE
4545
#define FILE_PATH_TWO MOUNT_PATH"/"FILE_TWO
@@ -130,10 +130,15 @@ static int setup_marks(unsigned int fd, struct test_case_t *tc)
130130
SAFE_FANOTIFY_MARK(fd, FAN_MARK_ADD | mark->flag, tc->mask,
131131
AT_FDCWD, objects[i].path);
132132

133-
/* Setup the expected mask for each generated event */
133+
/*
134+
* Setup the expected mask for each generated event.
135+
* No events are expected on directory without FAN_ONDIR.
136+
*/
134137
event_set[i].expected_mask = tc->mask;
135138
if (!objects[i].is_dir)
136139
event_set[i].expected_mask &= ~FAN_ONDIR;
140+
else if (!(event_set[i].expected_mask & FAN_ONDIR))
141+
event_set[i].expected_mask = 0;
137142
}
138143
return 0;
139144
}
@@ -163,7 +168,8 @@ static void do_test(unsigned int number)
163168
return;
164169
}
165170

166-
fanotify_fd = SAFE_FANOTIFY_INIT(FAN_CLASS_NOTIF | FAN_REPORT_FID, O_RDONLY);
171+
fanotify_fd = SAFE_FANOTIFY_INIT(FAN_CLASS_NOTIF | FAN_REPORT_FID |
172+
FAN_NONBLOCK, O_RDONLY);
167173

168174
/*
169175
* Place marks on a set of objects and setup the expected masks
@@ -279,6 +285,16 @@ static void do_test(unsigned int number)
279285
FSID_VAL_MEMBER(event_fid->fsid, 1),
280286
*(unsigned long *) event_file_handle->f_handle);
281287
}
288+
289+
/*
290+
* Verify that we did not get an extra event, for example, that we did
291+
* not get an event on directory without FAN_ONDIR.
292+
*/
293+
if (event_set[i].expected_mask) {
294+
tst_res(TFAIL,
295+
"Did not get an expected event (expected: %llx)",
296+
event_set[i].expected_mask);
297+
}
282298
out:
283299
SAFE_CLOSE(fanotify_fd);
284300
}

0 commit comments

Comments
 (0)