Skip to content

Commit 31f85cc

Browse files
Zhiguo NiuJaegeuk Kim
authored andcommitted
f2fs: unify the error handling of f2fs_is_valid_blkaddr
There are some cases of f2fs_is_valid_blkaddr not handled as ERROR_INVALID_BLKADDR,so unify the error handling about all of f2fs_is_valid_blkaddr. Do f2fs_handle_error in __f2fs_is_valid_blkaddr for cleanup. Signed-off-by: Zhiguo Niu <[email protected]> Signed-off-by: Chao Yu <[email protected]> Reviewed-by: Chao Yu <[email protected]> Signed-off-by: Jaegeuk Kim <[email protected]>
1 parent 11bec96 commit 31f85cc

File tree

7 files changed

+29
-62
lines changed

7 files changed

+29
-62
lines changed

fs/f2fs/checkpoint.c

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -154,19 +154,20 @@ static bool __is_bitmap_valid(struct f2fs_sb_info *sbi, block_t blkaddr,
154154
if (unlikely(f2fs_cp_error(sbi)))
155155
return exist;
156156

157-
if (exist && type == DATA_GENERIC_ENHANCE_UPDATE) {
158-
f2fs_err(sbi, "Inconsistent error blkaddr:%u, sit bitmap:%d",
159-
blkaddr, exist);
160-
set_sbi_flag(sbi, SBI_NEED_FSCK);
161-
return exist;
162-
}
157+
if ((exist && type == DATA_GENERIC_ENHANCE_UPDATE) ||
158+
(!exist && type == DATA_GENERIC_ENHANCE))
159+
goto out_err;
160+
if (!exist && type != DATA_GENERIC_ENHANCE_UPDATE)
161+
goto out_handle;
162+
return exist;
163163

164-
if (!exist && type == DATA_GENERIC_ENHANCE) {
165-
f2fs_err(sbi, "Inconsistent error blkaddr:%u, sit bitmap:%d",
166-
blkaddr, exist);
167-
set_sbi_flag(sbi, SBI_NEED_FSCK);
168-
dump_stack();
169-
}
164+
out_err:
165+
f2fs_err(sbi, "Inconsistent error blkaddr:%u, sit bitmap:%d",
166+
blkaddr, exist);
167+
set_sbi_flag(sbi, SBI_NEED_FSCK);
168+
dump_stack();
169+
out_handle:
170+
f2fs_handle_error(sbi, ERROR_INVALID_BLKADDR);
170171
return exist;
171172
}
172173

@@ -178,22 +179,22 @@ static bool __f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi,
178179
break;
179180
case META_SIT:
180181
if (unlikely(blkaddr >= SIT_BLK_CNT(sbi)))
181-
return false;
182+
goto err;
182183
break;
183184
case META_SSA:
184185
if (unlikely(blkaddr >= MAIN_BLKADDR(sbi) ||
185186
blkaddr < SM_I(sbi)->ssa_blkaddr))
186-
return false;
187+
goto err;
187188
break;
188189
case META_CP:
189190
if (unlikely(blkaddr >= SIT_I(sbi)->sit_base_addr ||
190191
blkaddr < __start_cp_addr(sbi)))
191-
return false;
192+
goto err;
192193
break;
193194
case META_POR:
194195
if (unlikely(blkaddr >= MAX_BLKADDR(sbi) ||
195196
blkaddr < MAIN_BLKADDR(sbi)))
196-
return false;
197+
goto err;
197198
break;
198199
case DATA_GENERIC:
199200
case DATA_GENERIC_ENHANCE:
@@ -210,21 +211,24 @@ static bool __f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi,
210211
blkaddr);
211212
set_sbi_flag(sbi, SBI_NEED_FSCK);
212213
dump_stack();
213-
return false;
214+
goto err;
214215
} else {
215216
return __is_bitmap_valid(sbi, blkaddr, type);
216217
}
217218
break;
218219
case META_GENERIC:
219220
if (unlikely(blkaddr < SEG0_BLKADDR(sbi) ||
220221
blkaddr >= MAIN_BLKADDR(sbi)))
221-
return false;
222+
goto err;
222223
break;
223224
default:
224225
BUG();
225226
}
226227

227228
return true;
229+
err:
230+
f2fs_handle_error(sbi, ERROR_INVALID_BLKADDR);
231+
return false;
228232
}
229233

230234
bool f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi,

fs/f2fs/data.c

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -690,10 +690,8 @@ int f2fs_submit_page_bio(struct f2fs_io_info *fio)
690690

691691
if (!f2fs_is_valid_blkaddr(fio->sbi, fio->new_blkaddr,
692692
fio->is_por ? META_POR : (__is_meta_io(fio) ?
693-
META_GENERIC : DATA_GENERIC_ENHANCE))) {
694-
f2fs_handle_error(fio->sbi, ERROR_INVALID_BLKADDR);
693+
META_GENERIC : DATA_GENERIC_ENHANCE)))
695694
return -EFSCORRUPTED;
696-
}
697695

698696
trace_f2fs_submit_page_bio(page, fio);
699697

@@ -888,10 +886,8 @@ int f2fs_merge_page_bio(struct f2fs_io_info *fio)
888886
fio->encrypted_page : fio->page;
889887

890888
if (!f2fs_is_valid_blkaddr(fio->sbi, fio->new_blkaddr,
891-
__is_meta_io(fio) ? META_GENERIC : DATA_GENERIC)) {
892-
f2fs_handle_error(fio->sbi, ERROR_INVALID_BLKADDR);
889+
__is_meta_io(fio) ? META_GENERIC : DATA_GENERIC))
893890
return -EFSCORRUPTED;
894-
}
895891

896892
trace_f2fs_submit_page_bio(page, fio);
897893

@@ -1219,8 +1215,6 @@ struct page *f2fs_get_read_data_page(struct inode *inode, pgoff_t index,
12191215
if (!f2fs_is_valid_blkaddr(F2FS_I_SB(inode), dn.data_blkaddr,
12201216
DATA_GENERIC_ENHANCE_READ)) {
12211217
err = -EFSCORRUPTED;
1222-
f2fs_handle_error(F2FS_I_SB(inode),
1223-
ERROR_INVALID_BLKADDR);
12241218
goto put_err;
12251219
}
12261220
goto got_it;
@@ -1246,8 +1240,6 @@ struct page *f2fs_get_read_data_page(struct inode *inode, pgoff_t index,
12461240
dn.data_blkaddr,
12471241
DATA_GENERIC_ENHANCE)) {
12481242
err = -EFSCORRUPTED;
1249-
f2fs_handle_error(F2FS_I_SB(inode),
1250-
ERROR_INVALID_BLKADDR);
12511243
goto put_err;
12521244
}
12531245
got_it:
@@ -1578,7 +1570,6 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, int flag)
15781570
if (!is_hole &&
15791571
!f2fs_is_valid_blkaddr(sbi, blkaddr, DATA_GENERIC_ENHANCE)) {
15801572
err = -EFSCORRUPTED;
1581-
f2fs_handle_error(sbi, ERROR_INVALID_BLKADDR);
15821573
goto sync_out;
15831574
}
15841575

@@ -2102,8 +2093,6 @@ static int f2fs_read_single_page(struct inode *inode, struct page *page,
21022093
if (!f2fs_is_valid_blkaddr(F2FS_I_SB(inode), block_nr,
21032094
DATA_GENERIC_ENHANCE_READ)) {
21042095
ret = -EFSCORRUPTED;
2105-
f2fs_handle_error(F2FS_I_SB(inode),
2106-
ERROR_INVALID_BLKADDR);
21072096
goto out;
21082097
}
21092098
} else {
@@ -2641,11 +2630,8 @@ int f2fs_do_write_data_page(struct f2fs_io_info *fio)
26412630
f2fs_lookup_read_extent_cache_block(inode, page->index,
26422631
&fio->old_blkaddr)) {
26432632
if (!f2fs_is_valid_blkaddr(fio->sbi, fio->old_blkaddr,
2644-
DATA_GENERIC_ENHANCE)) {
2645-
f2fs_handle_error(fio->sbi,
2646-
ERROR_INVALID_BLKADDR);
2633+
DATA_GENERIC_ENHANCE))
26472634
return -EFSCORRUPTED;
2648-
}
26492635

26502636
ipu_force = true;
26512637
fio->need_lock = LOCK_DONE;
@@ -2673,7 +2659,6 @@ int f2fs_do_write_data_page(struct f2fs_io_info *fio)
26732659
!f2fs_is_valid_blkaddr(fio->sbi, fio->old_blkaddr,
26742660
DATA_GENERIC_ENHANCE)) {
26752661
err = -EFSCORRUPTED;
2676-
f2fs_handle_error(fio->sbi, ERROR_INVALID_BLKADDR);
26772662
goto out_writepage;
26782663
}
26792664

@@ -3640,7 +3625,6 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping,
36403625
if (!f2fs_is_valid_blkaddr(sbi, blkaddr,
36413626
DATA_GENERIC_ENHANCE_READ)) {
36423627
err = -EFSCORRUPTED;
3643-
f2fs_handle_error(sbi, ERROR_INVALID_BLKADDR);
36443628
goto fail;
36453629
}
36463630
err = f2fs_submit_page_read(use_cow ?

fs/f2fs/extent_cache.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ bool sanity_check_extent_cache(struct inode *inode)
4343
if (!f2fs_is_valid_blkaddr(sbi, ei->blk, DATA_GENERIC_ENHANCE) ||
4444
!f2fs_is_valid_blkaddr(sbi, ei->blk + ei->len - 1,
4545
DATA_GENERIC_ENHANCE)) {
46-
set_sbi_flag(sbi, SBI_NEED_FSCK);
4746
f2fs_warn(sbi, "%s: inode (ino=%lx) extent info [%u, %u, %u] is incorrect, run fsck to fix",
4847
__func__, inode->i_ino,
4948
ei->blk, ei->fofs, ei->len);
@@ -856,10 +855,8 @@ static int __get_new_block_age(struct inode *inode, struct extent_info *ei,
856855
goto out;
857856

858857
if (__is_valid_data_blkaddr(blkaddr) &&
859-
!f2fs_is_valid_blkaddr(sbi, blkaddr, DATA_GENERIC_ENHANCE)) {
860-
f2fs_bug_on(sbi, 1);
858+
!f2fs_is_valid_blkaddr(sbi, blkaddr, DATA_GENERIC_ENHANCE))
861859
return -EINVAL;
862-
}
863860
out:
864861
/*
865862
* init block age with zero, this can happen when the block age extent

fs/f2fs/file.c

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -608,10 +608,8 @@ void f2fs_truncate_data_blocks_range(struct dnode_of_data *dn, int count)
608608
if (time_to_inject(sbi, FAULT_BLKADDR_CONSISTENCE))
609609
continue;
610610
if (!f2fs_is_valid_blkaddr_raw(sbi, blkaddr,
611-
DATA_GENERIC_ENHANCE)) {
612-
f2fs_handle_error(sbi, ERROR_INVALID_BLKADDR);
611+
DATA_GENERIC_ENHANCE))
613612
continue;
614-
}
615613
if (compressed_cluster)
616614
valid_blocks++;
617615
}
@@ -1209,7 +1207,6 @@ static int __read_out_blkaddrs(struct inode *inode, block_t *blkaddr,
12091207
!f2fs_is_valid_blkaddr(sbi, *blkaddr,
12101208
DATA_GENERIC_ENHANCE)) {
12111209
f2fs_put_dnode(&dn);
1212-
f2fs_handle_error(sbi, ERROR_INVALID_BLKADDR);
12131210
return -EFSCORRUPTED;
12141211
}
12151212

@@ -1495,7 +1492,6 @@ static int f2fs_do_zero_range(struct dnode_of_data *dn, pgoff_t start,
14951492
if (!f2fs_is_valid_blkaddr(sbi, dn->data_blkaddr,
14961493
DATA_GENERIC_ENHANCE)) {
14971494
ret = -EFSCORRUPTED;
1498-
f2fs_handle_error(sbi, ERROR_INVALID_BLKADDR);
14991495
break;
15001496
}
15011497

@@ -3474,10 +3470,8 @@ static int release_compress_blocks(struct dnode_of_data *dn, pgoff_t count)
34743470
if (!__is_valid_data_blkaddr(blkaddr))
34753471
continue;
34763472
if (unlikely(!f2fs_is_valid_blkaddr(sbi, blkaddr,
3477-
DATA_GENERIC_ENHANCE))) {
3478-
f2fs_handle_error(sbi, ERROR_INVALID_BLKADDR);
3473+
DATA_GENERIC_ENHANCE)))
34793474
return -EFSCORRUPTED;
3480-
}
34813475
}
34823476

34833477
while (count) {
@@ -3639,10 +3633,8 @@ static int reserve_compress_blocks(struct dnode_of_data *dn, pgoff_t count,
36393633
if (!__is_valid_data_blkaddr(blkaddr))
36403634
continue;
36413635
if (unlikely(!f2fs_is_valid_blkaddr(sbi, blkaddr,
3642-
DATA_GENERIC_ENHANCE))) {
3643-
f2fs_handle_error(sbi, ERROR_INVALID_BLKADDR);
3636+
DATA_GENERIC_ENHANCE)))
36443637
return -EFSCORRUPTED;
3645-
}
36463638
}
36473639

36483640
while (count) {
@@ -3924,8 +3916,6 @@ static int f2fs_sec_trim_file(struct file *filp, unsigned long arg)
39243916
DATA_GENERIC_ENHANCE)) {
39253917
ret = -EFSCORRUPTED;
39263918
f2fs_put_dnode(&dn);
3927-
f2fs_handle_error(sbi,
3928-
ERROR_INVALID_BLKADDR);
39293919
goto out;
39303920
}
39313921

fs/f2fs/gc.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,7 +1195,6 @@ static int ra_data_block(struct inode *inode, pgoff_t index)
11951195
if (unlikely(!f2fs_is_valid_blkaddr(sbi, dn.data_blkaddr,
11961196
DATA_GENERIC_ENHANCE_READ))) {
11971197
err = -EFSCORRUPTED;
1198-
f2fs_handle_error(sbi, ERROR_INVALID_BLKADDR);
11991198
goto put_page;
12001199
}
12011200
goto got_it;
@@ -1214,7 +1213,6 @@ static int ra_data_block(struct inode *inode, pgoff_t index)
12141213
if (unlikely(!f2fs_is_valid_blkaddr(sbi, dn.data_blkaddr,
12151214
DATA_GENERIC_ENHANCE))) {
12161215
err = -EFSCORRUPTED;
1217-
f2fs_handle_error(sbi, ERROR_INVALID_BLKADDR);
12181216
goto put_page;
12191217
}
12201218
got_it:

fs/f2fs/recovery.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -693,14 +693,12 @@ static int do_recover_data(struct f2fs_sb_info *sbi, struct inode *inode,
693693
if (__is_valid_data_blkaddr(src) &&
694694
!f2fs_is_valid_blkaddr(sbi, src, META_POR)) {
695695
err = -EFSCORRUPTED;
696-
f2fs_handle_error(sbi, ERROR_INVALID_BLKADDR);
697696
goto err;
698697
}
699698

700699
if (__is_valid_data_blkaddr(dest) &&
701700
!f2fs_is_valid_blkaddr(sbi, dest, META_POR)) {
702701
err = -EFSCORRUPTED;
703-
f2fs_handle_error(sbi, ERROR_INVALID_BLKADDR);
704702
goto err;
705703
}
706704

@@ -755,8 +753,6 @@ static int do_recover_data(struct f2fs_sb_info *sbi, struct inode *inode,
755753
f2fs_err(sbi, "Inconsistent dest blkaddr:%u, ino:%lu, ofs:%u",
756754
dest, inode->i_ino, dn.ofs_in_node);
757755
err = -EFSCORRUPTED;
758-
f2fs_handle_error(sbi,
759-
ERROR_INVALID_BLKADDR);
760756
goto err;
761757
}
762758

fs/f2fs/segment.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,6 @@ static int __f2fs_commit_atomic_write(struct inode *inode)
334334
DATA_GENERIC_ENHANCE)) {
335335
f2fs_put_dnode(&dn);
336336
ret = -EFSCORRUPTED;
337-
f2fs_handle_error(sbi,
338-
ERROR_INVALID_BLKADDR);
339337
goto out;
340338
}
341339

0 commit comments

Comments
 (0)