]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
f2fs: fix inline data not being written to disk in writeback path
authorYongpeng Yang <yangyongpeng@xiaomi.com>
Wed, 18 Mar 2026 08:46:35 +0000 (16:46 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Thu, 2 Apr 2026 16:24:19 +0000 (16:24 +0000)
When f2fs_fiemap() is called with `fileinfo->fi_flags` containing the
FIEMAP_FLAG_SYNC flag, it attempts to write data to disk before
retrieving file mappings via filemap_write_and_wait(). However, there is
an issue where the file does not get mapped as expected. The following
scenario can occur:

root@vm:/mnt/f2fs# dd if=/dev/zero of=data.3k bs=3k count=1
root@vm:/mnt/f2fs# xfs_io data.3k -c "fiemap -v 0 4096"
data.3k:
 EXT: FILE-OFFSET      BLOCK-RANGE      TOTAL FLAGS
   0: [0..5]:          0..5                 6 0x307

The root cause of this issue is that f2fs_write_single_data_page() only
calls f2fs_write_inline_data() to copy data from the data folio to the
inode folio, and it clears the dirty flag on the data folio. However, it
does not mark the data folio as writeback. When
__filemap_fdatawait_range() checks for folios with the writeback flag,
it returns early, causing f2fs_fiemap() to report that the file has no
mapping.

To fix this issue, the solution is to call
f2fs_write_single_node_folio() in f2fs_inline_data_fiemap() when
getting fiemap with FIEMAP_FLAG_SYNC flags. This patch ensures that the
inode folio is written back and the writeback process completes before
proceeding.

Cc: stable@kernel.org
Fixes: 9ffe0fb5f3bb ("f2fs: handle inline data operations")
Signed-off-by: Yongpeng Yang <yangyongpeng@xiaomi.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/f2fs.h
fs/f2fs/inline.c
fs/f2fs/node.c

index df4cdf804376a1ec734f27cdc2559d03aa760586..39b97621456adc27b3deb883f103227c9abe168a 100644 (file)
@@ -3946,6 +3946,8 @@ int f2fs_sanity_check_node_footer(struct f2fs_sb_info *sbi,
                                        enum node_type ntype, bool in_irq);
 struct folio *f2fs_get_inode_folio(struct f2fs_sb_info *sbi, pgoff_t ino);
 struct folio *f2fs_get_xnode_folio(struct f2fs_sb_info *sbi, pgoff_t xnid);
+int f2fs_write_single_node_folio(struct folio *node_folio, int sync_mode,
+                       bool mark_dirty, enum iostat_type io_type);
 int f2fs_move_node_folio(struct folio *node_folio, int gc_type);
 void f2fs_flush_inline_data(struct f2fs_sb_info *sbi);
 int f2fs_fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode,
index 86d2abbb40ff740678ba80bb9e9baa036f2d1cf7..62a8a1192a41a46321574a1c7ed0ec63d8a8b814 100644 (file)
@@ -814,6 +814,15 @@ int f2fs_inline_data_fiemap(struct inode *inode,
                goto out;
        }
 
+       if (fieinfo->fi_flags & FIEMAP_FLAG_SYNC) {
+               err = f2fs_write_single_node_folio(ifolio, true, false, FS_NODE_IO);
+               if (err)
+                       return err;
+               ifolio = f2fs_get_inode_folio(F2FS_I_SB(inode), inode->i_ino);
+               if (IS_ERR(ifolio))
+                       return PTR_ERR(ifolio);
+               f2fs_folio_wait_writeback(ifolio, NODE, true, true);
+       }
        ilen = min_t(size_t, MAX_INLINE_DATA(inode), i_size_read(inode));
        if (start >= ilen)
                goto out;
index c7499cb527453de65d73548d82a2f2d81db6c97e..a9cd2803e681b5ae34ab80349baa929eab6073eb 100644 (file)
@@ -1843,7 +1843,7 @@ redirty_out:
        return false;
 }
 
-static int f2fs_write_single_node_folio(struct folio *node_folio, int sync_mode,
+int f2fs_write_single_node_folio(struct folio *node_folio, int sync_mode,
                        bool mark_dirty, enum iostat_type io_type)
 {
        int err = 0;