From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v5 04/10] fanotify: Add helper for FAN_REPORT_FID support on fs
Date: Wed, 2 Dec 2020 16:46:04 +0100 [thread overview]
Message-ID: <20201202154604.GD12342@yuki.lan> (raw)
In-Reply-To: <20201201174214.24625-5-pvorel@suse.cz>
Hi!
> +/*
> + * @return 0: fanotify supported both in kernel and on tested filesystem
> + * @return -1: FAN_REPORT_FID not supported in kernel
> + * @return -2: FAN_REPORT_FID not supported on tested filesystem
> + */
> +static inline int fanotify_fan_report_fid_supported_on_fs(const char *fname)
> +{
> + int fd;
> + int rval = 0;
> +
> + fd = fanotify_init(FAN_CLASS_NOTIF | FAN_REPORT_FID, O_RDONLY);
> +
> + if (fd < 0) {
> + if (errno == ENOSYS)
> + tst_brk(TCONF, "fanotify not configured in kernel");
> +
> + if (errno == EINVAL)
> + return -1;
> +
> + tst_brk(TBROK | TERRNO, "fanotify_init() failed");
> + }
> +
> + if (fanotify_mark(fd, FAN_MARK_ADD, FAN_ACCESS, AT_FDCWD, fname) < 0) {
> + if (errno == ENODEV || errno == EOPNOTSUPP || errno == EXDEV) {
> + rval = -2;
> + } else {
> + tst_brk(TBROK | TERRNO,
> + "fanotify_mark (%d, FAN_MARK_ADD, ..., AT_FDCWD, \".\") failed", fd);
^
fname?
> + }
> + }
> +
> + SAFE_CLOSE(fd);
> +
> + return rval;
> +}
> +
> +typedef void (*tst_res_func_t)(const char *file, const int lineno,
> + int ttype, const char *fmt, ...);
> +
> +static inline void fanotify_fan_report_fid_err_msg(const char *file,
> + const int lineno, tst_res_func_t res_func, int fail)
> +{
> + if (fail == -1)
> + res_func(file, lineno, TCONF,
> + "FAN_REPORT_FID not supported in kernel?");
> +
> + if (fail == -2)
> + res_func(file, lineno, TCONF,
> + "FAN_REPORT_FID not supported on %s filesystem",
> + tst_device->fs_type);
> +}
Maybe this would be just easier to read as a macro:
#define FANOTIFY_FAN_REPORT_FID_ERR_MSG(res_func, fail) do { \
if (fail == -1) \
res_func(TCONF, "FAN_REPORT_FID not supported in kernel?"); \
if (fail == -2) \
res_func(TCONF, ...); \
} while (0)
> +#define FANOTIFY_FAN_REPORT_FID_ERR_MSG(fail) \
> + fanotify_fan_report_fid_err_msg(__FILE__, __LINE__, tst_res_, (fail))
> +
> +static inline void require_fanotify_fan_report_fid_supported_on_fs(const char *file,
> + const int lineno, const char *fname)
> +{
> + int rval;
> +
> + rval = fanotify_fan_report_fid_supported_on_fs(fname);
> + if (rval)
> + fanotify_fan_report_fid_err_msg(file, lineno, tst_brk_, rval);
We don't have to do the if here, just pass the rval, it will not trigger
tst_brk() if we pass zero.
The rest is good.
--
Cyril Hrubis
chrubis@suse.cz
next prev parent reply other threads:[~2020-12-02 15:46 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-01 17:42 [LTP] [PATCH v5 00/10] Introduce SAFE_FANOTIFY_MARK() macro + cleanup Petr Vorel
2020-12-01 17:42 ` [LTP] [PATCH v5 01/10] fanotify12: Drop incorrect hint Petr Vorel
2020-12-02 15:09 ` Cyril Hrubis
2020-12-01 17:42 ` [LTP] [PATCH v5 02/10] fanotify: Add helper for access permission check Petr Vorel
2020-12-02 15:24 ` Cyril Hrubis
2020-12-01 17:42 ` [LTP] [PATCH v5 03/10] fanotify: Add helper for event support check Petr Vorel
2020-12-02 15:36 ` Cyril Hrubis
2020-12-01 17:42 ` [LTP] [PATCH v5 04/10] fanotify: Add helper for FAN_REPORT_FID support on fs Petr Vorel
2020-12-02 15:46 ` Cyril Hrubis [this message]
2020-12-02 18:04 ` Petr Vorel
2020-12-04 10:11 ` Amir Goldstein
2020-12-04 13:47 ` Petr Vorel
2020-12-01 17:42 ` [LTP] [PATCH v5 05/10] fanotify16: Test also on FUSE Petr Vorel
2020-12-02 15:46 ` Cyril Hrubis
2020-12-01 17:42 ` [LTP] [PATCH v5 06/10] fanotify: Add helper for mark support check Petr Vorel
2020-12-02 6:27 ` Amir Goldstein
2020-12-02 15:57 ` Cyril Hrubis
2020-12-02 17:05 ` Petr Vorel
2020-12-02 15:53 ` Cyril Hrubis
2020-12-01 17:42 ` [LTP] [PATCH v5 07/10] fanotify: Introduce SAFE_FANOTIFY_MARK() macro Petr Vorel
2020-12-02 15:55 ` Cyril Hrubis
2020-12-02 15:58 ` Cyril Hrubis
2020-12-01 17:42 ` [LTP] [PATCH v5 08/10] fanotify: Use tst_brk_ in safe_fanotify_init() Petr Vorel
2020-12-02 15:55 ` Cyril Hrubis
2020-12-01 17:42 ` [LTP] [PATCH v5 09/10] fanotify: Add a pedantic check for return value Petr Vorel
2020-12-02 15:56 ` Cyril Hrubis
2020-12-01 17:42 ` [LTP] [PATCH] fanotify: Cleanup <sys/fanotify.h> use Petr Vorel
2020-12-02 16:12 ` Cyril Hrubis
2020-12-01 17:46 ` [LTP] [PATCH v5 00/10] Introduce SAFE_FANOTIFY_MARK() macro + cleanup Petr Vorel
2020-12-02 6:47 ` Amir Goldstein
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201202154604.GD12342@yuki.lan \
--to=chrubis@suse.cz \
--cc=ltp@lists.linux.it \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox