From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796123332; b=s2DI693w8nLsx4sNY2zA025+3JcPymecwhrGCMlWbvZKg6vuTPNeRd2/mBEz7zubew3e xb76gggmkVAbVrKtJDAlJeP8YLWkrVZfoWcpYiGkcrgWfLvMvCq/lxJ08vEvNWeAdtnlQ Ie+BvvOZ1r77g9hM4jBNZJSnOvEnq+eS8TQjLgpFNwoeCAlvLNWynF0eseHn2YYnZ5SSC Nx86lBjURRlzXR/2dCNAkTxXlGdJnnQrRHja0EuPkd0nTDQUp1kjeghSlA4wdfsXiO2yW tSt2FeX/sXUj0gAmN1xwvL/uRbG1ZK6rKXOhw7R+sPccutBc171Xr32eo4/lSzMbtiQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796123332; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=RtKej1zV8U3E0L1FmGazOkEhPSjmHhIc+b5K+8jkmsw=; b=jiPxXAAsvtaQudf+Zj6P3+YXEbSbo+hYtCAUn9XGtEPOOkXw9zYMNx1hSzyTndmtJbT3 hf61EtIaq5rWaUrsTjvpN2sJaGYI3CAcJCFy9dlq7Q0jyeWQ1A8bz3OCV5SkPwg6KVQqD 9HvLGefhurRsS/pQd2Fv1yflC9EdwVsVMQFqUh8yGj1+R+cc3IpFuccNPbitbWW9IgT7E iuHhh1J1xEsG4bSMnwAWpZpta1TFkF/zUkwsPbfg4Bc0q0PxpHMiQeEwPV0j+pe8LsC1x CtWwNOkfTa2a4mrlgJ3CXrU4PedHvghy2E2Z1KxsAArXGLZKyX521DfeJdfeuoyLvng== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=W4rs10Oa; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 376F9606A329; Tue, 1 Dec 2026 11:08:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=W4rs10Oa Received: by smtp.kernel.org (Postfix) with ESMTPSA id 317C71F00898; Tue, 1 Dec 2026 11:08:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796123332; bh=RtKej1zV8U3E0L1FmGazOkEhPSjmHhIc+b5K+8jkmsw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=W4rs10Oa5tN4a+RckIgOY+PNsZdBHJ6NCxvPBoRQU98aTtVPKnQo+752mAd86TGqF gRi4LqsdkQnhnKzaA6HCMzkfZMLSCgLCji0UvWcnfsgGa1Cb5Ajhk4kErsmNHL2bFT qtP/Ui+RQ11aH07ZUvmRPm8HY7NAyLFNb3pd2AVToAOZQAS+49nI99G+vg1EbjyByg nYNkeONKvEM/FXqlFecsqk3ts73VIc0QTpVA8Kl4QtEr1eSZesRaCMSmiJd4LSnFwl VFXiNQ3J+hTBU5A4OMRlbutA/V3z6GLfvoSHEfSVktwWw4zj22KSO3hv8LgPVeZAKY y3RAdyv2pTssA== From: Chao Yu To: jaegeuk@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Chao Yu , 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 Message-ID: <20261201110842.1825797-8-chao@kernel.org> X-Mailer: git-send-email 2.56.1.839.g22a8290db9-goog In-Reply-To: <20261201110842.1825797-7-chao@kernel.org> References: <20261201110842.1825797-7-chao@kernel.org> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Chao Yu 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 --- 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