Commit 31f85ccc authored by Zhiguo Niu's avatar Zhiguo Niu Committed by Jaegeuk Kim

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: default avatarZhiguo Niu <zhiguo.niu@unisoc.com>
Signed-off-by: default avatarChao Yu <chao@kernel.org>
Reviewed-by: default avatarChao Yu <chao@kernel.org>
Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
parent 11bec96a
...@@ -154,19 +154,20 @@ static bool __is_bitmap_valid(struct f2fs_sb_info *sbi, block_t blkaddr, ...@@ -154,19 +154,20 @@ static bool __is_bitmap_valid(struct f2fs_sb_info *sbi, block_t blkaddr,
if (unlikely(f2fs_cp_error(sbi))) if (unlikely(f2fs_cp_error(sbi)))
return exist; return exist;
if (exist && type == DATA_GENERIC_ENHANCE_UPDATE) { if ((exist && type == DATA_GENERIC_ENHANCE_UPDATE) ||
f2fs_err(sbi, "Inconsistent error blkaddr:%u, sit bitmap:%d", (!exist && type == DATA_GENERIC_ENHANCE))
blkaddr, exist); goto out_err;
set_sbi_flag(sbi, SBI_NEED_FSCK); if (!exist && type != DATA_GENERIC_ENHANCE_UPDATE)
goto out_handle;
return exist; return exist;
}
if (!exist && type == DATA_GENERIC_ENHANCE) { out_err:
f2fs_err(sbi, "Inconsistent error blkaddr:%u, sit bitmap:%d", f2fs_err(sbi, "Inconsistent error blkaddr:%u, sit bitmap:%d",
blkaddr, exist); blkaddr, exist);
set_sbi_flag(sbi, SBI_NEED_FSCK); set_sbi_flag(sbi, SBI_NEED_FSCK);
dump_stack(); dump_stack();
} out_handle:
f2fs_handle_error(sbi, ERROR_INVALID_BLKADDR);
return exist; return exist;
} }
...@@ -178,22 +179,22 @@ static bool __f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi, ...@@ -178,22 +179,22 @@ static bool __f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi,
break; break;
case META_SIT: case META_SIT:
if (unlikely(blkaddr >= SIT_BLK_CNT(sbi))) if (unlikely(blkaddr >= SIT_BLK_CNT(sbi)))
return false; goto err;
break; break;
case META_SSA: case META_SSA:
if (unlikely(blkaddr >= MAIN_BLKADDR(sbi) || if (unlikely(blkaddr >= MAIN_BLKADDR(sbi) ||
blkaddr < SM_I(sbi)->ssa_blkaddr)) blkaddr < SM_I(sbi)->ssa_blkaddr))
return false; goto err;
break; break;
case META_CP: case META_CP:
if (unlikely(blkaddr >= SIT_I(sbi)->sit_base_addr || if (unlikely(blkaddr >= SIT_I(sbi)->sit_base_addr ||
blkaddr < __start_cp_addr(sbi))) blkaddr < __start_cp_addr(sbi)))
return false; goto err;
break; break;
case META_POR: case META_POR:
if (unlikely(blkaddr >= MAX_BLKADDR(sbi) || if (unlikely(blkaddr >= MAX_BLKADDR(sbi) ||
blkaddr < MAIN_BLKADDR(sbi))) blkaddr < MAIN_BLKADDR(sbi)))
return false; goto err;
break; break;
case DATA_GENERIC: case DATA_GENERIC:
case DATA_GENERIC_ENHANCE: case DATA_GENERIC_ENHANCE:
...@@ -210,7 +211,7 @@ static bool __f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi, ...@@ -210,7 +211,7 @@ static bool __f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi,
blkaddr); blkaddr);
set_sbi_flag(sbi, SBI_NEED_FSCK); set_sbi_flag(sbi, SBI_NEED_FSCK);
dump_stack(); dump_stack();
return false; goto err;
} else { } else {
return __is_bitmap_valid(sbi, blkaddr, type); return __is_bitmap_valid(sbi, blkaddr, type);
} }
...@@ -218,13 +219,16 @@ static bool __f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi, ...@@ -218,13 +219,16 @@ static bool __f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi,
case META_GENERIC: case META_GENERIC:
if (unlikely(blkaddr < SEG0_BLKADDR(sbi) || if (unlikely(blkaddr < SEG0_BLKADDR(sbi) ||
blkaddr >= MAIN_BLKADDR(sbi))) blkaddr >= MAIN_BLKADDR(sbi)))
return false; goto err;
break; break;
default: default:
BUG(); BUG();
} }
return true; return true;
err:
f2fs_handle_error(sbi, ERROR_INVALID_BLKADDR);
return false;
} }
bool f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi, bool f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi,
......
...@@ -690,10 +690,8 @@ int f2fs_submit_page_bio(struct f2fs_io_info *fio) ...@@ -690,10 +690,8 @@ int f2fs_submit_page_bio(struct f2fs_io_info *fio)
if (!f2fs_is_valid_blkaddr(fio->sbi, fio->new_blkaddr, if (!f2fs_is_valid_blkaddr(fio->sbi, fio->new_blkaddr,
fio->is_por ? META_POR : (__is_meta_io(fio) ? fio->is_por ? META_POR : (__is_meta_io(fio) ?
META_GENERIC : DATA_GENERIC_ENHANCE))) { META_GENERIC : DATA_GENERIC_ENHANCE)))
f2fs_handle_error(fio->sbi, ERROR_INVALID_BLKADDR);
return -EFSCORRUPTED; return -EFSCORRUPTED;
}
trace_f2fs_submit_page_bio(page, fio); trace_f2fs_submit_page_bio(page, fio);
...@@ -888,10 +886,8 @@ int f2fs_merge_page_bio(struct f2fs_io_info *fio) ...@@ -888,10 +886,8 @@ int f2fs_merge_page_bio(struct f2fs_io_info *fio)
fio->encrypted_page : fio->page; fio->encrypted_page : fio->page;
if (!f2fs_is_valid_blkaddr(fio->sbi, fio->new_blkaddr, if (!f2fs_is_valid_blkaddr(fio->sbi, fio->new_blkaddr,
__is_meta_io(fio) ? META_GENERIC : DATA_GENERIC)) { __is_meta_io(fio) ? META_GENERIC : DATA_GENERIC))
f2fs_handle_error(fio->sbi, ERROR_INVALID_BLKADDR);
return -EFSCORRUPTED; return -EFSCORRUPTED;
}
trace_f2fs_submit_page_bio(page, fio); trace_f2fs_submit_page_bio(page, fio);
...@@ -1219,8 +1215,6 @@ struct page *f2fs_get_read_data_page(struct inode *inode, pgoff_t index, ...@@ -1219,8 +1215,6 @@ struct page *f2fs_get_read_data_page(struct inode *inode, pgoff_t index,
if (!f2fs_is_valid_blkaddr(F2FS_I_SB(inode), dn.data_blkaddr, if (!f2fs_is_valid_blkaddr(F2FS_I_SB(inode), dn.data_blkaddr,
DATA_GENERIC_ENHANCE_READ)) { DATA_GENERIC_ENHANCE_READ)) {
err = -EFSCORRUPTED; err = -EFSCORRUPTED;
f2fs_handle_error(F2FS_I_SB(inode),
ERROR_INVALID_BLKADDR);
goto put_err; goto put_err;
} }
goto got_it; goto got_it;
...@@ -1246,8 +1240,6 @@ struct page *f2fs_get_read_data_page(struct inode *inode, pgoff_t index, ...@@ -1246,8 +1240,6 @@ struct page *f2fs_get_read_data_page(struct inode *inode, pgoff_t index,
dn.data_blkaddr, dn.data_blkaddr,
DATA_GENERIC_ENHANCE)) { DATA_GENERIC_ENHANCE)) {
err = -EFSCORRUPTED; err = -EFSCORRUPTED;
f2fs_handle_error(F2FS_I_SB(inode),
ERROR_INVALID_BLKADDR);
goto put_err; goto put_err;
} }
got_it: got_it:
...@@ -1578,7 +1570,6 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, int flag) ...@@ -1578,7 +1570,6 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, int flag)
if (!is_hole && if (!is_hole &&
!f2fs_is_valid_blkaddr(sbi, blkaddr, DATA_GENERIC_ENHANCE)) { !f2fs_is_valid_blkaddr(sbi, blkaddr, DATA_GENERIC_ENHANCE)) {
err = -EFSCORRUPTED; err = -EFSCORRUPTED;
f2fs_handle_error(sbi, ERROR_INVALID_BLKADDR);
goto sync_out; goto sync_out;
} }
...@@ -2102,8 +2093,6 @@ static int f2fs_read_single_page(struct inode *inode, struct page *page, ...@@ -2102,8 +2093,6 @@ static int f2fs_read_single_page(struct inode *inode, struct page *page,
if (!f2fs_is_valid_blkaddr(F2FS_I_SB(inode), block_nr, if (!f2fs_is_valid_blkaddr(F2FS_I_SB(inode), block_nr,
DATA_GENERIC_ENHANCE_READ)) { DATA_GENERIC_ENHANCE_READ)) {
ret = -EFSCORRUPTED; ret = -EFSCORRUPTED;
f2fs_handle_error(F2FS_I_SB(inode),
ERROR_INVALID_BLKADDR);
goto out; goto out;
} }
} else { } else {
...@@ -2641,11 +2630,8 @@ int f2fs_do_write_data_page(struct f2fs_io_info *fio) ...@@ -2641,11 +2630,8 @@ int f2fs_do_write_data_page(struct f2fs_io_info *fio)
f2fs_lookup_read_extent_cache_block(inode, page->index, f2fs_lookup_read_extent_cache_block(inode, page->index,
&fio->old_blkaddr)) { &fio->old_blkaddr)) {
if (!f2fs_is_valid_blkaddr(fio->sbi, fio->old_blkaddr, if (!f2fs_is_valid_blkaddr(fio->sbi, fio->old_blkaddr,
DATA_GENERIC_ENHANCE)) { DATA_GENERIC_ENHANCE))
f2fs_handle_error(fio->sbi,
ERROR_INVALID_BLKADDR);
return -EFSCORRUPTED; return -EFSCORRUPTED;
}
ipu_force = true; ipu_force = true;
fio->need_lock = LOCK_DONE; fio->need_lock = LOCK_DONE;
...@@ -2673,7 +2659,6 @@ int f2fs_do_write_data_page(struct f2fs_io_info *fio) ...@@ -2673,7 +2659,6 @@ int f2fs_do_write_data_page(struct f2fs_io_info *fio)
!f2fs_is_valid_blkaddr(fio->sbi, fio->old_blkaddr, !f2fs_is_valid_blkaddr(fio->sbi, fio->old_blkaddr,
DATA_GENERIC_ENHANCE)) { DATA_GENERIC_ENHANCE)) {
err = -EFSCORRUPTED; err = -EFSCORRUPTED;
f2fs_handle_error(fio->sbi, ERROR_INVALID_BLKADDR);
goto out_writepage; goto out_writepage;
} }
...@@ -3640,7 +3625,6 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping, ...@@ -3640,7 +3625,6 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping,
if (!f2fs_is_valid_blkaddr(sbi, blkaddr, if (!f2fs_is_valid_blkaddr(sbi, blkaddr,
DATA_GENERIC_ENHANCE_READ)) { DATA_GENERIC_ENHANCE_READ)) {
err = -EFSCORRUPTED; err = -EFSCORRUPTED;
f2fs_handle_error(sbi, ERROR_INVALID_BLKADDR);
goto fail; goto fail;
} }
err = f2fs_submit_page_read(use_cow ? err = f2fs_submit_page_read(use_cow ?
......
...@@ -43,7 +43,6 @@ bool sanity_check_extent_cache(struct inode *inode) ...@@ -43,7 +43,6 @@ bool sanity_check_extent_cache(struct inode *inode)
if (!f2fs_is_valid_blkaddr(sbi, ei->blk, DATA_GENERIC_ENHANCE) || if (!f2fs_is_valid_blkaddr(sbi, ei->blk, DATA_GENERIC_ENHANCE) ||
!f2fs_is_valid_blkaddr(sbi, ei->blk + ei->len - 1, !f2fs_is_valid_blkaddr(sbi, ei->blk + ei->len - 1,
DATA_GENERIC_ENHANCE)) { DATA_GENERIC_ENHANCE)) {
set_sbi_flag(sbi, SBI_NEED_FSCK);
f2fs_warn(sbi, "%s: inode (ino=%lx) extent info [%u, %u, %u] is incorrect, run fsck to fix", f2fs_warn(sbi, "%s: inode (ino=%lx) extent info [%u, %u, %u] is incorrect, run fsck to fix",
__func__, inode->i_ino, __func__, inode->i_ino,
ei->blk, ei->fofs, ei->len); ei->blk, ei->fofs, ei->len);
...@@ -856,10 +855,8 @@ static int __get_new_block_age(struct inode *inode, struct extent_info *ei, ...@@ -856,10 +855,8 @@ static int __get_new_block_age(struct inode *inode, struct extent_info *ei,
goto out; goto out;
if (__is_valid_data_blkaddr(blkaddr) && if (__is_valid_data_blkaddr(blkaddr) &&
!f2fs_is_valid_blkaddr(sbi, blkaddr, DATA_GENERIC_ENHANCE)) { !f2fs_is_valid_blkaddr(sbi, blkaddr, DATA_GENERIC_ENHANCE))
f2fs_bug_on(sbi, 1);
return -EINVAL; return -EINVAL;
}
out: out:
/* /*
* init block age with zero, this can happen when the block age extent * init block age with zero, this can happen when the block age extent
......
...@@ -608,10 +608,8 @@ void f2fs_truncate_data_blocks_range(struct dnode_of_data *dn, int count) ...@@ -608,10 +608,8 @@ void f2fs_truncate_data_blocks_range(struct dnode_of_data *dn, int count)
if (time_to_inject(sbi, FAULT_BLKADDR_CONSISTENCE)) if (time_to_inject(sbi, FAULT_BLKADDR_CONSISTENCE))
continue; continue;
if (!f2fs_is_valid_blkaddr_raw(sbi, blkaddr, if (!f2fs_is_valid_blkaddr_raw(sbi, blkaddr,
DATA_GENERIC_ENHANCE)) { DATA_GENERIC_ENHANCE))
f2fs_handle_error(sbi, ERROR_INVALID_BLKADDR);
continue; continue;
}
if (compressed_cluster) if (compressed_cluster)
valid_blocks++; valid_blocks++;
} }
...@@ -1209,7 +1207,6 @@ static int __read_out_blkaddrs(struct inode *inode, block_t *blkaddr, ...@@ -1209,7 +1207,6 @@ static int __read_out_blkaddrs(struct inode *inode, block_t *blkaddr,
!f2fs_is_valid_blkaddr(sbi, *blkaddr, !f2fs_is_valid_blkaddr(sbi, *blkaddr,
DATA_GENERIC_ENHANCE)) { DATA_GENERIC_ENHANCE)) {
f2fs_put_dnode(&dn); f2fs_put_dnode(&dn);
f2fs_handle_error(sbi, ERROR_INVALID_BLKADDR);
return -EFSCORRUPTED; return -EFSCORRUPTED;
} }
...@@ -1495,7 +1492,6 @@ static int f2fs_do_zero_range(struct dnode_of_data *dn, pgoff_t start, ...@@ -1495,7 +1492,6 @@ static int f2fs_do_zero_range(struct dnode_of_data *dn, pgoff_t start,
if (!f2fs_is_valid_blkaddr(sbi, dn->data_blkaddr, if (!f2fs_is_valid_blkaddr(sbi, dn->data_blkaddr,
DATA_GENERIC_ENHANCE)) { DATA_GENERIC_ENHANCE)) {
ret = -EFSCORRUPTED; ret = -EFSCORRUPTED;
f2fs_handle_error(sbi, ERROR_INVALID_BLKADDR);
break; break;
} }
...@@ -3474,11 +3470,9 @@ static int release_compress_blocks(struct dnode_of_data *dn, pgoff_t count) ...@@ -3474,11 +3470,9 @@ static int release_compress_blocks(struct dnode_of_data *dn, pgoff_t count)
if (!__is_valid_data_blkaddr(blkaddr)) if (!__is_valid_data_blkaddr(blkaddr))
continue; continue;
if (unlikely(!f2fs_is_valid_blkaddr(sbi, blkaddr, if (unlikely(!f2fs_is_valid_blkaddr(sbi, blkaddr,
DATA_GENERIC_ENHANCE))) { DATA_GENERIC_ENHANCE)))
f2fs_handle_error(sbi, ERROR_INVALID_BLKADDR);
return -EFSCORRUPTED; return -EFSCORRUPTED;
} }
}
while (count) { while (count) {
int compr_blocks = 0; int compr_blocks = 0;
...@@ -3639,11 +3633,9 @@ static int reserve_compress_blocks(struct dnode_of_data *dn, pgoff_t count, ...@@ -3639,11 +3633,9 @@ static int reserve_compress_blocks(struct dnode_of_data *dn, pgoff_t count,
if (!__is_valid_data_blkaddr(blkaddr)) if (!__is_valid_data_blkaddr(blkaddr))
continue; continue;
if (unlikely(!f2fs_is_valid_blkaddr(sbi, blkaddr, if (unlikely(!f2fs_is_valid_blkaddr(sbi, blkaddr,
DATA_GENERIC_ENHANCE))) { DATA_GENERIC_ENHANCE)))
f2fs_handle_error(sbi, ERROR_INVALID_BLKADDR);
return -EFSCORRUPTED; return -EFSCORRUPTED;
} }
}
while (count) { while (count) {
int compr_blocks = 0; int compr_blocks = 0;
...@@ -3924,8 +3916,6 @@ static int f2fs_sec_trim_file(struct file *filp, unsigned long arg) ...@@ -3924,8 +3916,6 @@ static int f2fs_sec_trim_file(struct file *filp, unsigned long arg)
DATA_GENERIC_ENHANCE)) { DATA_GENERIC_ENHANCE)) {
ret = -EFSCORRUPTED; ret = -EFSCORRUPTED;
f2fs_put_dnode(&dn); f2fs_put_dnode(&dn);
f2fs_handle_error(sbi,
ERROR_INVALID_BLKADDR);
goto out; goto out;
} }
......
...@@ -1195,7 +1195,6 @@ static int ra_data_block(struct inode *inode, pgoff_t index) ...@@ -1195,7 +1195,6 @@ static int ra_data_block(struct inode *inode, pgoff_t index)
if (unlikely(!f2fs_is_valid_blkaddr(sbi, dn.data_blkaddr, if (unlikely(!f2fs_is_valid_blkaddr(sbi, dn.data_blkaddr,
DATA_GENERIC_ENHANCE_READ))) { DATA_GENERIC_ENHANCE_READ))) {
err = -EFSCORRUPTED; err = -EFSCORRUPTED;
f2fs_handle_error(sbi, ERROR_INVALID_BLKADDR);
goto put_page; goto put_page;
} }
goto got_it; goto got_it;
...@@ -1214,7 +1213,6 @@ static int ra_data_block(struct inode *inode, pgoff_t index) ...@@ -1214,7 +1213,6 @@ static int ra_data_block(struct inode *inode, pgoff_t index)
if (unlikely(!f2fs_is_valid_blkaddr(sbi, dn.data_blkaddr, if (unlikely(!f2fs_is_valid_blkaddr(sbi, dn.data_blkaddr,
DATA_GENERIC_ENHANCE))) { DATA_GENERIC_ENHANCE))) {
err = -EFSCORRUPTED; err = -EFSCORRUPTED;
f2fs_handle_error(sbi, ERROR_INVALID_BLKADDR);
goto put_page; goto put_page;
} }
got_it: got_it:
......
...@@ -693,14 +693,12 @@ static int do_recover_data(struct f2fs_sb_info *sbi, struct inode *inode, ...@@ -693,14 +693,12 @@ static int do_recover_data(struct f2fs_sb_info *sbi, struct inode *inode,
if (__is_valid_data_blkaddr(src) && if (__is_valid_data_blkaddr(src) &&
!f2fs_is_valid_blkaddr(sbi, src, META_POR)) { !f2fs_is_valid_blkaddr(sbi, src, META_POR)) {
err = -EFSCORRUPTED; err = -EFSCORRUPTED;
f2fs_handle_error(sbi, ERROR_INVALID_BLKADDR);
goto err; goto err;
} }
if (__is_valid_data_blkaddr(dest) && if (__is_valid_data_blkaddr(dest) &&
!f2fs_is_valid_blkaddr(sbi, dest, META_POR)) { !f2fs_is_valid_blkaddr(sbi, dest, META_POR)) {
err = -EFSCORRUPTED; err = -EFSCORRUPTED;
f2fs_handle_error(sbi, ERROR_INVALID_BLKADDR);
goto err; goto err;
} }
...@@ -755,8 +753,6 @@ static int do_recover_data(struct f2fs_sb_info *sbi, struct inode *inode, ...@@ -755,8 +753,6 @@ static int do_recover_data(struct f2fs_sb_info *sbi, struct inode *inode,
f2fs_err(sbi, "Inconsistent dest blkaddr:%u, ino:%lu, ofs:%u", f2fs_err(sbi, "Inconsistent dest blkaddr:%u, ino:%lu, ofs:%u",
dest, inode->i_ino, dn.ofs_in_node); dest, inode->i_ino, dn.ofs_in_node);
err = -EFSCORRUPTED; err = -EFSCORRUPTED;
f2fs_handle_error(sbi,
ERROR_INVALID_BLKADDR);
goto err; goto err;
} }
......
...@@ -334,8 +334,6 @@ static int __f2fs_commit_atomic_write(struct inode *inode) ...@@ -334,8 +334,6 @@ static int __f2fs_commit_atomic_write(struct inode *inode)
DATA_GENERIC_ENHANCE)) { DATA_GENERIC_ENHANCE)) {
f2fs_put_dnode(&dn); f2fs_put_dnode(&dn);
ret = -EFSCORRUPTED; ret = -EFSCORRUPTED;
f2fs_handle_error(sbi,
ERROR_INVALID_BLKADDR);
goto out; goto out;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment