Fix fanotify14
v3 cover Fix fanotify14
Fanotify14 tests some fanotify_init() flags which are not supported on older kernels but doesn't properly check for their availability. Add a reusable helper function for fanotify_init() feature detection and fix kernel support checks in fanotify14.
After discussion in the SUSE LTP team, I've decided to fix my previous patchset and submit it again.
Martin Doucha (2):
Add fanotify_get_supported_init_flags() helper function
fanotify14: Improve check for unsupported init flags
testcases/kernel/syscalls/fanotify/fanotify.h | 43 +++++++++++++++++++ .../kernel/syscalls/fanotify/fanotify14.c | 15 ++++--- 2 files changed, 52 insertions(+), 6 deletions(-)
Signature · 5 lines
2.42.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v3 1/2 Add fanotify_get_supported_init_flags() helper function
Since FAN_ALL_INIT_FLAGS constant is deprecated, the kernel has added new fanotify feature flags and there is no other way to check for their support, we need to manually check which init flags needed by our tests are available.
---
Changes since v1:
- Fixed check for FAN_REPORT_NAME
- Added longer patch description
Changes since v2:
- Added a table of flag dependencies so that each individual flag is tested together with all additional required flags
The helper function also checks that it wasn't called with a new uknown flag which might require dependency table update. In that case, the test will fail and advise the developer to review documentation and update the dependency table.
testcases/kernel/syscalls/fanotify/fanotify.h | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+)
testcases/kernel/syscalls/fanotify/fanotify.h +43 -0
@@ -217,6 +217,49 @@ static inline int fanotify_init_flags_supported_by_kernel(unsigned int flags)return fanotify_init_flags_supported_on_fs (flags,NULL ); } +#define TST_FANOTIFY_INIT_KNOWN_FLAGS \ + (FAN_REPORT_DFID_NAME_TARGET | FAN_REPORT_TID | FAN_REPORT_PIDFD | \ + FAN_CLASS_NOTIF | FAN_CLASS_CONTENT | FAN_CLASS_PRE_CONTENT) + +/* +* Check support of given init flags one by one and return those which are +* supported. +*/ +static inline unsigned int fanotify_get_supported_init_flags (unsigned int flags, +const char *fname) +{ +unsigned int i, flg, arg, ret =0 ; +static const struct {unsigned int flag, deps; } deplist[] = { + {FAN_REPORT_NAME ,FAN_REPORT_DIR_FID }, + {FAN_REPORT_TARGET_FID ,FAN_REPORT_DFID_NAME_FID }, + {0 ,0 } + }; + +if (flags & ~TST_FANOTIFY_INIT_KNOWN_FLAGS ) { +tst_brk (TBROK ,"fanotify_init() feature check called with unknown flags %x, please update flag dependency table if needed" , + flags & ~TST_FANOTIFY_INIT_KNOWN_FLAGS ); + } + +for (flg =1 ; flg; flg <<=1 ) { +if (!(flags & flg)) +continue ; + + arg = flg; + +for (i =0 ; deplist[i].flag; i++) { +if (deplist[i].flag == flg) { + arg |= deplist[i].deps; +break ; + } + } + +if (!fanotify_init_flags_supported_on_fs (arg, fname)) + ret |= flg; + } + +return ret; +} +typedef void (*tst_res_func_t )(const char *file,const int lineno,int ttype,const char *fmt, ...);
Signature · 5 lines
2.42.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v3 1/2] Add fanotify_get_supported_init_flags() helper function
Quoted 13 lines · Martin Doucha
Since
FAN_ALL_INIT_FLAGSconstant is deprecated, the kernel has added new fanotify feature flags and there is no other way to check for their support, we need to manually check which init flags needed by our tests are available.Signed-off-by Martin Doucha <[email protected]>---
Changes since v1:
- Fixed check forFAN_REPORT_NAME
- Added longer patch description
Quoted 9 lines
Changes since v2:
- Added a table of flag dependencies so that each individual flag is tested together with all additional required flagsThe helper function also checks that it wasn't called with a new uknown flag which might require dependency table update. In that case, the test will fail and advise the developer to review documentation and update the dependency table.
This is much more sane than the previous version :) You may add:
Quoted 60 lines
testcases/kernel/syscalls/fanotify/fanotify.h | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+)testcases/kernel/syscalls/fanotify/fanotify.h +43
-1@@ -217,6 +217,49 @@ static inline int fanotify_init_flags_supported_by_kernel(unsigned int flags)return fanotify_init_flags_supported_on_fs (flags,NULL ); } +#define TST_FANOTIFY_INIT_KNOWN_FLAGS \ + (FAN_REPORT_DFID_NAME_TARGET | FAN_REPORT_TID | FAN_REPORT_PIDFD | \ + FAN_CLASS_NOTIF | FAN_CLASS_CONTENT | FAN_CLASS_PRE_CONTENT) + +/* +* Check support of given init flags one by one and return those which are +* supported. +*/ +static inline unsigned int fanotify_get_supported_init_flags (unsigned int flags, +const char *fname) +{ +unsigned int i, flg, arg, ret =0 ; +static const struct {unsigned int flag, deps; } deplist[] = { + {FAN_REPORT_NAME ,FAN_REPORT_DIR_FID }, + {FAN_REPORT_TARGET_FID ,FAN_REPORT_DFID_NAME_FID }, + {0 ,0 } + }; + +if (flags & ~TST_FANOTIFY_INIT_KNOWN_FLAGS ) { +tst_brk (TBROK ,"fanotify_init() feature check called with unknown flags %x, please update flag dependency table if needed" , + flags & ~TST_FANOTIFY_INIT_KNOWN_FLAGS ); + } + +for (flg =1 ; flg; flg <<=1 ) { +if (!(flags & flg)) +continue ; + + arg = flg; + +for (i =0 ; deplist[i].flag; i++) { +if (deplist[i].flag == flg) { + arg |= deplist[i].deps; +break ; + } + } + +if (!fanotify_init_flags_supported_on_fs (arg, fname)) + ret |= flg; + } + +return ret; +} +typedef void (*tst_res_func_t )(const char *file,const int lineno,int ttype,const char *fmt, ...); --2.42.0
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Petr Vorel
Reviewed-byRe: [LTP] [PATCH v3 1/2] Add fanotify_get_supported_init_flags() helper function
Hi Martin, Amir,
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v3 2/2 fanotify14: Improve check for unsupported init flags
In reply to Martin DouchaTest case 8 of fanotify14 uses init flags supported only on kernel 5.9+ but does not properly check for their support. Rewrite fanotify feature checks using new helper function.
---
Changes since v1:
- Added FAN_CLASS_* constants to support check in setup()
- Added longer patch description
Changes since v2: None
I'd rather not squash this patch so that it can be reverted without potentially breaking other tests.
testcases/kernel/syscalls/fanotify/fanotify14.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
testcases/kernel/syscalls/fanotify/fanotify14.c +9 -6
@@ -45,8 +45,8 @@static int pipes[2 ] = {-1 ,-1 };static int fanotify_fd; -static int fan_report_target_fid_unsupported;static int ignore_mark_unsupported; +static unsigned int supported_init_flags;struct test_case_flags_t {unsigned long long flags;
@@ -246,9 +246,8 @@ static void do_test(unsigned int number)tst_res (TINFO ,"Test case %d: fanotify_init(%s, O_RDONLY)" , number, tc->init.desc); -if (fan_report_target_fid_unsupported && tc->init.flags &FAN_REPORT_TARGET_FID ) { -FANOTIFY_INIT_FLAGS_ERR_MSG (FAN_REPORT_TARGET_FID , - fan_report_target_fid_unsupported); +if (tc->init.flags & ~supported_init_flags) { +tst_res (TCONF ,"Unsupported init flags" );return ; }
@@ -317,11 +316,15 @@ out:static void do_setup (void ) { +unsigned int all_init_flags =FAN_REPORT_DFID_NAME_TARGET | +FAN_CLASS_NOTIF |FAN_CLASS_CONTENT |FAN_CLASS_PRE_CONTENT ; +/* Require FAN_REPORT_FID support for all tests to simplify per test case requirements */ REQUIRE_FANOTIFY_INIT_FLAGS_SUPPORTED_ON_FS (FAN_REPORT_FID ,MNTPOINT ); - fan_report_target_fid_unsupported = -fanotify_init_flags_supported_on_fs (FAN_REPORT_DFID_NAME_TARGET ,MNTPOINT ); + supported_init_flags =fanotify_get_supported_init_flags (all_init_flags, +MNTPOINT ); + ignore_mark_unsupported =fanotify_mark_supported_by_kernel (FAN_MARK_IGNORE_SURV );/* Create temporary test file to place marks on */
Signature · 5 lines
2.42.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v3 2/2] fanotify14: Improve check for unsupported init flags
Quoted 35 lines · Martin Doucha
Test case 8 of fanotify14 uses init flags supported only on kernel 5.9+ but does not properly check for their support. Rewrite fanotify feature checks using new helper function.
Signed-off-by Martin Doucha <[email protected]>---
Changes since v1:
- Added FAN_CLASS_* constants to support check insetup()
- Added longer patch descriptionChanges since v2: None
I'd rather not squash this patch so that it can be reverted without potentially breaking other tests.
testcases/kernel/syscalls/fanotify/fanotify14.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)testcases/kernel/syscalls/fanotify/fanotify14.c +1
-1@@ -45,8 +45,8 @@static int pipes[2 ] = {-1 ,-1 };static int fanotify_fd; -static int fan_report_target_fid_unsupported;static int ignore_mark_unsupported; +static unsigned int supported_init_flags;struct test_case_flags_t {unsigned long long flags;
testcases/kernel/syscalls/fanotify/fanotify14.c static void do_test(unsigned int number) · line 250
Quoted 8 lines
testcases/kernel/syscalls/fanotify/fanotify14.c +2
-3@@ -246,9 +246,8 @@ static void do_test(unsigned int number)tst_res (TINFO ,"Test case %d: fanotify_init(%s, O_RDONLY)" , number, tc->init.desc); -if (fan_report_target_fid_unsupported && tc->init.flags &FAN_REPORT_TARGET_FID ) { -FANOTIFY_INIT_FLAGS_ERR_MSG (FAN_REPORT_TARGET_FID , - fan_report_target_fid_unsupported); +if (tc->init.flags & ~supported_init_flags) { + tst_res(TCONF, "Unsupported init flags"
suggest to preserve the information printed by FANOTIFY_INIT_FLAGS_ERR_MSG, you can use tc->init.desc the for the flag name string.
Otherwise, you may add:
Quoted 24 lines
testcases/kernel/syscalls/fanotify/fanotify14.c +6
-3return ; }@@ -317,11 +316,15 @@ out:static void do_setup (void ) { +unsigned int all_init_flags =FAN_REPORT_DFID_NAME_TARGET | +FAN_CLASS_NOTIF |FAN_CLASS_CONTENT |FAN_CLASS_PRE_CONTENT ; +/* Require FAN_REPORT_FID support for all tests to simplify per test case requirements */ REQUIRE_FANOTIFY_INIT_FLAGS_SUPPORTED_ON_FS (FAN_REPORT_FID ,MNTPOINT ); - fan_report_target_fid_unsupported = -fanotify_init_flags_supported_on_fs (FAN_REPORT_DFID_NAME_TARGET ,MNTPOINT ); + supported_init_flags =fanotify_get_supported_init_flags (all_init_flags, +MNTPOINT ); + ignore_mark_unsupported =fanotify_mark_supported_by_kernel (FAN_MARK_IGNORE_SURV );/* Create temporary test file to place marks on */ --2.42.0
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v3 2/2] fanotify14: Improve check for unsupported init flags
Quoted 39 lines · Amir Goldstein
Quoted 38 lines · Martin Doucha
Test case 8 of fanotify14 uses init flags supported only on kernel 5.9+ but does not properly check for their support. Rewrite fanotify feature checks using new helper function.
Signed-off-by Martin Doucha <[email protected]>---
Changes since v1:
- Added FAN_CLASS_* constants to support check insetup()
- Added longer patch descriptionChanges since v2: None
I'd rather not squash this patch so that it can be reverted without potentially breaking other tests.
testcases/kernel/syscalls/fanotify/fanotify14.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)testcases/kernel/syscalls/fanotify/fanotify14.c +1
-1@@ -45,8 +45,8 @@static int pipes[2 ] = {-1 ,-1 };static int fanotify_fd; -static int fan_report_target_fid_unsupported;static int ignore_mark_unsupported; +static unsigned int supported_init_flags;struct test_case_flags_t {unsigned long long flags;@@ -246,9 +246,8 @@ static void do_test(unsigned int number)tst_res (TINFO ,"Test case %d: fanotify_init(%s, O_RDONLY)" , number, tc->init.desc);
Quoted 9 lines
testcases/kernel/syscalls/fanotify/fanotify14.c static void do_test(unsigned int number)
Quoted 5 lines
testcases/kernel/syscalls/fanotify/fanotify14.c +2
-3-if (fan_report_target_fid_unsupported && tc->init.flags &FAN_REPORT_TARGET_FID ) { -FANOTIFY_INIT_FLAGS_ERR_MSG (FAN_REPORT_TARGET_FID , - fan_report_target_fid_unsupported); +if (tc->init.flags & ~supported_init_flags) { + tst_res(TCONF, "Unsupported init flags"suggest to preserve the information printed by
FANOTIFY_INIT_FLAGS_ERR_MSG, you can usetc->init.descthe for the flag name string.
tc->init.desc gets printed by the TINFO message at the start of the patch chunk. The return value from fanotify_init_flags_supported_on_fs() is not preserved anywhere by the new fanotify_get_supported_init_flags() helper function so I have nothing to pass as the second argument of FANOTIFY_INIT_FLAGS_ERR_MSG().
Signature · 11 lines
Martin Doucha [email protected] SW Quality Engineer SUSE LINUX, s.r.o. CORSO IIa Krizikova 148/34 186 00 Prague 8 Czech Republic -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v3 2/2] fanotify14: Improve check for unsupported init flags
Hi all,
...
Quoted 10 lines
Quoted 9 lines
testcases/kernel/syscalls/fanotify/fanotify14.c static void do_test(unsigned int number)
Quoted 5 lines
testcases/kernel/syscalls/fanotify/fanotify14.c +2
-3-if (fan_report_target_fid_unsupported && tc->init.flags &FAN_REPORT_TARGET_FID ) { -FANOTIFY_INIT_FLAGS_ERR_MSG (FAN_REPORT_TARGET_FID , - fan_report_target_fid_unsupported); +if (tc->init.flags & ~supported_init_flags) { + tst_res(TCONF, "Unsupported init flags"suggest to preserve the information printed by
FANOTIFY_INIT_FLAGS_ERR_MSG, you can usetc->init.descthe for the flag name string.
Quoted 5 lines
tc->init.descgets printed by the TINFO message at the start of the patch chunk. The return value fromfanotify_init_flags_supported_on_fs()is not preserved anywhere by the newfanotify_get_supported_init_flags()helper function so I have nothing to pass as the second argument ofFANOTIFY_INIT_FLAGS_ERR_MSG().
You were faster than me. I don't know if it's worth to do mapping with function similar to *tst_strerrno() in lib/errnos.h and print info about unsupported flag (as string) in fanotify_get_supported_init_flags()).
BTW original error message does not print problematic flag in init (e.g. FAN_REPORT_DFID_NAME_TARGET), but the corresponding one in the test (FAN_REPORT_DFID_NAME_TARGET).
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v3 2/2] fanotify14: Improve check for unsupported init flags
In reply to Martin DouchaQuoted 51 lines · Martin Doucha
Quoted 39 lines · Amir Goldstein
Quoted 38 lines · Martin Doucha
Test case 8 of fanotify14 uses init flags supported only on kernel 5.9+ but does not properly check for their support. Rewrite fanotify feature checks using new helper function.
Signed-off-by Martin Doucha <[email protected]>---
Changes since v1:
- Added FAN_CLASS_* constants to support check insetup()
- Added longer patch descriptionChanges since v2: None
I'd rather not squash this patch so that it can be reverted without potentially breaking other tests.
testcases/kernel/syscalls/fanotify/fanotify14.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)testcases/kernel/syscalls/fanotify/fanotify14.c +1
-1@@ -45,8 +45,8 @@static int pipes[2 ] = {-1 ,-1 };static int fanotify_fd; -static int fan_report_target_fid_unsupported;static int ignore_mark_unsupported; +static unsigned int supported_init_flags;struct test_case_flags_t {unsigned long long flags;@@ -246,9 +246,8 @@ static void do_test(unsigned int number)tst_res (TINFO ,"Test case %d: fanotify_init(%s, O_RDONLY)" , number, tc->init.desc);Quoted 9 lines
testcases/kernel/syscalls/fanotify/fanotify14.c static void do_test(unsigned int number)
Quoted 5 lines
testcases/kernel/syscalls/fanotify/fanotify14.c +2
-3-if (fan_report_target_fid_unsupported && tc->init.flags &FAN_REPORT_TARGET_FID ) { -FANOTIFY_INIT_FLAGS_ERR_MSG (FAN_REPORT_TARGET_FID , - fan_report_target_fid_unsupported); +if (tc->init.flags & ~supported_init_flags) { + tst_res(TCONF, "Unsupported init flags"suggest to preserve the information printed by
FANOTIFY_INIT_FLAGS_ERR_MSG, you can usetc->init.descthe for the flag name string.
Quoted 6 lines
tc->init.descgets printed by the TINFO message at the start of the patch chunk. The return value fromfanotify_init_flags_supported_on_fs()is not preserved anywhere by the newfanotify_get_supported_init_flags()helper function so I have nothing to pass as the second argument ofFANOTIFY_INIT_FLAGS_ERR_MSG().
OK.
Thanks,
Amir.
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v3 2/2] fanotify14: Improve check for unsupported init flags
...
Quoted 22 lines
Quoted 21 lines
Quoted 21 lines
Quoted 9 lines
static int pipes[2] = {-1, -1}; static int fanotify_fd;testcases/kernel/syscalls/fanotify/fanotify14.c +1
-1-static int fan_report_target_fid_unsupported;static int ignore_mark_unsupported; +static unsigned int supported_init_flags;struct test_case_flags_t {unsigned long long flags;testcases/kernel/syscalls/fanotify/fanotify14.c static void do_test(unsigned int number) · line 250
Quoted 8 lines
testcases/kernel/syscalls/fanotify/fanotify14.c +2
-3@@ -246,9 +246,8 @@ static void do_test(unsigned int number)tst_res (TINFO ,"Test case %d: fanotify_init(%s, O_RDONLY)" , number, tc->init.desc); -if (fan_report_target_fid_unsupported && tc->init.flags &FAN_REPORT_TARGET_FID ) { -FANOTIFY_INIT_FLAGS_ERR_MSG (FAN_REPORT_TARGET_FID , - fan_report_target_fid_unsupported); +if (tc->init.flags & ~supported_init_flags) { + tst_res(TCONF, "Unsupported init flags"suggest to preserve the information printed by
FANOTIFY_INIT_FLAGS_ERR_MSG, you can usetc->init.descthe for the flag name string.
Quoted 8 lines
Quoted 5 lines
tc->init.descgets printed by the TINFO message at the start of the patch chunk. The return value fromfanotify_init_flags_supported_on_fs()is not preserved anywhere by the newfanotify_get_supported_init_flags()helper function so I have nothing to pass as the second argument ofFANOTIFY_INIT_FLAGS_ERR_MSG().OK.
Amir, thanks for your ack of this final issue. I merged the patchset.
Kind regards,
Petr
Quoted 2 lines
Thanks,
Amir.
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp