]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
fuse2fs: fix punching post-EOF blocks during truncate
authorDarrick J. Wong <djwong@kernel.org>
Sat, 26 Jul 2025 16:28:48 +0000 (09:28 -0700)
committerTheodore Ts'o <tytso@mit.edu>
Thu, 31 Jul 2025 14:46:02 +0000 (10:46 -0400)
ext2fs_punch() can update the inode that's passed in, so we need to
write it back.  This should fix some fstests failures where the test
file system ends up with inodes where all extent records fit within the
inode but inexplicably have extents beyond EOF.  While we're at it, add
the fuse2fs prefix to the two helper functions.

Cc: linux-ext4@vger.kernel.org # v1.47.3
Fixes: 4581ac60eb53ec ("fuse2fs: fix post-EOF preallocation clearing on truncation")
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Link: https://lore.kernel.org/r/20250726162848.GQ2672022@frogsfrogsfrogs
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
misc/fuse2fs.c

index 18d8f426a5eb43e3e20913903fa6156470173c98..c6b1684f53e2e4e8afce13f3a89a556675f8a0d5 100644 (file)
@@ -2461,7 +2461,8 @@ out:
        return ret;
 }
 
-static int punch_posteof(struct fuse2fs *ff, ext2_ino_t ino, off_t new_size)
+static int fuse2fs_punch_posteof(struct fuse2fs *ff, ext2_ino_t ino,
+                                off_t new_size)
 {
        ext2_filsys fs = ff->fs;
        struct ext2_inode_large inode;
@@ -2477,10 +2478,14 @@ static int punch_posteof(struct fuse2fs *ff, ext2_ino_t ino, off_t new_size)
        if (err)
                return translate_error(fs, ino, err);
 
+       err = fuse2fs_write_inode(fs, ino, &inode);
+       if (err)
+               return translate_error(fs, ino, err);
+
        return 0;
 }
 
-static int truncate_helper(struct fuse2fs *ff, ext2_ino_t ino, off_t new_size)
+static int fuse2fs_truncate(struct fuse2fs *ff, ext2_ino_t ino, off_t new_size)
 {
        ext2_filsys fs = ff->fs;
        ext2_file_t file;
@@ -2523,7 +2528,7 @@ out_close:
         * we should clear out post-EOF preallocations.
         */
        if (new_size == old_isize)
-               return punch_posteof(ff, ino, new_size);
+               return fuse2fs_punch_posteof(ff, ino, new_size);
 
        return 0;
 }
@@ -2559,7 +2564,7 @@ static int op_truncate(const char *path, off_t len
        if (ret)
                goto out;
 
-       ret = truncate_helper(ff, ino, len);
+       ret = fuse2fs_truncate(ff, ino, len);
        if (ret)
                goto out;
 
@@ -2659,7 +2664,7 @@ static int __op_open(struct fuse2fs *ff, const char *path,
        }
 
        if (fp->flags & O_TRUNC) {
-               ret = truncate_helper(ff, file->ino, 0);
+               ret = fuse2fs_truncate(ff, file->ino, 0);
                if (ret)
                        goto out;
        }