Skip to content

Commit 4d893a4

Browse files
Christoph HellwigChandan Babu R
authored andcommitted
xfs: factor out a xfs_dir_createname_args helper
Add a helper to switch between the different directory formats for creating a directory entry and to handle the XFS_DA_OP_JUSTCHECK flag based on the passed in ino number field. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: "Darrick J. Wong" <[email protected]> Signed-off-by: Chandan Babu R <[email protected]>
1 parent 14ee22f commit 4d893a4

File tree

3 files changed

+30
-43
lines changed

3 files changed

+30
-43
lines changed

fs/xfs/libxfs/xfs_dir2.c

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,33 @@ xfs_dir_init(
256256
return error;
257257
}
258258

259+
int
260+
xfs_dir_createname_args(
261+
struct xfs_da_args *args)
262+
{
263+
bool is_block, is_leaf;
264+
int error;
265+
266+
if (!args->inumber)
267+
args->op_flags |= XFS_DA_OP_JUSTCHECK;
268+
269+
if (args->dp->i_df.if_format == XFS_DINODE_FMT_LOCAL)
270+
return xfs_dir2_sf_addname(args);
271+
272+
error = xfs_dir2_isblock(args, &is_block);
273+
if (error)
274+
return error;
275+
if (is_block)
276+
return xfs_dir2_block_addname(args);
277+
278+
error = xfs_dir2_isleaf(args, &is_leaf);
279+
if (error)
280+
return error;
281+
if (is_leaf)
282+
return xfs_dir2_leaf_addname(args);
283+
return xfs_dir2_node_addname(args);
284+
}
285+
259286
/*
260287
* Enter a name in a directory, or check for available space.
261288
* If inum is 0, only the available space test is performed.
@@ -270,7 +297,6 @@ xfs_dir_createname(
270297
{
271298
struct xfs_da_args *args;
272299
int rval;
273-
bool v;
274300

275301
ASSERT(S_ISDIR(VFS_I(dp)->i_mode));
276302

@@ -297,31 +323,8 @@ xfs_dir_createname(
297323
args->trans = tp;
298324
args->op_flags = XFS_DA_OP_ADDNAME | XFS_DA_OP_OKNOENT;
299325
args->owner = dp->i_ino;
300-
if (!inum)
301-
args->op_flags |= XFS_DA_OP_JUSTCHECK;
302-
303-
if (dp->i_df.if_format == XFS_DINODE_FMT_LOCAL) {
304-
rval = xfs_dir2_sf_addname(args);
305-
goto out_free;
306-
}
307326

308-
rval = xfs_dir2_isblock(args, &v);
309-
if (rval)
310-
goto out_free;
311-
if (v) {
312-
rval = xfs_dir2_block_addname(args);
313-
goto out_free;
314-
}
315-
316-
rval = xfs_dir2_isleaf(args, &v);
317-
if (rval)
318-
goto out_free;
319-
if (v)
320-
rval = xfs_dir2_leaf_addname(args);
321-
else
322-
rval = xfs_dir2_node_addname(args);
323-
324-
out_free:
327+
rval = xfs_dir_createname_args(args);
325328
kfree(args);
326329
return rval;
327330
}

fs/xfs/libxfs/xfs_dir2.h

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

6969
int xfs_dir_lookup_args(struct xfs_da_args *args);
70+
int xfs_dir_createname_args(struct xfs_da_args *args);
7071

7172
/*
7273
* 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
@@ -687,7 +687,6 @@ xrep_dir_replay_createname(
687687
{
688688
struct xfs_scrub *sc = rd->sc;
689689
struct xfs_inode *dp = rd->sc->tempip;
690-
bool is_block, is_leaf;
691690
int error;
692691

693692
ASSERT(S_ISDIR(VFS_I(dp)->i_mode));
@@ -702,23 +701,7 @@ xrep_dir_replay_createname(
702701
rd->args.inumber = inum;
703702
rd->args.total = total;
704703
rd->args.op_flags = XFS_DA_OP_ADDNAME | XFS_DA_OP_OKNOENT;
705-
706-
if (dp->i_df.if_format == XFS_DINODE_FMT_LOCAL)
707-
return xfs_dir2_sf_addname(&rd->args);
708-
709-
error = xfs_dir2_isblock(&rd->args, &is_block);
710-
if (error)
711-
return error;
712-
if (is_block)
713-
return xfs_dir2_block_addname(&rd->args);
714-
715-
error = xfs_dir2_isleaf(&rd->args, &is_leaf);
716-
if (error)
717-
return error;
718-
if (is_leaf)
719-
return xfs_dir2_leaf_addname(&rd->args);
720-
721-
return xfs_dir2_node_addname(&rd->args);
704+
return xfs_dir_createname_args(&rd->args);
722705
}
723706

724707
/* Replay a stashed removename onto the temporary directory. */

0 commit comments

Comments
 (0)