* [PATCH] f2fs: fix to do sanity check on nat entry of quota inode
@ 2025-12-19 2:51 Chao Yu
2025-12-19 3:05 ` [f2fs-dev] " Zhiguo Niu
2026-01-07 3:30 ` patchwork-bot+f2fs
0 siblings, 2 replies; 3+ messages in thread
From: Chao Yu @ 2025-12-19 2:51 UTC (permalink / raw)
To: jaegeuk; +Cc: linux-f2fs-devel, linux-kernel, Chao Yu, Zhiguo Niu
As Zhiguo reported, nat entry of quota inode could be corrupted:
"ino/block_addr=NULL_ADDR in nid=4 entry"
We'd better to do sanity check on quota inode to detect and record
nat.blk_addr inconsistency, so that we can have a chance to repair
it w/ later fsck.
Reported-by: Zhiguo Niu <zhiguo.niu@unisoc.com>
Signed-off-by: Chao Yu <chao@kernel.org>
---
fs/f2fs/f2fs.h | 6 +++---
fs/f2fs/inode.c | 2 +-
fs/f2fs/node.c | 11 +++++++++++
3 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 65ca1a5eaa88..c458df92bb0d 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -4928,16 +4928,16 @@ static inline bool is_journalled_quota(struct f2fs_sb_info *sbi)
return false;
}
-static inline bool f2fs_quota_file(struct inode *inode)
+static inline bool f2fs_quota_file(struct f2fs_sb_info *sbi, nid_t ino)
{
#ifdef CONFIG_QUOTA
int i;
- if (!f2fs_sb_has_quota_ino(F2FS_I_SB(inode)))
+ if (!f2fs_sb_has_quota_ino(sbi))
return false;
for (i = 0; i < MAXQUOTAS; i++) {
- if (f2fs_qf_ino(F2FS_I_SB(inode)->sb, i) == inode->i_ino)
+ if (f2fs_qf_ino(sbi->sb, i) == ino)
return true;
}
#endif
diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c
index 921fb02c0f49..d1270b25ad7d 100644
--- a/fs/f2fs/inode.c
+++ b/fs/f2fs/inode.c
@@ -621,7 +621,7 @@ struct inode *f2fs_iget(struct super_block *sb, unsigned long ino)
inode->i_fop = &f2fs_file_operations;
inode->i_mapping->a_ops = &f2fs_dblock_aops;
if (IS_IMMUTABLE(inode) && !f2fs_compressed_file(inode) &&
- !f2fs_quota_file(inode))
+ !f2fs_quota_file(sbi, inode->i_ino))
mapping_set_folio_min_order(inode->i_mapping, 0);
} else if (S_ISDIR(inode->i_mode)) {
inode->i_op = &f2fs_dir_inode_operations;
diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
index 7feead595ba5..f1e6fa2dccc9 100644
--- a/fs/f2fs/node.c
+++ b/fs/f2fs/node.c
@@ -643,6 +643,17 @@ int f2fs_get_node_info(struct f2fs_sb_info *sbi, nid_t nid,
return -EFSCORRUPTED;
}
+ if (unlikely(f2fs_quota_file(sbi, ni->nid) &&
+ !__is_valid_data_blkaddr(ni->blk_addr))) {
+ set_sbi_flag(sbi, SBI_NEED_FSCK);
+ f2fs_err_ratelimited(sbi,
+ "f2fs_get_node_info of %pS: inconsistent nat entry from qf_ino, "
+ "ino:%u, nid:%u, blkaddr:%u, ver:%u, flag:%u",
+ __builtin_return_address(0),
+ ni->ino, ni->nid, ni->blk_addr, ni->version, ni->flag);
+ f2fs_handle_error(sbi, ERROR_INCONSISTENT_NAT);
+ }
+
/* cache nat entry */
if (need_cache)
cache_nat_entry(sbi, nid, &ne);
--
2.40.1
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [f2fs-dev] [PATCH] f2fs: fix to do sanity check on nat entry of quota inode
2025-12-19 2:51 [PATCH] f2fs: fix to do sanity check on nat entry of quota inode Chao Yu
@ 2025-12-19 3:05 ` Zhiguo Niu
2026-01-07 3:30 ` patchwork-bot+f2fs
1 sibling, 0 replies; 3+ messages in thread
From: Zhiguo Niu @ 2025-12-19 3:05 UTC (permalink / raw)
To: Chao Yu; +Cc: jaegeuk, Zhiguo Niu, linux-kernel, linux-f2fs-devel
Chao Yu via Linux-f2fs-devel <linux-f2fs-devel@lists.sourceforge.net>
于2025年12月19日周五 10:56写道:
>
> As Zhiguo reported, nat entry of quota inode could be corrupted:
>
> "ino/block_addr=NULL_ADDR in nid=4 entry"
>
> We'd better to do sanity check on quota inode to detect and record
> nat.blk_addr inconsistency, so that we can have a chance to repair
> it w/ later fsck.
>
> Reported-by: Zhiguo Niu <zhiguo.niu@unisoc.com>
> Signed-off-by: Chao Yu <chao@kernel.org>
Reviewed-by: Zhiguo Niu <zhiguo.niu@unisoc.com>
Thanks!
> ---
> fs/f2fs/f2fs.h | 6 +++---
> fs/f2fs/inode.c | 2 +-
> fs/f2fs/node.c | 11 +++++++++++
> 3 files changed, 15 insertions(+), 4 deletions(-)
>
> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
> index 65ca1a5eaa88..c458df92bb0d 100644
> --- a/fs/f2fs/f2fs.h
> +++ b/fs/f2fs/f2fs.h
> @@ -4928,16 +4928,16 @@ static inline bool is_journalled_quota(struct f2fs_sb_info *sbi)
> return false;
> }
>
> -static inline bool f2fs_quota_file(struct inode *inode)
> +static inline bool f2fs_quota_file(struct f2fs_sb_info *sbi, nid_t ino)
> {
> #ifdef CONFIG_QUOTA
> int i;
>
> - if (!f2fs_sb_has_quota_ino(F2FS_I_SB(inode)))
> + if (!f2fs_sb_has_quota_ino(sbi))
> return false;
>
> for (i = 0; i < MAXQUOTAS; i++) {
> - if (f2fs_qf_ino(F2FS_I_SB(inode)->sb, i) == inode->i_ino)
> + if (f2fs_qf_ino(sbi->sb, i) == ino)
> return true;
> }
> #endif
> diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c
> index 921fb02c0f49..d1270b25ad7d 100644
> --- a/fs/f2fs/inode.c
> +++ b/fs/f2fs/inode.c
> @@ -621,7 +621,7 @@ struct inode *f2fs_iget(struct super_block *sb, unsigned long ino)
> inode->i_fop = &f2fs_file_operations;
> inode->i_mapping->a_ops = &f2fs_dblock_aops;
> if (IS_IMMUTABLE(inode) && !f2fs_compressed_file(inode) &&
> - !f2fs_quota_file(inode))
> + !f2fs_quota_file(sbi, inode->i_ino))
> mapping_set_folio_min_order(inode->i_mapping, 0);
> } else if (S_ISDIR(inode->i_mode)) {
> inode->i_op = &f2fs_dir_inode_operations;
> diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
> index 7feead595ba5..f1e6fa2dccc9 100644
> --- a/fs/f2fs/node.c
> +++ b/fs/f2fs/node.c
> @@ -643,6 +643,17 @@ int f2fs_get_node_info(struct f2fs_sb_info *sbi, nid_t nid,
> return -EFSCORRUPTED;
> }
>
> + if (unlikely(f2fs_quota_file(sbi, ni->nid) &&
> + !__is_valid_data_blkaddr(ni->blk_addr))) {
> + set_sbi_flag(sbi, SBI_NEED_FSCK);
> + f2fs_err_ratelimited(sbi,
> + "f2fs_get_node_info of %pS: inconsistent nat entry from qf_ino, "
> + "ino:%u, nid:%u, blkaddr:%u, ver:%u, flag:%u",
> + __builtin_return_address(0),
> + ni->ino, ni->nid, ni->blk_addr, ni->version, ni->flag);
> + f2fs_handle_error(sbi, ERROR_INCONSISTENT_NAT);
> + }
> +
> /* cache nat entry */
> if (need_cache)
> cache_nat_entry(sbi, nid, &ne);
> --
> 2.40.1
>
>
>
> _______________________________________________
> Linux-f2fs-devel mailing list
> Linux-f2fs-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [f2fs-dev] [PATCH] f2fs: fix to do sanity check on nat entry of quota inode
2025-12-19 2:51 [PATCH] f2fs: fix to do sanity check on nat entry of quota inode Chao Yu
2025-12-19 3:05 ` [f2fs-dev] " Zhiguo Niu
@ 2026-01-07 3:30 ` patchwork-bot+f2fs
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+f2fs @ 2026-01-07 3:30 UTC (permalink / raw)
To: Chao Yu; +Cc: jaegeuk, zhiguo.niu, linux-kernel, linux-f2fs-devel
Hello:
This patch was applied to jaegeuk/f2fs.git (dev)
by Jaegeuk Kim <jaegeuk@kernel.org>:
On Fri, 19 Dec 2025 10:51:04 +0800 you wrote:
> As Zhiguo reported, nat entry of quota inode could be corrupted:
>
> "ino/block_addr=NULL_ADDR in nid=4 entry"
>
> We'd better to do sanity check on quota inode to detect and record
> nat.blk_addr inconsistency, so that we can have a chance to repair
> it w/ later fsck.
>
> [...]
Here is the summary with links:
- [f2fs-dev] f2fs: fix to do sanity check on nat entry of quota inode
https://git.kernel.org/jaegeuk/f2fs/c/3cb396a2c790
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-01-07 3:33 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-12-19 2:51 [PATCH] f2fs: fix to do sanity check on nat entry of quota inode Chao Yu
2025-12-19 3:05 ` [f2fs-dev] " Zhiguo Niu
2026-01-07 3:30 ` patchwork-bot+f2fs
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®