ltp.lists.linux.it archive mirror
 help / color / mirror / Atom feed
* [LTP] [PATCH v5 1/7] include/lapi: Move AT_* related macros to fcntl header
@ 2023-05-09  9:14 Yang Xu
  2023-05-09  9:14 ` [LTP] [PATCH v5 2/7] lapi/stat.h: Add STATX_DIOALIGN related definition Yang Xu
                   ` (5 more replies)
  0 siblings, 6 replies; 9+ messages in thread
From: Yang Xu @ 2023-05-09  9:14 UTC (permalink / raw)
  To: ltp

These AT* macro is belong to fcntl.h instead of stat.h.
So move them.

Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
 include/lapi/fcntl.h                          | 32 +++++++++++++----
 include/lapi/stat.h                           | 36 -------------------
 .../syscalls/mount_setattr/mount_setattr01.c  |  2 +-
 testcases/kernel/syscalls/statx/statx01.c     |  1 +
 testcases/kernel/syscalls/statx/statx02.c     |  1 +
 testcases/kernel/syscalls/statx/statx05.c     |  1 +
 testcases/kernel/syscalls/statx/statx07.c     |  1 +
 testcases/kernel/syscalls/statx/statx08.c     |  1 +
 testcases/kernel/syscalls/statx/statx09.c     |  1 +
 9 files changed, 33 insertions(+), 43 deletions(-)

diff --git a/include/lapi/fcntl.h b/include/lapi/fcntl.h
index f17220737..8fc92c521 100644
--- a/include/lapi/fcntl.h
+++ b/include/lapi/fcntl.h
@@ -87,20 +87,40 @@
 # define AT_FDCWD -100
 #endif
 
+#ifndef AT_SYMLINK_NOFOLLOW
+# define AT_SYMLINK_NOFOLLOW 	0x100
+#endif
+
+#ifndef AT_REMOVEDIR
+# define AT_REMOVEDIR 		0x200
+#endif
+
 #ifndef AT_SYMLINK_FOLLOW
-# define AT_SYMLINK_FOLLOW 0x400
+# define AT_SYMLINK_FOLLOW	0x400
 #endif
 
-#ifndef AT_SYMLINK_NOFOLLOW
-# define AT_SYMLINK_NOFOLLOW 0x100
+#ifndef AT_NO_AUTOMOUNT
+# define AT_NO_AUTOMOUNT	0x800
 #endif
 
 #ifndef AT_EMPTY_PATH
-# define AT_EMPTY_PATH 0x1000
+# define AT_EMPTY_PATH		0x1000
 #endif
 
-#ifndef AT_REMOVEDIR
-# define AT_REMOVEDIR 0x200
+#ifndef AT_STATX_SYNC_AS_STAT
+# define AT_STATX_SYNC_AS_STAT	0x0000
+#endif
+
+#ifndef AT_STATX_FORCE_SYNC
+# define AT_STATX_FORCE_SYNC	0x2000
+#endif
+
+#ifndef AT_STATX_DONT_SYNC
+# define AT_STATX_DONT_SYNC	0x4000
+#endif
+
+#ifndef AT_STATX_SYNC_TYPE
+# define AT_STATX_SYNC_TYPE	0x6000
 #endif
 
 #ifndef O_NOATIME
diff --git a/include/lapi/stat.h b/include/lapi/stat.h
index ce1f2b678..590ccd111 100644
--- a/include/lapi/stat.h
+++ b/include/lapi/stat.h
@@ -227,40 +227,4 @@ static inline int statx(int dirfd, const char *pathname, unsigned int flags,
 # define STATX_ATTR_VERITY	0x00100000
 #endif
 
-#ifndef AT_SYMLINK_NOFOLLOW
-# define AT_SYMLINK_NOFOLLOW	0x100
-#endif
-
-#ifndef AT_REMOVEDIR
-# define AT_REMOVEDIR		0x200
-#endif
-
-#ifndef AT_SYMLINK_FOLLOW
-# define AT_SYMLINK_FOLLOW	0x400
-#endif
-
-#ifndef AT_NO_AUTOMOUNT
-# define AT_NO_AUTOMOUNT	0x800
-#endif
-
-#ifndef AT_EMPTY_PATH
-# define AT_EMPTY_PATH		0x1000
-#endif
-
-#ifndef AT_STATX_SYNC_TYPE
-# define AT_STATX_SYNC_TYPE	0x6000
-#endif
-
-#ifndef AT_STATX_SYNC_AS_STAT
-# define AT_STATX_SYNC_AS_STAT	0x0000
-#endif
-
-#ifndef AT_STATX_FORCE_SYNC
-# define AT_STATX_FORCE_SYNC	0x2000
-#endif
-
-#ifndef AT_STATX_DONT_SYNC
-# define AT_STATX_DONT_SYNC	0x4000
-#endif
-
 #endif /* LAPI_STAT_H__ */
diff --git a/testcases/kernel/syscalls/mount_setattr/mount_setattr01.c b/testcases/kernel/syscalls/mount_setattr/mount_setattr01.c
index 83746b878..616ec5341 100644
--- a/testcases/kernel/syscalls/mount_setattr/mount_setattr01.c
+++ b/testcases/kernel/syscalls/mount_setattr/mount_setattr01.c
@@ -32,7 +32,7 @@
 #include <sys/statvfs.h>
 #include "tst_test.h"
 #include "lapi/fsmount.h"
-#include "lapi/stat.h"
+#include "lapi/fcntl.h"
 
 #define MNTPOINT        "mntpoint"
 #define OT_MNTPOINT     "ot_mntpoint"
diff --git a/testcases/kernel/syscalls/statx/statx01.c b/testcases/kernel/syscalls/statx/statx01.c
index 68f56549f..f9c2748d2 100644
--- a/testcases/kernel/syscalls/statx/statx01.c
+++ b/testcases/kernel/syscalls/statx/statx01.c
@@ -33,6 +33,7 @@
 #include "tst_test.h"
 #include "tst_safe_macros.h"
 #include "lapi/stat.h"
+#include "lapi/fcntl.h"
 #include "tst_safe_stdio.h"
 #include <string.h>
 #include <inttypes.h>
diff --git a/testcases/kernel/syscalls/statx/statx02.c b/testcases/kernel/syscalls/statx/statx02.c
index a8e868d7a..5ed80894d 100644
--- a/testcases/kernel/syscalls/statx/statx02.c
+++ b/testcases/kernel/syscalls/statx/statx02.c
@@ -28,6 +28,7 @@
 #include "tst_test.h"
 #include "tst_safe_macros.h"
 #include "lapi/stat.h"
+#include "lapi/fcntl.h"
 
 #define TESTFILE "test_temp"
 #define LINK_FILE "test_temp_ln"
diff --git a/testcases/kernel/syscalls/statx/statx05.c b/testcases/kernel/syscalls/statx/statx05.c
index f62dadd5c..9781b3e70 100644
--- a/testcases/kernel/syscalls/statx/statx05.c
+++ b/testcases/kernel/syscalls/statx/statx05.c
@@ -27,6 +27,7 @@
 #include "tst_test.h"
 #include "lapi/fs.h"
 #include "lapi/stat.h"
+#include "lapi/fcntl.h"
 
 #define MNTPOINT "mnt_point"
 #define TESTDIR_FLAGGED MNTPOINT"/test_dir1"
diff --git a/testcases/kernel/syscalls/statx/statx07.c b/testcases/kernel/syscalls/statx/statx07.c
index b13c11f72..f688b1b0f 100644
--- a/testcases/kernel/syscalls/statx/statx07.c
+++ b/testcases/kernel/syscalls/statx/statx07.c
@@ -39,6 +39,7 @@
 #include <sys/mount.h>
 #include "tst_test.h"
 #include "lapi/stat.h"
+#include "lapi/fcntl.h"
 
 #define MODE(X) (X & (~S_IFMT))
 #define FLAG_NAME(x) .flag = x, .flag_name = #x
diff --git a/testcases/kernel/syscalls/statx/statx08.c b/testcases/kernel/syscalls/statx/statx08.c
index 10b1ca460..64b36986d 100644
--- a/testcases/kernel/syscalls/statx/statx08.c
+++ b/testcases/kernel/syscalls/statx/statx08.c
@@ -26,6 +26,7 @@
 #include "lapi/fs.h"
 #include <stdlib.h>
 #include "lapi/stat.h"
+#include "lapi/fcntl.h"
 
 #define MOUNT_POINT "mntpoint"
 #define TESTDIR_FLAGGED MOUNT_POINT"/test_dir1"
diff --git a/testcases/kernel/syscalls/statx/statx09.c b/testcases/kernel/syscalls/statx/statx09.c
index aea329e08..c03d2c91e 100644
--- a/testcases/kernel/syscalls/statx/statx09.c
+++ b/testcases/kernel/syscalls/statx/statx09.c
@@ -24,6 +24,7 @@
 #include "lapi/fs.h"
 #include "lapi/fsverity.h"
 #include "lapi/stat.h"
+#include "lapi/fcntl.h"
 #include <inttypes.h>
 
 #define MNTPOINT "mnt_point"
-- 
2.39.1


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

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

* [LTP] [PATCH v5 2/7] lapi/stat.h: Add STATX_DIOALIGN related definition
  2023-05-09  9:14 [LTP] [PATCH v5 1/7] include/lapi: Move AT_* related macros to fcntl header Yang Xu
@ 2023-05-09  9:14 ` Yang Xu
  2023-05-09  9:14 ` [LTP] [PATCH v5 3/7] lapi/stat.h: Simplify definition Yang Xu
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: Yang Xu @ 2023-05-09  9:14 UTC (permalink / raw)
  To: ltp

Also add missing stx_mnt_id.

Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
 include/lapi/stat.h | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/include/lapi/stat.h b/include/lapi/stat.h
index 590ccd111..6ed4b6637 100644
--- a/include/lapi/stat.h
+++ b/include/lapi/stat.h
@@ -97,7 +97,11 @@ struct statx {
 	uint32_t	stx_dev_major;
 	uint32_t	stx_dev_minor;
 	/* 0x90 */
-	uint64_t	__spare2[14];
+	uint64_t	stx_mnt_id;
+	uint32_t	stx_dio_mem_align;
+	uint32_t	stx_dio_offset_align;
+	/* 0xa0 */
+	uint64_t	__spare3[12];
 	/* 0x100 */
 };
 #endif
@@ -180,6 +184,10 @@ static inline int statx(int dirfd, const char *pathname, unsigned int flags,
 # define STATX_MNT_ID		0x00001000U
 #endif
 
+#ifndef STATX_DIOALIGN
+# define STATX_DIOALIGN		0x00002000U
+#endif
+
 #ifndef STATX_ALL
 # define STATX_ALL		0x00000fffU
 #endif
-- 
2.39.1


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

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

* [LTP] [PATCH v5 3/7] lapi/stat.h: Simplify definition
  2023-05-09  9:14 [LTP] [PATCH v5 1/7] include/lapi: Move AT_* related macros to fcntl header Yang Xu
  2023-05-09  9:14 ` [LTP] [PATCH v5 2/7] lapi/stat.h: Add STATX_DIOALIGN related definition Yang Xu
@ 2023-05-09  9:14 ` Yang Xu
  2023-05-09  9:14 ` [LTP] [PATCH v5 4/7] syscalls/statx01: Relax mnt_id test condition Yang Xu
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: Yang Xu @ 2023-05-09  9:14 UTC (permalink / raw)
  To: ltp

Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
 include/lapi/stat.h | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/include/lapi/stat.h b/include/lapi/stat.h
index 6ed4b6637..e247c2159 100644
--- a/include/lapi/stat.h
+++ b/include/lapi/stat.h
@@ -11,6 +11,8 @@
 #include <stdint.h>
 #include <unistd.h>
 #include "lapi/syscalls.h"
+#include <sys/stat.h>
+
 /*
  * Timestamp structure for the timestamps in struct statx.
  *
@@ -21,9 +23,7 @@
  *
  * __reserved is held in case we need a yet finer resolution.
  */
-#if defined(HAVE_STRUCT_STATX_TIMESTAMP)
-#include <sys/stat.h>
-#else
+#ifndef HAVE_STRUCT_STATX_TIMESTAMP
 struct statx_timestamp {
 	int64_t tv_sec;
 	uint32_t tv_nsec;
@@ -67,9 +67,7 @@ struct statx_timestamp {
  * will have values installed for compatibility purposes so that stat() and
  * co. can be emulated in userspace.
  */
-#if defined(HAVE_STRUCT_STATX)
-#include <sys/stat.h>
-#else
+#ifndef HAVE_STRUCT_STATX
 struct statx {
 	/* 0x00 */
 	uint32_t	stx_mask;
@@ -106,8 +104,7 @@ struct statx {
 };
 #endif
 
-#if !defined(HAVE_STATX)
-
+#ifndef HAVE_STATX
 /*
  * statx: wrapper function of statx
  *
-- 
2.39.1


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

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

* [LTP] [PATCH v5 4/7] syscalls/statx01: Relax mnt_id test condition
  2023-05-09  9:14 [LTP] [PATCH v5 1/7] include/lapi: Move AT_* related macros to fcntl header Yang Xu
  2023-05-09  9:14 ` [LTP] [PATCH v5 2/7] lapi/stat.h: Add STATX_DIOALIGN related definition Yang Xu
  2023-05-09  9:14 ` [LTP] [PATCH v5 3/7] lapi/stat.h: Simplify definition Yang Xu
@ 2023-05-09  9:14 ` Yang Xu
  2023-05-13  0:28   ` Eric Biggers
  2023-05-09  9:14 ` [LTP] [PATCH v5 5/7] lapi/stat.h: Remove deprecated STATX_ALL macro Yang Xu
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 9+ messages in thread
From: Yang Xu @ 2023-05-09  9:14 UTC (permalink / raw)
  To: ltp

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

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

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

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


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

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

* [LTP] [PATCH v5 5/7] lapi/stat.h: Remove deprecated STATX_ALL macro
  2023-05-09  9:14 [LTP] [PATCH v5 1/7] include/lapi: Move AT_* related macros to fcntl header Yang Xu
                   ` (2 preceding siblings ...)
  2023-05-09  9:14 ` [LTP] [PATCH v5 4/7] syscalls/statx01: Relax mnt_id test condition Yang Xu
@ 2023-05-09  9:14 ` Yang Xu
  2023-05-09  9:14 ` [LTP] [PATCH v5 6/7] syscalls/statx10: Add basic test for STATX_DIOALIGN on regular file Yang Xu
  2023-05-09  9:14 ` [LTP] [PATCH v5 7/7] syscalls/statx11: Add basic test for STATX_DIOALIGN on block device Yang Xu
  5 siblings, 0 replies; 9+ messages in thread
From: Yang Xu @ 2023-05-09  9:14 UTC (permalink / raw)
  To: ltp

Since kernel 5.10-rc1 commit 581701b7efd6 ("uapi: deprecate STATX_ALL"),
this flag has been mark as deprecated.

Kernel should keep this macro for compatibility, but ltp doesn't think
about it. So remove it.

For statx06.c, we test btime, so we should STATX_BASIC_STATS | STATX_BTIME
to replace. For statx07.c, we just use STATX_BASIC_STATS is enough.

Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
 include/lapi/stat.h                       | 4 ----
 testcases/kernel/syscalls/statx/statx06.c | 4 ++--
 testcases/kernel/syscalls/statx/statx07.c | 6 +++---
 3 files changed, 5 insertions(+), 9 deletions(-)

diff --git a/include/lapi/stat.h b/include/lapi/stat.h
index e247c2159..891db33ad 100644
--- a/include/lapi/stat.h
+++ b/include/lapi/stat.h
@@ -185,10 +185,6 @@ static inline int statx(int dirfd, const char *pathname, unsigned int flags,
 # define STATX_DIOALIGN		0x00002000U
 #endif
 
-#ifndef STATX_ALL
-# define STATX_ALL		0x00000fffU
-#endif
-
 #ifndef STATX__RESERVED
 # define STATX__RESERVED	0x80000000U
 #endif
diff --git a/testcases/kernel/syscalls/statx/statx06.c b/testcases/kernel/syscalls/statx/statx06.c
index ce82b905b..60e736c5a 100644
--- a/testcases/kernel/syscalls/statx/statx06.c
+++ b/testcases/kernel/syscalls/statx/statx06.c
@@ -111,10 +111,10 @@ static void test_statx(unsigned int test_nr)
 	clock_wait_tick();
 	SAFE_CLOCK_GETTIME(CLOCK_REALTIME_COARSE, &after_time);
 
-	TEST(statx(AT_FDCWD, TEST_FILE, 0, STATX_ALL, &buff));
+	TEST(statx(AT_FDCWD, TEST_FILE, 0, STATX_BASIC_STATS | STATX_BTIME, &buff));
 	if (TST_RET != 0) {
 		tst_brk(TFAIL | TTERRNO,
-			"statx(AT_FDCWD, %s, 0, STATX_ALL, &buff)",
+			"statx(AT_FDCWD, %s, 0, STATX_BASIC_STATS | STATX_BTIME, &buff)",
 			TEST_FILE);
 	}
 
diff --git a/testcases/kernel/syscalls/statx/statx07.c b/testcases/kernel/syscalls/statx/statx07.c
index f688b1b0f..4dbf83e18 100644
--- a/testcases/kernel/syscalls/statx/statx07.c
+++ b/testcases/kernel/syscalls/statx/statx07.c
@@ -63,15 +63,15 @@ static int get_mode(char *file_name, int flag_type, char *flag_name)
 {
 	struct statx buf;
 
-	TEST(statx(AT_FDCWD, file_name, flag_type, STATX_ALL, &buf));
+	TEST(statx(AT_FDCWD, file_name, flag_type, STATX_BASIC_STATS, &buf));
 
 	if (TST_RET == -1) {
 		tst_brk(TFAIL | TST_ERR,
-			"statx(AT_FDCWD, %s, %s, STATX_ALL, &buf)",
+			"statx(AT_FDCWD, %s, %s, STATX_BASIC_STATS, &buf)",
 			file_name, flag_name);
 	}
 
-	tst_res(TINFO, "statx(AT_FDCWD, %s, %s, STATX_ALL, &buf) = %o",
+	tst_res(TINFO, "statx(AT_FDCWD, %s, %s, STATX_BASIC_STATS, &buf) = %o",
 		file_name, flag_name, buf.stx_mode);
 
 	return buf.stx_mode;
-- 
2.39.1


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

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

* [LTP] [PATCH v5 6/7] syscalls/statx10: Add basic test for STATX_DIOALIGN on regular file
  2023-05-09  9:14 [LTP] [PATCH v5 1/7] include/lapi: Move AT_* related macros to fcntl header Yang Xu
                   ` (3 preceding siblings ...)
  2023-05-09  9:14 ` [LTP] [PATCH v5 5/7] lapi/stat.h: Remove deprecated STATX_ALL macro Yang Xu
@ 2023-05-09  9:14 ` Yang Xu
  2023-05-09  9:14 ` [LTP] [PATCH v5 7/7] syscalls/statx11: Add basic test for STATX_DIOALIGN on block device Yang Xu
  5 siblings, 0 replies; 9+ messages in thread
From: Yang Xu @ 2023-05-09  9:14 UTC (permalink / raw)
  To: ltp

STATX_DIOALIGN is used to get stx_dio_mem_align and stx_dio_offset_align
for files on fs that support direct io. We just check whether these
value are nonzero on ext4 and xfs.

On ext4, files that use certain filesystem features (data journalling,
encryption, and verity) fall back to buffered I/O. But ltp creates own
filesystem by enabling mount_device in tst_test struct. If we set block
device to LTP_DEV environment, we use this block device to mount by using
default mount option. Otherwise, use loop device to simuate it. So it can
avoid these above situations and don't fall back to buffered I/O.

For struct statx member check, we only check stx_dio_mem_align because
these two member is introduced together in separate commit in kernel, so it
is safe.

Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
 configure.ac                               |   2 +-
 runtest/syscalls                           |   1 +
 testcases/kernel/syscalls/statx/.gitignore |   1 +
 testcases/kernel/syscalls/statx/statx10.c  | 103 +++++++++++++++++++++
 4 files changed, 106 insertions(+), 1 deletion(-)
 create mode 100644 testcases/kernel/syscalls/statx/statx10.c

diff --git a/configure.ac b/configure.ac
index 4c8763376..548288310 100644
--- a/configure.ac
+++ b/configure.ac
@@ -158,7 +158,7 @@ AC_CHECK_FUNCS(mkdtemp,[],AC_MSG_ERROR(mkdtemp() not found!))
 AC_CHECK_MEMBERS([struct fanotify_event_info_fid.fsid.__val],,,[#include <sys/fanotify.h>])
 AC_CHECK_MEMBERS([struct perf_event_mmap_page.aux_head],,,[#include <linux/perf_event.h>])
 AC_CHECK_MEMBERS([struct sigaction.sa_sigaction],[],[],[#include <signal.h>])
-AC_CHECK_MEMBERS([struct statx.stx_mnt_id],,,[
+AC_CHECK_MEMBERS([struct statx.stx_mnt_id, struct statx.stx_dio_mem_align],,,[
 #define _GNU_SOURCE
 #include <sys/stat.h>
 ])
diff --git a/runtest/syscalls b/runtest/syscalls
index 9c23a4248..e2548dae5 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -1765,6 +1765,7 @@ statx06 statx06
 statx07 statx07
 statx08 statx08
 statx09 statx09
+statx10 statx10
 
 membarrier01 membarrier01
 
diff --git a/testcases/kernel/syscalls/statx/.gitignore b/testcases/kernel/syscalls/statx/.gitignore
index 1cea43c0d..67341ff2d 100644
--- a/testcases/kernel/syscalls/statx/.gitignore
+++ b/testcases/kernel/syscalls/statx/.gitignore
@@ -7,3 +7,4 @@
 /statx07
 /statx08
 /statx09
+/statx10
diff --git a/testcases/kernel/syscalls/statx/statx10.c b/testcases/kernel/syscalls/statx/statx10.c
new file mode 100644
index 000000000..d52add9ed
--- /dev/null
+++ b/testcases/kernel/syscalls/statx/statx10.c
@@ -0,0 +1,103 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2023 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <xuyang2018.jy@fujitsu.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * It is a basic test for STATX_DIOALIGN mask on ext4 and xfs filesystem.
+ *
+ * - STATX_DIOALIGN   Want stx_dio_mem_align and stx_dio_offset_align value
+ *
+ * Check these two values are nonzero under dio situation when STATX_DIOALIGN
+ * in the request mask.
+ *
+ * On ext4, files that use certain filesystem features (data journaling,
+ * encryption, and verity) fall back to buffered I/O. But ltp creates own
+ * filesystem by enabling mount_device in tst_test struct. If we set block
+ * device to LTP_DEV environment, we use this block device to mount by using
+ * default mount option. Otherwise, use loop device to simuate it. So it can
+ * avoid these above situations and don't fall back to buffered I/O.
+ *
+ * Minimum Linux version required is v6.1.
+ */
+
+#define _GNU_SOURCE
+#include <sys/types.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include "tst_test.h"
+#include "lapi/stat.h"
+#include "lapi/fcntl.h"
+
+#define MNTPOINT "mnt_point"
+#define TESTFILE "testfile"
+
+static void verify_statx(void)
+{
+	struct statx buf;
+	uint32_t stx_dio_mem_align, stx_dio_offset_align;
+
+	TST_EXP_PASS_SILENT(statx(AT_FDCWD, TESTFILE, 0, STATX_DIOALIGN, &buf),
+		"statx(AT_FDCWD, %s, 0, STATX_DIOALIGN, &buf)", TESTFILE);
+
+	if (!(buf.stx_mask & STATX_DIOALIGN)) {
+		tst_res(TCONF, "Filesystem does not support STATX_DIOALIGN");
+		return;
+	}
+
+#if defined(HAVE_STRUCT_STATX) && !defined(HAVE_STRUCT_STATX_STX_DIO_MEM_ALIGN)
+  #if defined(HAVE_STRUCT_STATX_STX_MNT_ID)
+	stx_dio_mem_align = buf.__spare2 >> 32;
+	stx_dio_offset_align = buf.__spare2 & 0xffff;
+  #else
+	stx_dio_mem_align = buf.__spare2[1] >> 32;
+	stx_dio_offset_align = buf.__spare2[1] & 0xffff;
+  #endif
+#else
+	stx_dio_mem_align = buf.stx_dio_mem_align;
+	stx_dio_offset_align = buf.stx_dio_offset_align;
+#endif
+
+	if (stx_dio_mem_align != 0)
+		tst_res(TPASS, "stx_dio_mem_align:%u", stx_dio_mem_align);
+	else
+		tst_res(TFAIL, "stx_dio_mem_align was 0, but DIO should be supported");
+
+	if (stx_dio_offset_align != 0)
+		tst_res(TPASS, "stx_dio_offset_align:%u", stx_dio_offset_align);
+	else
+		tst_res(TFAIL, "stx_dio_offset_align was 0, but DIO should be supported");
+}
+
+static void setup(void)
+{
+	int fd = -1;
+
+	if (strcmp(tst_device->fs_type, "xfs") && strcmp(tst_device->fs_type, "ext4"))
+		tst_brk(TCONF, "This test only supports ext4 and xfs");
+
+	SAFE_FILE_PRINTF(TESTFILE, "AAAA");
+	fd = open(TESTFILE, O_RDWR | O_DIRECT);
+	if (fd == -1) {
+		if (errno == EINVAL)
+			tst_brk(TCONF,
+				"The regular file is not on a filesystem that support DIO");
+		else
+			tst_brk(TBROK | TERRNO,
+				"The regular file is open with O_RDWR | O_DIRECT failed");
+	}
+	SAFE_CLOSE(fd);
+}
+
+static struct tst_test test = {
+	.test_all = verify_statx,
+	.setup = setup,
+	.needs_root = 1,
+	.mntpoint = MNTPOINT,
+	.mount_device = 1,
+	.all_filesystems = 1,
+};
-- 
2.39.1


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

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

* [LTP] [PATCH v5 7/7] syscalls/statx11: Add basic test for STATX_DIOALIGN on block device
  2023-05-09  9:14 [LTP] [PATCH v5 1/7] include/lapi: Move AT_* related macros to fcntl header Yang Xu
                   ` (4 preceding siblings ...)
  2023-05-09  9:14 ` [LTP] [PATCH v5 6/7] syscalls/statx10: Add basic test for STATX_DIOALIGN on regular file Yang Xu
@ 2023-05-09  9:14 ` Yang Xu
  5 siblings, 0 replies; 9+ messages in thread
From: Yang Xu @ 2023-05-09  9:14 UTC (permalink / raw)
  To: ltp

Since STATX_DIOLAIGN is only supported on regular file and block device,
so this case is used to test the latter.

This test is tightly coupled to the kernel's current DIO restrictions on block
devices.  These changed in v6.0, and they are subject to further change in the
future.

It is fine for now because STATX_DIOALIGN is only in v6.1 and later
anyway.

Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
 runtest/syscalls                           |  1 +
 testcases/kernel/syscalls/statx/.gitignore |  1 +
 testcases/kernel/syscalls/statx/statx11.c  | 99 ++++++++++++++++++++++
 3 files changed, 101 insertions(+)
 create mode 100644 testcases/kernel/syscalls/statx/statx11.c

diff --git a/runtest/syscalls b/runtest/syscalls
index e2548dae5..e5ad2c2f9 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -1766,6 +1766,7 @@ statx07 statx07
 statx08 statx08
 statx09 statx09
 statx10 statx10
+statx11 statx11
 
 membarrier01 membarrier01
 
diff --git a/testcases/kernel/syscalls/statx/.gitignore b/testcases/kernel/syscalls/statx/.gitignore
index 67341ff2d..48ac4078b 100644
--- a/testcases/kernel/syscalls/statx/.gitignore
+++ b/testcases/kernel/syscalls/statx/.gitignore
@@ -8,3 +8,4 @@
 /statx08
 /statx09
 /statx10
+/statx11
diff --git a/testcases/kernel/syscalls/statx/statx11.c b/testcases/kernel/syscalls/statx/statx11.c
new file mode 100644
index 000000000..f32f05eff
--- /dev/null
+++ b/testcases/kernel/syscalls/statx/statx11.c
@@ -0,0 +1,99 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2023 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <xuyang2018.jy@fujitsu.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * It is a basic test for STATX_DIOALIGN mask on block device.
+ *
+ * - STATX_DIOALIGN   Want stx_dio_mem_align and stx_dio_offset_align value
+ *
+ * These two values are tightly coupled to the kernel's current DIO
+ * restrictions on block devices.
+ *
+ * Minimum Linux version required is v6.1.
+ */
+
+#define _GNU_SOURCE
+#include <sys/types.h>
+#include <sys/mount.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include "tst_test.h"
+#include "lapi/stat.h"
+
+static char sys_bdev_dma_path[1024], sys_bdev_logical_path[1024];
+
+static void verify_statx(void)
+{
+	struct statx buf;
+	uint32_t stx_dio_mem_align, stx_dio_offset_align;
+
+	TST_EXP_PASS_SILENT(statx(AT_FDCWD, tst_device->dev, 0, STATX_DIOALIGN, &buf),
+		"statx(AT_FDCWD, %s, 0, STATX_DIOALIGN, &buf)", tst_device->dev);
+
+	if (!(buf.stx_mask & STATX_DIOALIGN)) {
+		tst_res(TCONF, "Filesystem does not support STATX_DIOALIGN");
+		return;
+	}
+
+#if defined(HAVE_STRUCT_STATX) && !defined(HAVE_STRUCT_STATX_STX_DIO_MEM_ALIGN)
+  #if defined(HAVE_STRUCT_STATX_STX_MNT_ID)
+	stx_dio_mem_align = buf.__spare2 >> 32;
+	stx_dio_offset_align = buf.__spare2 & 0xffff;
+  #else
+	stx_dio_mem_align = buf.__spare2[1] >> 32;
+	stx_dio_offset_align = buf.__spare2[1] & 0xffff;
+  #endif
+#else
+	stx_dio_mem_align = buf.stx_dio_mem_align;
+	stx_dio_offset_align = buf.stx_dio_offset_align;
+#endif
+
+	/*
+	 * This test is tightly coupled to the kernel's current DIO restrictions
+	 * on block devices. The general rule of DIO needing to be aligned to the
+	 * block device's logical block size was relaxed to allow user buffers
+	 * (but not file offsets) aligned to the DMA alignment instead. See v6.0
+	 * commit bf8d08532bc1 ("iomap: add support for dma aligned direct-io") and
+	 * they are subject to further change in the future.
+	 * Also can see commit 2d985f8c6b9 ("vfs: support STATX_DIOALIGN on block devices).
+	 */
+	TST_ASSERT_ULONG(sys_bdev_dma_path, stx_dio_mem_align - 1);
+	TST_ASSERT_ULONG(sys_bdev_logical_path, stx_dio_offset_align);
+}
+
+static void setup(void)
+{
+	char full_name[256];
+	char *dev_name;
+
+	strcpy(full_name, tst_device->dev);
+	dev_name = SAFE_BASENAME(full_name);
+	sprintf(sys_bdev_logical_path, "/sys/block/%s/queue/logical_block_size", dev_name);
+
+	/*
+	 * Since /sys/block/%s/queue doesn't exist for partition, we need to
+	 * use a while to search block device instead of partition.
+	 */
+	while (access(sys_bdev_logical_path, F_OK) != 0) {
+		dev_name[strlen(dev_name)-1] = '\0';
+		sprintf(sys_bdev_logical_path, "/sys/block/%s/queue/logical_block_size", dev_name);
+	}
+
+	sprintf(sys_bdev_dma_path, "/sys/block/%s/queue/dma_alignment", dev_name);
+	if (access(sys_bdev_dma_path, F_OK) != 0)
+		tst_brk(TCONF, "dma_alignment sysfs file doesn't exist");
+}
+
+static struct tst_test test = {
+	.test_all = verify_statx,
+	.setup = setup,
+	.needs_device = 1,
+	.needs_root = 1,
+};
-- 
2.39.1


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

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

* Re: [LTP] [PATCH v5 4/7] syscalls/statx01: Relax mnt_id test condition
  2023-05-09  9:14 ` [LTP] [PATCH v5 4/7] syscalls/statx01: Relax mnt_id test condition Yang Xu
@ 2023-05-13  0:28   ` Eric Biggers
  2023-05-15  6:26     ` Yang Xu (Fujitsu)
  0 siblings, 1 reply; 9+ messages in thread
From: Eric Biggers @ 2023-05-13  0:28 UTC (permalink / raw)
  To: Yang Xu; +Cc: ltp

Hi Yang,

On Tue, May 09, 2023 at 05:14:05PM +0800, Yang Xu wrote:
> Before this patch, we test stx_mnt_id only when glibc's statx struct has
> this member. Now, if glibc miss this filed, we will use __spare2[0], see
> url[1]. If glibc miss statx struct, we will use ltp owner definition.

I don't think this is the right approach either.  Actually, this new proposal is
arguably worse than leaving the problem unsolved.  The problem with this new
proposal is that the fields in struct statx whose names are prefixed with
"__spare" were never intended to be used directly.  Their names can change from
one kernel version to the next, and they can change to a different offset and/or
size while keeping the same name.  That can result in breakages that only
reproduce on very specific versions of <sys/stat.h>.

As I've said several times, the proper way to ensure that the tests can be built
even when the system struct statx doesn't contain all the needed fields is to
use the LTP struct statx whenever the system one does not fully suffice.

One way to do that would be to make the tests use the struct via a different
name, such as struct ltp_statx, and define that to either the system statx or
the LTP statx depending on which one has the right definition.

It might also be possible to #define statx to achieve the same effect (though
maybe that would cause a collision with the function statx()...)

Anyway, I don't want to derail the STATX_DIOALIGN test too much, so if you're
having a lot of trouble solving this problem properly, I'm okay with just
adding the STATX_DIOALIGN test without it solved for now...

- Eric

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

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

* Re: [LTP] [PATCH v5 4/7] syscalls/statx01: Relax mnt_id test condition
  2023-05-13  0:28   ` Eric Biggers
@ 2023-05-15  6:26     ` Yang Xu (Fujitsu)
  0 siblings, 0 replies; 9+ messages in thread
From: Yang Xu (Fujitsu) @ 2023-05-15  6:26 UTC (permalink / raw)
  To: Eric Biggers; +Cc: ltp

Hi Eric


> Hi Yang,
> 
> On Tue, May 09, 2023 at 05:14:05PM +0800, Yang Xu wrote:
>> Before this patch, we test stx_mnt_id only when glibc's statx struct has
>> this member. Now, if glibc miss this filed, we will use __spare2[0], see
>> url[1]. If glibc miss statx struct, we will use ltp owner definition.
> 
> I don't think this is the right approach either.  Actually, this new proposal is
> arguably worse than leaving the problem unsolved.  The problem with this new
> proposal is that the fields in struct statx whose names are prefixed with
> "__spare" were never intended to be used directly.  Their names can change from
> one kernel version to the next, and they can change to a different offset and/or
> size while keeping the same name.  That can result in breakages that only
> reproduce on very specific versions of <sys/stat.h>.
> 

Ok, understood.

> As I've said several times, the proper way to ensure that the tests can be built
> even when the system struct statx doesn't contain all the needed fields is to
> use the LTP struct statx whenever the system one does not fully suffice.
> 
> One way to do that would be to make the tests use the struct via a different
> name, such as struct ltp_statx, and define that to either the system statx or
> the LTP statx depending on which one has the right definition.

Yes, use ltp_statx struct is a better sloution.

> 
> It might also be possible to #define statx to achieve the same effect (though
> maybe that would cause a collision with the function statx()...)

Indeed, it will report warning as below:
note: expected ‘struct statx * restrict’ but argument is of type ‘struct 
ltp_statx *’\

I change code as below:
+#if !defined(HAVE_STRUCT_STATX) ||  \
+    !defined(HAVE_STRUCT_STATX_MNT_ID) || \
+    !defined(HAVE_STRUCT_STATX_STX_DIO_MEM_ALIGN)
+struct ltp_statx {
         /* 0x00 */
         uint32_t        stx_mask;
         uint32_t        stx_blksize;
@@ -102,6 +104,8 @@ struct statx {
         uint64_t        __spare3[12];
         /* 0x100 */
  };
+#else
+#define ltp_statx statx;



> 
> Anyway, I don't want to derail the STATX_DIOALIGN test too much, so if you're
> having a lot of trouble solving this problem properly, I'm okay with just
> adding the STATX_DIOALIGN test without it solved for now...

In fact, I just want to leave run or not run this case on glibc header 
ie  I do in testing mnt_id[1]. It is simple and clean alough it will 
miss some overage if using a custom new kernel and old glibc. In other 
situation(ie various offical linux distributions), it should work well.


So I will send a v6 that simply just use #ifndef 
HAVE_STRUCT_STATX_STX_DIO_MEM_ALIGN.

[1]https://github.com/linux-test-project/ltp/commit/0578cfb3dc175426aff516025b3ca76103e5f551

Best Regards
Yang Xu
> 
> - Eric

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

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

end of thread, other threads:[~2023-05-15  6:26 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-09  9:14 [LTP] [PATCH v5 1/7] include/lapi: Move AT_* related macros to fcntl header Yang Xu
2023-05-09  9:14 ` [LTP] [PATCH v5 2/7] lapi/stat.h: Add STATX_DIOALIGN related definition Yang Xu
2023-05-09  9:14 ` [LTP] [PATCH v5 3/7] lapi/stat.h: Simplify definition Yang Xu
2023-05-09  9:14 ` [LTP] [PATCH v5 4/7] syscalls/statx01: Relax mnt_id test condition Yang Xu
2023-05-13  0:28   ` Eric Biggers
2023-05-15  6:26     ` Yang Xu (Fujitsu)
2023-05-09  9:14 ` [LTP] [PATCH v5 5/7] lapi/stat.h: Remove deprecated STATX_ALL macro Yang Xu
2023-05-09  9:14 ` [LTP] [PATCH v5 6/7] syscalls/statx10: Add basic test for STATX_DIOALIGN on regular file Yang Xu
2023-05-09  9:14 ` [LTP] [PATCH v5 7/7] syscalls/statx11: Add basic test for STATX_DIOALIGN on block device Yang Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).