ltp.lists.linux.it archive mirror
 help / color / mirror / Atom feed
* [LTP] [PATCH v6 1/6] include/lapi: Move AT_* related macros to fcntl header
@ 2023-05-15  7:11 Yang Xu
  2023-05-15  7:11 ` [LTP] [PATCH v6 2/6] lapi/stat.h: Add STATX_DIOALIGN related definition Yang Xu
                   ` (5 more replies)
  0 siblings, 6 replies; 16+ messages in thread
From: Yang Xu @ 2023-05-15  7:11 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] 16+ messages in thread

* [LTP] [PATCH v6 2/6] lapi/stat.h: Add STATX_DIOALIGN related definition
  2023-05-15  7:11 [LTP] [PATCH v6 1/6] include/lapi: Move AT_* related macros to fcntl header Yang Xu
@ 2023-05-15  7:11 ` Yang Xu
  2023-05-18  6:10   ` Xiao Yang (Fujitsu)
  2023-05-15  7:11 ` [LTP] [PATCH v6 3/6] lapi/stat.h: Simplify definition Yang Xu
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 16+ messages in thread
From: Yang Xu @ 2023-05-15  7:11 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] 16+ messages in thread

* [LTP] [PATCH v6 3/6] lapi/stat.h: Simplify definition
  2023-05-15  7:11 [LTP] [PATCH v6 1/6] include/lapi: Move AT_* related macros to fcntl header Yang Xu
  2023-05-15  7:11 ` [LTP] [PATCH v6 2/6] lapi/stat.h: Add STATX_DIOALIGN related definition Yang Xu
@ 2023-05-15  7:11 ` Yang Xu
  2023-05-18  6:24   ` Xiao Yang (Fujitsu)
  2023-05-15  7:11 ` [LTP] [PATCH v6 4/6] lapi/stat.h: Remove deprecated STATX_ALL macro Yang Xu
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 16+ messages in thread
From: Yang Xu @ 2023-05-15  7:11 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] 16+ messages in thread

* [LTP] [PATCH v6 4/6] lapi/stat.h: Remove deprecated STATX_ALL macro
  2023-05-15  7:11 [LTP] [PATCH v6 1/6] include/lapi: Move AT_* related macros to fcntl header Yang Xu
  2023-05-15  7:11 ` [LTP] [PATCH v6 2/6] lapi/stat.h: Add STATX_DIOALIGN related definition Yang Xu
  2023-05-15  7:11 ` [LTP] [PATCH v6 3/6] lapi/stat.h: Simplify definition Yang Xu
@ 2023-05-15  7:11 ` Yang Xu
  2023-05-18  7:34   ` Xiao Yang (Fujitsu)
  2023-05-15  7:11 ` [LTP] [PATCH v6 5/6] syscalls/statx10: Add basic test for STATX_DIOALIGN on regular file Yang Xu
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 16+ messages in thread
From: Yang Xu @ 2023-05-15  7:11 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] 16+ messages in thread

* [LTP] [PATCH v6 5/6] syscalls/statx10: Add basic test for STATX_DIOALIGN on regular file
  2023-05-15  7:11 [LTP] [PATCH v6 1/6] include/lapi: Move AT_* related macros to fcntl header Yang Xu
                   ` (2 preceding siblings ...)
  2023-05-15  7:11 ` [LTP] [PATCH v6 4/6] lapi/stat.h: Remove deprecated STATX_ALL macro Yang Xu
@ 2023-05-15  7:11 ` Yang Xu
  2023-05-19  6:24   ` Xiao Yang (Fujitsu)
  2023-05-15  7:11 ` [LTP] [PATCH v6 6/6] syscalls/statx11: Add basic test for STATX_DIOALIGN on block device Yang Xu
  2023-05-18  6:00 ` [LTP] [PATCH v6 1/6] include/lapi: Move AT_* related macros to fcntl header Xiao Yang (Fujitsu)
  5 siblings, 1 reply; 16+ messages in thread
From: Yang Xu @ 2023-05-15  7:11 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  | 93 ++++++++++++++++++++++
 4 files changed, 96 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..513a8c262
--- /dev/null
+++ b/testcases/kernel/syscalls/statx/statx10.c
@@ -0,0 +1,93 @@
+// 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;
+
+	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;
+	}
+
+#ifdef HAVE_STRUCT_STATX_STX_DIO_MEM_ALIGN
+	if (buf.stx_dio_mem_align != 0)
+		tst_res(TPASS, "stx_dio_mem_align:%u", buf.stx_dio_mem_align);
+	else
+		tst_res(TFAIL, "stx_dio_mem_align was 0, but DIO should be supported");
+
+	if (buf.stx_dio_offset_align != 0)
+		tst_res(TPASS, "stx_dio_offset_align:%u", buf.stx_dio_offset_align);
+	else
+		tst_res(TFAIL, "stx_dio_offset_align was 0, but DIO should be supported");
+#else
+	tst_res(TCONF, "glibc statx struct miss stx_dio_mem_align field");
+#endif
+}
+
+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] 16+ messages in thread

* [LTP] [PATCH v6 6/6] syscalls/statx11: Add basic test for STATX_DIOALIGN on block device
  2023-05-15  7:11 [LTP] [PATCH v6 1/6] include/lapi: Move AT_* related macros to fcntl header Yang Xu
                   ` (3 preceding siblings ...)
  2023-05-15  7:11 ` [LTP] [PATCH v6 5/6] syscalls/statx10: Add basic test for STATX_DIOALIGN on regular file Yang Xu
@ 2023-05-15  7:11 ` Yang Xu
  2023-05-19  6:24   ` Xiao Yang (Fujitsu)
  2023-05-18  6:00 ` [LTP] [PATCH v6 1/6] include/lapi: Move AT_* related macros to fcntl header Xiao Yang (Fujitsu)
  5 siblings, 1 reply; 16+ messages in thread
From: Yang Xu @ 2023-05-15  7:11 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  | 89 ++++++++++++++++++++++
 3 files changed, 91 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..653050855
--- /dev/null
+++ b/testcases/kernel/syscalls/statx/statx11.c
@@ -0,0 +1,89 @@
+// 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;
+
+	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;
+	}
+
+#ifdef HAVE_STRUCT_STATX_STX_DIO_MEM_ALIGN
+	/*
+	 * 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, buf.stx_dio_mem_align - 1);
+	TST_ASSERT_ULONG(sys_bdev_logical_path, buf.stx_dio_offset_align);
+#else
+	tst_res(TCONF, "glibc statx struct miss stx_dio_mem_align field");
+#endif
+}
+
+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] 16+ messages in thread

* Re: [LTP] [PATCH v6 1/6] include/lapi: Move AT_* related macros to fcntl header
  2023-05-15  7:11 [LTP] [PATCH v6 1/6] include/lapi: Move AT_* related macros to fcntl header Yang Xu
                   ` (4 preceding siblings ...)
  2023-05-15  7:11 ` [LTP] [PATCH v6 6/6] syscalls/statx11: Add basic test for STATX_DIOALIGN on block device Yang Xu
@ 2023-05-18  6:00 ` Xiao Yang (Fujitsu)
  5 siblings, 0 replies; 16+ messages in thread
From: Xiao Yang (Fujitsu) @ 2023-05-18  6:00 UTC (permalink / raw)
  To: Yang Xu (Fujitsu), ltp

On 2023/5/15 15:11, Yang Xu wrote:
> 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"Hi Xu

It seems unnecessary here because "lapi/fsmount.h" has included 
"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"

I hope we can add "lapi/fcntl.h" for all statx tests because AT_FDCWD 
macro which may not be defined is used by all tests.

> 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"

Other than that looks good to me.
Reviewed-by: Xiao Yang <yangx.jy@fujitsu.com>

Best Regards,
Xiao Yang

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

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

* Re: [LTP] [PATCH v6 2/6] lapi/stat.h: Add STATX_DIOALIGN related definition
  2023-05-15  7:11 ` [LTP] [PATCH v6 2/6] lapi/stat.h: Add STATX_DIOALIGN related definition Yang Xu
@ 2023-05-18  6:10   ` Xiao Yang (Fujitsu)
  2023-05-19  6:26     ` Xiao Yang (Fujitsu)
  0 siblings, 1 reply; 16+ messages in thread
From: Xiao Yang (Fujitsu) @ 2023-05-18  6:10 UTC (permalink / raw)
  To: Yang Xu (Fujitsu), ltp

Hi Xu

LGTM.
Reviewed-by: Xiao Yang <yangx.jy@fujitsu.com>

Best Regards,
Xiao Yang

On 2023/5/15 15:11, Yang Xu wrote:
> 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

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

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

* Re: [LTP] [PATCH v6 3/6] lapi/stat.h: Simplify definition
  2023-05-15  7:11 ` [LTP] [PATCH v6 3/6] lapi/stat.h: Simplify definition Yang Xu
