Skip to content

Commit dfe5feb

Browse files
Christoph HellwigChandan Babu R
authored andcommitted
xfs: factor out a xfs_dir_replace_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 3866e6e commit dfe5feb

File tree

3 files changed

+28
-41
lines changed

3 files changed

+28
-41
lines changed

fs/xfs/libxfs/xfs_dir2.c

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,31 @@ xfs_dir_removename(
505505
return rval;
506506
}
507507

508+
int
509+
xfs_dir_replace_args(
510+
struct xfs_da_args *args)
511+
{
512+
bool is_block, is_leaf;
513+
int error;
514+
515+
if (args->dp->i_df.if_format == XFS_DINODE_FMT_LOCAL)
516+
return xfs_dir2_sf_replace(args);
517+
518+
error = xfs_dir2_isblock(args, &is_block);
519+
if (error)
520+
return error;
521+
if (is_block)
522+
return xfs_dir2_block_replace(args);
523+
524+
error = xfs_dir2_isleaf(args, &is_leaf);
525+
if (error)
526+
return error;
527+
if (is_leaf)
528+
return xfs_dir2_leaf_replace(args);
529+
530+
return xfs_dir2_node_replace(args);
531+
}
532+
508533
/*
509534
* Replace the inode number of a directory entry.
510535
*/
@@ -518,7 +543,6 @@ xfs_dir_replace(
518543
{
519544
struct xfs_da_args *args;
520545
int rval;
521-
bool v;
522546

523547
ASSERT(S_ISDIR(VFS_I(dp)->i_mode));
524548

@@ -541,28 +565,7 @@ xfs_dir_replace(
541565
args->whichfork = XFS_DATA_FORK;
542566
args->trans = tp;
543567
args->owner = dp->i_ino;
544-
545-
if (dp->i_df.if_format == XFS_DINODE_FMT_LOCAL) {
546-
rval = xfs_dir2_sf_replace(args);
547-
goto out_free;
548-
}
549-
550-
rval = xfs_dir2_isblock(args, &v);
551-
if (rval)
552-
goto out_free;
553-
if (v) {
554-
rval = xfs_dir2_block_replace(args);
555-
goto out_free;
556-
}
557-
558-
rval = xfs_dir2_isleaf(args, &v);
559-
if (rval)
560-
goto out_free;
561-
if (v)
562-
rval = xfs_dir2_leaf_replace(args);
563-
else
564-
rval = xfs_dir2_node_replace(args);
565-
out_free:
568+
rval = xfs_dir_replace_args(args);
566569
kfree(args);
567570
return rval;
568571
}

fs/xfs/libxfs/xfs_dir2.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ extern int xfs_dir_canenter(struct xfs_trans *tp, struct xfs_inode *dp,
6969
int xfs_dir_lookup_args(struct xfs_da_args *args);
7070
int xfs_dir_createname_args(struct xfs_da_args *args);
7171
int xfs_dir_removename_args(struct xfs_da_args *args);
72+
int xfs_dir_replace_args(struct xfs_da_args *args);
7273

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

fs/xfs/scrub/dir_repair.c

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1513,7 +1513,6 @@ xrep_dir_replace(
15131513
xfs_extlen_t total)
15141514
{
15151515
struct xfs_scrub *sc = rd->sc;
1516-
bool is_block, is_leaf;
15171516
int error;
15181517

15191518
ASSERT(S_ISDIR(VFS_I(dp)->i_mode));
@@ -1525,23 +1524,7 @@ xrep_dir_replace(
15251524
xrep_dir_init_args(rd, dp, name);
15261525
rd->args.inumber = inum;
15271526
rd->args.total = total;
1528-
1529-
if (dp->i_df.if_format == XFS_DINODE_FMT_LOCAL)
1530-
return xfs_dir2_sf_replace(&rd->args);
1531-
1532-
error = xfs_dir2_isblock(&rd->args, &is_block);
1533-
if (error)
1534-
return error;
1535-
if (is_block)
1536-
return xfs_dir2_block_replace(&rd->args);
1537-
1538-
error = xfs_dir2_isleaf(&rd->args, &is_leaf);
1539-
if (error)
1540-
return error;
1541-
if (is_leaf)
1542-
return xfs_dir2_leaf_replace(&rd->args);
1543-
1544-
return xfs_dir2_node_replace(&rd->args);
1527+
return xfs_dir_replace_args(&rd->args);
15451528
}
15461529

15471530
/*

0 commit comments

Comments
 (0)