public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH v4 00/13] statmount/listmount testing suites
@ 2024-09-09 10:00 Andrea Cervesato
  2024-09-09 10:00 ` [LTP] [PATCH v4 01/13] Add SAFE_STATX macro Andrea Cervesato
                   ` (13 more replies)
  0 siblings, 14 replies; 35+ messages in thread
From: Andrea Cervesato @ 2024-09-09 10:00 UTC (permalink / raw)
  To: ltp

This patch-set is adding new testing suites for statmount() and listmount()
syscalls, which have been recently added in kernel v6.8.
To find out more information, please read the following documentation since
there's no man pages yet:

https://lwn.net/Articles/950569/
https://lore.kernel.org/lkml/170474400576.2602.7882507604401153304.pr-tracker-bot@kernel.org/T/

Along with kernel source code:

https://github.com/torvalds/linux/blob/1b294a1f35616977caddaddf3e9d28e576a1adbc/include/uapi/linux/mount.h#L155
https://github.com/torvalds/linux/blob/1b294a1f35616977caddaddf3e9d28e576a1adbc/tools/testing/selftests/filesystems/statmount/statmount_test.c

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
Changes in v4:
- listmount01: remove all filesystems run
- listmount02: better descriptions and proper unmount()
- statmount01: check all fields are zeroed
- statmount02: check also readonly flag
- statmount03: now it checks for all mount flags
- statmount04: moved read_peer_group inside statmount.h
- statmount07: add test for invalid values
- generic style fixes 
- fix statx import
- Link to v3: https://lore.kernel.org/r/20240516-listmount_statmount-v3-0-2ff4ba29bba7@suse.com

---
Andrea Cervesato (13):
      Add SAFE_STATX macro
      Add listmount/statmount syscalls
      Add listmount/statmount fallback declarations
      Add listmount01 test
      Add listmount02 test
      Add statmount01 test
      Add statmount02 test
      Add statmount03 test
      Add statmount04 test
      Add statmount05 test
      Add TST_EXP_EQ_STR macro
      Add statmount06 test
      Add statmount07 test

 compile_flags.txt                                  |   1 +
 configure.ac                                       |   4 +
 include/lapi/mount.h                               |  70 +++++++++++
 include/lapi/stat.h                                | 111 ++++++++++++-----
 include/lapi/syscalls/aarch64.in                   |   2 +
 include/lapi/syscalls/arc.in                       |   2 +
 include/lapi/syscalls/arm.in                       |   2 +
 include/lapi/syscalls/hppa.in                      |   2 +
 include/lapi/syscalls/i386.in                      |   2 +
 include/lapi/syscalls/ia64.in                      |   2 +
 include/lapi/syscalls/loongarch.in                 |   2 +
 include/lapi/syscalls/mips_n32.in                  |   2 +
 include/lapi/syscalls/mips_n64.in                  |   2 +
 include/lapi/syscalls/mips_o32.in                  |   2 +
 include/lapi/syscalls/powerpc.in                   |   2 +
 include/lapi/syscalls/powerpc64.in                 |   2 +
 include/lapi/syscalls/s390.in                      |   2 +
 include/lapi/syscalls/s390x.in                     |   2 +
 include/lapi/syscalls/sh.in                        |   2 +
 include/lapi/syscalls/sparc.in                     |   2 +
 include/lapi/syscalls/sparc64.in                   |   2 +
 include/lapi/syscalls/x86_64.in                    |   2 +
 include/tst_test_macros.h                          |  14 +++
 runtest/syscalls                                   |  11 ++
 testcases/kernel/syscalls/fchmodat2/fchmodat2_01.c |   2 +
 testcases/kernel/syscalls/listmount/.gitignore     |   2 +
 testcases/kernel/syscalls/listmount/Makefile       |   7 ++
 testcases/kernel/syscalls/listmount/listmount.h    |  26 ++++
 testcases/kernel/syscalls/listmount/listmount01.c  |  63 ++++++++++
 testcases/kernel/syscalls/listmount/listmount02.c  | 105 ++++++++++++++++
 testcases/kernel/syscalls/statmount/.gitignore     |   7 ++
 testcases/kernel/syscalls/statmount/Makefile       |   7 ++
 testcases/kernel/syscalls/statmount/statmount.h    |  50 ++++++++
 testcases/kernel/syscalls/statmount/statmount01.c  |  82 ++++++++++++
 testcases/kernel/syscalls/statmount/statmount02.c  |  84 +++++++++++++
 testcases/kernel/syscalls/statmount/statmount03.c  | 137 +++++++++++++++++++++
 testcases/kernel/syscalls/statmount/statmount04.c  | 105 ++++++++++++++++
 testcases/kernel/syscalls/statmount/statmount05.c  | 128 +++++++++++++++++++
 testcases/kernel/syscalls/statmount/statmount06.c  |  68 ++++++++++
 testcases/kernel/syscalls/statmount/statmount07.c  |  75 +++++++++++
 40 files changed, 1163 insertions(+), 32 deletions(-)
---
base-commit: 6df425bb7040e1c849cb84a83f5e8808967efc0e
change-id: 20240516-listmount_statmount-080965e2f80e

Best regards,
-- 
Andrea Cervesato <andrea.cervesato@suse.com>


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

^ permalink raw reply	[flat|nested] 35+ messages in thread

* [LTP] [PATCH v4 01/13] Add SAFE_STATX macro
  2024-09-09 10:00 [LTP] [PATCH v4 00/13] statmount/listmount testing suites Andrea Cervesato
@ 2024-09-09 10:00 ` Andrea Cervesato
  2024-09-09 16:21   ` Andrea Cervesato via ltp
  2024-10-02 12:27   ` Cyril Hrubis
  2024-09-09 10:00 ` [LTP] [PATCH v4 02/13] Add listmount/statmount syscalls Andrea Cervesato
                   ` (12 subsequent siblings)
  13 siblings, 2 replies; 35+ messages in thread
From: Andrea Cervesato @ 2024-09-09 10:00 UTC (permalink / raw)
  To: ltp

From: Andrea Cervesato <andrea.cervesato@suse.com>

Reviewed-by: Avinesh Kumar <akumar@suse.de>
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 compile_flags.txt                                  |   1 +
 include/lapi/stat.h                                | 111 +++++++++++++++------
 testcases/kernel/syscalls/fchmodat2/fchmodat2_01.c |   2 +
 3 files changed, 82 insertions(+), 32 deletions(-)

diff --git a/compile_flags.txt b/compile_flags.txt
new file mode 100644
index 000000000..3e2e7607a
--- /dev/null
+++ b/compile_flags.txt
@@ -0,0 +1 @@
+-Iinclude/
diff --git a/include/lapi/stat.h b/include/lapi/stat.h
index 030646a9e..1fa5f4eaf 100644
--- a/include/lapi/stat.h
+++ b/include/lapi/stat.h
@@ -30,6 +30,7 @@ struct statx_timestamp {
 	int32_t __reserved;
 };
 #endif
+
 /*
  * Structures for the extended file attribute retrieval system call
  * (statx()).
@@ -67,39 +68,57 @@ struct statx_timestamp {
  * will have values installed for compatibility purposes so that stat() and
  * co. can be emulated in userspace.
  */
-#ifndef HAVE_STRUCT_STATX
-struct statx {
-	/* 0x00 */
-	uint32_t	stx_mask;
-	uint32_t	stx_blksize;
-	uint64_t	stx_attributes;
-	/* 0x10 */
-	uint32_t	stx_nlink;
-	uint32_t	stx_uid;
-	uint32_t	stx_gid;
-	uint16_t	stx_mode;
-	uint16_t	__spare0[1];
-	/* 0x20 */
-	uint64_t	stx_ino;
-	uint64_t	stx_size;
-	uint64_t	stx_blocks;
-	uint64_t	stx_attributes_mask;
-	/* 0x40 */
-	const struct statx_timestamp	stx_atime;
-	const struct statx_timestamp	stx_btime;
-	const struct statx_timestamp	stx_ctime;
-	const struct statx_timestamp	stx_mtime;
-	/* 0x80 */
-	uint32_t	stx_rdev_major;
-	uint32_t	stx_rdev_minor;
-	uint32_t	stx_dev_major;
-	uint32_t	stx_dev_minor;
-	/* 0x90 */
-	uint64_t	__spare2[14];
-	/* 0x100 */
+ #define LTP_DEFINE_STATX_STRUCT(x) \
+ 	struct x { \
+	uint32_t	stx_mask; \
+	uint32_t	stx_blksize; \
+	uint64_t	stx_attributes; \
+	uint32_t	stx_nlink; \
+	uint32_t	stx_uid; \
+	uint32_t	stx_gid; \
+	uint16_t	stx_mode; \
+	uint16_t	__spare0[1]; \
+	uint64_t	stx_ino; \
+	uint64_t	stx_size; \
+	uint64_t	stx_blocks; \
+	uint64_t	stx_attributes_mask; \
+	const struct statx_timestamp	stx_atime; \
+	const struct statx_timestamp	stx_btime; \
+	const struct statx_timestamp	stx_ctime; \
+	const struct statx_timestamp	stx_mtime; \
+	uint32_t	stx_rdev_major; \
+	uint32_t	stx_rdev_minor; \
+	uint32_t	stx_dev_major; \
+	uint32_t	stx_dev_minor; \
+	uint64_t	stx_mnt_id; \
+	uint32_t	stx_dio_mem_align; \
+	uint32_t	stx_dio_offset_align; \
+	uint64_t	__spare3[12]; \
 };
+
+LTP_DEFINE_STATX_STRUCT(statx_fallback);
+
+#ifdef HAVE_STRUCT_STATX
+typedef struct statx ltp_statx_;
+#else
+LTP_DEFINE_STATX_STRUCT(statx);
+
+typedef struct statx_fallback ltp_statx_;
 #endif
 
+/*
+ * This is the fallback statx that we pass to the safe_statx() syscall.
+ * The reason why we need it, is that statx struct is constantly changing
+ * inside the kernel and we need to extend its definition when structure
+ * changes in order to compile the tests.
+ */
+struct ltp_statx {
+	union {
+		ltp_statx_ buff;
+		struct statx_fallback data;
+	};
+};
+
 #ifndef HAVE_STATX
 
 /*
@@ -108,9 +127,9 @@ struct statx {
  * Returns: It returns status of statx syscall
  */
 static inline int statx(int dirfd, const char *pathname, unsigned int flags,
-			unsigned int mask, struct statx *statxbuf)
+			unsigned int mask, struct statx *st)
 {
-	return tst_syscall(__NR_statx, dirfd, pathname, flags, mask, statxbuf);
+	return tst_syscall(__NR_statx, dirfd, pathname, flags, mask, st);
 }
 #endif
 
@@ -229,6 +248,10 @@ static inline int statx(int dirfd, const char *pathname, unsigned int flags,
 # define STATX_ATTR_VERITY	0x00100000
 #endif
 
+#ifndef STATX_MNT_ID_UNIQUE
+# define STATX_MNT_ID_UNIQUE  0x00004000U
+#endif
+
 #define SAFE_FCHMODAT2(dfd, filename, mode, flags) \
 	safe_fchmodat2(__FILE__, __LINE__, (dfd), (filename), (mode), (flags))
 
@@ -251,4 +274,28 @@ static inline int safe_fchmodat2(const char *file, const int lineno,
 	return ret;
 }
 
+#define SAFE_STATX(dirfd, pathname, flags, mask, buf) \
+	safe_statx(__FILE__, __LINE__, (dirfd), (pathname), (flags), (mask), (buf))
+
+static inline int safe_statx(const char *file, const int lineno,
+	int dirfd, const char *pathname, int flags, unsigned int mask,
+	struct ltp_statx *buf)
+{
+	int rval;
+
+	rval = statx(dirfd, pathname, flags, mask, &buf->buff);
+
+	if (rval == -1) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"statx(%d,%s,%d,%u,%p) failed", dirfd, pathname, flags, mask, buf);
+	} else if (rval) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"Invalid statx(%d,%s,%d,%u,%p) return value %d",
+			dirfd, pathname, flags, mask, buf,
+			rval);
+	}
+
+	return rval;
+}
+
 #endif /* LAPI_STAT_H__ */
diff --git a/testcases/kernel/syscalls/fchmodat2/fchmodat2_01.c b/testcases/kernel/syscalls/fchmodat2/fchmodat2_01.c
index a9932287c..f026b18df 100644
--- a/testcases/kernel/syscalls/fchmodat2/fchmodat2_01.c
+++ b/testcases/kernel/syscalls/fchmodat2/fchmodat2_01.c
@@ -12,6 +12,8 @@
  * usage on symlinks will raise EOPNOTSUPP.
  */
 
+#define _GNU_SOURCE
+
 #include "tst_test.h"
 #include "tst_safe_file_at.h"
 #include "lapi/fcntl.h"

-- 
2.43.0


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

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [LTP] [PATCH v4 02/13] Add listmount/statmount syscalls
  2024-09-09 10:00 [LTP] [PATCH v4 00/13] statmount/listmount testing suites Andrea Cervesato
  2024-09-09 10:00 ` [LTP] [PATCH v4 01/13] Add SAFE_STATX macro Andrea Cervesato
@ 2024-09-09 10:00 ` Andrea Cervesato
  2024-10-02 12:30   ` Cyril Hrubis
  2024-09-09 10:00 ` [LTP] [PATCH v4 03/13] Add listmount/statmount fallback declarations Andrea Cervesato
                   ` (11 subsequent siblings)
  13 siblings, 1 reply; 35+ messages in thread
From: Andrea Cervesato @ 2024-09-09 10:00 UTC (permalink / raw)
  To: ltp

From: Andrea Cervesato <andrea.cervesato@suse.com>

Reviewed-by: Avinesh Kumar <akumar@suse.de>
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 include/lapi/syscalls/aarch64.in   | 2 ++
 include/lapi/syscalls/arc.in       | 2 ++
 include/lapi/syscalls/arm.in       | 2 ++
 include/lapi/syscalls/hppa.in      | 2 ++
 include/lapi/syscalls/i386.in      | 2 ++
 include/lapi/syscalls/ia64.in      | 2 ++
 include/lapi/syscalls/loongarch.in | 2 ++
 include/lapi/syscalls/mips_n32.in  | 2 ++
 include/lapi/syscalls/mips_n64.in  | 2 ++
 include/lapi/syscalls/mips_o32.in  | 2 ++
 include/lapi/syscalls/powerpc.in   | 2 ++
 include/lapi/syscalls/powerpc64.in | 2 ++
 include/lapi/syscalls/s390.in      | 2 ++
 include/lapi/syscalls/s390x.in     | 2 ++
 include/lapi/syscalls/sh.in        | 2 ++
 include/lapi/syscalls/sparc.in     | 2 ++
 include/lapi/syscalls/sparc64.in   | 2 ++
 include/lapi/syscalls/x86_64.in    | 2 ++
 18 files changed, 36 insertions(+)

diff --git a/include/lapi/syscalls/aarch64.in b/include/lapi/syscalls/aarch64.in
index 61d4450bf..c184f5710 100644
--- a/include/lapi/syscalls/aarch64.in
+++ b/include/lapi/syscalls/aarch64.in
@@ -303,4 +303,6 @@ futex_waitv 449
 cachestat 451
 fchmodat2 452
 mseal 462
+statmount 457
+listmount 458
 _sysctl 1078
diff --git a/include/lapi/syscalls/arc.in b/include/lapi/syscalls/arc.in
index 752cc54fd..ff58f1be2 100644
--- a/include/lapi/syscalls/arc.in
+++ b/include/lapi/syscalls/arc.in
@@ -323,3 +323,5 @@ futex_waitv 449
 cachestat 451
 fchmodat2 452
 mseal 462
+statmount 457
+listmount 458
diff --git a/include/lapi/syscalls/arm.in b/include/lapi/syscalls/arm.in
index 84203ca4d..ff1415f52 100644
--- a/include/lapi/syscalls/arm.in
+++ b/include/lapi/syscalls/arm.in
@@ -402,3 +402,5 @@ futex_waitv (__NR_SYSCALL_BASE+449)
 cachestat (__NR_SYSCALL_BASE+451)
 fchmodat2 (__NR_SYSCALL_BASE+452)
 mseal (__NR_SYSCALL_BASE+462)
+statmount (__NR_SYSCALL_BASE+457)
+listmount (__NR_SYSCALL_BASE+458)
diff --git a/include/lapi/syscalls/hppa.in b/include/lapi/syscalls/hppa.in
index 8240c69ce..ac6cd691d 100644
--- a/include/lapi/syscalls/hppa.in
+++ b/include/lapi/syscalls/hppa.in
@@ -50,3 +50,5 @@ futex_waitv 449
 cachestat 451
 fchmodat2 452
 mseal 462
+statmount 457
+listmount 458
diff --git a/include/lapi/syscalls/i386.in b/include/lapi/syscalls/i386.in
index f6e8c7258..d2f8c295d 100644
--- a/include/lapi/syscalls/i386.in
+++ b/include/lapi/syscalls/i386.in
@@ -437,3 +437,5 @@ futex_waitv 449
 cachestat 451
 fchmodat2 452
 mseal 462
+statmount 457
+listmount 458
diff --git a/include/lapi/syscalls/ia64.in b/include/lapi/syscalls/ia64.in
index 8f55029a9..cd770bace 100644
--- a/include/lapi/syscalls/ia64.in
+++ b/include/lapi/syscalls/ia64.in
@@ -350,3 +350,5 @@ futex_waitv 1473
 cachestat 1475
 fchmodat2 1476
 mseal 1486
+statmount 1481
+listmount 1482
diff --git a/include/lapi/syscalls/loongarch.in b/include/lapi/syscalls/loongarch.in
index 3df354fce..7e40e01bf 100644
--- a/include/lapi/syscalls/loongarch.in
+++ b/include/lapi/syscalls/loongarch.in
@@ -308,3 +308,5 @@ set_mempolicy_home_node 450
 cachestat 451
 fchmodat2 452
 mseal 462
+statmount 457
+listmount 458
diff --git a/include/lapi/syscalls/mips_n32.in b/include/lapi/syscalls/mips_n32.in
index d85c567c7..1c64e9ab4 100644
--- a/include/lapi/syscalls/mips_n32.in
+++ b/include/lapi/syscalls/mips_n32.in
@@ -377,3 +377,5 @@ futex_waitv 6449
 cachestat 6451
 fchmodat2 6452
 mseal 6462
+statmount 6457
+listmount 6458
diff --git a/include/lapi/syscalls/mips_n64.in b/include/lapi/syscalls/mips_n64.in
index c34a85bbe..e3895b1ea 100644
--- a/include/lapi/syscalls/mips_n64.in
+++ b/include/lapi/syscalls/mips_n64.in
@@ -353,3 +353,5 @@ futex_waitv 5449
 cachestat 5451
 fchmodat2 5452
 mseal 5462
+statmount 5457
+listmount 5458
diff --git a/include/lapi/syscalls/mips_o32.in b/include/lapi/syscalls/mips_o32.in
index 10d77787b..043747da7 100644
--- a/include/lapi/syscalls/mips_o32.in
+++ b/include/lapi/syscalls/mips_o32.in
@@ -423,3 +423,5 @@ futex_waitv 4449
 cachestat 4451
 fchmodat2 4452
 mseal 4462
+statmount 4457
+listmount 4458
diff --git a/include/lapi/syscalls/powerpc.in b/include/lapi/syscalls/powerpc.in
index af3ae5c90..a3b8fdabf 100644
--- a/include/lapi/syscalls/powerpc.in
+++ b/include/lapi/syscalls/powerpc.in
@@ -430,3 +430,5 @@ futex_waitv 449
 cachestat 451
 fchmodat2 452
 mseal 462
+statmount 457
+listmount 458
diff --git a/include/lapi/syscalls/powerpc64.in b/include/lapi/syscalls/powerpc64.in
index af3ae5c90..a3b8fdabf 100644
--- a/include/lapi/syscalls/powerpc64.in
+++ b/include/lapi/syscalls/powerpc64.in
@@ -430,3 +430,5 @@ futex_waitv 449
 cachestat 451
 fchmodat2 452
 mseal 462
+statmount 457
+listmount 458
diff --git a/include/lapi/syscalls/s390.in b/include/lapi/syscalls/s390.in
index e8e7fff0b..bf55073d6 100644
--- a/include/lapi/syscalls/s390.in
+++ b/include/lapi/syscalls/s390.in
@@ -417,3 +417,5 @@ futex_waitv 449
 cachestat 451
 fchmodat2 452
 mseal 462
+statmount 457
+listmount 458
diff --git a/include/lapi/syscalls/s390x.in b/include/lapi/syscalls/s390x.in
index 0ee3bd897..d11e22bd3 100644
--- a/include/lapi/syscalls/s390x.in
+++ b/include/lapi/syscalls/s390x.in
@@ -365,3 +365,5 @@ futex_waitv 449
 cachestat 451
 fchmodat2 452
 mseal 462
+statmount 457
+listmount 458
diff --git a/include/lapi/syscalls/sh.in b/include/lapi/syscalls/sh.in
index 5701f2285..67cf85d50 100644
--- a/include/lapi/syscalls/sh.in
+++ b/include/lapi/syscalls/sh.in
@@ -411,3 +411,5 @@ futex_waitv 449
 cachestat 451
 fchmodat2 452
 mseal 462
+statmount 457
+listmount 458
diff --git a/include/lapi/syscalls/sparc.in b/include/lapi/syscalls/sparc.in
index 172969f60..56e275f74 100644
--- a/include/lapi/syscalls/sparc.in
+++ b/include/lapi/syscalls/sparc.in
@@ -416,3 +416,5 @@ futex_waitv 449
 cachestat 451
 fchmodat2 452
 mseal 462
+statmount 457
+listmount 458
diff --git a/include/lapi/syscalls/sparc64.in b/include/lapi/syscalls/sparc64.in
index 5b667f10f..cfe221919 100644
--- a/include/lapi/syscalls/sparc64.in
+++ b/include/lapi/syscalls/sparc64.in
@@ -381,3 +381,5 @@ futex_waitv 449
 cachestat 451
 fchmodat2 452
 mseal 462
+statmount 457
+listmount 458
diff --git a/include/lapi/syscalls/x86_64.in b/include/lapi/syscalls/x86_64.in
index 1993f343a..8919487c8 100644
--- a/include/lapi/syscalls/x86_64.in
+++ b/include/lapi/syscalls/x86_64.in
@@ -358,6 +358,8 @@ futex_waitv 449
 cachestat 451
 fchmodat2 452
 mseal 462
+statmount 457
+listmount 458
 rt_sigaction 512
 rt_sigreturn 513
 ioctl 514

-- 
2.43.0


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

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [LTP] [PATCH v4 03/13] Add listmount/statmount fallback declarations
  2024-09-09 10:00 [LTP] [PATCH v4 00/13] statmount/listmount testing suites Andrea Cervesato
  2024-09-09 10:00 ` [LTP] [PATCH v4 01/13] Add SAFE_STATX macro Andrea Cervesato
  2024-09-09 10:00 ` [LTP] [PATCH v4 02/13] Add listmount/statmount syscalls Andrea Cervesato
@ 2024-09-09 10:00 ` Andrea Cervesato
  2024-10-02 14:12   ` Cyril Hrubis
  2024-09-09 10:00 ` [LTP] [PATCH v4 04/13] Add listmount01 test Andrea Cervesato
                   ` (10 subsequent siblings)
  13 siblings, 1 reply; 35+ messages in thread
From: Andrea Cervesato @ 2024-09-09 10:00 UTC (permalink / raw)
  To: ltp

From: Andrea Cervesato <andrea.cervesato@suse.com>

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 configure.ac         |  4 +++
 include/lapi/mount.h | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 74 insertions(+)

