Skip to content

Commit 6a797d2

Browse files
djwongtytso
authored andcommitted
ext4: call out CRC and corruption errors with specific error codes
Instead of overloading EIO for CRC errors and corrupt structures, return the same error codes that XFS returns for the same issues. Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent 8c81bd8 commit 6a797d2

16 files changed

Lines changed: 107 additions & 88 deletions

File tree

‎fs/ext4/balloc.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ static int ext4_init_block_bitmap(struct super_block *sb,
203203
count);
204204
}
205205
set_bit(EXT4_GROUP_INFO_IBITMAP_CORRUPT_BIT, &grp->bb_state);
206-
return -EIO;
206+
return -EFSBADCRC;
207207
}
208208
memset(bh->b_data, 0, sb->s_blocksize);
209209

‎fs/ext4/block_validity.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ int ext4_check_blockref(const char *function, unsigned int line,
234234
es->s_last_error_block = cpu_to_le64(blk);
235235
ext4_error_inode(inode, function, line, blk,
236236
"invalid block");
237-
return -EIO;
237+
return -EFSCORRUPTED;
238238
}
239239
}
240240
return 0;

‎fs/ext4/dir.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -621,14 +621,14 @@ int ext4_check_all_de(struct inode *dir, struct buffer_head *bh, void *buf,
621621
while ((char *) de < top) {
622622
if (ext4_check_dir_entry(dir, NULL, de, bh,
623623
buf, buf_size, offset))
624-
return -EIO;
624+
return -EFSCORRUPTED;
625625
nlen = EXT4_DIR_REC_LEN(de->name_len);
626626
rlen = ext4_rec_len_from_disk(de->rec_len, buf_size);
627627
de = (struct ext4_dir_entry_2 *)((char *)de + rlen);
628628
offset += rlen;
629629
}
630630
if ((char *) de > top)
631-
return -EIO;
631+
return -EFSCORRUPTED;
632632

633633
return 0;
634634
}

‎fs/ext4/ext4.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3064,4 +3064,7 @@ extern void ext4_resize_end(struct super_block *sb);
30643064

30653065
#endif /* __KERNEL__ */
30663066

3067+
#define EFSBADCRC EBADMSG /* Bad CRC detected */
3068+
#define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */
3069+
30673070
#endif /* _EXT4_H */

‎fs/ext4/extents.c‎

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ static int __ext4_ext_check(const char *function, unsigned int line,
442442
int depth, ext4_fsblk_t pblk)
443443
{
444444
const char *error_msg;
445-
int max = 0;
445+
int max = 0, err = -EFSCORRUPTED;
446446

447447
if (unlikely(eh->eh_magic != EXT4_EXT_MAGIC)) {
448448
error_msg = "invalid magic";
@@ -473,6 +473,7 @@ static int __ext4_ext_check(const char *function, unsigned int line,
473473
if (ext_depth(inode) != depth &&
474474
!ext4_extent_block_csum_verify(inode, eh)) {
475475
error_msg = "extent tree corrupted";
476+
err = -EFSBADCRC;
476477
goto corrupted;
477478
}
478479
return 0;
@@ -485,7 +486,7 @@ static int __ext4_ext_check(const char *function, unsigned int line,
485486
le16_to_cpu(eh->eh_magic),
486487
le16_to_cpu(eh->eh_entries), le16_to_cpu(eh->eh_max),
487488
max, le16_to_cpu(eh->eh_depth), depth);
488-
return -EIO;
489+
return err;
489490
}
490491

491492
#define ext4_ext_check(inode, eh, depth, pblk) \
@@ -910,7 +911,7 @@ ext4_find_extent(struct inode *inode, ext4_lblk_t block,
910911
put_bh(bh);
911912
EXT4_ERROR_INODE(inode,
912913
"ppos %d > depth %d", ppos, depth);
913-
ret = -EIO;
914+
ret = -EFSCORRUPTED;
914915
goto err;
915916
}
916917
path[ppos].p_bh = bh;
@@ -959,7 +960,7 @@ static int ext4_ext_insert_index(handle_t *handle, struct inode *inode,
959960
EXT4_ERROR_INODE(inode,
960961
"logical %d == ei_block %d!",
961962
logical, le32_to_cpu(curp->p_idx->ei_block));
962-
return -EIO;
963+
return -EFSCORRUPTED;
963964
}
964965

965966
if (unlikely(le16_to_cpu(curp->p_hdr->eh_entries)
@@ -968,7 +969,7 @@ static int ext4_ext_insert_index(handle_t *handle, struct inode *inode,
968969
"eh_entries %d >= eh_max %d!",
969970
le16_to_cpu(curp->p_hdr->eh_entries),
970971
le16_to_cpu(curp->p_hdr->eh_max));
971-
return -EIO;
972+
return -EFSCORRUPTED;
972973
}
973974

974975
if (logical > le32_to_cpu(curp->p_idx->ei_block)) {
@@ -992,7 +993,7 @@ static int ext4_ext_insert_index(handle_t *handle, struct inode *inode,
992993

993994
if (unlikely(ix > EXT_MAX_INDEX(curp->p_hdr))) {
994995
EXT4_ERROR_INODE(inode, "ix > EXT_MAX_INDEX!");
995-
return -EIO;
996+
return -EFSCORRUPTED;
996997
}
997998

998999
ix->ei_block = cpu_to_le32(logical);
@@ -1001,7 +1002,7 @@ static int ext4_ext_insert_index(handle_t *handle, struct inode *inode,
10011002

10021003
if (unlikely(ix > EXT_LAST_INDEX(curp->p_hdr))) {
10031004
EXT4_ERROR_INODE(inode, "ix > EXT_LAST_INDEX!");
1004-
return -EIO;
1005+
return -EFSCORRUPTED;
10051006
}
10061007

10071008
err = ext4_ext_dirty(handle, inode, curp);
@@ -1042,7 +1043,7 @@ static int ext4_ext_split(handle_t *handle, struct inode *inode,
10421043
* border from split point */
10431044
if (unlikely(path[depth].p_ext > EXT_MAX_EXTENT(path[depth].p_hdr))) {
10441045
EXT4_ERROR_INODE(inode, "p_ext > EXT_MAX_EXTENT!");
1045-
return -EIO;
1046+
return -EFSCORRUPTED;
10461047
}
10471048
if (path[depth].p_ext != EXT_MAX_EXTENT(path[depth].p_hdr)) {
10481049
border = path[depth].p_ext[1].ee_block;
@@ -1086,7 +1087,7 @@ static int ext4_ext_split(handle_t *handle, struct inode *inode,
10861087
newblock = ablocks[--a];
10871088
if (unlikely(newblock == 0)) {
10881089
EXT4_ERROR_INODE(inode, "newblock == 0!");
1089-
err = -EIO;
1090+
err = -EFSCORRUPTED;
10901091
goto cleanup;
10911092
}
10921093
bh = sb_getblk_gfp(inode->i_sb, newblock, __GFP_MOVABLE | GFP_NOFS);
@@ -1112,7 +1113,7 @@ static int ext4_ext_split(handle_t *handle, struct inode *inode,
11121113
EXT4_ERROR_INODE(inode, "eh_entries %d != eh_max %d!",
11131114
path[depth].p_hdr->eh_entries,
11141115
path[depth].p_hdr->eh_max);
1115-
err = -EIO;
1116+
err = -EFSCORRUPTED;
11161117
goto cleanup;
11171118
}
11181119
/* start copy from next extent */
@@ -1151,7 +1152,7 @@ static int ext4_ext_split(handle_t *handle, struct inode *inode,
11511152
k = depth - at - 1;
11521153
if (unlikely(k < 0)) {
11531154
EXT4_ERROR_INODE(inode, "k %d < 0!", k);
1154-
err = -EIO;
1155+
err = -EFSCORRUPTED;
11551156
goto cleanup;
11561157
}
11571158
if (k)
@@ -1191,7 +1192,7 @@ static int ext4_ext_split(handle_t *handle, struct inode *inode,
11911192
EXT4_ERROR_INODE(inode,
11921193
"EXT_MAX_INDEX != EXT_LAST_INDEX ee_block %d!",
11931194
le32_to_cpu(path[i].p_ext->ee_block));
1194-
err = -EIO;
1195+
err = -EFSCORRUPTED;
11951196
goto cleanup;
11961197
}
11971198
/* start copy indexes */
@@ -1425,7 +1426,7 @@ static int ext4_ext_search_left(struct inode *inode,
14251426

14261427
if (unlikely(path == NULL)) {
14271428
EXT4_ERROR_INODE(inode, "path == NULL *logical %d!", *logical);
1428-
return -EIO;
1429+
return -EFSCORRUPTED;
14291430
}
14301431
depth = path->p_depth;
14311432
*phys = 0;
@@ -1444,7 +1445,7 @@ static int ext4_ext_search_left(struct inode *inode,
14441445
EXT4_ERROR_INODE(inode,
14451446
"EXT_FIRST_EXTENT != ex *logical %d ee_block %d!",
14461447
*logical, le32_to_cpu(ex->ee_block));
1447-
return -EIO;
1448+
return -EFSCORRUPTED;
14481449
}
14491450
while (--depth >= 0) {
14501451
ix = path[depth].p_idx;
@@ -1455,7 +1456,7 @@ static int ext4_ext_search_left(struct inode *inode,
14551456
EXT_FIRST_INDEX(path[depth].p_hdr) != NULL ?
14561457
le32_to_cpu(EXT_FIRST_INDEX(path[depth].p_hdr)->ei_block) : 0,
14571458
depth);
1458-
return -EIO;
1459+
return -EFSCORRUPTED;
14591460
}
14601461
}
14611462
return 0;
@@ -1465,7 +1466,7 @@ static int ext4_ext_search_left(struct inode *inode,
14651466
EXT4_ERROR_INODE(inode,
14661467
"logical %d < ee_block %d + ee_len %d!",
14671468
*logical, le32_to_cpu(ex->ee_block), ee_len);
1468-
return -EIO;
1469+
return -EFSCORRUPTED;
14691470
}
14701471

14711472
*logical = le32_to_cpu(ex->ee_block) + ee_len - 1;
@@ -1495,7 +1496,7 @@ static int ext4_ext_search_right(struct inode *inode,
14951496

14961497
if (unlikely(path == NULL)) {
14971498
EXT4_ERROR_INODE(inode, "path == NULL *logical %d!", *logical);
1498-
return -EIO;
1499+
return -EFSCORRUPTED;
14991500
}
15001501
depth = path->p_depth;
15011502
*phys = 0;
@@ -1514,15 +1515,15 @@ static int ext4_ext_search_right(struct inode *inode,
15141515
EXT4_ERROR_INODE(inode,
15151516
"first_extent(path[%d].p_hdr) != ex",
15161517
depth);
1517-
return -EIO;
1518+
return -EFSCORRUPTED;
15181519
}
15191520
while (--depth >= 0) {
15201521
ix = path[depth].p_idx;
15211522
if (unlikely(ix != EXT_FIRST_INDEX(path[depth].p_hdr))) {
15221523
EXT4_ERROR_INODE(inode,
15231524
"ix != EXT_FIRST_INDEX *logical %d!",
15241525
*logical);
1525-
return -EIO;
1526+
return -EFSCORRUPTED;
15261527
}
15271528
}
15281529
goto found_extent;
@@ -1532,7 +1533,7 @@ static int ext4_ext_search_right(struct inode *inode,
15321533
EXT4_ERROR_INODE(inode,
15331534
"logical %d < ee_block %d + ee_len %d!",
15341535
*logical, le32_to_cpu(ex->ee_block), ee_len);
1535-
return -EIO;
1536+
return -EFSCORRUPTED;
15361537
}
15371538

15381539
if (ex != EXT_LAST_EXTENT(path[depth].p_hdr)) {
@@ -1670,7 +1671,7 @@ static int ext4_ext_correct_indexes(handle_t *handle, struct inode *inode,
16701671
if (unlikely(ex == NULL || eh == NULL)) {
16711672
EXT4_ERROR_INODE(inode,
16721673
"ex %p == NULL or eh %p == NULL", ex, eh);
1673-
return -EIO;
1674+
return -EFSCORRUPTED;
16741675
}
16751676

16761677
if (depth == 0) {
@@ -1938,14 +1939,14 @@ int ext4_ext_insert_extent(handle_t *handle, struct inode *inode,
19381939
mb_flags |= EXT4_MB_DELALLOC_RESERVED;
19391940
if (unlikely(ext4_ext_get_actual_len(newext) == 0)) {
19401941
EXT4_ERROR_INODE(inode, "ext4_ext_get_actual_len(newext) == 0");
1941-
return -EIO;
1942+
return -EFSCORRUPTED;
19421943
}
19431944
depth = ext_depth(inode);
19441945
ex = path[depth].p_ext;
19451946
eh = path[depth].p_hdr;
19461947
if (unlikely(path[depth].p_hdr == NULL)) {
19471948
EXT4_ERROR_INODE(inode, "path[%d].p_hdr == NULL", depth);
1948-
return -EIO;
1949+
return -EFSCORRUPTED;
19491950
}
19501951

19511952
/* try to insert block into found extent and return */
@@ -2172,7 +2173,7 @@ static int ext4_fill_fiemap_extents(struct inode *inode,
21722173
if (unlikely(path[depth].p_hdr == NULL)) {
21732174
up_read(&EXT4_I(inode)->i_data_sem);
21742175
EXT4_ERROR_INODE(inode, "path[%d].p_hdr == NULL", depth);
2175-
err = -EIO;
2176+
err = -EFSCORRUPTED;
21762177
break;
21772178
}
21782179
ex = path[depth].p_ext;
@@ -2241,7 +2242,7 @@ static int ext4_fill_fiemap_extents(struct inode *inode,
22412242

22422243
if (unlikely(es.es_len == 0)) {
22432244
EXT4_ERROR_INODE(inode, "es.es_len == 0");
2244-
err = -EIO;
2245+
err = -EFSCORRUPTED;
22452246
break;
22462247
}
22472248

@@ -2264,7 +2265,7 @@ static int ext4_fill_fiemap_extents(struct inode *inode,
22642265
"next extent == %u, next "
22652266
"delalloc extent = %u",
22662267
next, next_del);
2267-
err = -EIO;
2268+
err = -EFSCORRUPTED;
22682269
break;
22692270
}
22702271
}
@@ -2363,7 +2364,7 @@ static int ext4_ext_rm_idx(handle_t *handle, struct inode *inode,
23632364
leaf = ext4_idx_pblock(path->p_idx);
23642365
if (unlikely(path->p_hdr->eh_entries == 0)) {
23652366
EXT4_ERROR_INODE(inode, "path->p_hdr->eh_entries == 0");
2366-
return -EIO;
2367+
return -EFSCORRUPTED;
23672368
}
23682369
err = ext4_ext_get_access(handle, inode, path);
23692370
if (err)
@@ -2612,7 +2613,7 @@ ext4_ext_rm_leaf(handle_t *handle, struct inode *inode,
26122613
eh = path[depth].p_hdr;
26132614
if (unlikely(path[depth].p_hdr == NULL)) {
26142615
EXT4_ERROR_INODE(inode, "path[%d].p_hdr == NULL", depth);
2615-
return -EIO;
2616+
return -EFSCORRUPTED;
26162617
}
26172618
/* find where to start removing */
26182619
ex = path[depth].p_ext;
@@ -2666,7 +2667,7 @@ ext4_ext_rm_leaf(handle_t *handle, struct inode *inode,
26662667
"on extent %u:%u",
26672668
start, end, ex_ee_block,
26682669
ex_ee_block + ex_ee_len - 1);
2669-
err = -EIO;
2670+
err = -EFSCORRUPTED;
26702671
goto out;
26712672
} else if (a != ex_ee_block) {
26722673
/* remove tail of the extent */
@@ -2841,7 +2842,7 @@ int ext4_ext_remove_space(struct inode *inode, ext4_lblk_t start,
28412842
EXT4_ERROR_INODE(inode,
28422843
"path[%d].p_hdr == NULL",
28432844
depth);
2844-
err = -EIO;
2845+
err = -EFSCORRUPTED;
28452846
}
28462847
goto out;
28472848
}
@@ -2920,7 +2921,7 @@ int ext4_ext_remove_space(struct inode *inode, ext4_lblk_t start,
29202921
i = 0;
29212922

29222923
if (ext4_ext_check(inode, path[0].p_hdr, depth, 0)) {
2923-
err = -EIO;
2924+
err = -EFSCORRUPTED;
29242925
goto out;
29252926
}
29262927
}
@@ -2978,7 +2979,7 @@ int ext4_ext_remove_space(struct inode *inode, ext4_lblk_t start,
29782979
* Should be a no-op if we did IO above. */
29792980
cond_resched();
29802981
if (WARN_ON(i + 1 > depth)) {
2981-
err = -EIO;
2982+
err = -EFSCORRUPTED;
29822983
break;
29832984
}
29842985
path[i + 1].p_bh = bh;
@@ -3345,7 +3346,7 @@ static int ext4_split_extent(handle_t *handle,
33453346
if (!ex) {
33463347
EXT4_ERROR_INODE(inode, "unexpected hole at %lu",
33473348
(unsigned long) map->m_lblk);
3348-
return -EIO;
3349+
return -EFSCORRUPTED;
33493350
}
33503351
unwritten = ext4_ext_is_unwritten(ex);
33513352
split_flag1 = 0;
@@ -3973,7 +3974,7 @@ convert_initialized_extent(handle_t *handle, struct inode *inode,
39733974
if (!ex) {
39743975
EXT4_ERROR_INODE(inode, "unexpected hole at %lu",
39753976
(unsigned long) map->m_lblk);
3976-
return -EIO;
3977+
return -EFSCORRUPTED;
39773978
}
39783979
}
39793980

@@ -4311,7 +4312,7 @@ int ext4_ext_map_blocks(handle_t *handle, struct inode *inode,
43114312
"lblock: %lu, depth: %d pblock %lld",
43124313
(unsigned long) map->m_lblk, depth,
43134314
path[depth].p_block);
4314-
err = -EIO;
4315+
err = -EFSCORRUPTED;
43154316
goto out2;
43164317
}
43174318

@@ -5274,7 +5275,7 @@ ext4_ext_shift_path_extents(struct ext4_ext_path *path, ext4_lblk_t shift,
52745275
if (depth == path->p_depth) {
52755276
ex_start = path[depth].p_ext;
52765277
if (!ex_start)
5277-
return -EIO;
5278+
return -EFSCORRUPTED;
52785279

52795280
ex_last = EXT_LAST_EXTENT(path[depth].p_hdr);
52805281

@@ -5414,7 +5415,7 @@ ext4_ext_shift_extents(struct inode *inode, handle_t *handle,
54145415
if (!extent) {
54155416
EXT4_ERROR_INODE(inode, "unexpected hole at %lu",
54165417
(unsigned long) *iterator);
5417-
return -EIO;
5418+
return -EFSCORRUPTED;
54185419
}
54195420
if (SHIFT == SHIFT_LEFT && *iterator >
54205421
le32_to_cpu(extent->ee_block)) {

‎fs/ext4/ialloc.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,6 +1116,7 @@ struct inode *ext4_orphan_get(struct super_block *sb, unsigned long ino)
11161116
/* Error cases - e2fsck has already cleaned up for us */
11171117
if (ino > max_ino) {
11181118
ext4_warning(sb, "bad orphan ino %lu! e2fsck was run?", ino);
1119+
err = -EFSCORRUPTED;
11191120
goto error;
11201121
}
11211122

‎fs/ext4/indirect.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ int ext4_ind_map_blocks(handle_t *handle, struct inode *inode,
566566
EXT4_FEATURE_RO_COMPAT_BIGALLOC)) {
567567
EXT4_ERROR_INODE(inode, "Can't allocate blocks for "
568568
"non-extent mapped inodes with bigalloc");
569-
return -EUCLEAN;
569+
return -EFSCORRUPTED;
570570
}
571571

572572
/* Set up for the direct block allocation */

0 commit comments

Comments
 (0)