Skip to content

Commit edfa71d

Browse files
LiBaokun96tytso
authored andcommitted
ext4: refactor ext4_ext_rm_idx() to index 'path'
As suggested by Honza in Link,modify ext4_ext_rm_idx() to leave 'path' alone and just index it like ext4_ext_correct_indexes() does it. This facilitates adding error handling later. No functional changes. Suggested-by: Jan Kara <jack@suse.cz> Link: https://lore.kernel.org/all/20230216130305.nrbtd42tppxhbynn@quack3/ Signed-off-by: Baokun Li <libaokun1@huawei.com> Reviewed-by: Jan Kara <jack@suse.cz> Reviewed-by: Ojaswin Mujoo <ojaswin@linux.ibm.com> Tested-by: Ojaswin Mujoo <ojaswin@linux.ibm.com> Link: https://patch.msgid.link/20240822023545.1994557-2-libaokun@huaweicloud.com Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent c6b72f5 commit edfa71d

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

fs/ext4/extents.c

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2279,27 +2279,26 @@ static int ext4_ext_rm_idx(handle_t *handle, struct inode *inode,
22792279
{
22802280
int err;
22812281
ext4_fsblk_t leaf;
2282+
int k = depth - 1;
22822283

22832284
/* free index block */
2284-
depth--;
2285-
path = path + depth;
2286-
leaf = ext4_idx_pblock(path->p_idx);
2287-
if (unlikely(path->p_hdr->eh_entries == 0)) {
2288-
EXT4_ERROR_INODE(inode, "path->p_hdr->eh_entries == 0");
2285+
leaf = ext4_idx_pblock(path[k].p_idx);
2286+
if (unlikely(path[k].p_hdr->eh_entries == 0)) {
2287+
EXT4_ERROR_INODE(inode, "path[%d].p_hdr->eh_entries == 0", k);
22892288
return -EFSCORRUPTED;
22902289
}
2291-
err = ext4_ext_get_access(handle, inode, path);
2290+
err = ext4_ext_get_access(handle, inode, path + k);
22922291
if (err)
22932292
return err;
22942293

2295-
if (path->p_idx != EXT_LAST_INDEX(path->p_hdr)) {
2296-
int len = EXT_LAST_INDEX(path->p_hdr) - path->p_idx;
2294+
if (path[k].p_idx != EXT_LAST_INDEX(path[k].p_hdr)) {
2295+
int len = EXT_LAST_INDEX(path[k].p_hdr) - path[k].p_idx;
22972296
len *= sizeof(struct ext4_extent_idx);
2298-
memmove(path->p_idx, path->p_idx + 1, len);
2297+
memmove(path[k].p_idx, path[k].p_idx + 1, len);
22992298
}
23002299

2301-
le16_add_cpu(&path->p_hdr->eh_entries, -1);
2302-
err = ext4_ext_dirty(handle, inode, path);
2300+
le16_add_cpu(&path[k].p_hdr->eh_entries, -1);
2301+
err = ext4_ext_dirty(handle, inode, path + k);
23032302
if (err)
23042303
return err;
23052304
ext_debug(inode, "index is empty, remove it, free block %llu\n", leaf);
@@ -2308,15 +2307,14 @@ static int ext4_ext_rm_idx(handle_t *handle, struct inode *inode,
23082307
ext4_free_blocks(handle, inode, NULL, leaf, 1,
23092308
EXT4_FREE_BLOCKS_METADATA | EXT4_FREE_BLOCKS_FORGET);
23102309

2311-
while (--depth >= 0) {
2312-
if (path->p_idx != EXT_FIRST_INDEX(path->p_hdr))
2310+
while (--k >= 0) {
2311+
if (path[k + 1].p_idx != EXT_FIRST_INDEX(path[k + 1].p_hdr))
23132312
break;
2314-
path--;
2315-
err = ext4_ext_get_access(handle, inode, path);
2313+
err = ext4_ext_get_access(handle, inode, path + k);
23162314
if (err)
23172315
break;
2318-
path->p_idx->ei_block = (path+1)->p_idx->ei_block;
2319-
err = ext4_ext_dirty(handle, inode, path);
2316+
path[k].p_idx->ei_block = path[k + 1].p_idx->ei_block;
2317+
err = ext4_ext_dirty(handle, inode, path + k);
23202318
if (err)
23212319
break;
23222320
}

0 commit comments

Comments
 (0)