Skip to contentSkip to conversation

lib/tst_supported_fs_types.c: Add tmpfs to filesystem whitelist

PATCH New zhaogongyi 2 participants 2 messages Feb 27, 2021 – Mar 2, 2021

lore
Share & tools
lore

zhaogongyi

author
#0 lore raw

PATCH 1/1 lib/tst_supported_fs_types.c: Add tmpfs to filesystem whitelist

Hi Cyril,

Quoted 4 lines

But there is another problem there, since the code still mounts tmpfs on tmpdir for a short while, which is temporary directory used by all LTP tests, which may potentially break tests that runs in parallel.

In general, when all_filesystems has been set to 1, the needs_tmpdir would be set to 1 and the mntpoint must has been set to some path, so the test run in /tmp/tmpxxxxxx/mntpoint and other LTP tests would run in another tmpdir. So it has no problem for running in parallel.

I don't know if I understand it right.

Quoted 4 lines

So we will have to prepare a temporary directory with mkdtemp() under the tmpdir as well and pass that to the mount() syscall instead.

Thanks so much!

-------------------------------------------------------------------------------------------------------

Quoted 67 lines

Hi!

lib/tst_supported_fs_types.c static int has_kernel_support(const char *fs_type,

Quoted 24 lines
(quoted diff) +0 -0

b/lib/tst_supported_fs_types.c index 00ede549d..696b6731e 100644

lib/tst_supported_fs_types.c +5 -0
@@ -22,6 +22,7 @@ static const char *const fs_type_whitelist[] = {
 	"vfat",
 	"exfat",
 	"ntfs",
+	"tmpfs",
 	NULL
 };
 
@@ -34,6 +35,10 @@ static int has_mkfs(const char *fs_type)
 
 	sprintf(buf, "mkfs.%s >/dev/null 2>&1", fs_type);
 
+	if (strstr(buf, "mkfs.tmpfs")) {
+		return 1;
+	}
+
 	ret = tst_system(buf);
 
 	if (WEXITSTATUS(ret) == 127) {
@@ -55,8 +60,8 @@ static int has_kernel_support(const char *fs_type,

int flags)

lib/tst_supported_fs_types.c static int has_kernel_support(const char *fs_type, · line 63

Quoted 6 lines
lib/tst_supported_fs_types.c +1 -2
 	if (!tmpdir)
 		tmpdir = "/tmp";
 
-	mount("/dev/zero", tmpdir, fs_type, 0, NULL);
-	if (errno != ENODEV) {
+	ret = mount("/dev/zero", tmpdir, fs_type, 0, NULL);

The manual page explicitly says that errno is set to ENODEV if filesystem is not supported by kernel. So the check for errno should stay, since the statement above will fail to mount any real filesystem since we pass "/dev/zero" instead of valid filesystem image there.

I.e. if we pass a real filesystem there it will either fail with EINVAL (since /dev/zero does not have a valid superblock) or ENODEV if there is no kernel driver for the filesystem.

lib/tst_supported_fs_types.c static int has_kernel_support(const char *fs_type, · line 64

Quoted 1 line
lib/tst_supported_fs_types.c +1 -0
+	if (!ret) {

I guess that tmpfs succeeds to mount there. So I guess that we should change the condition to:

	if ((ret && errno != ENODEV) || !ret) {
		if (!ret)
			tst_umount(tmpdir);

		tst_res(TINFO, "Kernel supports %s", fs_type);
		return 1;
	}

But there is another problem there, since the code still mounts tmpfs on tmpdir for a short while, which is temporary directory used by all LTP tests, which may potentially break tests that runs in parallel.

So we will have to prepare a temporary directory with mkdtemp() under the tmpdir as well and pass that to the mount() syscall instead.

--
Cyril Hrubis
[email protected]

#1 lore raw

PATCH 1/1 lib/tst_supported_fs_types.c: Add tmpfs to filesystem whitelist

Hi!

Quoted 8 lines
Quoted 3 lines

But there is another problem there, since the code still mounts tmpfs on tmpdir for a short while, which is temporary directory used by all LTP tests, which may potentially break tests that runs in parallel.

In general, when all_filesystems has been set to 1, the needs_tmpdir would be set to 1 and the mntpoint must has been set to some path, so the test run in /tmp/tmpxxxxxx/mntpoint and other LTP tests would run in another tmpdir. So it has no problem for running in parallel.

I don't know if I understand it right.

The has_kernel_support() uses TMPDIR as the mount point, which is the parent directory for all LTP tests, moreover it often points to just "/tmp". If you mount anything over that directory, even for a short while, the whole system will get different and empty "/tmp" which will possibly break many things.

We may get over this with using "." instead, in a case that testcase has created temporary directory and changed the PWD to it, but it's not that simple either, since tst_test.c is not the only place that calls has_kernel_support().

We have testcases/lib/tst_supported_fs.c helper as well that is used by shell tests. This is a standalone binary that does not create a temporary directory and should work even without TMPDIR being set, which is the reason we have the if (!tmpdir) tmpdir = "/tmp"; check in the has_kernel_support() function to begin with.

So all in all I guess that safest option would be to create a unique temporary directory under TMPDIR and use it as a mount point in the has_kernel_support() function.

Signature · 2 lines
Cyril Hrubis
[email protected]