Commit 4d893a40 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Chandan Babu R

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: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatar"Darrick J. Wong" <djwong@kernel.org>
Signed-off-by: default avatarChandan Babu R <chandanbabu@kernel.org>
parent 14ee22fe
...@@ -256,6 +256,33 @@ xfs_dir_init( ...@@ -256,6 +256,33 @@ xfs_dir_init(
return error; return error;
} }
int
xfs_dir_createname_args(
struct xfs_da_args *args)
{
bool is_block, is_leaf;
int error;
if (!args->inumber)
args->op_flags |= XFS_DA_OP_JUSTCHECK;
if (args->dp->i_df.if_format == XFS_DINODE_FMT_LOCAL)
return xfs_dir2_sf_addname(args);
error = xfs_dir2_isblock(args, &is_block);
if (error)
return error;
if (is_block)
return xfs_dir2_block_addname(args);
error = xfs_dir2_isleaf(args, &is_leaf);
if (error)
return error;
if (is_leaf)
return xfs_dir2_leaf_addname(args);
return xfs_dir2_node_addname(args);
}
/* /*
* Enter a name in a directory, or check for available space. * Enter a name in a directory, or check for available space.
* If inum is 0, only the available space test is performed. * If inum is 0, only the available space test is performed.
...@@ -270,7 +297,6 @@ xfs_dir_createname( ...@@ -270,7 +297,6 @@ xfs_dir_createname(
{ {
struct xfs_da_args *args; struct xfs_da_args *args;
int rval; int rval;
bool v;
ASSERT(S_ISDIR(VFS_I(dp)->i_mode)); ASSERT(S_ISDIR(VFS_I(dp)->i_mode));
...@@ -297,31 +323,8 @@ xfs_dir_createname( ...@@ -297,31 +323,8 @@ xfs_dir_createname(
args->trans = tp; args->trans = tp;
args->op_flags = XFS_DA_OP_ADDNAME | XFS_DA_OP_OKNOENT; args->op_flags = XFS_DA_OP_ADDNAME | XFS_DA_OP_OKNOENT;
args->owner = dp->i_ino; args->owner = dp->i_ino;
if (!inum)
args->op_flags |= XFS_DA_OP_JUSTCHECK;
if (dp->i_df.if_format == XFS_DINODE_FMT_LOCAL) {
rval = xfs_dir2_sf_addname(args);
goto out_free;
}
rval = xfs_dir2_isblock(args, &v); rval = xfs_dir_createname_args(args);
if (rval)
goto out_free;
if (v) {
rval = xfs_dir2_block_addname(args);
goto out_free;
}
rval = xfs_dir2_isleaf(args, &v);
if (rval)
goto out_free;
if (v)
rval = xfs_dir2_leaf_addname(args);
else
rval = xfs_dir2_node_addname(args);
out_free:
kfree(args); kfree(args);
return rval; return rval;
} }
......
...@@ -67,6 +67,7 @@ extern int xfs_dir_canenter(struct xfs_trans *tp, struct xfs_inode *dp, ...@@ -67,6 +67,7 @@ extern int xfs_dir_canenter(struct xfs_trans *tp, struct xfs_inode *dp,
struct xfs_name *name); struct xfs_name *name);
int xfs_dir_lookup_args(struct xfs_da_args *args); int xfs_dir_lookup_args(struct xfs_da_args *args);
int xfs_dir_createname_args(struct xfs_da_args *args);
/* /*
* Direct call from the bmap code, bypassing the generic directory layer. * Direct call from the bmap code, bypassing the generic directory layer.
......
...@@ -687,7 +687,6 @@ xrep_dir_replay_createname( ...@@ -687,7 +687,6 @@ xrep_dir_replay_createname(
{ {
struct xfs_scrub *sc = rd->sc; struct xfs_scrub *sc = rd->sc;
struct xfs_inode *dp = rd->sc->tempip; struct xfs_inode *dp = rd->sc->tempip;
bool is_block, is_leaf;
int error; int error;
ASSERT(S_ISDIR(VFS_I(dp)->i_mode)); ASSERT(S_ISDIR(VFS_I(dp)->i_mode));
...@@ -702,23 +701,7 @@ xrep_dir_replay_createname( ...@@ -702,23 +701,7 @@ xrep_dir_replay_createname(
rd->args.inumber = inum; rd->args.inumber = inum;
rd->args.total = total; rd->args.total = total;
rd->args.op_flags = XFS_DA_OP_ADDNAME | XFS_DA_OP_OKNOENT; rd->args.op_flags = XFS_DA_OP_ADDNAME | XFS_DA_OP_OKNOENT;
return xfs_dir_createname_args(&rd->args);
if (dp->i_df.if_format == XFS_DINODE_FMT_LOCAL)
return xfs_dir2_sf_addname(&rd->args);
error = xfs_dir2_isblock(&rd->args, &is_block);
if (error)
return error;
if (is_block)
return xfs_dir2_block_addname(&rd->args);
error = xfs_dir2_isleaf(&rd->args, &is_leaf);
if (error)
return error;
if (is_leaf)
return xfs_dir2_leaf_addname(&rd->args);
return xfs_dir2_node_addname(&rd->args);
} }
/* Replay a stashed removename onto the temporary directory. */ /* Replay a stashed removename onto the temporary directory. */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment