Skip to content

Commit 8e4e5cd

Browse files
zhangyi089tytso
authored andcommitted
ext4: factor out a common helper to query extent map
Factor out a new common helper ext4_map_query_blocks() from the ext4_da_map_blocks(), it query and return the extent map status on the inode's extent path, no logic changes. Signed-off-by: Zhang Yi <[email protected]> Reviewed-by: Jan Kara <[email protected]> Reviewed-by: Ritesh Harjani (IBM) <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent 907c3fe commit 8e4e5cd

File tree

1 file changed

+32
-25
lines changed

1 file changed

+32
-25
lines changed

fs/ext4/inode.c

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,35 @@ static void ext4_map_blocks_es_recheck(handle_t *handle,
453453
}
454454
#endif /* ES_AGGRESSIVE_TEST */
455455

456+
static int ext4_map_query_blocks(handle_t *handle, struct inode *inode,
457+
struct ext4_map_blocks *map)
458+
{
459+
unsigned int status;
460+
int retval;
461+
462+
if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))
463+
retval = ext4_ext_map_blocks(handle, inode, map, 0);
464+
else
465+
retval = ext4_ind_map_blocks(handle, inode, map, 0);
466+
467+
if (retval <= 0)
468+
return retval;
469+
470+
if (unlikely(retval != map->m_len)) {
471+
ext4_warning(inode->i_sb,
472+
"ES len assertion failed for inode "
473+
"%lu: retval %d != map->m_len %d",
474+
inode->i_ino, retval, map->m_len);
475+
WARN_ON(1);
476+
}
477+
478+
status = map->m_flags & EXT4_MAP_UNWRITTEN ?
479+
EXTENT_STATUS_UNWRITTEN : EXTENT_STATUS_WRITTEN;
480+
ext4_es_insert_extent(inode, map->m_lblk, map->m_len,
481+
map->m_pblk, status);
482+
return retval;
483+
}
484+
456485
/*
457486
* The ext4_map_blocks() function tries to look up the requested blocks,
458487
* and returns if the blocks are already mapped.
@@ -1744,33 +1773,11 @@ static int ext4_da_map_blocks(struct inode *inode, sector_t iblock,
17441773
down_read(&EXT4_I(inode)->i_data_sem);
17451774
if (ext4_has_inline_data(inode))
17461775
retval = 0;
1747-
else if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))
1748-
retval = ext4_ext_map_blocks(NULL, inode, map, 0);
17491776
else
1750-
retval = ext4_ind_map_blocks(NULL, inode, map, 0);
1751-
if (retval < 0) {
1752-
up_read(&EXT4_I(inode)->i_data_sem);
1753-
return retval;
1754-
}
1755-
if (retval > 0) {
1756-
unsigned int status;
1757-
1758-
if (unlikely(retval != map->m_len)) {
1759-
ext4_warning(inode->i_sb,
1760-
"ES len assertion failed for inode "
1761-
"%lu: retval %d != map->m_len %d",
1762-
inode->i_ino, retval, map->m_len);
1763-
WARN_ON(1);
1764-
}
1765-
1766-
status = map->m_flags & EXT4_MAP_UNWRITTEN ?
1767-
EXTENT_STATUS_UNWRITTEN : EXTENT_STATUS_WRITTEN;
1768-
ext4_es_insert_extent(inode, map->m_lblk, map->m_len,
1769-
map->m_pblk, status);
1770-
up_read(&EXT4_I(inode)->i_data_sem);
1771-
return retval;
1772-
}
1777+
retval = ext4_map_query_blocks(NULL, inode, map);
17731778
up_read(&EXT4_I(inode)->i_data_sem);
1779+
if (retval)
1780+
return retval;
17741781

17751782
add_delayed:
17761783
down_write(&EXT4_I(inode)->i_data_sem);

0 commit comments

Comments
 (0)