Skip to content

Commit

Permalink
f2fs: support in-memory inode checksum when checking consistency
Browse files Browse the repository at this point in the history
Enable in-memory inode checksum to protect metadata blocks from
in-memory scribbles when checking consistency, which has no
performance requirements.

Signed-off-by: Weichao Guo <guoweichao@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: khusika <khusikadhamar@gmail.com>
  • Loading branch information
Weichao Guo authored and khusika committed Oct 13, 2018
1 parent 912b256 commit e64d8e7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
8 changes: 8 additions & 0 deletions fs/f2fs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,12 @@ bool f2fs_inode_chksum_verify(struct f2fs_sb_info *sbi, struct page *page)
if (unlikely(is_sbi_flag_set(sbi, SBI_IS_SHUTDOWN)))
return true;

#ifdef CONFIG_F2FS_CHECK_FS
if (!f2fs_enable_inode_chksum(sbi, page))
#else
if (!f2fs_enable_inode_chksum(sbi, page) ||
PageDirty(page) || PageWriteback(page))
#endif
return true;

ri = &F2FS_NODE(page)->i;
Expand Down Expand Up @@ -477,6 +481,10 @@ void f2fs_update_inode(struct inode *inode, struct page *node_page)
F2FS_I(inode)->i_disk_time[1] = inode->i_ctime;
F2FS_I(inode)->i_disk_time[2] = inode->i_mtime;
F2FS_I(inode)->i_disk_time[3] = F2FS_I(inode)->i_crtime;

#ifdef CONFIG_F2FS_CHECK_FS
f2fs_inode_chksum_set(F2FS_I_SB(inode), node_page);
#endif
}

void f2fs_update_inode_page(struct inode *inode)
Expand Down
10 changes: 9 additions & 1 deletion fs/f2fs/node.c
Original file line number Diff line number Diff line change
Expand Up @@ -1141,8 +1141,12 @@ static int read_node_page(struct page *page, int op_flags)
.encrypted_page = NULL,
};

if (PageUptodate(page))
if (PageUptodate(page)) {
#ifdef CONFIG_F2FS_CHECK_FS
f2fs_bug_on(sbi, !f2fs_inode_chksum_verify(sbi, page));
#endif
return LOCKED_PAGE;
}

f2fs_get_node_info(sbi, page->index, &ni);

Expand Down Expand Up @@ -1779,6 +1783,10 @@ static int f2fs_set_node_page_dirty(struct page *page)

if (!PageUptodate(page))
SetPageUptodate(page);
#ifdef CONFIG_F2FS_CHECK_FS
if (IS_INODE(page))
f2fs_inode_chksum_set(F2FS_P_SB(page), page);
#endif
if (!PageDirty(page)) {
__set_page_dirty_nobuffers(page);
inc_page_count(F2FS_P_SB(page), F2FS_DIRTY_NODES);
Expand Down
4 changes: 4 additions & 0 deletions fs/f2fs/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,10 @@ static inline void set_mark(struct page *page, int mark, int type)
else
flag &= ~(0x1 << type);
rn->footer.flag = cpu_to_le32(flag);

#ifdef CONFIG_F2FS_CHECK_FS
f2fs_inode_chksum_set(F2FS_P_SB(page), page);
#endif
}
#define set_dentry_mark(page, mark) set_mark(page, mark, DENT_BIT_SHIFT)
#define set_fsync_mark(page, mark) set_mark(page, mark, FSYNC_BIT_SHIFT)

0 comments on commit e64d8e7

Please sign in to comment.