diff mbox series

[v2,2/4] lib/tst_test.c: add .needs_devfs flag

Message ID 1534409147-29519-2-git-send-email-yangx.jy@cn.fujitsu.com
State Accepted
Headers show
Series [v2,1/4] lib/tst_path_has_mnt_flags.c: Factor out tst_path_has_mnt_flags() for new API | expand

Commit Message

Xiao Yang Aug. 16, 2018, 8:45 a.m. UTC
We add .needs_devfs flag to prepare a suitable filesystem to test
device special files and use ext2 instead of tmpfs(because tmpfs
doesn't support extended attributes) as default filesystem if
.dev_fs_type is not specified.

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 include/tst_test.h |  1 +
 lib/tst_test.c     | 32 ++++++++++++++++++++++++++++++--
 2 files changed, 31 insertions(+), 2 deletions(-)

Comments

Cyril Hrubis Aug. 16, 2018, 1:28 p.m. UTC | #1
Hi!
> We add .needs_devfs flag to prepare a suitable filesystem to test
> device special files and use ext2 instead of tmpfs(because tmpfs
> doesn't support extended attributes) as default filesystem if
> .dev_fs_type is not specified.

Can we do that only if the test temporary directory is not suitable for
creating devices?

There are distributions out there that have /tmp residing on pretty much
normal filesystems, also user can override TMPDIR to point to a path
backed up by a regular fs. In these cases this will slow down these
tests for no good reason.

So I would rather go for:

if tst_test->needs_devfs is set:

* mkdir tst_test->mntpoint if it does not exits
* check if tst_test->mntpoint is suitable for creating devices
* if not, mount some filesystem over it
  - mounting tmpfs without nodev flag should be more than enough
    and if that fails for you, we can fall back to a regular filesystem
Xiao Yang Aug. 17, 2018, 4:26 a.m. UTC | #2
On 2018/08/16 21:28, Cyril Hrubis wrote:
> Hi!
>> We add .needs_devfs flag to prepare a suitable filesystem to test
>> device special files and use ext2 instead of tmpfs(because tmpfs
>> doesn't support extended attributes) as default filesystem if
>> .dev_fs_type is not specified.
> Can we do that only if the test temporary directory is not suitable for
> creating devices?
>
> There are distributions out there that have /tmp residing on pretty much
> normal filesystems, also user can override TMPDIR to point to a path
> backed up by a regular fs. In these cases this will slow down these
> tests for no good reason.
>
> So I would rather go for:
>
> if tst_test->needs_devfs is set:
>
> * mkdir tst_test->mntpoint if it does not exits
> * check if tst_test->mntpoint is suitable for creating devices
> * if not, mount some filesystem over it
>    - mounting tmpfs without nodev flag should be more than enough
>      and if that fails for you, we can fall back to a regular filesystem
Hi Cyril,

Thanks for your review and suggestion.

Mounting tmpfs without nodev over tst_test->mntpoint doesn't fail for 
me, so it isn't
necessary to mount a regular filesystem instead of tmpfs  over 
tst_test->mntpoint.

Thanks,
Xiao Yang
diff mbox series

Patch

diff --git a/include/tst_test.h b/include/tst_test.h
index f7d109a..4cc6202 100644
--- a/include/tst_test.h
+++ b/include/tst_test.h
@@ -129,6 +129,7 @@  struct tst_test {
 	int mount_device:1;
 	int needs_rofs:1;
 	int child_needs_reinit:1;
+	int needs_devfs:1;
 	/*
 	 * If set the test function will be executed for all available
 	 * filesystems and the current filesytem type would be set in the
diff --git a/lib/tst_test.c b/lib/tst_test.c
index 2f3d357..039c78f 100644
--- a/lib/tst_test.c
+++ b/lib/tst_test.c
@@ -724,6 +724,22 @@  static int prepare_and_mount_ro_fs(const char *dev,
 	return 0;
 }
 
+static void prepare_and_mount_dev_fs(const char *dev,
+				     const char *mntpoint,
+				     const char *fs_type)
+{
+	const char *flags[] = {"nodev", NULL};
+	char abs_path[PATH_MAX];
+
+	sprintf(abs_path, "%s/%s", tst_get_tmpdir(), mntpoint);
+
+	SAFE_MOUNT(dev, mntpoint, fs_type, MS_MGC_VAL, NULL);
+	mntpoint_mounted = 1;
+
+	if (tst_path_has_mnt_flags(NULL, abs_path, flags))
+		tst_brk(TBROK, "%s is mounted with nodev", fs_type);
+}
+
 static void prepare_device(void)
 {
 	if (tst_test->format_device) {
@@ -737,6 +753,12 @@  static void prepare_device(void)
 		return;
 	}
 
+	if (tst_test->needs_devfs) {
+		prepare_and_mount_dev_fs(tdev.dev, tst_test->mntpoint,
+					 tdev.fs_type);
+		return;
+	}
+
 	if (tst_test->mount_device) {
 		SAFE_MOUNT(tdev.dev, tst_test->mntpoint, tdev.fs_type,
 			   tst_test->mnt_flags, tst_test->mnt_data);
@@ -778,6 +800,11 @@  static void do_setup(int argc, char *argv[])
 	if (tst_test->all_filesystems)
 		tst_test->needs_device = 1;
 
+	if (tst_test->needs_devfs) {
+		tst_test->needs_device = 1;
+		tst_test->format_device = 1;
+	}
+
 	setup_ipc();
 
 	if (needs_tmpdir() && !tst_tmpdir_created())
@@ -786,8 +813,9 @@  static void do_setup(int argc, char *argv[])
 	if (tst_test->mntpoint)
 		SAFE_MKDIR(tst_test->mntpoint, 0777);
 
-	if ((tst_test->needs_rofs || tst_test->mount_device ||
-	     tst_test->all_filesystems) && !tst_test->mntpoint) {
+	if ((tst_test->needs_devfs || tst_test->needs_rofs ||
+	     tst_test->mount_device || tst_test->all_filesystems) &&
+	     !tst_test->mntpoint) {
 		tst_brk(TBROK, "tst_test->mntpoint must be set!");
 	}