All of lore.kernel.org
 help / color / mirror / Atom feed
From: Zhao Gongyi <zhaogongyi@huawei.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH] lib/tst_supported_fs_types.c: Add tmpfs to filesystem whitelist
Date: Tue, 9 Mar 2021 21:01:15 +0800	[thread overview]
Message-ID: <20210309130115.9693-1-zhaogongyi@huawei.com> (raw)

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(-)

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);
--
2.17.1


             reply	other threads:[~2021-03-09 13:01 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-09 13:01 Zhao Gongyi [this message]
2021-03-10 12:29 ` [LTP] [PATCH] lib/tst_supported_fs_types.c: Add tmpfs to filesystem whitelist Cyril Hrubis
2021-03-12 10:46 ` Petr Vorel
2021-04-13 17:28 ` Cyril Hrubis
  -- strict thread matches above, loose matches on Subject: below --
2021-03-09 13:08 zhaogongyi
2021-03-04  2:14 zhaogongyi
2021-03-04  2:08 Zhao Gongyi
2021-03-08 16:11 ` Cyril Hrubis
2021-02-27  9:33 zhaogongyi
2021-03-02 10:43 ` Cyril Hrubis
2021-02-26  9:06 Zhao Gongyi
2021-02-26  9:54 ` 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=20210309130115.9693-1-zhaogongyi@huawei.com \
    --to=zhaogongyi@huawei.com \
    --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.