From: Chao Yu <chao@kernel.org>
To: jaegeuk@kernel.org
Cc: linux-f2fs-devel@lists.sourceforge.net,
linux-kernel@vger.kernel.org, Chao Yu <chao@kernel.org>,
stable@vger.kernel.org
Subject: [PATCH 2/6] f2fs: quota: fix to recheck quota flush after taking node_change in checkpoint
Date: Tue, 1 Dec 2026 11:08:44 +0000 [thread overview]
Message-ID: <20261201110842.1825797-8-chao@kernel.org> (raw)
In-Reply-To: <20261201110842.1825797-7-chao@kernel.org>
From: Chao Yu <chao@kernel.org>
block_operations() flushes quota until __need_flush_quota() returns
false, then takes node_change and rechecks F2FS_DIRTY_IMETA. However,
block allocation w/ F2FS_GET_BLOCK_PRE_AIO only holds node_change, so
it can dirty quota in between, and the F2FS_DIRTY_IMETA recheck misses
it once the inode is synced:
checkpoint write (F2FS_GET_BLOCK_PRE_AIO)
block_operations
f2fs_lock_all
__need_flush_quota
: return false
prepare_write_begin
f2fs_map_lock(node_change)
f2fs_reserve_block
: dirty dquot, update i_blocks
f2fs_map_unlock(node_change)
f2fs_write_inode
: clear F2FS_DIRTY_IMETA
f2fs_down_write(node_change)
F2FS_DIRTY_IMETA is 0, go on
do_checkpoint
: persist new i_blocks w/ stale quota,
CP_QUOTA_NEED_FSCK_FLAG is not set
After a sudden power-off, fsck.f2fs reports "Quota file is missing or
invalid quota file content found." w/o quota_need_fsck flag in the
checkpoint. It was hit by f2fs consistency test (fault injection +
fsstress/fio/atomic write + periodic shutdown).
Fix it by rechecking quota after taking node_change, and retrying the
quota flush if quota is dirty, or quota_sem is held, e.g. quota file
is written by f2fs_dquot_acquire(). The retry is still bounded by
DEFAULT_RETRY_QUOTA_FLUSH_COUNT, and the recheck is skipped once
SBI_QUOTA_SKIP_FLUSH is set.
Cc: stable@vger.kernel.org
Fixes: db6ec53b7e03 ("f2fs: add a rw_sem to cover quota flag changes")
Signed-off-by: Chao Yu <chao@kernel.org>
---
fs/f2fs/checkpoint.c | 30 +++++++++++++++++++++++++++++-
1 file changed, 29 insertions(+), 1 deletion(-)
diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c
index a8c98a2acc53..a5efc2a82224 100644
--- a/fs/f2fs/checkpoint.c
+++ b/fs/f2fs/checkpoint.c
@@ -1522,6 +1522,29 @@ static bool __need_flush_quota(struct f2fs_sb_info *sbi)
return ret;
}
+/* Like __need_flush_quota(), but don't clear SBI_QUOTA_NEED_FLUSH. */
+static bool __quota_flush_pending(struct f2fs_sb_info *sbi)
+{
+ bool ret = false;
+
+ if (!is_journalled_quota(sbi))
+ return false;
+
+ /* we gave up flushing quota, don't retry */
+ if (is_sbi_flag_set(sbi, SBI_QUOTA_SKIP_FLUSH))
+ return false;
+
+ /* quota is being updated, e.g. by f2fs_dquot_acquire() */
+ if (!f2fs_down_write_trylock(&sbi->quota_sem))
+ return true;
+ if (!is_sbi_flag_set(sbi, SBI_QUOTA_NEED_REPAIR) &&
+ (is_sbi_flag_set(sbi, SBI_QUOTA_NEED_FLUSH) ||
+ get_nr_caches(sbi, F2FS_DIRTY_QDATA)))
+ ret = true;
+ f2fs_up_write(&sbi->quota_sem);
+ return ret;
+}
+
/*
* Freeze all the FS-operations for checkpoint.
*/
@@ -1574,7 +1597,12 @@ static int block_operations(struct f2fs_sb_info *sbi)
*/
f2fs_down_write(&sbi->node_change);
- if (get_nr_caches(sbi, F2FS_DIRTY_IMETA)) {
+ /*
+ * F2FS_GET_BLOCK_PRE_AIO allocates blocks w/ node_change only, so it
+ * may have updated i_blocks and quota since the checks above.
+ */
+ if (get_nr_caches(sbi, F2FS_DIRTY_IMETA) ||
+ __quota_flush_pending(sbi)) {
f2fs_up_write(&sbi->node_change);
f2fs_unlock_all(sbi);
err = f2fs_sync_inode_meta(sbi);
--
2.49.0
next prev parent reply other threads:[~2026-12-01 11:08 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 11:08 [PATCH 1/6] f2fs: fix to clear SBI_IS_CLOSE in __f2fs_remount() Chao Yu
2026-12-01 11:08 ` Chao Yu [this message]
2026-12-01 11:08 ` [PATCH 3/6] f2fs: cache: fix to submit cached DATA bio when waiting writeback of meta cache Chao Yu
2026-12-01 11:08 ` [PATCH 4/6] f2fs: atomic: fix to keep committed data of atomic file in f2fs_write_failed() Chao Yu
2026-12-01 11:08 ` [PATCH 5/6] f2fs: atomic: fix to avoid preallocating blocks in original inode for atomic file Chao Yu
2026-12-01 11:08 ` [PATCH 6/6] f2fs: atomic: fix to disallow shrinking atomic file via truncate Chao Yu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261201110842.1825797-8-chao@kernel.org \
--to=chao@kernel.org \
--cc=jaegeuk@kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox