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

Wei Gao via ltp
2025-12-11T01:59:55Z

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>
Reviewed-by: Petr Vorel <pvorel@suse.cz>
---
configure.ac | 1 +
.../kernel/syscalls/listmount/listmount04.c | 26 ++++++++++++++++++-
2 files changed, 26 insertions(+), 1 deletion(-)

v3->v4: fix grammatical errors

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/testcases/kernel/syscalls/listmount/listmount04.c b/testcases/kernel/syscalls/listmount/listmount04.c
index a6921a249..3579a4296 100644
--- a/testcases/kernel/syscalls/listmount/listmount04.c
+++ b/testcases/kernel/syscalls/listmount/listmount04.c
@@ -14,6 +14,7 @@

#define _GNU_SOURCE

+#include "config.h"
#include "tst_test.h"
#include "lapi/mount.h"
#include "lapi/syscalls.h"
@@ -26,7 +27,11 @@ static uint64_t mnt_ids[MNT_SIZE];
static struct tcase {
int req_usage;
uint32_t size;
+#ifdef HAVE_STRUCT_MNT_ID_REQ_MNT_NS_FD
+ uint32_t mnt_ns_fd;
+#else
uint32_t spare;
+#endif
uint64_t mnt_id;
uint64_t param;
uint64_t *mnt_ids;
@@ -73,12 +78,21 @@ static struct tcase {
{
.req_usage = 1,
.size = MNT_ID_REQ_SIZE_VER0,
+#ifdef HAVE_STRUCT_MNT_ID_REQ_MNT_NS_FD
+ .mnt_ns_fd = -1,
+#else
.spare = -1,
+#endif
.mnt_id = LSMT_ROOT,
.mnt_ids = mnt_ids,
.nr_mnt_ids = MNT_SIZE,
+#ifdef HAVE_STRUCT_MNT_ID_REQ_MNT_NS_FD
+ .exp_errno = EBADF,
+ .msg = "invalid mnt_id_req.mnt_ns_fd bad file descriptor",
+#else
.exp_errno = EINVAL,
.msg = "invalid mnt_id_req.spare",
+#endif
},
{
.req_usage = 1,
@@ -122,7 +136,17 @@ static void run(unsigned int n)
req->mnt_id = tc->mnt_id;
req->param = tc->param;
req->size = tc->size;
- req->spare = tc->spare;
+#ifdef HAVE_STRUCT_MNT_ID_REQ_MNT_NS_FD
+ if ((tst_kvercmp(6, 18, 0)) >= 0)
+ req->mnt_ns_fd = tc->mnt_ns_fd;
+ else
+ tst_brk(TCONF, "Skipping test, kernel version should be >= 6.18");
+#else
+ if ((tst_kvercmp(6, 18, 0)) >= 0)
+ tst_brk(TCONF, "Skipping test, kernel version should be < 6.18");
+ else
+ req->spare = tc->spare;
+#endif
}

TST_EXP_FAIL(tst_syscall(__NR_listmount, req, tc->mnt_ids,
--
2.51.0