Skip to content

Commit 49bf6ab

Browse files
zhangyi089tytso
authored andcommitted
ext4: factor out a helper to check the cluster allocation state
Factor out a common helper ext4_clu_alloc_state(), check whether the cluster containing a delalloc block to be added has been allocated or has delalloc reservation, no logic changes. Signed-off-by: Zhang Yi <[email protected]> Reviewed-by: Jan Kara <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent 0d66b23 commit 49bf6ab

File tree

1 file changed

+38
-17
lines changed

1 file changed

+38
-17
lines changed

fs/ext4/inode.c

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,6 +1649,35 @@ static void ext4_print_free_blocks(struct inode *inode)
16491649
return;
16501650
}
16511651

1652+
/*
1653+
* Check whether the cluster containing lblk has been allocated or has
1654+
* delalloc reservation.
1655+
*
1656+
* Returns 0 if the cluster doesn't have either, 1 if it has delalloc
1657+
* reservation, 2 if it's already been allocated, negative error code on
1658+
* failure.
1659+
*/
1660+
static int ext4_clu_alloc_state(struct inode *inode, ext4_lblk_t lblk)
1661+
{
1662+
struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
1663+
int ret;
1664+
1665+
/* Has delalloc reservation? */
1666+
if (ext4_es_scan_clu(inode, &ext4_es_is_delonly, lblk))
1667+
return 1;
1668+
1669+
/* Already been allocated? */
1670+
if (ext4_es_scan_clu(inode, &ext4_es_is_mapped, lblk))
1671+
return 2;
1672+
ret = ext4_clu_mapped(inode, EXT4_B2C(sbi, lblk));
1673+
if (ret < 0)
1674+
return ret;
1675+
if (ret > 0)
1676+
return 2;
1677+
1678+
return 0;
1679+
}
1680+
16521681
/*
16531682
* ext4_insert_delayed_block - adds a delayed block to the extents status
16541683
* tree, incrementing the reserved cluster/block
@@ -1682,23 +1711,15 @@ static int ext4_insert_delayed_block(struct inode *inode, ext4_lblk_t lblk)
16821711
if (ret != 0) /* ENOSPC */
16831712
return ret;
16841713
} else { /* bigalloc */
1685-
if (!ext4_es_scan_clu(inode, &ext4_es_is_delonly, lblk)) {
1686-
if (!ext4_es_scan_clu(inode,
1687-
&ext4_es_is_mapped, lblk)) {
1688-
ret = ext4_clu_mapped(inode,
1689-
EXT4_B2C(sbi, lblk));
1690-
if (ret < 0)
1691-
return ret;
1692-
if (ret == 0) {
1693-
ret = ext4_da_reserve_space(inode, 1);
1694-
if (ret != 0) /* ENOSPC */
1695-
return ret;
1696-
} else {
1697-
allocated = true;
1698-
}
1699-
} else {
1700-
allocated = true;
1701-
}
1714+
ret = ext4_clu_alloc_state(inode, lblk);
1715+
if (ret < 0)
1716+
return ret;
1717+
if (ret == 2)
1718+
allocated = true;
1719+
if (ret == 0) {
1720+
ret = ext4_da_reserve_space(inode, 1);
1721+
if (ret != 0) /* ENOSPC */
1722+
return ret;
17021723
}
17031724
}
17041725

0 commit comments

Comments
 (0)