[PATCH v1] src/stat_test.c: add STATX_DIOALIGN support

[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]



From: Boyang Xue <bxue@xxxxxxxxxx>

Signed-off-by: Boyang Xue <bxue@xxxxxxxxxx>
---
Hi,

The latest kernel has support for exposing direct I/O alignment
information via statx() by

825cf206ed51 statx: add direct I/O alignment information

I'm trying to enhance xfstests/src/stat_test.c to support this
functionality, and the final goal is enhancing generic/423 to test it.

I think I have made all the necessary change here, but it always prints
stx_dio_mem_align and stx_dio_offset_align as 0 (should be 512)

[root@localhost repo_xfstests-dev]# src/stat_test -v
../testfile stx_dio_offset_align=222
 - call statx ../testfile
 - call stat ../testfile
 - compare statx and stat
 - begin time 0.000000000
 -      btime 1672804449.041990601
 -      atime 1672804449.041990601
 -      mtime 1672804449.127990601
 -      ctime 1672804449.127990601
 - check stx_dio_offset_align=222
[!] stx_dio_offset_align differs, 0 != 222
Failed

 src/stat_test.c | 10 ++++++++++
 src/statx.h     | 10 ++++++++--
 2 files changed, 18 insertions(+), 2 deletions(-)

The kernel version in test is kernel-6.2.0-0.rc1.

Could you suggest how to fix it please?

Thanks,
Boyang

diff --git a/src/stat_test.c b/src/stat_test.c
index 95cfdc4f..cd38a54a 100644
--- a/src/stat_test.c
+++ b/src/stat_test.c
@@ -42,6 +42,8 @@ enum fields {
 	stx_ctime_tv_sec,
 	stx_dev_major,
 	stx_dev_minor,
+	stx_dio_mem_align,
+	stx_dio_offset_align,
 	stx_gid,
 	stx_ino,
 	stx_mask,
@@ -77,6 +79,8 @@ static const struct field field_list[nr__fields] = {
 	[stx_ctime_tv_sec]	= { "stx_ctime.tv_sec",		STATX_CTIME },
 	[stx_dev_major]		= { "stx_dev_major",		0 },
 	[stx_dev_minor]		= { "stx_dev_minor",		0 },
+	[stx_dio_mem_align]	= { "stx_dio_mem_align",	STATX_DIOALIGN },
+	[stx_dio_offset_align]	= { "stx_dio_offset_align",	STATX_DIOALIGN },
 	[stx_gid]		= { "stx_gid",			STATX_GID },
 	[stx_ino]		= { "stx_ino",			STATX_INO },
 	[stx_mask]		= { "stx_mask",			0 },
@@ -460,6 +464,8 @@ static void cmp_ref(const struct statx *stx, unsigned int mask)
 	cmp("%llu", stx_rdev_minor);
 	cmp("%llu", stx_dev_major);
 	cmp("%llu", stx_dev_minor);
+	cmp("%llu", stx_dio_mem_align);
+	cmp("%llu", stx_dio_offset_align);
 }
 
 /*
@@ -506,6 +512,8 @@ static void check_field(const struct statx *stx, char *arg)
 	case stx_rdev_minor:	uval = stx->stx_rdev_minor;	break;
 	case stx_dev_major:	uval = stx->stx_dev_major;	break;
 	case stx_dev_minor:	uval = stx->stx_dev_minor;	break;
+	case stx_dio_mem_align:	uval = stx->stx_dio_mem_align;	break;
+	case stx_dio_offset_align: uval = stx->stx_dio_offset_align; break;
 
 	case stx_atime_tv_sec:	sval = stx->stx_atime.tv_sec;	break;
 	case stx_atime_tv_nsec:	sval = stx->stx_atime.tv_nsec;	break;
@@ -569,6 +577,8 @@ static void check_field(const struct statx *stx, char *arg)
 		      "%s differs, %llu != %llu\n", key, uval, ucheck);
 		break;
 
+	case stx_dio_mem_align:
+	case stx_dio_offset_align:
 	case stx_atime_tv_sec:
 	case stx_atime_tv_nsec:
 	case stx_btime_tv_sec:
diff --git a/src/statx.h b/src/statx.h
index 3f239d79..116d1f43 100644
--- a/src/statx.h
+++ b/src/statx.h
@@ -114,7 +114,11 @@ struct statx {
 	__u32	stx_dev_major;	/* ID of device containing file [uncond] */
 	__u32	stx_dev_minor;
 	/* 0x90 */
-	__u64	__spare2[14];	/* Spare space for future expansion */
+	__u64	stx_mnt_id;
+	__u32	stx_dio_mem_align;	/* Memory buffer alignment for direct I/O */
+	__u32	stx_dio_offset_align;	/* File offset alignment for direct I/O */
+	/* 0xa0 */
+	__u64	__spare3[12];	/* Spare space for future expansion */
 	/* 0x100 */
 };
 
@@ -139,7 +143,9 @@ struct statx {
 #define STATX_BLOCKS		0x00000400U	/* Want/got stx_blocks */
 #define STATX_BASIC_STATS	0x000007ffU	/* The stuff in the normal stat struct */
 #define STATX_BTIME		0x00000800U	/* Want/got stx_btime */
-#define STATX_ALL		0x00000fffU	/* All currently supported flags */
+#define STATX_MNT_ID		0x00001000U	/* Got stx_mnt_id */
+#define STATX_DIOALIGN		0x00002000U	/* Want/got direct I/O alignment info */
+#define STATX_ALL		0x00003fffU	/* All currently supported flags */
 
 /*
  * Attributes to be found in stx_attributes
-- 
2.27.0




[Index of Archives]     [Linux Filesystems Development]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux