Re: [PATCH 4/8] btrfs: Switch to iomap_dio_rw() for dio

Goldwyn Rodrigues
2019-12-05T17:44:46Z

On 18:32 05/12, Johannes Thumshirn wrote:
> On Thu, Dec 05, 2019 at 09:19:59AM -0800, Christoph Hellwig wrote:
> > I actually much prefer exporting generic_file_buffered_read and will
> > gladly switch other callers not needing the messy direct I/O handling
> > in generic_file_read_iter over to generic_file_buffered_read once this
> > series is merged.
>
> I think you misunderstood me here, I meant the code to be:
>
> static ssize_t btrfs_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
> {
> ssize_t ret = 0;
>
> if (iocb->ki_flags & IOCB_DIRECT) {
> struct inode *inode = file_inode(iocb->ki_filp);
>
> inode_lock_shared(inode);
> ret = btrfs_direct_IO(iocb, to);
> inode_unlock_shared(inode);
> if (ret < 0)
> return ret;
> }
> }
>
> return generic_file_read_iter(icob, to);
> }
>
> This way an iocb that is no dio will end in generic_file_read_iter():
>
> generic_file_read_iter(iocb, to)
> {
> size_t count = iov_iter_count(iter);
> ssize_t retval = 0;
>
> if (!count)
> goto out; /* skip atime */
>
> if (iocb->ki_flags & IOCB_DIRECT) {
> skipped as flag is not set
> }
>
> retval = generic_file_buffered_read(iocb, iter, retval);
> out:
> return retval;
> }
>
> Meaning we do not need to export generic_file_buffered_read() and still can
> skip the generic DIO madness.
>
> Makes sense?

For btrfs, DIO and buffered I/O is not mutually exclusive, since we fall
back to buffered I/O in case of incomplete Direct I/O. In this case,
the control will not skip IOCB_DIRECT branch.

--
Goldwyn