* [LTP] [PATCH v7 00/16] statmount/listmount testing suites
@ 2024-10-09 8:29 Andrea Cervesato
2024-10-09 8:29 ` [LTP] [PATCH v7 01/16] Add SAFE_STATX macro Andrea Cervesato
` (15 more replies)
0 siblings, 16 replies; 19+ messages in thread
From: Andrea Cervesato @ 2024-10-09 8:29 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 v7:
- fix statmount01
- add more EOVERFLOW tests in statmount07
- add more invalid tests in listmount04
- Link to v6: https://lore.kernel.org/r/20241008-listmount_statmount-v6-0-0fd456b6b9bf@suse.com
Changes in v6:
- fix statmount01
- add more EOVERFLOW tests in statmount06
- Link to v5: https://lore.kernel.org/r/20241008-listmount_statmount-v5-0-66f4e1a9e7db@suse.com
Changes in v5:
- usage of sx.data.stx_mask
- use TST_EXP_EQ_STR
- use tst_tmpdir_genpath()
- use !TST_PASS instead of TST_RET == -1
- listmount03
- listmount04
- statmount08
- Link to v4: https://lore.kernel.org/r/20240909-listmount_statmount-v4-0-39558204ddf0@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 (16):
Add SAFE_STATX macro
Add TST_EXP_EQ_STR 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 statmount06 test
Add statmount07 test
Add statmount08 test
Add listmount03 test
Add listmount04 test
configure.ac | 2 +
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 | 14 ++
testcases/kernel/syscalls/listmount/.gitignore | 4 +
testcases/kernel/syscalls/listmount/Makefile | 7 +
testcases/kernel/syscalls/listmount/listmount.h | 27 ++++
testcases/kernel/syscalls/listmount/listmount01.c | 63 +++++++++
testcases/kernel/syscalls/listmount/listmount02.c | 105 ++++++++++++++
testcases/kernel/syscalls/listmount/listmount03.c | 62 +++++++++
testcases/kernel/syscalls/listmount/listmount04.c | 162 ++++++++++++++++++++++
testcases/kernel/syscalls/statmount/.gitignore | 8 ++
testcases/kernel/syscalls/statmount/Makefile | 7 +
testcases/kernel/syscalls/statmount/statmount.h | 51 +++++++
testcases/kernel/syscalls/statmount/statmount01.c | 77 ++++++++++
testcases/kernel/syscalls/statmount/statmount02.c | 84 +++++++++++
testcases/kernel/syscalls/statmount/statmount03.c | 138 ++++++++++++++++++
testcases/kernel/syscalls/statmount/statmount04.c | 105 ++++++++++++++
testcases/kernel/syscalls/statmount/statmount05.c | 123 ++++++++++++++++
testcases/kernel/syscalls/statmount/statmount06.c | 68 +++++++++
testcases/kernel/syscalls/statmount/statmount07.c | 144 +++++++++++++++++++
testcases/kernel/syscalls/statmount/statmount08.c | 65 +++++++++
41 files changed, 1515 insertions(+), 32 deletions(-)
---
base-commit: 701212f08d6e850457cc2b10238f28662ef48471
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] 19+ messages in thread
* [LTP] [PATCH v7 01/16] Add SAFE_STATX macro
2024-10-09 8:29 [LTP] [PATCH v7 00/16] statmount/listmount testing suites Andrea Cervesato
@ 2024-10-09 8:29 ` Andrea Cervesato
2024-10-09 9:12 ` Cyril Hrubis
2024-10-09 8:29 ` [LTP] [PATCH v7 02/16] Add TST_EXP_EQ_STR macro Andrea Cervesato
` (14 subsequent siblings)
15 siblings, 1 reply; 19+ messages in thread
From: Andrea Cervesato @ 2024-10-09 8:29 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/stat.h | 111 +++++++++++++++++++++++++++++++++++++---------------
1 file changed, 79 insertions(+), 32 deletions(-)
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__ */
--
2.43.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [LTP] [PATCH v7 02/16] Add TST_EXP_EQ_STR macro
2024-10-09 8:29 [LTP] [PATCH v7 00/16] statmount/listmount testing suites Andrea Cervesato
2024-10-09 8:29 ` [LTP] [PATCH v7 01/16] Add SAFE_STATX macro Andrea Cervesato
@ 2024-10-09 8:29 ` Andrea Cervesato
2024-10-09 8:29 ` [LTP] [PATCH v7 03/16] Add listmount/statmount syscalls Andrea Cervesato
` (13 subsequent siblings)
15 siblings, 0 replies; 19+ messages in thread
From: Andrea Cervesato @ 2024-10-09 8:29 UTC (permalink / raw)
To: ltp
From: Andrea Cervesato <andrea.cervesato@suse.com>
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
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 c02ad38f9..b2ca32f77 100644
--- a/include/tst_test_macros.h
+++ b/include/tst_test_macros.h
@@ -411,4 +411,18 @@ const char *tst_errno_names(char *buf, const int *exp_errs, int exp_errs_cnt);
#define TST_EXP_EQ_SSZ_SILENT(VAL_A, VAL_B) \
TST_EXP_EQ_SILENT_(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] 19+ messages in thread
* [LTP] [PATCH v7 03/16] Add listmount/statmount syscalls
2024-10-09 8:29 [LTP] [PATCH v7 00/16] statmount/listmount testing suites Andrea Cervesato
2024-10-09 8:29 ` [LTP] [PATCH v7 01/16] Add SAFE_STATX macro Andrea Cervesato
2024-10-09 8:29 ` [LTP] [PATCH v7 02/16] Add TST_EXP_EQ_STR macro Andrea Cervesato
@ 2024-10-09 8:29 ` Andrea Cervesato
2024-10-09 8:29 ` [LTP] [PATCH v7 04/16] Add listmount/statmount fallback declarations Andrea Cervesato
` (12 subsequent siblings)
15 siblings, 0 replies; 19+ messages in thread
From: Andrea Cervesato @ 2024-10-09 8:29 UTC (permalink / raw)
To: ltp
From: Andrea Cervesato <andrea.cervesato@suse.com>
Reviewed-by: Avinesh Kumar <akumar@suse.de>
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
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] 19+ messages in thread
* [LTP] [PATCH v7 04/16] Add listmount/statmount fallback declarations
2024-10-09 8:29 [LTP] [PATCH v7 00/16] statmount/listmount testing suites Andrea Cervesato
` (2 preceding siblings ...)
2024-10-09 8:29 ` [LTP] [PATCH v7 03/16] Add listmount/statmount syscalls Andrea Cervesato
@ 2024-10-09 8:29 ` Andrea Cervesato
2024-10-09 8:29 ` [LTP] [PATCH v7 05/16] Add listmount01 test Andrea Cervesato
` (11 subsequent siblings)
15 siblings, 0 replies; 19+ messages in thread
From: Andrea Cervesato @ 2024-10-09 8:29 UTC (permalink / raw)
To: ltp
From: Andrea Cervesato <andrea.cervesato@suse.com>
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
configure.ac | 2 ++
include/lapi/mount.h | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 72 insertions(+)
diff --git a/configure.ac b/configure.ac
index ebbf49e28..b4ab81e26 100644
--- a/configure.ac
+++ b/configure.ac
@@ -246,6 +246,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] 19+ messages in thread
* [LTP] [PATCH v7 05/16] Add listmount01 test
2024-10-09 8:29 [LTP] [PATCH v7 00/16] statmount/listmount testing suites Andrea Cervesato
` (3 preceding siblings ...)
2024-10-09 8:29 ` [LTP] [PATCH v7 04/16] Add listmount/statmount fallback declarations Andrea Cervesato
@ 2024-10-09 8:29 ` Andrea Cervesato
2024-10-09 8:29 ` [LTP] [PATCH v7 06/16] Add listmount02 test Andrea Cervesato
` (10 subsequent siblings)
15 siblings, 0 replies; 19+ messages in thread
From: Andrea Cervesato @ 2024-10-09 8:29 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.
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
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 | 27 ++++++++++
testcases/kernel/syscalls/listmount/listmount01.c | 63 +++++++++++++++++++++++
5 files changed, 100 insertions(+)
diff --git a/runtest/syscalls b/runtest/syscalls
index 02e721df9..09e3025a6 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -731,6 +731,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..aad927f71
--- /dev/null
+++ b/testcases/kernel/syscalls/listmount/listmount.h
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+#ifndef LISTMOUNT_H
+#define 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..604e5ce92
--- /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_PASS)
+ 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] 19+ messages in thread
* [LTP] [PATCH v7 06/16] Add listmount02 test
2024-10-09 8:29 [LTP] [PATCH v7 00/16] statmount/listmount testing suites Andrea Cervesato
` (4 preceding siblings ...)
2024-10-09 8:29 ` [LTP] [PATCH v7 05/16] Add listmount01 test Andrea Cervesato
@ 2024-10-09 8:29 ` Andrea Cervesato
2024-10-09 8:29 ` [LTP] [PATCH v7 07/16] Add statmount01 test Andrea Cervesato
` (9 subsequent siblings)
15 siblings, 0 replies; 19+ messages in thread
From: Andrea Cervesato @ 2024-10-09 8:29 UTC (permalink / raw)
To: ltp
From: Andrea Cervesato <andrea.cervesato@suse.com>
This test verifies that listmount() is properly reading groups of
mount IDs.
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
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 09e3025a6..564066b2b 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -732,6 +732,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..4b831b615
--- /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_PASS)
+ 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] 19+ messages in thread
* [LTP] [PATCH v7 07/16] Add statmount01 test
2024-10-09 8:29 [LTP] [PATCH v7 00/16] statmount/listmount testing suites Andrea Cervesato
` (5 preceding siblings ...)
2024-10-09 8:29 ` [LTP] [PATCH v7 06/16] Add listmount02 test Andrea Cervesato
@ 2024-10-09 8:29 ` Andrea Cervesato
2024-10-09 8:29 ` [LTP] [PATCH v7 08/16] Add statmount02 test Andrea Cervesato
` (8 subsequent siblings)
15 siblings, 0 replies; 19+ messages in thread
From: Andrea Cervesato @ 2024-10-09 8:29 UTC (permalink / raw)
To: ltp
From: Andrea Cervesato <andrea.cervesato@suse.com>
This test verifies that statmount() is working with no mask flags.
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
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 | 27 ++++++++
testcases/kernel/syscalls/statmount/statmount01.c | 77 +++++++++++++++++++++++
5 files changed, 114 insertions(+)
diff --git a/runtest/syscalls b/runtest/syscalls
index 564066b2b..677d797f8 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -1574,6 +1574,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..cb0fd1cca
--- /dev/null
+++ b/testcases/kernel/syscalls/statmount/statmount.h
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+#ifndef STATMOUNT_H
+#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..73b9a59b0
--- /dev/null
+++ b/testcases/kernel/syscalls/statmount/statmount01.c
@@ -0,0 +1,77 @@
+// 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 mntpoint_id;
+static struct statmount *st_mount;
+
+static void run(void)
+{
+ memset(st_mount, 0, sizeof(struct statmount));
+
+ TST_EXP_PASS(statmount(mntpoint_id, 0, st_mount, sizeof(struct statmount), 0));
+
+ if (!TST_PASS)
+ 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);
+
+ mntpoint_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,
+ .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] 19+ messages in thread
* [LTP] [PATCH v7 08/16] Add statmount02 test
2024-10-09 8:29 [LTP] [PATCH v7 00/16] statmount/listmount testing suites Andrea Cervesato
` (6 preceding siblings ...)
2024-10-09 8:29 ` [LTP] [PATCH v7 07/16] Add statmount01 test Andrea Cervesato
@ 2024-10-09 8:29 ` Andrea Cervesato
2024-10-09 8:29 ` [LTP] [PATCH v7 09/16] Add statmount03 test Andrea Cervesato
` (7 subsequent siblings)
15 siblings, 0 replies; 19+ messages in thread
From: Andrea Cervesato @ 2024-10-09 8:29 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.
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
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 677d797f8..c6c31c546 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -1575,6 +1575,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..4e23c6979
--- /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_PASS)
+ 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] 19+ messages in thread
* [LTP] [PATCH v7 09/16] Add statmount03 test
2024-10-09 8:29 [LTP] [PATCH v7 00/16] statmount/listmount testing suites Andrea Cervesato
` (7 preceding siblings ...)
2024-10-09 8:29 ` [LTP] [PATCH v7 08/16] Add statmount02 test Andrea Cervesato
@ 2024-10-09 8:29 ` Andrea Cervesato
2024-10-09 8:29 ` [LTP] [PATCH v7 10/16] Add statmount04 test Andrea Cervesato
` (6 subsequent siblings)
15 siblings, 0 replies; 19+ messages in thread
From: Andrea Cervesato @ 2024-10-09 8:29 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.
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
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 | 138 ++++++++++++++++++++++
4 files changed, 164 insertions(+)
diff --git a/runtest/syscalls b/runtest/syscalls
index c6c31c546..47ca26213 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -1576,6 +1576,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 cb0fd1cca..d21d7f8da 100644
--- a/testcases/kernel/syscalls/statmount/statmount.h
+++ b/testcases/kernel/syscalls/statmount/statmount.h
@@ -11,6 +11,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)
@@ -24,4 +25,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..dface528f
--- /dev/null
+++ b/testcases/kernel/syscalls/statmount/statmount03.c
@@ -0,0 +1,138 @@
+// 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) {
+ sx.data.stx_mask = STATX_MNT_ID;
+
+ SAFE_STATX(AT_FDCWD, path, 0, STATX_MNT_ID, &sx);
+ *mnt_id = sx.data.stx_mnt_id;
+ }
+
+ if (mnt_id_unique) {
+ sx.data.stx_mask = STATX_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_PASS)
+ return;
+
+ 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] 19+ messages in thread
* [LTP] [PATCH v7 10/16] Add statmount04 test
2024-10-09 8:29 [LTP] [PATCH v7 00/16] statmount/listmount testing suites Andrea Cervesato
` (8 preceding siblings ...)
2024-10-09 8:29 ` [LTP] [PATCH v7 09/16] Add statmount03 test Andrea Cervesato
@ 2024-10-09 8:29 ` Andrea Cervesato
2024-10-09 8:29 ` [LTP] [PATCH v7 11/16] Add statmount05 test Andrea Cervesato
` (5 subsequent siblings)
15 siblings, 0 replies; 19+ messages in thread
From: Andrea Cervesato @ 2024-10-09 8:29 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.
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
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 47ca26213..452ac1ac9 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -1577,6 +1577,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..509fdf6a1
--- /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_PASS)
+ 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] 19+ messages in thread
* [LTP] [PATCH v7 11/16] Add statmount05 test
2024-10-09 8:29 [LTP] [PATCH v7 00/16] statmount/listmount testing suites Andrea Cervesato
` (9 preceding siblings ...)
2024-10-09 8:29 ` [LTP] [PATCH v7 10/16] Add statmount04 test Andrea Cervesato
@ 2024-10-09 8:29 ` Andrea Cervesato
2024-10-09 8:29 ` [LTP] [PATCH v7 12/16] Add statmount06 test Andrea Cervesato
` (4 subsequent siblings)
15 siblings, 0 replies; 19+ messages in thread
From: Andrea Cervesato @ 2024-10-09 8:29 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().
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
runtest/syscalls | 1 +
testcases/kernel/syscalls/statmount/.gitignore | 1 +
testcases/kernel/syscalls/statmount/statmount05.c | 123 ++++++++++++++++++++++
3 files changed, 125 insertions(+)
diff --git a/runtest/syscalls b/runtest/syscalls
index 452ac1ac9..97c7049a2 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -1578,6 +1578,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..95e674c06
--- /dev/null
+++ b/testcases/kernel/syscalls/statmount/statmount05.c
@@ -0,0 +1,123 @@
+// 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_PASS)
+ return;
+
+ last_root = strrchr(mnt_root, '/');
+
+ TST_EXP_EQ_LI(st_mount->mask, STATMOUNT_MNT_ROOT);
+ TST_EXP_EQ_STR(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_PASS)
+ return;
+
+ TST_EXP_EQ_LI(st_mount->mask, STATMOUNT_MNT_POINT);
+ TST_EXP_EQ_STR(st_mount->str + st_mount->mnt_point, mnt_point);
+}
+
+static void run(void)
+{
+ test_mount_root();
+ test_mount_point();
+}
+
+static void setup(void)
+{
+ struct ltp_statx sx;
+
+ mnt_root = tst_tmpdir_genpath(DIRA);
+ mnt_point = tst_tmpdir_genpath(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] 19+ messages in thread
* [LTP] [PATCH v7 12/16] Add statmount06 test
2024-10-09 8:29 [LTP] [PATCH v7 00/16] statmount/listmount testing suites Andrea Cervesato
` (10 preceding siblings ...)
2024-10-09 8:29 ` [LTP] [PATCH v7 11/16] Add statmount05 test Andrea Cervesato
@ 2024-10-09 8:29 ` Andrea Cervesato
2024-10-09 8:29 ` [LTP] [PATCH v7 13/16] Add statmount07 test Andrea Cervesato
` (3 subsequent siblings)
15 siblings, 0 replies; 19+ messages in thread
From: Andrea Cervesato @ 2024-10-09 8:29 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.
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
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 97c7049a2..a742e405b 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -1579,6 +1579,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..73740407e
--- /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_PASS)
+ 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] 19+ messages in thread
* [LTP] [PATCH v7 13/16] Add statmount07 test
2024-10-09 8:29 [LTP] [PATCH v7 00/16] statmount/listmount testing suites Andrea Cervesato
` (11 preceding siblings ...)
2024-10-09 8:29 ` [LTP] [PATCH v7 12/16] Add statmount06 test Andrea Cervesato
@ 2024-10-09 8:29 ` Andrea Cervesato
2024-10-09 8:29 ` [LTP] [PATCH v7 14/16] Add statmount08 test Andrea Cervesato
` (2 subsequent siblings)
15 siblings, 0 replies; 19+ messages in thread
From: Andrea Cervesato @ 2024-10-09 8:29 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.
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
runtest/syscalls | 1 +
testcases/kernel/syscalls/statmount/.gitignore | 1 +
testcases/kernel/syscalls/statmount/statmount07.c | 144 ++++++++++++++++++++++
3 files changed, 146 insertions(+)
diff --git a/runtest/syscalls b/runtest/syscalls
index a742e405b..bf222e466 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -1580,6 +1580,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..0cc834298
--- /dev/null
+++ b/testcases/kernel/syscalls/statmount/statmount07.c
@@ -0,0 +1,144 @@
+// 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 struct statmount *st_mount_small;
+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
+ },
+ {
+ EOVERFLOW,
+ "small buffer for fs type",
+ &mnt_id,
+ STATMOUNT_FS_TYPE,
+ 0,
+ &buff_size,
+ &st_mount_small
+ },
+ {
+ EOVERFLOW,
+ "small buffer for mnt root",
+ &mnt_id,
+ STATMOUNT_MNT_ROOT,
+ 0,
+ &buff_size,
+ &st_mount_small
+ },
+ {
+ EOVERFLOW,
+ "small buffer for mnt point",
+ &mnt_id,
+ STATMOUNT_MNT_POINT,
+ 0,
+ &buff_size,
+ &st_mount_small
+ },
+ {
+ 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)},
+ {&st_mount_small, .size = sizeof(struct statmount)},
+ {}
+ }
+};
--
2.43.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [LTP] [PATCH v7 14/16] Add statmount08 test
2024-10-09 8:29 [LTP] [PATCH v7 00/16] statmount/listmount testing suites Andrea Cervesato
` (12 preceding siblings ...)
2024-10-09 8:29 ` [LTP] [PATCH v7 13/16] Add statmount07 test Andrea Cervesato
@ 2024-10-09 8:29 ` Andrea Cervesato
2024-10-09 8:29 ` [LTP] [PATCH v7 15/16] Add listmount03 test Andrea Cervesato
2024-10-09 8:29 ` [LTP] [PATCH v7 16/16] Add listmount04 test Andrea Cervesato
15 siblings, 0 replies; 19+ messages in thread
From: Andrea Cervesato @ 2024-10-09 8:29 UTC (permalink / raw)
To: ltp
From: Andrea Cervesato <andrea.cervesato@suse.com>
Verify that statmount() raises EPERM when mount point is not accessible.
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
runtest/syscalls | 1 +
testcases/kernel/syscalls/statmount/.gitignore | 1 +
testcases/kernel/syscalls/statmount/statmount08.c | 65 +++++++++++++++++++++++
3 files changed, 67 insertions(+)
diff --git a/runtest/syscalls b/runtest/syscalls
index bf222e466..f8ae25344 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -1581,6 +1581,7 @@ statmount04 statmount04
statmount05 statmount05
statmount06 statmount06
statmount07 statmount07
+statmount08 statmount08
statfs01 statfs01
statfs01_64 statfs01_64
diff --git a/testcases/kernel/syscalls/statmount/.gitignore b/testcases/kernel/syscalls/statmount/.gitignore
index b2a55c077..6106fcf07 100644
--- a/testcases/kernel/syscalls/statmount/.gitignore
+++ b/testcases/kernel/syscalls/statmount/.gitignore
@@ -5,3 +5,4 @@ statmount04
statmount05
statmount06
statmount07
+statmount08
diff --git a/testcases/kernel/syscalls/statmount/statmount08.c b/testcases/kernel/syscalls/statmount/statmount08.c
new file mode 100644
index 000000000..21b8b7342
--- /dev/null
+++ b/testcases/kernel/syscalls/statmount/statmount08.c
@@ -0,0 +1,65 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Verify that statmount() raises EPERM when mount point is not accessible.
+ */
+
+#define _GNU_SOURCE
+
+#include <pwd.h>
+#include "statmount.h"
+#include "lapi/stat.h"
+
+static struct statmount *st_mount;
+static uint64_t root_id;
+static gid_t nobody_gid;
+static uid_t nobody_uid;
+
+static void run(void)
+{
+ if (SAFE_FORK())
+ return;
+
+ SAFE_SETEGID(nobody_gid);
+ SAFE_SETEUID(nobody_uid);
+
+ memset(st_mount, 0, sizeof(struct statmount));
+
+ TST_EXP_FAIL(statmount(root_id, STATMOUNT_SB_BASIC, st_mount,
+ sizeof(struct statmount), 0), EPERM);
+
+ exit(0);
+}
+
+static void setup(void)
+{
+ struct ltp_statx sx;
+ struct passwd *pw;
+
+ pw = SAFE_GETPWNAM("nobody");
+ nobody_gid = pw->pw_gid;
+ nobody_uid = pw->pw_uid;
+
+ SAFE_STATX(AT_FDCWD, "/", 0, STATX_MNT_ID_UNIQUE, &sx);
+ root_id = sx.data.stx_mnt_id;
+
+ SAFE_CHROOT(tst_tmpdir_path());
+}
+
+static struct tst_test test = {
+ .test_all = run,
+ .setup = setup,
+ .needs_root = 1,
+ .needs_tmpdir = 1,
+ .forks_child = 1,
+ .min_kver = "6.8",
+ .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] 19+ messages in thread
* [LTP] [PATCH v7 15/16] Add listmount03 test
2024-10-09 8:29 [LTP] [PATCH v7 00/16] statmount/listmount testing suites Andrea Cervesato
` (13 preceding siblings ...)
2024-10-09 8:29 ` [LTP] [PATCH v7 14/16] Add statmount08 test Andrea Cervesato
@ 2024-10-09 8:29 ` Andrea Cervesato
2024-10-09 8:29 ` [LTP] [PATCH v7 16/16] Add listmount04 test Andrea Cervesato
15 siblings, 0 replies; 19+ messages in thread
From: Andrea Cervesato @ 2024-10-09 8:29 UTC (permalink / raw)
To: ltp
From: Andrea Cervesato <andrea.cervesato@suse.com>
Verify that listmount() raises EPERM when mount point is not accessible.
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
runtest/syscalls | 1 +
testcases/kernel/syscalls/listmount/.gitignore | 1 +
testcases/kernel/syscalls/listmount/listmount03.c | 62 +++++++++++++++++++++++
3 files changed, 64 insertions(+)
diff --git a/runtest/syscalls b/runtest/syscalls
index f8ae25344..7e6d7aacf 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -733,6 +733,7 @@ listen01 listen01
listmount01 listmount01
listmount02 listmount02
+listmount03 listmount03
listxattr01 listxattr01
listxattr02 listxattr02
diff --git a/testcases/kernel/syscalls/listmount/.gitignore b/testcases/kernel/syscalls/listmount/.gitignore
index 30bbf9f02..e4273f319 100644
--- a/testcases/kernel/syscalls/listmount/.gitignore
+++ b/testcases/kernel/syscalls/listmount/.gitignore
@@ -1,2 +1,3 @@
listmount01
listmount02
+listmount03
diff --git a/testcases/kernel/syscalls/listmount/listmount03.c b/testcases/kernel/syscalls/listmount/listmount03.c
new file mode 100644
index 000000000..befe0edaf
--- /dev/null
+++ b/testcases/kernel/syscalls/listmount/listmount03.c
@@ -0,0 +1,62 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Verify that listmount() raises EPERM when mount point is not accessible.
+ */
+
+#define _GNU_SOURCE
+
+#include <pwd.h>
+#include "listmount.h"
+#include "lapi/stat.h"
+
+#define LISTSIZE 32
+
+static uint64_t root_id;
+static gid_t nobody_gid;
+static uid_t nobody_uid;
+
+static void run(void)
+{
+ if (SAFE_FORK())
+ return;
+
+ uint64_t list[LISTSIZE];
+
+ SAFE_SETEGID(nobody_gid);
+ SAFE_SETEUID(nobody_uid);
+
+ TST_EXP_FAIL(listmount(root_id, 0, list, LISTSIZE, 0), EPERM);
+
+ exit(0);
+}
+
+static void setup(void)
+{
+ struct ltp_statx sx;
+ struct passwd *pw;
+
+ pw = SAFE_GETPWNAM("nobody");
+ nobody_gid = pw->pw_gid;
+ nobody_uid = pw->pw_uid;
+
+ SAFE_STATX(AT_FDCWD, "/", 0, STATX_MNT_ID_UNIQUE, &sx);
+ root_id = sx.data.stx_mnt_id;
+
+ SAFE_CHROOT(tst_tmpdir_path());
+}
+
+static struct tst_test test = {
+ .test_all = run,
+ .setup = setup,
+ .needs_root = 1,
+ .needs_tmpdir = 1,
+ .forks_child = 1,
+ .min_kver = "6.8",
+};
+
--
2.43.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [LTP] [PATCH v7 16/16] Add listmount04 test
2024-10-09 8:29 [LTP] [PATCH v7 00/16] statmount/listmount testing suites Andrea Cervesato
` (14 preceding siblings ...)
2024-10-09 8:29 ` [LTP] [PATCH v7 15/16] Add listmount03 test Andrea Cervesato
@ 2024-10-09 8:29 ` Andrea Cervesato
2024-10-09 10:45 ` Cyril Hrubis
15 siblings, 1 reply; 19+ messages in thread
From: Andrea Cervesato @ 2024-10-09 8:29 UTC (permalink / raw)
To: ltp
From: Andrea Cervesato <andrea.cervesato@suse.com>
Verify that listmount() raises the correct errors according with
invalid data:
- EFAULT: req or mnt_id are unaccessible memories
- EINVAL: invalid flags or mnt_id request
- ENOENT: non-existent mount point
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
runtest/syscalls | 1 +
testcases/kernel/syscalls/listmount/.gitignore | 1 +
testcases/kernel/syscalls/listmount/listmount04.c | 162 ++++++++++++++++++++++
3 files changed, 164 insertions(+)
diff --git a/runtest/syscalls b/runtest/syscalls
index 7e6d7aacf..80c4888ee 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -734,6 +734,7 @@ listen01 listen01
listmount01 listmount01
listmount02 listmount02
listmount03 listmount03
+listmount04 listmount04
listxattr01 listxattr01
listxattr02 listxattr02
diff --git a/testcases/kernel/syscalls/listmount/.gitignore b/testcases/kernel/syscalls/listmount/.gitignore
index e4273f319..4d709bae5 100644
--- a/testcases/kernel/syscalls/listmount/.gitignore
+++ b/testcases/kernel/syscalls/listmount/.gitignore
@@ -1,3 +1,4 @@
listmount01
listmount02
listmount03
+listmount04
diff --git a/testcases/kernel/syscalls/listmount/listmount04.c b/testcases/kernel/syscalls/listmount/listmount04.c
new file mode 100644
index 000000000..b14ad4f01
--- /dev/null
+++ b/testcases/kernel/syscalls/listmount/listmount04.c
@@ -0,0 +1,162 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Verify that listmount() raises the correct errors according with
+ * invalid data:
+ *
+ * - EFAULT: req or mnt_id are unaccessible memories
+ * - EINVAL: invalid flags or mnt_id request
+ * - ENOENT: non-existent mount point
+ */
+
+#define _GNU_SOURCE
+
+#include "tst_test.h"
+#include "lapi/mount.h"
+#include "lapi/syscalls.h"
+
+#define MNT_SIZE 32
+
+static struct mnt_id_req *request;
+static uint64_t mnt_ids[MNT_SIZE];
+
+static struct tcase {
+ int req_usage;
+ uint32_t size;
+ uint32_t spare;
+ uint64_t mnt_id;
+ uint64_t param;
+ uint64_t *mnt_ids;
+ size_t nr_mnt_ids;
+ uint64_t flags;
+ int exp_errno;
+ char *msg;
+} tcases[] = {
+ {
+ .req_usage = 0,
+ .mnt_ids = mnt_ids,
+ .nr_mnt_ids = MNT_SIZE,
+ .flags = 0,
+ .exp_errno = EFAULT,
+ .msg = "request points to unaccessible memory",
+ },
+ {
+ .req_usage = 1,
+ .size = MNT_ID_REQ_SIZE_VER0,
+ .spare = 0,
+ .mnt_id = LSMT_ROOT,
+ .param = 0,
+ .mnt_ids = NULL,
+ .nr_mnt_ids = MNT_SIZE,
+ .flags = 0,
+ .exp_errno = EFAULT,
+ .msg = "mnt_ids points to unaccessible memory",
+ },
+ {
+ .req_usage = 1,
+ .size = MNT_ID_REQ_SIZE_VER0,
+ .spare = 0,
+ .mnt_id = LSMT_ROOT,
+ .param = 0,
+ .mnt_ids = mnt_ids,
+ .nr_mnt_ids = MNT_SIZE,
+ .flags = -1,
+ .exp_errno = EINVAL,
+ .msg = "invalid flags",
+ },
+ {
+ .req_usage = 1,
+ .size = 0,
+ .spare = 0,
+ .mnt_id = LSMT_ROOT,
+ .param = 0,
+ .mnt_ids = mnt_ids,
+ .nr_mnt_ids = MNT_SIZE,
+ .flags = 0,
+ .exp_errno = EINVAL,
+ .msg = "insufficient mnt_id_req.size",
+ },
+ {
+ .req_usage = 1,
+ .size = MNT_ID_REQ_SIZE_VER0,
+ .spare = -1,
+ .mnt_id = LSMT_ROOT,
+ .param = 0,
+ .mnt_ids = mnt_ids,
+ .nr_mnt_ids = MNT_SIZE,
+ .flags = 0,
+ .exp_errno = EINVAL,
+ .msg = "invalid mnt_id_req.spare",
+ },
+ {
+ .req_usage = 1,
+ .size = MNT_ID_REQ_SIZE_VER0,
+ .spare = 0,
+ .mnt_id = LSMT_ROOT,
+ .param = STATMOUNT_PROPAGATE_FROM + 1,
+ .mnt_ids = mnt_ids,
+ .nr_mnt_ids = MNT_SIZE,
+ .flags = 0,
+ .exp_errno = EINVAL,
+ .msg = "invalid mnt_id_req.param",
+ },
+ {
+ .req_usage = 1,
+ .size = MNT_ID_REQ_SIZE_VER0,
+ .spare = 0,
+ .mnt_id = 0,
+ .param = 0,
+ .mnt_ids = mnt_ids,
+ .nr_mnt_ids = MNT_SIZE,
+ .flags = 0,
+ .exp_errno = EINVAL,
+ .msg = "invalid mnt_id_req.mnt_id",
+ },
+ {
+ .req_usage = 1,
+ .size = MNT_ID_REQ_SIZE_VER0,
+ .spare = 0,
+ .mnt_id = LSMT_ROOT - 1,
+ .param = 0,
+ .mnt_ids = mnt_ids,
+ .nr_mnt_ids = MNT_SIZE,
+ .flags = 0,
+ .exp_errno = ENOENT,
+ .msg = "non-existant mnt_id",
+ },
+};
+
+static void run(unsigned int n)
+{
+ struct tcase *tc = &tcases[n];
+ struct mnt_id_req *req = NULL;
+
+ memset(mnt_ids, 0, sizeof(mnt_ids));
+
+ if (tc->req_usage) {
+ req = request;
+ req->mnt_id = tc->mnt_id;
+ req->param = tc->param;
+ req->size = tc->size;
+ req->spare = tc->spare;
+ }
+
+ TST_EXP_FAIL(tst_syscall(__NR_listmount, req, tc->mnt_ids,
+ tc->nr_mnt_ids, tc->flags), tc->exp_errno,
+ "%s", tc->msg);
+}
+
+static struct tst_test test = {
+ .test = run,
+ .tcnt = ARRAY_SIZE(tcases),
+ .min_kver = "6.8",
+ .bufs = (struct tst_buffers []) {
+ { &request, .size = sizeof(struct mnt_id_req) },
+ {},
+ },
+};
--
2.43.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 19+ messages in thread
* Re: [LTP] [PATCH v7 01/16] Add SAFE_STATX macro
2024-10-09 8:29 ` [LTP] [PATCH v7 01/16] Add SAFE_STATX macro Andrea Cervesato
@ 2024-10-09 9:12 ` Cyril Hrubis
0 siblings, 0 replies; 19+ messages in thread
From: Cyril Hrubis @ 2024-10-09 9:12 UTC (permalink / raw)
To: Andrea Cervesato; +Cc: ltp
Hi!
> +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
Do we need these typedefs at all? We end up with statx structure defined
in all cases anyways, so we can just use that in the union instead and
we can do just:
LTP_DEFINE_STATX_STRUCT(statx_fallback);
#ifndef HAVE_STRUCT_STATX
LTP_DEFINE_STATX_STRUCT(statx);
#endif
struct ltp_statx {
union {
struct statx buf;
struct statx_fallback fallback;
};
};
Which will create exactly the same result with less complexity (note
that if there is no system statx definition the statx and statx_fallback
structures are identical).
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [LTP] [PATCH v7 16/16] Add listmount04 test
2024-10-09 8:29 ` [LTP] [PATCH v7 16/16] Add listmount04 test Andrea Cervesato
@ 2024-10-09 10:45 ` Cyril Hrubis
0 siblings, 0 replies; 19+ messages in thread
From: Cyril Hrubis @ 2024-10-09 10:45 UTC (permalink / raw)
To: Andrea Cervesato; +Cc: ltp
Hi!
> +static struct tcase {
> + int req_usage;
> + uint32_t size;
> + uint32_t spare;
> + uint64_t mnt_id;
> + uint64_t param;
> + uint64_t *mnt_ids;
> + size_t nr_mnt_ids;
> + uint64_t flags;
> + int exp_errno;
> + char *msg;
> +} tcases[] = {
> + {
> + .req_usage = 0,
> + .mnt_ids = mnt_ids,
> + .nr_mnt_ids = MNT_SIZE,
> + .flags = 0,
> + .exp_errno = EFAULT,
> + .msg = "request points to unaccessible memory",
> + },
> + {
> + .req_usage = 1,
> + .size = MNT_ID_REQ_SIZE_VER0,
> + .spare = 0,
> + .mnt_id = LSMT_ROOT,
> + .param = 0,
> + .mnt_ids = NULL,
> + .nr_mnt_ids = MNT_SIZE,
> + .flags = 0,
> + .exp_errno = EFAULT,
> + .msg = "mnt_ids points to unaccessible memory",
> + },
> + {
> + .req_usage = 1,
> + .size = MNT_ID_REQ_SIZE_VER0,
> + .spare = 0,
> + .mnt_id = LSMT_ROOT,
> + .param = 0,
> + .mnt_ids = mnt_ids,
> + .nr_mnt_ids = MNT_SIZE,
> + .flags = -1,
> + .exp_errno = EINVAL,
> + .msg = "invalid flags",
> + },
> + {
> + .req_usage = 1,
> + .size = 0,
> + .spare = 0,
> + .mnt_id = LSMT_ROOT,
> + .param = 0,
> + .mnt_ids = mnt_ids,
> + .nr_mnt_ids = MNT_SIZE,
> + .flags = 0,
> + .exp_errno = EINVAL,
> + .msg = "insufficient mnt_id_req.size",
> + },
> + {
> + .req_usage = 1,
> + .size = MNT_ID_REQ_SIZE_VER0,
> + .spare = -1,
> + .mnt_id = LSMT_ROOT,
> + .param = 0,
> + .mnt_ids = mnt_ids,
> + .nr_mnt_ids = MNT_SIZE,
> + .flags = 0,
> + .exp_errno = EINVAL,
> + .msg = "invalid mnt_id_req.spare",
> + },
> + {
> + .req_usage = 1,
> + .size = MNT_ID_REQ_SIZE_VER0,
> + .spare = 0,
> + .mnt_id = LSMT_ROOT,
> + .param = STATMOUNT_PROPAGATE_FROM + 1,
> + .mnt_ids = mnt_ids,
> + .nr_mnt_ids = MNT_SIZE,
> + .flags = 0,
> + .exp_errno = EINVAL,
> + .msg = "invalid mnt_id_req.param",
> + },
> + {
> + .req_usage = 1,
> + .size = MNT_ID_REQ_SIZE_VER0,
> + .spare = 0,
> + .mnt_id = 0,
> + .param = 0,
> + .mnt_ids = mnt_ids,
> + .nr_mnt_ids = MNT_SIZE,
> + .flags = 0,
> + .exp_errno = EINVAL,
> + .msg = "invalid mnt_id_req.mnt_id",
> + },
> + {
> + .req_usage = 1,
> + .size = MNT_ID_REQ_SIZE_VER0,
> + .spare = 0,
> + .mnt_id = LSMT_ROOT - 1,
> + .param = 0,
> + .mnt_ids = mnt_ids,
> + .nr_mnt_ids = MNT_SIZE,
> + .flags = 0,
> + .exp_errno = ENOENT,
> + .msg = "non-existant mnt_id",
> + },
> +};
We can omit setting spare, params and flags to 0 here, to make it
shorter, 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] 19+ messages in thread
end of thread, other threads:[~2024-10-09 10:47 UTC | newest]
Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-09 8:29 [LTP] [PATCH v7 00/16] statmount/listmount testing suites Andrea Cervesato
2024-10-09 8:29 ` [LTP] [PATCH v7 01/16] Add SAFE_STATX macro Andrea Cervesato
2024-10-09 9:12 ` Cyril Hrubis
2024-10-09 8:29 ` [LTP] [PATCH v7 02/16] Add TST_EXP_EQ_STR macro Andrea Cervesato
2024-10-09 8:29 ` [LTP] [PATCH v7 03/16] Add listmount/statmount syscalls Andrea Cervesato
2024-10-09 8:29 ` [LTP] [PATCH v7 04/16] Add listmount/statmount fallback declarations Andrea Cervesato
2024-10-09 8:29 ` [LTP] [PATCH v7 05/16] Add listmount01 test Andrea Cervesato
2024-10-09 8:29 ` [LTP] [PATCH v7 06/16] Add listmount02 test Andrea Cervesato
2024-10-09 8:29 ` [LTP] [PATCH v7 07/16] Add statmount01 test Andrea Cervesato
2024-10-09 8:29 ` [LTP] [PATCH v7 08/16] Add statmount02 test Andrea Cervesato
2024-10-09 8:29 ` [LTP] [PATCH v7 09/16] Add statmount03 test Andrea Cervesato
2024-10-09 8:29 ` [LTP] [PATCH v7 10/16] Add statmount04 test Andrea Cervesato
2024-10-09 8:29 ` [LTP] [PATCH v7 11/16] Add statmount05 test Andrea Cervesato
2024-10-09 8:29 ` [LTP] [PATCH v7 12/16] Add statmount06 test Andrea Cervesato
2024-10-09 8:29 ` [LTP] [PATCH v7 13/16] Add statmount07 test Andrea Cervesato
2024-10-09 8:29 ` [LTP] [PATCH v7 14/16] Add statmount08 test Andrea Cervesato
2024-10-09 8:29 ` [LTP] [PATCH v7 15/16] Add listmount03 test Andrea Cervesato
2024-10-09 8:29 ` [LTP] [PATCH v7 16/16] Add listmount04 test Andrea Cervesato
2024-10-09 10:45 ` Cyril Hrubis
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox