diff mbox series

lib/tst_supported_fs_types.c: Add tmpfs to filesystem whitelist

Message ID 20210309130115.9693-1-zhaogongyi@huawei.com
State Accepted
Headers show
Series lib/tst_supported_fs_types.c: Add tmpfs to filesystem whitelist | expand

Commit Message

Zhao Gongyi March 9, 2021, 1:01 p.m. UTC
In many embedded system, we need add tmpfs to filesystem whitelist since
there is only tmpfs can be used to test.

Signed-off-by: Zhao Gongyi <zhaogongyi@huawei.com>

---------------
v2->v3:
1)skipping mkfs for tmpfs gracefully.
2)replace sprintf with snprintf.
3)remove __func__ in the message
4)replace rmdir with SAFE_RMDIR
---------------
---
 lib/tst_supported_fs_types.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

--
2.17.1

Comments

Cyril Hrubis March 10, 2021, 12:29 p.m. UTC | #1
Hi!
> In many embedded system, we need add tmpfs to filesystem whitelist since
> there is only tmpfs can be used to test.
> 
> Signed-off-by: Zhao Gongyi <zhaogongyi@huawei.com>
> 
> ---------------
> v2->v3:
> 1)skipping mkfs for tmpfs gracefully.
> 2)replace sprintf with snprintf.
> 3)remove __func__ in the message
> 4)replace rmdir with SAFE_RMDIR
> ---------------

Minor nits:

This changelog part should be below the "---" line, since that part gets
cut out automatically and the patch subject should have v3 in it's name
(git format-patch -v3 ...).

As for the rest of the patch, it's nearly perfect, I will push it with
minor changes but we need to apply my patchset[1] first so that we can
skip a few tests on tmpfs.

[1] http://patchwork.ozlabs.org/project/ltp/list/?series=233180
Petr Vorel March 12, 2021, 10:46 a.m. UTC | #2
Hi Gongyi,

Reviewed-by: Petr Vorel <pvorel@suse.cz>
Thanks!

Kind regards,
Petr
Cyril Hrubis April 13, 2021, 5:28 p.m. UTC | #3
Hi!
Finally pushed, along with two patches that skip sync and O_DIRECT tests
on tmpfs, thanks.
diff mbox series

Patch

diff --git a/lib/tst_supported_fs_types.c b/lib/tst_supported_fs_types.c
index 00ede549d..b5e3cbe85 100644
--- a/lib/tst_supported_fs_types.c
+++ b/lib/tst_supported_fs_types.c
@@ -22,6 +22,7 @@  static const char *const fs_type_whitelist[] = {
 	"vfat",
 	"exfat",
 	"ntfs",
+	"tmpfs",
 	NULL
 };

@@ -32,6 +33,11 @@  static int has_mkfs(const char *fs_type)
 	char buf[128];
 	int ret;

+	if (strstr(fs_type, "tmpfs")) {
+		tst_res(TINFO, "mkfs is not needed for tmpfs");
+		return 1;
+	}
+
 	sprintf(buf, "mkfs.%s >/dev/null 2>&1", fs_type);

 	ret = tst_system(buf);
@@ -50,17 +56,28 @@  static int has_kernel_support(const char *fs_type, int flags)
 	static int fuse_supported = -1;
 	const char *tmpdir = getenv("TMPDIR");
 	char buf[128];
+	char template[PATH_MAX];
 	int ret;

 	if (!tmpdir)
 		tmpdir = "/tmp";

-	mount("/dev/zero", tmpdir, fs_type, 0, NULL);
-	if (errno != ENODEV) {
+	snprintf(template, sizeof(template), "%s/mountXXXXXX", tmpdir);
+	if (mkdtemp(template) == NULL) {
+		tst_brk(TBROK | TERRNO , "mkdtemp(%s) failed", template);
+	}
+
+	ret = mount("/dev/zero", template, fs_type, 0, NULL);
+	if ((ret && errno != ENODEV) || !ret) {
+		if (!ret)
+			tst_umount(template);
 		tst_res(TINFO, "Kernel supports %s", fs_type);
+		SAFE_RMDIR(template);
 		return 1;
 	}

+	SAFE_RMDIR(template);
+
 	/* Is FUSE supported by kernel? */
 	if (fuse_supported == -1) {
 		ret = open("/dev/fuse", O_RDWR);