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

Wei Gao wegao@suse.com
Fri Dec 12 12:50:47 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                                     |  1 +
 include/lapi/mount.h                             | 10 +++++++---
 .../kernel/syscalls/listmount/listmount04.c      | 16 +++++++++++++---
 3 files changed, 21 insertions(+), 6 deletions(-)

v4->v5: Update base solution of Cyril

diff --git a/configure.ac b/configure.ac
index 0480f46ca..fcff90799 100644
--- a/configure.ac
+++ b/configure.ac
@@ -263,6 +263,7 @@ 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..7b1c4ca0f 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;
 };
+
+#if !defined(HAVE_STRUCT_MNT_ID_REQ) || !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/listmount04.c b/testcases/kernel/syscalls/listmount/listmount04.c
index a6921a249..955f98e20 100644
--- a/testcases/kernel/syscalls/listmount/listmount04.c
+++ b/testcases/kernel/syscalls/listmount/listmount04.c
@@ -14,13 +14,14 @@
 
 #define _GNU_SOURCE
 
+#include "config.h"
 #include "tst_test.h"
 #include "lapi/mount.h"
 #include "lapi/syscalls.h"
 
 #define MNT_SIZE 32
 
-static struct mnt_id_req *request;
+static mnt_id_req *request;
 static uint64_t mnt_ids[MNT_SIZE];
 
 static struct tcase {
@@ -113,7 +114,7 @@ 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;
 
 	memset(mnt_ids, 0, sizeof(mnt_ids));
 
@@ -122,7 +123,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 +131,17 @@ static void run(unsigned int n)
 		"%s", tc->msg);
 }
 
+static void setup(void)
+{
+	if (tst_kvercmp(6, 18, 0) >= 0) {
+		tcases[4].exp_errno = EBADF;
+		tcases[4].msg = "invalid mnt_id_req.mnt_ns_fd (EBADF)";
+	}
+}
+
 static struct tst_test test = {
 	.test = run,
+	.setup = setup,
 	.tcnt = ARRAY_SIZE(tcases),
 	.min_kver = "6.11",
 	.bufs = (struct tst_buffers []) {
-- 
2.52.0



More information about the ltp mailing list