xfs: factor out a xfs_dir_replace_args helper
authorChristoph Hellwig <hch@lst.de>
Thu, 25 Apr 2024 13:17:02 +0000 (15:17 +0200)
committerChandan Babu R <chandanbabu@kernel.org>
Fri, 26 Apr 2024 05:49:04 +0000 (11:19 +0530)
Add a helper to switch between the different directory formats for
removing a directory entry.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>
fs/xfs/libxfs/xfs_dir2.c
fs/xfs/libxfs/xfs_dir2.h
fs/xfs/scrub/dir_repair.c

index 76aa11ade2e92d21b0b32710896686339f1aced4..d3d4d80c2098d38be3705156ac6e98da9c561acf 100644 (file)
@@ -505,6 +505,31 @@ xfs_dir_removename(
        return rval;
 }
 
+int
+xfs_dir_replace_args(
+       struct xfs_da_args      *args)
+{
+       bool                    is_block, is_leaf;
+       int                     error;
+
+       if (args->dp->i_df.if_format == XFS_DINODE_FMT_LOCAL)
+               return xfs_dir2_sf_replace(args);
+
+       error = xfs_dir2_isblock(args, &is_block);
+       if (error)
+               return error;
+       if (is_block)
+               return xfs_dir2_block_replace(args);
+
+       error = xfs_dir2_isleaf(args, &is_leaf);
+       if (error)
+               return error;
+       if (is_leaf)
+               return xfs_dir2_leaf_replace(args);
+
+       return xfs_dir2_node_replace(args);
+}
+
 /*
  * Replace the inode number of a directory entry.
  */
@@ -518,7 +543,6 @@ xfs_dir_replace(
 {
        struct xfs_da_args      *args;
        int                     rval;
-       bool                    v;
 
        ASSERT(S_ISDIR(VFS_I(dp)->i_mode));
 
@@ -541,28 +565,7 @@ xfs_dir_replace(
        args->whichfork = XFS_DATA_FORK;
        args->trans = tp;
        args->owner = dp->i_ino;
-
-       if (dp->i_df.if_format == XFS_DINODE_FMT_LOCAL) {
-               rval = xfs_dir2_sf_replace(args);
-               goto out_free;
-       }
-
-       rval = xfs_dir2_isblock(args, &v);
-       if (rval)
-               goto out_free;
-       if (v) {
-               rval = xfs_dir2_block_replace(args);
-               goto out_free;
-       }
-
-       rval = xfs_dir2_isleaf(args, &v);
-       if (rval)
-               goto out_free;
-       if (v)
-               rval = xfs_dir2_leaf_replace(args);
-       else
-               rval = xfs_dir2_node_replace(args);
-out_free:
+       rval = xfs_dir_replace_args(args);
        kfree(args);
        return rval;
 }
index 3db54801d69ecd7f934c5333cfb9ab4e1bfc6383..6c00fe24a8987ec160e46522ed05c3b50066d159 100644 (file)
@@ -69,6 +69,7 @@ extern int xfs_dir_canenter(struct xfs_trans *tp, struct xfs_inode *dp,
 int xfs_dir_lookup_args(struct xfs_da_args *args);
 int xfs_dir_createname_args(struct xfs_da_args *args);
 int xfs_dir_removename_args(struct xfs_da_args *args);
+int xfs_dir_replace_args(struct xfs_da_args *args);
 
 /*
  * Direct call from the bmap code, bypassing the generic directory layer.
index 98e4ed25cc230967c1d0c0ad56be41026384aa11..64679fe08446505ecd0bb183e52560b0fbe4a95b 100644 (file)
@@ -1513,7 +1513,6 @@ xrep_dir_replace(
        xfs_extlen_t            total)
 {
        struct xfs_scrub        *sc = rd->sc;
-       bool                    is_block, is_leaf;
        int                     error;
 
        ASSERT(S_ISDIR(VFS_I(dp)->i_mode));
@@ -1525,23 +1524,7 @@ xrep_dir_replace(
        xrep_dir_init_args(rd, dp, name);
        rd->args.inumber = inum;
        rd->args.total = total;
-
-       if (dp->i_df.if_format == XFS_DINODE_FMT_LOCAL)
-               return xfs_dir2_sf_replace(&rd->args);
-
-       error = xfs_dir2_isblock(&rd->args, &is_block);
-       if (error)
-               return error;
-       if (is_block)
-               return xfs_dir2_block_replace(&rd->args);
-
-       error = xfs_dir2_isleaf(&rd->args, &is_leaf);
-       if (error)
-               return error;
-       if (is_leaf)
-               return xfs_dir2_leaf_replace(&rd->args);
-
-       return xfs_dir2_node_replace(&rd->args);
+       return xfs_dir_replace_args(&rd->args);
 }
 
 /*