[LTP] [PATCH v6] listmount04.c: Update case support mnt_id_req.mnt_ns_fd

Wei Gao wegao@suse.com
Sun Dec 14 03:15:20 CET 2025


Kernel change from v6.18-rc7 lead test case failure with following error message:
listmount04.c:128: TFAIL: invalid mnt_id_req.spare expected EINVAL: EBADF (9)

Detail of new kernel commit:
commit: 78f0e33cd6c939a555aa80dbed2fec6b333a7660
fs/namespace: correctly handle errors returned by grab_requested_mnt_ns

Signed-off-by: Wei Gao <wegao@suse.com>
---
 configure.ac                                  |  2 +-
 include/lapi/mount.h                          | 10 +++--
 .../kernel/syscalls/listmount/listmount.h     |  2 +-
 .../kernel/syscalls/listmount/listmount04.c   | 37 +++++++++++++++++--
 .../kernel/syscalls/statmount/statmount.h     |  2 +-
 5 files changed, 44 insertions(+), 9 deletions(-)

diff --git a/configure.ac b/configure.ac
index 0480f46ca..a0ebbb34d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -262,7 +262,7 @@ AC_CHECK_TYPES([struct cachestat_range],,,[#include <sys/mman.h>])
 AC_CHECK_TYPES([struct cachestat],,,[#include <sys/mman.h>])
 
 # Defined in <linux/mount.h>, but include/lapi/mount.h includes <sys/mount.h> */
-AC_CHECK_TYPES([struct mnt_id_req],,,[#include <sys/mount.h>])
+AC_CHECK_MEMBERS([struct mnt_id_req.mnt_ns_fd],,,[#include <sys/mount.h>])
 AC_CHECK_TYPES([struct statmount],,,[#include <sys/mount.h>])
 AC_CHECK_MEMBERS([struct statmount.mnt_ns_id],,,[#include <unistd.h>
 #include <linux/mount.h>])
diff --git a/include/lapi/mount.h b/include/lapi/mount.h
index 0f7bb5e43..3b296fc9c 100644
--- a/include/lapi/mount.h
+++ b/include/lapi/mount.h
@@ -45,14 +45,18 @@
 # define MS_NOSYMFOLLOW 256
 #endif
 
-#ifndef HAVE_STRUCT_MNT_ID_REQ
-struct mnt_id_req {
+struct mnt_id_req_fallback {
 	uint32_t size;
-	uint32_t spare;
+	uint32_t mnt_ns_fd;
 	uint64_t mnt_id;
 	uint64_t param;
 	uint64_t mnt_ns_id;
 };
+
+#ifndef HAVE_STRUCT_MNT_ID_REQ_MNT_NS_FD
+typedef struct mnt_id_req_fallback mnt_id_req;
+#else
+typedef struct mnt_id_req mnt_id_req;
 #endif
 
 #ifndef HAVE_STRUCT_STATMOUNT
diff --git a/testcases/kernel/syscalls/listmount/listmount.h b/testcases/kernel/syscalls/listmount/listmount.h
index aad927f71..e7ef375d7 100644
--- a/testcases/kernel/syscalls/listmount/listmount.h
+++ b/testcases/kernel/syscalls/listmount/listmount.h
@@ -15,7 +15,7 @@
 static inline ssize_t listmount(uint64_t mnt_id, uint64_t last_mnt_id,
 			 uint64_t list[], size_t num, unsigned int flags)
 {
-	struct mnt_id_req req = {
+	mnt_id_req req = {
 		.size = MNT_ID_REQ_SIZE_VER0,
 		.mnt_id = mnt_id,
 		.param = last_mnt_id,
diff --git a/testcases/kernel/syscalls/listmount/listmount04.c b/testcases/kernel/syscalls/listmount/listmount04.c
index a6921a249..c1f00d99a 100644
--- a/testcases/kernel/syscalls/listmount/listmount04.c
+++ b/testcases/kernel/syscalls/listmount/listmount04.c
@@ -14,14 +14,18 @@
 
 #define _GNU_SOURCE
 
+#include "config.h"
 #include "tst_test.h"
 #include "lapi/mount.h"
 #include "lapi/syscalls.h"
 
 #define MNT_SIZE 32
+#define BEFORE_6_18 1
+#define AFTER_6_18 2
 
-static struct mnt_id_req *request;
+static mnt_id_req *request;
 static uint64_t mnt_ids[MNT_SIZE];
+static int kver;
 
 static struct tcase {
 	int req_usage;
@@ -34,6 +38,7 @@ static struct tcase {
 	uint64_t flags;
 	int exp_errno;
 	char *msg;
+	int kver;
 } tcases[] = {
 	{
 		.req_usage = 0,
@@ -79,6 +84,18 @@ static struct tcase {
 		.nr_mnt_ids = MNT_SIZE,
 		.exp_errno = EINVAL,
 		.msg = "invalid mnt_id_req.spare",
+		.kver = BEFORE_6_18,
+	},
+	{
+		.req_usage = 1,
+		.size = MNT_ID_REQ_SIZE_VER0,
+		.spare = -1,
+		.mnt_id = LSMT_ROOT,
+		.mnt_ids = mnt_ids,
+		.nr_mnt_ids = MNT_SIZE,
+		.exp_errno = EBADF,
+		.msg = "invalid mnt_id_req.mnt_ns_fd",
+		.kver = AFTER_6_18,
 	},
 	{
 		.req_usage = 1,
@@ -113,7 +130,12 @@ static struct tcase {
 static void run(unsigned int n)
 {
 	struct tcase *tc = &tcases[n];
-	struct mnt_id_req *req = NULL;
+	mnt_id_req *req = NULL;
+
+	if (tc->kver && tc->kver != kver) {
+		tst_res(TCONF, "Skip the case that is not suitable for the current kernel version");
+		return;
+	}
 
 	memset(mnt_ids, 0, sizeof(mnt_ids));
 
@@ -122,7 +144,7 @@ static void run(unsigned int n)
 		req->mnt_id = tc->mnt_id;
 		req->param = tc->param;
 		req->size = tc->size;
-		req->spare = tc->spare;
+		req->mnt_ns_fd = tc->spare;
 	}
 
 	TST_EXP_FAIL(tst_syscall(__NR_listmount, req, tc->mnt_ids,
@@ -130,8 +152,17 @@ static void run(unsigned int n)
 		"%s", tc->msg);
 }
 
+static void setup(void)
+{
+	if (tst_kvercmp(6, 18, 0) >= 0)
+		kver = AFTER_6_18;
+	else
+		kver = BEFORE_6_18;
+}
+
 static struct tst_test test = {
 	.test = run,
+	.setup = setup,
 	.tcnt = ARRAY_SIZE(tcases),
 	.min_kver = "6.11",
 	.bufs = (struct tst_buffers []) {
diff --git a/testcases/kernel/syscalls/statmount/statmount.h b/testcases/kernel/syscalls/statmount/statmount.h
index d21d7f8da..4217a82d8 100644
--- a/testcases/kernel/syscalls/statmount/statmount.h
+++ b/testcases/kernel/syscalls/statmount/statmount.h
@@ -16,7 +16,7 @@
 static inline int statmount(uint64_t mnt_id, uint64_t mask, struct statmount *buf,
 		     size_t bufsize, unsigned int flags)
 {
-	struct mnt_id_req req = {
+	mnt_id_req req = {
 		.size = MNT_ID_REQ_SIZE_VER0,
 		.mnt_id = mnt_id,
 		.param = mask,
-- 
2.52.0



More information about the ltp mailing list