Skip to content

Commit 359047c

Browse files
amir73ilpevik
authored andcommitted
fanotify01: Test setting two marks on different filesystems
When tested fs has zero fsid (e.g. fuse) and events are reported with fsid+fid, watching different filesystems with the same group is not supported. Try to setup a bogus mark on test tmp dir, in addition to the mark on the tested filesystem, to check if marks on different filesystems are supported. Run on all filesystem to test both fs with zero fsid (e.g. fuse) and fs with valid fsid. Link: https://lore.kernel.org/ltp/20240125110510.751445-1-amir73il@gmail.com/ Reviewed-by: Jan Kara <jack@suse.cz> Reviewed-by: Petr Vorel <pvorel@suse.cz> Signed-off-by: Amir Goldstein <amir73il@gmail.com>
1 parent 7118786 commit 359047c

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

testcases/kernel/syscalls/fanotify/fanotify.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,20 +166,23 @@ static inline int fanotify_flags_supported_on_fs(unsigned int init_flags,
166166
{
167167
int fd;
168168
int rval = 0;
169+
int err = 0;
169170

170171
fd = fanotify_init(init_flags, O_RDONLY);
171-
172172
if (fd < 0) {
173+
err = errno;
173174
if (errno == ENOSYS)
174175
tst_brk(TCONF, "fanotify not configured in kernel");
175176
if (errno != EINVAL)
176177
tst_brk(TBROK | TERRNO,
177178
"fanotify_init(%x, O_RDONLY) failed",
178179
init_flags);
180+
errno = err;
179181
return -1;
180182
}
181183

182184
if (fname && fanotify_mark(fd, FAN_MARK_ADD | mark_flags, event_flags, AT_FDCWD, fname) < 0) {
185+
err = errno;
183186
if (errno == ENODEV || errno == EOPNOTSUPP || errno == EXDEV) {
184187
rval = strcmp(fname, OVL_MNT) ? -2 : -3;
185188
} else if (errno != EINVAL) {
@@ -194,6 +197,7 @@ static inline int fanotify_flags_supported_on_fs(unsigned int init_flags,
194197

195198
SAFE_CLOSE(fd);
196199

200+
errno = err;
197201
return rval;
198202
}
199203

testcases/kernel/syscalls/fanotify/fanotify01.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ static char buf[BUF_SIZE];
7777
static int fd_notify;
7878
static int fan_report_fid_unsupported;
7979
static int mount_mark_fid_unsupported;
80+
static int inode_mark_fid_xdev;
8081
static int filesystem_mark_unsupported;
8182

8283
static unsigned long long event_set[EVENT_MAX];
@@ -328,6 +329,17 @@ static void test_fanotify(unsigned int n)
328329

329330
}
330331

332+
333+
/*
334+
* Try to setup a bogus mark on test tmp dir, to check if marks on
335+
* different filesystems are supported.
336+
* When tested fs has zero fsid (e.g. fuse) and events are reported
337+
* with fsid+fid, watching different filesystems is not supported.
338+
*/
339+
ret = report_fid ? inode_mark_fid_xdev : 0;
340+
TST_EXP_FD_OR_FAIL(fanotify_mark(fd_notify, FAN_MARK_ADD, FAN_CLOSE_WRITE,
341+
AT_FDCWD, "."), ret);
342+
331343
/* Remove mark to clear FAN_MARK_IGNORED_SURV_MODIFY */
332344
SAFE_FANOTIFY_MARK(fd_notify, FAN_MARK_REMOVE | mark->flag,
333345
FAN_ACCESS | FAN_MODIFY | FAN_CLOSE | FAN_OPEN,
@@ -352,6 +364,20 @@ static void setup(void)
352364
mount_mark_fid_unsupported = fanotify_flags_supported_on_fs(FAN_REPORT_FID,
353365
FAN_MARK_MOUNT,
354366
FAN_OPEN, fname);
367+
/*
368+
* When mount mark is not supported due to zero fsid (e.g. fuse) or if TMPDIR has
369+
* non-uniform fsid (e.g. btrfs subvol), multi fs inode marks are not supported.
370+
*/
371+
if (mount_mark_fid_unsupported && errno == ENODEV) {
372+
tst_res(TINFO, "filesystem %s does not support reporting events with fid from multi fs",
373+
tst_device->fs_type);
374+
inode_mark_fid_xdev = EXDEV;
375+
}
376+
377+
if (fanotify_flags_supported_on_fs(FAN_REPORT_FID, FAN_MARK_MOUNT, FAN_OPEN, ".")) {
378+
inode_mark_fid_xdev = errno;
379+
tst_res(TINFO, "TMPDIR does not support reporting events with fid from multi fs");
380+
}
355381
}
356382

357383
static void cleanup(void)
@@ -368,6 +394,7 @@ static struct tst_test test = {
368394
.needs_root = 1,
369395
.mount_device = 1,
370396
.mntpoint = MOUNT_PATH,
397+
.all_filesystems = 1,
371398
};
372399

373400
#else

0 commit comments

Comments
 (0)