Re: [RFC PATCH 3/8] fat: add iomap direct I/O support

From: Matheus Alves de Almeida

Date: Wed Nov 11 2026 - 23:18:42 EST


On Sun, Nov 08, 2026 at 11:56:11PM +0900, OGAWA Hirofumi wrote:
>Matheus Alves de Almeida <matheus.aalmeida@xxxxxxxxxxxx> writes:
>
>> Replace the deprecated ->direct_IO() path with ->{read,write}_iter() and
>> iomap_dio_rw(). Add fat_file_open() to advertise direct I/O support.
>>
>> Signed-off-by: Matheus Alves de Almeida <matheus.aalmeida@xxxxxxxxxxxx>
>> ---
>> fs/fat/Kconfig | 1 -
>> fs/fat/fat.h | 1 +
>> fs/fat/file.c | 119 ++++++++++++++++++++++++++++++++++++++++++++++++-
>> fs/fat/inode.c | 36 ---------------
>> fs/fat/iomap.c | 24 ++++++++++
>> 5 files changed, 142 insertions(+), 39 deletions(-)
>>
>
>[...]
>
>> diff --git a/fs/fat/file.c b/fs/fat/file.c
>> index c27d4e7f698c..177a26186ddc 100644
>> --- a/fs/fat/file.c
>> +++ b/fs/fat/file.c
>> @@ -201,11 +201,126 @@ int fat_file_fsync(struct file *filp, loff_t start, loff_t end, int datasync)
>> return blkdev_issue_flush(inode->i_sb->s_bdev);
>> }
>>
>
>[...]
>
>> +static ssize_t fat_file_write_iter(struct kiocb *iocb, struct iov_iter *iter)
>> +{
>> + ssize_t ret;
>> +
>> + if ((iocb->ki_flags & IOCB_DIRECT) == 0)
>> + return generic_file_write_iter(iocb, iter);
>> +
>> + ret = fat_file_dio_write_iter(iocb, iter);
>> + if (ret == -ENOTBLK)
>> + ret = 0;
>> + else if (ret < 0)
>> + return ret;
>> +
>> + /* Fall back to buffered I/O if we could not do DIO */
>> + if (iov_iter_count(iter)) {
>> + ssize_t done;
>> +
>> + done = fat_file_write_iter_buffered_fallback(iocb, iter);
>> + if (done < 0)
>> + return done;
>
>If fat_file_dio_write_iter() wrote some, this should return ret (how
>many written), instead of the error? Or it never happen?
>

While I don't think it can currently happen, I will fix it in v2 for
future correctness. Good catch.

>> + ret += done;
>> + }
>> +
>> + return ret;
>> +}

Thanks,
Matheus