提交 59a5cea4 编写于 作者: C Chao Yu 提交者: Greg Kroah-Hartman

f2fs: use generic EFSBADCRC/EFSCORRUPTED

[ Upstream commit 10f966bbf521bb9b2e497bbca496a5141f4071d0 ]

f2fs uses EFAULT as error number to indicate filesystem is corrupted
all the time, but generic filesystems use EUCLEAN for such condition,
we need to change to follow others.

This patch adds two new macros as below to wrap more generic error
code macros, and spread them in code.

EFSBADCRC	EBADMSG		/* Bad CRC detected */
EFSCORRUPTED	EUCLEAN		/* Filesystem is corrupted */
Reported-by: NPavel Machek <pavel@ucw.cz>
Signed-off-by: NChao Yu <yuchao0@huawei.com>
Acked-by: NPavel Machek <pavel@ucw.cz>
Signed-off-by: NJaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: NSasha Levin <sashal@kernel.org>
上级 fc3d2964
...@@ -849,6 +849,7 @@ int f2fs_get_valid_checkpoint(struct f2fs_sb_info *sbi) ...@@ -849,6 +849,7 @@ int f2fs_get_valid_checkpoint(struct f2fs_sb_info *sbi)
unsigned int cp_blks = 1 + __cp_payload(sbi); unsigned int cp_blks = 1 + __cp_payload(sbi);
block_t cp_blk_no; block_t cp_blk_no;
int i; int i;
int err;
sbi->ckpt = f2fs_kzalloc(sbi, array_size(blk_size, cp_blks), sbi->ckpt = f2fs_kzalloc(sbi, array_size(blk_size, cp_blks),
GFP_KERNEL); GFP_KERNEL);
...@@ -876,6 +877,7 @@ int f2fs_get_valid_checkpoint(struct f2fs_sb_info *sbi) ...@@ -876,6 +877,7 @@ int f2fs_get_valid_checkpoint(struct f2fs_sb_info *sbi)
} else if (cp2) { } else if (cp2) {
cur_page = cp2; cur_page = cp2;
} else { } else {
err = -EFSCORRUPTED;
goto fail_no_cp; goto fail_no_cp;
} }
...@@ -888,8 +890,10 @@ int f2fs_get_valid_checkpoint(struct f2fs_sb_info *sbi) ...@@ -888,8 +890,10 @@ int f2fs_get_valid_checkpoint(struct f2fs_sb_info *sbi)
sbi->cur_cp_pack = 2; sbi->cur_cp_pack = 2;
/* Sanity checking of checkpoint */ /* Sanity checking of checkpoint */
if (f2fs_sanity_check_ckpt(sbi)) if (f2fs_sanity_check_ckpt(sbi)) {
err = -EFSCORRUPTED;
goto free_fail_no_cp; goto free_fail_no_cp;
}
if (cp_blks <= 1) if (cp_blks <= 1)
goto done; goto done;
...@@ -903,8 +907,10 @@ int f2fs_get_valid_checkpoint(struct f2fs_sb_info *sbi) ...@@ -903,8 +907,10 @@ int f2fs_get_valid_checkpoint(struct f2fs_sb_info *sbi)
unsigned char *ckpt = (unsigned char *)sbi->ckpt; unsigned char *ckpt = (unsigned char *)sbi->ckpt;
cur_page = f2fs_get_meta_page(sbi, cp_blk_no + i); cur_page = f2fs_get_meta_page(sbi, cp_blk_no + i);
if (IS_ERR(cur_page)) if (IS_ERR(cur_page)) {
err = PTR_ERR(cur_page);
goto free_fail_no_cp; goto free_fail_no_cp;
}
sit_bitmap_ptr = page_address(cur_page); sit_bitmap_ptr = page_address(cur_page);
memcpy(ckpt + i * blk_size, sit_bitmap_ptr, blk_size); memcpy(ckpt + i * blk_size, sit_bitmap_ptr, blk_size);
f2fs_put_page(cur_page, 1); f2fs_put_page(cur_page, 1);
...@@ -919,7 +925,7 @@ int f2fs_get_valid_checkpoint(struct f2fs_sb_info *sbi) ...@@ -919,7 +925,7 @@ int f2fs_get_valid_checkpoint(struct f2fs_sb_info *sbi)
f2fs_put_page(cp2, 1); f2fs_put_page(cp2, 1);
fail_no_cp: fail_no_cp:
kfree(sbi->ckpt); kfree(sbi->ckpt);
return -EINVAL; return err;
} }
static void __add_dirty_inode(struct inode *inode, enum inode_type type) static void __add_dirty_inode(struct inode *inode, enum inode_type type)
......
...@@ -449,7 +449,7 @@ int f2fs_submit_page_bio(struct f2fs_io_info *fio) ...@@ -449,7 +449,7 @@ 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,
__is_meta_io(fio) ? META_GENERIC : DATA_GENERIC)) __is_meta_io(fio) ? META_GENERIC : DATA_GENERIC))
return -EFAULT; return -EFSCORRUPTED;
trace_f2fs_submit_page_bio(page, fio); trace_f2fs_submit_page_bio(page, fio);
f2fs_trace_ios(fio, 0); f2fs_trace_ios(fio, 0);
...@@ -1071,7 +1071,7 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, ...@@ -1071,7 +1071,7 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map,
if (__is_valid_data_blkaddr(blkaddr) && if (__is_valid_data_blkaddr(blkaddr) &&
!f2fs_is_valid_blkaddr(sbi, blkaddr, DATA_GENERIC)) { !f2fs_is_valid_blkaddr(sbi, blkaddr, DATA_GENERIC)) {
err = -EFAULT; err = -EFSCORRUPTED;
goto sync_out; goto sync_out;
} }
...@@ -1755,7 +1755,7 @@ int f2fs_do_write_data_page(struct f2fs_io_info *fio) ...@@ -1755,7 +1755,7 @@ int f2fs_do_write_data_page(struct f2fs_io_info *fio)
if (!f2fs_is_valid_blkaddr(fio->sbi, fio->old_blkaddr, if (!f2fs_is_valid_blkaddr(fio->sbi, fio->old_blkaddr,
DATA_GENERIC)) DATA_GENERIC))
return -EFAULT; return -EFSCORRUPTED;
ipu_force = true; ipu_force = true;
fio->need_lock = LOCK_DONE; fio->need_lock = LOCK_DONE;
...@@ -1781,7 +1781,7 @@ int f2fs_do_write_data_page(struct f2fs_io_info *fio) ...@@ -1781,7 +1781,7 @@ int f2fs_do_write_data_page(struct f2fs_io_info *fio)
if (__is_valid_data_blkaddr(fio->old_blkaddr) && if (__is_valid_data_blkaddr(fio->old_blkaddr) &&
!f2fs_is_valid_blkaddr(fio->sbi, fio->old_blkaddr, !f2fs_is_valid_blkaddr(fio->sbi, fio->old_blkaddr,
DATA_GENERIC)) { DATA_GENERIC)) {
err = -EFAULT; err = -EFSCORRUPTED;
goto out_writepage; goto out_writepage;
} }
/* /*
......
...@@ -3487,3 +3487,7 @@ extern void f2fs_build_fault_attr(struct f2fs_sb_info *sbi, unsigned int rate, ...@@ -3487,3 +3487,7 @@ extern void f2fs_build_fault_attr(struct f2fs_sb_info *sbi, unsigned int rate,
#endif #endif
#endif #endif
#define EFSBADCRC EBADMSG /* Bad CRC detected */
#define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */
...@@ -636,7 +636,7 @@ static int ra_data_block(struct inode *inode, pgoff_t index) ...@@ -636,7 +636,7 @@ 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))) { DATA_GENERIC))) {
err = -EFAULT; err = -EFSCORRUPTED;
goto put_page; goto put_page;
} }
got_it: got_it:
......
...@@ -146,7 +146,7 @@ int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page) ...@@ -146,7 +146,7 @@ int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page)
"%s: corrupted inline inode ino=%lx, i_addr[0]:0x%x, " "%s: corrupted inline inode ino=%lx, i_addr[0]:0x%x, "
"run fsck to fix.", "run fsck to fix.",
__func__, dn->inode->i_ino, dn->data_blkaddr); __func__, dn->inode->i_ino, dn->data_blkaddr);
return -EINVAL; return -EFSCORRUPTED;
} }
f2fs_bug_on(F2FS_P_SB(page), PageWriteback(page)); f2fs_bug_on(F2FS_P_SB(page), PageWriteback(page));
...@@ -389,7 +389,7 @@ static int f2fs_move_inline_dirents(struct inode *dir, struct page *ipage, ...@@ -389,7 +389,7 @@ static int f2fs_move_inline_dirents(struct inode *dir, struct page *ipage,
"%s: corrupted inline inode ino=%lx, i_addr[0]:0x%x, " "%s: corrupted inline inode ino=%lx, i_addr[0]:0x%x, "
"run fsck to fix.", "run fsck to fix.",
__func__, dir->i_ino, dn.data_blkaddr); __func__, dir->i_ino, dn.data_blkaddr);
err = -EINVAL; err = -EFSCORRUPTED;
goto out; goto out;
} }
......
...@@ -76,7 +76,7 @@ static int __written_first_block(struct f2fs_sb_info *sbi, ...@@ -76,7 +76,7 @@ static int __written_first_block(struct f2fs_sb_info *sbi,
if (!__is_valid_data_blkaddr(addr)) if (!__is_valid_data_blkaddr(addr))
return 1; return 1;
if (!f2fs_is_valid_blkaddr(sbi, addr, DATA_GENERIC)) if (!f2fs_is_valid_blkaddr(sbi, addr, DATA_GENERIC))
return -EFAULT; return -EFSCORRUPTED;
return 0; return 0;
} }
...@@ -361,7 +361,7 @@ static int do_read_inode(struct inode *inode) ...@@ -361,7 +361,7 @@ static int do_read_inode(struct inode *inode)
if (!sanity_check_inode(inode, node_page)) { if (!sanity_check_inode(inode, node_page)) {
f2fs_put_page(node_page, 1); f2fs_put_page(node_page, 1);
return -EINVAL; return -EFSCORRUPTED;
} }
/* check data exist */ /* check data exist */
......
...@@ -40,7 +40,7 @@ int f2fs_check_nid_range(struct f2fs_sb_info *sbi, nid_t nid) ...@@ -40,7 +40,7 @@ int f2fs_check_nid_range(struct f2fs_sb_info *sbi, nid_t nid)
f2fs_msg(sbi->sb, KERN_WARNING, f2fs_msg(sbi->sb, KERN_WARNING,
"%s: out-of-range nid=%x, run fsck to fix.", "%s: out-of-range nid=%x, run fsck to fix.",
__func__, nid); __func__, nid);
return -EINVAL; return -EFSCORRUPTED;
} }
return 0; return 0;
} }
...@@ -1284,7 +1284,7 @@ static int read_node_page(struct page *page, int op_flags) ...@@ -1284,7 +1284,7 @@ static int read_node_page(struct page *page, int op_flags)
if (PageUptodate(page)) { if (PageUptodate(page)) {
if (!f2fs_inode_chksum_verify(sbi, page)) { if (!f2fs_inode_chksum_verify(sbi, page)) {
ClearPageUptodate(page); ClearPageUptodate(page);
return -EBADMSG; return -EFSBADCRC;
} }
return LOCKED_PAGE; return LOCKED_PAGE;
} }
...@@ -1370,7 +1370,7 @@ static struct page *__get_node_page(struct f2fs_sb_info *sbi, pgoff_t nid, ...@@ -1370,7 +1370,7 @@ static struct page *__get_node_page(struct f2fs_sb_info *sbi, pgoff_t nid,
} }
if (!f2fs_inode_chksum_verify(sbi, page)) { if (!f2fs_inode_chksum_verify(sbi, page)) {
err = -EBADMSG; err = -EFSBADCRC;
goto out_err; goto out_err;
} }
page_hit: page_hit:
......
...@@ -491,7 +491,7 @@ static int do_recover_data(struct f2fs_sb_info *sbi, struct inode *inode, ...@@ -491,7 +491,7 @@ static int do_recover_data(struct f2fs_sb_info *sbi, struct inode *inode,
"Inconsistent ofs_of_node, ino:%lu, ofs:%u, %u", "Inconsistent ofs_of_node, ino:%lu, ofs:%u, %u",
inode->i_ino, ofs_of_node(dn.node_page), inode->i_ino, ofs_of_node(dn.node_page),
ofs_of_node(page)); ofs_of_node(page));
err = -EFAULT; err = -EFSCORRUPTED;
goto err; goto err;
} }
......
...@@ -2657,7 +2657,7 @@ int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range) ...@@ -2657,7 +2657,7 @@ int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range)
if (is_sbi_flag_set(sbi, SBI_NEED_FSCK)) { if (is_sbi_flag_set(sbi, SBI_NEED_FSCK)) {
f2fs_msg(sbi->sb, KERN_WARNING, f2fs_msg(sbi->sb, KERN_WARNING,
"Found FS corruption, run fsck to fix."); "Found FS corruption, run fsck to fix.");
return -EIO; return -EFSCORRUPTED;
} }
/* start/end segment number in main_area */ /* start/end segment number in main_area */
...@@ -3079,7 +3079,7 @@ int f2fs_inplace_write_data(struct f2fs_io_info *fio) ...@@ -3079,7 +3079,7 @@ int f2fs_inplace_write_data(struct f2fs_io_info *fio)
if (!IS_DATASEG(get_seg_entry(sbi, segno)->type)) { if (!IS_DATASEG(get_seg_entry(sbi, segno)->type)) {
set_sbi_flag(sbi, SBI_NEED_FSCK); set_sbi_flag(sbi, SBI_NEED_FSCK);
return -EFAULT; return -EFSCORRUPTED;
} }
stat_inc_inplace_blocks(fio->sbi); stat_inc_inplace_blocks(fio->sbi);
...@@ -3966,7 +3966,7 @@ static int build_sit_entries(struct f2fs_sb_info *sbi) ...@@ -3966,7 +3966,7 @@ static int build_sit_entries(struct f2fs_sb_info *sbi)
"Wrong journal entry on segno %u", "Wrong journal entry on segno %u",
start); start);
set_sbi_flag(sbi, SBI_NEED_FSCK); set_sbi_flag(sbi, SBI_NEED_FSCK);
err = -EINVAL; err = -EFSCORRUPTED;
break; break;
} }
...@@ -4007,7 +4007,7 @@ static int build_sit_entries(struct f2fs_sb_info *sbi) ...@@ -4007,7 +4007,7 @@ static int build_sit_entries(struct f2fs_sb_info *sbi)
"SIT is corrupted node# %u vs %u", "SIT is corrupted node# %u vs %u",
total_node_blocks, valid_node_count(sbi)); total_node_blocks, valid_node_count(sbi));
set_sbi_flag(sbi, SBI_NEED_FSCK); set_sbi_flag(sbi, SBI_NEED_FSCK);
err = -EINVAL; err = -EFSCORRUPTED;
} }
return err; return err;
...@@ -4127,7 +4127,7 @@ static int sanity_check_curseg(struct f2fs_sb_info *sbi) ...@@ -4127,7 +4127,7 @@ static int sanity_check_curseg(struct f2fs_sb_info *sbi)
"segno:%u, type:%u, next_blkoff:%u, blkofs:%u", "segno:%u, type:%u, next_blkoff:%u, blkofs:%u",
i, curseg->segno, curseg->alloc_type, i, curseg->segno, curseg->alloc_type,
curseg->next_blkoff, blkofs); curseg->next_blkoff, blkofs);
return -EINVAL; return -EFSCORRUPTED;
} }
} }
return 0; return 0;
......
...@@ -684,7 +684,7 @@ static inline int check_block_count(struct f2fs_sb_info *sbi, ...@@ -684,7 +684,7 @@ static inline int check_block_count(struct f2fs_sb_info *sbi,
"Mismatch valid blocks %d vs. %d", "Mismatch valid blocks %d vs. %d",
GET_SIT_VBLOCKS(raw_sit), valid_blocks); GET_SIT_VBLOCKS(raw_sit), valid_blocks);
set_sbi_flag(sbi, SBI_NEED_FSCK); set_sbi_flag(sbi, SBI_NEED_FSCK);
return -EINVAL; return -EFSCORRUPTED;
} }
/* check segment usage, and check boundary of a given segment number */ /* check segment usage, and check boundary of a given segment number */
...@@ -694,7 +694,7 @@ static inline int check_block_count(struct f2fs_sb_info *sbi, ...@@ -694,7 +694,7 @@ static inline int check_block_count(struct f2fs_sb_info *sbi,
"Wrong valid blocks %d or segno %u", "Wrong valid blocks %d or segno %u",
GET_SIT_VBLOCKS(raw_sit), segno); GET_SIT_VBLOCKS(raw_sit), segno);
set_sbi_flag(sbi, SBI_NEED_FSCK); set_sbi_flag(sbi, SBI_NEED_FSCK);
return -EINVAL; return -EFSCORRUPTED;
} }
return 0; return 0;
} }
......
...@@ -2616,7 +2616,7 @@ static int read_raw_super_block(struct f2fs_sb_info *sbi, ...@@ -2616,7 +2616,7 @@ static int read_raw_super_block(struct f2fs_sb_info *sbi,
f2fs_msg(sb, KERN_ERR, f2fs_msg(sb, KERN_ERR,
"Can't find valid F2FS filesystem in %dth superblock", "Can't find valid F2FS filesystem in %dth superblock",
block + 1); block + 1);
err = -EINVAL; err = -EFSCORRUPTED;
brelse(bh); brelse(bh);
continue; continue;
} }
......
...@@ -349,7 +349,7 @@ static int lookup_all_xattrs(struct inode *inode, struct page *ipage, ...@@ -349,7 +349,7 @@ static int lookup_all_xattrs(struct inode *inode, struct page *ipage,
*xe = __find_xattr(cur_addr, last_txattr_addr, index, len, name); *xe = __find_xattr(cur_addr, last_txattr_addr, index, len, name);
if (!*xe) { if (!*xe) {
err = -EFAULT; err = -EFSCORRUPTED;
goto out; goto out;
} }
check: check:
...@@ -625,7 +625,7 @@ static int __f2fs_setxattr(struct inode *inode, int index, ...@@ -625,7 +625,7 @@ static int __f2fs_setxattr(struct inode *inode, int index,
/* find entry with wanted name. */ /* find entry with wanted name. */
here = __find_xattr(base_addr, last_base_addr, index, len, name); here = __find_xattr(base_addr, last_base_addr, index, len, name);
if (!here) { if (!here) {
error = -EFAULT; error = -EFSCORRUPTED;
goto exit; goto exit;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册