[PATCH v4 3/6] f2fs: add helper to get inode chksum from inode page

From: Sheng Yong
Date: Sun Jun 11 2023 - 23:02:20 EST


Signed-off-by: Sheng Yong <shengyong@xxxxxxxx>
---
fs/f2fs/f2fs.h | 2 ++
fs/f2fs/inode.c | 21 +++++++++++++++++++++
2 files changed, 23 insertions(+)

diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 1b17bbe7e8656..a30c81ac7299d 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -3478,6 +3478,8 @@ int f2fs_pin_file_control(struct inode *inode, bool inc);
void f2fs_set_inode_flags(struct inode *inode);
bool f2fs_inode_chksum_verify(struct f2fs_sb_info *sbi, struct page *page);
void f2fs_inode_chksum_set(struct f2fs_sb_info *sbi, struct page *page);
+int f2fs_inode_chksum_get(struct f2fs_sb_info *sbi, struct inode *inode,
+ u32 *chksum);
struct inode *f2fs_iget(struct super_block *sb, unsigned long ino);
struct inode *f2fs_iget_retry(struct super_block *sb, unsigned long ino);
int f2fs_try_to_free_nats(struct f2fs_sb_info *sbi, int nr_shrink);
diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c
index 1e49009831c12..098d1ee72bfcb 100644
--- a/fs/f2fs/inode.c
+++ b/fs/f2fs/inode.c
@@ -204,6 +204,27 @@ void f2fs_inode_chksum_set(struct f2fs_sb_info *sbi, struct page *page)
ri->i_inode_checksum = cpu_to_le32(f2fs_inode_chksum(sbi, page));
}

+int f2fs_inode_chksum_get(struct f2fs_sb_info *sbi,
+ struct inode *inode, u32 *chksum)
+{
+ struct page *ipage;
+ struct f2fs_inode_info *fi = F2FS_I(inode);
+ struct f2fs_inode *ri;
+
+ if (!f2fs_sb_has_inode_chksum(sbi) ||
+ !f2fs_has_extra_attr(inode) ||
+ !F2FS_FITS_IN_INODE(ri, fi->i_extra_isize, i_inode_checksum))
+ return -EOPNOTSUPP;
+
+ ipage = f2fs_get_node_page(sbi, inode->i_ino);
+ if (IS_ERR(ipage))
+ return PTR_ERR(ipage);
+
+ *chksum = f2fs_inode_chksum(sbi, ipage);
+ f2fs_put_page(ipage, true);
+ return 0;
+}
+
static bool sanity_check_compress_inode(struct inode *inode,
struct f2fs_inode *ri)
{
--
2.40.1