[PATCH 12/19] fuse2fs: only flush O_SYNC files on close

Darrick J. Wong
2025-11-06T22:34:16Z

Don't call ext2fs_flush2() from op_release unless the file was opened
with either synchronous write flag.

XXX: Maybe this should be replaced with actual incore state tracking for
inodes?

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

diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index 0b4f7f10ddc97f..4af22ea9e0d3a3 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -3059,11 +3059,15 @@ static int op_release(const char *path EXT2FS_ATTR((unused)),
FUSE2FS_CHECK_MAGIC(fs, fh, FUSE2FS_FILE_MAGIC);
dbg_printf(ff, "%s: ino=%d\n", __func__, fh->ino);
pthread_mutex_lock(&ff->bfl);
- if (fs_writeable(fs) && fh->open_flags & EXT2_FILE_WRITE) {
+
+ if ((fp->flags & O_SYNC) &&
+ fs_writeable(fs) &&
+ (fh->open_flags & EXT2_FILE_WRITE)) {
err = ext2fs_flush2(fs, EXT2_FLAG_FLUSH_NO_SYNC);
if (err)
ret = translate_error(fs, fh->ino, err);
}
+
fp->fh = 0;
pthread_mutex_unlock(&ff->bfl);