]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: factor out a xfs_dir_removename_args helper
authorChristoph Hellwig <hch@lst.de>
Mon, 29 Jul 2024 23:22:53 +0000 (16:22 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Tue, 30 Jul 2024 00:01:04 +0000 (17:01 -0700)
Source kernel commit: 3866e6e669e2c1b3eebf580b8779ea55838c3f5a

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>
libxfs/xfs_dir2.c
libxfs/xfs_dir2.h

index 97c7ddc9286d0ee5093b01e02e604db0c8587855..e2e0832c16f37350c2f57abf0257c643b9c67279 100644 (file)
@@ -443,6 +443,30 @@ xfs_dir_lookup(
        return rval;
 }
 
+int
+xfs_dir_removename_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_removename(args);
+
+       error = xfs_dir2_isblock(args, &is_block);
+       if (error)
+               return error;
+       if (is_block)
+               return xfs_dir2_block_removename(args);
+
+       error = xfs_dir2_isleaf(args, &is_leaf);
+       if (error)
+               return error;
+       if (is_leaf)
+               return xfs_dir2_leaf_removename(args);
+       return xfs_dir2_node_removename(args);
+}
+
 /*
  * Remove an entry from a directory.
  */
@@ -456,7 +480,6 @@ xfs_dir_removename(
 {
        struct xfs_da_args      *args;
        int                     rval;
-       bool                    v;
 
        ASSERT(S_ISDIR(VFS_I(dp)->i_mode));
        XFS_STATS_INC(dp->i_mount, xs_dir_remove);
@@ -476,28 +499,7 @@ xfs_dir_removename(
        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_removename(args);
-               goto out_free;
-       }
-
-       rval = xfs_dir2_isblock(args, &v);
-       if (rval)
-               goto out_free;
-       if (v) {
-               rval = xfs_dir2_block_removename(args);
-               goto out_free;
-       }
-
-       rval = xfs_dir2_isleaf(args, &v);
-       if (rval)
-               goto out_free;
-       if (v)
-               rval = xfs_dir2_leaf_removename(args);
-       else
-               rval = xfs_dir2_node_removename(args);
-out_free:
+       rval = xfs_dir_removename_args(args);
        kfree(args);
        return rval;
 }
index f5361dd7b90a93f6bfcc215422702f6ef3edd260..3db54801d69ecd7f934c5333cfb9ab4e1bfc6383 100644 (file)
@@ -68,6 +68,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);
 
 /*
  * Direct call from the bmap code, bypassing the generic directory layer.