[LTP] [PATCH v5 4/7] syscalls/statx01: Relax mnt_id test condition

Yang Xu xuyang2018.jy@fujitsu.com
Tue May 9 11:14:05 CEST 2023


Before this patch, we test stx_mnt_id only when glibc's statx struct has
this member. Now, if glibc miss this filed, we will use __spare2[0], see
url[1]. If glibc miss statx struct, we will use ltp owner definition.

[1]https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=fa2fcf4f

Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
 testcases/kernel/syscalls/statx/statx01.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/testcases/kernel/syscalls/statx/statx01.c b/testcases/kernel/syscalls/statx/statx01.c
index f9c2748d2..08b26f77b 100644
--- a/testcases/kernel/syscalls/statx/statx01.c
+++ b/testcases/kernel/syscalls/statx/statx01.c
@@ -49,20 +49,25 @@
 
 static int file_fd = -1;
 
-#ifdef HAVE_STRUCT_STATX_STX_MNT_ID
 static void test_mnt_id(struct statx *buf)
 {
 	FILE *file;
 	char line[PATH_MAX];
 	int pid, flag = 0;
 	unsigned int line_mjr, line_mnr;
-	uint64_t mnt_id;
+	uint64_t mnt_id, stx_mnt_id;
 
 	if (!(buf->stx_mask & STATX_MNT_ID)) {
 		tst_res(TCONF, "stx_mnt_id is not supported until linux 5.8");
 		return;
 	}
 
+#if defined(HAVE_STRUCT_STATX) && !defined(HAVE_STRUCT_STATX_STX_MNT_ID)
+	stx_mnt_id = buf->__spare2[0];
+#else
+	stx_mnt_id = buf->stx_mnt_id;
+#endif
+
 	file = SAFE_FOPEN("/proc/self/mountinfo", "r");
 
 	while (fgets(line, sizeof(line), file)) {
@@ -70,12 +75,12 @@ static void test_mnt_id(struct statx *buf)
 			continue;
 
 		if (line_mjr == buf->stx_dev_major && line_mnr == buf->stx_dev_minor) {
-			if (buf->stx_mnt_id == mnt_id) {
+			if (stx_mnt_id == mnt_id) {
 				flag = 1;
 				break;
 			}
 			tst_res(TINFO, "%s doesn't contain %"PRIu64" %d:%d",
-				line, (uint64_t)buf->stx_mnt_id, buf->stx_dev_major, buf->stx_dev_minor);
+				line, (uint64_t)stx_mnt_id, buf->stx_dev_major, buf->stx_dev_minor);
 		}
 	}
 
@@ -88,13 +93,12 @@ static void test_mnt_id(struct statx *buf)
 	else
 		tst_res(TFAIL,
 			"statx.stx_mnt_id(%"PRIu64") doesn't exist in /proc/self/mountinfo",
-			(uint64_t)buf->stx_mnt_id);
+			(uint64_t)stx_mnt_id);
 
 	pid = getpid();
 	snprintf(line, PATH_MAX, "/proc/%d/fdinfo/%d", pid, file_fd);
-	TST_ASSERT_FILE_INT(line, "mnt_id:", buf->stx_mnt_id);
+	TST_ASSERT_FILE_INT(line, "mnt_id:", stx_mnt_id);
 }
-#endif
 
 static void test_normal_file(void)
 {
@@ -147,11 +151,7 @@ static void test_normal_file(void)
 		tst_res(TFAIL, "stx_nlink(%u) is different from expected(1)",
 			buff.stx_nlink);
 
-#ifdef HAVE_STRUCT_STATX_STX_MNT_ID
 	test_mnt_id(&buff);
-#else
-	tst_res(TCONF, "stx_mnt_id is not defined in struct statx");
-#endif
 }
 
 static void test_device_file(void)
-- 
2.39.1



More information about the ltp mailing list