diff --git a/configure.ac b/configure.ac
index ebbf49e28..3dca7c646 100644
--- a/configure.ac
+++ b/configure.ac
@@ -114,6 +114,7 @@ AC_CHECK_FUNCS_ONCE([ \
     io_uring_register \
     io_uring_enter \
     kcmp \
+    listmount \
     mallinfo \
     mallinfo2 \
     mallopt \
@@ -143,6 +144,7 @@ AC_CHECK_FUNCS_ONCE([ \
     setns \
     sigpending \
     splice \
+    statmount \
     statx \
     stime \
     sync_file_range \
@@ -246,6 +248,8 @@ AC_CHECK_TYPES([struct mount_attr],,,[
 
 AC_CHECK_TYPES([struct cachestat_range],,,[#include <sys/mman.h>])
 AC_CHECK_TYPES([struct cachestat],,,[#include <sys/mman.h>])
+AC_CHECK_TYPES([struct mnt_id_req],,,[#include <linux/mount.h>])
+AC_CHECK_TYPES([struct statmount],,,[#include <linux/mount.h>])
 
 # Tools knobs
 
diff --git a/include/lapi/mount.h b/include/lapi/mount.h
index c1af944fe..01a0fd2d6 100644
--- a/include/lapi/mount.h
+++ b/include/lapi/mount.h
@@ -2,12 +2,15 @@
 /*
  * Copyright (c) Linux Test Project, 2015-2022
  * Copyright (c) 2015 Cui Bixuan <cuibixuan@huawei.com>
+ * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
  */
 
 #ifndef LAPI_MOUNT_H__
 #define LAPI_MOUNT_H__
 
+#include <stdint.h>
 #include <sys/mount.h>
+#include "config.h"
 
 #ifndef MS_REC
 # define MS_REC 16384
@@ -37,4 +40,71 @@
 # define MS_NOSYMFOLLOW 256
 #endif
 
+#ifndef HAVE_STRUCT_MNT_ID_REQ
+struct mnt_id_req {
+	uint32_t size;
+	uint32_t spare;
+	uint64_t mnt_id;
+	uint64_t param;
+};
+#endif
+
+#ifndef HAVE_STRUCT_STATMOUNT
+struct statmount {
+	uint32_t size;
+	uint32_t __spare1;
+	uint64_t mask;
+	uint32_t sb_dev_major;
+	uint32_t sb_dev_minor;
+	uint64_t sb_magic;
+	uint32_t sb_flags;
+	uint32_t fs_type;
+	uint64_t mnt_id;
+	uint64_t mnt_parent_id;
+	uint32_t mnt_id_old;
+	uint32_t mnt_parent_id_old;
+	uint64_t mnt_attr;
+	uint64_t mnt_propagation;
+	uint64_t mnt_peer_group;
+	uint64_t mnt_master;
+	uint64_t propagate_from;
+	uint32_t mnt_root;
+	uint32_t mnt_point;
+	uint64_t __spare2[50];
+	char str[];
+};
+#endif
+
+#ifndef MNT_ID_REQ_SIZE_VER0
+# define MNT_ID_REQ_SIZE_VER0 24
+#endif
+
+#ifndef STATMOUNT_SB_BASIC
+# define STATMOUNT_SB_BASIC 0x00000001U
+#endif
+
+#ifndef STATMOUNT_MNT_BASIC
+# define STATMOUNT_MNT_BASIC 0x00000002U
+#endif
+
+#ifndef STATMOUNT_PROPAGATE_FROM
+# define STATMOUNT_PROPAGATE_FROM 0x00000004U
+#endif
+
+#ifndef STATMOUNT_MNT_ROOT
+# define STATMOUNT_MNT_ROOT 0x00000008U
+#endif
+
+#ifndef STATMOUNT_MNT_POINT
+# define STATMOUNT_MNT_POINT 0x00000010U
+#endif
+
+#ifndef STATMOUNT_FS_TYPE
+# define STATMOUNT_FS_TYPE 0x00000020U
+#endif
+
+#ifndef LSMT_ROOT
+# define LSMT_ROOT 0xffffffffffffffff
+#endif
+
 #endif /* LAPI_MOUNT_H__ */

-- 
2.43.0


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

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [LTP] [PATCH v4 04/13] Add listmount01 test
  2024-09-09 10:00 [LTP] [PATCH v4 00/13] statmount/listmount testing suites Andrea Cervesato
                   ` (2 preceding siblings ...)
  2024-09-09 10:00 ` [LTP] [PATCH v4 03/13] Add listmount/statmount fallback declarations Andrea Cervesato
@ 2024-09-09 10:00 ` Andrea Cervesato
  2024-10-02 14:05   ` Cyril Hrubis
  2024-10-02 14:14   ` Cyril Hrubis
  2024-09-09 10:00 ` [LTP] [PATCH v4 05/13] Add listmount02 test Andrea Cervesato
                   ` (9 subsequent siblings)
  13 siblings, 2 replies; 35+ messages in thread
From: Andrea Cervesato @ 2024-09-09 10:00 UTC (permalink / raw)
  To: ltp

From: Andrea Cervesato <andrea.cervesato@suse.com>

This test verifies that listmount() is properly recognizing a mounted
root directory using LSMT_ROOT flag.

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 runtest/syscalls                                  |  2 +
 testcases/kernel/syscalls/listmount/.gitignore    |  1 +
 testcases/kernel/syscalls/listmount/Makefile      |  7 +++
 testcases/kernel/syscalls/listmount/listmount.h   | 26 ++++++++++
 testcases/kernel/syscalls/listmount/listmount01.c | 63 +++++++++++++++++++++++
 5 files changed, 99 insertions(+)

diff --git a/runtest/syscalls b/runtest/syscalls
index a9fc8c432..48db6259b 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -730,6 +730,8 @@ linkat02 linkat02
 
 listen01 listen01
 
+listmount01 listmount01
+
 listxattr01 listxattr01
 listxattr02 listxattr02
 listxattr03 listxattr03
diff --git a/testcases/kernel/syscalls/listmount/.gitignore b/testcases/kernel/syscalls/listmount/.gitignore
new file mode 100644
index 000000000..5257b298c
--- /dev/null
+++ b/testcases/kernel/syscalls/listmount/.gitignore
@@ -0,0 +1 @@
+listmount01
diff --git a/testcases/kernel/syscalls/listmount/Makefile b/testcases/kernel/syscalls/listmount/Makefile
new file mode 100644
index 000000000..8cf1b9024
--- /dev/null
+++ b/testcases/kernel/syscalls/listmount/Makefile
@@ -0,0 +1,7 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/syscalls/listmount/listmount.h b/testcases/kernel/syscalls/listmount/listmount.h
new file mode 100644
index 000000000..93766cd33
--- /dev/null
+++ b/testcases/kernel/syscalls/listmount/listmount.h
@@ -0,0 +1,26 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+#ifndef LISTMOUNT_H
+
+#define _GNU_SOURCE
+
+#include "tst_test.h"
+#include "lapi/mount.h"
+#include "lapi/syscalls.h"
+
+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 = {
+		.size = MNT_ID_REQ_SIZE_VER0,
+		.mnt_id = mnt_id,
+		.param = last_mnt_id,
+	};
+
+	return tst_syscall(__NR_listmount, &req, list, num, flags);
+}
+
+#endif
diff --git a/testcases/kernel/syscalls/listmount/listmount01.c b/testcases/kernel/syscalls/listmount/listmount01.c
new file mode 100644
index 000000000..ab74b776b
--- /dev/null
+++ b/testcases/kernel/syscalls/listmount/listmount01.c
@@ -0,0 +1,63 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * This test verifies that listmount() is properly recognizing a mounted
+ * root directory using LSMT_ROOT flag.
+ *
+ * [Algorithm]
+ *
+ * - move into a new unshared namespace
+ * - mount() a root inside temporary folder and get its mount ID
+ * - get list of mounted IDs using listmount(LSMT_ROOT, ..)
+ * - verify that the root mount ID is the only mount ID present inside the list
+ */
+
+#define _GNU_SOURCE
+
+#include "listmount.h"
+#include "lapi/stat.h"
+#include "lapi/sched.h"
+
+#define MNTPOINT "mntpoint"
+#define LISTSIZE 32
+
+static uint64_t root_id;
+
+static void run(void)
+{
+	uint64_t list[LISTSIZE];
+
+	TST_EXP_POSITIVE(listmount(LSMT_ROOT, 0, list, LISTSIZE, 0));
+	if (TST_RET == -1)
+		return;
+
+	TST_EXP_EQ_LI(TST_RET, 1);
+	TST_EXP_EQ_LI(list[0], root_id);
+}
+
+static void setup(void)
+{
+	struct ltp_statx sx;
+
+	SAFE_UNSHARE(CLONE_NEWNS);
+
+	SAFE_CHROOT(MNTPOINT);
+	SAFE_MOUNT("", "/", NULL, MS_REC | MS_PRIVATE, NULL);
+	SAFE_STATX(AT_FDCWD, "/", 0, STATX_MNT_ID_UNIQUE, &sx);
+
+	root_id = sx.data.stx_mnt_id;
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.forks_child = 1,
+	.min_kver = "6.8",
+	.mount_device = 1,
+	.mntpoint = MNTPOINT,
+};

-- 
2.43.0


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

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [LTP] [PATCH v4 05/13] Add listmount02 test
  2024-09-09 10:00 [LTP] [PATCH v4 00/13] statmount/listmount testing suites Andrea Cervesato
                   ` (3 preceding siblings ...)
  2024-09-09 10:00 ` [LTP] [PATCH v4 04/13] Add listmount01 test Andrea Cervesato
@ 2024-09-09 10:00 ` Andrea Cervesato
  2024-10-02 14:37   ` Cyril Hrubis
  2024-09-09 10:00 ` [LTP] [PATCH v4 06/13] Add statmount01 test Andrea Cervesato
                   ` (8 subsequent siblings)
  13 siblings, 1 reply; 35+ messages in thread
From: Andrea Cervesato @ 2024-09-09 10:00 UTC (permalink / raw)
  To: ltp

From: Andrea Cervesato <andrea.cervesato@suse.com>

This test verifies that listmount() is properly reading groups of
mount IDs.

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 runtest/syscalls                                  |   1 +
 testcases/kernel/syscalls/listmount/.gitignore    |   1 +
 testcases/kernel/syscalls/listmount/listmount02.c | 105 ++++++++++++++++++++++
 3 files changed, 107 insertions(+)

diff --git a/runtest/syscalls b/runtest/syscalls
index 48db6259b..13b6a28b9 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -731,6 +731,7 @@ linkat02 linkat02
 listen01 listen01
 
 listmount01 listmount01
+listmount02 listmount02
 
 listxattr01 listxattr01
 listxattr02 listxattr02
diff --git a/testcases/kernel/syscalls/listmount/.gitignore b/testcases/kernel/syscalls/listmount/.gitignore
index 5257b298c..30bbf9f02 100644
--- a/testcases/kernel/syscalls/listmount/.gitignore
+++ b/testcases/kernel/syscalls/listmount/.gitignore
@@ -1 +1,2 @@
 listmount01
+listmount02
diff --git a/testcases/kernel/syscalls/listmount/listmount02.c b/testcases/kernel/syscalls/listmount/listmount02.c
new file mode 100644
index 000000000..950d660d7
--- /dev/null
+++ b/testcases/kernel/syscalls/listmount/listmount02.c
@@ -0,0 +1,105 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * This test verifies that listmount() is properly reading groups of mount IDs,
+ * checking that both oneshoot and iterator API for listmount() return the same
+ * array.
+ *
+ * [Algorithm]
+ *
+ * - move into a new unshared namespace
+ * - mount() our new root inside temporary folder
+ * - generate a full mounts tree inside root folder, doubling the number of
+ *   mounted filesystems each bind mount
+ * - read the full list of mounted IDs using listmount(LSMT_ROOT, ..)
+ * - read the list of mounted IDs using groups of fixed size
+ * - compare the first mount list with the second mount list
+ */
+
+#include "listmount.h"
+#include "lapi/sched.h"
+
+#define MNTPOINT "mntpoint"
+#define BIND_MOUNTS 7
+#define GROUPS_SIZE 3
+#define LISTSIZE (1 << BIND_MOUNTS)
+
+static void run(void)
+{
+	ssize_t ret;
+	size_t id, tot_ids, count = 0;
+	uint64_t mount_ids[LISTSIZE];
+	uint64_t list[LISTSIZE];
+
+	for (int i = 0; i < BIND_MOUNTS; i++)
+		SAFE_MOUNT("/", "/", NULL, MS_BIND, NULL);
+
+	tst_res(TINFO, "Reading all %d mount IDs in once", LISTSIZE);
+
+	TST_EXP_POSITIVE(listmount(LSMT_ROOT, 0, mount_ids, LISTSIZE, 0));
+	if (TST_RET == -1)
+		goto end;
+
+	tot_ids = (size_t)TST_RET;
+
+	if (tot_ids != LISTSIZE) {
+		tst_res(TFAIL, "listmount() returned %lu but %d was expected",
+			tot_ids, LISTSIZE);
+		goto end;
+	}
+
+	tst_res(TINFO, "Reading groups of %d mount IDs", GROUPS_SIZE);
+
+	while (count < LISTSIZE) {
+		id = count ? list[count - 1] : 0;
+		ret = listmount(LSMT_ROOT, id, list + count, GROUPS_SIZE, 0);
+
+		tst_res(TDEBUG, "listmount(LSMT_ROOT, %lu, list + %lu, %d, 0)",
+			id, count, GROUPS_SIZE);
+
+		if (ret == -1) {
+			tst_res(TFAIL, "listmount() failed with %s", tst_strerrno(errno));
+			goto end;
+		}
+
+		count += ret;
+
+		if (TST_RET < GROUPS_SIZE)
+			break;
+	}
+
+	for (size_t i = 0; i < LISTSIZE; i++) {
+		if (mount_ids[i] != list[i]) {
+			tst_res(TFAIL, "Mount ID differs at %ld index", i);
+			goto end;
+		}
+	}
+
+	tst_res(TPASS, "All mount IDs have been correctly read");
+
+end:
+	for (int i = 0; i < BIND_MOUNTS; i++)
+		SAFE_UMOUNT("/");
+}
+
+static void setup(void)
+{
+	SAFE_UNSHARE(CLONE_NEWNS);
+	SAFE_CHROOT(MNTPOINT);
+
+	SAFE_MOUNT("", "/", NULL, MS_REC | MS_SHARED, NULL);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.forks_child = 1,
+	.min_kver = "6.8",
+	.mount_device = 1,
+	.mntpoint = MNTPOINT,
+};

-- 
2.43.0


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

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [LTP] [PATCH v4 06/13] Add statmount01 test
  2024-09-09 10:00 [LTP] [PATCH v4 00/13] statmount/listmount testing suites Andrea Cervesato
                   ` (4 preceding siblings ...)
  2024-09-09 10:00 ` [LTP] [PATCH v4 05/13] Add listmount02 test Andrea Cervesato
@ 2024-09-09 10:00 ` Andrea Cervesato
  2024-10-02 14:45   ` Cyril Hrubis
  2024-09-09 10:00 ` [LTP] [PATCH v4 07/13] Add statmount02 test Andrea Cervesato
                   ` (7 subsequent siblings)
  13 siblings, 1 reply; 35+ messages in thread
From: Andrea Cervesato @ 2024-09-09 10:00 UTC (permalink / raw)
  To: ltp

From: Andrea Cervesato <andrea.cervesato@suse.com>

This test verifies that statmount() is working with no mask flags.

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 runtest/syscalls                                  |  2 +
 testcases/kernel/syscalls/statmount/.gitignore    |  1 +
 testcases/kernel/syscalls/statmount/Makefile      |  7 ++
 testcases/kernel/syscalls/statmount/statmount.h   | 26 +++++++
 testcases/kernel/syscalls/statmount/statmount01.c | 82 +++++++++++++++++++++++
 5 files changed, 118 insertions(+)

diff --git a/runtest/syscalls b/runtest/syscalls
index 13b6a28b9..ebe0de2a0 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -1568,6 +1568,8 @@ stat03_64 stat03_64
 stat04 stat04
 stat04_64 stat04_64
 
+statmount01 statmount01
+
 statfs01 statfs01
 statfs01_64 statfs01_64
 statfs02 statfs02
diff --git a/testcases/kernel/syscalls/statmount/.gitignore b/testcases/kernel/syscalls/statmount/.gitignore
new file mode 100644
index 000000000..f1529eb29
--- /dev/null
+++ b/testcases/kernel/syscalls/statmount/.gitignore
@@ -0,0 +1 @@
+statmount01
diff --git a/testcases/kernel/syscalls/statmount/Makefile b/testcases/kernel/syscalls/statmount/Makefile
new file mode 100644
index 000000000..8cf1b9024
--- /dev/null
+++ b/testcases/kernel/syscalls/statmount/Makefile
@@ -0,0 +1,7 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/syscalls/statmount/statmount.h b/testcases/kernel/syscalls/statmount/statmount.h
new file mode 100644
index 000000000..e807c8288
--- /dev/null
+++ b/testcases/kernel/syscalls/statmount/statmount.h
@@ -0,0 +1,26 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+#ifndef STATMOUNT_H
+
+#define _GNU_SOURCE
+
+#include "tst_test.h"
+#include "lapi/mount.h"
+#include "lapi/syscalls.h"
+
+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 = {
+		.size = MNT_ID_REQ_SIZE_VER0,
+		.mnt_id = mnt_id,
+		.param = mask,
+	};
+
+	return tst_syscall(__NR_statmount, &req, buf, bufsize, flags);
+}
+
+#endif
diff --git a/testcases/kernel/syscalls/statmount/statmount01.c b/testcases/kernel/syscalls/statmount/statmount01.c
new file mode 100644
index 000000000..95dac5c92
--- /dev/null
+++ b/testcases/kernel/syscalls/statmount/statmount01.c
@@ -0,0 +1,82 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * This test verifies that statmount() is working with no mask flags.
+ *
+ * [Algorithm]
+ *
+ * - create a mount point
+ * - run statmount() on the mount point without giving any mask
+ * - read results and check that mask and size are correct
+ */
+
+#define _GNU_SOURCE
+
+#include "statmount.h"
+#include "lapi/stat.h"
+#include "lapi/sched.h"
+
+#define MNTPOINT "mntpoint"
+
+static uint64_t root_id;
+static struct statmount *st_mount;
+
+static void run(void)
+{
+	memset(st_mount, 0, sizeof(struct statmount));
+
+	TST_EXP_PASS(statmount(root_id, 0, st_mount, sizeof(struct statmount), 0));
+
+	if (TST_RET == -1)
+		return;
+
+	TST_EXP_EQ_LI(st_mount->size, sizeof(struct statmount));
+	TST_EXP_EQ_LI(st_mount->mask, 0);
+	TST_EXP_EQ_LI(st_mount->sb_dev_major, 0);
+	TST_EXP_EQ_LI(st_mount->sb_dev_minor, 0);
+	TST_EXP_EQ_LI(st_mount->sb_magic, 0);
+	TST_EXP_EQ_LI(st_mount->sb_flags, 0);
+	TST_EXP_EQ_LI(st_mount->fs_type, 0);
+	TST_EXP_EQ_LI(st_mount->mnt_id, 0);
+	TST_EXP_EQ_LI(st_mount->mnt_parent_id, 0);
+	TST_EXP_EQ_LI(st_mount->mnt_id_old, 0);
+	TST_EXP_EQ_LI(st_mount->mnt_parent_id_old, 0);
+	TST_EXP_EQ_LI(st_mount->mnt_attr, 0);
+	TST_EXP_EQ_LI(st_mount->mnt_propagation, 0);
+	TST_EXP_EQ_LI(st_mount->mnt_peer_group, 0);
+	TST_EXP_EQ_LI(st_mount->mnt_master, 0);
+	TST_EXP_EQ_LI(st_mount->propagate_from, 0);
+	TST_EXP_EQ_LI(st_mount->mnt_root, 0);
+	TST_EXP_EQ_LI(st_mount->mnt_point, 0);
+}
+
+static void setup(void)
+{
+	struct ltp_statx sx;
+
+	SAFE_STATX(AT_FDCWD, MNTPOINT, 0, STATX_MNT_ID_UNIQUE, &sx);
+
+	root_id = sx.data.stx_mnt_id;
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.min_kver = "6.8",
+	.mount_device = 1,
+	.mntpoint = MNTPOINT,
+	.all_filesystems = 1,
+	.skip_filesystems = (const char *const []) {
+		"fuse",
+		NULL
+	},
+	.bufs = (struct tst_buffers []) {
+		{&st_mount, .size = sizeof(struct statmount)},
+		{}
+	}
+};

-- 
2.43.0


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

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [LTP] [PATCH v4 07/13] Add statmount02 test
  2024-09-09 10:00 [LTP] [PATCH v4 00/13] statmount/listmount testing suites Andrea Cervesato
                   ` (5 preceding siblings ...)
  2024-09-09 10:00 ` [LTP] [PATCH v4 06/13] Add statmount01 test Andrea Cervesato
@ 2024-09-09 10:00 ` Andrea Cervesato
  2024-10-02 15:15   ` Cyril Hrubis
  2024-09-09 10:00 ` [LTP] [PATCH v4 08/13] Add statmount03 test Andrea Cervesato
                   ` (6 subsequent siblings)
  13 siblings, 1 reply; 35+ messages in thread
From: Andrea Cervesato @ 2024-09-09 10:00 UTC (permalink / raw)
  To: ltp

From: Andrea Cervesato <andrea.cervesato@suse.com>

This test verifies that statmount() is correctly reading basic
filesystem info using STATMOUNT_SB_BASIC.

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 runtest/syscalls                                  |  1 +
 testcases/kernel/syscalls/statmount/.gitignore    |  1 +
 testcases/kernel/syscalls/statmount/statmount02.c | 84 +++++++++++++++++++++++
 3 files changed, 86 insertions(+)

diff --git a/runtest/syscalls b/runtest/syscalls
index ebe0de2a0..e028baf19 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -1569,6 +1569,7 @@ stat04 stat04
 stat04_64 stat04_64
 
 statmount01 statmount01
+statmount02 statmount02
 
 statfs01 statfs01
 statfs01_64 statfs01_64
diff --git a/testcases/kernel/syscalls/statmount/.gitignore b/testcases/kernel/syscalls/statmount/.gitignore
index f1529eb29..a30b9565f 100644
--- a/testcases/kernel/syscalls/statmount/.gitignore
+++ b/testcases/kernel/syscalls/statmount/.gitignore
@@ -1 +1,2 @@
 statmount01
+statmount02
diff --git a/testcases/kernel/syscalls/statmount/statmount02.c b/testcases/kernel/syscalls/statmount/statmount02.c
new file mode 100644
index 000000000..8c87a7a5c
--- /dev/null
+++ b/testcases/kernel/syscalls/statmount/statmount02.c
@@ -0,0 +1,84 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * This test verifies that statmount() is correctly reading basic filesystem
+ * info using STATMOUNT_SB_BASIC.
+ * The btrfs validation is currently skipped due to the lack of support for VFS.
+ *
+ * [Algorithm]
+ *
+ * - create a mount point and read its mount info
+ * - run statmount() on the mount point using STATMOUNT_SB_BASIC
+ * - read results and check if mount info are correct
+ */
+
+#define _GNU_SOURCE
+
+#include "statmount.h"
+#include "lapi/stat.h"
+#include "lapi/sched.h"
+#include <linux/btrfs.h>
+
+#define MNTPOINT "mntpoint"
+
+static struct statmount *st_mount;
+static struct ltp_statx *sx_mount;
+static struct statfs *sf_mount;
+
+static void run(void)
+{
+	memset(st_mount, 0, sizeof(struct statmount));
+
+	TST_EXP_PASS(statmount(sx_mount->data.stx_mnt_id, STATMOUNT_SB_BASIC,
+		st_mount, sizeof(struct statmount), 0));
+
+	if (TST_RET == -1)
+		return;
+
+	TST_EXP_EQ_LI(st_mount->mask, STATMOUNT_SB_BASIC);
+	TST_EXP_EQ_LI(st_mount->size, sizeof(struct statmount));
+	TST_EXP_EQ_LI(st_mount->sb_dev_major, sx_mount->data.stx_dev_major);
+	TST_EXP_EQ_LI(st_mount->sb_dev_minor, sx_mount->data.stx_dev_minor);
+	TST_EXP_EQ_LI(st_mount->sb_magic, sf_mount->f_type);
+	TST_EXP_EQ_LI(st_mount->sb_flags, MS_RDONLY);
+}
+
+static void setup(void)
+{
+	SAFE_MOUNT(tst_device->dev, MNTPOINT, tst_device->fs_type, MS_RDONLY, NULL);
+
+	SAFE_STATX(AT_FDCWD, MNTPOINT, 0, STATX_MNT_ID_UNIQUE, sx_mount);
+	SAFE_STATFS(MNTPOINT, sf_mount);
+}
+
+static void cleanup(void)
+{
+	if (tst_is_mounted(MNTPOINT))
+		SAFE_UMOUNT(MNTPOINT);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.cleanup = cleanup,
+	.min_kver = "6.8",
+	.mntpoint = MNTPOINT,
+	.format_device = 1,
+	.all_filesystems = 1,
+	.skip_filesystems = (const char *const []) {
+		"fuse",
+		"btrfs",
+		NULL
+	},
+	.bufs = (struct tst_buffers []) {
+		{&st_mount, .size = sizeof(struct statmount)},
+		{&sx_mount, .size = sizeof(struct ltp_statx)},
+		{&sf_mount, .size = sizeof(struct statfs)},
+		{}
+	}
+};

-- 
2.43.0


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

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [LTP] [PATCH v4 08/13] Add statmount03 test
  2024-09-09 10:00 [LTP] [PATCH v4 00/13] statmount/listmount testing suites Andrea Cervesato
                   ` (6 preceding siblings ...)
  2024-09-09 10:00 ` [LTP] [PATCH v4 07/13] Add statmount02 test Andrea Cervesato
@ 2024-09-09 10:00 ` Andrea Cervesato
  2024-10-03 13:27   ` Cyril Hrubis
  2024-09-09 10:00 ` [LTP] [PATCH v4 09/13] Add statmount04 test Andrea Cervesato
                   ` (5 subsequent siblings)
  13 siblings, 1 reply; 35+ messages in thread
From: Andrea Cervesato @ 2024-09-09 10:00 UTC (permalink / raw)
  To: ltp

From: Andrea Cervesato <andrea.cervesato@suse.com>

This test verifies that statmount() is correctly reading mount
information (mount id, parent mount id, mount attributes etc.)
using STATMOUNT_MNT_BASIC.

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 runtest/syscalls                                  |   1 +
 testcases/kernel/syscalls/statmount/.gitignore    |   1 +
 testcases/kernel/syscalls/statmount/statmount.h   |  24 ++++
 testcases/kernel/syscalls/statmount/statmount03.c | 137 ++++++++++++++++++++++
 4 files changed, 163 insertions(+)

diff --git a/runtest/syscalls b/runtest/syscalls
index e028baf19..ec11a3a21 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -1570,6 +1570,7 @@ stat04_64 stat04_64
 
 statmount01 statmount01
 statmount02 statmount02
+statmount03 statmount03
 
 statfs01 statfs01
 statfs01_64 statfs01_64
diff --git a/testcases/kernel/syscalls/statmount/.gitignore b/testcases/kernel/syscalls/statmount/.gitignore
index a30b9565f..2a02bf721 100644
--- a/testcases/kernel/syscalls/statmount/.gitignore
+++ b/testcases/kernel/syscalls/statmount/.gitignore
@@ -1,2 +1,3 @@
 statmount01
 statmount02
+statmount03
diff --git a/testcases/kernel/syscalls/statmount/statmount.h b/testcases/kernel/syscalls/statmount/statmount.h
index e807c8288..5cd54242c 100644
--- a/testcases/kernel/syscalls/statmount/statmount.h
+++ b/testcases/kernel/syscalls/statmount/statmount.h
@@ -10,6 +10,7 @@
 #include "tst_test.h"
 #include "lapi/mount.h"
 #include "lapi/syscalls.h"
+#include "tst_safe_stdio.h"
 
 static inline int statmount(uint64_t mnt_id, uint64_t mask, struct statmount *buf,
 		     size_t bufsize, unsigned int flags)
@@ -23,4 +24,27 @@ static inline int statmount(uint64_t mnt_id, uint64_t mask, struct statmount *bu
 	return tst_syscall(__NR_statmount, &req, buf, bufsize, flags);
 }
 
+static inline int read_peer_group(const char *path)
+{
+	FILE *file;
+	char line[PATH_MAX];
+	char mroot[PATH_MAX];
+	int group = -1;
+
+	file = SAFE_FOPEN("/proc/self/mountinfo", "r");
+
+	while (fgets(line, sizeof(line), file)) {
+		if (sscanf(line, "%*d %*d %*d:%*d %s %*s %*s shared:%d", mroot, &group) != 2)
+			continue;
+
+		if (strcmp(mroot, path) == 0)
+			break;
+	}
+
+	if (group == -1)
+		tst_brk(TBROK, "Can't reed peer group ID for %s", path);
+
+	return group;
+}
+
 #endif
diff --git a/testcases/kernel/syscalls/statmount/statmount03.c b/testcases/kernel/syscalls/statmount/statmount03.c
new file mode 100644
index 000000000..634c4b447
--- /dev/null
+++ b/testcases/kernel/syscalls/statmount/statmount03.c
@@ -0,0 +1,137 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * This test verifies that statmount() is correctly reading mount information
+ * (mount id, parent mount id, mount attributes etc.) using STATMOUNT_MNT_BASIC.
+ *
+ * [Algorithm]
+ *
+ * - create a mount point
+ * - create a new parent folder inside the mount point and obtain its mount info
+ * - create the new "/" mount folder and obtain its mount info
+ * - run statmount() on the mount point using STATMOUNT_MNT_BASIC
+ * - read results and check if mount info are correct
+ */
+
+#define _GNU_SOURCE
+
+#include "statmount.h"
+#include "lapi/stat.h"
+#include "lapi/sched.h"
+
+#define DIR_A "LTP_DIR_A"
+#define DIR_B "LTP_DIR_B"
+
+static uint64_t mnt_id;
+static uint64_t mnt_id_old;
+static uint64_t parent_id;
+static uint64_t parent_id_old;
+static uint64_t mnt_peer_group;
+static uint64_t mnt_master;
+static struct statmount *st_mount;
+
+static void read_mnt_id(
+	const char *path,
+	uint64_t *mnt_id,
+	uint64_t *mnt_id_unique)
+{
+	struct ltp_statx sx;
+
+	if (mnt_id) {
+		SAFE_STATX(AT_FDCWD, path, 0, STATX_MNT_ID, &sx);
+		*mnt_id = sx.data.stx_mnt_id;
+	}
+
+	if (mnt_id_unique) {
+		SAFE_STATX(AT_FDCWD, path, 0, STATX_MNT_ID_UNIQUE, &sx);
+		*mnt_id_unique = sx.data.stx_mnt_id;
+	}
+}
+
+static struct tcase {
+	uint64_t prop_type;
+	char *msg;
+} tcases[] = {
+	{ MS_PRIVATE, TST_TO_STR_(MS_PRIVATE) },
+	{ MS_SHARED, TST_TO_STR_(MS_SHARED) },
+	{ MS_SLAVE, TST_TO_STR_(MS_SLAVE) },
+	{ MS_UNBINDABLE, TST_TO_STR_(MS_UNBINDABLE) },
+};
+
+static void run(unsigned int i)
+{
+	struct tcase *tc = &tcases[i];
+
+	tst_res(TINFO,  "Testing statmount() on %s", tc->msg);
+
+	SAFE_MOUNT(DIR_B, DIR_A, "none", MS_BIND, NULL);
+	SAFE_MOUNT("none", DIR_A, "none", tc->prop_type, NULL);
+	read_mnt_id(DIR_A, &mnt_id_old, &mnt_id);
+
+	memset(st_mount, 0, sizeof(struct statmount));
+
+	TST_EXP_PASS(statmount(mnt_id, STATMOUNT_MNT_BASIC, st_mount,
+		sizeof(struct statmount), 0));
+
+	SAFE_UMOUNT(DIR_A);
+
+	if (TST_RET == -1)
+		return;
+
+	/* s->sm.mnt_peer_group = IS_MNT_SHARED(m) ? m->mnt_group_id : 0;
+	 * s->sm.mnt_master = IS_MNT_SLAVE(m) ? m->mnt_master->mnt_group_id : 0;
+	 */
+	mnt_peer_group = tc->prop_type == MS_SHARED ? read_peer_group(DIR_A) : 0;
+	mnt_master = tc->prop_type == MS_SLAVE ? read_peer_group(DIR_A) : 0;
+
+	TST_EXP_EQ_LI(st_mount->mask, STATMOUNT_MNT_BASIC);
+	TST_EXP_EQ_LI(st_mount->size, sizeof(struct statmount));
+	TST_EXP_EQ_LI(st_mount->mnt_id, mnt_id);
+	TST_EXP_EQ_LI(st_mount->mnt_id_old, mnt_id_old);
+	TST_EXP_EQ_LI(st_mount->mnt_parent_id, parent_id);
+	TST_EXP_EQ_LI(st_mount->mnt_parent_id_old, parent_id_old);
+	TST_EXP_EQ_LU(st_mount->mnt_propagation & tc->prop_type, tc->prop_type);
+	TST_EXP_EQ_LI(st_mount->mnt_master, mnt_master);
+	TST_EXP_EQ_LI(st_mount->mnt_peer_group, mnt_peer_group);
+}
+
+static void setup(void)
+{
+	SAFE_MKDIR(DIR_A, 0700);
+	SAFE_MKDIR(DIR_B, 0700);
+
+	SAFE_UNSHARE(CLONE_NEWNS);
+	SAFE_MOUNT("none", "/", "none", MS_REC | MS_PRIVATE, NULL);
+
+	SAFE_MOUNT(DIR_B, DIR_B, "none", MS_BIND, NULL);
+	SAFE_MOUNT("none", DIR_B, "none", MS_SHARED, NULL);
+
+	read_mnt_id(DIR_A, &parent_id_old, &parent_id);
+}
+
+static void cleanup(void)
+{
+	if (tst_is_mounted(DIR_B))
+		SAFE_UMOUNT(DIR_B);
+
+	if (tst_is_mounted(DIR_A))
+		SAFE_UMOUNT(DIR_A);
+}
+
+static struct tst_test test = {
+	.test = run,
+	.tcnt = ARRAY_SIZE(tcases),
+	.setup = setup,
+	.cleanup = cleanup,
+	.min_kver = "6.8",
+	.needs_tmpdir = 1,
+	.bufs = (struct tst_buffers []) {
+		{&st_mount, .size = sizeof(struct statmount)},
+		{}
+	}
+};

-- 
2.43.0


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

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [LTP] [PATCH v4 09/13] Add statmount04 test
  2024-09-09 10:00 [LTP] [PATCH v4 00/13] statmount/listmount testing suites Andrea Cervesato
                   ` (7 preceding siblings ...)
  2024-09-09 10:00 ` [LTP] [PATCH v4 08/13] Add statmount03 test Andrea Cervesato
@ 2024-09-09 10:00 ` Andrea Cervesato
  2024-10-03 13:51   ` Cyril Hrubis
  2024-09-09 10:00 ` [LTP] [PATCH v4 10/13] Add statmount05 test Andrea Cervesato
                   ` (4 subsequent siblings)
  13 siblings, 1 reply; 35+ messages in thread
From: Andrea Cervesato @ 2024-09-09 10:00 UTC (permalink / raw)
  To: ltp

From: Andrea Cervesato <andrea.cervesato@suse.com>

This test verifies that statmount() is correctly reading propagation
from what mount in current namespace using STATMOUNT_PROPAGATE_FROM.

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 runtest/syscalls                                  |   1 +
 testcases/kernel/syscalls/statmount/.gitignore    |   1 +
 testcases/kernel/syscalls/statmount/statmount04.c | 105 ++++++++++++++++++++++
 3 files changed, 107 insertions(+)

diff --git a/runtest/syscalls b/runtest/syscalls
index ec11a3a21..e43e53002 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -1571,6 +1571,7 @@ stat04_64 stat04_64
 statmount01 statmount01
 statmount02 statmount02
 statmount03 statmount03
+statmount04 statmount04
 
 statfs01 statfs01
 statfs01_64 statfs01_64
diff --git a/testcases/kernel/syscalls/statmount/.gitignore b/testcases/kernel/syscalls/statmount/.gitignore
index 2a02bf721..e720050b5 100644
--- a/testcases/kernel/syscalls/statmount/.gitignore
+++ b/testcases/kernel/syscalls/statmount/.gitignore
@@ -1,3 +1,4 @@
 statmount01
 statmount02
 statmount03
+statmount04
diff --git a/testcases/kernel/syscalls/statmount/statmount04.c b/testcases/kernel/syscalls/statmount/statmount04.c
new file mode 100644
index 000000000..2d9a4e6c9
--- /dev/null
+++ b/testcases/kernel/syscalls/statmount/statmount04.c
@@ -0,0 +1,105 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * This test verifies that statmount() is correctly reading propagation from
+ * what mount in current namespace using STATMOUNT_PROPAGATE_FROM.
+ *
+ * [Algorithm]
+ *
+ * - create a mount point
+ * - propagate a mounted folder inside the mount point
+ * - run statmount() on the mount point using STATMOUNT_PROPAGATE_FROM
+ * - read results and check propagated_from parameter contains the propagated
+ *   folder ID
+ */
+
+#define _GNU_SOURCE
+
+#include "statmount.h"
+#include "lapi/stat.h"
+#include "lapi/sched.h"
+
+#define MNTPOINT "mntpoint"
+#define DIR_A MNTPOINT "/LTP_DIR_A"
+#define DIR_C_SUBFOLDER "/LTP_DIR_A/propagated"
+#define DIR_C (MNTPOINT DIR_C_SUBFOLDER)
+#define DIR_B MNTPOINT "/LTP_DIR_B"
+#define DIR_D MNTPOINT "/LTP_DIR_B/propagated"
+
+static uint64_t peer_group_id;
+static uint64_t dird_id;
+static struct statmount *st_mount;
+
+static void run(void)
+{
+	memset(st_mount, 0, sizeof(struct statmount));
+
+	TST_EXP_PASS(statmount(dird_id, STATMOUNT_PROPAGATE_FROM, st_mount,
+		sizeof(struct statmount), 0));
+
+	if (TST_RET == -1)
+		return;
+
+	TST_EXP_EQ_LI(st_mount->mask, STATMOUNT_PROPAGATE_FROM);
+	TST_EXP_EQ_LI(st_mount->size, sizeof(struct statmount));
+	TST_EXP_EQ_LI(st_mount->propagate_from, peer_group_id);
+}
+
+static void setup(void)
+{
+	struct ltp_statx sx;
+
+	/* create DIR_A / DIR_C structure with DIR_C mounted */
+	SAFE_MKDIR(DIR_A, 0700);
+	SAFE_MOUNT(DIR_A, DIR_A, "none", MS_BIND, NULL);
+	SAFE_MOUNT("none", DIR_A, "none", MS_SHARED, NULL);
+
+	SAFE_MKDIR(DIR_C, 0700);
+	SAFE_MOUNT(DIR_C, DIR_C, "none", MS_BIND, NULL);
+	SAFE_MOUNT("none", DIR_C, "none", MS_SHARED, NULL);
+
+	/* DIR_A mounts into DIR_B. DIR_D is propagated */
+	SAFE_MKDIR(DIR_B, 0700);
+	SAFE_MOUNT(DIR_A, DIR_B, "none", MS_BIND, NULL);
+	SAFE_MOUNT("none", DIR_B, "none", MS_SLAVE, NULL);
+
+	SAFE_STATX(AT_FDCWD, DIR_D, 0, STATX_MNT_ID_UNIQUE, &sx);
+	dird_id = sx.data.stx_mnt_id;
+
+	peer_group_id = read_peer_group(DIR_A);
+}
+
+static void cleanup(void)
+{
+	if (tst_is_mounted(DIR_C))
+		SAFE_UMOUNT(DIR_C);
+
+	if (tst_is_mounted(DIR_B))
+		SAFE_UMOUNT(DIR_B);
+
+	if (tst_is_mounted(DIR_A))
+		SAFE_UMOUNT(DIR_A);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.cleanup = cleanup,
+	.min_kver = "6.8",
+	.mount_device = 1,
+	.mntpoint = MNTPOINT,
+	.all_filesystems = 1,
+	.skip_filesystems = (const char *const []) {
+		"fuse",
+		NULL
+	},
+	.bufs = (struct tst_buffers []) {
+		{&st_mount, .size = sizeof(struct statmount)},
+		{}
+	}
+};

-- 
2.43.0


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

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [LTP] [PATCH v4 10/13] Add statmount05 test
  2024-09-09 10:00 [LTP] [PATCH v4 00/13] statmount/listmount testing suites Andrea Cervesato
                   ` (8 preceding siblings ...)
  2024-09-09 10:00 ` [LTP] [PATCH v4 09/13] Add statmount04 test Andrea Cervesato
@ 2024-09-09 10:00 ` Andrea Cervesato
  2024-10-03 14:09   ` Cyril Hrubis
  2024-09-09 10:00 ` [LTP] [PATCH v4 11/13] Add TST_EXP_EQ_STR macro Andrea Cervesato
                   ` (3 subsequent siblings)
  13 siblings, 1 reply; 35+ messages in thread
From: Andrea Cervesato @ 2024-09-09 10:00 UTC (permalink / raw)
  To: ltp

From: Andrea Cervesato <andrea.cervesato@suse.com>

This test verifies STATMOUNT_MNT_ROOT and STATMOUNT_MNT_POINT
functionalities of statmount().

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 runtest/syscalls                                  |   1 +
 testcases/kernel/syscalls/statmount/.gitignore    |   1 +
 testcases/kernel/syscalls/statmount/statmount05.c | 128 ++++++++++++++++++++++
 3 files changed, 130 insertions(+)

diff --git a/runtest/syscalls b/runtest/syscalls
index e43e53002..9f5a473f3 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -1572,6 +1572,7 @@ statmount01 statmount01
 statmount02 statmount02
 statmount03 statmount03
 statmount04 statmount04
+statmount05 statmount05
 
 statfs01 statfs01
 statfs01_64 statfs01_64
diff --git a/testcases/kernel/syscalls/statmount/.gitignore b/testcases/kernel/syscalls/statmount/.gitignore
index e720050b5..f64763242 100644
--- a/testcases/kernel/syscalls/statmount/.gitignore
+++ b/testcases/kernel/syscalls/statmount/.gitignore
@@ -2,3 +2,4 @@ statmount01
 statmount02
 statmount03
 statmount04
+statmount05
diff --git a/testcases/kernel/syscalls/statmount/statmount05.c b/testcases/kernel/syscalls/statmount/statmount05.c
new file mode 100644
index 000000000..dd4bb17f0
--- /dev/null
+++ b/testcases/kernel/syscalls/statmount/statmount05.c
@@ -0,0 +1,128 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * This test verifies STATMOUNT_MNT_ROOT and STATMOUNT_MNT_POINT functionalities
+ * of statmount(). In particular, STATMOUNT_MNT_ROOT will give the mount root
+ * (i.e. mount --bind /mnt /bla -> /mnt) and STATMOUNT_MNT_POINT will
+ * give the mount point (i.e. mount --bind /mnt /bla -> /bla).
+ *
+ * [Algorithm]
+ *
+ * - create a mount point
+ * - mount a folder inside the mount point
+ * - run statmount() on the mounted folder using STATMOUNT_MNT_ROOT
+ * - read results and check if contain the mount root path
+ * - run statmount() on the mounted folder using STATMOUNT_MNT_POINT
+ * - read results and check if contain the mount point path
+ */
+
+#define _GNU_SOURCE
+
+#include "statmount.h"
+#include "lapi/stat.h"
+#include "lapi/sched.h"
+#include "tst_tmpdir.h"
+
+#define MNTPOINT "mntpoint"
+#define DIRA MNTPOINT "/LTP_DIR_A"
+#define DIRB MNTPOINT "/LTP_DIR_B"
+#define SM_SIZE (1 << 10)
+
+static uint64_t root_id;
+static struct statmount *st_mount;
+static char *mnt_root;
+static char *mnt_point;
+
+static void test_mount_root(void)
+{
+	tst_res(TINFO, "Testing STATMOUNT_MNT_ROOT");
+
+	char *last_root;
+
+	memset(st_mount, 0, SM_SIZE);
+
+	TST_EXP_PASS(statmount(root_id, STATMOUNT_MNT_ROOT, st_mount,
+		SM_SIZE, 0));
+
+	if (TST_RET == -1)
+		return;
+
+	last_root = strrchr(mnt_root, '/');
+
+	TST_EXP_EQ_LI(st_mount->mask, STATMOUNT_MNT_ROOT);
+	TST_EXP_EXPR(strcmp(st_mount->str + st_mount->mnt_root, last_root) == 0,
+		"statmount() read '%s', expected '%s'",
+		st_mount->str + st_mount->mnt_root,
+		last_root);
+}
+
+static void test_mount_point(void)
+{
+	tst_res(TINFO, "Testing STATMOUNT_MNT_POINT");
+
+	memset(st_mount, 0, SM_SIZE);
+
+	TST_EXP_POSITIVE(statmount(root_id, STATMOUNT_MNT_POINT, st_mount,
+		SM_SIZE, 0));
+
+	if (TST_RET == -1)
+		return;
+
+	TST_EXP_EQ_LI(st_mount->mask, STATMOUNT_MNT_POINT);
+	TST_EXP_EXPR(strcmp(st_mount->str + st_mount->mnt_point, mnt_point) == 0,
+		"mount point is '%s'",
+		st_mount->str + st_mount->mnt_point);
+}
+
+static void run(void)
+{
+	test_mount_root();
+	test_mount_point();
+}
+
+static void setup(void)
+{
+	struct ltp_statx sx;
+
+	mnt_root = tst_tmpdir_mkpath(DIRA);
+	mnt_point = tst_tmpdir_mkpath(DIRB);
+
+	SAFE_MKDIR(mnt_root, 0700);
+	SAFE_MKDIR(mnt_point, 0700);
+	SAFE_MOUNT(mnt_root, mnt_point, "none", MS_BIND, NULL);
+
+	SAFE_STATX(AT_FDCWD, mnt_point, 0, STATX_MNT_ID_UNIQUE, &sx);
+	root_id = sx.data.stx_mnt_id;
+}
+
+static void cleanup(void)
+{
+	if (tst_is_mounted(DIRB))
+		SAFE_UMOUNT(DIRB);
+
+	if (tst_is_mounted(DIRA))
+		SAFE_UMOUNT(DIRA);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.cleanup = cleanup,
+	.min_kver = "6.8",
+	.mount_device = 1,
+	.mntpoint = MNTPOINT,
+	.all_filesystems = 1,
+	.skip_filesystems = (const char *const []) {
+		"fuse",
+		NULL
+	},
+	.bufs = (struct tst_buffers []) {
+		{&st_mount, .size = SM_SIZE},
+		{}
+	}
+};

-- 
2.43.0


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

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [LTP] [PATCH v4 11/13] Add TST_EXP_EQ_STR macro
  2024-09-09 10:00 [LTP] [PATCH v4 00/13] statmount/listmount testing suites Andrea Cervesato
                   ` (9 preceding siblings ...)
  2024-09-09 10:00 ` [LTP] [PATCH v4 10/13] Add statmount05 test Andrea Cervesato
@ 2024-09-09 10:00 ` Andrea Cervesato
  2024-10-03 14:13   ` Cyril Hrubis
  2024-09-09 10:00 ` [LTP] [PATCH v4 12/13] Add statmount06 test Andrea Cervesato
                   ` (2 subsequent siblings)
  13 siblings, 1 reply; 35+ messages in thread
From: Andrea Cervesato @ 2024-09-09 10:00 UTC (permalink / raw)
  To: ltp

From: Andrea Cervesato <andrea.cervesato@suse.com>

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 include/tst_test_macros.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/include/tst_test_macros.h b/include/tst_test_macros.h
index 7a443c803..ad8ebe4b5 100644
--- a/include/tst_test_macros.h
+++ b/include/tst_test_macros.h
@@ -369,4 +369,18 @@ const char *tst_errno_names(char *buf, const int *exp_errs, int exp_errs_cnt);
 #define TST_EXP_EQ_SSZ(VAL_A, VAL_B) \
 		TST_EXP_EQ_(VAL_A, #VAL_A, VAL_B, #VAL_B, ssize_t, "%zi")
 
+#define TST_EXP_EQ_STR(STR_A, STR_B) do {                                      \
+	TST_PASS = strcmp(STR_A, STR_B) == 0;                                  \
+                                                                               \
+	if (TST_PASS) {                                                        \
+		tst_res_(__FILE__, __LINE__, TPASS,                            \
+			"%s == %s (%s)",                                       \
+			#STR_A, #STR_B, STR_B);                                \
+	} else {                                                               \
+		tst_res_(__FILE__, __LINE__, TFAIL,                            \
+			"%s (%s) != %s (%s)",                                  \
+			#STR_A, STR_A, #STR_B, STR_B);                         \
+	}                                                                      \
+} while (0)
+
 #endif	/* TST_TEST_MACROS_H__ */

-- 
2.43.0


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

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [LTP] [PATCH v4 12/13] Add statmount06 test
  2024-09-09 10:00 [LTP] [PATCH v4 00/13] statmount/listmount testing suites Andrea Cervesato
                   ` (10 preceding siblings ...)
  2024-09-09 10:00 ` [LTP] [PATCH v4 11/13] Add TST_EXP_EQ_STR macro Andrea Cervesato
@ 2024-09-09 10:00 ` Andrea Cervesato
  2024-10-03 14:20   ` Cyril Hrubis
  2024-09-09 10:00 ` [LTP] [PATCH v4 13/13] Add statmount07 test Andrea Cervesato
  2024-10-03 14:42 ` [LTP] [PATCH v4 00/13] statmount/listmount testing suites Cyril Hrubis
  13 siblings, 1 reply; 35+ messages in thread
From: Andrea Cervesato @ 2024-09-09 10:00 UTC (permalink / raw)
  To: ltp

From: Andrea Cervesato <andrea.cervesato@suse.com>

This test verifies that statmount() is correctly reading name of the
filesystem type using STATMOUNT_FS_TYPE.

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 runtest/syscalls                                  |  1 +
 testcases/kernel/syscalls/statmount/.gitignore    |  1 +
 testcases/kernel/syscalls/statmount/statmount06.c | 68 +++++++++++++++++++++++
 3 files changed, 70 insertions(+)

diff --git a/runtest/syscalls b/runtest/syscalls
index 9f5a473f3..209e04b79 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -1573,6 +1573,7 @@ statmount02 statmount02
 statmount03 statmount03
 statmount04 statmount04
 statmount05 statmount05
+statmount06 statmount06
 
 statfs01 statfs01
 statfs01_64 statfs01_64
diff --git a/testcases/kernel/syscalls/statmount/.gitignore b/testcases/kernel/syscalls/statmount/.gitignore
index f64763242..03a75bd40 100644
--- a/testcases/kernel/syscalls/statmount/.gitignore
+++ b/testcases/kernel/syscalls/statmount/.gitignore
@@ -3,3 +3,4 @@ statmount02
 statmount03
 statmount04
 statmount05
+statmount06
diff --git a/testcases/kernel/syscalls/statmount/statmount06.c b/testcases/kernel/syscalls/statmount/statmount06.c
new file mode 100644
index 000000000..be53a6589
--- /dev/null
+++ b/testcases/kernel/syscalls/statmount/statmount06.c
@@ -0,0 +1,68 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * This test verifies that statmount() is correctly reading name of the
+ * filesystem type using STATMOUNT_FS_TYPE.
+ *
+ * [Algorithm]
+ *
+ * - create a mount point
+ * - run statmount() on the mount point using STATMOUNT_FS_TYPE
+ * - read results and check if contain the name of the filesystem
+ */
+
+#define _GNU_SOURCE
+
+#include "statmount.h"
+#include "lapi/stat.h"
+#include "lapi/sched.h"
+
+#define MNTPOINT "mntpoint"
+#define SM_SIZE (1 << 10)
+
+static uint64_t root_id;
+static struct statmount *st_mount;
+
+static void run(void)
+{
+	memset(st_mount, 0, SM_SIZE);
+
+	TST_EXP_PASS(statmount(root_id,	STATMOUNT_FS_TYPE, st_mount,
+		SM_SIZE, 0));
+
+	if (TST_RET == -1)
+		return;
+
+	TST_EXP_EQ_LI(st_mount->mask, STATMOUNT_FS_TYPE);
+	TST_EXP_EQ_STR(st_mount->str + st_mount->fs_type, tst_device->fs_type);
+}
+
+static void setup(void)
+{
+	struct ltp_statx sx;
+
+	SAFE_STATX(AT_FDCWD, MNTPOINT, 0, STATX_MNT_ID_UNIQUE, &sx);
+	root_id = sx.data.stx_mnt_id;
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.min_kver = "6.8",
+	.mount_device = 1,
+	.mntpoint = MNTPOINT,
+	.all_filesystems = 1,
+	.skip_filesystems = (const char *const []) {
+		"fuse",
+		NULL
+	},
+	.bufs = (struct tst_buffers []) {
+		{&st_mount, .size = SM_SIZE},
+		{}
+	}
+};

-- 
2.43.0


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

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [LTP] [PATCH v4 13/13] Add statmount07 test
  2024-09-09 10:00 [LTP] [PATCH v4 00/13] statmount/listmount testing suites Andrea Cervesato
                   ` (11 preceding siblings ...)
  2024-09-09 10:00 ` [LTP] [PATCH v4 12/13] Add statmount06 test Andrea Cervesato
@ 2024-09-09 10:00 ` Andrea Cervesato
  2024-10-03 14:34   ` Cyril Hrubis
  2024-10-03 14:42 ` [LTP] [PATCH v4 00/13] statmount/listmount testing suites Cyril Hrubis
  13 siblings, 1 reply; 35+ messages in thread
From: Andrea Cervesato @ 2024-09-09 10:00 UTC (permalink / raw)
  To: ltp

From: Andrea Cervesato <andrea.cervesato@suse.com>

This test is verifying that statmount syscall is raising the correct
errors according with invalid input values.

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 runtest/syscalls                                  |  1 +
 testcases/kernel/syscalls/statmount/.gitignore    |  1 +
 testcases/kernel/syscalls/statmount/statmount07.c | 75 +++++++++++++++++++++++
 3 files changed, 77 insertions(+)

diff --git a/runtest/syscalls b/runtest/syscalls
index 209e04b79..125d8fb00 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -1574,6 +1574,7 @@ statmount03 statmount03
 statmount04 statmount04
 statmount05 statmount05
 statmount06 statmount06
+statmount07 statmount07
 
 statfs01 statfs01
 statfs01_64 statfs01_64
diff --git a/testcases/kernel/syscalls/statmount/.gitignore b/testcases/kernel/syscalls/statmount/.gitignore
index 03a75bd40..b2a55c077 100644
--- a/testcases/kernel/syscalls/statmount/.gitignore
+++ b/testcases/kernel/syscalls/statmount/.gitignore
@@ -4,3 +4,4 @@ statmount03
 statmount04
 statmount05
 statmount06
+statmount07
diff --git a/testcases/kernel/syscalls/statmount/statmount07.c b/testcases/kernel/syscalls/statmount/statmount07.c
new file mode 100644
index 000000000..2746bf424
--- /dev/null
+++ b/testcases/kernel/syscalls/statmount/statmount07.c
@@ -0,0 +1,75 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * This test verifies that statmount() is raising the correct errors according
+ * with invalid input values.
+ */
+
+#define _GNU_SOURCE
+
+#include "statmount.h"
+#include "lapi/stat.h"
+
+#define MNTPOINT "mntpoint"
+
+static struct statmount *st_mount;
+static struct statmount *st_mount_null;
+static uint64_t mnt_id;
+static uint64_t mnt_id_dont_exist = -1;
+static size_t buff_size;
+static size_t buff_size_invalid = -1;
+
+struct tcase {
+	int exp_errno;
+	char *msg;
+	uint64_t *mnt_id;
+	uint64_t mask;
+	unsigned int flags;
+	size_t *buff_size;
+	struct statmount **buff;
+} tcases[] = {
+	{ENOENT, "mount id doesn't exist'", &mnt_id_dont_exist, 0, 0, &buff_size, &st_mount},
+	{EOVERFLOW, "invalid mask", &mnt_id, -1, 0, &buff_size, &st_mount},
+	{EINVAL, "flags must be zero", &mnt_id, 0, 1, &buff_size, &st_mount},
+	{EFAULT, "invalid buffer size", &mnt_id, 0, 0, &buff_size_invalid, &st_mount},
+	{EFAULT, "invalid buffer pointer", &mnt_id, 0, 0, &buff_size, &st_mount_null},
+};
+
+static void run(unsigned int n)
+{
+	struct tcase *tc = &tcases[n];
+
+	memset(st_mount, 0, sizeof(struct statmount));
+
+	TST_EXP_FAIL(statmount(*tc->mnt_id, tc->mask,
+		*tc->buff, *tc->buff_size, tc->flags),
+		tc->exp_errno, "%s", tc->msg);
+}
+
+static void setup(void)
+{
+	struct ltp_statx sx;
+
+	SAFE_STATX(AT_FDCWD, MNTPOINT, 0, STATX_MNT_ID_UNIQUE, &sx);
+
+	mnt_id = sx.data.stx_mnt_id;
+	buff_size = sizeof(struct statmount);
+}
+static struct tst_test test = {
+	.test = run,
+	.tcnt = ARRAY_SIZE(tcases),
+	.setup = setup,
+	.min_kver = "6.8",
+	.mount_device = 1,
+	.mntpoint = MNTPOINT,
+	.format_device = 1,
+	.bufs = (struct tst_buffers []) {
+		{&st_mount, .size = sizeof(struct statmount)},
+		{}
+	}
+};

-- 
2.43.0


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

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* Re: [LTP] [PATCH v4 01/13] Add SAFE_STATX macro
  2024-09-09 10:00 ` [LTP] [PATCH v4 01/13] Add SAFE_STATX macro Andrea Cervesato
@ 2024-09-09 16:21   ` Andrea Cervesato via ltp
  2024-10-02 12:27   ` Cyril Hrubis
  1 sibling, 0 replies; 35+ messages in thread
From: Andrea Cervesato via ltp @ 2024-09-09 16:21 UTC (permalink / raw)
  To: ltp

Hi!

read below...

On 9/9/24 12:00, Andrea Cervesato wrote:
> From: Andrea Cervesato <andrea.cervesato@suse.com>
>
> Reviewed-by: Avinesh Kumar <akumar@suse.de>
> Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
> ---
>   compile_flags.txt                                  |   1 +
>   include/lapi/stat.h                                | 111 +++++++++++++++------
>   testcases/kernel/syscalls/fchmodat2/fchmodat2_01.c |   2 +
>   3 files changed, 82 insertions(+), 32 deletions(-)
>
> diff --git a/compile_flags.txt b/compile_flags.txt
> new file mode 100644
> index 000000000..3e2e7607a
> --- /dev/null
> +++ b/compile_flags.txt

This is a file for configuring clangd. I guess I had a "git add ." in 
the folder. Please ignore this part of the patch.

Andrea

> @@ -0,0 +1 @@
> +-Iinclude/
> diff --git a/include/lapi/stat.h b/include/lapi/stat.h
> index 030646a9e..1fa5f4eaf 100644
> --- a/include/lapi/stat.h
> +++ b/include/lapi/stat.h
> @@ -30,6 +30,7 @@ struct statx_timestamp {
>   	int32_t __reserved;
>   };
>   #endif
> +
>   /*
>    * Structures for the extended file attribute retrieval system call
>    * (statx()).
> @@ -67,39 +68,57 @@ struct statx_timestamp {
>    * will have values installed for compatibility purposes so that stat() and
>    * co. can be emulated in userspace.
>    */
> -#ifndef HAVE_STRUCT_STATX
> -struct statx {
> -	/* 0x00 */
> -	uint32_t	stx_mask;
> -	uint32_t	stx_blksize;
> -	uint64_t	stx_attributes;
> -	/* 0x10 */
> -	uint32_t	stx_nlink;
> -	uint32_t	stx_uid;
> -	uint32_t	stx_gid;
> -	uint16_t	stx_mode;
> -	uint16_t	__spare0[1];
> -	/* 0x20 */
> -	uint64_t	stx_ino;
> -	uint64_t	stx_size;
> -	uint64_t	stx_blocks;
> -	uint64_t	stx_attributes_mask;
> -	/* 0x40 */
> -	const struct statx_timestamp	stx_atime;
> -	const struct statx_timestamp	stx_btime;
> -	const struct statx_timestamp	stx_ctime;
> -	const struct statx_timestamp	stx_mtime;
> -	/* 0x80 */
> -	uint32_t	stx_rdev_major;
> -	uint32_t	stx_rdev_minor;
> -	uint32_t	stx_dev_major;
> -	uint32_t	stx_dev_minor;
> -	/* 0x90 */
> -	uint64_t	__spare2[14];
> -	/* 0x100 */
> + #define LTP_DEFINE_STATX_STRUCT(x) \
> + 	struct x { \
> +	uint32_t	stx_mask; \
> +	uint32_t	stx_blksize; \
> +	uint64_t	stx_attributes; \
> +	uint32_t	stx_nlink; \
> +	uint32_t	stx_uid; \
> +	uint32_t	stx_gid; \
> +	uint16_t	stx_mode; \
> +	uint16_t	__spare0[1]; \
> +	uint64_t	stx_ino; \
> +	uint64_t	stx_size; \
> +	uint64_t	stx_blocks; \
> +	uint64_t	stx_attributes_mask; \
> +	const struct statx_timestamp	stx_atime; \
> +	const struct statx_timestamp	stx_btime; \
> +	const struct statx_timestamp	stx_ctime; \
> +	const struct statx_timestamp	stx_mtime; \
> +	uint32_t	stx_rdev_major; \
> +	uint32_t	stx_rdev_minor; \
> +	uint32_t	stx_dev_major; \
> +	uint32_t	stx_dev_minor; \
> +	uint64_t	stx_mnt_id; \
> +	uint32_t	stx_dio_mem_align; \
> +	uint32_t	stx_dio_offset_align; \
> +	uint64_t	__spare3[12]; \
>   };
> +
> +LTP_DEFINE_STATX_STRUCT(statx_fallback);
> +
> +#ifdef HAVE_STRUCT_STATX
> +typedef struct statx ltp_statx_;
> +#else
> +LTP_DEFINE_STATX_STRUCT(statx);
> +
> +typedef struct statx_fallback ltp_statx_;
>   #endif
>   
> +/*
> + * This is the fallback statx that we pass to the safe_statx() syscall.
> + * The reason why we need it, is that statx struct is constantly changing
> + * inside the kernel and we need to extend its definition when structure
> + * changes in order to compile the tests.
> + */
> +struct ltp_statx {
> +	union {
> +		ltp_statx_ buff;
> +		struct statx_fallback data;
> +	};
> +};
> +
>   #ifndef HAVE_STATX
>   
>   /*
> @@ -108,9 +127,9 @@ struct statx {
>    * Returns: It returns status of statx syscall
>    */
>   static inline int statx(int dirfd, const char *pathname, unsigned int flags,
> -			unsigned int mask, struct statx *statxbuf)
> +			unsigned int mask, struct statx *st)
>   {
> -	return tst_syscall(__NR_statx, dirfd, pathname, flags, mask, statxbuf);
> +	return tst_syscall(__NR_statx, dirfd, pathname, flags, mask, st);
>   }
>   #endif
>   
> @@ -229,6 +248,10 @@ static inline int statx(int dirfd, const char *pathname, unsigned int flags,
>   # define STATX_ATTR_VERITY	0x00100000
>   #endif
>   
> +#ifndef STATX_MNT_ID_UNIQUE
> +# define STATX_MNT_ID_UNIQUE  0x00004000U
> +#endif
> +
>   #define SAFE_FCHMODAT2(dfd, filename, mode, flags) \
>   	safe_fchmodat2(__FILE__, __LINE__, (dfd), (filename), (mode), (flags))
>   
> @@ -251,4 +274,28 @@ static inline int safe_fchmodat2(const char *file, const int lineno,
>   	return ret;
>   }
>   
> +#define SAFE_STATX(dirfd, pathname, flags, mask, buf) \
> +	safe_statx(__FILE__, __LINE__, (dirfd), (pathname), (flags), (mask), (buf))
> +
> +static inline int safe_statx(const char *file, const int lineno,
> +	int dirfd, const char *pathname, int flags, unsigned int mask,
> +	struct ltp_statx *buf)
> +{
> +	int rval;
> +
> +	rval = statx(dirfd, pathname, flags, mask, &buf->buff);
> +
> +	if (rval == -1) {
> +		tst_brk_(file, lineno, TBROK | TERRNO,
> +			"statx(%d,%s,%d,%u,%p) failed", dirfd, pathname, flags, mask, buf);
> +	} else if (rval) {
> +		tst_brk_(file, lineno, TBROK | TERRNO,
> +			"Invalid statx(%d,%s,%d,%u,%p) return value %d",
> +			dirfd, pathname, flags, mask, buf,
> +			rval);
> +	}
> +
> +	return rval;
> +}
> +
>   #endif /* LAPI_STAT_H__ */
> diff --git a/testcases/kernel/syscalls/fchmodat2/fchmodat2_01.c b/testcases/kernel/syscalls/fchmodat2/fchmodat2_01.c
> index a9932287c..f026b18df 100644
> --- a/testcases/kernel/syscalls/fchmodat2/fchmodat2_01.c
> +++ b/testcases/kernel/syscalls/fchmodat2/fchmodat2_01.c
> @@ -12,6 +12,8 @@
>    * usage on symlinks will raise EOPNOTSUPP.
>    */
>   
> +#define _GNU_SOURCE
> +
>   #include "tst_test.h"
>   #include "tst_safe_file_at.h"
>   #include "lapi/fcntl.h"
>

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

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [LTP] [PATCH v4 01/13] Add SAFE_STATX macro
  2024-09-09 10:00 ` [LTP] [PATCH v4 01/13] Add SAFE_STATX macro Andrea Cervesato
  2024-09-09 16:21   ` Andrea Cervesato via ltp
@ 2024-10-02 12:27   ` Cyril Hrubis
  2024-10-02 13:00     ` Andrea Cervesato via ltp
  1 sibling, 1 reply; 35+ messages in thread
From: Cyril Hrubis @ 2024-10-02 12:27 UTC (permalink / raw)
  To: Andrea Cervesato; +Cc: ltp

Hi!
> --- a/testcases/kernel/syscalls/fchmodat2/fchmodat2_01.c
> +++ b/testcases/kernel/syscalls/fchmodat2/fchmodat2_01.c
> @@ -12,6 +12,8 @@
>   * usage on symlinks will raise EOPNOTSUPP.
>   */
>  
> +#define _GNU_SOURCE
> +
>  #include "tst_test.h"
>  #include "tst_safe_file_at.h"
>  #include "lapi/fcntl.h"

This looks like it should be in a separate patch as well. At least there
is no description why this is needed in the patch either.

-- 
Cyril Hrubis
chrubis@suse.cz

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

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [LTP] [PATCH v4 02/13] Add listmount/statmount syscalls
  2024-09-09 10:00 ` [LTP] [PATCH v4 02/13] Add listmount/statmount syscalls Andrea Cervesato
@ 2024-10-02 12:30   ` Cyril Hrubis
  0 siblings, 0 replies; 35+ messages in thread
From: Cyril Hrubis @ 2024-10-02 12:30 UTC (permalink / raw)
  To: Andrea Cervesato; +Cc: ltp

Hi!
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>

-- 
Cyril Hrubis
chrubis@suse.cz

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

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [LTP] [PATCH v4 01/13] Add SAFE_STATX macro
  2024-10-02 12:27   ` Cyril Hrubis
@ 2024-10-02 13:00     ` Andrea Cervesato via ltp
  0 siblings, 0 replies; 35+ messages in thread
From: Andrea Cervesato via ltp @ 2024-10-02 13:00 UTC (permalink / raw)
  To: Cyril Hrubis, Andrea Cervesato; +Cc: ltp

Hi!

On 10/2/24 14:27, Cyril Hrubis wrote:
> Hi!
>> --- a/testcases/kernel/syscalls/fchmodat2/fchmodat2_01.c
>> +++ b/testcases/kernel/syscalls/fchmodat2/fchmodat2_01.c
>> @@ -12,6 +12,8 @@
>>    * usage on symlinks will raise EOPNOTSUPP.
>>    */
>>   
>> +#define _GNU_SOURCE
>> +
>>   #include "tst_test.h"
>>   #include "tst_safe_file_at.h"
>>   #include "lapi/fcntl.h"
> This looks like it should be in a separate patch as well. At least there
> is no description why this is needed in the patch either.
>
This is clearly an error. Probably git added a wrong file.

Andrea


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

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [LTP] [PATCH v4 04/13] Add listmount01 test
  2024-09-09 10:00 ` [LTP] [PATCH v4 04/13] Add listmount01 test Andrea Cervesato
@ 2024-10-02 14:05   ` Cyril Hrubis
  2024-10-02 14:14   ` Cyril Hrubis
  1 sibling, 0 replies; 35+ messages in thread
From: Cyril Hrubis @ 2024-10-02 14:05 UTC (permalink / raw)
  To: Andrea Cervesato; +Cc: ltp

Hi!
> This test verifies that listmount() is properly recognizing a mounted
> root directory using LSMT_ROOT flag.
> 
> Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
> ---
>  runtest/syscalls                                  |  2 +
>  testcases/kernel/syscalls/listmount/.gitignore    |  1 +
>  testcases/kernel/syscalls/listmount/Makefile      |  7 +++
>  testcases/kernel/syscalls/listmount/listmount.h   | 26 ++++++++++
>  testcases/kernel/syscalls/listmount/listmount01.c | 63 +++++++++++++++++++++++
>  5 files changed, 99 insertions(+)
> 
> diff --git a/runtest/syscalls b/runtest/syscalls
> index a9fc8c432..48db6259b 100644
> --- a/runtest/syscalls
> +++ b/runtest/syscalls
> @@ -730,6 +730,8 @@ linkat02 linkat02
>  
>  listen01 listen01
>  
> +listmount01 listmount01
> +
>  listxattr01 listxattr01
>  listxattr02 listxattr02
>  listxattr03 listxattr03
> diff --git a/testcases/kernel/syscalls/listmount/.gitignore b/testcases/kernel/syscalls/listmount/.gitignore
> new file mode 100644
> index 000000000..5257b298c
> --- /dev/null
> +++ b/testcases/kernel/syscalls/listmount/.gitignore
> @@ -0,0 +1 @@
> +listmount01
> diff --git a/testcases/kernel/syscalls/listmount/Makefile b/testcases/kernel/syscalls/listmount/Makefile
> new file mode 100644
> index 000000000..8cf1b9024
> --- /dev/null
> +++ b/testcases/kernel/syscalls/listmount/Makefile
> @@ -0,0 +1,7 @@
> +# SPDX-License-Identifier: GPL-2.0-or-later
> +# Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
> +
> +top_srcdir		?= ../../../..
> +
> +include $(top_srcdir)/include/mk/testcases.mk
> +include $(top_srcdir)/include/mk/generic_leaf_target.mk
> diff --git a/testcases/kernel/syscalls/listmount/listmount.h b/testcases/kernel/syscalls/listmount/listmount.h
> new file mode 100644
> index 000000000..93766cd33
> --- /dev/null
> +++ b/testcases/kernel/syscalls/listmount/listmount.h
> @@ -0,0 +1,26 @@
> +/* SPDX-License-Identifier: GPL-2.0-or-later */
> +/*
> + * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
> + */
> +
> +#ifndef LISTMOUNT_H
> +
> +#define _GNU_SOURCE
> +
> +#include "tst_test.h"
> +#include "lapi/mount.h"
> +#include "lapi/syscalls.h"
> +
> +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 = {
> +		.size = MNT_ID_REQ_SIZE_VER0,
> +		.mnt_id = mnt_id,
> +		.param = last_mnt_id,
> +	};
> +
> +	return tst_syscall(__NR_listmount, &req, list, num, flags);
> +}
> +
> +#endif
> diff --git a/testcases/kernel/syscalls/listmount/listmount01.c b/testcases/kernel/syscalls/listmount/listmount01.c
> new file mode 100644
> index 000000000..ab74b776b
> --- /dev/null
> +++ b/testcases/kernel/syscalls/listmount/listmount01.c
> @@ -0,0 +1,63 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
> + */
> +
> +/*\
> + * [Description]
> + *
> + * This test verifies that listmount() is properly recognizing a mounted
> + * root directory using LSMT_ROOT flag.
> + *
> + * [Algorithm]
> + *
> + * - move into a new unshared namespace
> + * - mount() a root inside temporary folder and get its mount ID
> + * - get list of mounted IDs using listmount(LSMT_ROOT, ..)
> + * - verify that the root mount ID is the only mount ID present inside the list
> + */
> +
> +#define _GNU_SOURCE
> +
> +#include "listmount.h"
> +#include "lapi/stat.h"
> +#include "lapi/sched.h"
> +
> +#define MNTPOINT "mntpoint"
> +#define LISTSIZE 32
> +
> +static uint64_t root_id;
> +
> +static void run(void)
> +{
> +	uint64_t list[LISTSIZE];
> +
> +	TST_EXP_POSITIVE(listmount(LSMT_ROOT, 0, list, LISTSIZE, 0));
> +	if (TST_RET == -1)
> +		return;

This is purely cosmetic but this should be if (!TST_PASS).


The rest looks good:

Reviewed-by: Cyril Hrubis <chrubis@suse.cz>

-- 
Cyril Hrubis
chrubis@suse.cz

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

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [LTP] [PATCH v4 03/13] Add listmount/statmount fallback declarations
  2024-09-09 10:00 ` [LTP] [PATCH v4 03/13] Add listmount/statmount fallback declarations Andrea Cervesato
@ 2024-10-02 14:12   ` Cyril Hrubis
  0 siblings, 0 replies; 35+ messages in thread
From: Cyril Hrubis @ 2024-10-02 14:12 UTC (permalink / raw)
  To: Andrea Cervesato; +Cc: ltp

Hi!
> diff --git a/configure.ac b/configure.ac
> index ebbf49e28..3dca7c646 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -114,6 +114,7 @@ AC_CHECK_FUNCS_ONCE([ \
>      io_uring_register \
>      io_uring_enter \
>      kcmp \
> +    listmount \
>      mallinfo \
>      mallinfo2 \
>      mallopt \
> @@ -143,6 +144,7 @@ AC_CHECK_FUNCS_ONCE([ \
>      setns \
>      sigpending \
>      splice \
> +    statmount \
>      statx \
>      stime \
>      sync_file_range \

These two checks shouldn't be here because we do not use them at all and
just define cunstom wrappers later on.

> @@ -246,6 +248,8 @@ AC_CHECK_TYPES([struct mount_attr],,,[
>  
>  AC_CHECK_TYPES([struct cachestat_range],,,[#include <sys/mman.h>])
>  AC_CHECK_TYPES([struct cachestat],,,[#include <sys/mman.h>])
> +AC_CHECK_TYPES([struct mnt_id_req],,,[#include <linux/mount.h>])
> +AC_CHECK_TYPES([struct statmount],,,[#include <linux/mount.h>])
>  
>  # Tools knobs
>  
> diff --git a/include/lapi/mount.h b/include/lapi/mount.h
> index c1af944fe..01a0fd2d6 100644
> --- a/include/lapi/mount.h
> +++ b/include/lapi/mount.h
> @@ -2,12 +2,15 @@
>  /*
>   * Copyright (c) Linux Test Project, 2015-2022
>   * Copyright (c) 2015 Cui Bixuan <cuibixuan@huawei.com>
> + * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
>   */
>  
>  #ifndef LAPI_MOUNT_H__
>  #define LAPI_MOUNT_H__
>  
> +#include <stdint.h>
>  #include <sys/mount.h>
> +#include "config.h"
>  
>  #ifndef MS_REC
>  # define MS_REC 16384
> @@ -37,4 +40,71 @@
>  # define MS_NOSYMFOLLOW 256
>  #endif
>  
> +#ifndef HAVE_STRUCT_MNT_ID_REQ
> +struct mnt_id_req {
> +	uint32_t size;
> +	uint32_t spare;
> +	uint64_t mnt_id;
> +	uint64_t param;
> +};
> +#endif
> +
> +#ifndef HAVE_STRUCT_STATMOUNT
> +struct statmount {
> +	uint32_t size;
> +	uint32_t __spare1;
> +	uint64_t mask;
> +	uint32_t sb_dev_major;
> +	uint32_t sb_dev_minor;
> +	uint64_t sb_magic;
> +	uint32_t sb_flags;
> +	uint32_t fs_type;
> +	uint64_t mnt_id;
> +	uint64_t mnt_parent_id;
> +	uint32_t mnt_id_old;
> +	uint32_t mnt_parent_id_old;
> +	uint64_t mnt_attr;
> +	uint64_t mnt_propagation;
> +	uint64_t mnt_peer_group;
> +	uint64_t mnt_master;
> +	uint64_t propagate_from;
> +	uint32_t mnt_root;
> +	uint32_t mnt_point;
> +	uint64_t __spare2[50];
> +	char str[];
> +};
> +#endif
> +
> +#ifndef MNT_ID_REQ_SIZE_VER0
> +# define MNT_ID_REQ_SIZE_VER0 24
> +#endif
> +
> +#ifndef STATMOUNT_SB_BASIC
> +# define STATMOUNT_SB_BASIC 0x00000001U
> +#endif
> +
> +#ifndef STATMOUNT_MNT_BASIC
> +# define STATMOUNT_MNT_BASIC 0x00000002U
> +#endif
> +
> +#ifndef STATMOUNT_PROPAGATE_FROM
> +# define STATMOUNT_PROPAGATE_FROM 0x00000004U
> +#endif
> +
> +#ifndef STATMOUNT_MNT_ROOT
> +# define STATMOUNT_MNT_ROOT 0x00000008U
> +#endif
> +
> +#ifndef STATMOUNT_MNT_POINT
> +# define STATMOUNT_MNT_POINT 0x00000010U
> +#endif
> +
> +#ifndef STATMOUNT_FS_TYPE
> +# define STATMOUNT_FS_TYPE 0x00000020U
> +#endif
> +
> +#ifndef LSMT_ROOT
> +# define LSMT_ROOT 0xffffffffffffffff
> +#endif
> +
>  #endif /* LAPI_MOUNT_H__ */

The rest looks fine:

Reviewed-by: Cyril Hrubis <chrubis@suse.cz>

-- 
Cyril Hrubis
chrubis@suse.cz

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

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [LTP] [PATCH v4 04/13] Add listmount01 test
  2024-09-09 10:00 ` [LTP] [PATCH v4 04/13] Add listmount01 test Andrea Cervesato
  2024-10-02 14:05   ` Cyril Hrubis
@ 2024-10-02 14:14   ` Cyril Hrubis
  1 sibling, 0 replies; 35+ messages in thread
From: Cyril Hrubis @ 2024-10-02 14:14 UTC (permalink / raw)
  To: Andrea Cervesato; +Cc: ltp

Hi!
> +/* SPDX-License-Identifier: GPL-2.0-or-later */
> +/*
> + * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
> + */
> +
> +#ifndef LISTMOUNT_H

Ah, and #define LISTMOUNT_H is missing here, otherwise the header guards
does not work at all.

> +#define _GNU_SOURCE
> +
> +#include "tst_test.h"
> +#include "lapi/mount.h"
> +#include "lapi/syscalls.h"
> +
> +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 = {
> +		.size = MNT_ID_REQ_SIZE_VER0,
> +		.mnt_id = mnt_id,
> +		.param = last_mnt_id,
> +	};
> +
> +	return tst_syscall(__NR_listmount, &req, list, num, flags);
> +}
> +
> +#endif

-- 
Cyril Hrubis
chrubis@suse.cz

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

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [LTP] [PATCH v4 05/13] Add listmount02 test
  2024-09-09 10:00 ` [LTP] [PATCH v4 05/13] Add listmount02 test Andrea Cervesato
@ 2024-10-02 14:37   ` Cyril Hrubis
  0 siblings, 0 replies; 35+ messages in thread
From: Cyril Hrubis @ 2024-10-02 14:37 UTC (permalink / raw)
  To: Andrea Cervesato; +Cc: ltp

Hi!
> +static void run(void)
> +{
> +	ssize_t ret;
> +	size_t id, tot_ids, count = 0;
> +	uint64_t mount_ids[LISTSIZE];
> +	uint64_t list[LISTSIZE];
> +
> +	for (int i = 0; i < BIND_MOUNTS; i++)
> +		SAFE_MOUNT("/", "/", NULL, MS_BIND, NULL);
> +
> +	tst_res(TINFO, "Reading all %d mount IDs in once", LISTSIZE);
> +
> +	TST_EXP_POSITIVE(listmount(LSMT_ROOT, 0, mount_ids, LISTSIZE, 0));
> +	if (TST_RET == -1)
> +		goto end;

Again this should be if (!TST_PASS)


Otherwise:

Reviewed-by: Cyril Hrubis <chrubis@suse.cz>

-- 
Cyril Hrubis
chrubis@suse.cz

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

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [LTP] [PATCH v4 06/13] Add statmount01 test
  2024-09-09 10:00 ` [LTP] [PATCH v4 06/13] Add statmount01 test Andrea Cervesato
@ 2024-10-02 14:45   ` Cyril Hrubis
  0 siblings, 0 replies; 35+ messages in thread
From: Cyril Hrubis @ 2024-10-02 14:45 UTC (permalink / raw)
  To: Andrea Cervesato; +Cc: ltp

Hi!
> +/* SPDX-License-Identifier: GPL-2.0-or-later */
> +/*
> + * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
> + */
> +
> +#ifndef STATMOUNT_H

Here as well, missing #define STATMOUNT_H

> +#define _GNU_SOURCE
> +
> +#include "tst_test.h"
> +#include "lapi/mount.h"
> +#include "lapi/syscalls.h"
> +
> +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 = {
> +		.size = MNT_ID_REQ_SIZE_VER0,
> +		.mnt_id = mnt_id,
> +		.param = mask,
> +	};
> +
> +	return tst_syscall(__NR_statmount, &req, buf, bufsize, flags);
> +}
> +
> +#endif
> diff --git a/testcases/kernel/syscalls/statmount/statmount01.c b/testcases/kernel/syscalls/statmount/statmount01.c
> new file mode 100644
> index 000000000..95dac5c92
> --- /dev/null
> +++ b/testcases/kernel/syscalls/statmount/statmount01.c
> @@ -0,0 +1,82 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
> + */
> +
> +/*\
> + * [Description]
> + *
> + * This test verifies that statmount() is working with no mask flags.
> + *
> + * [Algorithm]
> + *
> + * - create a mount point
> + * - run statmount() on the mount point without giving any mask
> + * - read results and check that mask and size are correct
> + */
> +
> +#define _GNU_SOURCE
> +
> +#include "statmount.h"
> +#include "lapi/stat.h"
> +#include "lapi/sched.h"
> +
> +#define MNTPOINT "mntpoint"
> +
> +static uint64_t root_id;
> +static struct statmount *st_mount;
> +
> +static void run(void)
> +{
> +	memset(st_mount, 0, sizeof(struct statmount));
> +
> +	TST_EXP_PASS(statmount(root_id, 0, st_mount, sizeof(struct statmount), 0));
> +
> +	if (TST_RET == -1)
> +		return;

Here if (!TST_PASS) as well.

> +	TST_EXP_EQ_LI(st_mount->size, sizeof(struct statmount));
> +	TST_EXP_EQ_LI(st_mount->mask, 0);
> +	TST_EXP_EQ_LI(st_mount->sb_dev_major, 0);
> +	TST_EXP_EQ_LI(st_mount->sb_dev_minor, 0);
> +	TST_EXP_EQ_LI(st_mount->sb_magic, 0);
> +	TST_EXP_EQ_LI(st_mount->sb_flags, 0);
> +	TST_EXP_EQ_LI(st_mount->fs_type, 0);
> +	TST_EXP_EQ_LI(st_mount->mnt_id, 0);
> +	TST_EXP_EQ_LI(st_mount->mnt_parent_id, 0);
> +	TST_EXP_EQ_LI(st_mount->mnt_id_old, 0);
> +	TST_EXP_EQ_LI(st_mount->mnt_parent_id_old, 0);
> +	TST_EXP_EQ_LI(st_mount->mnt_attr, 0);
> +	TST_EXP_EQ_LI(st_mount->mnt_propagation, 0);
> +	TST_EXP_EQ_LI(st_mount->mnt_peer_group, 0);
> +	TST_EXP_EQ_LI(st_mount->mnt_master, 0);
> +	TST_EXP_EQ_LI(st_mount->propagate_from, 0);
> +	TST_EXP_EQ_LI(st_mount->mnt_root, 0);
> +	TST_EXP_EQ_LI(st_mount->mnt_point, 0);
> +}
> +
> +static void setup(void)
> +{
> +	struct ltp_statx sx;
> +
> +	SAFE_STATX(AT_FDCWD, MNTPOINT, 0, STATX_MNT_ID_UNIQUE, &sx);
> +
> +	root_id = sx.data.stx_mnt_id;

Maybe this should be called mntpoint_id to make it less confusing.

> +}
> +
> +static struct tst_test test = {
> +	.test_all = run,
> +	.setup = setup,
> +	.min_kver = "6.8",
> +	.mount_device = 1,
> +	.mntpoint = MNTPOINT,
> +	.all_filesystems = 1,
> +	.skip_filesystems = (const char *const []) {
> +		"fuse",
> +		NULL
> +	},

I'm not sure that it makes sense to run this test for all filesystems,
it's just at test that the returned buffer is untouched/cleared if we do
not request any information. I bet that it does not call any filesystem
specific code at all.

> +	.bufs = (struct tst_buffers []) {
> +		{&st_mount, .size = sizeof(struct statmount)},
> +		{}
> +	}
> +};

-- 
Cyril Hrubis
chrubis@suse.cz

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

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [LTP] [PATCH v4 07/13] Add statmount02 test
  2024-09-09 10:00 ` [LTP] [PATCH v4 07/13] Add statmount02 test Andrea Cervesato
@ 2024-10-02 15:15   ` Cyril Hrubis
  0 siblings, 0 replies; 35+ messages in thread
From: Cyril Hrubis @ 2024-10-02 15:15 UTC (permalink / raw)
  To: Andrea Cervesato; +Cc: ltp

Hi!
> +static void run(void)
> +{
> +	memset(st_mount, 0, sizeof(struct statmount));
> +
> +	TST_EXP_PASS(statmount(sx_mount->data.stx_mnt_id, STATMOUNT_SB_BASIC,
> +		st_mount, sizeof(struct statmount), 0));
> +
> +	if (TST_RET == -1)
> +		return;

Same here if (!TST_PASS)


The rest looks good:

Reviewed-by: Cyril Hrubis <chrubis@suse.cz>

-- 
Cyril Hrubis
chrubis@suse.cz

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

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [LTP] [PATCH v4 08/13] Add statmount03 test
  2024-09-09 10:00 ` [LTP] [PATCH v4 08/13] Add statmount03 test Andrea Cervesato
@ 2024-10-03 13:27   ` Cyril Hrubis
  0 siblings, 0 replies; 35+ messages in thread
From: Cyril Hrubis @ 2024-10-03 13:27 UTC (permalink / raw)
  To: Andrea Cervesato; +Cc: ltp

Hi!
> This test verifies that statmount() is correctly reading mount
> information (mount id, parent mount id, mount attributes etc.)
> using STATMOUNT_MNT_BASIC.
> 
> Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
> ---
>  runtest/syscalls                                  |   1 +
>  testcases/kernel/syscalls/statmount/.gitignore    |   1 +
>  testcases/kernel/syscalls/statmount/statmount.h   |  24 ++++
>  testcases/kernel/syscalls/statmount/statmount03.c | 137 ++++++++++++++++++++++
>  4 files changed, 163 insertions(+)
> 
> diff --git a/runtest/syscalls b/runtest/syscalls
> index e028baf19..ec11a3a21 100644
> --- a/runtest/syscalls
> +++ b/runtest/syscalls
> @@ -1570,6 +1570,7 @@ stat04_64 stat04_64
>  
>  statmount01 statmount01
>  statmount02 statmount02
> +statmount03 statmount03
>  
>  statfs01 statfs01
>  statfs01_64 statfs01_64
> diff --git a/testcases/kernel/syscalls/statmount/.gitignore b/testcases/kernel/syscalls/statmount/.gitignore
> index a30b9565f..2a02bf721 100644
> --- a/testcases/kernel/syscalls/statmount/.gitignore
> +++ b/testcases/kernel/syscalls/statmount/.gitignore
> @@ -1,2 +1,3 @@
>  statmount01
>  statmount02
> +statmount03
> diff --git a/testcases/kernel/syscalls/statmount/statmount.h b/testcases/kernel/syscalls/statmount/statmount.h
> index e807c8288..5cd54242c 100644
> --- a/testcases/kernel/syscalls/statmount/statmount.h
> +++ b/testcases/kernel/syscalls/statmount/statmount.h
> @@ -10,6 +10,7 @@
>  #include "tst_test.h"
>  #include "lapi/mount.h"
>  #include "lapi/syscalls.h"
> +#include "tst_safe_stdio.h"
>  
>  static inline int statmount(uint64_t mnt_id, uint64_t mask, struct statmount *buf,
>  		     size_t bufsize, unsigned int flags)
> @@ -23,4 +24,27 @@ static inline int statmount(uint64_t mnt_id, uint64_t mask, struct statmount *bu
>  	return tst_syscall(__NR_statmount, &req, buf, bufsize, flags);
>  }
>  
> +static inline int read_peer_group(const char *path)
> +{
> +	FILE *file;
> +	char line[PATH_MAX];
> +	char mroot[PATH_MAX];
> +	int group = -1;
> +
> +	file = SAFE_FOPEN("/proc/self/mountinfo", "r");
> +
> +	while (fgets(line, sizeof(line), file)) {
> +		if (sscanf(line, "%*d %*d %*d:%*d %s %*s %*s shared:%d", mroot, &group) != 2)
> +			continue;
> +
> +		if (strcmp(mroot, path) == 0)
> +			break;
> +	}
> +
> +	if (group == -1)
> +		tst_brk(TBROK, "Can't reed peer group ID for %s", path);
> +
> +	return group;
> +}
> +
>  #endif
> diff --git a/testcases/kernel/syscalls/statmount/statmount03.c b/testcases/kernel/syscalls/statmount/statmount03.c
> new file mode 100644
> index 000000000..634c4b447
> --- /dev/null
> +++ b/testcases/kernel/syscalls/statmount/statmount03.c
> @@ -0,0 +1,137 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
> + */
> +
> +/*\
> + * [Description]
> + *
> + * This test verifies that statmount() is correctly reading mount information
> + * (mount id, parent mount id, mount attributes etc.) using STATMOUNT_MNT_BASIC.
> + *
> + * [Algorithm]
> + *
> + * - create a mount point
> + * - create a new parent folder inside the mount point and obtain its mount info
> + * - create the new "/" mount folder and obtain its mount info
> + * - run statmount() on the mount point using STATMOUNT_MNT_BASIC
> + * - read results and check if mount info are correct
> + */
> +
> +#define _GNU_SOURCE
> +
> +#include "statmount.h"
> +#include "lapi/stat.h"
> +#include "lapi/sched.h"
> +
> +#define DIR_A "LTP_DIR_A"
> +#define DIR_B "LTP_DIR_B"
> +
> +static uint64_t mnt_id;
> +static uint64_t mnt_id_old;
> +static uint64_t parent_id;
> +static uint64_t parent_id_old;
> +static uint64_t mnt_peer_group;
> +static uint64_t mnt_master;
> +static struct statmount *st_mount;
> +
> +static void read_mnt_id(
> +	const char *path,
> +	uint64_t *mnt_id,
> +	uint64_t *mnt_id_unique)
> +{
> +	struct ltp_statx sx;
> +
> +	if (mnt_id) {
> +		SAFE_STATX(AT_FDCWD, path, 0, STATX_MNT_ID, &sx);
> +		*mnt_id = sx.data.stx_mnt_id;
> +	}
> +
> +	if (mnt_id_unique) {
> +		SAFE_STATX(AT_FDCWD, path, 0, STATX_MNT_ID_UNIQUE, &sx);
> +		*mnt_id_unique = sx.data.stx_mnt_id;
> +	}

Technically the stx_mnt_id is only valid if the sx.data.stx_mask has the
STATX_MNT_ID or STATX_MNT_ID_UNIQUE set when statx() returns.

We have min_kver set to 6.8 so this should always work, but it wouldn't
hurt to double check.

> +}
> +
> +static struct tcase {
> +	uint64_t prop_type;
> +	char *msg;
> +} tcases[] = {
> +	{ MS_PRIVATE, TST_TO_STR_(MS_PRIVATE) },
> +	{ MS_SHARED, TST_TO_STR_(MS_SHARED) },
> +	{ MS_SLAVE, TST_TO_STR_(MS_SLAVE) },
> +	{ MS_UNBINDABLE, TST_TO_STR_(MS_UNBINDABLE) },
> +};
> +
> +static void run(unsigned int i)
> +{
> +	struct tcase *tc = &tcases[i];
> +
> +	tst_res(TINFO,  "Testing statmount() on %s", tc->msg);
> +
> +	SAFE_MOUNT(DIR_B, DIR_A, "none", MS_BIND, NULL);
> +	SAFE_MOUNT("none", DIR_A, "none", tc->prop_type, NULL);
> +	read_mnt_id(DIR_A, &mnt_id_old, &mnt_id);
> +
> +	memset(st_mount, 0, sizeof(struct statmount));
> +
> +	TST_EXP_PASS(statmount(mnt_id, STATMOUNT_MNT_BASIC, st_mount,
> +		sizeof(struct statmount), 0));
> +
> +	SAFE_UMOUNT(DIR_A);
> +
> +	if (TST_RET == -1)
> +		return;

Here as well if (!TST_PASS)

> +	/* s->sm.mnt_peer_group = IS_MNT_SHARED(m) ? m->mnt_group_id : 0;
> +	 * s->sm.mnt_master = IS_MNT_SLAVE(m) ? m->mnt_master->mnt_group_id : 0;
> +	 */

This comment looks like a leftover.

> +	mnt_peer_group = tc->prop_type == MS_SHARED ? read_peer_group(DIR_A) : 0;
> +	mnt_master = tc->prop_type == MS_SLAVE ? read_peer_group(DIR_A) : 0;
> +
> +	TST_EXP_EQ_LI(st_mount->mask, STATMOUNT_MNT_BASIC);
> +	TST_EXP_EQ_LI(st_mount->size, sizeof(struct statmount));
> +	TST_EXP_EQ_LI(st_mount->mnt_id, mnt_id);
> +	TST_EXP_EQ_LI(st_mount->mnt_id_old, mnt_id_old);
> +	TST_EXP_EQ_LI(st_mount->mnt_parent_id, parent_id);
> +	TST_EXP_EQ_LI(st_mount->mnt_parent_id_old, parent_id_old);
> +	TST_EXP_EQ_LU(st_mount->mnt_propagation & tc->prop_type, tc->prop_type);
> +	TST_EXP_EQ_LI(st_mount->mnt_master, mnt_master);
> +	TST_EXP_EQ_LI(st_mount->mnt_peer_group, mnt_peer_group);
> +}

Otherwise it looks good:

Reviewed-by: Cyril Hrubis <chrubis@suse.cz>

-- 
Cyril Hrubis
chrubis@suse.cz

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

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [LTP] [PATCH v4 09/13] Add statmount04 test
  2024-09-09 10:00 ` [LTP] [PATCH v4 09/13] Add statmount04 test Andrea Cervesato
@ 2024-10-03 13:51   ` Cyril Hrubis
  0 siblings, 0 replies; 35+ messages in thread
From: Cyril Hrubis @ 2024-10-03 13:51 UTC (permalink / raw)
  To: Andrea Cervesato; +Cc: ltp

Hi!
> +/*\
> + * [Description]
> + *
> + * This test verifies that statmount() is correctly reading propagation from
> + * what mount in current namespace using STATMOUNT_PROPAGATE_FROM.
> + *
> + * [Algorithm]
> + *
> + * - create a mount point
> + * - propagate a mounted folder inside the mount point
> + * - run statmount() on the mount point using STATMOUNT_PROPAGATE_FROM
> + * - read results and check propagated_from parameter contains the propagated
> + *   folder ID
> + */
> +
> +#define _GNU_SOURCE
> +
> +#include "statmount.h"
> +#include "lapi/stat.h"
> +#include "lapi/sched.h"
> +
> +#define MNTPOINT "mntpoint"
> +#define DIR_A MNTPOINT "/LTP_DIR_A"
> +#define DIR_C_SUBFOLDER "/LTP_DIR_A/propagated"
> +#define DIR_C (MNTPOINT DIR_C_SUBFOLDER)
> +#define DIR_B MNTPOINT "/LTP_DIR_B"
> +#define DIR_D MNTPOINT "/LTP_DIR_B/propagated"
> +
> +static uint64_t peer_group_id;
> +static uint64_t dird_id;
> +static struct statmount *st_mount;
> +
> +static void run(void)
> +{
> +	memset(st_mount, 0, sizeof(struct statmount));
> +
> +	TST_EXP_PASS(statmount(dird_id, STATMOUNT_PROPAGATE_FROM, st_mount,
> +		sizeof(struct statmount), 0));
> +
> +	if (TST_RET == -1)
> +		return;

Again if (!TST_PASS)

> +	TST_EXP_EQ_LI(st_mount->mask, STATMOUNT_PROPAGATE_FROM);
> +	TST_EXP_EQ_LI(st_mount->size, sizeof(struct statmount));
> +	TST_EXP_EQ_LI(st_mount->propagate_from, peer_group_id);
> +}
> +
> +static void setup(void)
> +{
> +	struct ltp_statx sx;
> +
> +	/* create DIR_A / DIR_C structure with DIR_C mounted */
> +	SAFE_MKDIR(DIR_A, 0700);
> +	SAFE_MOUNT(DIR_A, DIR_A, "none", MS_BIND, NULL);
> +	SAFE_MOUNT("none", DIR_A, "none", MS_SHARED, NULL);
> +
> +	SAFE_MKDIR(DIR_C, 0700);
> +	SAFE_MOUNT(DIR_C, DIR_C, "none", MS_BIND, NULL);
> +	SAFE_MOUNT("none", DIR_C, "none", MS_SHARED, NULL);
> +
> +	/* DIR_A mounts into DIR_B. DIR_D is propagated */
> +	SAFE_MKDIR(DIR_B, 0700);
> +	SAFE_MOUNT(DIR_A, DIR_B, "none", MS_BIND, NULL);
> +	SAFE_MOUNT("none", DIR_B, "none", MS_SLAVE, NULL);
> +
> +	SAFE_STATX(AT_FDCWD, DIR_D, 0, STATX_MNT_ID_UNIQUE, &sx);
> +	dird_id = sx.data.stx_mnt_id;
> +
> +	peer_group_id = read_peer_group(DIR_A);
> +}
> +
> +static void cleanup(void)
> +{
> +	if (tst_is_mounted(DIR_C))
> +		SAFE_UMOUNT(DIR_C);
> +
> +	if (tst_is_mounted(DIR_B))
> +		SAFE_UMOUNT(DIR_B);
> +
> +	if (tst_is_mounted(DIR_A))
> +		SAFE_UMOUNT(DIR_A);
> +}
> +
> +static struct tst_test test = {
> +	.test_all = run,
> +	.setup = setup,
> +	.cleanup = cleanup,
> +	.min_kver = "6.8",
> +	.mount_device = 1,
> +	.mntpoint = MNTPOINT,
> +	.all_filesystems = 1,
> +	.skip_filesystems = (const char *const []) {
> +		"fuse",
> +		NULL
> +	},
> +	.bufs = (struct tst_buffers []) {
> +		{&st_mount, .size = sizeof(struct statmount)},
> +		{}
> +	}
> +};


Otherwise:

Reviewed-by: Cyril Hrubis <chrubis@suse.cz>

-- 
Cyril Hrubis
chrubis@suse.cz

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

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [LTP] [PATCH v4 10/13] Add statmount05 test
  2024-09-09 10:00 ` [LTP] [PATCH v4 10/13] Add statmount05 test Andrea Cervesato
@ 2024-10-03 14:09   ` Cyril Hrubis
  0 siblings, 0 replies; 35+ messages in thread
From: Cyril Hrubis @ 2024-10-03 14:09 UTC (permalink / raw)
  To: Andrea Cervesato; +Cc: ltp

Hi!
> This test verifies STATMOUNT_MNT_ROOT and STATMOUNT_MNT_POINT
> functionalities of statmount().
> 
> Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
> ---
>  runtest/syscalls                                  |   1 +
>  testcases/kernel/syscalls/statmount/.gitignore    |   1 +
>  testcases/kernel/syscalls/statmount/statmount05.c | 128 ++++++++++++++++++++++
>  3 files changed, 130 insertions(+)
> 
> diff --git a/runtest/syscalls b/runtest/syscalls
> index e43e53002..9f5a473f3 100644
> --- a/runtest/syscalls
> +++ b/runtest/syscalls
> @@ -1572,6 +1572,7 @@ statmount01 statmount01
>  statmount02 statmount02
>  statmount03 statmount03
>  statmount04 statmount04
> +statmount05 statmount05
>  
>  statfs01 statfs01
>  statfs01_64 statfs01_64
> diff --git a/testcases/kernel/syscalls/statmount/.gitignore b/testcases/kernel/syscalls/statmount/.gitignore
> index e720050b5..f64763242 100644
> --- a/testcases/kernel/syscalls/statmount/.gitignore
> +++ b/testcases/kernel/syscalls/statmount/.gitignore
> @@ -2,3 +2,4 @@ statmount01
>  statmount02
>  statmount03
>  statmount04
> +statmount05
> diff --git a/testcases/kernel/syscalls/statmount/statmount05.c b/testcases/kernel/syscalls/statmount/statmount05.c
> new file mode 100644
> index 000000000..dd4bb17f0
> --- /dev/null
> +++ b/testcases/kernel/syscalls/statmount/statmount05.c
> @@ -0,0 +1,128 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
> + */
> +
> +/*\
> + * [Description]
> + *
> + * This test verifies STATMOUNT_MNT_ROOT and STATMOUNT_MNT_POINT functionalities
> + * of statmount(). In particular, STATMOUNT_MNT_ROOT will give the mount root
> + * (i.e. mount --bind /mnt /bla -> /mnt) and STATMOUNT_MNT_POINT will
> + * give the mount point (i.e. mount --bind /mnt /bla -> /bla).
> + *
> + * [Algorithm]
> + *
> + * - create a mount point
> + * - mount a folder inside the mount point
> + * - run statmount() on the mounted folder using STATMOUNT_MNT_ROOT
> + * - read results and check if contain the mount root path
> + * - run statmount() on the mounted folder using STATMOUNT_MNT_POINT
> + * - read results and check if contain the mount point path
> + */
> +
> +#define _GNU_SOURCE
> +
> +#include "statmount.h"
> +#include "lapi/stat.h"
> +#include "lapi/sched.h"
> +#include "tst_tmpdir.h"
> +
> +#define MNTPOINT "mntpoint"
> +#define DIRA MNTPOINT "/LTP_DIR_A"
> +#define DIRB MNTPOINT "/LTP_DIR_B"
> +#define SM_SIZE (1 << 10)
> +
> +static uint64_t root_id;
> +static struct statmount *st_mount;
> +static char *mnt_root;
> +static char *mnt_point;
> +
> +static void test_mount_root(void)
> +{
> +	tst_res(TINFO, "Testing STATMOUNT_MNT_ROOT");
> +
> +	char *last_root;
> +
> +	memset(st_mount, 0, SM_SIZE);
> +
> +	TST_EXP_PASS(statmount(root_id, STATMOUNT_MNT_ROOT, st_mount,
> +		SM_SIZE, 0));
> +
> +	if (TST_RET == -1)
> +		return;

if (!TST_PASSED)

> +	last_root = strrchr(mnt_root, '/');
> +
> +	TST_EXP_EQ_LI(st_mount->mask, STATMOUNT_MNT_ROOT);
> +	TST_EXP_EXPR(strcmp(st_mount->str + st_mount->mnt_root, last_root) == 0,
> +		"statmount() read '%s', expected '%s'",
> +		st_mount->str + st_mount->mnt_root,
> +		last_root);

You have added TST_EXP_EQ_STR() in an subsequent patch, you should use
it here as well.

> +}
> +
> +static void test_mount_point(void)
> +{
> +	tst_res(TINFO, "Testing STATMOUNT_MNT_POINT");
> +
> +	memset(st_mount, 0, SM_SIZE);
> +
> +	TST_EXP_POSITIVE(statmount(root_id, STATMOUNT_MNT_POINT, st_mount,
> +		SM_SIZE, 0));
> +
> +	if (TST_RET == -1)
> +		return;

Here as well.

> +	TST_EXP_EQ_LI(st_mount->mask, STATMOUNT_MNT_POINT);
> +	TST_EXP_EXPR(strcmp(st_mount->str + st_mount->mnt_point, mnt_point) == 0,
> +		"mount point is '%s'",
> +		st_mount->str + st_mount->mnt_point);

And here as well.

> +}
> +
> +static void run(void)
> +{
> +	test_mount_root();
> +	test_mount_point();
> +}
> +
> +static void setup(void)
> +{
> +	struct ltp_statx sx;
> +
> +	mnt_root = tst_tmpdir_mkpath(DIRA);
> +	mnt_point = tst_tmpdir_mkpath(DIRB);

This was renamed to tst_tmpdir_genpath()

> +	SAFE_MKDIR(mnt_root, 0700);
> +	SAFE_MKDIR(mnt_point, 0700);
> +	SAFE_MOUNT(mnt_root, mnt_point, "none", MS_BIND, NULL);
> +
> +	SAFE_STATX(AT_FDCWD, mnt_point, 0, STATX_MNT_ID_UNIQUE, &sx);
> +	root_id = sx.data.stx_mnt_id;
> +}
> +
> +static void cleanup(void)
> +{
> +	if (tst_is_mounted(DIRB))
> +		SAFE_UMOUNT(DIRB);
> +
> +	if (tst_is_mounted(DIRA))
> +		SAFE_UMOUNT(DIRA);
> +}
> +
> +static struct tst_test test = {
> +	.test_all = run,
> +	.setup = setup,
> +	.cleanup = cleanup,
> +	.min_kver = "6.8",
> +	.mount_device = 1,
> +	.mntpoint = MNTPOINT,
> +	.all_filesystems = 1,
> +	.skip_filesystems = (const char *const []) {
> +		"fuse",
> +		NULL
> +	},
> +	.bufs = (struct tst_buffers []) {
> +		{&st_mount, .size = SM_SIZE},
> +		{}
> +	}
> +};

-- 
Cyril Hrubis
chrubis@suse.cz

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

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [LTP] [PATCH v4 11/13] Add TST_EXP_EQ_STR macro
  2024-09-09 10:00 ` [LTP] [PATCH v4 11/13] Add TST_EXP_EQ_STR macro Andrea Cervesato
@ 2024-10-03 14:13   ` Cyril Hrubis
  0 siblings, 0 replies; 35+ messages in thread
From: Cyril Hrubis @ 2024-10-03 14:13 UTC (permalink / raw)
  To: Andrea Cervesato; +Cc: ltp

Hi!
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>

-- 
Cyril Hrubis
chrubis@suse.cz

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

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [LTP] [PATCH v4 12/13] Add statmount06 test
  2024-09-09 10:00 ` [LTP] [PATCH v4 12/13] Add statmount06 test Andrea Cervesato
@ 2024-10-03 14:20   ` Cyril Hrubis
  0 siblings, 0 replies; 35+ messages in thread
From: Cyril Hrubis @ 2024-10-03 14:20 UTC (permalink / raw)
  To: Andrea Cervesato; +Cc: ltp

Hi!
> +	if (TST_RET == -1)
> +		return;

if (!TST_PASS)

Otherwise:

Reviewed-by: Cyril Hrubis <chrubis@suse.cz>

-- 
Cyril Hrubis
chrubis@suse.cz

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

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [LTP] [PATCH v4 13/13] Add statmount07 test
  2024-09-09 10:00 ` [LTP] [PATCH v4 13/13] Add statmount07 test Andrea Cervesato
@ 2024-10-03 14:34   ` Cyril Hrubis
  2024-10-04  8:19     ` Andrea Cervesato via ltp
  0 siblings, 1 reply; 35+ messages in thread
From: Cyril Hrubis @ 2024-10-03 14:34 UTC (permalink / raw)
  To: Andrea Cervesato; +Cc: ltp

Hi!
> +static struct statmount *st_mount;
> +static struct statmount *st_mount_null;
> +static uint64_t mnt_id;
> +static uint64_t mnt_id_dont_exist = -1;
> +static size_t buff_size;
> +static size_t buff_size_invalid = -1;

I suppose that we can as well add buff_size_zero, I would expected
getting EINVAL from such test.

Otherwise:

Reviewed-by: Cyril Hrubis <chrubis@suse.cz>

-- 
Cyril Hrubis
chrubis@suse.cz

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

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [LTP] [PATCH v4 00/13] statmount/listmount testing suites
  2024-09-09 10:00 [LTP] [PATCH v4 00/13] statmount/listmount testing suites Andrea Cervesato
                   ` (12 preceding siblings ...)
  2024-09-09 10:00 ` [LTP] [PATCH v4 13/13] Add statmount07 test Andrea Cervesato
@ 2024-10-03 14:42 ` Cyril Hrubis
  13 siblings, 0 replies; 35+ messages in thread
From: Cyril Hrubis @ 2024-10-03 14:42 UTC (permalink / raw)
  To: Andrea Cervesato; +Cc: ltp

Hi!
And we still need an invalid parameters for listmount() test I suppose.

I suppose that we can at least pass invalid size, flags and invalid
mnt_id and invalid param.

Also we should add a check for EPERM with LISTMOUNT_UNREACHABLE and
unpriviledged user.

See errors at:
https://lore.kernel.org/linux-man/cover.1719840964.git.josef@toxicpanda.com/T/#m0eba3ca21ebf29bd5a5cfe681fc4cb2b9aa7f6e7

-- 
Cyril Hrubis
chrubis@suse.cz

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

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [LTP] [PATCH v4 13/13] Add statmount07 test
  2024-10-03 14:34   ` Cyril Hrubis
@ 2024-10-04  8:19     ` Andrea Cervesato via ltp
  2024-10-04  9:17       ` Cyril Hrubis
  0 siblings, 1 reply; 35+ messages in thread
From: Andrea Cervesato via ltp @ 2024-10-04  8:19 UTC (permalink / raw)
  To: Cyril Hrubis, Andrea Cervesato; +Cc: ltp

Hi!

On 10/3/24 16:34, Cyril Hrubis wrote:
> Hi!
>> +static struct statmount *st_mount;
>> +static struct statmount *st_mount_null;
>> +static uint64_t mnt_id;
>> +static uint64_t mnt_id_dont_exist = -1;
>> +static size_t buff_size;
>> +static size_t buff_size_invalid = -1;
> I suppose that we can as well add buff_size_zero, I would expected
> getting EINVAL from such test.
That seems to be a valid value, since I get PASS. Kernel bug?
> Otherwise:
>
> Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
>
Andrea

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

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [LTP] [PATCH v4 13/13] Add statmount07 test
  2024-10-04  8:19     ` Andrea Cervesato via ltp
@ 2024-10-04  9:17       ` Cyril Hrubis
  2024-10-04 11:03         ` Andrea Cervesato via ltp
  2024-10-04 12:02         ` Jan Kara
  0 siblings, 2 replies; 35+ messages in thread
From: Cyril Hrubis @ 2024-10-04  9:17 UTC (permalink / raw)
  To: Andrea Cervesato; +Cc: Jan Kara, ltp

Hi!
> That seems to be a valid value, since I get PASS. Kernel bug?

Looking at kernel it's a bit confusing, the bufsize is supposed to be
the size of the structure plus the buffer allocated for the string
reply. Which makes the code more complicated than it could have been if
these two were separeted properly.


However we do have:

       if (kbufsize >= s->bufsize)
                return -EOVERFLOW;

in statmount_string(), so we will trigger the error there if we pass one
of the requests that is supposed to produce a string reply.


But there seems to be something strange going on in the
prepare_kstatmount() as well, we do have:

        if (ks->mask & STATMOUNT_STRING_REQ) {
                if (bufsize == sizeof(ks->sm))
                        return -EOVERFLOW;

		^ This line should probably be if (bufsize <= sizeof(ks->sm))
                  because we are trying to make sure that the structure is large
		  enough that we can write at the offset where the
		  string area starts.

		  It seems to be guarded by the checks in
		  statmount_string() later on as well, so I suppose that we
		  will trigger the EOVERFLOW slightly later if this does not
		  work though. CCying Jan to have a look.

                ks->seq.buf = kvmalloc(seq_size, GFP_KERNEL_ACCOUNT);
                if (!ks->seq.buf)
                        return -ENOMEM;

                ks->seq.size = seq_size;
        }




However the size seems to be properly used in the
copy_statmount_to_user()

        size_t copysize = min_t(size_t, s->bufsize, sizeof(*sm));

	...

	if (copy_to_user(s->buf, sm, copysize))
                return -EFAULT;


This means that we will copy as much of the statmount structure to
userspace as we requested, so in the case that we pass 0 as bufsize none
of the data should be copied and indeed we should get back success.

-- 
Cyril Hrubis
chrubis@suse.cz

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

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [LTP] [PATCH v4 13/13] Add statmount07 test
  2024-10-04  9:17       ` Cyril Hrubis
@ 2024-10-04 11:03         ` Andrea Cervesato via ltp
  2024-10-04 12:02         ` Jan Kara
  1 sibling, 0 replies; 35+ messages in thread
From: Andrea Cervesato via ltp @ 2024-10-04 11:03 UTC (permalink / raw)
  To: Cyril Hrubis; +Cc: Jan Kara, ltp

Thanks for the explanation! I will fix the other patches and send the 
new version.

Andrea

On 10/4/24 11:17, Cyril Hrubis wrote:
> Hi!
>> That seems to be a valid value, since I get PASS. Kernel bug?
> Looking at kernel it's a bit confusing, the bufsize is supposed to be
> the size of the structure plus the buffer allocated for the string
> reply. Which makes the code more complicated than it could have been if
> these two were separeted properly.
>
>
> However we do have:
>
>         if (kbufsize >= s->bufsize)
>                  return -EOVERFLOW;
>
> in statmount_string(), so we will trigger the error there if we pass one
> of the requests that is supposed to produce a string reply.
>
>
> But there seems to be something strange going on in the
> prepare_kstatmount() as well, we do have:
>
>          if (ks->mask & STATMOUNT_STRING_REQ) {
>                  if (bufsize == sizeof(ks->sm))
>                          return -EOVERFLOW;
>
> 		^ This line should probably be if (bufsize <= sizeof(ks->sm))
>                    because we are trying to make sure that the structure is large
> 		  enough that we can write at the offset where the
> 		  string area starts.
>
> 		  It seems to be guarded by the checks in
> 		  statmount_string() later on as well, so I suppose that we
> 		  will trigger the EOVERFLOW slightly later if this does not
> 		  work though. CCying Jan to have a look.
>
>                  ks->seq.buf = kvmalloc(seq_size, GFP_KERNEL_ACCOUNT);
>                  if (!ks->seq.buf)
>                          return -ENOMEM;
>
>                  ks->seq.size = seq_size;
>          }
>
>
>
>
> However the size seems to be properly used in the
> copy_statmount_to_user()
>
>          size_t copysize = min_t(size_t, s->bufsize, sizeof(*sm));
>
> 	...
>
> 	if (copy_to_user(s->buf, sm, copysize))
>                  return -EFAULT;
>
>
> This means that we will copy as much of the statmount structure to
> userspace as we requested, so in the case that we pass 0 as bufsize none
> of the data should be copied and indeed we should get back success.
>

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

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [LTP] [PATCH v4 13/13] Add statmount07 test
  2024-10-04  9:17       ` Cyril Hrubis
  2024-10-04 11:03         ` Andrea Cervesato via ltp
@ 2024-10-04 12:02         ` Jan Kara
  1 sibling, 0 replies; 35+ messages in thread
From: Jan Kara @ 2024-10-04 12:02 UTC (permalink / raw)
  To: Christian Brauner; +Cc: Jan Kara, ltp

Hi!

On Fri 04-10-24 11:17:21, Cyril Hrubis wrote:
> > That seems to be a valid value, since I get PASS. Kernel bug?
> 
> Looking at kernel it's a bit confusing, the bufsize is supposed to be
> the size of the structure plus the buffer allocated for the string
> reply. Which makes the code more complicated than it could have been if
> these two were separeted properly.
> 
> 
> However we do have:
> 
>        if (kbufsize >= s->bufsize)
>                 return -EOVERFLOW;
> 
> in statmount_string(), so we will trigger the error there if we pass one
> of the requests that is supposed to produce a string reply.

Yes, if STATMOUNT_STRING_REQ is set, the above check should always make
sure bufsize is large enough.

> But there seems to be something strange going on in the
> prepare_kstatmount() as well, we do have:
> 
>         if (ks->mask & STATMOUNT_STRING_REQ) {
>                 if (bufsize == sizeof(ks->sm))
>                         return -EOVERFLOW;
> 
> 		^ This line should probably be if (bufsize <= sizeof(ks->sm))
>                   because we are trying to make sure that the structure is large
> 		  enough that we can write at the offset where the
> 		  string area starts.
> 
> 		  It seems to be guarded by the checks in
> 		  statmount_string() later on as well, so I suppose that we
> 		  will trigger the EOVERFLOW slightly later if this does not
> 		  work though. CCying Jan to have a look.

Yup, this looks confusing to me as well. Christian, is this check indeed
meant to bail early if the buffer obviously is not large enough? Shouldn't
it then be <= as Cyril suggests? I have a feeling I might be missing some
"extensible syscall" magic that does the check bufsize < sizeof(struct)
automatically somewhere but I could not find it...

								Honza
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

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

^ permalink raw reply	[flat|nested] 35+ messages in thread

end of thread, other threads:[~2024-10-04 12:03 UTC | newest]

Thread overview: 35+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-09 10:00 [LTP] [PATCH v4 00/13] statmount/listmount testing suites Andrea Cervesato
2024-09-09 10:00 ` [LTP] [PATCH v4 01/13] Add SAFE_STATX macro Andrea Cervesato
2024-09-09 16:21   ` Andrea Cervesato via ltp
2024-10-02 12:27   ` Cyril Hrubis
2024-10-02 13:00     ` Andrea Cervesato via ltp
2024-09-09 10:00 ` [LTP] [PATCH v4 02/13] Add listmount/statmount syscalls Andrea Cervesato
2024-10-02 12:30   ` Cyril Hrubis
2024-09-09 10:00 ` [LTP] [PATCH v4 03/13] Add listmount/statmount fallback declarations Andrea Cervesato
2024-10-02 14:12   ` Cyril Hrubis
2024-09-09 10:00 ` [LTP] [PATCH v4 04/13] Add listmount01 test Andrea Cervesato
2024-10-02 14:05   ` Cyril Hrubis
2024-10-02 14:14   ` Cyril Hrubis
2024-09-09 10:00 ` [LTP] [PATCH v4 05/13] Add listmount02 test Andrea Cervesato
2024-10-02 14:37   ` Cyril Hrubis
2024-09-09 10:00 ` [LTP] [PATCH v4 06/13] Add statmount01 test Andrea Cervesato
2024-10-02 14:45   ` Cyril Hrubis
2024-09-09 10:00 ` [LTP] [PATCH v4 07/13] Add statmount02 test Andrea Cervesato
2024-10-02 15:15   ` Cyril Hrubis
2024-09-09 10:00 ` [LTP] [PATCH v4 08/13] Add statmount03 test Andrea Cervesato
2024-10-03 13:27   ` Cyril Hrubis
2024-09-09 10:00 ` [LTP] [PATCH v4 09/13] Add statmount04 test Andrea Cervesato
2024-10-03 13:51   ` Cyril Hrubis
2024-09-09 10:00 ` [LTP] [PATCH v4 10/13] Add statmount05 test Andrea Cervesato
2024-10-03 14:09   ` Cyril Hrubis
2024-09-09 10:00 ` [LTP] [PATCH v4 11/13] Add TST_EXP_EQ_STR macro Andrea Cervesato
2024-10-03 14:13   ` Cyril Hrubis
2024-09-09 10:00 ` [LTP] [PATCH v4 12/13] Add statmount06 test Andrea Cervesato
2024-10-03 14:20   ` Cyril Hrubis
2024-09-09 10:00 ` [LTP] [PATCH v4 13/13] Add statmount07 test Andrea Cervesato
2024-10-03 14:34   ` Cyril Hrubis
2024-10-04  8:19     ` Andrea Cervesato via ltp
2024-10-04  9:17       ` Cyril Hrubis
2024-10-04 11:03         ` Andrea Cervesato via ltp
2024-10-04 12:02         ` Jan Kara
2024-10-03 14:42 ` [LTP] [PATCH v4 00/13] statmount/listmount testing suites Cyril Hrubis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox