Skip to content

Commit 3866e6e

Browse files
Christoph HellwigChandan Babu R
authored andcommitted
xfs: factor out a xfs_dir_removename_args helper
Add a helper to switch between the different directory formats for removing a directory entry. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: "Darrick J. Wong" <[email protected]> Signed-off-by: Chandan Babu R <[email protected]>
1 parent 4d893a4 commit 3866e6e

File tree

3 files changed

+27
-42
lines changed

3 files changed

+27
-42
lines changed

fs/xfs/libxfs/xfs_dir2.c

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,30 @@ xfs_dir_lookup(
444444
return rval;
445445
}
446446

447+
int
448+
xfs_dir_removename_args(
449+
struct xfs_da_args *args)
450+
{
451+
bool is_block, is_leaf;
452+
int error;
453+
454+
if (args->dp->i_df.if_format == XFS_DINODE_FMT_LOCAL)
455+
return xfs_dir2_sf_removename(args);
456+
457+
error = xfs_dir2_isblock(args, &is_block);
458+
if (error)
459+
return error;
460+
if (is_block)
461+
return xfs_dir2_block_removename(args);
462+
463+
error = xfs_dir2_isleaf(args, &is_leaf);
464+
if (error)
465+
return error;
466+
if (is_leaf)
467+
return xfs_dir2_leaf_removename(args);
468+
return xfs_dir2_node_removename(args);
469+
}
470+
447471
/*
448472
* Remove an entry from a directory.
449473
*/
@@ -457,7 +481,6 @@ xfs_dir_removename(
457481
{
458482
struct xfs_da_args *args;
459483
int rval;
460-
bool v;
461484

462485
ASSERT(S_ISDIR(VFS_I(dp)->i_mode));
463486
XFS_STATS_INC(dp->i_mount, xs_dir_remove);
@@ -477,28 +500,7 @@ xfs_dir_removename(
477500
args->whichfork = XFS_DATA_FORK;
478501
args->trans = tp;
479502
args->owner = dp->i_ino;
480-
481-
if (dp->i_df.if_format == XFS_DINODE_FMT_LOCAL) {
482-
rval = xfs_dir2_sf_removename(args);
483-
goto out_free;
484-
}
485-
486-
rval = xfs_dir2_isblock(args, &v);
487-
if (rval)
488-
goto out_free;
489-
if (v) {
490-
rval = xfs_dir2_block_removename(args);
491-
goto out_free;
492-
}
493-
494-
rval = xfs_dir2_isleaf(args, &v);
495-
if (rval)
496-
goto out_free;
497-
if (v)
498-
rval = xfs_dir2_leaf_removename(args);
499-
else
500-
rval = xfs_dir2_node_removename(args);
501-
out_free:
503+
rval = xfs_dir_removename_args(args);
502504
kfree(args);
503505
return rval;
504506
}

fs/xfs/libxfs/xfs_dir2.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ extern int xfs_dir_canenter(struct xfs_trans *tp, struct xfs_inode *dp,
6868

6969
int xfs_dir_lookup_args(struct xfs_da_args *args);
7070
int xfs_dir_createname_args(struct xfs_da_args *args);
71+
int xfs_dir_removename_args(struct xfs_da_args *args);
7172

7273
/*
7374
* Direct call from the bmap code, bypassing the generic directory layer.

fs/xfs/scrub/dir_repair.c

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -712,8 +712,6 @@ xrep_dir_replay_removename(
712712
xfs_extlen_t total)
713713
{
714714
struct xfs_inode *dp = rd->args.dp;
715-
bool is_block, is_leaf;
716-
int error;
717715

718716
ASSERT(S_ISDIR(VFS_I(dp)->i_mode));
719717

@@ -722,23 +720,7 @@ xrep_dir_replay_removename(
722720
rd->args.total = total;
723721

724722
trace_xrep_dir_replay_removename(dp, name, 0);
725-
726-
if (dp->i_df.if_format == XFS_DINODE_FMT_LOCAL)
727-
return xfs_dir2_sf_removename(&rd->args);
728-
729-
error = xfs_dir2_isblock(&rd->args, &is_block);
730-
if (error)
731-
return error;
732-
if (is_block)
733-
return xfs_dir2_block_removename(&rd->args);
734-
735-
error = xfs_dir2_isleaf(&rd->args, &is_leaf);
736-
if (error)
737-
return error;
738-
if (is_leaf)
739-
return xfs_dir2_leaf_removename(&rd->args);
740-
741-
return xfs_dir2_node_removename(&rd->args);
723+
return xfs_dir_removename_args(&rd->args);
742724
}
743725

744726
/*

0 commit comments

Comments
 (0)