f2fs: introduce f2fs_map_bh to clean codes of check_extent_cache
RFC PATCH 3/10 f2fs: introduce f2fs_map_bh to clean codes of check_extent_cache
This patch introduces f2fs_map_bh to clean codes of check_extent_cache.
--- fs/f2fs/data.c | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-)
fs/f2fs/data.c +28 -14
@@ -248,8 +248,30 @@ int f2fs_reserve_block(struct dnode_of_data *dn, pgoff_t index)return err; } +static void f2fs_map_bh (struct inode *inode,pgoff_t pgofs, +struct extent_info *ei,struct buffer_head *bh_result) +{ +unsigned int blkbits = inode->i_sb->s_blocksize_bits; +pgoff_t start_fofs, end_fofs; +block_t start_blkaddr; +size_t count; + + start_fofs = ei->fofs; + end_fofs = ei->fofs + ei->len -1 ; + start_blkaddr = ei->blk; + +clear_buffer_new (bh_result); +map_bh (bh_result, inode->i_sb, + start_blkaddr + pgofs - start_fofs); + count = end_fofs - pgofs +1 ; +if (count < (UINT_MAX >> blkbits)) + bh_result->b_size = (count << blkbits); +else + bh_result->b_size =UINT_MAX ; +} +static int check_extent_cache (struct inode *inode,pgoff_t pgofs, -struct buffer_head *bh_result) +struct extent_info *ei) {struct f2fs_inode_info *fi =F2FS_I (inode);pgoff_t start_fofs, end_fofs;
@@ -271,18 +293,7 @@ static int check_extent_cache(struct inode *inode, pgoff_t pgofs, start_blkaddr = fi->ext.blk;if (pgofs >= start_fofs && pgofs <= end_fofs) { -unsigned int blkbits = inode->i_sb->s_blocksize_bits; -size_t count; - -clear_buffer_new (bh_result); -map_bh (bh_result, inode->i_sb, - start_blkaddr + pgofs - start_fofs); - count = end_fofs - pgofs +1 ; -if (count < (UINT_MAX >> blkbits)) - bh_result->b_size = (count << blkbits); -else - bh_result->b_size =UINT_MAX ; - + *ei = fi->ext;stat_inc_read_hit (inode->i_sb);read_unlock (&fi->ext_lock);return 1 ;
@@ -608,13 +619,16 @@ static int __get_data_block(struct inode *inode, sector_t iblock,int mode = create ?ALLOC_NODE :LOOKUP_NODE_RA ;pgoff_t pgofs, end_offset;int err =0 , ofs =1 ; +struct extent_info ei;bool allocated = false;/* Get the page offset from the block offset(iblock) */ pgofs = (pgoff_t)(iblock >> (PAGE_CACHE_SHIFT - blkbits)); -if (check_extent_cache (inode, pgofs, bh_result)) +if (check_extent_cache (inode, pgofs, &ei)) { +f2fs_map_bh (inode, pgofs, &ei, bh_result); goto out; + }if (create) {f2fs_balance_fs (F2FS_I_SB (inode));
Signature · 1 line
2.2.1
Jaegeuk Kim
maintainerHi Chao,
Quoted 21 lines · Chao Yu
This patch introduces
f2fs_map_bhto clean codes ofcheck_extent_cache.Signed-off-by Chao Yu <[email protected]>--- fs/f2fs/data.c | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-)fs/f2fs/data.c +6
-0@@ -248,8 +248,30 @@ int f2fs_reserve_block(struct dnode_of_data *dn, pgoff_t index)return err; } +static void f2fs_map_bh (struct inode *inode,pgoff_t pgofs, +struct extent_info *ei,struct buffer_head *bh_result) +{ +unsigned int blkbits = inode->i_sb->s_blocksize_bits; +pgoff_t start_fofs, end_fofs; +block_t start_blkaddr;
fs/f2fs/data.c int f2fs_reserve_block(struct dnode_of_data *dn, pgoff_t index) · line 266
Quoted 10 lines
fs/f2fs/data.c +10
-0+size_t count; + + start_fofs = ei->fofs; + end_fofs = ei->fofs + ei->len -1 ; + start_blkaddr = ei->blk; + +clear_buffer_new (bh_result); +map_bh (bh_result, inode->i_sb, + start_blkaddr + pgofs - start_fofs); + count = end_fofs - pgofs +1 ;
How about cleaning this codes like this?
static void f2fs_map_bh(struct super_block *sb, pgoff_t pgofs,
struct extent_info *ei, struct buffer_head *bh_result)
{
unsigned int blkbits = sb->s_blocksize_bits;
size_t count;
clear_buffer_new(bh_result);
map_bh(bh_result, sb, ei->blk + pgofs - ei->fofs);
count = ei->fofs + ei->len - pgofs;
if (count < (UINT_MAX >> blkbits))
bh_result->b_size = (count << blkbits);
else
bh_result->b_size = UINT_MAX;
}Quoted 52 lines
fs/f2fs/data.c +12
-14+if (count < (UINT_MAX >> blkbits)) + bh_result->b_size = (count << blkbits); +else + bh_result->b_size =UINT_MAX ; +} +static int check_extent_cache (struct inode *inode,pgoff_t pgofs, -struct buffer_head *bh_result) +struct extent_info *ei) {struct f2fs_inode_info *fi =F2FS_I (inode);pgoff_t start_fofs, end_fofs;@@ -271,18 +293,7 @@ static int check_extent_cache(struct inode *inode, pgoff_t pgofs, start_blkaddr = fi->ext.blk;if (pgofs >= start_fofs && pgofs <= end_fofs) { -unsigned int blkbits = inode->i_sb->s_blocksize_bits; -size_t count; - -clear_buffer_new (bh_result); -map_bh (bh_result, inode->i_sb, - start_blkaddr + pgofs - start_fofs); - count = end_fofs - pgofs +1 ; -if (count < (UINT_MAX >> blkbits)) - bh_result->b_size = (count << blkbits); -else - bh_result->b_size =UINT_MAX ; - + *ei = fi->ext;stat_inc_read_hit (inode->i_sb);read_unlock (&fi->ext_lock);return 1 ;@@ -608,13 +619,16 @@ static int __get_data_block(struct inode *inode, sector_t iblock,int mode = create ?ALLOC_NODE :LOOKUP_NODE_RA ;pgoff_t pgofs, end_offset;int err =0 , ofs =1 ; +struct extent_info ei;bool allocated = false;/* Get the page offset from the block offset(iblock) */ pgofs = (pgoff_t)(iblock >> (PAGE_CACHE_SHIFT - blkbits)); -if (check_extent_cache (inode, pgofs, bh_result)) +if (check_extent_cache (inode, pgofs, &ei)) { +f2fs_map_bh (inode, pgofs, &ei, bh_result); goto out; + }if (create) {f2fs_balance_fs (F2FS_I_SB (inode));Signature · 1 line
2.2.1
Hi Jaegeuk,
Quoted 36 lines
-----Original Message-----
From: Jaegeuk Kim [mailto:[email protected]]
Sent: Friday, January 23, 2015 8:25 AM
To: Chao Yu
Cc: Changman Lee; [email protected]; [email protected]
Subject: Re: [f2fs-dev][RFC PATCH 03/10] f2fs: introducef2fs_map_bhto clean codes ofcheck_extent_cacheHi Chao,
Quoted 25 lines · Chao Yu
This patch introduces
f2fs_map_bhto clean codes ofcheck_extent_cache.Signed-off-by Chao Yu <[email protected]>--- fs/f2fs/data.c | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-)fs/f2fs/data.c +10
-0@@ -248,8 +248,30 @@ int f2fs_reserve_block(struct dnode_of_data *dn, pgoff_t index)return err; } +static void f2fs_map_bh (struct inode *inode,pgoff_t pgofs, +struct extent_info *ei,struct buffer_head *bh_result) +{ +unsigned int blkbits = inode->i_sb->s_blocksize_bits; +pgoff_t start_fofs, end_fofs; +block_t start_blkaddr; +size_t count; + + start_fofs = ei->fofs; + end_fofs = ei->fofs + ei->len -1 ;
Quoted 8 lines
fs/f2fs/data.c int f2fs_reserve_block(struct dnode_of_data *dn, pgoff_t index) · line 266
Quoted 6 lines
fs/f2fs/data.c +6
-0+ start_blkaddr = ei->blk; + +clear_buffer_new (bh_result); +map_bh (bh_result, inode->i_sb, + start_blkaddr + pgofs - start_fofs); + count = end_fofs - pgofs +1 ;How about cleaning this codes like this?
Nice! I will use it.
Thanks,
Yu
Quoted 68 lines
static void f2fs_map_bh(struct
super_block*sb,pgoff_tpgofs,
structextent_info*ei, structbuffer_head*bh_result){ unsigned int blkbits = sb->s_blocksize_bits; size_t count; clear_buffer_new(bh_result); map_bh(bh_result, sb, ei->blk + pgofs - ei->fofs); count = ei->fofs + ei->len - pgofs; if (count < (UINT_MAX >> blkbits)) bh_result->b_size = (count << blkbits); else bh_result->b_size = UINT_MAX; }Quoted 52 lines
fs/f2fs/data.c +12
-15+if (count < (UINT_MAX >> blkbits)) + bh_result->b_size = (count << blkbits); +else + bh_result->b_size =UINT_MAX ; +} +static int check_extent_cache (struct inode *inode,pgoff_t pgofs, -struct buffer_head *bh_result) +struct extent_info *ei) {struct f2fs_inode_info *fi =F2FS_I (inode);pgoff_t start_fofs, end_fofs;@@ -271,18 +293,7 @@ static int check_extent_cache(struct inode *inode, pgoff_t pgofs, start_blkaddr = fi->ext.blk;if (pgofs >= start_fofs && pgofs <= end_fofs) { -unsigned int blkbits = inode->i_sb->s_blocksize_bits; -size_t count; - -clear_buffer_new (bh_result); -map_bh (bh_result, inode->i_sb, - start_blkaddr + pgofs - start_fofs); - count = end_fofs - pgofs +1 ; -if (count < (UINT_MAX >> blkbits)) - bh_result->b_size = (count << blkbits); -else - bh_result->b_size =UINT_MAX ; - + *ei = fi->ext;stat_inc_read_hit (inode->i_sb);read_unlock (&fi->ext_lock);return 1 ;@@ -608,13 +619,16 @@ static int __get_data_block(struct inode *inode, sector_t iblock,int mode = create ?ALLOC_NODE :LOOKUP_NODE_RA ;pgoff_t pgofs, end_offset;int err =0 , ofs =1 ; +struct extent_info ei;bool allocated = false;/* Get the page offset from the block offset(iblock) */ pgofs = (pgoff_t)(iblock >> (PAGE_CACHE_SHIFT - blkbits)); -if (check_extent_cache (inode, pgofs, bh_result)) +if (check_extent_cache (inode, pgofs, &ei)) { +f2fs_map_bh (inode, pgofs, &ei, bh_result); goto out; + }if (create) {f2fs_balance_fs (F2FS_I_SB (inode)); --2.2.1