f2fs: convert inline quota files when turning quota on
PATCH 1/1 f2fs: convert inline quota files when turning quota on
From: Daeho Jeong <[email protected]>
With a block size larger than 4KB, the inline data area is large enough to hold a freshly created quota file (quotacheck writes 6KB), so aquota.user/aquota.group stay inline after quotaon. f2fs does not expect quota files to be inline, and this causes two problems:
1. Quota file corruption. f2fs_write_single_data_page() sends quota inodes straight to f2fs_do_write_data_page(), which sees NULL_ADDR for index 0, treats the folio as truncated and drops it. Updates to the quota file are lost once the folio is reclaimed, so the quota tree reads stale data: chown/chgrp fail with EIO and quota entries of users disappear. For example, the kernel log shows:
find_free_dqentry: Data block full but it shouldn't
qtree_write_dquot: Error -5 occurred while creating quota
2. Deadlock. Writing a quota file past MAX_INLINE_DATA converts it from f2fs_write_begin() under f2fs_lock_op(). dquot_transfer() is called from f2fs_setattr() with f2fs_lock_op() already held, so chown/chgrp take cp_rwsem for read twice and hang, together with the checkpoint and every other writer, once a checkpoint waits for cp_rwsem in between (seen with generic/232).
Quota files only grow and there are at most MAXQUOTAS of them, so there is no point in keeping them inline. Convert them in f2fs_quota_on() and after dquot_quota_on_mount(), which keeps every block size on the same path as 4KB blocks, where quota files never fit inline. Quota sysfiles are created by mkfs with real blocks and are not affected.
--- fs/f2fs/super.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-)
fs/f2fs/super.c +32 -1
@@ -3321,15 +3321,42 @@ static qsize_t *f2fs_get_reserved_space(struct inode *inode)return &F2FS_I (inode)->i_reserved_quota; } +/* +* Quota files only grow and there are at most MAXQUOTAS of them, so there is +* no point in keeping them inline. Writeback of quota files does not handle +* inline data and would drop what was written to them. +*/ +static int f2fs_quota_convert_inline (struct inode *inode) +{ +int err; + +if (!f2fs_has_inline_data (inode)) +return 0 ; + +inode_lock (inode); + err =f2fs_convert_inline_inode (inode); +inode_unlock (inode); +return err; +} +static int f2fs_quota_on_mount (struct f2fs_sb_info *sbi,int type) { +int err; +if (is_set_ckpt_flags (sbi,CP_QUOTA_NEED_FSCK_FLAG )) {f2fs_err (sbi,"quota sysfile may be corrupted, skip loading it" );return 0 ; } -return dquot_quota_on_mount (sbi->sb,F2FS_OPTION (sbi).s_qf_names[type], + err =dquot_quota_on_mount (sbi->sb,F2FS_OPTION (sbi).s_qf_names[type],F2FS_OPTION (sbi).s_jquota_fmt, type); +if (err) +return err; + + err =f2fs_quota_convert_inline (sb_dqopt (sbi->sb)->files[type]); +if (err) +dquot_quota_off (sbi->sb, type); +return err; }int f2fs_enable_quota_files (struct f2fs_sb_info *sbi,bool rdonly)
@@ -3534,6 +3561,10 @@ static int f2fs_quota_on(struct super_block *sb, int type, int format_id, inode =d_inode (path->dentry); + err =f2fs_quota_convert_inline (inode); +if (err) + goto out; + err =filemap_fdatawrite (inode->i_mapping);if (err) goto out;
Signature · 1 line
2.56.0.rc1.315.gc6ed9934b7-goog
Quoted 24 lines · Daeho Jeong
From: Daeho Jeong <[email protected]>
With a block size larger than 4KB, the inline data area is large enough to hold a freshly created quota file (quotacheck writes 6KB), so aquota.user/aquota.group stay inline after quotaon. f2fs does not expect quota files to be inline, and this causes two problems:
1. Quota file corruption.
f2fs_write_single_data_page()sends quota inodes straight tof2fs_do_write_data_page(), which seesNULL_ADDRfor index 0, treats the folio as truncated and drops it. Updates to the quota file are lost once the folio is reclaimed, so the quota tree reads stale data: chown/chgrp fail with EIO and quota entries of users disappear. For example, the kernel log shows:
find_free_dqentry: Data block full but it shouldn't
qtree_write_dquot: Error -5 occurred while creating quota2. Deadlock. Writing a quota file past
MAX_INLINE_DATAconverts it fromf2fs_write_begin()underf2fs_lock_op().dquot_transfer()is called fromf2fs_setattr()withf2fs_lock_op()already held, so chown/chgrp takecp_rwsemfor read twice and hang, together with the checkpoint and every other writer, once a checkpoint waits forcp_rwsemin between (seen with generic/232).
Quoted 6 lines
Quota files only grow and there are at most MAXQUOTAS of them, so there is no point in keeping them inline. Convert them in
f2fs_quota_on()and afterdquot_quota_on_mount(), which keeps every block size on the same path as 4KB blocks, where quota files never fit inline. Quota sysfiles are created by mkfs with real blocks and are not affected.
Quoted 2 lines
Fixes d7e9a9037de2 ("f2fs: Support Block Size == Page Size")Signed-off-by Daeho Jeong <[email protected]>
Thanks,
This patch was applied to jaegeuk/f2fs.git (dev) by Jaegeuk Kim <[email protected]>:
Hello:
This patch was applied to jaegeuk/f2fs.git (dev)
by Jaegeuk Kim <[email protected]>:
Quoted 8 lines · On Sun, 4 Oct 2026 17:04:56 +0000 you wrote:
From: Daeho Jeong <[email protected]>
With a block size larger than 4KB, the inline data area is large enough to hold a freshly created quota file (quotacheck writes 6KB), so aquota.user/aquota.group stay inline after quotaon. f2fs does not expect quota files to be inline, and this causes two problems:
[...]
Here is the summary with links:
- [f2fs-dev] f2fs: convert inline quota files when turning quota on
https://git.kernel.org/jaegeuk/f2fs/c/a85e09bd6cc8
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html