Re: [RFC PATCH v2 3/8] fat: add iomap direct I/O support
From: Matheus Alves de Almeida
Date: Sun Nov 29 2026 - 20:17:56 EST
On Fri, Nov 20, 2026 at 07:29:47PM +0100, Christoph Hellwig wrote:
>On Tue, Nov 17, 2026 at 11:01:43PM -0300, Matheus Alves de Almeida wrote:
>> +{
>> + struct inode *inode = file_inode(iocb->ki_filp);
>> + ssize_t ret;
>> +
>> + if ((iocb->ki_flags & IOCB_DIRECT) == 0)
>> + return generic_file_read_iter(iocb, iter);
>
>Does fat never cause a fallback to buffered I/O?
>
Reads don't need one, as everything below i_size is mapped.
Writes do fall back using direct_write_fallback(), though.
>> + /* Wait under the inode lock for size updates and partial-block zeroing. */
>
>Overly long line.
>
Will fix, thanks.
>> + if (iocb->ki_pos + iov_iter_count(iter) > i_size_read(inode) ||
>> + !IS_ALIGNED(iocb->ki_pos | iov_iter_alignment(iter),
>> + i_blocksize(inode)))
>> + dio_flags |= IOMAP_DIO_FORCE_WAIT;
>
>Explain why the wait is fored please.
>
Extending writes have to finish under the inode lock, because
->end_io() updates i_size without taking any lock. Unaligned writes
ending at or past EOF also need to wait, so iomap's zeroing of the rest
of the EOF block can't race with a later write.
Looking at it again, changing the first check to >= covers both cases,
so I'll drop the alignment check in the next version.
>> +static int fat_dio_write_end_io(struct kiocb *iocb, ssize_t size, int error,
>> + unsigned int flags)
>> +{
>> + struct inode *inode = file_inode(iocb->ki_filp);
>> +
>> + if (error)
>> + return error;
>> +
>> + if (size && i_size_read(inode) < iocb->ki_pos + size) {
>> + i_size_write(inode, iocb->ki_pos + size);
>> + mark_inode_dirty(inode);
>> + }
>> +
>> + return 0;
>
>And just as a I comment on the hfsplus thread, this really should be
>the default in iomap if no need_io is provided. Please coordinate
>with Slava so that we get this into iomap first and then rebase both
>series on top.
>
This callback is temporary and gets removed later alongside
->mmu_private.
I will drop the use of ->end_io() from this patch and make it fall back
to buffered I/O in the case the callback would handle.
Thanks,
Matheus