Linux Btrfs filesystem development
 help / color / mirror / Atom feed
* [PATCH] btrfs: support STATX_DIOALIGN for statx
@ 2024-06-20 13:20 Hongbo Li
  2024-06-24 16:02 ` David Sterba
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Hongbo Li @ 2024-06-20 13:20 UTC (permalink / raw)
  To: clm, josef, dsterba; +Cc: linux-btrfs, lihongbo22

Add support for STATX_DIOALIGN for btrfs, so that direct I/O alignment
restrictions are exposed to userspace in a generic way.

[Before]
```
./statx_test /mnt/btrfs/test
statx(/mnt/btrfs/test) = 0
dio mem align:0
dio offset align:0
```

[After]
```
./statx_test /mnt/btrfs/test
statx(/mnt/btrfs/test) = 0
dio mem align:4096
dio offset align:4096
```

Signed-off-by: Hongbo Li <lihongbo22@huawei.com>
---
 fs/btrfs/inode.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 753db965f7c0..a648e81143fd 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -8610,6 +8610,18 @@ static int btrfs_getattr(struct mnt_idmap *idmap,
 	stat->result_mask |= STATX_BTIME;
 	stat->btime.tv_sec = BTRFS_I(inode)->i_otime_sec;
 	stat->btime.tv_nsec = BTRFS_I(inode)->i_otime_nsec;
+
+	if ((request_mask & STATX_DIOALIGN) && S_ISREG(inode->i_mode)) {
+		btrfs_fs_info *fs_info = inode_to_fs_info(inode);
+		struct block_device *bdev = fs_info->fs_devices->latest_dev->bdev;
+
+		stat->result_mask |= STATX_DIOALIGN;
+		stat->dio_mem_align = max_t(u32, (bdev_dma_alignment(bdev) + 1),
+			fs_info->sectorsize);
+		stat->dio_offset_align = max_t(u32, bdev_logical_block_size(bdev),
+			fs_info->sectorsize);
+	}
+
 	if (bi_flags & BTRFS_INODE_APPEND)
 		stat->attributes |= STATX_ATTR_APPEND;
 	if (bi_flags & BTRFS_INODE_COMPRESS)
-- 
2.34.1


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

end of thread, other threads:[~2024-07-25 13:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-20 13:20 [PATCH] btrfs: support STATX_DIOALIGN for statx Hongbo Li
2024-06-24 16:02 ` David Sterba
2024-07-25 13:45   ` Hongbo Li
2024-06-25 21:56 ` kernel test robot
2024-06-26  0:24 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox