Skip to contentSkip to conversation

actually exercise sub-block direct I/O reads v2

PATCH In review Christoph Hellwig 3 participants 9 messages Sep 14

lore
Share & tools
lore
#0 lore raw

Hi all,

when looking into testing changes that might require a minimum read size larger than a page size, I realized that various tests hard code PAGE_SIZE as a direct I/O read size despite claiming that they exercise sub-block direct I/O.

This series adds support to query the minimum read size and actually uses that for testing.

Changes since v1:
- explicitly request STATX_DIO_READ_ALIGN
- spelling fixes

#1 lore raw

PATCH 1/5 statx.h: update to latest kernel UAPI

Update the locally provided statx definition to the kernel UAPI as of 7.3-rc1.

---
 src/statx.h | 126 +++++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 96 insertions(+), 30 deletions(-)
src/statx.h +96 -30
index bae1c86f6201..0a27bf030b1d 100644
@@ -95,44 +95,97 @@ struct statx_timestamp {
  */
 struct statx {
 	/* 0x00 */
-	__u32	stx_mask;	/* What results were written [uncond] */
-	__u32	stx_blksize;	/* Preferred general I/O size [uncond] */
-	__u64	stx_attributes;	/* Flags conveying information about the file [uncond] */
+	/* What results were written [uncond] */
+	__u32	stx_mask;
+
+	/* Preferred general I/O size [uncond] */
+	__u32	stx_blksize;
+
+	/* Flags conveying information about the file [uncond] */
+	__u64	stx_attributes;
+
 	/* 0x10 */
-	__u32	stx_nlink;	/* Number of hard links */
-	__u32	stx_uid;	/* User ID of owner */
-	__u32	stx_gid;	/* Group ID of owner */
-	__u16	stx_mode;	/* File mode */
+	/* Number of hard links */
+	__u32	stx_nlink;
+
+	/* User ID of owner */
+	__u32	stx_uid;
+
+	/* Group ID of owner */
+	__u32	stx_gid;
+
+	/* File mode */
+	__u16	stx_mode;
 	__u16	__spare0[1];
+
 	/* 0x20 */
-	__u64	stx_ino;	/* Inode number */
-	__u64	stx_size;	/* File size */
-	__u64	stx_blocks;	/* Number of 512-byte blocks allocated */
-	__u64	stx_attributes_mask; /* Mask to show what's supported in stx_attributes */
+	/* Inode number */
+	__u64	stx_ino;
+
+	/* File size */
+	__u64	stx_size;
+
+	/* Number of 512-byte blocks allocated */
+	__u64	stx_blocks;
+
+	/* Mask to show what's supported in stx_attributes */
+	__u64	stx_attributes_mask;
 
 	/* 0x40 */
-	struct statx_timestamp	stx_atime;	/* Last access time */
-	struct statx_timestamp	stx_btime;	/* File creation time */
-	struct statx_timestamp	stx_ctime;	/* Last attribute change time */
-	struct statx_timestamp	stx_mtime;	/* Last data modification time */
+	/* Last access time */
+	struct statx_timestamp	stx_atime;
+
+	/* File creation time */
+	struct statx_timestamp	stx_btime;
+
+	/* Last attribute change time */
+	struct statx_timestamp	stx_ctime;
+
+	/* Last data modification time */
+	struct statx_timestamp	stx_mtime;
+
 	/* 0x80 */
-	__u32	stx_rdev_major;	/* Device ID of special file [if bdev/cdev] */
+	/* Device ID of special file [if bdev/cdev] */
+	__u32	stx_rdev_major;
 	__u32	stx_rdev_minor;
-	__u32	stx_dev_major;	/* ID of device containing file [uncond] */
+
+	/* ID of device containing file [uncond] */
+	__u32	stx_dev_major;
 	__u32	stx_dev_minor;
+
 	/* 0x90 */
 	__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 */
+
+	/* Memory buffer alignment for direct I/O */
+	__u32	stx_dio_mem_align;
+
+	/* File offset alignment for direct I/O */
+	__u32	stx_dio_offset_align;
+
 	/* 0xa0 */
-	__u64	stx_subvol;	/* Subvolume identifier */
-	__u32	stx_atomic_write_unit_min;	/* Min atomic write unit in bytes */
-	__u32	stx_atomic_write_unit_max;	/* Max atomic write unit in bytes */
+	/* Subvolume identifier */
+	__u64	stx_subvol;
+
+	/* Min atomic write unit in bytes */
+	__u32	stx_atomic_write_unit_min;
+
+	/* Max atomic write unit in bytes */
+	__u32	stx_atomic_write_unit_max;
+
 	/* 0xb0 */
-	__u32   stx_atomic_write_segments_max;	/* Max atomic write segment count */
-	__u32   __spare1[1];
-	/* 0xb8 */
-	__u64	__spare3[9];	/* Spare space for future expansion */
+	/* Max atomic write segment count */
+	__u32   stx_atomic_write_segments_max;
+
+	/* File offset alignment for direct I/O reads */
+	__u32	stx_dio_read_offset_align;
+
+	/* Optimised max atomic write unit in bytes */
+	__u32	stx_atomic_write_unit_max_opt;
+	__u32	__spare2[1];
+
+	/* 0xc0 */
+	__u64	__spare3[8];	/* Spare space for future expansion */
+
 	/* 0x100 */
 };
 
@@ -162,19 +215,32 @@ struct statx {
 #define STATX_MNT_ID_UNIQUE	0x00004000U	/* Want/got extended stx_mount_id */
 #define STATX_SUBVOL		0x00008000U	/* Want/got stx_subvol */
 #define STATX_WRITE_ATOMIC	0x00010000U	/* Want/got atomic_write_* fields */
+#define STATX_DIO_READ_ALIGN	0x00020000U	/* Want/got dio read alignment info */
 
-#define STATX_ALL		0x00000fffU	/* All currently supported flags */
+#define STATX__RESERVED		0x80000000U	/* Reserved for future struct statx expansion */
 
+#ifndef __KERNEL__
 /*
- * Attributes to be found in stx_attributes
+ * This is deprecated, and shall remain the same value in the future.  To avoid
+ * confusion please use the equivalent (STATX_BASIC_STATS | STATX_BTIME)
+ * instead.
+ */
+#define STATX_ALL		0x00000fffU
+#endif
+
+/*
+ * Attributes to be found in stx_attributes and masked in stx_attributes_mask.
  *
  * These give information about the features or the state of a file that might
  * be of use to ordinary userspace programs such as GUIs or ls rather than
  * specialised tools.
  *
- * Note that the flags marked [I] correspond to generic FS_IOC_FLAGS
+ * Note that the flags marked [I] correspond to the FS_IOC_SETFLAGS flags
  * semantically.  Where possible, the numerical value is picked to correspond
- * also.
+ * also.  Note that the DAX attribute indicates that the file is in the CPU
+ * direct access state.  It does not correspond to the per-inode flag that
+ * some filesystems support.
+ *
  */
 #define STATX_ATTR_COMPRESSED		0x00000004 /* [I] File is compressed by the fs */
 #define STATX_ATTR_IMMUTABLE		0x00000010 /* [I] File is marked immutable */
Signature · 1 line
2.53.0
#2 lore raw

Re: [PATCH 1/5] statx.h: update to latest kernel UAPI

Quoted 7 lines · Christoph Hellwig

Update the locally provided statx definition to the kernel UAPI as of 7.3-rc1.

Nit: no blank line between RVB tags. Otherwise this still looks ok.

--D

Quoted 172 lines
---
 src/statx.h | 126 +++++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 96 insertions(+), 30 deletions(-)
src/statx.h +96 -30
index bae1c86f6201..0a27bf030b1d 100644
@@ -95,44 +95,97 @@ struct statx_timestamp {
  */
 struct statx {
 	/* 0x00 */
-	__u32	stx_mask;	/* What results were written [uncond] */
-	__u32	stx_blksize;	/* Preferred general I/O size [uncond] */
-	__u64	stx_attributes;	/* Flags conveying information about the file [uncond] */
+	/* What results were written [uncond] */
+	__u32	stx_mask;
+
+	/* Preferred general I/O size [uncond] */
+	__u32	stx_blksize;
+
+	/* Flags conveying information about the file [uncond] */
+	__u64	stx_attributes;
+
 	/* 0x10 */
-	__u32	stx_nlink;	/* Number of hard links */
-	__u32	stx_uid;	/* User ID of owner */
-	__u32	stx_gid;	/* Group ID of owner */
-	__u16	stx_mode;	/* File mode */
+	/* Number of hard links */
+	__u32	stx_nlink;
+
+	/* User ID of owner */
+	__u32	stx_uid;
+
+	/* Group ID of owner */
+	__u32	stx_gid;
+
+	/* File mode */
+	__u16	stx_mode;
 	__u16	__spare0[1];
+
 	/* 0x20 */
-	__u64	stx_ino;	/* Inode number */
-	__u64	stx_size;	/* File size */
-	__u64	stx_blocks;	/* Number of 512-byte blocks allocated */
-	__u64	stx_attributes_mask; /* Mask to show what's supported in stx_attributes */
+	/* Inode number */
+	__u64	stx_ino;
+
+	/* File size */
+	__u64	stx_size;
+
+	/* Number of 512-byte blocks allocated */
+	__u64	stx_blocks;
+
+	/* Mask to show what's supported in stx_attributes */
+	__u64	stx_attributes_mask;
 
 	/* 0x40 */
-	struct statx_timestamp	stx_atime;	/* Last access time */
-	struct statx_timestamp	stx_btime;	/* File creation time */
-	struct statx_timestamp	stx_ctime;	/* Last attribute change time */
-	struct statx_timestamp	stx_mtime;	/* Last data modification time */
+	/* Last access time */
+	struct statx_timestamp	stx_atime;
+
+	/* File creation time */
+	struct statx_timestamp	stx_btime;
+
+	/* Last attribute change time */
+	struct statx_timestamp	stx_ctime;
+
+	/* Last data modification time */
+	struct statx_timestamp	stx_mtime;
+
 	/* 0x80 */
-	__u32	stx_rdev_major;	/* Device ID of special file [if bdev/cdev] */
+	/* Device ID of special file [if bdev/cdev] */
+	__u32	stx_rdev_major;
 	__u32	stx_rdev_minor;
-	__u32	stx_dev_major;	/* ID of device containing file [uncond] */
+
+	/* ID of device containing file [uncond] */
+	__u32	stx_dev_major;
 	__u32	stx_dev_minor;
+
 	/* 0x90 */
 	__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 */
+
+	/* Memory buffer alignment for direct I/O */
+	__u32	stx_dio_mem_align;
+
+	/* File offset alignment for direct I/O */
+	__u32	stx_dio_offset_align;
+
 	/* 0xa0 */
-	__u64	stx_subvol;	/* Subvolume identifier */
-	__u32	stx_atomic_write_unit_min;	/* Min atomic write unit in bytes */
-	__u32	stx_atomic_write_unit_max;	/* Max atomic write unit in bytes */
+	/* Subvolume identifier */
+	__u64	stx_subvol;
+
+	/* Min atomic write unit in bytes */
+	__u32	stx_atomic_write_unit_min;
+
+	/* Max atomic write unit in bytes */
+	__u32	stx_atomic_write_unit_max;
+
 	/* 0xb0 */
-	__u32   stx_atomic_write_segments_max;	/* Max atomic write segment count */
-	__u32   __spare1[1];
-	/* 0xb8 */
-	__u64	__spare3[9];	/* Spare space for future expansion */
+	/* Max atomic write segment count */
+	__u32   stx_atomic_write_segments_max;
+
+	/* File offset alignment for direct I/O reads */
+	__u32	stx_dio_read_offset_align;
+
+	/* Optimised max atomic write unit in bytes */
+	__u32	stx_atomic_write_unit_max_opt;
+	__u32	__spare2[1];
+
+	/* 0xc0 */
+	__u64	__spare3[8];	/* Spare space for future expansion */
+
 	/* 0x100 */
 };
 
@@ -162,19 +215,32 @@ struct statx {
 #define STATX_MNT_ID_UNIQUE	0x00004000U	/* Want/got extended stx_mount_id */
 #define STATX_SUBVOL		0x00008000U	/* Want/got stx_subvol */
 #define STATX_WRITE_ATOMIC	0x00010000U	/* Want/got atomic_write_* fields */
+#define STATX_DIO_READ_ALIGN	0x00020000U	/* Want/got dio read alignment info */
 
-#define STATX_ALL		0x00000fffU	/* All currently supported flags */
+#define STATX__RESERVED		0x80000000U	/* Reserved for future struct statx expansion */
 
+#ifndef __KERNEL__
 /*
- * Attributes to be found in stx_attributes
+ * This is deprecated, and shall remain the same value in the future.  To avoid
+ * confusion please use the equivalent (STATX_BASIC_STATS | STATX_BTIME)
+ * instead.
+ */
+#define STATX_ALL		0x00000fffU
+#endif
+
+/*
+ * Attributes to be found in stx_attributes and masked in stx_attributes_mask.
  *
  * These give information about the features or the state of a file that might
  * be of use to ordinary userspace programs such as GUIs or ls rather than
  * specialised tools.
  *
- * Note that the flags marked [I] correspond to generic FS_IOC_FLAGS
+ * Note that the flags marked [I] correspond to the FS_IOC_SETFLAGS flags
  * semantically.  Where possible, the numerical value is picked to correspond
- * also.
+ * also.  Note that the DAX attribute indicates that the file is in the CPU
+ * direct access state.  It does not correspond to the per-inode flag that
+ * some filesystems support.
+ *
  */
 #define STATX_ATTR_COMPRESSED		0x00000004 /* [I] File is compressed by the fs */
 #define STATX_ATTR_IMMUTABLE		0x00000010 /* [I] File is marked immutable */
Signature · 1 line
2.53.0
#3 lore raw

Re: [PATCH 1/5] statx.h: update to latest kernel UAPI

Quoted 10 lines · Darrick J. Wong
Quoted 7 lines · Christoph Hellwig

Update the locally provided statx definition to the kernel UAPI as of 7.3-rc1.

Nit: no blank line between RVB tags. Otherwise this still looks ok.

Thanks Darrick, I'll remove that blank line.

Quoted 175 lines

--D

Quoted 172 lines
---
 src/statx.h | 126 +++++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 96 insertions(+), 30 deletions(-)
src/statx.h +96 -30
index bae1c86f6201..0a27bf030b1d 100644
@@ -95,44 +95,97 @@ struct statx_timestamp {
  */
 struct statx {
 	/* 0x00 */
-	__u32	stx_mask;	/* What results were written [uncond] */
-	__u32	stx_blksize;	/* Preferred general I/O size [uncond] */
-	__u64	stx_attributes;	/* Flags conveying information about the file [uncond] */
+	/* What results were written [uncond] */
+	__u32	stx_mask;
+
+	/* Preferred general I/O size [uncond] */
+	__u32	stx_blksize;
+
+	/* Flags conveying information about the file [uncond] */
+	__u64	stx_attributes;
+
 	/* 0x10 */
-	__u32	stx_nlink;	/* Number of hard links */
-	__u32	stx_uid;	/* User ID of owner */
-	__u32	stx_gid;	/* Group ID of owner */
-	__u16	stx_mode;	/* File mode */
+	/* Number of hard links */
+	__u32	stx_nlink;
+
+	/* User ID of owner */
+	__u32	stx_uid;
+
+	/* Group ID of owner */
+	__u32	stx_gid;
+
+	/* File mode */
+	__u16	stx_mode;
 	__u16	__spare0[1];
+
 	/* 0x20 */
-	__u64	stx_ino;	/* Inode number */
-	__u64	stx_size;	/* File size */
-	__u64	stx_blocks;	/* Number of 512-byte blocks allocated */
-	__u64	stx_attributes_mask; /* Mask to show what's supported in stx_attributes */
+	/* Inode number */
+	__u64	stx_ino;
+
+	/* File size */
+	__u64	stx_size;
+
+	/* Number of 512-byte blocks allocated */
+	__u64	stx_blocks;
+
+	/* Mask to show what's supported in stx_attributes */
+	__u64	stx_attributes_mask;
 
 	/* 0x40 */
-	struct statx_timestamp	stx_atime;	/* Last access time */
-	struct statx_timestamp	stx_btime;	/* File creation time */
-	struct statx_timestamp	stx_ctime;	/* Last attribute change time */
-	struct statx_timestamp	stx_mtime;	/* Last data modification time */
+	/* Last access time */
+	struct statx_timestamp	stx_atime;
+
+	/* File creation time */
+	struct statx_timestamp	stx_btime;
+
+	/* Last attribute change time */
+	struct statx_timestamp	stx_ctime;
+
+	/* Last data modification time */
+	struct statx_timestamp	stx_mtime;
+
 	/* 0x80 */
-	__u32	stx_rdev_major;	/* Device ID of special file [if bdev/cdev] */
+	/* Device ID of special file [if bdev/cdev] */
+	__u32	stx_rdev_major;
 	__u32	stx_rdev_minor;
-	__u32	stx_dev_major;	/* ID of device containing file [uncond] */
+
+	/* ID of device containing file [uncond] */
+	__u32	stx_dev_major;
 	__u32	stx_dev_minor;
+
 	/* 0x90 */
 	__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 */
+
+	/* Memory buffer alignment for direct I/O */
+	__u32	stx_dio_mem_align;
+
+	/* File offset alignment for direct I/O */
+	__u32	stx_dio_offset_align;
+
 	/* 0xa0 */
-	__u64	stx_subvol;	/* Subvolume identifier */
-	__u32	stx_atomic_write_unit_min;	/* Min atomic write unit in bytes */
-	__u32	stx_atomic_write_unit_max;	/* Max atomic write unit in bytes */
+	/* Subvolume identifier */
+	__u64	stx_subvol;
+
+	/* Min atomic write unit in bytes */
+	__u32	stx_atomic_write_unit_min;
+
+	/* Max atomic write unit in bytes */
+	__u32	stx_atomic_write_unit_max;
+
 	/* 0xb0 */
-	__u32   stx_atomic_write_segments_max;	/* Max atomic write segment count */
-	__u32   __spare1[1];
-	/* 0xb8 */
-	__u64	__spare3[9];	/* Spare space for future expansion */
+	/* Max atomic write segment count */
+	__u32   stx_atomic_write_segments_max;
+
+	/* File offset alignment for direct I/O reads */
+	__u32	stx_dio_read_offset_align;
+
+	/* Optimised max atomic write unit in bytes */
+	__u32	stx_atomic_write_unit_max_opt;
+	__u32	__spare2[1];
+
+	/* 0xc0 */
+	__u64	__spare3[8];	/* Spare space for future expansion */
+
 	/* 0x100 */
 };
 
@@ -162,19 +215,32 @@ struct statx {
 #define STATX_MNT_ID_UNIQUE	0x00004000U	/* Want/got extended stx_mount_id */
 #define STATX_SUBVOL		0x00008000U	/* Want/got stx_subvol */
 #define STATX_WRITE_ATOMIC	0x00010000U	/* Want/got atomic_write_* fields */
+#define STATX_DIO_READ_ALIGN	0x00020000U	/* Want/got dio read alignment info */
 
-#define STATX_ALL		0x00000fffU	/* All currently supported flags */
+#define STATX__RESERVED		0x80000000U	/* Reserved for future struct statx expansion */
 
+#ifndef __KERNEL__
 /*
- * Attributes to be found in stx_attributes
+ * This is deprecated, and shall remain the same value in the future.  To avoid
+ * confusion please use the equivalent (STATX_BASIC_STATS | STATX_BTIME)
+ * instead.
+ */
+#define STATX_ALL		0x00000fffU
+#endif
+
+/*
+ * Attributes to be found in stx_attributes and masked in stx_attributes_mask.
  *
  * These give information about the features or the state of a file that might
  * be of use to ordinary userspace programs such as GUIs or ls rather than
  * specialised tools.
  *
- * Note that the flags marked [I] correspond to generic FS_IOC_FLAGS
+ * Note that the flags marked [I] correspond to the FS_IOC_SETFLAGS flags
  * semantically.  Where possible, the numerical value is picked to correspond
- * also.
+ * also.  Note that the DAX attribute indicates that the file is in the CPU
+ * direct access state.  It does not correspond to the per-inode flag that
+ * some filesystems support.
+ *
  */
 #define STATX_ATTR_COMPRESSED		0x00000004 /* [I] File is compressed by the fs */
 #define STATX_ATTR_IMMUTABLE		0x00000010 /* [I] File is marked immutable */
Signature · 1 line
2.53.0
#4 lore raw

PATCH 2/5 min_dio_alignment: add a -r option to query read alignment

In reply to Christoph Hellwig

Add an option to query the STATX_DIO_READ_ALIGN if provided.

---
 src/min_dio_alignment.c | 45 +++++++++++++++++++++++++++++++----------
 1 file changed, 34 insertions(+), 11 deletions(-)
src/min_dio_alignment.c +34 -11
index 866fba1546c4..a557ce93a5d6 100644
@@ -1,17 +1,19 @@
 // SPDX-License-Identifier: GPL-2.0
 /*
- * Copyright (c) 2024 Christoph Hellwig
+ * Copyright (c) 2024,2026 Christoph Hellwig
  */
 #include <fcntl.h>
+#include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <getopt.h>
 #include <sys/mount.h>
 #include <sys/ioctl.h>
 #include <sys/stat.h>
 #include "statx.h"
 
-static int min_dio_alignment(const char *mntpnt, const char *devname)
+static int min_dio_alignment(const char *mntpnt, const char *devname, bool read)
 {
 	struct statx stx = { };
 	struct stat st;
@@ -27,9 +29,17 @@ static int min_dio_alignment(const char *mntpnt, const char *devname)
 	 */
 	fd = open(mntpnt, O_TMPFILE | O_RDWR | O_EXCL, 0600);
 	if (fd >= 0 &&
-	    xfstests_statx(fd, "", AT_EMPTY_PATH, STATX_DIOALIGN, &stx) == 0 &&
-	    (stx.stx_mask & STATX_DIOALIGN) && stx.stx_dio_offset_align != 0)
-		return stx.stx_dio_offset_align;
+	    xfstests_statx(fd, "", AT_EMPTY_PATH,
+			STATX_DIOALIGN | STATX_DIO_READ_ALIGN, &stx) == 0) {
+		if (read &&
+		    (stx.stx_mask & STATX_DIO_READ_ALIGN) &&
+		    stx.stx_dio_read_offset_align != 0)
+			return stx.stx_dio_read_offset_align;
+
+		if ((stx.stx_mask & STATX_DIOALIGN) &&
+		    stx.stx_dio_offset_align != 0)
+			return stx.stx_dio_offset_align;
+	}
 
 	/*
 	 * If we are on a block device and no explicit aligned is reported, use
@@ -42,9 +52,8 @@ static int min_dio_alignment(const char *mntpnt, const char *devname)
 		if (dev_fd > 0 &&
 		    fstat(dev_fd, &st) == 0 &&
 		    S_ISBLK(st.st_mode) &&
-		    ioctl(dev_fd, BLKSSZGET, &logical_block_size) == 0) {
+		    ioctl(dev_fd, BLKSSZGET, &logical_block_size) == 0)
 			return logical_block_size;
-		}
 	}
 
 	/*
@@ -56,11 +65,25 @@ static int min_dio_alignment(const char *mntpnt, const char *devname)
 
 int main(int argc, char **argv)
 {
-	if (argc != 3) {
-		fprintf(stderr, "usage: %s mountpoint devicename\n", argv[0]);
-		exit(1);
+	bool read = false;
+	int c;
+
+	while ((c = getopt(argc, argv, "r")) != -1) {
+		switch(c) {
+		case 'r':
+			read = 1;
+			break;
+		default:
+			goto usage;
+		}
 	}
 
-	printf("%d\n", min_dio_alignment(argv[1], argv[2]));
+	if (argc - optind != 2)
+		goto usage;
+
+	printf("%d\n", min_dio_alignment(argv[optind], argv[optind + 1], read));
 	exit(0);
+usage:
+	fprintf(stderr, "usage: %s [-r] mountpoint devicename\n", argv[0]);
+	exit(1);
 }
Signature · 1 line
2.53.0
Reviewed-by on v1 2/5
#5 lore raw

Re: [PATCH 2/5] min_dio_alignment: add a -r option to query read alignment

Quoted 5 lines · Christoph Hellwig

Add an option to query the STATX_DIO_READ_ALIGN if provided.

---

Thanks Christoph, this version is good to me:)

Quoted 94 lines
 src/min_dio_alignment.c | 45 +++++++++++++++++++++++++++++++----------
 1 file changed, 34 insertions(+), 11 deletions(-)
src/min_dio_alignment.c +34 -11
index 866fba1546c4..a557ce93a5d6 100644
@@ -1,17 +1,19 @@
 // SPDX-License-Identifier: GPL-2.0
 /*
- * Copyright (c) 2024 Christoph Hellwig
+ * Copyright (c) 2024,2026 Christoph Hellwig
  */
 #include <fcntl.h>
+#include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <getopt.h>
 #include <sys/mount.h>
 #include <sys/ioctl.h>
 #include <sys/stat.h>
 #include "statx.h"
 
-static int min_dio_alignment(const char *mntpnt, const char *devname)
+static int min_dio_alignment(const char *mntpnt, const char *devname, bool read)
 {
 	struct statx stx = { };
 	struct stat st;
@@ -27,9 +29,17 @@ static int min_dio_alignment(const char *mntpnt, const char *devname)
 	 */
 	fd = open(mntpnt, O_TMPFILE | O_RDWR | O_EXCL, 0600);
 	if (fd >= 0 &&
-	    xfstests_statx(fd, "", AT_EMPTY_PATH, STATX_DIOALIGN, &stx) == 0 &&
-	    (stx.stx_mask & STATX_DIOALIGN) && stx.stx_dio_offset_align != 0)
-		return stx.stx_dio_offset_align;
+	    xfstests_statx(fd, "", AT_EMPTY_PATH,
+			STATX_DIOALIGN | STATX_DIO_READ_ALIGN, &stx) == 0) {
+		if (read &&
+		    (stx.stx_mask & STATX_DIO_READ_ALIGN) &&
+		    stx.stx_dio_read_offset_align != 0)
+			return stx.stx_dio_read_offset_align;
+
+		if ((stx.stx_mask & STATX_DIOALIGN) &&
+		    stx.stx_dio_offset_align != 0)
+			return stx.stx_dio_offset_align;
+	}
 
 	/*
 	 * If we are on a block device and no explicit aligned is reported, use
@@ -42,9 +52,8 @@ static int min_dio_alignment(const char *mntpnt, const char *devname)
 		if (dev_fd > 0 &&
 		    fstat(dev_fd, &st) == 0 &&
 		    S_ISBLK(st.st_mode) &&
-		    ioctl(dev_fd, BLKSSZGET, &logical_block_size) == 0) {
+		    ioctl(dev_fd, BLKSSZGET, &logical_block_size) == 0)
 			return logical_block_size;
-		}
 	}
 
 	/*
@@ -56,11 +65,25 @@ static int min_dio_alignment(const char *mntpnt, const char *devname)
 
 int main(int argc, char **argv)
 {
-	if (argc != 3) {
-		fprintf(stderr, "usage: %s mountpoint devicename\n", argv[0]);
-		exit(1);
+	bool read = false;
+	int c;
+
+	while ((c = getopt(argc, argv, "r")) != -1) {
+		switch(c) {
+		case 'r':
+			read = 1;
+			break;
+		default:
+			goto usage;
+		}
 	}
 
-	printf("%d\n", min_dio_alignment(argv[1], argv[2]));
+	if (argc - optind != 2)
+		goto usage;
+
+	printf("%d\n", min_dio_alignment(argv[optind], argv[optind + 1], read));
 	exit(0);
+usage:
+	fprintf(stderr, "usage: %s [-r] mountpoint devicename\n", argv[0]);
+	exit(1);
 }
Signature · 1 line
2.53.0
#6 lore raw

PATCH 3/5 generic/091: enable sub-block reads

In reply to Christoph Hellwig

The description of generic/091 claims that it tries to exercise sub-block direct I/O, but the test currently limits reads to PAGE_SIZE alignment.

Use the new min_dio_alignment -r option to query the minimal read alignment and only limit the read alignment to that.

---
 tests/generic/091 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tests/generic/091 +1 -1
index 5cdf04890c0e..b2fba09d39ef 100755
@@ -15,8 +15,8 @@ _begin_fstest rw auto quick
 _require_test
 _require_odirect
 
-psize=`$here/src/feature -s`
 bsize=`$here/src/min_dio_alignment $TEST_DIR $TEST_DEV`
+psize=`$here/src/min_dio_alignment -r $TEST_DIR $TEST_DEV`
 
 # fsx usage:
 # 
Signature · 1 line
2.53.0
#7 lore raw

PATCH 4/5 generic/263: enable sub-block reads

In reply to Christoph Hellwig

The description of generic/263 claims that it tries to exercise sub-block direct I/O, but the test currently limits reads to PAGE_SIZE alignment.

Use the new min_dio_alignment -r option to query the minimal read alignment and only limit the read alignment to that.

---
 tests/generic/263 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tests/generic/263 +1 -1
index 91cfbe5253bd..c456d62ebd43 100755
@@ -15,7 +15,7 @@ _begin_fstest rw auto quick
 _require_test
 _require_odirect
 
-psize=`$here/src/feature -s`
+psize=`$here/src/min_dio_alignment -r $TEST_DIR $TEST_DEV`
 bsize=`$here/src/min_dio_alignment $TEST_DIR $TEST_DEV`
 
 run_fsx -N 10000  -o 8192   -l 500000 -r PSIZE -t BSIZE -w BSIZE -Z
Signature · 1 line
2.53.0
#8 lore raw

PATCH 5/5 generic/760: enable sub-block reads

In reply to Christoph Hellwig

generic/760 currently limits reads to PAGE_SIZE alignments while allowing smaller writes. Use the new min_dio_alignment -r option to query the minimal read alignment and only limit the read alignment to that.

---
 tests/generic/760 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tests/generic/760 +1 -1
index f270636e56a3..facd83e4af0c 100755
@@ -16,7 +16,7 @@ _require_odirect
 _require_thp
 _require_hugepage_fsx
 
-psize=`$here/src/feature -s`
+psize=`$here/src/min_dio_alignment -r $TEST_DIR $TEST_DEV`
 bsize=`$here/src/min_dio_alignment $TEST_DIR $TEST_DEV`
 
 _run_hugepage_fsx -N 10000            -l 500000 -r PSIZE -t BSIZE -w BSIZE -Z -R -W
Signature · 1 line
2.53.0