[PATCH 04/16] fuse2fs: implement directio file reads

Darrick J. Wong
2025-05-22T00:11:54Z

Implement file reads via iomap. Currently only directio is supported.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
misc/fuse2fs.c | 26 +++++++++++++++++++++++++-
1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index 91c0da096bef9c..b1f3002ec8c481 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -1103,6 +1103,11 @@ static void *op_init(struct fuse_conn_info *conn
goto mount_fail;
}

+#if defined(HAVE_FUSE_IOMAP) && defined(FUSE_CAP_IOMAP_DIRECTIO)
+ if (iomap_enabled(ff))
+ fuse_set_feature_flag(conn, FUSE_CAP_IOMAP_DIRECTIO);
+#endif
+
/* Clear the valid flag so that an unclean shutdown forces a fsck */
if (ff->writable) {
fs->super->s_mnt_count++;
@@ -4942,7 +4947,26 @@ static int fuse_iomap_begin_read(struct fuse2fs *ff, ext2_ino_t ino,
uint64_t count, uint32_t opflags,
struct fuse_iomap *read_iomap)
{
- return -ENOSYS;
+ errcode_t err;
+
+ if (!(opflags & FUSE_IOMAP_OP_DIRECT))
+ return -ENOSYS;
+
+ /* fall back to slow path for inline data reads */
+ if (inode->i_flags & EXT4_INLINE_DATA_FL)
+ return -ENOSYS;
+
+ /* flush dirty io_channel buffers to disk before iomap reads them */
+ err = io_channel_flush(ff->fs->io);
+ if (err)
+ return translate_error(ff->fs, ino, err);
+
+ if (inode->i_flags & EXT4_EXTENTS_FL)
+ return extent_iomap_begin(ff, ino, inode, pos, count, opflags,
+ read_iomap);
+
+ return indirect_iomap_begin(ff, ino, inode, pos, count, opflags,
+ read_iomap);
}

static int fuse_iomap_begin_write(struct fuse2fs *ff, ext2_ino_t ino,