Skip to content

Commit 125d1f6

Browse files
LiBaokun96tytso
authored andcommitted
ext4: add EXT4_LBLK_TO_B macro for logical block to bytes conversion
No functional changes. Signed-off-by: Baokun Li <libaokun1@huawei.com> Reviewed-by: Zhang Yi <yi.zhang@huawei.com> Reviewed-by: Jan Kara <jack@suse.cz> Reviewed-by: Ojaswin Mujoo <ojaswin@linux.ibm.com> Message-ID: <20251121090654.631996-10-libaokun@huaweicloud.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent 609c5e0 commit 125d1f6

5 files changed

Lines changed: 15 additions & 18 deletions

File tree

fs/ext4/ext4.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ struct ext4_io_submit {
368368
blkbits))
369369
#define EXT4_B_TO_LBLK(inode, offset) \
370370
(round_up((offset), i_blocksize(inode)) >> (inode)->i_blkbits)
371+
#define EXT4_LBLK_TO_B(inode, lblk) ((loff_t)(lblk) << (inode)->i_blkbits)
371372

372373
/* Translate a block number to a cluster number */
373374
#define EXT4_B2C(sbi, blk) ((blk) >> (sbi)->s_cluster_bits)

fs/ext4/extents.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4562,7 +4562,7 @@ static int ext4_alloc_file_blocks(struct file *file, ext4_lblk_t offset,
45624562
* allow a full retry cycle for any remaining allocations
45634563
*/
45644564
retries = 0;
4565-
epos = (loff_t)(map.m_lblk + ret) << blkbits;
4565+
epos = EXT4_LBLK_TO_B(inode, map.m_lblk + ret);
45664566
inode_set_ctime_current(inode);
45674567
if (new_size) {
45684568
if (epos > new_size)

fs/ext4/inode.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -837,9 +837,8 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode,
837837
!(flags & EXT4_GET_BLOCKS_ZERO) &&
838838
!ext4_is_quota_file(inode) &&
839839
ext4_should_order_data(inode)) {
840-
loff_t start_byte =
841-
(loff_t)map->m_lblk << inode->i_blkbits;
842-
loff_t length = (loff_t)map->m_len << inode->i_blkbits;
840+
loff_t start_byte = EXT4_LBLK_TO_B(inode, map->m_lblk);
841+
loff_t length = EXT4_LBLK_TO_B(inode, map->m_len);
843842

844843
if (flags & EXT4_GET_BLOCKS_IO_SUBMIT)
845844
ret = ext4_jbd2_inode_add_wait(handle, inode,
@@ -2235,7 +2234,6 @@ static int mpage_process_folio(struct mpage_da_data *mpd, struct folio *folio,
22352234
ext4_lblk_t lblk = *m_lblk;
22362235
ext4_fsblk_t pblock = *m_pblk;
22372236
int err = 0;
2238-
int blkbits = mpd->inode->i_blkbits;
22392237
ssize_t io_end_size = 0;
22402238
struct ext4_io_end_vec *io_end_vec = ext4_last_io_end_vec(io_end);
22412239

@@ -2261,7 +2259,8 @@ static int mpage_process_folio(struct mpage_da_data *mpd, struct folio *folio,
22612259
err = PTR_ERR(io_end_vec);
22622260
goto out;
22632261
}
2264-
io_end_vec->offset = (loff_t)mpd->map.m_lblk << blkbits;
2262+
io_end_vec->offset = EXT4_LBLK_TO_B(mpd->inode,
2263+
mpd->map.m_lblk);
22652264
}
22662265
*map_bh = true;
22672266
goto out;
@@ -2271,7 +2270,7 @@ static int mpage_process_folio(struct mpage_da_data *mpd, struct folio *folio,
22712270
bh->b_blocknr = pblock++;
22722271
}
22732272
clear_buffer_unwritten(bh);
2274-
io_end_size += (1 << blkbits);
2273+
io_end_size += i_blocksize(mpd->inode);
22752274
} while (lblk++, (bh = bh->b_this_page) != head);
22762275

22772276
io_end_vec->size += io_end_size;
@@ -2473,7 +2472,7 @@ static int mpage_map_and_submit_extent(handle_t *handle,
24732472
io_end_vec = ext4_alloc_io_end_vec(io_end);
24742473
if (IS_ERR(io_end_vec))
24752474
return PTR_ERR(io_end_vec);
2476-
io_end_vec->offset = ((loff_t)map->m_lblk) << inode->i_blkbits;
2475+
io_end_vec->offset = EXT4_LBLK_TO_B(inode, map->m_lblk);
24772476
do {
24782477
err = mpage_map_one_extent(handle, mpd);
24792478
if (err < 0) {
@@ -3513,8 +3512,8 @@ static void ext4_set_iomap(struct inode *inode, struct iomap *iomap,
35133512
iomap->dax_dev = EXT4_SB(inode->i_sb)->s_daxdev;
35143513
else
35153514
iomap->bdev = inode->i_sb->s_bdev;
3516-
iomap->offset = (u64) map->m_lblk << blkbits;
3517-
iomap->length = (u64) map->m_len << blkbits;
3515+
iomap->offset = EXT4_LBLK_TO_B(inode, map->m_lblk);
3516+
iomap->length = EXT4_LBLK_TO_B(inode, map->m_len);
35183517

35193518
if ((map->m_flags & EXT4_MAP_MAPPED) &&
35203519
!ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))
@@ -3688,7 +3687,6 @@ static int ext4_iomap_alloc(struct inode *inode, struct ext4_map_blocks *map,
36883687
unsigned int flags)
36893688
{
36903689
handle_t *handle;
3691-
u8 blkbits = inode->i_blkbits;
36923690
int ret, dio_credits, m_flags = 0, retries = 0;
36933691
bool force_commit = false;
36943692

@@ -3747,7 +3745,7 @@ static int ext4_iomap_alloc(struct inode *inode, struct ext4_map_blocks *map,
37473745
* i_disksize out to i_size. This could be beyond where direct I/O is
37483746
* happening and thus expose allocated blocks to direct I/O reads.
37493747
*/
3750-
else if (((loff_t)map->m_lblk << blkbits) >= i_size_read(inode))
3748+
else if (EXT4_LBLK_TO_B(inode, map->m_lblk) >= i_size_read(inode))
37513749
m_flags = EXT4_GET_BLOCKS_CREATE;
37523750
else if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))
37533751
m_flags = EXT4_GET_BLOCKS_IO_CREATE_EXT;

fs/ext4/namei.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,7 +1076,7 @@ static int htree_dirblock_to_tree(struct file *dir_file,
10761076
for (; de < top; de = ext4_next_entry(de, dir->i_sb->s_blocksize)) {
10771077
if (ext4_check_dir_entry(dir, NULL, de, bh,
10781078
bh->b_data, bh->b_size,
1079-
(block<<EXT4_BLOCK_SIZE_BITS(dir->i_sb))
1079+
EXT4_LBLK_TO_B(dir, block)
10801080
+ ((char *)de - bh->b_data))) {
10811081
/* silently ignore the rest of the block */
10821082
break;
@@ -1630,7 +1630,7 @@ static struct buffer_head *__ext4_find_entry(struct inode *dir,
16301630
}
16311631
set_buffer_verified(bh);
16321632
i = search_dirblock(bh, dir, fname,
1633-
block << EXT4_BLOCK_SIZE_BITS(sb), res_dir);
1633+
EXT4_LBLK_TO_B(dir, block), res_dir);
16341634
if (i == 1) {
16351635
EXT4_I(dir)->i_dir_start_lookup = block;
16361636
ret = bh;
@@ -1710,7 +1710,6 @@ static struct buffer_head * ext4_dx_find_entry(struct inode *dir,
17101710
struct ext4_filename *fname,
17111711
struct ext4_dir_entry_2 **res_dir)
17121712
{
1713-
struct super_block * sb = dir->i_sb;
17141713
struct dx_frame frames[EXT4_HTREE_LEVEL], *frame;
17151714
struct buffer_head *bh;
17161715
ext4_lblk_t block;
@@ -1729,8 +1728,7 @@ static struct buffer_head * ext4_dx_find_entry(struct inode *dir,
17291728
goto errout;
17301729

17311730
retval = search_dirblock(bh, dir, fname,
1732-
block << EXT4_BLOCK_SIZE_BITS(sb),
1733-
res_dir);
1731+
EXT4_LBLK_TO_B(dir, block), res_dir);
17341732
if (retval == 1)
17351733
goto success;
17361734
brelse(bh);

fs/ext4/verity.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ static int ext4_get_verity_descriptor_location(struct inode *inode,
302302

303303
end_lblk = le32_to_cpu(last_extent->ee_block) +
304304
ext4_ext_get_actual_len(last_extent);
305-
desc_size_pos = (u64)end_lblk << inode->i_blkbits;
305+
desc_size_pos = EXT4_LBLK_TO_B(inode, end_lblk);
306306
ext4_free_ext_path(path);
307307

308308
if (desc_size_pos < sizeof(desc_size_disk))

0 commit comments

Comments
 (0)