@ 2023-05-18  6:24   ` Xiao Yang (Fujitsu)
  0 siblings, 0 replies; 16+ messages in thread
From: Xiao Yang (Fujitsu) @ 2023-05-18  6:24 UTC (permalink / raw)
  To: Yang Xu (Fujitsu), ltp

Hi Xu

LGTM.
Reviewed-by: Xiao Yang <yangx.jy@fujitsu.com>

Best Regards,
Xiao Yang

On 2023/5/15 15:11, Yang Xu wrote:
> 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
>    *

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

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

* Re: [LTP] [PATCH v6 4/6] lapi/stat.h: Remove deprecated STATX_ALL macro
  2023-05-15  7:11 ` [LTP] [PATCH v6 4/6] lapi/stat.h: Remove deprecated STATX_ALL macro Yang Xu
@ 2023-05-18  7:34   ` Xiao Yang (Fujitsu)
  0 siblings, 0 replies; 16+ messages in thread
From: Xiao Yang (Fujitsu) @ 2023-05-18  7:34 UTC (permalink / raw)
  To: Yang Xu (Fujitsu), ltp

On 2023/5/15 15:11, Yang Xu wrote:
> 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.
> 
Hi Xu,

> 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.

One minor comment here:
statx06.c verifies various timestamps including stx_btime so we should 
call STATX_BASIC_STATS | STATX_BTIME.
statx07.c just needs to get stx_mode so STATX_BASIC_STATS is enough.

Other than that looks good to me.
Reviewed-by: Xiao Yang <yangx.jy@fujitsu.com>

Best Regards,
Xiao Yang
> 
> 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;

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

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

* Re: [LTP] [PATCH v6 5/6] syscalls/statx10: Add basic test for STATX_DIOALIGN on regular file
  2023-05-15  7:11 ` [LTP] [PATCH v6 5/6] syscalls/statx10: Add basic test for STATX_DIOALIGN on regular file Yang Xu
@ 2023-05-19  6:24   ` Xiao Yang (Fujitsu)
  2023-05-19  6:45     ` Yang Xu (Fujitsu)
  0 siblings, 1 reply; 16+ messages in thread
From: Xiao Yang (Fujitsu) @ 2023-05-19  6:24 UTC (permalink / raw)
  To: Yang Xu (Fujitsu), ltp

On 2023/5/15 15:11, Yang Xu wrote:
> 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  | 93 ++++++++++++++++++++++
>   4 files changed, 96 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..513a8c262
> --- /dev/null
> +++ b/testcases/kernel/syscalls/statx/statx10.c
> @@ -0,0 +1,93 @@
> +// 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"
Hi Xu,

I think you should use #define TESTFILE MNTPOINT"/testfile" instead.

> +
> +static void verify_statx(void)
> +{
> +	struct statx buf;
> +
> +	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;
> +	}
> +
> +#ifdef HAVE_STRUCT_STATX_STX_DIO_MEM_ALIGN
> +	if (buf.stx_dio_mem_align != 0)
> +		tst_res(TPASS, "stx_dio_mem_align:%u", buf.stx_dio_mem_align);
> +	else
> +		tst_res(TFAIL, "stx_dio_mem_align was 0, but DIO should be supported");
> +
> +	if (buf.stx_dio_offset_align != 0)
> +		tst_res(TPASS, "stx_dio_offset_align:%u", buf.stx_dio_offset_align);
> +	else
> +		tst_res(TFAIL, "stx_dio_offset_align was 0, but DIO should be supported");
> +#else
> +	tst_res(TCONF, "glibc statx struct miss stx_dio_mem_align field");
> +#endif
> +}
> +
> +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,
> +};
Is it necessary to use all_filesystems? because this test can be run on 
only ext4 and xfs filesystem. It's OK for me if we don't have any better 
way.

Other than that looks good to me.
Reviewed-by: Xiao Yang <yangx.jy@fujitsu.com>

Best Regards,
Xiao Yang

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

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

* Re: [LTP] [PATCH v6 6/6] syscalls/statx11: Add basic test for STATX_DIOALIGN on block device
  2023-05-15  7:11 ` [LTP] [PATCH v6 6/6] syscalls/statx11: Add basic test for STATX_DIOALIGN on block device Yang Xu
@ 2023-05-19  6:24   ` Xiao Yang (Fujitsu)
  2023-05-19  9:06     ` Yang Xu (Fujitsu)
  0 siblings, 1 reply; 16+ messages in thread
From: Xiao Yang (Fujitsu) @ 2023-05-19  6:24 UTC (permalink / raw)
  To: Yang Xu (Fujitsu), ltp

Hi Xu

LGTM.
Reviewed-by: Xiao Yang <yangx.jy@fujitsu.com>

Best Regards,
Xiao Yang

On 2023/5/15 15:11, Yang Xu wrote:
> 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  | 89 ++++++++++++++++++++++
>   3 files changed, 91 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..653050855
> --- /dev/null
> +++ b/testcases/kernel/syscalls/statx/statx11.c
> @@ -0,0 +1,89 @@
> +// 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;
> +
> +	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;
> +	}
> +
> +#ifdef HAVE_STRUCT_STATX_STX_DIO_MEM_ALIGN
> +	/*
> +	 * 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, buf.stx_dio_mem_align - 1);
> +	TST_ASSERT_ULONG(sys_bdev_logical_path, buf.stx_dio_offset_align);
> +#else
> +	tst_res(TCONF, "glibc statx struct miss stx_dio_mem_align field");
> +#endif
> +}
> +
> +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,
> +};

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

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

* Re: [LTP] [PATCH v6 2/6] lapi/stat.h: Add STATX_DIOALIGN related definition
  2023-05-18  6:10   ` Xiao Yang (Fujitsu)
@ 2023-05-19  6:26     ` Xiao Yang (Fujitsu)
  2023-05-19  6:48       ` Yang Xu (Fujitsu)
  0 siblings, 1 reply; 16+ messages in thread
From: Xiao Yang (Fujitsu) @ 2023-05-19  6:26 UTC (permalink / raw)
  To: Yang Xu (Fujitsu), ltp

On 2023/5/18 14:10, Xiao Yang (Fujitsu) wrote:
> Hi Xu
> 
> LGTM.
> Reviewed-by: Xiao Yang <yangx.jy@fujitsu.com>
> 
> Best Regards,
> Xiao Yang
> 
> On 2023/5/15 15:11, Yang Xu wrote:
>> 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];
Hi Xu,

After looking into the logic of statx10 and statx11, I think it's 
unnecessary to add these new members into struct statx.

Best Regards,
Xiao Yang

>>    	/* 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
> 

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

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

* Re: [LTP] [PATCH v6 5/6] syscalls/statx10: Add basic test for STATX_DIOALIGN on regular file
  2023-05-19  6:24   ` Xiao Yang (Fujitsu)
@ 2023-05-19  6:45     ` Yang Xu (Fujitsu)
  0 siblings, 0 replies; 16+ messages in thread
From: Yang Xu (Fujitsu) @ 2023-05-19  6:45 UTC (permalink / raw)
  To: Xiao Yang (Fujitsu), ltp



on 2023/05/19 14:24, Yang, Xiao/杨 晓 wrote:
> On 2023/5/15 15:11, Yang Xu wrote:
>> 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  | 93 ++++++++++++++++++++++
>>    4 files changed, 96 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..513a8c262
>> --- /dev/null
>> +++ b/testcases/kernel/syscalls/statx/statx10.c
>> @@ -0,0 +1,93 @@
>> +// 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"
> Hi Xu,
> 
> I think you should use #define TESTFILE MNTPOINT"/testfile" instead.

Yes, good catch.
> 
>> +
>> +static void verify_statx(void)
>> +{
>> +	struct statx buf;
>> +
>> +	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;
>> +	}
>> +
>> +#ifdef HAVE_STRUCT_STATX_STX_DIO_MEM_ALIGN
>> +	if (buf.stx_dio_mem_align != 0)
>> +		tst_res(TPASS, "stx_dio_mem_align:%u", buf.stx_dio_mem_align);
>> +	else
>> +		tst_res(TFAIL, "stx_dio_mem_align was 0, but DIO should be supported");
>> +
>> +	if (buf.stx_dio_offset_align != 0)
>> +		tst_res(TPASS, "stx_dio_offset_align:%u", buf.stx_dio_offset_align);
>> +	else
>> +		tst_res(TFAIL, "stx_dio_offset_align was 0, but DIO should be supported");
>> +#else
>> +	tst_res(TCONF, "glibc statx struct miss stx_dio_mem_align field");
>> +#endif
>> +}
>> +
>> +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,
>> +};
> Is it necessary to use all_filesystems? because this test can be run on
> only ext4 and xfs filesystem. It's OK for me if we don't have any better
> way.

AFAIK, we only have a blacklist for skip_filesystem and maybe I can 
introduce a whitelist for this situation.

Best Regards
Yang Xu
> 
> Other than that looks good to me.
> Reviewed-by: Xiao Yang <yangx.jy@fujitsu.com>
> 
> Best Regards,
> Xiao Yang

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

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

* Re: [LTP] [PATCH v6 2/6] lapi/stat.h: Add STATX_DIOALIGN related definition
  2023-05-19  6:26     ` Xiao Yang (Fujitsu)
@ 2023-05-19  6:48       ` Yang Xu (Fujitsu)
  0 siblings, 0 replies; 16+ messages in thread
From: Yang Xu (Fujitsu) @ 2023-05-19  6:48 UTC (permalink / raw)
  To: Xiao Yang (Fujitsu), ltp



on 2023/05/19 14:26, Yang, Xiao/杨 晓 wrote:
> On 2023/5/18 14:10, Xiao Yang (Fujitsu) wrote:
>> Hi Xu
>>
>> LGTM.
>> Reviewed-by: Xiao Yang <yangx.jy@fujitsu.com>
>>
>> Best Regards,
>> Xiao Yang
>>
>> On 2023/5/15 15:11, Yang Xu wrote:
>>> 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];
> Hi Xu,
> 
> After looking into the logic of statx10 and statx11, I think it's
> unnecessary to add these new members into struct statx.

Agree. Let glibc decide whether to run these cases sounds more meaingful 
and clean, will remove it.

Best Regards
Yang Xu
> 
> Best Regards,
> Xiao Yang
> 
>>>     	/* 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

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

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

* Re: [LTP] [PATCH v6 6/6] syscalls/statx11: Add basic test for STATX_DIOALIGN on block device
  2023-05-19  6:24   ` Xiao Yang (Fujitsu)
@ 2023-05-19  9:06     ` Yang Xu (Fujitsu)
  0 siblings, 0 replies; 16+ messages in thread
From: Yang Xu (Fujitsu) @ 2023-05-19  9:06 UTC (permalink / raw)
  To: Xiao Yang (Fujitsu), ltp

Hi Yang


I have modified this patch set as you suggested and merged.

Thanks for your review.

Best Regards
Yang Xu
> Hi Xu
> 
> LGTM.
> Reviewed-by: Xiao Yang <yangx.jy@fujitsu.com>
> 
> Best Regards,
> Xiao Yang
> 
> On 2023/5/15 15:11, Yang Xu wrote:
>> 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  | 89 ++++++++++++++++++++++
>>    3 files changed, 91 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..653050855
>> --- /dev/null
>> +++ b/testcases/kernel/syscalls/statx/statx11.c
>> @@ -0,0 +1,89 @@
>> +// 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;
>> +
>> +	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;
>> +	}
>> +
>> +#ifdef HAVE_STRUCT_STATX_STX_DIO_MEM_ALIGN
>> +	/*
>> +	 * 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, buf.stx_dio_mem_align - 1);
>> +	TST_ASSERT_ULONG(sys_bdev_logical_path, buf.stx_dio_offset_align);
>> +#else
>> +	tst_res(TCONF, "glibc statx struct miss stx_dio_mem_align field");
>> +#endif
>> +}
>> +
>> +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,
>> +};

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

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

end of thread, other threads:[~2023-05-19  9:06 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-15  7:11 [LTP] [PATCH v6 1/6] include/lapi: Move AT_* related macros to fcntl header Yang Xu
2023-05-15  7:11 ` [LTP] [PATCH v6 2/6] lapi/stat.h: Add STATX_DIOALIGN related definition Yang Xu
2023-05-18  6:10   ` Xiao Yang (Fujitsu)
2023-05-19  6:26     ` Xiao Yang (Fujitsu)
2023-05-19  6:48       ` Yang Xu (Fujitsu)
2023-05-15  7:11 ` [LTP] [PATCH v6 3/6] lapi/stat.h: Simplify definition Yang Xu
2023-05-18  6:24   ` Xiao Yang (Fujitsu)
2023-05-15  7:11 ` [LTP] [PATCH v6 4/6] lapi/stat.h: Remove deprecated STATX_ALL macro Yang Xu
2023-05-18  7:34   ` Xiao Yang (Fujitsu)
2023-05-15  7:11 ` [LTP] [PATCH v6 5/6] syscalls/statx10: Add basic test for STATX_DIOALIGN on regular file Yang Xu
2023-05-19  6:24   ` Xiao Yang (Fujitsu)
2023-05-19  6:45     ` Yang Xu (Fujitsu)
2023-05-15  7:11 ` [LTP] [PATCH v6 6/6] syscalls/statx11: Add basic test for STATX_DIOALIGN on block device Yang Xu
2023-05-19  6:24   ` Xiao Yang (Fujitsu)
2023-05-19  9:06     ` Yang Xu (Fujitsu)
2023-05-18  6:00 ` [LTP] [PATCH v6 1/6] include/lapi: Move AT_* related macros to fcntl header Xiao Yang (Fujitsu)

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).