f2fs: avoid looking up extents outside specified range
PATCH 3/3 f2fs: avoid looking up extents outside specified range
There are two advantages to update b_size in this way:
1. get_data_block tends to round down b_size to align with block size, if b_size isn't aligned already, it would take an extra loop to go through the range. So we round it up first.
2. unlike extent-based file, get_data_block could be time-consuming for indirect-based file, update b_size may avoid looking up blocks outside the range.
Signed-off-by Fan li <[email protected]>
--- fs/f2fs/data.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
fs/f2fs/data.c +4 -4
@@ -798,15 +798,15 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, isize =i_size_read (inode);mutex_lock (&inode->i_mutex); -if (logical_to_blk (inode, len) ==0 ) - len =blk_to_logical (inode,1 ); start_blk =logical_to_blk (inode, start); last_blk =logical_to_blk (inode, start + len -1 ); - next:memset (&map_bh,0 ,sizeof (struct buffer_head )); - map_bh.b_size = len; +if (last_blk >= start_blk) + map_bh.b_size =blk_to_logical (inode, last_blk - start_blk +1 ); +else + map_bh.b_size =blk_to_logical (inode,1 ); ret =get_data_block (inode, start_blk, &map_bh,0 ,F2FS_GET_BLOCK_FIEMAP );
Signature · 4 lines
1.7.9.5 ------------------------------------------------------------------------------