Message ID | 20201126214121.6836-6-pvorel@suse.cz |
---|---|
State | Changes Requested |
Headers | show |
Series | Introduce SAFE_FANOTIFY_MARK() macro + cleanup | expand |
On Thu, Nov 26, 2020 at 11:41 PM Petr Vorel <pvorel@suse.cz> wrote: > > in safe_fanotify_init() > > That require to move the definition after flags. > > Also use tst_res_()/tst_brk_() instead of tst_res()/tst_brk() in > safe_fanotify_init() (synchronize with safe_fanotify_mark()). > > Make use of this simplification in fanotify15.c. > > Suggested-by: Amir Goldstein <amir73il@gmail.com> > Signed-off-by: Petr Vorel <pvorel@suse.cz> > --- > Changes v3->v4: > * use tst_res_() and tst_brk_() for safe_*() functions > > testcases/kernel/syscalls/fanotify/fanotify.h | 64 +++++++++++-------- > .../kernel/syscalls/fanotify/fanotify01.c | 13 +--- > .../kernel/syscalls/fanotify/fanotify13.c | 12 +--- > .../kernel/syscalls/fanotify/fanotify15.c | 9 +-- > 4 files changed, 41 insertions(+), 57 deletions(-) > > diff --git a/testcases/kernel/syscalls/fanotify/fanotify.h b/testcases/kernel/syscalls/fanotify/fanotify.h > index 2a5280636..4b725f334 100644 > --- a/testcases/kernel/syscalls/fanotify/fanotify.h > +++ b/testcases/kernel/syscalls/fanotify/fanotify.h > @@ -38,32 +38,6 @@ static long fanotify_mark(int fd, unsigned int flags, uint64_t mask, > > #endif /* HAVE_SYS_FANOTIFY_H */ > > -int safe_fanotify_init(const char *file, const int lineno, > - unsigned int flags, unsigned int event_f_flags) > -{ > - int rval; > - > -#ifdef HAVE_SYS_FANOTIFY_H > - rval = fanotify_init(flags, event_f_flags); > - > - if (rval == -1) { > - if (errno == ENOSYS) { > - tst_brk(TCONF, > - "fanotify is not configured in this kernel."); > - } > - tst_brk(TBROK | TERRNO, > - "%s:%d: fanotify_init() failed", file, lineno); > - } > -#else > - tst_brk(TCONF, "Header <sys/fanotify.h> is not present"); > -#endif /* HAVE_SYS_FANOTIFY_H */ > - > - return rval; > -} > - > -#define SAFE_FANOTIFY_INIT(fan, mode) \ > - safe_fanotify_init(__FILE__, __LINE__, (fan), (mode)) > - > #ifndef FAN_REPORT_TID > #define FAN_REPORT_TID 0x00000100 > #endif > @@ -190,6 +164,44 @@ struct fanotify_event_info_fid { > #define MAX_HANDLE_SZ 128 > #endif > > +int safe_fanotify_init(const char *file, const int lineno, > + unsigned int flags, unsigned int event_f_flags) > +{ > + int rval; > + > +#ifdef HAVE_SYS_FANOTIFY_H > + rval = fanotify_init(flags, event_f_flags); > + > + if (rval == -1) { > + if (errno == ENOSYS) { > + tst_brk_(file, lineno, TCONF, > + "fanotify not configured in kernel"); > + } > + > + if (errno == EINVAL) { > + if (flags & FAN_REPORT_FID) { > + tst_brk_(file, lineno, TCONF, > + "FAN_REPORT_FID not supported in kernel?"); > + } Unless I am missing something, this would make fanotify_fan_report_fid_supported_on_fs() break on old kernel in the start of fanotify01. That was not the intention... The FAN_REPORT_FID test case in fanotify01 should be skipped if either kernel has no support for FAN_REPORT_FID (checked on fanotify_init) or filesystem has no support for FAN_REPORT_FID (checked on fanotify_mark). I guess you can leave SAFE_FANOTIFY_INIT as is and change the helper fanotify_fan_report_fid_supported() to return a different value for unsupported by kernel and unsupported by fs and then pass that value of fan_report_fid_unsupported to another helper to decide if test case should be skipped and print the proper TCONF message. > + > + if (flags & FAN_REPORT_NAME) { > + tst_brk_(file, lineno, TCONF, > + "FAN_REPORT_NAME not supported in kernel?"); > + } This check should be before the check for FAN_REPORT_FID, because a kernel that does not support FAN_REPORT_FID also does not support FAN_REPORT_NAME, but not the other way around. I think that also solves the problem you mentioned in the cover letter about fanotify16, but if not you can leave that problem to me. Thanks, Amir.
diff --git a/testcases/kernel/syscalls/fanotify/fanotify.h b/testcases/kernel/syscalls/fanotify/fanotify.h index 2a5280636..4b725f334 100644 --- a/testcases/kernel/syscalls/fanotify/fanotify.h +++ b/testcases/kernel/syscalls/fanotify/fanotify.h @@ -38,32 +38,6 @@ static long fanotify_mark(int fd, unsigned int flags, uint64_t mask, #endif /* HAVE_SYS_FANOTIFY_H */ -int safe_fanotify_init(const char *file, const int lineno, - unsigned int flags, unsigned int event_f_flags) -{ - int rval; - -#ifdef HAVE_SYS_FANOTIFY_H - rval = fanotify_init(flags, event_f_flags); - - if (rval == -1) { - if (errno == ENOSYS) { - tst_brk(TCONF, - "fanotify is not configured in this kernel."); - } - tst_brk(TBROK | TERRNO, - "%s:%d: fanotify_init() failed", file, lineno); - } -#else - tst_brk(TCONF, "Header <sys/fanotify.h> is not present"); -#endif /* HAVE_SYS_FANOTIFY_H */ - - return rval; -} - -#define SAFE_FANOTIFY_INIT(fan, mode) \ - safe_fanotify_init(__FILE__, __LINE__, (fan), (mode)) - #ifndef FAN_REPORT_TID #define FAN_REPORT_TID 0x00000100 #endif @@ -190,6 +164,44 @@ struct fanotify_event_info_fid { #define MAX_HANDLE_SZ 128 #endif +int safe_fanotify_init(const char *file, const int lineno, + unsigned int flags, unsigned int event_f_flags) +{ + int rval; + +#ifdef HAVE_SYS_FANOTIFY_H + rval = fanotify_init(flags, event_f_flags); + + if (rval == -1) { + if (errno == ENOSYS) { + tst_brk_(file, lineno, TCONF, + "fanotify not configured in kernel"); + } + + if (errno == EINVAL) { + if (flags & FAN_REPORT_FID) { + tst_brk_(file, lineno, TCONF, + "FAN_REPORT_FID not supported in kernel?"); + } + + if (flags & FAN_REPORT_NAME) { + tst_brk_(file, lineno, TCONF, + "FAN_REPORT_NAME not supported in kernel?"); + } + } + + tst_brk_(file, lineno, TBROK | TERRNO, "fanotify_init() failed"); + } +#else + tst_brk_(file, lineno, TCONF, "Header <sys/fanotify.h> is not present"); +#endif /* HAVE_SYS_FANOTIFY_H */ + + return rval; +} + +#define SAFE_FANOTIFY_INIT(fan, mode) \ + safe_fanotify_init(__FILE__, __LINE__, (fan), (mode)) + static inline int safe_fanotify_mark(const char *file, const int lineno, int fd, unsigned int flags, uint64_t mask, int dfd, const char *pathname) diff --git a/testcases/kernel/syscalls/fanotify/fanotify01.c b/testcases/kernel/syscalls/fanotify/fanotify01.c index 170428eba..cd571e002 100644 --- a/testcases/kernel/syscalls/fanotify/fanotify01.c +++ b/testcases/kernel/syscalls/fanotify/fanotify01.c @@ -95,18 +95,7 @@ static void test_fanotify(unsigned int n) return; } - fd_notify = fanotify_init(tc->init_flags, O_RDONLY); - if (fd_notify < 0) { - if (errno == EINVAL && - (tc->init_flags & FAN_REPORT_FID)) { - tst_res(TCONF, - "FAN_REPORT_FID not supported in kernel?"); - return; - } - tst_brk(TBROK | TERRNO, - "fanotify_init (0x%x, O_RDONLY) " - "failed", tc->init_flags); - } + fd_notify = SAFE_FANOTIFY_INIT(tc->init_flags, O_RDONLY); SAFE_FANOTIFY_MARK(fd_notify, FAN_MARK_ADD | mark->flag, FAN_ACCESS | FAN_MODIFY | FAN_CLOSE | FAN_OPEN, AT_FDCWD, fname); diff --git a/testcases/kernel/syscalls/fanotify/fanotify13.c b/testcases/kernel/syscalls/fanotify/fanotify13.c index 2c1dc4624..3d5cfc13b 100644 --- a/testcases/kernel/syscalls/fanotify/fanotify13.c +++ b/testcases/kernel/syscalls/fanotify/fanotify13.c @@ -142,17 +142,7 @@ static void do_test(unsigned int number) "Test #%d: FAN_REPORT_FID with mark flag: %s", number, mark->name); - fanotify_fd = fanotify_init(FAN_CLASS_NOTIF | FAN_REPORT_FID, O_RDONLY); - if (fanotify_fd == -1) { - if (errno == EINVAL) { - tst_res(TCONF, - "FAN_REPORT_FID not supported by kernel"); - return; - } - tst_brk(TBROK | TERRNO, - "fanotify_init(FAN_CLASS_NOTIF | FAN_REPORT_FID, " - "O_RDONLY) failed"); - } + fanotify_fd = SAFE_FANOTIFY_INIT(FAN_CLASS_NOTIF | FAN_REPORT_FID, O_RDONLY); /* * Place marks on a set of objects and setup the expected masks diff --git a/testcases/kernel/syscalls/fanotify/fanotify15.c b/testcases/kernel/syscalls/fanotify/fanotify15.c index 6121ef211..8bf8f2045 100644 --- a/testcases/kernel/syscalls/fanotify/fanotify15.c +++ b/testcases/kernel/syscalls/fanotify/fanotify15.c @@ -277,14 +277,7 @@ static void do_setup(void) fd = SAFE_FANOTIFY_INIT(FAN_CLASS_NOTIF, O_RDONLY); SAFE_CLOSE(fd); - fanotify_fd = fanotify_init(FAN_REPORT_FID, O_RDONLY); - if (fanotify_fd == -1) { - if (errno == EINVAL) - tst_brk(TCONF, - "FAN_REPORT_FID not supported in kernel"); - tst_brk(TBROK | TERRNO, - "fanotify_init(FAN_REPORT_FID, O_RDONLY) failed"); - } + fanotify_fd = SAFE_FANOTIFY_INIT(FAN_REPORT_FID, O_RDONLY); SAFE_MKDIR(TEST_DIR, 0755);
in safe_fanotify_init() That require to move the definition after flags. Also use tst_res_()/tst_brk_() instead of tst_res()/tst_brk() in safe_fanotify_init() (synchronize with safe_fanotify_mark()). Make use of this simplification in fanotify15.c. Suggested-by: Amir Goldstein <amir73il@gmail.com> Signed-off-by: Petr Vorel <pvorel@suse.cz> --- Changes v3->v4: * use tst_res_() and tst_brk_() for safe_*() functions testcases/kernel/syscalls/fanotify/fanotify.h | 64 +++++++++++-------- .../kernel/syscalls/fanotify/fanotify01.c | 13 +--- .../kernel/syscalls/fanotify/fanotify13.c | 12 +--- .../kernel/syscalls/fanotify/fanotify15.c | 9 +-- 4 files changed, 41 insertions(+), 57 deletions(-)