[LTP] [PATCH] fanotify01: Test setting two marks on different filesystems
Amir Goldstein
amir73il@gmail.com
Thu Jan 25 12:05:10 CET 2024
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.
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
Petr,
The fanotify tests changes that you already picked from my github [1]
have to do with fixing new test failures in v6.7 and v6.8-rc1, dues to
the fact that each of those kernel versions added new filesystems that
support fanotify events with fid+fsid.
This is the only change to test new functionality in v6.8-rc1, namely,
that for fs with zero fsid (e.g. fuse), an fanotify group can watch a
single fs instance.
To fix the problem that you reported with this test on exfat [2],
I needed to make a distiction between the fs that do not support mount
mark with fid due to having zero fsid (e.g. fuse) and those fs that
do not support decoding fid (e.g. exfat).
It is not urgent to merge this change to the upcoming code freeze -
it's up to you, but since I already tested it I am posting it now.
Thanks,
Amir.
[1] https://github.com/amir73il/ltp/commits/fanotify_fsid/
[2] https://lore.kernel.org/ltp/CAOQ4uxh1VwoMK_ssjdcxo_sk4cw0pD_FcXZ6Lb2=XHLf21kGAw@mail.gmail.com/T/#mf15d751e8f77a497ee4387b0791219e800cde7ea
testcases/kernel/syscalls/fanotify/fanotify.h | 6 +++++-
.../kernel/syscalls/fanotify/fanotify01.c | 19 +++++++++++++++++++
2 files changed, 24 insertions(+), 1 deletion(-)
diff --git a/testcases/kernel/syscalls/fanotify/fanotify.h b/testcases/kernel/syscalls/fanotify/fanotify.h
index e0d178bcc..554940a7e 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify.h
+++ b/testcases/kernel/syscalls/fanotify/fanotify.h
@@ -166,20 +166,23 @@ static inline int fanotify_flags_supported_on_fs(unsigned int init_flags,
{
int fd;
int rval = 0;
+ int err = 0;
fd = fanotify_init(init_flags, O_RDONLY);
-
if (fd < 0) {
+ err = errno;
if (errno == ENOSYS)
tst_brk(TCONF, "fanotify not configured in kernel");
if (errno != EINVAL)
tst_brk(TBROK | TERRNO,
"fanotify_init(%x, O_RDONLY) failed",
init_flags);
+ errno = err;
return -1;
}
if (fname && fanotify_mark(fd, FAN_MARK_ADD | mark_flags, event_flags, AT_FDCWD, fname) < 0) {
+ err = errno;
if (errno == ENODEV || errno == EOPNOTSUPP || errno == EXDEV) {
rval = strcmp(fname, OVL_MNT) ? -2 : -3;
} else if (errno != EINVAL) {
@@ -194,6 +197,7 @@ static inline int fanotify_flags_supported_on_fs(unsigned int init_flags,
SAFE_CLOSE(fd);
+ errno = err;
return rval;
}
diff --git a/testcases/kernel/syscalls/fanotify/fanotify01.c b/testcases/kernel/syscalls/fanotify/fanotify01.c
index e4398f236..ba09f309d 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify01.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify01.c
@@ -77,6 +77,7 @@ static char buf[BUF_SIZE];
static int fd_notify;
static int fan_report_fid_unsupported;
static int mount_mark_fid_unsupported;
+static int inode_mark_fid_xdev;
static int filesystem_mark_unsupported;
static unsigned long long event_set[EVENT_MAX];
@@ -328,6 +329,17 @@ pass:
}
+
+ /*
+ * Try to setup a bogus mark on test tmp dir, to check if marks on
+ * different filesystems are supported.
+ * When tested fs has zero fsid (e.g. fuse) and events are reported
+ * with fsid+fid, watching different filesystems is not supported.
+ */
+ ret = report_fid ? inode_mark_fid_xdev : 0;
+ TST_EXP_FD_OR_FAIL(fanotify_mark(fd_notify, FAN_MARK_ADD, FAN_CLOSE_WRITE,
+ AT_FDCWD, "."), ret);
+
/* Remove mark to clear FAN_MARK_IGNORED_SURV_MODIFY */
SAFE_FANOTIFY_MARK(fd_notify, FAN_MARK_REMOVE | mark->flag,
FAN_ACCESS | FAN_MODIFY | FAN_CLOSE | FAN_OPEN,
@@ -352,6 +364,12 @@ static void setup(void)
mount_mark_fid_unsupported = fanotify_flags_supported_on_fs(FAN_REPORT_FID,
FAN_MARK_MOUNT,
FAN_OPEN, fname);
+ /* When mount mark is not supported due to zero fsid, multi fs inode marks are not supported */
+ if (mount_mark_fid_unsupported && errno == ENODEV) {
+ tst_res(TINFO, "filesystem %s does not support reporting events with fid from multi fs",
+ tst_device->fs_type);
+ inode_mark_fid_xdev = EXDEV;
+ }
}
static void cleanup(void)
@@ -368,6 +386,7 @@ static struct tst_test test = {
.needs_root = 1,
.mount_device = 1,
.mntpoint = MOUNT_PATH,
+ .all_filesystems = 1,
};
#else
--
2.34.1
More information about the ltp
mailing list