[LTP] [PATCH 3/3] Add statmount09 test
Andrea Cervesato
andrea.cervesato@suse.de
Tue Jun 17 14:45:36 CEST 2025
From: Andrea Cervesato <andrea.cervesato@suse.com>
This test verifies that statmount() is correctly reading the mount ID for
the current namespace.
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
runtest/syscalls | 1 +
testcases/kernel/syscalls/statmount/.gitignore | 1 +
testcases/kernel/syscalls/statmount/statmount09.c | 74 +++++++++++++++++++++++
3 files changed, 76 insertions(+)
diff --git a/runtest/syscalls b/runtest/syscalls
index d5582ca8da01f11adba75a56d22cb6e5c4996c68..fe4047161754b2c04f16e5cf69d4a5e94cb02d73 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -1606,6 +1606,7 @@ statmount05 statmount05
statmount06 statmount06
statmount07 statmount07
statmount08 statmount08
+statmount09 statmount09
statfs01 statfs01
statfs01_64 statfs01_64
diff --git a/testcases/kernel/syscalls/statmount/.gitignore b/testcases/kernel/syscalls/statmount/.gitignore
index 6106fcf07378b5360130e9d61d4150210eadf703..dc1b18963ffd18cdef18ebe3e94ee83a786f4352 100644
--- a/testcases/kernel/syscalls/statmount/.gitignore
+++ b/testcases/kernel/syscalls/statmount/.gitignore
@@ -6,3 +6,4 @@ statmount05
statmount06
statmount07
statmount08
+statmount09
diff --git a/testcases/kernel/syscalls/statmount/statmount09.c b/testcases/kernel/syscalls/statmount/statmount09.c
new file mode 100644
index 0000000000000000000000000000000000000000..20c76ba24faee6c52a760bb85446c46bd68c056a
--- /dev/null
+++ b/testcases/kernel/syscalls/statmount/statmount09.c
@@ -0,0 +1,74 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2025 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * This test verifies that statmount() is correctly reading the mount ID for
+ * the current namespace.
+ *
+ * [Algorithm]
+ *
+ * - create a mount point
+ * - run statmount() on the mount point using STATMOUNT_MNT_NS_ID
+ * - read results and check if contain the correct mount ID for the current
+ * namespace
+ */
+
+#define _GNU_SOURCE
+
+#include "statmount.h"
+#include "lapi/stat.h"
+#include "lapi/ioctl_ns.h"
+
+#define MNTPOINT "mntpoint"
+#define SM_SIZE (1 << 10)
+
+static uint64_t root_id;
+static u_int64_t mnt_ns_id;
+static struct statmount *st_mount;
+
+static void run(void)
+{
+ memset(st_mount, 0, SM_SIZE);
+
+ TST_EXP_PASS(statmount(root_id, STATMOUNT_MNT_NS_ID, st_mount,
+ SM_SIZE, 0));
+
+ if (!TST_PASS)
+ return;
+
+ TST_EXP_EQ_LI(st_mount->mask, STATMOUNT_MNT_NS_ID);
+ TST_EXP_EQ_LI(st_mount->mnt_ns_id, mnt_ns_id);
+}
+
+static void setup(void)
+{
+ struct ltp_statx sx;
+ int fd;
+
+ SAFE_STATX(AT_FDCWD, MNTPOINT, 0, STATX_MNT_ID_UNIQUE, &sx);
+ root_id = sx.data.stx_mnt_id;
+
+ fd = SAFE_OPEN("/proc/self/ns/mnt", O_RDONLY);
+ SAFE_IOCTL(fd, NS_GET_MNTNS_ID, &mnt_ns_id);
+ SAFE_CLOSE(fd);
+}
+
+static struct tst_test test = {
+ .test_all = run,
+ .setup = setup,
+ .min_kver = "6.11",
+ .mount_device = 1,
+ .mntpoint = MNTPOINT,
+ .all_filesystems = 1,
+ .skip_filesystems = (const char *const []) {
+ "fuse",
+ NULL
+ },
+ .bufs = (struct tst_buffers []) {
+ {&st_mount, .size = SM_SIZE},
+ {}
+ }
+};
+
--
2.43.0
More information about the ltp
mailing list