From 001dbd05ded7e2116092f5fee0c7187b3a8c5982 Mon Sep 17 00:00:00 2001 From: Hongbo Li Date: Thu, 20 Jun 2024 21:21:12 +0800 Subject: [PATCH] bcachefs: support STATX_DIOALIGN for statx file Add support for STATX_DIOALIGN to bcachefs, so that direct I/O alignment restrictions are exposed to userspace in a generic way. [Before] ``` ./statx_test /mnt/bcachefs/test statx(/mnt/bcachefs/test) = 0 dio mem align:0 dio offset align:0 ``` [After] ``` ./statx_test /mnt/bcachefs/test statx(/mnt/bcachefs/test) = 0 dio mem align:1 dio offset align:512 ``` Signed-off-by: Hongbo Li Signed-off-by: Kent Overstreet --- fs/bcachefs/fs.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/fs/bcachefs/fs.c b/fs/bcachefs/fs.c index d6349e1f16e05..423d742eb5bb0 100644 --- a/fs/bcachefs/fs.c +++ b/fs/bcachefs/fs.c @@ -888,6 +888,12 @@ static int bch2_getattr(struct mnt_idmap *idmap, stat->subvol = inode->ei_subvol; stat->result_mask |= STATX_SUBVOL; + if ((request_mask & STATX_DIOALIGN) && S_ISREG(inode->v.i_mode)) { + stat->result_mask |= STATX_DIOALIGN; + stat->dio_mem_align = 1; + stat->dio_offset_align = SECTOR_SIZE; + } + if (request_mask & STATX_BTIME) { stat->result_mask |= STATX_BTIME; stat->btime = bch2_time_to_timespec(c, inode->ei_inode.bi_otime);