aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJaegeuk Kim2020-11-24 17:04:27 -0600
committerJaegeuk Kim2020-12-21 15:33:15 -0600
commit366d9ab986603ebdb56958775ad6bd0afc40d25c (patch)
tree78264837692979f727b71cde936037733cf8c8d2
parent1c870991f58ef0620112e6510fb8025b1f58a656 (diff)
downloadkernel-366d9ab986603ebdb56958775ad6bd0afc40d25c.tar.gz
kernel-366d9ab986603ebdb56958775ad6bd0afc40d25c.tar.xz
kernel-366d9ab986603ebdb56958775ad6bd0afc40d25c.zip
f2fs: use new conversion functions between blks and bytes
This patch cleans up blks and bytes conversions. Reviewed-by: Chao Yu <yuchao0@huawei.com> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
-rw-r--r--fs/f2fs/data.c46
1 files changed, 21 insertions, 25 deletions
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index a8612c6f40ab..a84e5bc09337 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -1750,6 +1750,16 @@ bool f2fs_overwrite_io(struct inode *inode, loff_t pos, size_t len)
1750 return true; 1750 return true;
1751} 1751}
1752 1752
1753static inline u64 bytes_to_blks(struct inode *inode, u64 bytes)
1754{
1755 return (bytes >> inode->i_blkbits);
1756}
1757
1758static inline u64 blks_to_bytes(struct inode *inode, u64 blks)
1759{
1760 return (blks << inode->i_blkbits);
1761}
1762
1753static int __get_data_block(struct inode *inode, sector_t iblock, 1763static int __get_data_block(struct inode *inode, sector_t iblock,
1754 struct buffer_head *bh, int create, int flag, 1764 struct buffer_head *bh, int create, int flag,
1755 pgoff_t *next_pgofs, int seg_type, bool may_write) 1765 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,
1758 int err; 1768 int err;
1759 1769
1760 map.m_lblk = iblock; 1770 map.m_lblk = iblock;
1761 map.m_len = bh->b_size >> inode->i_blkbits; 1771 map.m_len = bytes_to_blks(inode, bh->b_size);
1762 map.m_next_pgofs = next_pgofs; 1772 map.m_next_pgofs = next_pgofs;
1763 map.m_next_extent = NULL; 1773 map.m_next_extent = NULL;
1764 map.m_seg_type = seg_type; 1774 map.m_seg_type = seg_type;
@@ -1768,7 +1778,7 @@ static int __get_data_block(struct inode *inode, sector_t iblock,
1768 if (!err) { 1778 if (!err) {
1769 map_bh(bh, inode->i_sb, map.m_pblk); 1779 map_bh(bh, inode->i_sb, map.m_pblk);
1770 bh->b_state = (bh->b_state & ~F2FS_MAP_FLAGS) | map.m_flags; 1780 bh->b_state = (bh->b_state & ~F2FS_MAP_FLAGS) | map.m_flags;
1771 bh->b_size = (u64)map.m_len << inode->i_blkbits; 1781 bh->b_size = blks_to_bytes(inode, map.m_len);
1772 } 1782 }
1773 return err; 1783 return err;
1774} 1784}
@@ -1808,16 +1818,6 @@ static int get_data_block_bmap(struct inode *inode, sector_t iblock,
1808 NO_CHECK_TYPE, create); 1818 NO_CHECK_TYPE, create);
1809} 1819}
1810 1820
1811static inline u64 bytes_to_blks(struct inode *inode, u64 bytes)
1812{
1813 return (bytes >> inode->i_blkbits);
1814}
1815
1816static inline u64 blks_to_bytes(struct inode *inode, u64 blks)
1817{
1818 return (blks << inode->i_blkbits);
1819}
1820
1821static int f2fs_xattr_fiemap(struct inode *inode, 1821static int f2fs_xattr_fiemap(struct inode *inode,
1822 struct fiemap_extent_info *fieinfo) 1822 struct fiemap_extent_info *fieinfo)
1823{ 1823{
@@ -2053,8 +2053,7 @@ static int f2fs_read_single_page(struct inode *inode, struct page *page,
2053 bool is_readahead) 2053 bool is_readahead)
2054{ 2054{
2055 struct bio *bio = *bio_ret; 2055 struct bio *bio = *bio_ret;
2056 const unsigned blkbits = inode->i_blkbits; 2056 const unsigned blocksize = blks_to_bytes(inode, 1);
2057 const unsigned blocksize = 1 << blkbits;
2058 sector_t block_in_file; 2057 sector_t block_in_file;
2059 sector_t last_block; 2058 sector_t last_block;
2060 sector_t last_block_in_file; 2059 sector_t last_block_in_file;
@@ -2063,8 +2062,8 @@ static int f2fs_read_single_page(struct inode *inode, struct page *page,
2063 2062
2064 block_in_file = (sector_t)page_index(page); 2063 block_in_file = (sector_t)page_index(page);
2065 last_block = block_in_file + nr_pages; 2064 last_block = block_in_file + nr_pages;
2066 last_block_in_file = (f2fs_readpage_limit(inode) + blocksize - 1) >> 2065 last_block_in_file = bytes_to_blks(inode,
2067 blkbits; 2066 f2fs_readpage_limit(inode) + blocksize - 1);
2068 if (last_block > last_block_in_file) 2067 if (last_block > last_block_in_file)
2069 last_block = last_block_in_file; 2068 last_block = last_block_in_file;
2070 2069
@@ -2177,16 +2176,15 @@ int f2fs_read_multi_pages(struct compress_ctx *cc, struct bio **bio_ret,
2177 struct bio *bio = *bio_ret; 2176 struct bio *bio = *bio_ret;
2178 unsigned int start_idx = cc->cluster_idx << cc->log_cluster_size; 2177 unsigned int start_idx = cc->cluster_idx << cc->log_cluster_size;
2179 sector_t last_block_in_file; 2178 sector_t last_block_in_file;
2180 const unsigned blkbits = inode->i_blkbits; 2179 const unsigned blocksize = blks_to_bytes(inode, 1);
2181 const unsigned blocksize = 1 << blkbits;
2182 struct decompress_io_ctx *dic = NULL; 2180 struct decompress_io_ctx *dic = NULL;
2183 int i; 2181 int i;
2184 int ret = 0; 2182 int ret = 0;
2185 2183
2186 f2fs_bug_on(sbi, f2fs_cluster_is_empty(cc)); 2184 f2fs_bug_on(sbi, f2fs_cluster_is_empty(cc));
2187 2185
2188 last_block_in_file = (f2fs_readpage_limit(inode) + 2186 last_block_in_file = bytes_to_blks(inode,
2189 blocksize - 1) >> blkbits; 2187 f2fs_readpage_limit(inode) + blocksize - 1);
2190 2188
2191 /* get rid of pages beyond EOF */ 2189 /* get rid of pages beyond EOF */
2192 for (i = 0; i < cc->cluster_size; i++) { 2190 for (i = 0; i < cc->cluster_size; i++) {
@@ -3968,7 +3966,6 @@ static int check_swap_activate(struct swap_info_struct *sis,
3968 struct inode *inode = mapping->host; 3966 struct inode *inode = mapping->host;
3969 unsigned blocks_per_page; 3967 unsigned blocks_per_page;
3970 unsigned long page_no; 3968 unsigned long page_no;
3971 unsigned blkbits;
3972 sector_t probe_block; 3969 sector_t probe_block;
3973 sector_t last_block; 3970 sector_t last_block;
3974 sector_t lowest_block = -1; 3971 sector_t lowest_block = -1;
@@ -3979,8 +3976,7 @@ static int check_swap_activate(struct swap_info_struct *sis,
3979 if (PAGE_SIZE == F2FS_BLKSIZE) 3976 if (PAGE_SIZE == F2FS_BLKSIZE)
3980 return check_swap_activate_fast(sis, swap_file, span); 3977 return check_swap_activate_fast(sis, swap_file, span);
3981 3978
3982 blkbits = inode->i_blkbits; 3979 blocks_per_page = bytes_to_blks(inode, PAGE_SIZE);
3983 blocks_per_page = PAGE_SIZE >> blkbits;
3984 3980
3985 /* 3981 /*
3986 * Map all the blocks into the extent list. This code doesn't try 3982 * 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,
3988 */ 3984 */
3989 probe_block = 0; 3985 probe_block = 0;
3990 page_no = 0; 3986 page_no = 0;
3991 last_block = i_size_read(inode) >> blkbits; 3987 last_block = bytes_to_blks(inode, i_size_read(inode));
3992 while ((probe_block + blocks_per_page) <= last_block && 3988 while ((probe_block + blocks_per_page) <= last_block &&
3993 page_no < sis->max) { 3989 page_no < sis->max) {
3994 unsigned block_in_page; 3990 unsigned block_in_page;
@@ -4028,7 +4024,7 @@ static int check_swap_activate(struct swap_info_struct *sis,
4028 } 4024 }
4029 } 4025 }
4030 4026
4031 first_block >>= (PAGE_SHIFT - blkbits); 4027 first_block >>= (PAGE_SHIFT - inode->i_blkbits);
4032 if (page_no) { /* exclude the header page */ 4028 if (page_no) { /* exclude the header page */
4033 if (first_block < lowest_block) 4029 if (first_block < lowest_block)
4034 lowest_block = first_block; 4030 lowest_block = first_block;