f2fs: rename logical_to_blk and blk_to_logical
Jaegeuk Kim
maintainerPATCH 1/4 f2fs: rename logical_to_blk and blk_to_logical
This patch renames two functions like below having u64.
- logical_to_blk to bytes_to_blks
- blk_to_logical to blks_to_bytes
--- fs/f2fs/data.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-)
fs/f2fs/data.c +20 -20
@@ -1808,14 +1808,14 @@ static int get_data_block_bmap(struct inode *inode, sector_t iblock, NO_CHECK_TYPE, create); } -static inline sector_t logical_to_blk (struct inode *inode,loff_t offset) +static inline u64 bytes_to_blks (struct inode *inode,u64 bytes) { -return (offset >> inode->i_blkbits); +return (bytes >> inode->i_blkbits); } -static inline loff_t blk_to_logical (struct inode *inode,sector_t blk) +static inline u64 blks_to_bytes (struct inode *inode,u64 blks) { -return (blk << inode->i_blkbits); +return (blks << inode->i_blkbits); } static int f2fs_xattr_fiemap(struct inode *inode,
@@ -1843,7 +1843,7 @@ static int f2fs_xattr_fiemap(struct inode *inode,return err; } - phys = (__u64 )blk_to_logical (inode, ni.blk_addr); + phys =blks_to_bytes (inode, ni.blk_addr); offset = offsetof(struct f2fs_inode , i_addr) +sizeof (__le32) * (DEF_ADDRS_PER_INODE -get_inline_xattr_addrs (inode));
@@ -1875,7 +1875,7 @@ static int f2fs_xattr_fiemap(struct inode *inode,return err; } - phys = (__u64 )blk_to_logical (inode, ni.blk_addr); + phys =blks_to_bytes (inode, ni.blk_addr); len = inode->i_sb->s_blocksize;f2fs_put_page (page,1 );
@@ -1945,18 +1945,18 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, goto out; } -if (logical_to_blk (inode, len) ==0 ) - len =blk_to_logical (inode,1 ); +if (bytes_to_blks (inode, len) ==0 ) + len =blks_to_bytes (inode,1 ); - start_blk =logical_to_blk (inode, start); - last_blk =logical_to_blk (inode, start + len -1 ); + start_blk =bytes_to_blks (inode, start); + last_blk =bytes_to_blks (inode, start + len -1 ); next:memset (&map_bh,0 ,sizeof (struct buffer_head )); map_bh.b_size = len;if (compr_cluster) - map_bh.b_size =blk_to_logical (inode, cluster_size -1 ); + map_bh.b_size =blks_to_bytes (inode, cluster_size -1 ); ret =get_data_block (inode, start_blk, &map_bh,0 ,F2FS_GET_BLOCK_FIEMAP , &next_pgofs);
@@ -1967,7 +1967,7 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,if (!buffer_mapped (&map_bh)) { start_blk = next_pgofs; -if (blk_to_logical (inode, start_blk) <blk_to_logical (inode, +if (blks_to_bytes (inode, start_blk) <blks_to_bytes (inode,max_inode_blocks (inode))) goto prep_next;
@@ -1993,9 +1993,9 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, compr_cluster = false; - logical =blk_to_logical (inode, start_blk -1 ); - phys =blk_to_logical (inode, map_bh.b_blocknr); - size =blk_to_logical (inode, cluster_size); + logical =blks_to_bytes (inode, start_blk -1 ); + phys =blks_to_bytes (inode, map_bh.b_blocknr); + size =blks_to_bytes (inode, cluster_size); flags |=FIEMAP_EXTENT_ENCODED ;
@@ -2013,14 +2013,14 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, goto prep_next; } - logical =blk_to_logical (inode, start_blk); - phys =blk_to_logical (inode, map_bh.b_blocknr); + logical =blks_to_bytes (inode, start_blk); + phys =blks_to_bytes (inode, map_bh.b_blocknr); size = map_bh.b_size; flags =0 ;if (buffer_unwritten (&map_bh)) flags =FIEMAP_EXTENT_UNWRITTEN ; - start_blk +=logical_to_blk (inode, size); + start_blk +=bytes_to_blks (inode, size); prep_next:cond_resched ();
@@ -3903,7 +3903,7 @@ static int check_swap_activate_fast(struct swap_info_struct *sis,* to be very smart. */ cur_lblock =0 ; - last_lblock =logical_to_blk (inode,i_size_read (inode)); + last_lblock =bytes_to_blks (inode,i_size_read (inode)); len =i_size_read (inode);while (cur_lblock <= last_lblock && cur_lblock < sis->max) {
@@ -3925,7 +3925,7 @@ static int check_swap_activate_fast(struct swap_info_struct *sis, goto err_out; pblock = map_bh.b_blocknr; - nr_pblocks =logical_to_blk (inode, map_bh.b_size); + nr_pblocks =bytes_to_blks (inode, map_bh.b_size);if (cur_lblock + nr_pblocks >= sis->max) nr_pblocks = sis->max - cur_lblock;
Signature · 1 line
2.29.2.454.gaff20da3a2-goog
Jaegeuk Kim
maintainerPATCH 2/4 f2fs: use new conversion functions between blks and bytes
This patch cleans up blks and bytes conversions.
--- fs/f2fs/data.c | 46 +++++++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 25 deletions(-)
fs/f2fs/data.c +21 -25
@@ -1750,6 +1750,16 @@ bool f2fs_overwrite_io(struct inode *inode, loff_t pos, size_t len)return true; } +static inline u64 bytes_to_blks (struct inode *inode,u64 bytes) +{ +return (bytes >> inode->i_blkbits); +} + +static inline u64 blks_to_bytes (struct inode *inode,u64 blks) +{ +return (blks << inode->i_blkbits); +} +static int __get_data_block (struct inode *inode,sector_t iblock,struct buffer_head *bh,int create,int flag,pgoff_t *next_pgofs,int seg_type,bool may_write)
@@ -1758,7 +1768,7 @@ static int __get_data_block(struct inode *inode, sector_t iblock,int err; map.m_lblk = iblock; - map.m_len = bh->b_size >> inode->i_blkbits; + map.m_len =bytes_to_blks (inode, bh->b_size); map.m_next_pgofs = next_pgofs; map.m_next_extent =NULL ; map.m_seg_type = seg_type;
@@ -1768,7 +1778,7 @@ static int __get_data_block(struct inode *inode, sector_t iblock,if (!err) {map_bh (bh, inode->i_sb, map.m_pblk); bh->b_state = (bh->b_state & ~F2FS_MAP_FLAGS ) | map.m_flags; - bh->b_size = (u64 )map.m_len << inode->i_blkbits; + bh->b_size =blks_to_bytes (inode, map.m_len); }return err; }
@@ -1808,16 +1818,6 @@ static int get_data_block_bmap(struct inode *inode, sector_t iblock, NO_CHECK_TYPE, create); } -static inline u64 bytes_to_blks (struct inode *inode,u64 bytes) -{ -return (bytes >> inode->i_blkbits); -} - -static inline u64 blks_to_bytes (struct inode *inode,u64 blks) -{ -return (blks << inode->i_blkbits); -} -static int f2fs_xattr_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo) {
@@ -2053,8 +2053,7 @@ static int f2fs_read_single_page(struct inode *inode, struct page *page, bool is_readahead) {struct bio *bio = *bio_ret; -const unsigned blkbits = inode->i_blkbits; -const unsigned blocksize =1 << blkbits; +const unsigned blocksize =blks_to_bytes (inode,1 );sector_t block_in_file;sector_t last_block;sector_t last_block_in_file;
@@ -2063,8 +2062,8 @@ static int f2fs_read_single_page(struct inode *inode, struct page *page, block_in_file = (sector_t )page_index (page); last_block = block_in_file + nr_pages; - last_block_in_file = (f2fs_readpage_limit (inode) + blocksize -1 ) >> - blkbits; + last_block_in_file =bytes_to_blks (inode, +f2fs_readpage_limit (inode) + blocksize -1 );if (last_block > last_block_in_file) last_block = last_block_in_file;
@@ -2177,16 +2176,15 @@ int f2fs_read_multi_pages(struct compress_ctx *cc, struct bio **bio_ret,struct bio *bio = *bio_ret;unsigned int start_idx = cc->cluster_idx << cc->log_cluster_size;sector_t last_block_in_file; -const unsigned blkbits = inode->i_blkbits; -const unsigned blocksize =1 << blkbits; +const unsigned blocksize =blks_to_bytes (inode,1 );struct decompress_io_ctx *dic =NULL ;int i;int ret =0 ;f2fs_bug_on (sbi,f2fs_cluster_is_empty (cc)); - last_block_in_file = (f2fs_readpage_limit (inode) + - blocksize -1 ) >> blkbits; + last_block_in_file =bytes_to_blks (inode, +f2fs_readpage_limit (inode) + blocksize -1 );/* get rid of pages beyond EOF */ for (i =0 ; i < cc->cluster_size; i++) {
@@ -3968,7 +3966,6 @@ static int check_swap_activate(struct swap_info_struct *sis,struct inode *inode = mapping->host;unsigned blocks_per_page;unsigned long page_no; -unsigned blkbits;sector_t probe_block;sector_t last_block;sector_t lowest_block =-1 ;
@@ -3979,8 +3976,7 @@ static int check_swap_activate(struct swap_info_struct *sis,if (PAGE_SIZE ==F2FS_BLKSIZE )return check_swap_activate_fast (sis, swap_file, span); - blkbits = inode->i_blkbits; - blocks_per_page =PAGE_SIZE >> blkbits; + blocks_per_page =bytes_to_blks (inode,PAGE_SIZE );/* * Map all the blocks into the extent list. This code doesn't try
@@ -3988,7 +3984,7 @@ static int check_swap_activate(struct swap_info_struct *sis,*/ probe_block =0 ; page_no =0 ; - last_block =i_size_read (inode) >> blkbits; + last_block =bytes_to_blks (inode,i_size_read (inode));while ((probe_block + blocks_per_page) <= last_block && page_no < sis->max) {unsigned block_in_page;
@@ -4028,7 +4024,7 @@ static int check_swap_activate(struct swap_info_struct *sis, } } - first_block >>= (PAGE_SHIFT - blkbits); + first_block >>= (PAGE_SHIFT - inode->i_blkbits);if (page_no) {/* exclude the header page */ if (first_block < lowest_block) lowest_block = first_block;
Signature · 1 line
2.29.2.454.gaff20da3a2-goog
Jaegeuk Kim
maintainerRe: [PATCH 2/4] f2fs: use new conversion functions between blks and bytes
Quoted 142 lines · Jaegeuk Kim
This patch cleans up blks and bytes conversions.
Signed-off-by Jaegeuk Kim <[email protected]>--- fs/f2fs/data.c | 46 +++++++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 25 deletions(-)fs/f2fs/data.c +21
-25@@ -1750,6 +1750,16 @@ bool f2fs_overwrite_io(struct inode *inode, loff_t pos, size_t len)return true; } +static inline u64 bytes_to_blks (struct inode *inode,u64 bytes) +{ +return (bytes >> inode->i_blkbits); +} + +static inline u64 blks_to_bytes (struct inode *inode,u64 blks) +{ +return (blks << inode->i_blkbits); +} +static int __get_data_block (struct inode *inode,sector_t iblock,struct buffer_head *bh,int create,int flag,pgoff_t *next_pgofs,int seg_type,bool may_write)@@ -1758,7 +1768,7 @@ static int __get_data_block(struct inode *inode, sector_t iblock,int err; map.m_lblk = iblock; - map.m_len = bh->b_size >> inode->i_blkbits; + map.m_len =bytes_to_blks (inode, bh->b_size); map.m_next_pgofs = next_pgofs; map.m_next_extent =NULL ; map.m_seg_type = seg_type;@@ -1768,7 +1778,7 @@ static int __get_data_block(struct inode *inode, sector_t iblock,if (!err) {map_bh (bh, inode->i_sb, map.m_pblk); bh->b_state = (bh->b_state & ~F2FS_MAP_FLAGS ) | map.m_flags; - bh->b_size = (u64 )map.m_len << inode->i_blkbits; + bh->b_size =blks_to_bytes (inode, map.m_len); }return err; }@@ -1808,16 +1818,6 @@ static int get_data_block_bmap(struct inode *inode, sector_t iblock, NO_CHECK_TYPE, create); } -static inline u64 bytes_to_blks (struct inode *inode,u64 bytes) -{ -return (bytes >> inode->i_blkbits); -} - -static inline u64 blks_to_bytes (struct inode *inode,u64 blks) -{ -return (blks << inode->i_blkbits); -} -static int f2fs_xattr_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo) {@@ -2053,8 +2053,7 @@ static int f2fs_read_single_page(struct inode *inode, struct page *page, bool is_readahead) {struct bio *bio = *bio_ret; -const unsigned blkbits = inode->i_blkbits; -const unsigned blocksize =1 << blkbits; +const unsigned blocksize =blks_to_bytes (inode,1 );sector_t block_in_file;sector_t last_block;sector_t last_block_in_file;@@ -2063,8 +2062,8 @@ static int f2fs_read_single_page(struct inode *inode, struct page *page, block_in_file = (sector_t )page_index (page); last_block = block_in_file + nr_pages; - last_block_in_file = (f2fs_readpage_limit (inode) + blocksize -1 ) >> - blkbits; + last_block_in_file =bytes_to_blks (inode, +f2fs_readpage_limit (inode) + blocksize -1 );if (last_block > last_block_in_file) last_block = last_block_in_file;@@ -2177,16 +2176,15 @@ int f2fs_read_multi_pages(struct compress_ctx *cc, struct bio **bio_ret,struct bio *bio = *bio_ret;unsigned int start_idx = cc->cluster_idx << cc->log_cluster_size;sector_t last_block_in_file; -const unsigned blkbits = inode->i_blkbits; -const unsigned blocksize =1 << blkbits; +const unsigned blocksize =blks_to_bytes (inode,1 );struct decompress_io_ctx *dic =NULL ;int i;int ret =0 ;f2fs_bug_on (sbi,f2fs_cluster_is_empty (cc)); - last_block_in_file = (f2fs_readpage_limit (inode) + - blocksize -1 ) >> blkbits; + last_block_in_file =bytes_to_blks (inode, +f2fs_readpage_limit (inode) + blocksize -1 );/* get rid of pages beyond EOF */ for (i =0 ; i < cc->cluster_size; i++) {@@ -3968,7 +3966,6 @@ static int check_swap_activate(struct swap_info_struct *sis,struct inode *inode = mapping->host;unsigned blocks_per_page;unsigned long page_no; -unsigned blkbits;sector_t probe_block;sector_t last_block;sector_t lowest_block =-1 ;@@ -3979,8 +3976,7 @@ static int check_swap_activate(struct swap_info_struct *sis,if (PAGE_SIZE ==F2FS_BLKSIZE )return check_swap_activate_fast (sis, swap_file, span); - blkbits = inode->i_blkbits; - blocks_per_page =PAGE_SIZE >> blkbits; + blocks_per_page =bytes_to_blks (inode,PAGE_SIZE );/* * Map all the blocks into the extent list. This code doesn't try @@ -3988,7 +3984,7 @@ static int check_swap_activate(struct swap_info_struct *sis,*/ probe_block =0 ; page_no =0 ; - last_block =i_size_read (inode) >> blkbits; + last_block =bytes_to_blks (inode,i_size_read (inode));while ((probe_block + blocks_per_page) <= last_block && page_no < sis->max) {unsigned block_in_page;@@ -4028,7 +4024,7 @@ static int check_swap_activate(struct swap_info_struct *sis, } } - first_block >>= (PAGE_SHIFT - blkbits); + first_block >>= (PAGE_SHIFT - inode->i_blkbits);if (page_no) {/* exclude the header page */ if (first_block < lowest_block) lowest_block = first_block;Signature · 1 line
2.29.2.454.gaff20da3a2-goog
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Chao Yu
Reviewed-byRe: [f2fs-dev] [PATCH 2/4] f2fs: use new conversion functions between blks and bytes
Quoted 4 lines · Jaegeuk Kim
Quoted 3 lines · Jaegeuk Kim
This patch cleans up blks and bytes conversions.
Signed-off-by Jaegeuk Kim <[email protected]>
Thanks,
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Jaegeuk Kim
maintainerPATCH 3/4 f2fs: fix wrong block count instead of bytes
In reply to Jaegeuk KimWe should convert cur_lblock, a block count, to bytes for len.
--- fs/f2fs/data.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/f2fs/data.c +2 -2
@@ -3893,7 +3893,7 @@ static int check_swap_activate_fast(struct swap_info_struct *sis,sector_t highest_pblock =0 ;int nr_extents =0 ;unsigned long nr_pblocks; -unsigned long len; +u64 len;int ret;/*
@@ -3911,7 +3911,7 @@ static int check_swap_activate_fast(struct swap_info_struct *sis,cond_resched ();memset (&map_bh,0 ,sizeof (struct buffer_head )); - map_bh.b_size = len - cur_lblock; + map_bh.b_size = len -blks_to_bytes (inode, cur_lblock); ret =get_data_block (inode, cur_lblock, &map_bh,0 ,F2FS_GET_BLOCK_FIEMAP , &next_pgofs);
Signature · 1 line
2.29.2.454.gaff20da3a2-goog
Jaegeuk Kim
maintainerRe: [PATCH 3/4] f2fs: fix wrong block count instead of bytes
Quoted 31 lines · Jaegeuk Kim
We should convert
cur_lblock, a block count, to bytes for len.Signed-off-by Jaegeuk Kim <[email protected]>--- fs/f2fs/data.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)fs/f2fs/data.c +2
-2@@ -3893,7 +3893,7 @@ static int check_swap_activate_fast(struct swap_info_struct *sis,sector_t highest_pblock =0 ;int nr_extents =0 ;unsigned long nr_pblocks; -unsigned long len; +u64 len;int ret;/* @@ -3911,7 +3911,7 @@ static int check_swap_activate_fast(struct swap_info_struct *sis,cond_resched ();memset (&map_bh,0 ,sizeof (struct buffer_head )); - map_bh.b_size = len - cur_lblock; + map_bh.b_size = len -blks_to_bytes (inode, cur_lblock); ret =get_data_block (inode, cur_lblock, &map_bh,0 ,F2FS_GET_BLOCK_FIEMAP , &next_pgofs);Signature · 1 line
2.29.2.454.gaff20da3a2-goog
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Chao Yu
Reviewed-byRe: [f2fs-dev] [PATCH 3/4] f2fs: fix wrong block count instead of bytes
Quoted 4 lines · Jaegeuk Kim
Quoted 3 lines · Jaegeuk Kim
We should convert
cur_lblock, a block count, to bytes for len.Signed-off-by Jaegeuk Kim <[email protected]>
Thanks,
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Jaegeuk Kim
maintainerPATCH 4/4 f2fs: remove buffer_head which has 32bits limit
In reply to Jaegeuk KimThis patch removes buffer_head dependency when getting block addresses. Light reported there's a 32bit issue in f2fs_fiemap where map_bh.b_size is 32bits while len is 64bits given by user. This will give wrong length to f2fs_map_block.
--- fs/f2fs/data.c | 76 ++++++++++++++++++++++---------------------------- 1 file changed, 34 insertions(+), 42 deletions(-)
fs/f2fs/data.c +34 -42
@@ -1783,15 +1783,6 @@ static int __get_data_block(struct inode *inode, sector_t iblock,return err; } -static int get_data_block (struct inode *inode,sector_t iblock, -struct buffer_head *bh_result,int create,int flag, -pgoff_t *next_pgofs) -{ -return __get_data_block (inode, iblock, bh_result, create, - flag, next_pgofs, -NO_CHECK_TYPE , create); -} -static int get_data_block_dio_write (struct inode *inode,sector_t iblock,struct buffer_head *bh_result,int create) {
@@ -1810,14 +1801,6 @@ static int get_data_block_dio(struct inode *inode, sector_t iblock, false); } -static int get_data_block_bmap (struct inode *inode,sector_t iblock, -struct buffer_head *bh_result,int create) -{ -return __get_data_block (inode, iblock, bh_result, create, -F2FS_GET_BLOCK_BMAP ,NULL , -NO_CHECK_TYPE , create); -} -static int f2fs_xattr_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo) {
@@ -1913,7 +1896,7 @@ static loff_t max_inode_blocks(struct inode *inode)int f2fs_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo,u64 start,u64 len) { -struct buffer_head map_bh; +struct f2fs_map_blocks map;sector_t start_blk, last_blk;pgoff_t next_pgofs;u64 logical =0 , phys =0 , size =0 ;
@@ -1952,19 +1935,21 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, last_blk =bytes_to_blks (inode, start + len -1 ); next: -memset (&map_bh,0 ,sizeof (struct buffer_head )); - map_bh.b_size = len; +memset (&map,0 ,sizeof (map)); + map.m_lblk = start_blk; + map.m_len =bytes_to_blks (inode, len); + map.m_next_pgofs = &next_pgofs; + map.m_seg_type =NO_CHECK_TYPE ;if (compr_cluster) - map_bh.b_size =blks_to_bytes (inode, cluster_size -1 ); + map.m_len = cluster_size -1 ; - ret =get_data_block (inode, start_blk, &map_bh,0 , -F2FS_GET_BLOCK_FIEMAP , &next_pgofs); + ret =f2fs_map_blocks (inode, &map,0 ,F2FS_GET_BLOCK_FIEMAP );if (ret) goto out;/* HOLE */ - if (!buffer_mapped(&map_bh)) { + if (!(map.m_flags & F2FS_MAP_FLAGS)) { start_blk = next_pgofs; if (blks_to_bytes(inode, start_blk) < blks_to_bytes(inode,
@@ -1994,7 +1979,7 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, logical =blks_to_bytes (inode, start_blk -1 ); - phys =blks_to_bytes (inode, map_bh.b_blocknr); + phys =blks_to_bytes (inode, map.m_pblk); size =blks_to_bytes (inode, cluster_size); flags |=FIEMAP_EXTENT_ENCODED ;
@@ -2007,17 +1992,17 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, goto prep_next; } -if (map_bh.b_blocknr ==COMPRESS_ADDR ) { +if (map.m_pblk ==COMPRESS_ADDR ) { compr_cluster = true; start_blk++; goto prep_next; } logical =blks_to_bytes (inode, start_blk); - phys =blks_to_bytes (inode, map_bh.b_blocknr); - size = map_bh.b_size; + phys =blks_to_bytes (inode, map.m_pblk); + size =blks_to_bytes (inode, map.m_len); flags =0 ; -if (buffer_unwritten (&map_bh)) +if (map.m_flags &F2FS_MAP_UNWRITTEN ) flags =FIEMAP_EXTENT_UNWRITTEN ; start_blk +=bytes_to_blks (inode, size);
@@ -3797,9 +3782,6 @@ static sector_t f2fs_bmap_compress(struct inode *inode, sector_t block)static sector_t f2fs_bmap (struct address_space *mapping,sector_t block) {struct inode *inode = mapping->host; -struct buffer_head tmp = { - .b_size =i_blocksize (inode), - };sector_t blknr =0 ;if (f2fs_has_inline_data (inode))
@@ -3816,8 +3798,16 @@ static sector_t f2fs_bmap(struct address_space *mapping, sector_t block)if (f2fs_compressed_file (inode)) { blknr =f2fs_bmap_compress (inode, block); }else { -if (!get_data_block_bmap (inode, block, &tmp,0 )) - blknr = tmp.b_blocknr; +struct f2fs_map_blocks map; + +memset (&map,0 ,sizeof (map)); + map.m_lblk = block; + map.m_len =1 ; + map.m_next_pgofs =NULL ; + map.m_seg_type =NO_CHECK_TYPE ; + +if (!f2fs_map_blocks (inode, &map,0 ,F2FS_GET_BLOCK_BMAP )) + blknr = map.m_pblk; } out:trace_f2fs_bmap (inode, block, blknr);
@@ -3905,25 +3895,27 @@ static int check_swap_activate_fast(struct swap_info_struct *sis, len =i_size_read (inode);while (cur_lblock <= last_lblock && cur_lblock < sis->max) { -struct buffer_head map_bh; +struct f2fs_map_blocks map;pgoff_t next_pgofs;cond_resched (); -memset (&map_bh,0 ,sizeof (struct buffer_head )); - map_bh.b_size = len -blks_to_bytes (inode, cur_lblock); +memset (&map,0 ,sizeof (map)); + map.m_lblk = cur_lblock; + map.m_len =bytes_to_blks (inode, len) - cur_lblock; + map.m_next_pgofs = &next_pgofs; + map.m_seg_type =NO_CHECK_TYPE ; - ret =get_data_block (inode, cur_lblock, &map_bh,0 , -F2FS_GET_BLOCK_FIEMAP , &next_pgofs); + ret =f2fs_map_blocks (inode, &map,0 ,F2FS_GET_BLOCK_FIEMAP );if (ret) goto err_out;/* hole */ -if (!buffer_mapped (&map_bh)) +if (!(map.m_flags &F2FS_MAP_FLAGS )) goto err_out; - pblock = map_bh.b_blocknr; - nr_pblocks =bytes_to_blks (inode, map_bh.b_size); + pblock = map.m_pblk; + nr_pblocks = map.m_len;if (cur_lblock + nr_pblocks >= sis->max) nr_pblocks = sis->max - cur_lblock;
Signature · 1 line
2.29.2.454.gaff20da3a2-goog
Jaegeuk Kim
maintainerRe: [PATCH 4/4] f2fs: remove buffer_head which has 32bits limit
Quoted 181 lines · Jaegeuk Kim
This patch removes
buffer_headdependency when getting block addresses. Light reported there's a 32bit issue inf2fs_fiemapwhere map_bh.b_size is 32bits while len is 64bits given by user. This will give wrong length tof2fs_map_block.Reported-by Light Hsieh <[email protected]>Signed-off-by Jaegeuk Kim <[email protected]>--- fs/f2fs/data.c | 76 ++++++++++++++++++++++---------------------------- 1 file changed, 34 insertions(+), 42 deletions(-)fs/f2fs/data.c +34
-42@@ -1783,15 +1783,6 @@ static int __get_data_block(struct inode *inode, sector_t iblock,return err; } -static int get_data_block (struct inode *inode,sector_t iblock, -struct buffer_head *bh_result,int create,int flag, -pgoff_t *next_pgofs) -{ -return __get_data_block (inode, iblock, bh_result, create, - flag, next_pgofs, -NO_CHECK_TYPE , create); -} -static int get_data_block_dio_write (struct inode *inode,sector_t iblock,struct buffer_head *bh_result,int create) {@@ -1810,14 +1801,6 @@ static int get_data_block_dio(struct inode *inode, sector_t iblock, false); } -static int get_data_block_bmap (struct inode *inode,sector_t iblock, -struct buffer_head *bh_result,int create) -{ -return __get_data_block (inode, iblock, bh_result, create, -F2FS_GET_BLOCK_BMAP ,NULL , -NO_CHECK_TYPE , create); -} -static int f2fs_xattr_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo) {@@ -1913,7 +1896,7 @@ static loff_t max_inode_blocks(struct inode *inode)int f2fs_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo,u64 start,u64 len) { -struct buffer_head map_bh; +struct f2fs_map_blocks map;sector_t start_blk, last_blk;pgoff_t next_pgofs;u64 logical =0 , phys =0 , size =0 ;@@ -1952,19 +1935,21 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, last_blk =bytes_to_blks (inode, start + len -1 ); next: -memset (&map_bh,0 ,sizeof (struct buffer_head )); - map_bh.b_size = len; +memset (&map,0 ,sizeof (map)); + map.m_lblk = start_blk; + map.m_len =bytes_to_blks (inode, len); + map.m_next_pgofs = &next_pgofs; + map.m_seg_type =NO_CHECK_TYPE ;if (compr_cluster) - map_bh.b_size =blks_to_bytes (inode, cluster_size -1 ); + map.m_len = cluster_size -1 ; - ret =get_data_block (inode, start_blk, &map_bh,0 , -F2FS_GET_BLOCK_FIEMAP , &next_pgofs); + ret =f2fs_map_blocks (inode, &map,0 ,F2FS_GET_BLOCK_FIEMAP );if (ret) goto out;/* HOLE */ - if (!buffer_mapped(&map_bh)) { + if (!(map.m_flags & F2FS_MAP_FLAGS)) { start_blk = next_pgofs; if (blks_to_bytes(inode, start_blk) < blks_to_bytes(inode,@@ -1994,7 +1979,7 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, logical =blks_to_bytes (inode, start_blk -1 ); - phys =blks_to_bytes (inode, map_bh.b_blocknr); + phys =blks_to_bytes (inode, map.m_pblk); size =blks_to_bytes (inode, cluster_size); flags |=FIEMAP_EXTENT_ENCODED ;@@ -2007,17 +1992,17 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, goto prep_next; } -if (map_bh.b_blocknr ==COMPRESS_ADDR ) { +if (map.m_pblk ==COMPRESS_ADDR ) { compr_cluster = true; start_blk++; goto prep_next; } logical =blks_to_bytes (inode, start_blk); - phys =blks_to_bytes (inode, map_bh.b_blocknr); - size = map_bh.b_size; + phys =blks_to_bytes (inode, map.m_pblk); + size =blks_to_bytes (inode, map.m_len); flags =0 ; -if (buffer_unwritten (&map_bh)) +if (map.m_flags &F2FS_MAP_UNWRITTEN ) flags =FIEMAP_EXTENT_UNWRITTEN ; start_blk +=bytes_to_blks (inode, size);@@ -3797,9 +3782,6 @@ static sector_t f2fs_bmap_compress(struct inode *inode, sector_t block)static sector_t f2fs_bmap (struct address_space *mapping,sector_t block) {struct inode *inode = mapping->host; -struct buffer_head tmp = { - .b_size =i_blocksize (inode), - };sector_t blknr =0 ;if (f2fs_has_inline_data (inode))@@ -3816,8 +3798,16 @@ static sector_t f2fs_bmap(struct address_space *mapping, sector_t block)if (f2fs_compressed_file (inode)) { blknr =f2fs_bmap_compress (inode, block); }else { -if (!get_data_block_bmap (inode, block, &tmp,0 )) - blknr = tmp.b_blocknr; +struct f2fs_map_blocks map; + +memset (&map,0 ,sizeof (map)); + map.m_lblk = block; + map.m_len =1 ; + map.m_next_pgofs =NULL ; + map.m_seg_type =NO_CHECK_TYPE ; + +if (!f2fs_map_blocks (inode, &map,0 ,F2FS_GET_BLOCK_BMAP )) + blknr = map.m_pblk; } out:trace_f2fs_bmap (inode, block, blknr);@@ -3905,25 +3895,27 @@ static int check_swap_activate_fast(struct swap_info_struct *sis, len =i_size_read (inode);while (cur_lblock <= last_lblock && cur_lblock < sis->max) { -struct buffer_head map_bh; +struct f2fs_map_blocks map;pgoff_t next_pgofs;cond_resched (); -memset (&map_bh,0 ,sizeof (struct buffer_head )); - map_bh.b_size = len -blks_to_bytes (inode, cur_lblock); +memset (&map,0 ,sizeof (map)); + map.m_lblk = cur_lblock; + map.m_len =bytes_to_blks (inode, len) - cur_lblock; + map.m_next_pgofs = &next_pgofs; + map.m_seg_type =NO_CHECK_TYPE ; - ret =get_data_block (inode, cur_lblock, &map_bh,0 , -F2FS_GET_BLOCK_FIEMAP , &next_pgofs); + ret =f2fs_map_blocks (inode, &map,0 ,F2FS_GET_BLOCK_FIEMAP );if (ret) goto err_out;/* hole */ -if (!buffer_mapped (&map_bh)) +if (!(map.m_flags &F2FS_MAP_FLAGS )) goto err_out; - pblock = map_bh.b_blocknr; - nr_pblocks =bytes_to_blks (inode, map_bh.b_size); + pblock = map.m_pblk; + nr_pblocks = map.m_len;if (cur_lblock + nr_pblocks >= sis->max) nr_pblocks = sis->max - cur_lblock;Signature · 1 line
2.29.2.454.gaff20da3a2-goog
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Chao Yu
Reviewed-byRe: [f2fs-dev] [PATCH 4/4] f2fs: remove buffer_head which has 32bits limit
Quoted 8 lines · Jaegeuk Kim
Quoted 7 lines · Jaegeuk Kim
This patch removes
buffer_headdependency when getting block addresses. Light reported there's a 32bit issue inf2fs_fiemapwhere map_bh.b_size is 32bits while len is 64bits given by user. This will give wrong length tof2fs_map_block.Reported-by Light Hsieh <[email protected]>Signed-off-by Jaegeuk Kim <[email protected]>
Thanks,
Jaegeuk Kim
maintainerForgot to add f2fs mailing list.
Quoted 134 lines · Jaegeuk Kim
This patch renames two functions like below having u64.
-logical_to_blktobytes_to_blks
-blk_to_logicaltoblks_to_bytesSigned-off-by Jaegeuk Kim <[email protected]>--- fs/f2fs/data.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-)fs/f2fs/data.c +20
-20@@ -1808,14 +1808,14 @@ static int get_data_block_bmap(struct inode *inode, sector_t iblock, NO_CHECK_TYPE, create); } -static inline sector_t logical_to_blk (struct inode *inode,loff_t offset) +static inline u64 bytes_to_blks (struct inode *inode,u64 bytes) { -return (offset >> inode->i_blkbits); +return (bytes >> inode->i_blkbits); } -static inline loff_t blk_to_logical (struct inode *inode,sector_t blk) +static inline u64 blks_to_bytes (struct inode *inode,u64 blks) { -return (blk << inode->i_blkbits); +return (blks << inode->i_blkbits); } static int f2fs_xattr_fiemap(struct inode *inode,@@ -1843,7 +1843,7 @@ static int f2fs_xattr_fiemap(struct inode *inode,return err; } - phys = (__u64 )blk_to_logical (inode, ni.blk_addr); + phys =blks_to_bytes (inode, ni.blk_addr); offset = offsetof(struct f2fs_inode , i_addr) +sizeof (__le32) * (DEF_ADDRS_PER_INODE -get_inline_xattr_addrs (inode));@@ -1875,7 +1875,7 @@ static int f2fs_xattr_fiemap(struct inode *inode,return err; } - phys = (__u64 )blk_to_logical (inode, ni.blk_addr); + phys =blks_to_bytes (inode, ni.blk_addr); len = inode->i_sb->s_blocksize;f2fs_put_page (page,1 );@@ -1945,18 +1945,18 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, goto out; } -if (logical_to_blk (inode, len) ==0 ) - len =blk_to_logical (inode,1 ); +if (bytes_to_blks (inode, len) ==0 ) + len =blks_to_bytes (inode,1 ); - start_blk =logical_to_blk (inode, start); - last_blk =logical_to_blk (inode, start + len -1 ); + start_blk =bytes_to_blks (inode, start); + last_blk =bytes_to_blks (inode, start + len -1 ); next:memset (&map_bh,0 ,sizeof (struct buffer_head )); map_bh.b_size = len;if (compr_cluster) - map_bh.b_size =blk_to_logical (inode, cluster_size -1 ); + map_bh.b_size =blks_to_bytes (inode, cluster_size -1 ); ret =get_data_block (inode, start_blk, &map_bh,0 ,F2FS_GET_BLOCK_FIEMAP , &next_pgofs);@@ -1967,7 +1967,7 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,if (!buffer_mapped (&map_bh)) { start_blk = next_pgofs; -if (blk_to_logical (inode, start_blk) <blk_to_logical (inode, +if (blks_to_bytes (inode, start_blk) <blks_to_bytes (inode,max_inode_blocks (inode))) goto prep_next;@@ -1993,9 +1993,9 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, compr_cluster = false; - logical =blk_to_logical (inode, start_blk -1 ); - phys =blk_to_logical (inode, map_bh.b_blocknr); - size =blk_to_logical (inode, cluster_size); + logical =blks_to_bytes (inode, start_blk -1 ); + phys =blks_to_bytes (inode, map_bh.b_blocknr); + size =blks_to_bytes (inode, cluster_size); flags |=FIEMAP_EXTENT_ENCODED ;@@ -2013,14 +2013,14 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, goto prep_next; } - logical =blk_to_logical (inode, start_blk); - phys =blk_to_logical (inode, map_bh.b_blocknr); + logical =blks_to_bytes (inode, start_blk); + phys =blks_to_bytes (inode, map_bh.b_blocknr); size = map_bh.b_size; flags =0 ;if (buffer_unwritten (&map_bh)) flags =FIEMAP_EXTENT_UNWRITTEN ; - start_blk +=logical_to_blk (inode, size); + start_blk +=bytes_to_blks (inode, size); prep_next:cond_resched ();@@ -3903,7 +3903,7 @@ static int check_swap_activate_fast(struct swap_info_struct *sis,* to be very smart. */ cur_lblock =0 ; - last_lblock =logical_to_blk (inode,i_size_read (inode)); + last_lblock =bytes_to_blks (inode,i_size_read (inode)); len =i_size_read (inode);while (cur_lblock <= last_lblock && cur_lblock < sis->max) {@@ -3925,7 +3925,7 @@ static int check_swap_activate_fast(struct swap_info_struct *sis, goto err_out; pblock = map_bh.b_blocknr; - nr_pblocks =logical_to_blk (inode, map_bh.b_size); + nr_pblocks =bytes_to_blks (inode, map_bh.b_size);if (cur_lblock + nr_pblocks >= sis->max) nr_pblocks = sis->max - cur_lblock;Signature · 1 line
2.29.2.454.gaff20da3a2-goog
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Chao Yu
Reviewed-byQuoted 8 lines · Jaegeuk Kim
Forgot to add f2fs mailing list.
Quoted 5 lines · Jaegeuk Kim
This patch renames two functions like below having u64.
-logical_to_blktobytes_to_blks
-blk_to_logicaltoblks_to_bytesSigned-off-by Jaegeuk Kim <[email protected]>
Thanks,
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel