f2fs: introduce sanity_check_blocks()
PATCH 1/1 f2fs: introduce sanity_check_blocks()
There are very similar codes in release_compress_blocks() and reserve_compress_blocks() which is used for data blocks check.
This patch introduces a new helper sanity_check_blocks() to include those common codes, and used it instead for cleanup.
--- fs/f2fs/file.c | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-)
fs/f2fs/file.c +20 -16
@@ -3369,11 +3369,9 @@ static int f2fs_get_compress_blocks(struct file *filp, unsigned long arg)return put_user (blocks, (u64 __user *)arg); } -static int release_compress_blocks (struct dnode_of_data *dn,pgoff_t count) +static int sanity_check_blocks (struct dnode_of_data *dn,pgoff_t count) {struct f2fs_sb_info *sbi =F2FS_I_SB (dn->inode); -unsigned int released_blocks =0 ; -int cluster_size =F2FS_I (dn->inode)->i_cluster_size;block_t blkaddr;int i;
@@ -3390,6 +3388,21 @@ static int release_compress_blocks(struct dnode_of_data *dn, pgoff_t count) } } +return 0 ; +} + +static int release_compress_blocks (struct dnode_of_data *dn,pgoff_t count) +{ +struct f2fs_sb_info *sbi =F2FS_I_SB (dn->inode); +unsigned int released_blocks =0 ; +int cluster_size =F2FS_I (dn->inode)->i_cluster_size; +block_t blkaddr; +int i, rc; + + rc =sanity_check_blocks (dn, count); +if (rc) +return rc; +while (count) {int compr_blocks =0 ;
@@ -3539,20 +3552,11 @@ static int reserve_compress_blocks(struct dnode_of_data *dn, pgoff_t count)unsigned int reserved_blocks =0 ;int cluster_size =F2FS_I (dn->inode)->i_cluster_size;block_t blkaddr; -int i; +int i, rc; -for (i =0 ; i < count; i++) { - blkaddr =data_blkaddr (dn->inode, dn->node_page, - dn->ofs_in_node + i); - -if (!__is_valid_data_blkaddr (blkaddr)) -continue ; -if (unlikely (!f2fs_is_valid_blkaddr (sbi, blkaddr, -DATA_GENERIC_ENHANCE ))) { -f2fs_handle_error (sbi,ERROR_INVALID_BLKADDR ); -return -EFSCORRUPTED ; - } - } + rc =sanity_check_blocks (dn, count); +if (rc) +return rc;while (count) {int compr_blocks =0 ;
Signature · 8 lines
2.25.1 _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Jaegeuk Kim
maintainerQuoted 34 lines · Yangtao Li
There are very similar codes in
release_compress_blocks()andreserve_compress_blocks()which is used for data blocks check.This patch introduces a new helper
sanity_check_blocks()to include those common codes, and used it instead for cleanup.Signed-off-by Yangtao Li <[email protected]>--- fs/f2fs/file.c | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-)fs/f2fs/file.c +3
-3@@ -3369,11 +3369,9 @@ static int f2fs_get_compress_blocks(struct file *filp, unsigned long arg)return put_user (blocks, (u64 __user *)arg); } -static int release_compress_blocks (struct dnode_of_data *dn,pgoff_t count) +static int sanity_check_blocks (struct dnode_of_data *dn,pgoff_t count) {struct f2fs_sb_info *sbi =F2FS_I_SB (dn->inode); -unsigned int released_blocks =0 ; -int cluster_size =F2FS_I (dn->inode)->i_cluster_size;block_t blkaddr;int i;@@ -3390,6 +3388,21 @@ static int release_compress_blocks(struct dnode_of_data *dn, pgoff_t count) } } +return 0 ; +}
fs/f2fs/file.c static int release_compress_blocks(struct dnode_of_data *dn, pgoff_t count) · line 3402
Quoted 10 lines
fs/f2fs/file.c +10
-0+ +static int release_compress_blocks (struct dnode_of_data *dn,pgoff_t count) +{ +struct f2fs_sb_info *sbi =F2FS_I_SB (dn->inode); +unsigned int released_blocks =0 ; +int cluster_size =F2FS_I (dn->inode)->i_cluster_size; +block_t blkaddr; +int i, rc; + + rc =sanity_check_blocks (dn, count);
^
errQuoted 33 lines
fs/f2fs/file.c +7
-13+if (rc) +return rc; +while (count) {int compr_blocks =0 ;@@ -3539,20 +3552,11 @@ static int reserve_compress_blocks(struct dnode_of_data *dn, pgoff_t count)unsigned int reserved_blocks =0 ;int cluster_size =F2FS_I (dn->inode)->i_cluster_size;block_t blkaddr; -int i; +int i, rc; -for (i =0 ; i < count; i++) { - blkaddr =data_blkaddr (dn->inode, dn->node_page, - dn->ofs_in_node + i); - -if (!__is_valid_data_blkaddr (blkaddr)) -continue ; -if (unlikely (!f2fs_is_valid_blkaddr (sbi, blkaddr, -DATA_GENERIC_ENHANCE ))) { -f2fs_handle_error (sbi,ERROR_INVALID_BLKADDR ); -return -EFSCORRUPTED ; - } - } + rc =sanity_check_blocks (dn, count); +if (rc) +return rc;while (count) {int compr_blocks =0 ;Signature · 1 line
2.25.1
Chao Yu
maintainerQuoted 5 lines · Yangtao Li
There are very similar codes in
release_compress_blocks()andreserve_compress_blocks()which is used for data blocks check.This patch introduces a new helper
sanity_check_blocks()to include those common codes, and used it instead for cleanup.
How about reusing f2fs_sanity_check_cluster()? Something like:
bool f2fs_sanity_check_cluster()
if (compressed_cluster)
f2fs_sanity_check_compressed_cluster()
else
f2fs_sanity_check_normal_cluster()
Quoted 70 lines
Signed-off-by Yangtao Li <[email protected]>--- fs/f2fs/file.c | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-)fs/f2fs/file.c +20
-16@@ -3369,11 +3369,9 @@ static int f2fs_get_compress_blocks(struct file *filp, unsigned long arg)return put_user (blocks, (u64 __user *)arg); } -static int release_compress_blocks (struct dnode_of_data *dn,pgoff_t count) +static int sanity_check_blocks (struct dnode_of_data *dn,pgoff_t count) {struct f2fs_sb_info *sbi =F2FS_I_SB (dn->inode); -unsigned int released_blocks =0 ; -int cluster_size =F2FS_I (dn->inode)->i_cluster_size;block_t blkaddr;int i;@@ -3390,6 +3388,21 @@ static int release_compress_blocks(struct dnode_of_data *dn, pgoff_t count) } } +return 0 ; +} + +static int release_compress_blocks (struct dnode_of_data *dn,pgoff_t count) +{ +struct f2fs_sb_info *sbi =F2FS_I_SB (dn->inode); +unsigned int released_blocks =0 ; +int cluster_size =F2FS_I (dn->inode)->i_cluster_size; +block_t blkaddr; +int i, rc; + + rc =sanity_check_blocks (dn, count); +if (rc) +return rc; +while (count) {int compr_blocks =0 ;@@ -3539,20 +3552,11 @@ static int reserve_compress_blocks(struct dnode_of_data *dn, pgoff_t count)unsigned int reserved_blocks =0 ;int cluster_size =F2FS_I (dn->inode)->i_cluster_size;block_t blkaddr; -int i; +int i, rc; -for (i =0 ; i < count; i++) { - blkaddr =data_blkaddr (dn->inode, dn->node_page, - dn->ofs_in_node + i); - -if (!__is_valid_data_blkaddr (blkaddr)) -continue ; -if (unlikely (!f2fs_is_valid_blkaddr (sbi, blkaddr, -DATA_GENERIC_ENHANCE ))) { -f2fs_handle_error (sbi,ERROR_INVALID_BLKADDR ); -return -EFSCORRUPTED ; - } - } + rc =sanity_check_blocks (dn, count); +if (rc) +return rc;while (count) {int compr_blocks =0 ;