[PATCH] erofs: support STATX_DIOALIGN
Gao Xiang
hsiangkao at linux.alibaba.com
Wed Jul 17 12:00:48 AEST 2024
Hi,
On 2024/7/16 20:45, Hongbo Li wrote:
> Add support for STATX_DIOALIGN to erofs, so that direct I/O
> alignment restrictions are exposed to userspace in a generic
> way.
>
> [Before]
> ```
> ./statx_test /mnt/erofs/testfile
> statx(/mnt/erofs/testfile) = 0
> dio mem align:0
> dio offset align:0
> ```
>
> [After]
> ```
> ./statx_test /mnt/erofs/testfile
> statx(/mnt/erofs/testfile) = 0
> dio mem align:512
> dio offset align:512
> ```
>
> Signed-off-by: Hongbo Li <lihongbo22 at huawei.com>
> ---
> fs/erofs/inode.c | 19 +++++++++++++++++++
> 1 file changed, 19 insertions(+)
>
> diff --git a/fs/erofs/inode.c b/fs/erofs/inode.c
> index 5f6439a63af7..9325a6f0058a 100644
> --- a/fs/erofs/inode.c
> +++ b/fs/erofs/inode.c
> @@ -342,6 +342,25 @@ int erofs_getattr(struct mnt_idmap *idmap, const struct path *path,
> stat->attributes_mask |= (STATX_ATTR_COMPRESSED |
> STATX_ATTR_IMMUTABLE);
>
> + /*
> + * Return the DIO alignment restrictions if requested.
> + *
> + * In erofs, STATX_DIOALIGN is not supported in ondemand mode and
> + * the compressed file, so in these cases we report no DIO support.
> + */
> + if ((request_mask & STATX_DIOALIGN) && S_ISREG(inode->i_mode)) {
> + stat->result_mask |= STATX_DIOALIGN;
> + if (!erofs_is_fscache_mode(inode->i_sb) &&
> + !erofs_inode_is_data_compressed(EROFS_I(inode)->datalayout)) {
> + struct block_device *bdev = inode->i_sb->s_bdev;
> + unsigned int bsize = (bdev) ? bdev_logical_block_size(bdev) :
> + i_blocksize(inode);
I guess in this way you could always use
stat->dio_mem_align = bdev_logical_block_size(bdev);
stat->dio_offset_align = stat->dio_mem_align;
? since bdev won't be NULL.
Otherwise it looks good to me.
Thanks,
Gao Xiang
More information about the Linux-erofs
mailing list