* [LTP] [PATCH 0/2] fanotify LTP tests for v6.6 @ 2023-11-14 7:23 Amir Goldstein 2023-11-14 7:23 ` [LTP] [PATCH 1/2] fanotify13: Test overlayfs while watching lower fs Amir Goldstein 2023-11-14 7:23 ` [LTP] [PATCH 2/2] fanotify13: Test watching overlayfs with FAN_REPORT_FID Amir Goldstein 0 siblings, 2 replies; 7+ messages in thread From: Amir Goldstein @ 2023-11-14 7:23 UTC (permalink / raw) To: Petr Vorel; +Cc: ltp, Jan Kara, linux-unionfs, Miklos Szeredi Hi Petr, For v6.5, we added a new test variant to fanotify13, to test fanotify watching upper fs path while making changes to overlayfs. To increase test coverage, adding another test variant for watching lower fs path instad of upper fs path, which also runs on v6.5. Adding two new test variants for watching overlayfs paths. The new variants only run on v6.6 where overlayfs gained support for being watched by fanotify. Thanks, Amir. Amir Goldstein (2): fanotify13: Test overlayfs while watching lower fs fanotify13: Test watching overlayfs with FAN_REPORT_FID testcases/kernel/syscalls/fanotify/fanotify.h | 28 ++++++++--- .../kernel/syscalls/fanotify/fanotify13.c | 50 ++++++++++++++----- 2 files changed, 59 insertions(+), 19 deletions(-) -- 2.34.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 7+ messages in thread
* [LTP] [PATCH 1/2] fanotify13: Test overlayfs while watching lower fs 2023-11-14 7:23 [LTP] [PATCH 0/2] fanotify LTP tests for v6.6 Amir Goldstein @ 2023-11-14 7:23 ` Amir Goldstein 2023-11-14 10:29 ` Petr Vorel 2023-11-14 7:23 ` [LTP] [PATCH 2/2] fanotify13: Test watching overlayfs with FAN_REPORT_FID Amir Goldstein 1 sibling, 1 reply; 7+ messages in thread From: Amir Goldstein @ 2023-11-14 7:23 UTC (permalink / raw) To: Petr Vorel; +Cc: ltp, Jan Kara, linux-unionfs, Miklos Szeredi We already have a test variant when watching upper fs. Improve test coverage by adding a test variant with overlayfs (over all supported fs) when watching the lower fs. Signed-off-by: Amir Goldstein <amir73il@gmail.com> --- .../kernel/syscalls/fanotify/fanotify13.c | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/testcases/kernel/syscalls/fanotify/fanotify13.c b/testcases/kernel/syscalls/fanotify/fanotify13.c index a25a360fd..4bcffaab2 100644 --- a/testcases/kernel/syscalls/fanotify/fanotify13.c +++ b/testcases/kernel/syscalls/fanotify/fanotify13.c @@ -168,10 +168,10 @@ static void do_test(unsigned int number) if (setup_marks(fanotify_fd, tc) != 0) goto out; - /* Variant #1: watching upper fs - open files on overlayfs */ - if (tst_variant == 1) { + /* Watching base fs - open files on overlayfs */ + if (tst_variant) { if (mark->flag & FAN_MARK_MOUNT) { - tst_res(TCONF, "overlayfs upper fs cannot be watched with mount mark"); + tst_res(TCONF, "overlayfs base fs cannot be watched with mount mark"); goto out; } SAFE_MOUNT(OVL_MNT, MOUNT_PATH, "none", MS_BIND, NULL); @@ -191,7 +191,7 @@ static void do_test(unsigned int number) SAFE_CLOSE(fds[i]); } - if (tst_variant == 1) + if (tst_variant) SAFE_UMOUNT(MOUNT_PATH); /* Read events from event queue */ @@ -286,9 +286,10 @@ static void do_setup(void) /* * Bind mount to either base fs or to overlayfs over base fs: * Variant #0: watch base fs - open files on base fs - * Variant #1: watch upper fs - open files on overlayfs + * Variant #1: watch lower fs - open lower files on overlayfs + * Variant #2: watch upper fs - open upper files on overlayfs * - * Variant #1 tests a bug whose fix bc2473c90fca ("ovl: enable fsnotify + * Variants 1,2 test a bug whose fix bc2473c90fca ("ovl: enable fsnotify * events on underlying real files") in kernel 6.5 is not likely to be * backported to older kernels. * To avoid waiting for events that won't arrive when testing old kernels, @@ -298,7 +299,10 @@ static void do_setup(void) if (tst_variant) { REQUIRE_HANDLE_TYPE_SUPPORTED_BY_KERNEL(AT_HANDLE_FID); ovl_mounted = TST_MOUNT_OVERLAY(); - mnt = OVL_UPPER; + if (!ovl_mounted) + return; + + mnt = tst_variant & 1 ? OVL_LOWER : OVL_UPPER; } else { mnt = OVL_BASE_MNTPOINT; @@ -312,7 +316,7 @@ static void do_setup(void) nofid_fd = SAFE_FANOTIFY_INIT(FAN_CLASS_NOTIF, O_RDONLY); - /* Create file and directory objects for testing */ + /* Create file and directory objects for testing on base fs */ create_objects(); /* @@ -329,7 +333,8 @@ static void do_setup(void) static void do_cleanup(void) { - SAFE_CLOSE(nofid_fd); + if (nofid_fd > 0) + SAFE_CLOSE(nofid_fd); if (fanotify_fd > 0) SAFE_CLOSE(fanotify_fd); if (bind_mounted) { @@ -343,7 +348,7 @@ static void do_cleanup(void) static struct tst_test test = { .test = do_test, .tcnt = ARRAY_SIZE(test_cases), - .test_variants = 2, + .test_variants = 3, .setup = do_setup, .cleanup = do_cleanup, .needs_root = 1, -- 2.34.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [LTP] [PATCH 1/2] fanotify13: Test overlayfs while watching lower fs 2023-11-14 7:23 ` [LTP] [PATCH 1/2] fanotify13: Test overlayfs while watching lower fs Amir Goldstein @ 2023-11-14 10:29 ` Petr Vorel 0 siblings, 0 replies; 7+ messages in thread From: Petr Vorel @ 2023-11-14 10:29 UTC (permalink / raw) To: Amir Goldstein; +Cc: ltp, Jan Kara, linux-unionfs, Miklos Szeredi Hi Amir, Reviewed-by: Petr Vorel <pvorel@suse.cz> Kind regards, Petr -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 7+ messages in thread
* [LTP] [PATCH 2/2] fanotify13: Test watching overlayfs with FAN_REPORT_FID 2023-11-14 7:23 [LTP] [PATCH 0/2] fanotify LTP tests for v6.6 Amir Goldstein 2023-11-14 7:23 ` [LTP] [PATCH 1/2] fanotify13: Test overlayfs while watching lower fs Amir Goldstein @ 2023-11-14 7:23 ` Amir Goldstein 2023-11-14 10:57 ` Petr Vorel 1 sibling, 1 reply; 7+ messages in thread From: Amir Goldstein @ 2023-11-14 7:23 UTC (permalink / raw) To: Petr Vorel; +Cc: ltp, Jan Kara, linux-unionfs, Miklos Szeredi Run test variants watching overlayfs (over all supported fs) and reporting events with fid. This requires overlayfs support for AT_HANDLE_FID (kernel 6.6) and even with AT_HANDLE_FID file handles, only inode marks are supported. Signed-off-by: Amir Goldstein <amir73il@gmail.com> --- testcases/kernel/syscalls/fanotify/fanotify.h | 28 ++++++++++++----- .../kernel/syscalls/fanotify/fanotify13.c | 31 ++++++++++++++++--- 2 files changed, 47 insertions(+), 12 deletions(-) diff --git a/testcases/kernel/syscalls/fanotify/fanotify.h b/testcases/kernel/syscalls/fanotify/fanotify.h index 78424a350..a8aec6597 100644 --- a/testcases/kernel/syscalls/fanotify/fanotify.h +++ b/testcases/kernel/syscalls/fanotify/fanotify.h @@ -79,8 +79,11 @@ static inline int safe_fanotify_mark(const char *file, const int lineno, /* * Helper function used to obtain fsid and file_handle for a given path. * Used by test files correlated to FAN_REPORT_FID functionality. + * + * Returns 0 if normal NFS file handles are supported. + * Returns AT_HANDLE_FID, of only non-decodeable file handles are supported. */ -static inline void fanotify_get_fid(const char *path, __kernel_fsid_t *fsid, +static inline int fanotify_get_fid(const char *path, __kernel_fsid_t *fsid, struct file_handle *handle) { int mount_id; @@ -93,6 +96,11 @@ static inline void fanotify_get_fid(const char *path, __kernel_fsid_t *fsid, if (name_to_handle_at(AT_FDCWD, path, handle, &mount_id, 0) == -1) { if (errno == EOPNOTSUPP) { + /* Try to request non-decodeable fid instead */ + if (name_to_handle_at(AT_FDCWD, path, handle, &mount_id, + AT_HANDLE_FID) == 0) + return AT_HANDLE_FID; + tst_brk(TCONF, "filesystem %s does not support file handles", tst_device->fs_type); @@ -100,6 +108,7 @@ static inline void fanotify_get_fid(const char *path, __kernel_fsid_t *fsid, tst_brk(TBROK | TERRNO, "name_to_handle_at(AT_FDCWD, %s, ...) failed", path); } + return 0; } #ifndef FILEID_INVALID @@ -112,18 +121,21 @@ struct fanotify_fid_t { char buf[MAX_HANDLE_SZ]; }; -static inline void fanotify_save_fid(const char *path, +static inline int fanotify_save_fid(const char *path, struct fanotify_fid_t *fid) { int *fh = (int *)(fid->handle.f_handle); + int ret; fh[0] = fh[1] = fh[2] = 0; fid->handle.handle_bytes = MAX_HANDLE_SZ; - fanotify_get_fid(path, &fid->fsid, &fid->handle); + ret = fanotify_get_fid(path, &fid->fsid, &fid->handle); tst_res(TINFO, "fid(%s) = %x.%x.%x.%x.%x...", path, fid->fsid.val[0], fid->fsid.val[1], fh[0], fh[1], fh[2]); + + return ret; } #endif /* HAVE_NAME_TO_HANDLE_AT */ @@ -179,6 +191,7 @@ static inline int fanotify_events_supported_by_kernel(uint64_t mask, * @return 0: fanotify supported both in kernel and on tested filesystem * @return -1: @flags not supported in kernel * @return -2: @flags not supported on tested filesystem (tested if @fname is not NULL) + * @return -3: @flags not supported on overlayfs (tested if @fname == OVL_MNT) */ static inline int fanotify_init_flags_supported_on_fs(unsigned int flags, const char *fname) { @@ -199,7 +212,7 @@ static inline int fanotify_init_flags_supported_on_fs(unsigned int flags, const if (fname && fanotify_mark(fd, FAN_MARK_ADD, FAN_ACCESS, AT_FDCWD, fname) < 0) { if (errno == ENODEV || errno == EOPNOTSUPP || errno == EXDEV) { - rval = -2; + rval = strcmp(fname, OVL_MNT) ? -2 : -3; } else { tst_brk(TBROK | TERRNO, "fanotify_mark (%d, FAN_MARK_ADD, ..., AT_FDCWD, %s) failed", @@ -269,10 +282,11 @@ static inline void fanotify_init_flags_err_msg(const char *flags_str, if (fail == -1) res_func(file, lineno, TCONF, "%s not supported in kernel?", flags_str); - if (fail == -2) + if (fail == -2 || fail == -3) res_func(file, lineno, TCONF, - "%s not supported on %s filesystem", - flags_str, tst_device->fs_type); + "%s not supported on %s%s filesystem", + flags_str, fail == -3 ? "overlayfs over " : "", + tst_device->fs_type); } #define FANOTIFY_INIT_FLAGS_ERR_MSG(flags, fail) \ diff --git a/testcases/kernel/syscalls/fanotify/fanotify13.c b/testcases/kernel/syscalls/fanotify/fanotify13.c index 4bcffaab2..4a7c2af23 100644 --- a/testcases/kernel/syscalls/fanotify/fanotify13.c +++ b/testcases/kernel/syscalls/fanotify/fanotify13.c @@ -91,8 +91,10 @@ static struct test_case_t { static int ovl_mounted; static int bind_mounted; +static int ovl_bind_mounted; static int nofid_fd; static int fanotify_fd; +static int at_handle_fid; static int filesystem_mark_unsupported; static char events_buf[BUF_SIZE]; static struct event_t event_set[EVENT_MAX]; @@ -113,8 +115,10 @@ static void get_object_stats(void) { unsigned int i; - for (i = 0; i < ARRAY_SIZE(objects); i++) - fanotify_save_fid(objects[i].path, &objects[i].fid); + for (i = 0; i < ARRAY_SIZE(objects); i++) { + at_handle_fid |= + fanotify_save_fid(objects[i].path, &objects[i].fid); + } } static int setup_marks(unsigned int fd, struct test_case_t *tc) @@ -154,6 +158,11 @@ static void do_test(unsigned int number) return; } + if (at_handle_fid && mark->flag != FAN_MARK_INODE) { + tst_res(TCONF, "overlayfs does not support decodeable file handles required by %s", mark->name); + return; + } + if (filesystem_mark_unsupported && mark->flag & FAN_MARK_FILESYSTEM) { tst_res(TCONF, "FAN_MARK_FILESYSTEM not supported in kernel?"); return; @@ -169,7 +178,7 @@ static void do_test(unsigned int number) goto out; /* Watching base fs - open files on overlayfs */ - if (tst_variant) { + if (tst_variant && !ovl_bind_mounted) { if (mark->flag & FAN_MARK_MOUNT) { tst_res(TCONF, "overlayfs base fs cannot be watched with mount mark"); goto out; @@ -191,7 +200,7 @@ static void do_test(unsigned int number) SAFE_CLOSE(fds[i]); } - if (tst_variant) + if (tst_variant && !ovl_bind_mounted) SAFE_UMOUNT(MOUNT_PATH); /* Read events from event queue */ @@ -288,6 +297,8 @@ static void do_setup(void) * Variant #0: watch base fs - open files on base fs * Variant #1: watch lower fs - open lower files on overlayfs * Variant #2: watch upper fs - open upper files on overlayfs + * Variant #3: watch overlayfs - open lower files on overlayfs + * Variant #4: watch overlayfs - open upper files on overlayfs * * Variants 1,2 test a bug whose fix bc2473c90fca ("ovl: enable fsnotify * events on underlying real files") in kernel 6.5 is not likely to be @@ -295,6 +306,8 @@ static void do_setup(void) * To avoid waiting for events that won't arrive when testing old kernels, * require that kernel supports encoding fid with new flag AT_HADNLE_FID, * also merged to 6.5 and not likely to be backported to older kernels. + * Variants 3,4 test overlayfs watch with FAN_REPORT_FID, which also + * requires kernel with support for AT_HADNLE_FID. */ if (tst_variant) { REQUIRE_HANDLE_TYPE_SUPPORTED_BY_KERNEL(AT_HANDLE_FID); @@ -319,6 +332,12 @@ static void do_setup(void) /* Create file and directory objects for testing on base fs */ create_objects(); + if (tst_variant > 2) { + /* Setup watches on overlayfs */ + SAFE_MOUNT(OVL_MNT, MOUNT_PATH, "none", MS_BIND, NULL); + ovl_bind_mounted = 1; + } + /* * Create a mark on first inode without FAN_REPORT_FID, to test * uninitialized connector->fsid cache. This mark remains for all test @@ -337,6 +356,8 @@ static void do_cleanup(void) SAFE_CLOSE(nofid_fd); if (fanotify_fd > 0) SAFE_CLOSE(fanotify_fd); + if (ovl_bind_mounted) + SAFE_UMOUNT(MOUNT_PATH); if (bind_mounted) { SAFE_UMOUNT(MOUNT_PATH); SAFE_RMDIR(MOUNT_PATH); @@ -348,7 +369,7 @@ static void do_cleanup(void) static struct tst_test test = { .test = do_test, .tcnt = ARRAY_SIZE(test_cases), - .test_variants = 3, + .test_variants = 5, .setup = do_setup, .cleanup = do_cleanup, .needs_root = 1, -- 2.34.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [LTP] [PATCH 2/2] fanotify13: Test watching overlayfs with FAN_REPORT_FID 2023-11-14 7:23 ` [LTP] [PATCH 2/2] fanotify13: Test watching overlayfs with FAN_REPORT_FID Amir Goldstein @ 2023-11-14 10:57 ` Petr Vorel 2023-11-21 9:59 ` Petr Vorel 0 siblings, 1 reply; 7+ messages in thread From: Petr Vorel @ 2023-11-14 10:57 UTC (permalink / raw) To: Amir Goldstein; +Cc: ltp, Jan Kara, linux-unionfs, Miklos Szeredi Hi Amir, Reviewed-by: Petr Vorel <pvorel@suse.cz> Few notes below. > Run test variants watching overlayfs (over all supported fs) > and reporting events with fid. > This requires overlayfs support for AT_HANDLE_FID (kernel 6.6) and > even with AT_HANDLE_FID file handles, only inode marks are supported. > Signed-off-by: Amir Goldstein <amir73il@gmail.com> > --- > testcases/kernel/syscalls/fanotify/fanotify.h | 28 ++++++++++++----- > .../kernel/syscalls/fanotify/fanotify13.c | 31 ++++++++++++++++--- > 2 files changed, 47 insertions(+), 12 deletions(-) > diff --git a/testcases/kernel/syscalls/fanotify/fanotify.h b/testcases/kernel/syscalls/fanotify/fanotify.h > index 78424a350..a8aec6597 100644 > --- a/testcases/kernel/syscalls/fanotify/fanotify.h > +++ b/testcases/kernel/syscalls/fanotify/fanotify.h > @@ -79,8 +79,11 @@ static inline int safe_fanotify_mark(const char *file, const int lineno, > /* > * Helper function used to obtain fsid and file_handle for a given path. > * Used by test files correlated to FAN_REPORT_FID functionality. > + * > + * Returns 0 if normal NFS file handles are supported. > + * Returns AT_HANDLE_FID, of only non-decodeable file handles are supported. s/ of / if / I can fix this before merge. Also I noticed (not related to this change) that #define AT_HANDLE_FID 0x200 added in dc7b1332ab into testcases/kernel/syscalls/fanotify/fanotify.h should have been in include/lapi/fanotify.h (this file is for fallback definitions). Tiny detail, which should be fixed afterwards. > */ > -static inline void fanotify_get_fid(const char *path, __kernel_fsid_t *fsid, > +static inline int fanotify_get_fid(const char *path, __kernel_fsid_t *fsid, > struct file_handle *handle) > { > int mount_id; > @@ -93,6 +96,11 @@ static inline void fanotify_get_fid(const char *path, __kernel_fsid_t *fsid, > if (name_to_handle_at(AT_FDCWD, path, handle, &mount_id, 0) == -1) { > if (errno == EOPNOTSUPP) { > + /* Try to request non-decodeable fid instead */ > + if (name_to_handle_at(AT_FDCWD, path, handle, &mount_id, > + AT_HANDLE_FID) == 0) > + return AT_HANDLE_FID; > + > tst_brk(TCONF, > "filesystem %s does not support file handles", > tst_device->fs_type); > @@ -100,6 +108,7 @@ static inline void fanotify_get_fid(const char *path, __kernel_fsid_t *fsid, > tst_brk(TBROK | TERRNO, > "name_to_handle_at(AT_FDCWD, %s, ...) failed", path); > } > + return 0; > } > #ifndef FILEID_INVALID > @@ -112,18 +121,21 @@ struct fanotify_fid_t { > char buf[MAX_HANDLE_SZ]; > }; > -static inline void fanotify_save_fid(const char *path, > +static inline int fanotify_save_fid(const char *path, > struct fanotify_fid_t *fid) > { > int *fh = (int *)(fid->handle.f_handle); > + int ret; > fh[0] = fh[1] = fh[2] = 0; > fid->handle.handle_bytes = MAX_HANDLE_SZ; > - fanotify_get_fid(path, &fid->fsid, &fid->handle); > + ret = fanotify_get_fid(path, &fid->fsid, &fid->handle); > tst_res(TINFO, > "fid(%s) = %x.%x.%x.%x.%x...", path, fid->fsid.val[0], > fid->fsid.val[1], fh[0], fh[1], fh[2]); > + > + return ret; > } > #endif /* HAVE_NAME_TO_HANDLE_AT */ > @@ -179,6 +191,7 @@ static inline int fanotify_events_supported_by_kernel(uint64_t mask, > * @return 0: fanotify supported both in kernel and on tested filesystem > * @return -1: @flags not supported in kernel > * @return -2: @flags not supported on tested filesystem (tested if @fname is not NULL) > + * @return -3: @flags not supported on overlayfs (tested if @fname == OVL_MNT) > */ > static inline int fanotify_init_flags_supported_on_fs(unsigned int flags, const char *fname) > { > @@ -199,7 +212,7 @@ static inline int fanotify_init_flags_supported_on_fs(unsigned int flags, const > if (fname && fanotify_mark(fd, FAN_MARK_ADD, FAN_ACCESS, AT_FDCWD, fname) < 0) { > if (errno == ENODEV || errno == EOPNOTSUPP || errno == EXDEV) { > - rval = -2; > + rval = strcmp(fname, OVL_MNT) ? -2 : -3; > } else { > tst_brk(TBROK | TERRNO, > "fanotify_mark (%d, FAN_MARK_ADD, ..., AT_FDCWD, %s) failed", > @@ -269,10 +282,11 @@ static inline void fanotify_init_flags_err_msg(const char *flags_str, > if (fail == -1) > res_func(file, lineno, TCONF, > "%s not supported in kernel?", flags_str); > - if (fail == -2) > + if (fail == -2 || fail == -3) > res_func(file, lineno, TCONF, > - "%s not supported on %s filesystem", > - flags_str, tst_device->fs_type); > + "%s not supported on %s%s filesystem", > + flags_str, fail == -3 ? "overlayfs over " : "", > + tst_device->fs_type); > } > #define FANOTIFY_INIT_FLAGS_ERR_MSG(flags, fail) \ > diff --git a/testcases/kernel/syscalls/fanotify/fanotify13.c b/testcases/kernel/syscalls/fanotify/fanotify13.c > index 4bcffaab2..4a7c2af23 100644 > --- a/testcases/kernel/syscalls/fanotify/fanotify13.c > +++ b/testcases/kernel/syscalls/fanotify/fanotify13.c > @@ -91,8 +91,10 @@ static struct test_case_t { > static int ovl_mounted; > static int bind_mounted; > +static int ovl_bind_mounted; > static int nofid_fd; > static int fanotify_fd; > +static int at_handle_fid; > static int filesystem_mark_unsupported; > static char events_buf[BUF_SIZE]; > static struct event_t event_set[EVENT_MAX]; > @@ -113,8 +115,10 @@ static void get_object_stats(void) > { > unsigned int i; > - for (i = 0; i < ARRAY_SIZE(objects); i++) > - fanotify_save_fid(objects[i].path, &objects[i].fid); > + for (i = 0; i < ARRAY_SIZE(objects); i++) { > + at_handle_fid |= > + fanotify_save_fid(objects[i].path, &objects[i].fid); > + } > } > static int setup_marks(unsigned int fd, struct test_case_t *tc) > @@ -154,6 +158,11 @@ static void do_test(unsigned int number) > return; > } > + if (at_handle_fid && mark->flag != FAN_MARK_INODE) { > + tst_res(TCONF, "overlayfs does not support decodeable file handles required by %s", mark->name); > + return; > + } > + > if (filesystem_mark_unsupported && mark->flag & FAN_MARK_FILESYSTEM) { > tst_res(TCONF, "FAN_MARK_FILESYSTEM not supported in kernel?"); > return; > @@ -169,7 +178,7 @@ static void do_test(unsigned int number) > goto out; > /* Watching base fs - open files on overlayfs */ > - if (tst_variant) { > + if (tst_variant && !ovl_bind_mounted) { > if (mark->flag & FAN_MARK_MOUNT) { > tst_res(TCONF, "overlayfs base fs cannot be watched with mount mark"); > goto out; > @@ -191,7 +200,7 @@ static void do_test(unsigned int number) > SAFE_CLOSE(fds[i]); > } > - if (tst_variant) > + if (tst_variant && !ovl_bind_mounted) > SAFE_UMOUNT(MOUNT_PATH); > /* Read events from event queue */ > @@ -288,6 +297,8 @@ static void do_setup(void) > * Variant #0: watch base fs - open files on base fs > * Variant #1: watch lower fs - open lower files on overlayfs > * Variant #2: watch upper fs - open upper files on overlayfs > + * Variant #3: watch overlayfs - open lower files on overlayfs > + * Variant #4: watch overlayfs - open upper files on overlayfs > * > * Variants 1,2 test a bug whose fix bc2473c90fca ("ovl: enable fsnotify > * events on underlying real files") in kernel 6.5 is not likely to be > @@ -295,6 +306,8 @@ static void do_setup(void) > * To avoid waiting for events that won't arrive when testing old kernels, > * require that kernel supports encoding fid with new flag AT_HADNLE_FID, s/AT_HADNLE_FID/AT_HANDLE_FID/ (old typo) > * also merged to 6.5 and not likely to be backported to older kernels. > + * Variants 3,4 test overlayfs watch with FAN_REPORT_FID, which also > + * requires kernel with support for AT_HADNLE_FID. s/AT_HADNLE_FID/AT_HANDLE_FID/ (new typo) I can fix these during merge. Kind regards, Petr > */ > if (tst_variant) { > REQUIRE_HANDLE_TYPE_SUPPORTED_BY_KERNEL(AT_HANDLE_FID); > @@ -319,6 +332,12 @@ static void do_setup(void) > /* Create file and directory objects for testing on base fs */ > create_objects(); > + if (tst_variant > 2) { > + /* Setup watches on overlayfs */ > + SAFE_MOUNT(OVL_MNT, MOUNT_PATH, "none", MS_BIND, NULL); > + ovl_bind_mounted = 1; > + } > + > /* > * Create a mark on first inode without FAN_REPORT_FID, to test > * uninitialized connector->fsid cache. This mark remains for all test > @@ -337,6 +356,8 @@ static void do_cleanup(void) > SAFE_CLOSE(nofid_fd); > if (fanotify_fd > 0) > SAFE_CLOSE(fanotify_fd); > + if (ovl_bind_mounted) > + SAFE_UMOUNT(MOUNT_PATH); > if (bind_mounted) { > SAFE_UMOUNT(MOUNT_PATH); > SAFE_RMDIR(MOUNT_PATH); > @@ -348,7 +369,7 @@ static void do_cleanup(void) > static struct tst_test test = { > .test = do_test, > .tcnt = ARRAY_SIZE(test_cases), > - .test_variants = 3, > + .test_variants = 5, > .setup = do_setup, > .cleanup = do_cleanup, > .needs_root = 1, -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [LTP] [PATCH 2/2] fanotify13: Test watching overlayfs with FAN_REPORT_FID 2023-11-14 10:57 ` Petr Vorel @ 2023-11-21 9:59 ` Petr Vorel 2023-11-21 10:31 ` Amir Goldstein 0 siblings, 1 reply; 7+ messages in thread From: Petr Vorel @ 2023-11-21 9:59 UTC (permalink / raw) To: Amir Goldstein, ltp, Jan Kara, linux-unionfs, Miklos Szeredi Hi Amir, > Hi Amir, > Reviewed-by: Petr Vorel <pvorel@suse.cz> > Few notes below. > > Run test variants watching overlayfs (over all supported fs) > > and reporting events with fid. > > This requires overlayfs support for AT_HANDLE_FID (kernel 6.6) and > > even with AT_HANDLE_FID file handles, only inode marks are supported. > > Signed-off-by: Amir Goldstein <amir73il@gmail.com> > > --- > > testcases/kernel/syscalls/fanotify/fanotify.h | 28 ++++++++++++----- > > .../kernel/syscalls/fanotify/fanotify13.c | 31 ++++++++++++++++--- > > 2 files changed, 47 insertions(+), 12 deletions(-) > > diff --git a/testcases/kernel/syscalls/fanotify/fanotify.h b/testcases/kernel/syscalls/fanotify/fanotify.h > > index 78424a350..a8aec6597 100644 > > --- a/testcases/kernel/syscalls/fanotify/fanotify.h > > +++ b/testcases/kernel/syscalls/fanotify/fanotify.h > > @@ -79,8 +79,11 @@ static inline int safe_fanotify_mark(const char *file, const int lineno, > > /* > > * Helper function used to obtain fsid and file_handle for a given path. > > * Used by test files correlated to FAN_REPORT_FID functionality. > > + * > > + * Returns 0 if normal NFS file handles are supported. > > + * Returns AT_HANDLE_FID, of only non-decodeable file handles are supported. > s/ of / if / > I can fix this before merge. I dared to fix this and s/AT_HADNLE_FID/AT_HANDLE_FID/ and merge. > Also I noticed (not related to this change) that #define AT_HANDLE_FID 0x200 > added in dc7b1332ab into testcases/kernel/syscalls/fanotify/fanotify.h should > have been in include/lapi/fanotify.h (this file is for fallback definitions). > Tiny detail, which should be fixed afterwards. I also merged a cleanup of the fallback definitions. Thanks for maintaining fanotify tests! Kind regards, Petr > > */ > > -static inline void fanotify_get_fid(const char *path, __kernel_fsid_t *fsid, > > +static inline int fanotify_get_fid(const char *path, __kernel_fsid_t *fsid, > > struct file_handle *handle) > > { > > int mount_id; > > @@ -93,6 +96,11 @@ static inline void fanotify_get_fid(const char *path, __kernel_fsid_t *fsid, > > if (name_to_handle_at(AT_FDCWD, path, handle, &mount_id, 0) == -1) { > > if (errno == EOPNOTSUPP) { > > + /* Try to request non-decodeable fid instead */ > > + if (name_to_handle_at(AT_FDCWD, path, handle, &mount_id, > > + AT_HANDLE_FID) == 0) > > + return AT_HANDLE_FID; > > + > > tst_brk(TCONF, > > "filesystem %s does not support file handles", > > tst_device->fs_type); > > @@ -100,6 +108,7 @@ static inline void fanotify_get_fid(const char *path, __kernel_fsid_t *fsid, > > tst_brk(TBROK | TERRNO, > > "name_to_handle_at(AT_FDCWD, %s, ...) failed", path); > > } > > + return 0; > > } > > #ifndef FILEID_INVALID > > @@ -112,18 +121,21 @@ struct fanotify_fid_t { > > char buf[MAX_HANDLE_SZ]; > > }; > > -static inline void fanotify_save_fid(const char *path, > > +static inline int fanotify_save_fid(const char *path, > > struct fanotify_fid_t *fid) > > { > > int *fh = (int *)(fid->handle.f_handle); > > + int ret; > > fh[0] = fh[1] = fh[2] = 0; > > fid->handle.handle_bytes = MAX_HANDLE_SZ; > > - fanotify_get_fid(path, &fid->fsid, &fid->handle); > > + ret = fanotify_get_fid(path, &fid->fsid, &fid->handle); > > tst_res(TINFO, > > "fid(%s) = %x.%x.%x.%x.%x...", path, fid->fsid.val[0], > > fid->fsid.val[1], fh[0], fh[1], fh[2]); > > + > > + return ret; > > } > > #endif /* HAVE_NAME_TO_HANDLE_AT */ > > @@ -179,6 +191,7 @@ static inline int fanotify_events_supported_by_kernel(uint64_t mask, > > * @return 0: fanotify supported both in kernel and on tested filesystem > > * @return -1: @flags not supported in kernel > > * @return -2: @flags not supported on tested filesystem (tested if @fname is not NULL) > > + * @return -3: @flags not supported on overlayfs (tested if @fname == OVL_MNT) > > */ > > static inline int fanotify_init_flags_supported_on_fs(unsigned int flags, const char *fname) > > { > > @@ -199,7 +212,7 @@ static inline int fanotify_init_flags_supported_on_fs(unsigned int flags, const > > if (fname && fanotify_mark(fd, FAN_MARK_ADD, FAN_ACCESS, AT_FDCWD, fname) < 0) { > > if (errno == ENODEV || errno == EOPNOTSUPP || errno == EXDEV) { > > - rval = -2; > > + rval = strcmp(fname, OVL_MNT) ? -2 : -3; > > } else { > > tst_brk(TBROK | TERRNO, > > "fanotify_mark (%d, FAN_MARK_ADD, ..., AT_FDCWD, %s) failed", > > @@ -269,10 +282,11 @@ static inline void fanotify_init_flags_err_msg(const char *flags_str, > > if (fail == -1) > > res_func(file, lineno, TCONF, > > "%s not supported in kernel?", flags_str); > > - if (fail == -2) > > + if (fail == -2 || fail == -3) > > res_func(file, lineno, TCONF, > > - "%s not supported on %s filesystem", > > - flags_str, tst_device->fs_type); > > + "%s not supported on %s%s filesystem", > > + flags_str, fail == -3 ? "overlayfs over " : "", > > + tst_device->fs_type); > > } > > #define FANOTIFY_INIT_FLAGS_ERR_MSG(flags, fail) \ > > diff --git a/testcases/kernel/syscalls/fanotify/fanotify13.c b/testcases/kernel/syscalls/fanotify/fanotify13.c > > index 4bcffaab2..4a7c2af23 100644 > > --- a/testcases/kernel/syscalls/fanotify/fanotify13.c > > +++ b/testcases/kernel/syscalls/fanotify/fanotify13.c > > @@ -91,8 +91,10 @@ static struct test_case_t { > > static int ovl_mounted; > > static int bind_mounted; > > +static int ovl_bind_mounted; > > static int nofid_fd; > > static int fanotify_fd; > > +static int at_handle_fid; > > static int filesystem_mark_unsupported; > > static char events_buf[BUF_SIZE]; > > static struct event_t event_set[EVENT_MAX]; > > @@ -113,8 +115,10 @@ static void get_object_stats(void) > > { > > unsigned int i; > > - for (i = 0; i < ARRAY_SIZE(objects); i++) > > - fanotify_save_fid(objects[i].path, &objects[i].fid); > > + for (i = 0; i < ARRAY_SIZE(objects); i++) { > > + at_handle_fid |= > > + fanotify_save_fid(objects[i].path, &objects[i].fid); > > + } > > } > > static int setup_marks(unsigned int fd, struct test_case_t *tc) > > @@ -154,6 +158,11 @@ static void do_test(unsigned int number) > > return; > > } > > + if (at_handle_fid && mark->flag != FAN_MARK_INODE) { > > + tst_res(TCONF, "overlayfs does not support decodeable file handles required by %s", mark->name); > > + return; > > + } > > + > > if (filesystem_mark_unsupported && mark->flag & FAN_MARK_FILESYSTEM) { > > tst_res(TCONF, "FAN_MARK_FILESYSTEM not supported in kernel?"); > > return; > > @@ -169,7 +178,7 @@ static void do_test(unsigned int number) > > goto out; > > /* Watching base fs - open files on overlayfs */ > > - if (tst_variant) { > > + if (tst_variant && !ovl_bind_mounted) { > > if (mark->flag & FAN_MARK_MOUNT) { > > tst_res(TCONF, "overlayfs base fs cannot be watched with mount mark"); > > goto out; > > @@ -191,7 +200,7 @@ static void do_test(unsigned int number) > > SAFE_CLOSE(fds[i]); > > } > > - if (tst_variant) > > + if (tst_variant && !ovl_bind_mounted) > > SAFE_UMOUNT(MOUNT_PATH); > > /* Read events from event queue */ > > @@ -288,6 +297,8 @@ static void do_setup(void) > > * Variant #0: watch base fs - open files on base fs > > * Variant #1: watch lower fs - open lower files on overlayfs > > * Variant #2: watch upper fs - open upper files on overlayfs > > + * Variant #3: watch overlayfs - open lower files on overlayfs > > + * Variant #4: watch overlayfs - open upper files on overlayfs > > * > > * Variants 1,2 test a bug whose fix bc2473c90fca ("ovl: enable fsnotify > > * events on underlying real files") in kernel 6.5 is not likely to be > > @@ -295,6 +306,8 @@ static void do_setup(void) > > * To avoid waiting for events that won't arrive when testing old kernels, > > * require that kernel supports encoding fid with new flag AT_HADNLE_FID, > s/AT_HADNLE_FID/AT_HANDLE_FID/ > (old typo) > > * also merged to 6.5 and not likely to be backported to older kernels. > > + * Variants 3,4 test overlayfs watch with FAN_REPORT_FID, which also > > + * requires kernel with support for AT_HADNLE_FID. > s/AT_HADNLE_FID/AT_HANDLE_FID/ > (new typo) > I can fix these during merge. > Kind regards, > Petr > > */ > > if (tst_variant) { > > REQUIRE_HANDLE_TYPE_SUPPORTED_BY_KERNEL(AT_HANDLE_FID); > > @@ -319,6 +332,12 @@ static void do_setup(void) > > /* Create file and directory objects for testing on base fs */ > > create_objects(); > > + if (tst_variant > 2) { > > + /* Setup watches on overlayfs */ > > + SAFE_MOUNT(OVL_MNT, MOUNT_PATH, "none", MS_BIND, NULL); > > + ovl_bind_mounted = 1; > > + } > > + > > /* > > * Create a mark on first inode without FAN_REPORT_FID, to test > > * uninitialized connector->fsid cache. This mark remains for all test > > @@ -337,6 +356,8 @@ static void do_cleanup(void) > > SAFE_CLOSE(nofid_fd); > > if (fanotify_fd > 0) > > SAFE_CLOSE(fanotify_fd); > > + if (ovl_bind_mounted) > > + SAFE_UMOUNT(MOUNT_PATH); > > if (bind_mounted) { > > SAFE_UMOUNT(MOUNT_PATH); > > SAFE_RMDIR(MOUNT_PATH); > > @@ -348,7 +369,7 @@ static void do_cleanup(void) > > static struct tst_test test = { > > .test = do_test, > > .tcnt = ARRAY_SIZE(test_cases), > > - .test_variants = 3, > > + .test_variants = 5, > > .setup = do_setup, > > .cleanup = do_cleanup, > > .needs_root = 1, -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [LTP] [PATCH 2/2] fanotify13: Test watching overlayfs with FAN_REPORT_FID 2023-11-21 9:59 ` Petr Vorel @ 2023-11-21 10:31 ` Amir Goldstein 0 siblings, 0 replies; 7+ messages in thread From: Amir Goldstein @ 2023-11-21 10:31 UTC (permalink / raw) To: Petr Vorel; +Cc: Jan Kara, linux-unionfs, ltp, Miklos Szeredi On Tue, Nov 21, 2023 at 11:59 AM Petr Vorel <pvorel@suse.cz> wrote: > > Hi Amir, > > > Hi Amir, > > > Reviewed-by: Petr Vorel <pvorel@suse.cz> > > Few notes below. > > > > Run test variants watching overlayfs (over all supported fs) > > > and reporting events with fid. > > > > This requires overlayfs support for AT_HANDLE_FID (kernel 6.6) and > > > even with AT_HANDLE_FID file handles, only inode marks are supported. > > > > Signed-off-by: Amir Goldstein <amir73il@gmail.com> > > > --- > > > testcases/kernel/syscalls/fanotify/fanotify.h | 28 ++++++++++++----- > > > .../kernel/syscalls/fanotify/fanotify13.c | 31 ++++++++++++++++--- > > > 2 files changed, 47 insertions(+), 12 deletions(-) > > > > diff --git a/testcases/kernel/syscalls/fanotify/fanotify.h b/testcases/kernel/syscalls/fanotify/fanotify.h > > > index 78424a350..a8aec6597 100644 > > > --- a/testcases/kernel/syscalls/fanotify/fanotify.h > > > +++ b/testcases/kernel/syscalls/fanotify/fanotify.h > > > @@ -79,8 +79,11 @@ static inline int safe_fanotify_mark(const char *file, const int lineno, > > > /* > > > * Helper function used to obtain fsid and file_handle for a given path. > > > * Used by test files correlated to FAN_REPORT_FID functionality. > > > + * > > > + * Returns 0 if normal NFS file handles are supported. > > > + * Returns AT_HANDLE_FID, of only non-decodeable file handles are supported. > > s/ of / if / > > I can fix this before merge. > > I dared to fix this and s/AT_HADNLE_FID/AT_HANDLE_FID/ and merge. > That's great! > > Also I noticed (not related to this change) that #define AT_HANDLE_FID 0x200 > > added in dc7b1332ab into testcases/kernel/syscalls/fanotify/fanotify.h should > > have been in include/lapi/fanotify.h (this file is for fallback definitions). > > Tiny detail, which should be fixed afterwards. > > I also merged a cleanup of the fallback definitions. > > Thanks for maintaining fanotify tests! > Thank you! Amir. -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2023-11-21 10:32 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2023-11-14 7:23 [LTP] [PATCH 0/2] fanotify LTP tests for v6.6 Amir Goldstein 2023-11-14 7:23 ` [LTP] [PATCH 1/2] fanotify13: Test overlayfs while watching lower fs Amir Goldstein 2023-11-14 10:29 ` Petr Vorel 2023-11-14 7:23 ` [LTP] [PATCH 2/2] fanotify13: Test watching overlayfs with FAN_REPORT_FID Amir Goldstein 2023-11-14 10:57 ` Petr Vorel 2023-11-21 9:59 ` Petr Vorel 2023-11-21 10:31 ` Amir Goldstein
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox