]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
f2fs: fix to update map->m_next_extent correctly in f2fs_map_blocks()
authorChao Yu <chao@kernel.org>
Fri, 12 Sep 2025 08:12:50 +0000 (16:12 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Tue, 16 Sep 2025 02:10:54 +0000 (02:10 +0000)
Script to reproduce:
mkfs.f2fs -O extra_attr,compression /dev/vdb -f
mount /dev/vdb /mnt/f2fs -o mode=lfs,noextent_cache
cd /mnt/f2fs
f2fs_io write 1 0 1024 rand dsync testfile
xfs_io testfile -c "fsync"
f2fs_io write 1 0 512 rand dsync testfile
xfs_io testfile -c "fsync"
cd /
umount /mnt/f2fs
mount /dev/vdb /mnt/f2fs
f2fs_io precache_extents /mnt/f2fs/testfile
umount /mnt/f2fs

Tracepoint output:
f2fs_update_read_extent_tree_range: dev = (253,16), ino = 4, pgofs = 0, len = 512, blkaddr = 1055744, c_len = 0
f2fs_update_read_extent_tree_range: dev = (253,16), ino = 4, pgofs = 513, len = 351, blkaddr = 17921, c_len = 0
f2fs_update_read_extent_tree_range: dev = (253,16), ino = 4, pgofs = 864, len = 160, blkaddr = 18272, c_len = 0

During precache_extents, there is off-by-one issue, we should update
map->m_next_extent to pgofs rather than pgofs + 1, if last blkaddr is
valid and not contiguous to previous extent.

Fixes: c4020b2da4c9 ("f2fs: support F2FS_IOC_PRECACHE_EXTENTS")
Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/data.c

index 86395b54631194bc4a92debe8cfba097731c9ec8..2bec936174e23ef13da30ac88796fefef1923653 100644 (file)
@@ -1776,7 +1776,7 @@ sync_out:
                                map->m_len - ofs);
                }
                if (map->m_next_extent)
-                       *map->m_next_extent = pgofs + 1;
+                       *map->m_next_extent = is_hole ? pgofs + 1 : pgofs;
        }
        f2fs_put_dnode(&dn);
 unlock_out: