1 From 671376cc826fe7d12bc92e1d7d96671c0dbbf985 Mon Sep 17 00:00:00 2001
2 From: Sasha Levin <sashal@kernel.org>
3 Date: Fri, 19 Jan 2024 14:29:08 +0800
4 Subject: ext4: forbid commit inconsistent quota data when errors=remount-ro
6 From: Ye Bin <yebin10@huawei.com>
8 [ Upstream commit d8b945fa475f13d787df00c26a6dc45a3e2e1d1d ]
10 There's issue as follows When do IO fault injection test:
11 Quota error (device dm-3): find_block_dqentry: Quota for id 101 referenced but not present
12 Quota error (device dm-3): qtree_read_dquot: Can't read quota structure for id 101
13 Quota error (device dm-3): do_check_range: Getting block 2021161007 out of range 1-186
14 Quota error (device dm-3): qtree_read_dquot: Can't read quota structure for id 661
16 Now, ext4_write_dquot()/ext4_acquire_dquot()/ext4_release_dquot() may commit
17 inconsistent quota data even if process failed. This may lead to filesystem
19 To ensure filesystem consistent when errors=remount-ro there is need to call
20 ext4_handle_error() to abort journal.
22 Signed-off-by: Ye Bin <yebin10@huawei.com>
23 Reviewed-by: Jan Kara <jack@suse.cz>
24 Link: https://lore.kernel.org/r/20240119062908.3598806-1-yebin10@huawei.com
25 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
26 Signed-off-by: Sasha Levin <sashal@kernel.org>
28 fs/ext4/super.c | 12 ++++++++++++
29 1 file changed, 12 insertions(+)
31 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
32 index 32bd83adf0bb8..4866657c6d41f 100644
35 @@ -6864,6 +6864,10 @@ static int ext4_write_dquot(struct dquot *dquot)
37 return PTR_ERR(handle);
38 ret = dquot_commit(dquot);
40 + ext4_error_err(dquot->dq_sb, -ret,
41 + "Failed to commit dquot type %d",
43 err = ext4_journal_stop(handle);
46 @@ -6880,6 +6884,10 @@ static int ext4_acquire_dquot(struct dquot *dquot)
48 return PTR_ERR(handle);
49 ret = dquot_acquire(dquot);
51 + ext4_error_err(dquot->dq_sb, -ret,
52 + "Failed to acquire dquot type %d",
54 err = ext4_journal_stop(handle);
57 @@ -6899,6 +6907,10 @@ static int ext4_release_dquot(struct dquot *dquot)
58 return PTR_ERR(handle);
60 ret = dquot_release(dquot);
62 + ext4_error_err(dquot->dq_sb, -ret,
63 + "Failed to release dquot type %d",
65 err = ext4_journal_stop(handle);