[LTP] [PATCH v1] fsmount01: Add test if MOUNT_ATTR_* have expected effect on the mount

Wei Gao wegao@suse.com
Fri Aug 29 00:51:54 CEST 2025


The fsmount01 test does not test if MOUNT_ATTR_* have expected effect
on the mount, e.g. if MOUNT_ATTR_RDONLY mounts the FS read only etc.

Fixes: #1170
Signed-off-by: Wei Gao <wegao@suse.com>
---
 include/tst_device.h                          |  1 +
 lib/tst_device.c                              |  2 +-
 testcases/kernel/syscalls/fsmount/fsmount01.c | 27 +++++++++++++++++++
 3 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/include/tst_device.h b/include/tst_device.h
index e0627a24d..24b5201c5 100644
--- a/include/tst_device.h
+++ b/include/tst_device.h
@@ -35,6 +35,7 @@ int tst_umount(const char *path);
 int tst_is_mounted(const char *path);
 int tst_is_mounted_ro(const char *path);
 int tst_is_mounted_rw(const char *path);
+int tst_mount_has_opt(const char *path, const char *opt);
 int tst_is_mounted_at_tmpdir(const char *path);
 
 /*
diff --git a/lib/tst_device.c b/lib/tst_device.c
index 5b0498c03..2364df052 100644
--- a/lib/tst_device.c
+++ b/lib/tst_device.c
@@ -429,7 +429,7 @@ int tst_umount(const char *path)
 	return -1;
 }
 
-static int tst_mount_has_opt(const char *path, const char *opt)
+int tst_mount_has_opt(const char *path, const char *opt)
 {
 	char line[PATH_MAX];
 	char abspath[PATH_MAX];
diff --git a/testcases/kernel/syscalls/fsmount/fsmount01.c b/testcases/kernel/syscalls/fsmount/fsmount01.c
index 6dafe25a8..bf0f5f100 100644
--- a/testcases/kernel/syscalls/fsmount/fsmount01.c
+++ b/testcases/kernel/syscalls/fsmount/fsmount01.c
@@ -8,6 +8,7 @@
 
 #include "tst_test.h"
 #include "lapi/fsmount.h"
+#include "tst_safe_stdio.h"
 
 #define MNTPOINT	"mntpoint"
 
@@ -75,6 +76,32 @@ static void run(unsigned int n)
 	TEST(move_mount(mfd, "", AT_FDCWD, MNTPOINT, MOVE_MOUNT_F_EMPTY_PATH));
 	SAFE_CLOSE(mfd);
 
+	switch (tc->attrs) {
+	case MOUNT_ATTR_RDONLY:
+		TST_EXP_VAL(tst_is_mounted_ro(MNTPOINT), 1);
+		break;
+	case MOUNT_ATTR_NOSUID:
+		TST_EXP_VAL(tst_mount_has_opt(MNTPOINT, "nosuid"), 1);
+		break;
+	case MOUNT_ATTR_NODEV:
+		TST_EXP_VAL(tst_mount_has_opt(MNTPOINT, "nodev"), 1);
+		break;
+	case MOUNT_ATTR_NOEXEC:
+		TST_EXP_VAL(tst_mount_has_opt(MNTPOINT, "noexec"), 1);
+		break;
+	case MOUNT_ATTR_RELATIME:
+		TST_EXP_VAL(tst_mount_has_opt(MNTPOINT, "relatime"), 1);
+		break;
+	case MOUNT_ATTR_NOATIME:
+		TST_EXP_VAL(tst_mount_has_opt(MNTPOINT, "noatime"), 1);
+		break;
+	case MOUNT_ATTR_NODIRATIME:
+		TST_EXP_VAL(tst_mount_has_opt(MNTPOINT, "nodiratime"), 1);
+		break;
+	default:
+		break;
+	}
+
 	if (TST_RET == -1) {
 		tst_res(TFAIL | TTERRNO,
 			"move_mount() failed to attach to the mount point");
-- 
2.51.0



More information about the ltp mailing list