Skip to content

Commit a88612f

Browse files
amir73ilpevik
authored andcommitted
fanotify13: Add test case for FAN_DELETE_SELF
Verify that FAN_DELETE_SELF on overlayfs reports a valid file handle. This was fixed in v6.13-rc7 and backported to v6.12.10 and v6.6.74. Link: https://lore.kernel.org/ltp/[email protected]/ Reviewed-by: Petr Vorel <[email protected]> Signed-off-by: Amir Goldstein <[email protected]>
1 parent 40abb10 commit a88612f

File tree

1 file changed

+57
-11
lines changed

1 file changed

+57
-11
lines changed

testcases/kernel/syscalls/fanotify/fanotify13.c

Lines changed: 57 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@
1515
/*
1616
* This is also regression test for:
1717
* c285a2f01d69 ("fanotify: update connector fsid cache on add mark")
18+
*
19+
* The test variants 1-2 are regression tests for:
20+
* bc2473c90fca ("ovl: enable fsnotify events on underlying real files")
21+
*
22+
* The test variants 3-4 are tests for overlay fid events supprted since v6.6:
23+
* 16aac5ad1fa9 ("ovl: support encoding non-decodable file handles")
24+
*
25+
* The last test case for FAN_DELETE_SELF is a regression test for:
26+
* c45beebfde34a ("ovl: support encoding fid from inode with no alias")
1827
*/
1928

2029
#define _GNU_SOURCE
@@ -86,7 +95,12 @@ static struct test_case_t {
8695
{
8796
INIT_FANOTIFY_MARK_TYPE(FILESYSTEM),
8897
FAN_OPEN | FAN_CLOSE_NOWRITE | FAN_ONDIR
89-
}
98+
},
99+
/* Keep this test case last because it deletes the test files */
100+
{
101+
INIT_FANOTIFY_MARK_TYPE(INODE),
102+
FAN_DELETE_SELF | FAN_ONDIR
103+
},
90104
};
91105

92106
static int ovl_mounted;
@@ -111,6 +125,18 @@ static void create_objects(void)
111125
}
112126
}
113127

128+
static void delete_objects(void)
129+
{
130+
unsigned int i;
131+
132+
for (i = 0; i < ARRAY_SIZE(objects); i++) {
133+
if (objects[i].is_dir)
134+
SAFE_RMDIR(objects[i].path);
135+
else
136+
SAFE_UNLINK(objects[i].path);
137+
}
138+
}
139+
114140
static void get_object_stats(void)
115141
{
116142
unsigned int i;
@@ -155,8 +181,10 @@ static void do_test(unsigned int number)
155181
struct fanotify_mark_type *mark = &tc->mark;
156182

157183
tst_res(TINFO,
158-
"Test #%d.%d: FAN_REPORT_FID with mark flag: %s",
159-
number, tst_variant, mark->name);
184+
"Test #%d.%d: FAN_REPORT_FID of %s events with mark type %s",
185+
number, tst_variant,
186+
(tc->mask & FAN_DELETE_SELF) ? "delete" : "open/close",
187+
mark->name);
160188

161189
if (tst_variant && !ovl_mounted) {
162190
tst_res(TCONF, "overlayfs not supported on %s", tst_device->fs_type);
@@ -184,23 +212,40 @@ static void do_test(unsigned int number)
184212
tst_res(TCONF, "overlayfs base fs cannot be watched with mount mark");
185213
goto out;
186214
}
215+
if (tc->mask & FAN_DELETE_SELF) {
216+
/* The eviction of base fs inodes is defered due to overlay held reference */
217+
tst_res(TCONF, "overlayfs base fs cannot be watched for delete self events");
218+
goto out;
219+
}
187220
SAFE_MOUNT(OVL_MNT, MOUNT_PATH, "none", MS_BIND, NULL);
188221
}
189222

190223
/* Generate sequence of FAN_OPEN events on objects */
191-
for (i = 0; i < ARRAY_SIZE(objects); i++)
192-
fds[i] = SAFE_OPEN(objects[i].path, O_RDONLY);
224+
if (tc->mask & FAN_OPEN) {
225+
for (i = 0; i < ARRAY_SIZE(objects); i++)
226+
fds[i] = SAFE_OPEN(objects[i].path, O_RDONLY);
227+
}
193228

194229
/*
195-
* Generate sequence of FAN_CLOSE_NOWRITE events on objects. Each
196-
* FAN_CLOSE_NOWRITE event is expected to be merged with its
197-
* respective FAN_OPEN event that was performed on the same object.
230+
* Generate sequence of FAN_CLOSE_NOWRITE events on objects.
231+
* Each FAN_CLOSE_NOWRITE event is expected to be merged with the
232+
* respective FAN_OPEN event that was reported on the same object.
198233
*/
199-
for (i = 0; i < ARRAY_SIZE(objects); i++) {
200-
if (fds[i] > 0)
201-
SAFE_CLOSE(fds[i]);
234+
if (tc->mask & FAN_CLOSE) {
235+
for (i = 0; i < ARRAY_SIZE(objects); i++) {
236+
if (fds[i] > 0)
237+
SAFE_CLOSE(fds[i]);
238+
}
202239
}
203240

241+
/*
242+
* Generate sequence of FAN_DELETE_SELF events on objects.
243+
* Each FAN_DELETE_SELF event is expected to be merged with the
244+
* respective OPEN/CLOSE events that were reported on the same object.
245+
*/
246+
if (tc->mask & FAN_DELETE_SELF)
247+
delete_objects();
248+
204249
if (tst_variant && !ovl_bind_mounted)
205250
SAFE_UMOUNT(MOUNT_PATH);
206251

@@ -392,6 +437,7 @@ static struct tst_test test = {
392437
.tags = (const struct tst_tag[]) {
393438
{"linux-git", "c285a2f01d69"},
394439
{"linux-git", "bc2473c90fca"},
440+
{"linux-git", "c45beebfde34a"},
395441
{}
396442
}
397443
};

0 commit comments

Comments
 (0)