Skip to contentSkip to conversation

statmount.h: add check for STATMOUNT_MNT_NS_ID

PATCH In review Jack Morgan 3 participants 11 messages Sep 26, 2025

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 statmount.h: add check for STATMOUNT_MNT_NS_ID

statmount.h: add check for STATMOUNT_MNT_NS_ID

Enable check for STATMOUNT_MNT_NS_ID in kernel headers. Define LTP_HAVE_STRUCT_STATMOUNT_MNT_NS_ID for mnt_ns_id and mnt_id use cases.

Fixes #1260
---
 testcases/kernel/syscalls/statmount/statmount.h | 5 +++++
 1 file changed, 5 insertions(+)
testcases/kernel/syscalls/statmount/statmount.h +5 -0
index d21d7f8da..df883f792 100644
@@ -13,6 +13,11 @@
 #include "lapi/syscalls.h"
 #include "tst_safe_stdio.h"
 
+/* Enable STATMOUNT_MNT_NS_ID check for struct statmount. */
+#if!defined(HAVE_STRUCT_STATMOUNT) || defined(HAVE_STRUCT_STATMOUNT_MNT_NS_ID)
+#define LTP_HAVE_STRUCT_STATMOUNT_MNT_NS_ID 1
+#endif
+
 static inline int statmount(uint64_t mnt_id, uint64_t mask, struct statmount *buf,
 		     size_t bufsize, unsigned int flags)
 {

--
2.51.0

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

PATCH v2 1/1 statmount09.c: Enable mnt_ns_id for STATMOUNT_MNT_NS_ID

statmount09.c: Enable mnt_ns_id for STATMOUNT_MNT_NS_ID

When LTP_HAVE_STRUCT_STATMOUNT_MNT_NS_ID is defined, use mnt_ns_id for statmount09 test case. Otherswise, use mnt_id.

Fixes #1260
---
 testcases/kernel/syscalls/statmount/statmount09.c | 4 ++++
 1 file changed, 4 insertions(+)
testcases/kernel/syscalls/statmount/statmount09.c +4 -0
index 20c76ba24..aae32cd95 100644
@@ -39,7 +39,11 @@ static void run(void)
 		return;
 
 	TST_EXP_EQ_LI(st_mount->mask, STATMOUNT_MNT_NS_ID);
+#ifdef LTP_HAVE_STRUCT_STATMOUNT_MNT_NS_ID
 	TST_EXP_EQ_LI(st_mount->mnt_ns_id, mnt_ns_id);
+#else
+	tst_res(TCONF, "statmount.mnt_ns_id not available in current headers, skipping check");
+#endif
 }
 
 static void setup(void)

--
2.51.0

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw

Re: [LTP] [PATCH v2] statmount09.c: Enable mnt_ns_id for STATMOUNT_MNT_NS_ID

Hi!

Review

Quoted 5 lines · Jack Morgan
(quoted diff) +4 -0
+#ifdef LTP_HAVE_STRUCT_STATMOUNT_MNT_NS_ID
  	TST_EXP_EQ_LI(st_mount->mnt_ns_id, mnt_ns_id);
+#else
+	tst_res(TCONF, "statmount.mnt_ns_id not available in current headers, skipping check");
+#endif

The statmount09 is testing STATMOUNT_MNT_NS_ID feature, which is carrying the mnt_ns_id as well, so we don't need to run this test if HAVE_STRUCT_STATMOUNT_MNT_NS_ID is not defined. We can do something like:

