Enable in-memory inode checksum to protect metadata blocks
from in-memory scribbles only when checking consistency with
no performance requirements.

Signed-off-by: Weichao Guo <guoweic...@huawei.com>
---
 fs/f2fs/inode.c | 7 +++++++
 fs/f2fs/node.c  | 5 +++++
 2 files changed, 12 insertions(+)

diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c
index 89c838b..cb51557 100644
--- a/fs/f2fs/inode.c
+++ b/fs/f2fs/inode.c
@@ -159,8 +159,12 @@ bool f2fs_inode_chksum_verify(struct f2fs_sb_info *sbi, 
struct page *page)
        struct f2fs_inode *ri;
        __u32 provided, calculated;
 
+#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;
@@ -464,6 +468,9 @@ void update_inode_page(struct inode *inode)
                return;
        }
        update_inode(inode, node_page);
+#ifdef CONFIG_F2FS_CHECK_FS
+       f2fs_inode_chksum_set(sbi, node_page);
+#endif
        f2fs_put_page(node_page, 1);
 }
 
diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
index 177c438..d76399d 100644
--- a/fs/f2fs/node.c
+++ b/fs/f2fs/node.c
@@ -1191,11 +1191,16 @@ static struct page *__get_node_page(struct f2fs_sb_info 
*sbi, pgoff_t nid,
                goto out_err;
        }
 
+#ifdef CONFIG_F2FS_CHECK_FS
+page_hit:
+       BUG_ON(f2fs_inode_chksum_verify(sbi, page));
+#else
        if (!f2fs_inode_chksum_verify(sbi, page)) {
                err = -EBADMSG;
                goto out_err;
        }
 page_hit:
+#endif
        if(unlikely(nid != nid_of_node(page))) {
                f2fs_msg(sbi->sb, KERN_WARNING, "inconsistent node block, "
                        "nid:%lu, 
node_footer[nid:%u,ino:%u,ofs:%u,cpver:%llu,blkaddr:%u]",
-- 
2.10.1


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

Reply via email to