Skip to content

Commit 3fcc2b8

Browse files
zhangyi089tytso
authored andcommitted
ext4: refactor ext4_da_map_blocks()
Refactor and cleanup ext4_da_map_blocks(), reduce some unnecessary parameters and branches, no logic changes. Signed-off-by: Zhang Yi <yi.zhang@huawei.com> Reviewed-by: Jan Kara <jack@suse.cz> Link: https://lore.kernel.org/r/20240127015825.1608160-2-yi.zhang@huaweicloud.com Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent f0e54b6 commit 3fcc2b8

File tree

1 file changed

+17
-22
lines changed

1 file changed

+17
-22
lines changed

fs/ext4/inode.c

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1704,7 +1704,6 @@ static int ext4_da_map_blocks(struct inode *inode, sector_t iblock,
17041704
/* Lookup extent status tree firstly */
17051705
if (ext4_es_lookup_extent(inode, iblock, NULL, &es)) {
17061706
if (ext4_es_is_hole(&es)) {
1707-
retval = 0;
17081707
down_read(&EXT4_I(inode)->i_data_sem);
17091708
goto add_delayed;
17101709
}
@@ -1749,26 +1748,9 @@ static int ext4_da_map_blocks(struct inode *inode, sector_t iblock,
17491748
retval = ext4_ext_map_blocks(NULL, inode, map, 0);
17501749
else
17511750
retval = ext4_ind_map_blocks(NULL, inode, map, 0);
1752-
1753-
add_delayed:
1754-
if (retval == 0) {
1755-
int ret;
1756-
1757-
/*
1758-
* XXX: __block_prepare_write() unmaps passed block,
1759-
* is it OK?
1760-
*/
1761-
1762-
ret = ext4_insert_delayed_block(inode, map->m_lblk);
1763-
if (ret != 0) {
1764-
retval = ret;
1765-
goto out_unlock;
1766-
}
1767-
1768-
map_bh(bh, inode->i_sb, invalid_block);
1769-
set_buffer_new(bh);
1770-
set_buffer_delay(bh);
1771-
} else if (retval > 0) {
1751+
if (retval < 0)
1752+
goto out_unlock;
1753+
if (retval > 0) {
17721754
unsigned int status;
17731755

17741756
if (unlikely(retval != map->m_len)) {
@@ -1783,11 +1765,24 @@ static int ext4_da_map_blocks(struct inode *inode, sector_t iblock,
17831765
EXTENT_STATUS_UNWRITTEN : EXTENT_STATUS_WRITTEN;
17841766
ext4_es_insert_extent(inode, map->m_lblk, map->m_len,
17851767
map->m_pblk, status);
1768+
goto out_unlock;
17861769
}
17871770

1771+
add_delayed:
1772+
/*
1773+
* XXX: __block_prepare_write() unmaps passed block,
1774+
* is it OK?
1775+
*/
1776+
retval = ext4_insert_delayed_block(inode, map->m_lblk);
1777+
if (retval)
1778+
goto out_unlock;
1779+
1780+
map_bh(bh, inode->i_sb, invalid_block);
1781+
set_buffer_new(bh);
1782+
set_buffer_delay(bh);
1783+
17881784
out_unlock:
17891785
up_read((&EXT4_I(inode)->i_data_sem));
1790-
17911786
return retval;
17921787
}
17931788

0 commit comments

Comments
 (0)