configure.ac +0 -0
index d4dd13033..189d8771e 100644
@@ -264,6 +264,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_TYPES([struct statmount],,,[#include <sys/mount.h>]) +AC_CHECK_MEMBERS([struct statmount.mnt_ns_id],,,[#include <linux/mount.h>])

 AC_CHECK_TYPES([struct pidfd_info],,,[#include <sys/pidfd.h>]) AC_CHECK_TYPES([struct file_attr],,,[#include <linux/fs.h>])

testcases/kernel/syscalls/statmount/statmount09.c +0 -0
index 20c76ba24..b78cec6b4 100644
@@ -15,6 +15,11 @@

  *   namespace
  */

+#include "config.h"
+#include "tst_test.h"
+
+#ifdef HAVE_STRUCT_STATMOUNT_MNT_NS_ID
+
 #define _GNU_SOURCE

 #include "statmount.h"
@@ -72,3 +77,8 @@ static struct tst_test test = {
        }
 };

+#else
+
+TST_TEST_TCONF("STATMOUNT_MNT_NS_ID support is required"); +
+#endif

This could be done by checking if STATMOUNT_MNT_NS_ID exists, but since mnt_ns_id attribute and STATMOUNT_MNT_NS_ID are defined in the same commit (09b31295f833031c88419550172703d45c5401e3 - fs: export the mount ns id via statmount), we can safely use configure.ac.

- Andrea

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw

Re: [LTP] [PATCH v2] statmount09.c: Enable mnt_ns_id for STATMOUNT_MNT_NS_ID

Hi Cyril

Quoted 53 lines · Andrea Cervesato

Hi!

Quoted 6 lines · Jack Morgan

+#ifdef LTP_HAVE_STRUCT_STATMOUNT_MNT_NS_ID TST_EXP_EQ_LI(st_mount->mnt_ns_id, mnt_ns_id); +#else
+    tst_res(TCONF, "statmount.mnt_ns_id not available in current headers, skipping check");
+#endif

The statmount09 is testing STATMOUNT_MNT_NS_ID feature, which is carrying the mnt_ns_id as well, so we don't need to run this test if HAVE_STRUCT_STATMOUNT_MNT_NS_ID is not defined. We can do something like:

configure.ac +1 -0
index d4dd13033..189d8771e 100644
@@ -264,6 +264,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_TYPES([struct statmount],,,[#include <sys/mount.h>])
+AC_CHECK_MEMBERS([struct statmount.mnt_ns_id],,,[#include 
 <linux/mount.h>])
 

 AC_CHECK_TYPES([struct pidfd_info],,,[#include <sys/pidfd.h>]) AC_CHECK_TYPES([struct file_attr],,,[#include <linux/fs.h>])

testcases/kernel/syscalls/statmount/statmount09.c +10 -0
index 20c76ba24..b78cec6b4 100644
@@ -15,6 +15,11 @@
   *   namespace
   */
 
+#include "config.h"
+#include "tst_test.h"
+
+#ifdef HAVE_STRUCT_STATMOUNT_MNT_NS_ID
+
  #define _GNU_SOURCE
 
  #include "statmount.h"
@@ -72,3 +77,8 @@ static struct tst_test test = {
         }
  };
 
+#else
+
+TST_TEST_TCONF("STATMOUNT_MNT_NS_ID support is required");
+
+#endif
Quoted 4 lines

This could be done by checking if STATMOUNT_MNT_NS_ID exists, but since mnt_ns_id attribute and STATMOUNT_MNT_NS_ID are defined in the same commit (09b31295f833031c88419550172703d45c5401e3 - fs: export the mount ns id via statmount), we can safely use configure.ac.

- Andrea

FYI this patch might be needed for the release, since it's breaking the build on old kernels before 09b31295f833031c88419550172703d45c5401e3 commit. What do you think?

---
Andrea Cervesato

[email protected]

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#4 lore raw

Re: [LTP] [PATCH v2] statmount09.c: Enable mnt_ns_id for STATMOUNT_MNT_NS_ID

Hi!

Quoted 3 lines

FYI this patch might be needed for the release, since it's breaking the build on old kernels before 09b31295f833031c88419550172703d45c5401e3 commit. What do you think?

Yes, this is one of the fixes that should go in.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#5 lore raw

Re: [LTP] [PATCH v2] statmount09.c: Enable mnt_ns_id for STATMOUNT_MNT_NS_ID

In reply to Andrea Cervesato via ltp

Review

Quoted 2 lines · Andrea Cervesato
(quoted diff) +2 -0
+#ifdef HAVE_STRUCT_STATMOUNT_MNT_NS_ID
+

According to the follow-up discussion, this is more correct:

#if!defined(HAVE_STRUCT_STATMOUNT) || defined(HAVE_STRUCT_STATMOUNT_MNT_NS_ID)

Signature · 7 lines
Andrea Cervesato

[email protected]


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#6 lore raw

Re: [LTP] [PATCH v2] statmount09.c: Enable mnt_ns_id for STATMOUNT_MNT_NS_ID

Quoted 7 lines · Andrea Cervesato

Review

Quoted 2 lines · Andrea Cervesato
(quoted diff) +2 -0
+#ifdef HAVE_STRUCT_STATMOUNT_MNT_NS_ID
+

According to the follow-up discussion, this is more correct:

#if!defined(HAVE_STRUCT_STATMOUNT) ||
defined(HAVE_STRUCT_STATMOUNT_MNT_NS_ID)

Thank you for the feedback. I'll update my patch with this change and send v3 shortly.

For the change to configure.ac, I've sent a separate patch for this[1].

Finally, the suggestion is to then drop patch for statmount.h as checks will be in statmount09.c test case, correct?

Is there anything else I'm missing?

[1]
https://lore.kernel.org/ltp/[email protected]/T/#u

Regards,
Jack Morgan

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#7 lore raw
In reply to Jack Morgan

Hi!

testcases/kernel/syscalls/statmount/statmount.h line 19

Quoted 4 lines · Jack Morgan
testcases/kernel/syscalls/statmount/statmount.h +4 -0
+/* Enable STATMOUNT_MNT_NS_ID check for struct statmount. */
+#if!defined(HAVE_STRUCT_STATMOUNT) || defined(HAVE_STRUCT_STATMOUNT_MNT_NS_ID)
+#define LTP_HAVE_STRUCT_STATMOUNT_MNT_NS_ID 1
+#endif

This is not a good practice, better to avoid defining LTP_* wrappers, since we already have the HAVE_* variables defined by autoconf.

- Andrea

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#8 lore raw

Hi!

Quoted 7 lines

testcases/kernel/syscalls/statmount/statmount.h line 19

Quoted 4 lines
testcases/kernel/syscalls/statmount/statmount.h +4 -0
+/* Enable STATMOUNT_MNT_NS_ID check for struct statmount. */
+#if!defined(HAVE_STRUCT_STATMOUNT) || defined(HAVE_STRUCT_STATMOUNT_MNT_NS_ID)
+#define LTP_HAVE_STRUCT_STATMOUNT_MNT_NS_ID 1
+#endif

This is not a good practice, better to avoid defining LTP_* wrappers, since we already have the HAVE_* variables defined by autoconf.

This has to be unfortunately there because the field is present if we are using lapi fallback or if we have new enough system headers. So either we open code the ifdefs in the test, or define the macro like this.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#9 lore raw
Quoted 4 lines · Cyril Hrubis

This has to be unfortunately there because the field is present if we are using lapi fallback or if we have new enough system headers. So either we open code the ifdefs in the test, or define the macro like this.

Why not just using  "#if!defined(HAVE_STRUCT_STATMOUNT) || defined(HAVE_STRUCT_STATMOUNT_MNT_NS_ID)" inside the statmount09 test then? These LTP_HAVE_* wrappers are a bit weird because they are mixing with internal LTP macros, also considering the fact we are not testing "struct statmount.mnt_ns_id" anywhere else but in statmount09.

Signature · 6 lines
Andrea Cervesato
[email protected]


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#10 lore raw

Hi!

Quoted 5 lines

Why not just using  "#if!defined(HAVE_STRUCT_STATMOUNT) || defined(HAVE_STRUCT_STATMOUNT_MNT_NS_ID)" inside the statmount09 test then? These LTP_HAVE_* wrappers are a bit weird because they are mixing with internal LTP macros, also considering the fact we are not testing "struct statmount.mnt_ns_id" anywhere else but in statmount09.

Works for me as well, I do not have a strong opinion here.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp