[PATCH 13/16] fuse2fs: don't do file data block IO when iomap is enabled

Darrick J. Wong
2025-05-22T00:14:15Z

When iomap is in use for the page cache, the kernel will take care of
all the file data block IO for us, including zeroing of punched ranges
and post-EOF bytes. fuse2fs only needs to do IO for inline data.

Therefore, set the NOBLOCKIO ext2_file flag so that libext2fs will not
do any regular file IO to or from disk blocks at all.

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

diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index aeb2b6fbc28401..842ea3a191fa44 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -2863,9 +2863,14 @@ static int truncate_helper(struct fuse2fs *ff, ext2_ino_t ino, off_t new_size)
ext2_file_t file;
__u64 old_isize;
errcode_t err;
+ int flags = EXT2_FILE_WRITE;
int ret = 0;

- err = ext2fs_file_open(fs, ino, EXT2_FILE_WRITE, &file);
+ /* the kernel handles all eof zeroing for us in iomap mode */
+ if (iomap_does_fileio(ff))
+ flags |= EXT2_FILE_NOBLOCKIO;
+
+ err = ext2fs_file_open(fs, ino, flags, &file);
if (err)
return translate_error(fs, ino, err);

@@ -2987,6 +2992,9 @@ static int __op_open(struct fuse2fs *ff, const char *path,
file->open_flags |= EXT2_FILE_WRITE;
break;
}
+ /* the kernel handles all block IO for us in iomap mode */
+ if (iomap_does_fileio(ff))
+ file->open_flags |= EXT2_FILE_NOBLOCKIO;
if (fp->flags & O_APPEND) {
/* the kernel doesn't allow truncation of an append-only file */
if (fp->flags & O_TRUNC) {