Skip to content

Commit 4268496

Browse files
yangerkuntytso
authored andcommitted
ext4: ensure enough credits in ext4_ext_shift_path_extents
Like ext4_ext_rm_leaf, we can ensure that there are enough credits before every call that will consume credits. As part of this fix we fold the functionality of ext4_access_path() into ext4_ext_shift_path_extents(). This change is needed as a preparation for the next bugfix patch. Cc: [email protected] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: yangerkun <[email protected]> Reviewed-by: Jan Kara <[email protected]> Signed-off-by: Theodore Ts'o <[email protected]>
1 parent 83c5688 commit 4268496

File tree

1 file changed

+15
-34
lines changed

1 file changed

+15
-34
lines changed

fs/ext4/extents.c

Lines changed: 15 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4979,36 +4979,6 @@ int ext4_get_es_cache(struct inode *inode, struct fiemap_extent_info *fieinfo,
49794979
return ext4_fill_es_cache_info(inode, start_blk, len_blks, fieinfo);
49804980
}
49814981

4982-
/*
4983-
* ext4_access_path:
4984-
* Function to access the path buffer for marking it dirty.
4985-
* It also checks if there are sufficient credits left in the journal handle
4986-
* to update path.
4987-
*/
4988-
static int
4989-
ext4_access_path(handle_t *handle, struct inode *inode,
4990-
struct ext4_ext_path *path)
4991-
{
4992-
int credits, err;
4993-
4994-
if (!ext4_handle_valid(handle))
4995-
return 0;
4996-
4997-
/*
4998-
* Check if need to extend journal credits
4999-
* 3 for leaf, sb, and inode plus 2 (bmap and group
5000-
* descriptor) for each block group; assume two block
5001-
* groups
5002-
*/
5003-
credits = ext4_writepage_trans_blocks(inode);
5004-
err = ext4_datasem_ensure_credits(handle, inode, 7, credits, 0);
5005-
if (err < 0)
5006-
return err;
5007-
5008-
err = ext4_ext_get_access(handle, inode, path);
5009-
return err;
5010-
}
5011-
50124982
/*
50134983
* ext4_ext_shift_path_extents:
50144984
* Shift the extents of a path structure lying between path[depth].p_ext
@@ -5023,6 +4993,7 @@ ext4_ext_shift_path_extents(struct ext4_ext_path *path, ext4_lblk_t shift,
50234993
int depth, err = 0;
50244994
struct ext4_extent *ex_start, *ex_last;
50254995
bool update = false;
4996+
int credits, restart_credits;
50264997
depth = path->p_depth;
50274998

50284999
while (depth >= 0) {
@@ -5032,13 +5003,23 @@ ext4_ext_shift_path_extents(struct ext4_ext_path *path, ext4_lblk_t shift,
50325003
return -EFSCORRUPTED;
50335004

50345005
ex_last = EXT_LAST_EXTENT(path[depth].p_hdr);
5006+
/* leaf + sb + inode */
5007+
credits = 3;
5008+
if (ex_start == EXT_FIRST_EXTENT(path[depth].p_hdr)) {
5009+
update = true;
5010+
/* extent tree + sb + inode */
5011+
credits = depth + 2;
5012+
}
50355013

5036-
err = ext4_access_path(handle, inode, path + depth);
5014+
restart_credits = ext4_writepage_trans_blocks(inode);
5015+
err = ext4_datasem_ensure_credits(handle, inode, credits,
5016+
restart_credits, 0);
50375017
if (err)
50385018
goto out;
50395019

5040-
if (ex_start == EXT_FIRST_EXTENT(path[depth].p_hdr))
5041-
update = true;
5020+
err = ext4_ext_get_access(handle, inode, path + depth);
5021+
if (err)
5022+
goto out;
50425023

50435024
while (ex_start <= ex_last) {
50445025
if (SHIFT == SHIFT_LEFT) {
@@ -5069,7 +5050,7 @@ ext4_ext_shift_path_extents(struct ext4_ext_path *path, ext4_lblk_t shift,
50695050
}
50705051

50715052
/* Update index too */
5072-
err = ext4_access_path(handle, inode, path + depth);
5053+
err = ext4_ext_get_access(handle, inode, path + depth);
50735054
if (err)
50745055
goto out;
50755056

0 commit comments

Comments
 (0)