Commit bf245129 authored by Ye Bin's avatar Ye Bin Committed by sanglipeng1
Browse files

ext4: forbid commit inconsistent quota data when errors=remount-ro

stable inclusion
from stable-v5.10.215
commit 48882b489f90cfd8af21247368073c1dad5a32a9
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/IAJJ2D

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=48882b489f90cfd8af21247368073c1dad5a32a9



--------------------------------

[ Upstream commit d8b945fa475f13d787df00c26a6dc45a3e2e1d1d ]

There's issue as follows When do IO fault injection test:
Quota error (device dm-3): find_block_dqentry: Quota for id 101 referenced but not present
Quota error (device dm-3): qtree_read_dquot: Can't read quota structure for id 101
Quota error (device dm-3): do_check_range: Getting block 2021161007 out of range 1-186
Quota error (device dm-3): qtree_read_dquot: Can't read quota structure for id 661

Now, ext4_write_dquot()/ext4_acquire_dquot()/ext4_release_dquot() may commit
inconsistent quota data even if process failed. This may lead to filesystem
corruption.
To ensure filesystem consistent when errors=remount-ro there is need to call
ext4_handle_error() to abort journal.

Signed-off-by: default avatarYe Bin <yebin10@huawei.com>
Reviewed-by: default avatarJan Kara <jack@suse.cz>
Link: https://lore.kernel.org/r/20240119062908.3598806-1-yebin10@huawei.com


Signed-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
Signed-off-by: default avatarsanglipeng1 <sanglipeng1@jd.com>
parent b31e2816
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -6398,6 +6398,10 @@ static int ext4_write_dquot(struct dquot *dquot)
	if (IS_ERR(handle))
		return PTR_ERR(handle);
	ret = dquot_commit(dquot);
	if (ret < 0)
		ext4_error_err(dquot->dq_sb, -ret,
			       "Failed to commit dquot type %d",
			       dquot->dq_id.type);
	err = ext4_journal_stop(handle);
	if (!ret)
		ret = err;
@@ -6414,6 +6418,10 @@ static int ext4_acquire_dquot(struct dquot *dquot)
	if (IS_ERR(handle))
		return PTR_ERR(handle);
	ret = dquot_acquire(dquot);
	if (ret < 0)
		ext4_error_err(dquot->dq_sb, -ret,
			      "Failed to acquire dquot type %d",
			      dquot->dq_id.type);
	err = ext4_journal_stop(handle);
	if (!ret)
		ret = err;
@@ -6433,6 +6441,10 @@ static int ext4_release_dquot(struct dquot *dquot)
		return PTR_ERR(handle);
	}
	ret = dquot_release(dquot);
	if (ret < 0)
		ext4_error_err(dquot->dq_sb, -ret,
			       "Failed to release dquot type %d",
			       dquot->dq_id.type);
	err = ext4_journal_stop(handle);
	if (!ret)
		ret = err;