Commit cb3de5f
ext4: fix a potential assertion failure due to improperly dirtied buffer
On an old kernel version(4.19, ext3, data=journal, pagesize=64k),
an assertion failure will occasionally be triggered by the line below:
-----------
jbd2_journal_commit_transaction
{
...
J_ASSERT_BH(bh, !buffer_dirty(bh));
/*
* The buffer on BJ_Forget list and not jbddirty means
...
}
-----------
The same condition may also be applied to the lattest kernel version.
When blocksize < pagesize and we truncate a file, there can be buffers in
the mapping tail page beyond i_size. These buffers will be filed to
transaction's BJ_Forget list by ext4_journalled_invalidatepage() during
truncation. When the transaction doing truncate starts committing, we can
grow the file again. This calls __block_write_begin() which allocates new
blocks under these buffers in the tail page we go through the branch:
if (buffer_new(bh)) {
clean_bdev_bh_alias(bh);
if (folio_test_uptodate(folio)) {
clear_buffer_new(bh);
set_buffer_uptodate(bh);
mark_buffer_dirty(bh);
continue;
}
...
}
Hence buffers on BJ_Forget list of the committing transaction get marked
dirty and this triggers the jbd2 assertion.
Teach ext4_block_write_begin() to properly handle files with data
journalling by avoiding dirtying them directly. Instead of
folio_zero_new_buffers() we use ext4_journalled_zero_new_buffers() which
takes care of handling journalling. We also don't need to mark new uptodate
buffers as dirty in ext4_block_write_begin(). That will be either done
either by block_commit_write() in case of success or by
folio_zero_new_buffers() in case of failure.
Reported-by: Baolin Liu <liubaolin@kylinos.cn>
Suggested-by: Jan Kara <jack@suse.cz>
Signed-off-by: Shida Zhang <zhangshida@kylinos.cn>
Reviewed-by: Jan Kara <jack@suse.cz>
Link: https://patch.msgid.link/20240830053739.3588573-4-zhangshida@kylinos.cn
Signed-off-by: Theodore Ts'o <tytso@mit.edu>1 parent 6b730a4 commit cb3de5f
3 files changed
+40
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3853 | 3853 | | |
3854 | 3854 | | |
3855 | 3855 | | |
3856 | | - | |
| 3856 | + | |
| 3857 | + | |
3857 | 3858 | | |
3858 | 3859 | | |
3859 | 3860 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
601 | 601 | | |
602 | 602 | | |
603 | 603 | | |
604 | | - | |
| 604 | + | |
605 | 605 | | |
606 | 606 | | |
607 | | - | |
| 607 | + | |
| 608 | + | |
608 | 609 | | |
609 | 610 | | |
610 | 611 | | |
| |||
856 | 857 | | |
857 | 858 | | |
858 | 859 | | |
859 | | - | |
| 860 | + | |
860 | 861 | | |
861 | 862 | | |
862 | 863 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
52 | 57 | | |
53 | 58 | | |
54 | 59 | | |
| |||
1023 | 1028 | | |
1024 | 1029 | | |
1025 | 1030 | | |
1026 | | - | |
| 1031 | + | |
| 1032 | + | |
1027 | 1033 | | |
1028 | 1034 | | |
1029 | 1035 | | |
| |||
1037 | 1043 | | |
1038 | 1044 | | |
1039 | 1045 | | |
| 1046 | + | |
1040 | 1047 | | |
1041 | 1048 | | |
1042 | 1049 | | |
| |||
1066 | 1073 | | |
1067 | 1074 | | |
1068 | 1075 | | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
| 1083 | + | |
1069 | 1084 | | |
1070 | | - | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
1071 | 1091 | | |
1072 | | - | |
1073 | 1092 | | |
1074 | 1093 | | |
1075 | 1094 | | |
| |||
1099 | 1118 | | |
1100 | 1119 | | |
1101 | 1120 | | |
1102 | | - | |
| 1121 | + | |
| 1122 | + | |
| 1123 | + | |
| 1124 | + | |
| 1125 | + | |
1103 | 1126 | | |
1104 | 1127 | | |
1105 | 1128 | | |
| |||
1197 | 1220 | | |
1198 | 1221 | | |
1199 | 1222 | | |
1200 | | - | |
| 1223 | + | |
1201 | 1224 | | |
1202 | 1225 | | |
1203 | | - | |
| 1226 | + | |
| 1227 | + | |
1204 | 1228 | | |
1205 | 1229 | | |
1206 | 1230 | | |
| |||
2926 | 2950 | | |
2927 | 2951 | | |
2928 | 2952 | | |
2929 | | - | |
| 2953 | + | |
| 2954 | + | |
2930 | 2955 | | |
2931 | 2956 | | |
2932 | 2957 | | |
| |||
6183 | 6208 | | |
6184 | 6209 | | |
6185 | 6210 | | |
6186 | | - | |
| 6211 | + | |
| 6212 | + | |
6187 | 6213 | | |
6188 | 6214 | | |
6189 | 6215 | | |
| |||
0 commit comments