* [LTP] [PATCH v5 01/16] Add SAFE_STATX macro
2024-10-08 9:41 [LTP] [PATCH v5 00/16] statmount/listmount testing suites Andrea Cervesato
@ 2024-10-08 9:41 ` Andrea Cervesato
2024-10-08 9:41 ` [LTP] [PATCH v5 02/16] Add TST_EXP_EQ_STR macro Andrea Cervesato
` (14 subsequent siblings)
15 siblings, 0 replies; 27+ messages in thread
From: Andrea Cervesato @ 2024-10-08 9:41 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] 27+ messages in thread* [LTP] [PATCH v5 02/16] Add TST_EXP_EQ_STR macro
2024-10-08 9:41 [LTP] [PATCH v5 00/16] statmount/listmount testing suites Andrea Cervesato
2024-10-08 9:41 ` [LTP] [PATCH v5 01/16] Add SAFE_STATX macro Andrea Cervesato
@ 2024-10-08 9:41 ` Andrea Cervesato
2024-10-08 9:41 ` [LTP] [PATCH v5 03/16] Add listmount/statmount syscalls Andrea Cervesato
` (13 subsequent siblings)
15 siblings, 0 replies; 27+ messages in thread
From: Andrea Cervesato @ 2024-10-08 9:41 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] 27+ messages in thread* [LTP] [PATCH v5 03/16] Add listmount/statmount syscalls
2024-10-08 9:41 [LTP] [PATCH v5 00/16] statmount/listmount testing suites Andrea Cervesato
2024-10-08 9:41 ` [LTP] [PATCH v5 01/16] Add SAFE_STATX macro Andrea Cervesato
2024-10-08 9:41 ` [LTP] [PATCH v5 02/16] Add TST_EXP_EQ_STR macro Andrea Cervesato
@ 2024-10-08 9:41 ` Andrea Cervesato
2024-10-08 9:41 ` [LTP] [PATCH v5 04/16] Add listmount/statmount fallback declarations Andrea Cervesato
` (12 subsequent siblings)
15 siblings, 0 replies; 27+ messages in thread
From: Andrea Cervesato @ 2024-10-08 9:41 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] 27+ messages in thread* [LTP] [PATCH v5 04/16] Add listmount/statmount fallback declarations
2024-10-08 9:41 [LTP] [PATCH v5 00/16] statmount/listmount testing suites Andrea Cervesato
` (2 preceding siblings ...)
2024-10-08 9:41 ` [LTP] [PATCH v5 03/16] Add listmount/statmount syscalls Andrea Cervesato
@ 2024-10-08 9:41 ` Andrea Cervesato
2024-10-08 9:41 ` [LTP] [PATCH v5 05/16] Add listmount01 test Andrea Cervesato
` (11 subsequent siblings)
15 siblings, 0 replies; 27+ messages in thread
From: Andrea Cervesato @ 2024-10-08 9:41 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] 27+ messages in thread* [LTP] [PATCH v5 05/16] Add listmount01 test
2024-10-08 9:41 [LTP] [PATCH v5 00/16] statmount/listmount testing suites Andrea Cervesato
` (3 preceding siblings ...)
2024-10-08 9:41 ` [LTP] [PATCH v5 04/16] Add listmount/statmount fallback declarations Andrea Cervesato
@ 2024-10-08 9:41 ` Andrea Cervesato
2024-10-08 9:41 ` [LTP] [PATCH v5 06/16] Add listmount02 test Andrea Cervesato
` (10 subsequent siblings)
15 siblings, 0 replies; 27+ messages in thread
From: Andrea Cervesato @ 2024-10-08 9:41 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] 27+ messages in thread* [LTP] [PATCH v5 06/16] Add listmount02 test
2024-10-08 9:41 [LTP] [PATCH v5 00/16] statmount/listmount testing suites Andrea Cervesato
` (4 preceding siblings ...)
2024-10-08 9:41 ` [LTP] [PATCH v5 05/16] Add listmount01 test Andrea Cervesato
@ 2024-10-08 9:41 ` Andrea Cervesato
2024-10-08 9:42 ` [LTP] [PATCH v5 07/16] Add statmount01 test Andrea Cervesato
` (9 subsequent siblings)
15 siblings, 0 replies; 27+ messages in thread
From: Andrea Cervesato @ 2024-10-08 9:41 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] 27+ messages in thread* [LTP] [PATCH v5 07/16] Add statmount01 test
2024-10-08 9:41 [LTP] [PATCH v5 00/16] statmount/listmount testing suites Andrea Cervesato
` (5 preceding siblings ...)
2024-10-08 9:41 ` [LTP] [PATCH v5 06/16] Add listmount02 test Andrea Cervesato
@ 2024-10-08 9:42 ` Andrea Cervesato
2024-10-08 11:54 ` Cyril Hrubis
2024-10-08 9:42 ` [LTP] [PATCH v5 08/16] Add statmount02 test Andrea Cervesato
` (8 subsequent siblings)
15 siblings, 1 reply; 27+ messages in thread
From: Andrea Cervesato @ 2024-10-08 9:42 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 | 27 ++++++++
testcases/kernel/syscalls/statmount/statmount01.c | 82 +++++++++++++++++++++++
5 files changed, 119 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..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] 27+ messages in thread* Re: [LTP] [PATCH v5 07/16] Add statmount01 test
2024-10-08 9:42 ` [LTP] [PATCH v5 07/16] Add statmount01 test Andrea Cervesato
@ 2024-10-08 11:54 ` Cyril Hrubis
0 siblings, 0 replies; 27+ messages in thread
From: Cyril Hrubis @ 2024-10-08 11:54 UTC (permalink / raw)
To: Andrea Cervesato; +Cc: ltp
Hi!
> +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;
I asked for this to be changed to if (!TST_PASS)
> + 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;
And here to be changed to mntpoint_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
> + },
And here I suggested that there is no point in running this for all
filesystems.
None of these has been addressed in v5.
> + .bufs = (struct tst_buffers []) {
> + {&st_mount, .size = sizeof(struct statmount)},
> + {}
> + }
> +};
>
> --
> 2.43.0
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 27+ messages in thread
* [LTP] [PATCH v5 08/16] Add statmount02 test
2024-10-08 9:41 [LTP] [PATCH v5 00/16] statmount/listmount testing suites Andrea Cervesato
` (6 preceding siblings ...)
2024-10-08 9:42 ` [LTP] [PATCH v5 07/16] Add statmount01 test Andrea Cervesato
@ 2024-10-08 9:42 ` Andrea Cervesato
2024-10-08 9:42 ` [LTP] [PATCH v5 09/16] Add statmount03 test Andrea Cervesato
` (7 subsequent siblings)
15 siblings, 0 replies; 27+ messages in thread
From: Andrea Cervesato @ 2024-10-08 9:42 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] 27+ messages in thread* [LTP] [PATCH v5 09/16] Add statmount03 test
2024-10-08 9:41 [LTP] [PATCH v5 00/16] statmount/listmount testing suites Andrea Cervesato
` (7 preceding siblings ...)
2024-10-08 9:42 ` [LTP] [PATCH v5 08/16] Add statmount02 test Andrea Cervesato
@ 2024-10-08 9:42 ` Andrea Cervesato
2024-10-08 9:42 ` [LTP] [PATCH v5 10/16] Add statmount04 test Andrea Cervesato
` (6 subsequent siblings)
15 siblings, 0 replies; 27+ messages in thread
From: Andrea Cervesato @ 2024-10-08 9:42 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] 27+ messages in thread* [LTP] [PATCH v5 10/16] Add statmount04 test
2024-10-08 9:41 [LTP] [PATCH v5 00/16] statmount/listmount testing suites Andrea Cervesato
` (8 preceding siblings ...)
2024-10-08 9:42 ` [LTP] [PATCH v5 09/16] Add statmount03 test Andrea Cervesato
@ 2024-10-08 9:42 ` Andrea Cervesato
2024-10-08 9:42 ` [LTP] [PATCH v5 11/16] Add statmount05 test Andrea Cervesato
` (5 subsequent siblings)
15 siblings, 0 replies; 27+ messages in thread
From: Andrea Cervesato @ 2024-10-08 9:42 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] 27+ messages in thread* [LTP] [PATCH v5 11/16] Add statmount05 test
2024-10-08 9:41 [LTP] [PATCH v5 00/16] statmount/listmount testing suites Andrea Cervesato
` (9 preceding siblings ...)
2024-10-08 9:42 ` [LTP] [PATCH v5 10/16] Add statmount04 test Andrea Cervesato
@ 2024-10-08 9:42 ` Andrea Cervesato
2024-10-08 12:03 ` Cyril Hrubis
2024-10-08 9:42 ` [LTP] [PATCH v5 12/16] Add statmount06 test Andrea Cervesato
` (4 subsequent siblings)
15 siblings, 1 reply; 27+ messages in thread
From: Andrea Cervesato @ 2024-10-08 9:42 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 | 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] 27+ messages in thread* Re: [LTP] [PATCH v5 11/16] Add statmount05 test
2024-10-08 9:42 ` [LTP] [PATCH v5 11/16] Add statmount05 test Andrea Cervesato
@ 2024-10-08 12:03 ` Cyril Hrubis
2024-10-08 13:57 ` Andrea Cervesato via ltp
0 siblings, 1 reply; 27+ messages in thread
From: Cyril Hrubis @ 2024-10-08 12:03 UTC (permalink / raw)
To: Andrea Cervesato; +Cc: ltp
Hi!
> +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, '/');
Wouldn't last_root = strrchr(DIRA, '/') produce the same result?
I'm just wondering why MNT_ROOT is relative and MNT_POINT is absolute
here.
> + TST_EXP_EQ_LI(st_mount->mask, STATMOUNT_MNT_ROOT);
> + TST_EXP_EQ_STR(st_mount->str + st_mount->mnt_root, last_root);
> +}
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] 27+ messages in thread* Re: [LTP] [PATCH v5 11/16] Add statmount05 test
2024-10-08 12:03 ` Cyril Hrubis
@ 2024-10-08 13:57 ` Andrea Cervesato via ltp
2024-10-08 14:11 ` Andrea Cervesato via ltp
0 siblings, 1 reply; 27+ messages in thread
From: Andrea Cervesato via ltp @ 2024-10-08 13:57 UTC (permalink / raw)
To: Cyril Hrubis, Andrea Cervesato; +Cc: ltp
Hi,
On 10/8/24 14:03, Cyril Hrubis wrote:
> Hi!
>> +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, '/');
> Wouldn't last_root = strrchr(DIRA, '/') produce the same result?
>
> I'm just wondering why MNT_ROOT is relative and MNT_POINT is absolute
> here.
Because STATMOUNT_MNT_ROOT returns the root folder and
STATMOUNT_MNT_POINT returns the mount point folder, relative to the root
folder.
>> + TST_EXP_EQ_LI(st_mount->mask, STATMOUNT_MNT_ROOT);
>> + TST_EXP_EQ_STR(st_mount->str + st_mount->mnt_root, last_root);
>> +}
> Otherwise:
> Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
>
Andrea
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 27+ messages in thread* Re: [LTP] [PATCH v5 11/16] Add statmount05 test
2024-10-08 13:57 ` Andrea Cervesato via ltp
@ 2024-10-08 14:11 ` Andrea Cervesato via ltp
0 siblings, 0 replies; 27+ messages in thread
From: Andrea Cervesato via ltp @ 2024-10-08 14:11 UTC (permalink / raw)
To: Cyril Hrubis, Andrea Cervesato; +Cc: ltp
On 10/8/24 15:57, Andrea Cervesato wrote:
> Hi,
>
> On 10/8/24 14:03, Cyril Hrubis wrote:
>> Hi!
>>> +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, '/');
>> Wouldn't last_root = strrchr(DIRA, '/') produce the same result?
>>
>> I'm just wondering why MNT_ROOT is relative and MNT_POINT is absolute
>> here.
> Because STATMOUNT_MNT_ROOT returns the root folder and
> STATMOUNT_MNT_POINT returns the mount point folder, relative to the
> root folder.
That seems like the way statmount() is working by the way. Also in the
kselftests root folder is given with a relative path, while mount point
is containing the absolute path.
>>> + TST_EXP_EQ_LI(st_mount->mask, STATMOUNT_MNT_ROOT);
>>> + TST_EXP_EQ_STR(st_mount->str + st_mount->mnt_root, last_root);
>>> +}
>> Otherwise:
>> Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
>>
> Andrea
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 27+ messages in thread
* [LTP] [PATCH v5 12/16] Add statmount06 test
2024-10-08 9:41 [LTP] [PATCH v5 00/16] statmount/listmount testing suites Andrea Cervesato
` (10 preceding siblings ...)
2024-10-08 9:42 ` [LTP] [PATCH v5 11/16] Add statmount05 test Andrea Cervesato
@ 2024-10-08 9:42 ` Andrea Cervesato
2024-10-08 9:42 ` [LTP] [PATCH v5 13/16] Add statmount07 test Andrea Cervesato
` (3 subsequent siblings)
15 siblings, 0 replies; 27+ messages in thread
From: Andrea Cervesato @ 2024-10-08 9:42 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] 27+ messages in thread* [LTP] [PATCH v5 13/16] Add statmount07 test
2024-10-08 9:41 [LTP] [PATCH v5 00/16] statmount/listmount testing suites Andrea Cervesato
` (11 preceding siblings ...)
2024-10-08 9:42 ` [LTP] [PATCH v5 12/16] Add statmount06 test Andrea Cervesato
@ 2024-10-08 9:42 ` Andrea Cervesato
2024-10-08 12:27 ` Cyril Hrubis
2024-10-08 9:42 ` [LTP] [PATCH v5 14/16] Add statmount08 test Andrea Cervesato
` (2 subsequent siblings)
15 siblings, 1 reply; 27+ messages in thread
From: Andrea Cervesato @ 2024-10-08 9:42 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 | 75 +++++++++++++++++++++++
3 files changed, 77 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..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] 27+ messages in thread* Re: [LTP] [PATCH v5 13/16] Add statmount07 test
2024-10-08 9:42 ` [LTP] [PATCH v5 13/16] Add statmount07 test Andrea Cervesato
@ 2024-10-08 12:27 ` Cyril Hrubis
0 siblings, 0 replies; 27+ messages in thread
From: Cyril Hrubis @ 2024-10-08 12:27 UTC (permalink / raw)
To: Andrea Cervesato; +Cc: ltp
Hi!
> +} 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},
I guess that we stil miss the EOVERFLOW case here with one of the
requests that yields string reply and small buffer.
> + {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
>
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 27+ messages in thread
* [LTP] [PATCH v5 14/16] Add statmount08 test
2024-10-08 9:41 [LTP] [PATCH v5 00/16] statmount/listmount testing suites Andrea Cervesato
` (12 preceding siblings ...)
2024-10-08 9:42 ` [LTP] [PATCH v5 13/16] Add statmount07 test Andrea Cervesato
@ 2024-10-08 9:42 ` Andrea Cervesato
2024-10-08 12:05 ` Cyril Hrubis
2024-10-08 9:42 ` [LTP] [PATCH v5 15/16] Add listmount03 test Andrea Cervesato
2024-10-08 9:42 ` [LTP] [PATCH v5 16/16] Add listmount04 test Andrea Cervesato
15 siblings, 1 reply; 27+ messages in thread
From: Andrea Cervesato @ 2024-10-08 9:42 UTC (permalink / raw)
To: ltp
From: Andrea Cervesato <andrea.cervesato@suse.com>
Verify that statmount() raises EPERM when mount point is not accessible.
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] 27+ messages in thread* [LTP] [PATCH v5 15/16] Add listmount03 test
2024-10-08 9:41 [LTP] [PATCH v5 00/16] statmount/listmount testing suites Andrea Cervesato
` (13 preceding siblings ...)
2024-10-08 9:42 ` [LTP] [PATCH v5 14/16] Add statmount08 test Andrea Cervesato
@ 2024-10-08 9:42 ` Andrea Cervesato
2024-10-08 12:08 ` Cyril Hrubis
2024-10-08 9:42 ` [LTP] [PATCH v5 16/16] Add listmount04 test Andrea Cervesato
15 siblings, 1 reply; 27+ messages in thread
From: Andrea Cervesato @ 2024-10-08 9:42 UTC (permalink / raw)
To: ltp
From: Andrea Cervesato <andrea.cervesato@suse.com>
Verify that listmount() raises EPERM when mount point is not accessible.
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] 27+ messages in thread* [LTP] [PATCH v5 16/16] Add listmount04 test
2024-10-08 9:41 [LTP] [PATCH v5 00/16] statmount/listmount testing suites Andrea Cervesato
` (14 preceding siblings ...)
2024-10-08 9:42 ` [LTP] [PATCH v5 15/16] Add listmount03 test Andrea Cervesato
@ 2024-10-08 9:42 ` Andrea Cervesato
2024-10-08 15:00 ` Cyril Hrubis
15 siblings, 1 reply; 27+ messages in thread
From: Andrea Cervesato @ 2024-10-08 9:42 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 req with insufficient size
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
runtest/syscalls | 1 +
testcases/kernel/syscalls/listmount/.gitignore | 1 +
testcases/kernel/syscalls/listmount/listmount04.c | 97 +++++++++++++++++++++++
3 files changed, 99 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..638bbf6fe
--- /dev/null
+++ b/testcases/kernel/syscalls/listmount/listmount04.c
@@ -0,0 +1,97 @@
+// 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 req with insufficient size
+ */
+
+#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 struct mnt_id_req *request_null;
+static struct mnt_id_req *request_small;
+static uint64_t mnt_ids[MNT_SIZE];
+
+static struct tcase {
+ struct mnt_id_req **req;
+ uint64_t *mnt_ids;
+ size_t nr_mnt_ids;
+ uint64_t flags;
+ int exp_errno;
+ char *msg;
+} tcases[] = {
+ {
+ .req = &request_null,
+ .mnt_ids = mnt_ids,
+ .nr_mnt_ids = MNT_SIZE,
+ .flags = 0,
+ .exp_errno = EFAULT,
+ .msg = "request points to unaccessible memory",
+ },
+ {
+ .req = &request,
+ .mnt_ids = NULL,
+ .nr_mnt_ids = MNT_SIZE,
+ .flags = 0,
+ .exp_errno = EFAULT,
+ .msg = "mnt_ids points to unaccessible memory",
+ },
+ {
+ .req = &request,
+ .mnt_ids = mnt_ids,
+ .nr_mnt_ids = MNT_SIZE,
+ .flags = -1,
+ .exp_errno = EINVAL,
+ .msg = "invalid flags",
+ },
+ {
+ .req = &request_small,
+ .mnt_ids = mnt_ids,
+ .nr_mnt_ids = MNT_SIZE,
+ .flags = 0,
+ .exp_errno = EINVAL,
+ .msg = "request has insufficient size",
+ },
+};
+
+static void run(unsigned int n)
+{
+ struct tcase *tc = &tcases[n];
+
+ TST_EXP_FAIL(tst_syscall(__NR_listmount, *tc->req, tc->mnt_ids,
+ tc->nr_mnt_ids, tc->flags), tc->exp_errno,
+ "%s", tc->msg);
+}
+
+static void setup(void)
+{
+ request->mnt_id = LSMT_ROOT;
+ request->size = MNT_ID_REQ_SIZE_VER0;
+ request->param = 0;
+}
+
+static struct tst_test test = {
+ .test = run,
+ .setup = setup,
+ .tcnt = ARRAY_SIZE(tcases),
+ .min_kver = "6.8",
+ .bufs = (struct tst_buffers []) {
+ { &request, .size = sizeof(struct mnt_id_req) },
+ { &request_small, .size = sizeof(struct mnt_id_req) - 4 },
+ {},
+ },
+};
--
2.43.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 27+ messages in thread* Re: [LTP] [PATCH v5 16/16] Add listmount04 test
2024-10-08 9:42 ` [LTP] [PATCH v5 16/16] Add listmount04 test Andrea Cervesato
@ 2024-10-08 15:00 ` Cyril Hrubis
2024-10-08 15:33 ` Andrea Cervesato via ltp
0 siblings, 1 reply; 27+ messages in thread
From: Cyril Hrubis @ 2024-10-08 15:00 UTC (permalink / raw)
To: Andrea Cervesato; +Cc: ltp
Hi!
> + {
> + .req = &request_small,
> + .mnt_ids = mnt_ids,
> + .nr_mnt_ids = MNT_SIZE,
> + .flags = 0,
> + .exp_errno = EINVAL,
> + .msg = "request has insufficient size",
> + },
It took me a while to realize that this is a request with .size set to
0, which is obviously rejected as invalid. Maybe it should be called
request_zero_size instead.
Also there is quite a bit more errors we can trigger, looking at
statmount kernel syscall we can easily trigger at least:
- param > 0 && param <= MNT_UNIUQE_ID_OFFSET -> EINVAL
- spare != 0 -> EINVAL
- nonexisting mnt_ns_id -> ENOENT
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 27+ messages in thread* Re: [LTP] [PATCH v5 16/16] Add listmount04 test
2024-10-08 15:00 ` Cyril Hrubis
@ 2024-10-08 15:33 ` Andrea Cervesato via ltp
2024-10-08 15:39 ` Cyril Hrubis
0 siblings, 1 reply; 27+ messages in thread
From: Andrea Cervesato via ltp @ 2024-10-08 15:33 UTC (permalink / raw)
To: Cyril Hrubis, Andrea Cervesato; +Cc: ltp
Hi,
On 10/8/24 17:00, Cyril Hrubis wrote:
> Hi!
>> + {
>> + .req = &request_small,
>> + .mnt_ids = mnt_ids,
>> + .nr_mnt_ids = MNT_SIZE,
>> + .flags = 0,
>> + .exp_errno = EINVAL,
>> + .msg = "request has insufficient size",
>> + },
> It took me a while to realize that this is a request with .size set to
> 0, which is obviously rejected as invalid. Maybe it should be called
> request_zero_size instead.
This is actually a request with a small memory size for mnt_id_req. I
remove 4 bytes allocation from the struct, so it doesn't make sense
request_zero_size.
>
> Also there is quite a bit more errors we can trigger, looking at
> statmount kernel syscall we can easily trigger at least:
>
> - param > 0 && param <= MNT_UNIUQE_ID_OFFSET -> EINVAL
> - spare != 0 -> EINVAL
> - nonexisting mnt_ns_id -> ENOENT
>
Andrea
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 27+ messages in thread* Re: [LTP] [PATCH v5 16/16] Add listmount04 test
2024-10-08 15:33 ` Andrea Cervesato via ltp
@ 2024-10-08 15:39 ` Cyril Hrubis
0 siblings, 0 replies; 27+ messages in thread
From: Cyril Hrubis @ 2024-10-08 15:39 UTC (permalink / raw)
To: Andrea Cervesato; +Cc: ltp
Hi!
> >> + {
> >> + .req = &request_small,
> >> + .mnt_ids = mnt_ids,
> >> + .nr_mnt_ids = MNT_SIZE,
> >> + .flags = 0,
> >> + .exp_errno = EINVAL,
> >> + .msg = "request has insufficient size",
> >> + },
> > It took me a while to realize that this is a request with .size set to
> > 0, which is obviously rejected as invalid. Maybe it should be called
> > request_zero_size instead.
> This is actually a request with a small memory size for mnt_id_req. I
> remove 4 bytes allocation from the struct, so it doesn't make sense
> request_zero_size.
But you pass the size as a zero, at least I do not see that you ever set
request_small->size.
> > Also there is quite a bit more errors we can trigger, looking at
> > statmount kernel syscall we can easily trigger at least:
> >
> > - param > 0 && param <= MNT_UNIUQE_ID_OFFSET -> EINVAL
> > - spare != 0 -> EINVAL
> > - nonexisting mnt_ns_id -> ENOENT
> >
> Andrea
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 27+ messages in thread