All of lore.kernel.org
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v3 02/16] lib: Add interface to list supported filesystems
Date: Wed, 11 Oct 2017 16:41:16 +0200	[thread overview]
Message-ID: <20171011144130.29728-2-chrubis@suse.cz> (raw)
In-Reply-To: <20171011144130.29728-1-chrubis@suse.cz>

A filesystem is supported if kernel can mount it (we do not get ENODEV
when we attempt to mount it) and if there is mkfs installed so that we
can format a test device.

The function starts with a whitelist of filesystems to use and loops
over them filtering out unsupported ones, then finally returns a list
of filesystem that could be used for the testing.

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 include/tst_fs.h             |   4 ++
 lib/tst_supported_fs_types.c | 118 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 122 insertions(+)
 create mode 100644 lib/tst_supported_fs_types.c

diff --git a/include/tst_fs.h b/include/tst_fs.h
index 52befbec9..1f6d2bab5 100644
--- a/include/tst_fs.h
+++ b/include/tst_fs.h
@@ -146,6 +146,10 @@ int tst_get_path(const char *prog_name, char *buf, size_t buf_len);
  */
 int tst_fill_file(const char *path, char pattern, size_t bs, size_t bcount);
 
+/*
+ * Returns NULL-terminated array of kernel-supported filesystems.
+ */
+const char **tst_get_supported_fs_types(void);
 
 #ifdef TST_TEST_H__
 static inline long tst_fs_type(const char *path)
diff --git a/lib/tst_supported_fs_types.c b/lib/tst_supported_fs_types.c
new file mode 100644
index 000000000..a23b1ed52
--- /dev/null
+++ b/lib/tst_supported_fs_types.c
@@ -0,0 +1,118 @@
+/*
+ * Copyright (c) 2017 Cyril Hrubis <chrubis@suse.cz>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdio.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <sys/mount.h>
+#include <sys/wait.h>
+
+#define TST_NO_DEFAULT_MAIN
+#include "tst_test.h"
+#include "tst_fs.h"
+
+static const char *const fs_type_whitelist[] = {
+	"ext2",
+	"ext3",
+	"ext4",
+	"xfs",
+	"btrfs",
+	"vfat",
+	"exfat",
+	"ntfs",
+	NULL
+};
+
+static const char *fs_types[ARRAY_SIZE(fs_type_whitelist)];
+
+static int has_mkfs(const char *fs_type)
+{
+	char buf[128];
+	int ret;
+
+	sprintf(buf, "mkfs.%s >/dev/null 2>&1", fs_type);
+
+	ret = tst_system(buf);
+
+	if (WEXITSTATUS(ret) == 127) {
+		tst_res(TINFO, "mkfs.%s does not exist", fs_type);
+		return 0;
+	}
+
+	tst_res(TINFO, "mkfs.%s does exist", fs_type);
+	return 1;
+}
+
+static int has_kernel_support(const char *fs_type)
+{
+	static int fuse_supported = -1;
+	const char *tmpdir = getenv("TMPDIR");
+	char buf[128];
+	int ret;
+
+	if (!tmpdir)
+		tmpdir = "/tmp";
+
+	mount("/dev/zero", tmpdir, fs_type, 0, NULL);
+	if (errno != ENODEV) {
+		tst_res(TINFO, "Kernel supports %s", fs_type);
+		return 1;
+	}
+
+	/* Is FUSE supported by kernel? */
+	if (fuse_supported == -1) {
+		ret = open("/dev/fuse", O_RDWR);
+		if (ret < 0) {
+			fuse_supported = 0;
+		} else {
+			fuse_supported = 1;
+			SAFE_CLOSE(ret);
+		}
+	}
+
+	if (!fuse_supported)
+		return 0;
+
+	/* Is FUSE implementation installed? */
+	sprintf(buf, "mount.%s >/dev/null 2>&1", fs_type);
+
+	ret = tst_system(buf);
+	if (WEXITSTATUS(ret) == 127) {
+		tst_res(TINFO, "Filesystem %s is not supported", fs_type);
+		return 0;
+	}
+
+	tst_res(TINFO, "FUSE does support %s", fs_type);
+	return 1;
+}
+
+static int is_supported(const char *fs_type)
+{
+	return has_kernel_support(fs_type) && has_mkfs(fs_type);
+}
+
+const char **tst_get_supported_fs_types(void)
+{
+	unsigned int i, j = 0;
+
+	for (i = 0; fs_type_whitelist[i]; i++) {
+		if (is_supported(fs_type_whitelist[i]))
+			fs_types[j++] = fs_type_whitelist[i];
+	}
+
+	return fs_types;
+}
-- 
2.13.5


  reply	other threads:[~2017-10-11 14:41 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-11 14:41 [LTP] [PATCH v3 01/16] lib/tst_mkfs: Clear first 512k of the device Cyril Hrubis
2017-10-11 14:41 ` Cyril Hrubis [this message]
2017-11-09 18:38   ` [LTP] [PATCH v3 02/16] lib: Add interface to list supported filesystems Sandeep Patil
2017-10-11 14:41 ` [LTP] [PATCH v3 03/16] SAFE_MOUNT: Handle FUSE mounts as well Cyril Hrubis
2017-10-11 14:41 ` [LTP] [PATCH v3 04/16] lib/tst_test: Add .all_filesystems flag Cyril Hrubis
2017-10-11 14:41 ` [LTP] [PATCH v3 05/16] lib/tst_fs: Add tst_fill_fs() Cyril Hrubis
2017-11-09 18:50   ` Sandeep Patil
2017-10-11 14:41 ` [LTP] [PATCH v3 06/16] syscalls/fallocate05: New test Cyril Hrubis
2017-10-11 14:41 ` [LTP] [PATCH v3 07/16] syscalls/msync04: Run test for all filesystems Cyril Hrubis
2017-10-11 14:41 ` [LTP] [PATCH v3 08/16] syscalls/fallocate04: Convert to the new library Cyril Hrubis
2017-10-11 14:41 ` [LTP] [PATCH v3 09/16] syscalls/fallocate04: Run test for all filesystems Cyril Hrubis
2017-10-11 14:41 ` [LTP] [PATCH v3 10/16] syscalls/setxattr01: Convert to the new library Cyril Hrubis
2017-10-11 14:41 ` [LTP] [PATCH v3 11/16] syscalls/setxattr01: Run test for all filesystems Cyril Hrubis
2017-10-11 14:41 ` [LTP] [PATCH v3 12/16] syscallse/setxattr02: Convert to the new library Cyril Hrubis
2017-10-11 14:41 ` [LTP] [PATCH v3 13/16] syscalls/fsync01: " Cyril Hrubis
2017-10-11 14:41 ` [LTP] [PATCH v3 14/16] syscalls/fsync01: Run test for all filesystems Cyril Hrubis
2017-10-11 14:41 ` [LTP] [PATCH v3 15/16] fs/fs_fill: Add a test to fill a FS in a few threads Cyril Hrubis
2017-11-09 10:03   ` Li Wang
2017-11-09 10:19     ` Cyril Hrubis
2017-11-09 10:43       ` Li Wang
2017-11-09 10:50         ` Cyril Hrubis
2017-11-09 10:58           ` Li Wang
2017-10-11 14:41 ` [LTP] [PATCH v3 16/16] doc: Update device flags in test-writing-guidelines Cyril Hrubis
2017-11-09 18:51   ` Sandeep Patil
2017-11-01 12:24 ` [LTP] [PATCH v3 01/16] lib/tst_mkfs: Clear first 512k of the device Cyril Hrubis
2017-11-02  9:26   ` Jan Stancek
2017-11-02 13:15     ` Cyril Hrubis

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=20171011144130.29728-2-chrubis@suse.cz \
    --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.