Skip to content

Commit 3499046

Browse files
Eric Whitneytytso
authored andcommitted
ext4: clean up ext4_ext_insert_extent() call in ext4_ext_map_blocks()
Now that the eofblocks code has been removed, we don't need to assign 0 to err before calling ext4_ext_insert_extent() since it will assign a return value to ret anyway. The variable free_on_err can be eliminated and replaced by a reference to allocated_clusters which clearly conveys the idea that newly allocated blocks should be freed when recovering from an extent insertion failure. The error handling code itself should be restructured so that it errors out immediately on an insertion failure in the case where no new blocks have been allocated (bigalloc) rather than proceeding further into the mapping code. The initializer for fb_flags can also be rearranged for improved readability. Finally, insert a missing space in nearby code. No known bugs are addressed by this patch - it's simply a cleanup. Reviewed-by: Ritesh Harjani <[email protected]> Signed-off-by: Eric Whitney <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent eb57608 commit 3499046

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

fs/ext4/extents.c

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4028,7 +4028,7 @@ int ext4_ext_map_blocks(handle_t *handle, struct inode *inode,
40284028
struct ext4_extent newex, *ex, *ex2;
40294029
struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
40304030
ext4_fsblk_t newblock = 0;
4031-
int free_on_err = 0, err = 0, depth, ret;
4031+
int err = 0, depth, ret;
40324032
unsigned int allocated = 0, offset = 0;
40334033
unsigned int allocated_clusters = 0;
40344034
struct ext4_allocation_request ar;
@@ -4226,7 +4226,6 @@ int ext4_ext_map_blocks(handle_t *handle, struct inode *inode,
42264226
goto out2;
42274227
ext_debug("allocate new block: goal %llu, found %llu/%u\n",
42284228
ar.goal, newblock, allocated);
4229-
free_on_err = 1;
42304229
allocated_clusters = ar.len;
42314230
ar.len = EXT4_C2B(sbi, ar.len) - offset;
42324231
if (ar.len > allocated)
@@ -4237,23 +4236,28 @@ int ext4_ext_map_blocks(handle_t *handle, struct inode *inode,
42374236
ext4_ext_store_pblock(&newex, newblock + offset);
42384237
newex.ee_len = cpu_to_le16(ar.len);
42394238
/* Mark unwritten */
4240-
if (flags & EXT4_GET_BLOCKS_UNWRIT_EXT){
4239+
if (flags & EXT4_GET_BLOCKS_UNWRIT_EXT) {
42414240
ext4_ext_mark_unwritten(&newex);
42424241
map->m_flags |= EXT4_MAP_UNWRITTEN;
42434242
}
42444243

4245-
err = 0;
42464244
err = ext4_ext_insert_extent(handle, inode, &path, &newex, flags);
4245+
if (err) {
4246+
if (allocated_clusters) {
4247+
int fb_flags = 0;
42474248

4248-
if (err && free_on_err) {
4249-
int fb_flags = flags & EXT4_GET_BLOCKS_DELALLOC_RESERVE ?
4250-
EXT4_FREE_BLOCKS_NO_QUOT_UPDATE : 0;
4251-
/* free data blocks we just allocated */
4252-
/* not a good idea to call discard here directly,
4253-
* but otherwise we'd need to call it every free() */
4254-
ext4_discard_preallocations(inode);
4255-
ext4_free_blocks(handle, inode, NULL, newblock,
4256-
EXT4_C2B(sbi, allocated_clusters), fb_flags);
4249+
/*
4250+
* free data blocks we just allocated.
4251+
* not a good idea to call discard here directly,
4252+
* but otherwise we'd need to call it every free().
4253+
*/
4254+
ext4_discard_preallocations(inode);
4255+
if (flags & EXT4_GET_BLOCKS_DELALLOC_RESERVE)
4256+
fb_flags = EXT4_FREE_BLOCKS_NO_QUOT_UPDATE;
4257+
ext4_free_blocks(handle, inode, NULL, newblock,
4258+
EXT4_C2B(sbi, allocated_clusters),
4259+
fb_flags);
4260+
}
42574261
goto out2;
42584262
}
42594263

0 commit comments

Comments
 (0)