FAILED: patch "[PATCH] f2fs: release a removed xattr node in roll-forward recovery" failed to apply to 7.3-stable tree
Subsystems (2)
Sasha Levin
maintainerThe patch below does not apply to the 7.3-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-7.3.y
git checkout FETCH_HEAD
git cherry-pick -x f5924de8867c09206ba631b9faed63862ec00a10
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '[email protected]' --subject-prefix 'PATCH 7.3.y' 'HEAD^..'
Thanks,
Sasha
------------------ original commit in Linus's tree ------------------
From f5924de8867c09206ba631b9faed63862ec00a10 Mon Sep 17 00:00:00 2001
From: Daeho Jeong <[email protected]>
Date: Thu, 15 Oct 2026 02:57:31 +0000
Subject: [PATCH] f2fs: release a removed xattr node in roll-forward recovery
When xattrs shrink enough to fit in the inline xattr area, write_all_xattrs() truncates the xattr node and clears i_xattr_nid. If the file is then fsynced without a checkpoint, only the inode block is written, with i_xattr_nid of 0.
Roll-forward recovery starts from the checkpointed inode, whose i_xattr_nid still points to the old xattr node. f2fs_recover_inline_xattr() copies only the inline xattr area, and f2fs_update_inode() writes the old i_xattr_nid back. So the inode keeps the stale xattr node:
- The node block is never released, and fsck reports "nonzero bytes in xattr space after end of list".
- If the inline xattr list ends exactly at the end of the inline area, its terminator is read from the stale node, and the removed xattrs come back after recovery.
When the fsynced inode has no xattr node but the checkpointed one has, release the old xattr node as truncate_node() does: check its block address, invalidate the block and drop its node cache, which may still be dirty.
--- fs/f2fs/node.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)
fs/f2fs/node.c +37 -0
@@ -2846,6 +2846,43 @@ int f2fs_recover_inline_xattr(struct inode *inode, struct f2fs_cached_block *entf2fs_cache_wait_writeback (ientry);memcpy (dst_addr, src_addr, inline_size); update_inode: +/* +* The xattr node of the checkpoint was removed before fsync, e.g. the +* xattrs became small enough to fit inline. Release it as well, or +* the inode keeps pointing to the stale xattrs. +*/ +if (!ri->i_xattr_nid &&F2FS_I (inode)->i_xattr_nid) { +struct f2fs_sb_info *sbi =F2FS_I_SB (inode); +struct node_info ni; +int err; + + err =f2fs_get_node_info (sbi,F2FS_I (inode)->i_xattr_nid, + &ni, false); +if (err) { +f2fs_put_cache (ientry, true); +return err; + } + +if (ni.blk_addr !=NEW_ADDR && + !f2fs_is_valid_blkaddr (sbi, ni.blk_addr, +DATA_GENERIC_ENHANCE )) { +f2fs_err_ratelimited (sbi, +"nat entry is corrupted, run fsck to fix it, ino:%u, nid:%u, blkaddr:%u" , + ni.ino, ni.nid, ni.blk_addr); +set_sbi_flag (sbi,SBI_NEED_FSCK ); +f2fs_handle_error (sbi,ERROR_INCONSISTENT_NAT ); +f2fs_put_cache (ientry, true); +return -EFSCORRUPTED ; + } + +f2fs_invalidate_blocks (sbi, ni.blk_addr,1 ); +dec_valid_node_count (sbi, inode, false); +set_node_addr (sbi, &ni,NULL_ADDR , false); +/* drop the cached xattr node, which may be dirty */ +f2fs_truncate_node_caches (sbi, ni.nid,1 ); +f2fs_i_xnid_write (inode,0 ); + } +f2fs_update_inode (inode, ientry);f2fs_put_cache (ientry, true);return 0 ;
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 1/1 f2fs: release a removed xattr node in roll-forward recovery
From: Daeho Jeong <[email protected]>
[ Upstream commit f5924de8867c09206ba631b9faed63862ec00a10 ]
When xattrs shrink enough to fit in the inline xattr area, write_all_xattrs() truncates the xattr node and clears i_xattr_nid. If the file is then fsynced without a checkpoint, only the inode block is written, with i_xattr_nid of 0.
Roll-forward recovery starts from the checkpointed inode, whose i_xattr_nid still points to the old xattr node. f2fs_recover_inline_xattr() copies only the inline xattr area, and f2fs_update_inode() writes the old i_xattr_nid back. So the inode keeps the stale xattr node:
- The node block is never released, and fsck reports "nonzero bytes in xattr space after end of list".
- If the inline xattr list ends exactly at the end of the inline area, its terminator is read from the stale node, and the removed xattrs come back after recovery.
When the fsynced inode has no xattr node but the checkpointed one has, release the old xattr node as truncate_node() does: check its block address, invalidate the block and drop its node cache, which may still be dirty.
--- fs/f2fs/node.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+)
fs/f2fs/node.c +39 -0
@@ -2871,6 +2871,45 @@ int f2fs_recover_inline_xattr(struct inode *inode, struct folio *folio)f2fs_folio_wait_writeback (ifolio,NODE , true, true);memcpy (dst_addr, src_addr, inline_size); update_inode: +/* +* The xattr node of the checkpoint was removed before fsync, e.g. the +* xattrs became small enough to fit inline. Release it as well, or +* the inode keeps pointing to the stale xattrs. +*/ +if (!ri->i_xattr_nid &&F2FS_I (inode)->i_xattr_nid) { +struct f2fs_sb_info *sbi =F2FS_I_SB (inode); +struct node_info ni; +int err; + + err =f2fs_get_node_info (sbi,F2FS_I (inode)->i_xattr_nid, + &ni, false); +if (err) { +f2fs_folio_put (ifolio, true); +return err; + } + +if (ni.blk_addr !=NEW_ADDR && + !f2fs_is_valid_blkaddr (sbi, ni.blk_addr, +DATA_GENERIC_ENHANCE )) { +f2fs_err_ratelimited (sbi, +"nat entry is corrupted, run fsck to fix it, ino:%u, nid:%u, blkaddr:%u" , + ni.ino, ni.nid, ni.blk_addr); +set_sbi_flag (sbi,SBI_NEED_FSCK ); +f2fs_handle_error (sbi,ERROR_INCONSISTENT_NAT ); +f2fs_folio_put (ifolio, true); +return -EFSCORRUPTED ; + } + +f2fs_invalidate_blocks (sbi, ni.blk_addr,1 ); +dec_valid_node_count (sbi, inode, false); +set_node_addr (sbi, &ni,NULL_ADDR , false); +/* drop the cached xattr node, which may be dirty */ +truncate_inode_pages_range (NODE_MAPPING (sbi), +F2FS_BLK_TO_BYTES ((loff_t )ni.nid), +F2FS_BLK_END_BYTES ((loff_t )ni.nid)); +f2fs_i_xnid_write (inode,0 ); + } +f2fs_update_inode (inode, ifolio);f2fs_folio_put (ifolio, true);return 0 ;
Signature · 1 line
2.53.0