All of lore.kernel.org
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH 1/1] lib: Fix fs support detection for non-root
Date: Thu, 28 Jan 2021 15:59:53 +0100	[thread overview]
Message-ID: <YBLRadSFcxAWN57a@yuki.lan> (raw)
In-Reply-To: <20210128144649.6012-1-pvorel@suse.cz>

Hi!
> grep /proc/filesystems to find kernel support.
> But consider only 0 (filesystem found) or 1 (not found),
> ignore other results (e.g. 2: /proc/filesystems not available or
> no permissions) and fallback to old solution (calling mount()).

Why is this needed?

Also this breaks FUSE detection.

> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
>  lib/tst_supported_fs_types.c | 19 +++++++++++++++++++
>  1 file changed, 19 insertions(+)
> 
> diff --git a/lib/tst_supported_fs_types.c b/lib/tst_supported_fs_types.c
> index 00ede549d..66307e09e 100644
> --- a/lib/tst_supported_fs_types.c
> +++ b/lib/tst_supported_fs_types.c
> @@ -52,10 +52,29 @@ static int has_kernel_support(const char *fs_type, int flags)
>  	char buf[128];
>  	int ret;
>  
> +	const char * const argv[] = { "grep", "-q", "-F", "-w", fs_type, "/proc/filesystems", NULL };
> +	ret = tst_cmd_(NULL, argv, "/dev/null", "/dev/null", TST_CMD_PASS_RETVAL);

Can't we just open the file and use fgets() in a loop?

Why do we have to execute a grep binary for something like this?

> +	if (ret == 0) {
> +		tst_res(TINFO, "Kernel supports %s", fs_type);
> +		return 1;
> +	}
> +
> +	if (ret == 1) {
> +		tst_res(TINFO, "Filesystem %s is not supported", fs_type);
> +		return 0;
> +	}
> +
>  	if (!tmpdir)
>  		tmpdir = "/tmp";
>  
>  	mount("/dev/zero", tmpdir, fs_type, 0, NULL);
> +
> +	if (errno == EPERM) {
> +		tst_res(TWARN, "No permission to detect support for %s", fs_type);
> +		return 1;

Maybe we can try to read /proc/filesystems here as a fallback?

Again why do we need this at all?

> +	}
> +
>  	if (errno != ENODEV) {
>  		tst_res(TINFO, "Kernel supports %s", fs_type);
>  		return 1;
> -- 
> 2.30.0
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

-- 
Cyril Hrubis
chrubis@suse.cz

  parent reply	other threads:[~2021-01-28 14:59 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-28 14:46 [LTP] [PATCH 1/1] lib: Fix fs support detection for non-root Petr Vorel
2021-01-28 14:55 ` Petr Vorel
2021-01-28 14:59 ` Cyril Hrubis [this message]
2021-01-28 16:03   ` Petr Vorel

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=YBLRadSFcxAWN57a@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.