Commit a1358aa3 authored by Dave Chinner's avatar Dave Chinner Committed by Dave Chinner

xfs: allocate xfs_da_args to reduce stack footprint

The struct xfs_da_args used to pass directory/attribute operation
information to the lower layers is 128 bytes in size and is
allocated on the stack. Dynamically allocate them to reduce the
stack footprint of directory operations.
Signed-off-by: default avatarDave Chinner <dchinner@redhat.com>
Reviewed-by: default avatarBrian Foster <bfoster@redhat.com>
Signed-off-by: default avatarDave Chinner <david@fromorbit.com>
parent f876e446
...@@ -180,16 +180,23 @@ xfs_dir_init( ...@@ -180,16 +180,23 @@ xfs_dir_init(
xfs_inode_t *dp, xfs_inode_t *dp,
xfs_inode_t *pdp) xfs_inode_t *pdp)
{ {
xfs_da_args_t args; struct xfs_da_args *args;
int error; int error;
memset((char *)&args, 0, sizeof(args));
args.dp = dp;
args.trans = tp;
ASSERT(S_ISDIR(dp->i_d.di_mode)); ASSERT(S_ISDIR(dp->i_d.di_mode));
if ((error = xfs_dir_ino_validate(tp->t_mountp, pdp->i_ino))) error = xfs_dir_ino_validate(tp->t_mountp, pdp->i_ino);
if (error)
return error; return error;
return xfs_dir2_sf_create(&args, pdp->i_ino);
args = kmem_zalloc(sizeof(*args), KM_SLEEP | KM_NOFS);
if (!args)
return ENOMEM;
args->dp = dp;
args->trans = tp;
error = xfs_dir2_sf_create(args, pdp->i_ino);
kmem_free(args);
return error;
} }
/* /*
...@@ -205,41 +212,56 @@ xfs_dir_createname( ...@@ -205,41 +212,56 @@ xfs_dir_createname(
xfs_bmap_free_t *flist, /* bmap's freeblock list */ xfs_bmap_free_t *flist, /* bmap's freeblock list */
xfs_extlen_t total) /* bmap's total block count */ xfs_extlen_t total) /* bmap's total block count */
{ {
xfs_da_args_t args; struct xfs_da_args *args;
int rval; int rval;
int v; /* type-checking value */ int v; /* type-checking value */
ASSERT(S_ISDIR(dp->i_d.di_mode)); ASSERT(S_ISDIR(dp->i_d.di_mode));
if ((rval = xfs_dir_ino_validate(tp->t_mountp, inum))) rval = xfs_dir_ino_validate(tp->t_mountp, inum);
if (rval)
return rval; return rval;
XFS_STATS_INC(xs_dir_create); XFS_STATS_INC(xs_dir_create);
memset(&args, 0, sizeof(xfs_da_args_t)); args = kmem_zalloc(sizeof(*args), KM_SLEEP | KM_NOFS);
args.name = name->name; if (!args)
args.namelen = name->len; return ENOMEM;
args.filetype = name->type;
args.hashval = dp->i_mount->m_dirnameops->hashname(name); args->name = name->name;
args.inumber = inum; args->namelen = name->len;
args.dp = dp; args->filetype = name->type;
args.firstblock = first; args->hashval = dp->i_mount->m_dirnameops->hashname(name);
args.flist = flist; args->inumber = inum;
args.total = total; args->dp = dp;
args.whichfork = XFS_DATA_FORK; args->firstblock = first;
args.trans = tp; args->flist = flist;
args.op_flags = XFS_DA_OP_ADDNAME | XFS_DA_OP_OKNOENT; args->total = total;
args->whichfork = XFS_DATA_FORK;
if (dp->i_d.di_format == XFS_DINODE_FMT_LOCAL) args->trans = tp;
rval = xfs_dir2_sf_addname(&args); args->op_flags = XFS_DA_OP_ADDNAME | XFS_DA_OP_OKNOENT;
else if ((rval = xfs_dir2_isblock(tp, dp, &v)))
return rval; if (dp->i_d.di_format == XFS_DINODE_FMT_LOCAL) {
else if (v) rval = xfs_dir2_sf_addname(args);
rval = xfs_dir2_block_addname(&args); goto out_free;
else if ((rval = xfs_dir2_isleaf(tp, dp, &v))) }
return rval;
else if (v) rval = xfs_dir2_isblock(tp, dp, &v);
rval = xfs_dir2_leaf_addname(&args); if (rval)
goto out_free;
if (v) {
rval = xfs_dir2_block_addname(args);
goto out_free;
}
rval = xfs_dir2_isleaf(tp, dp, &v);
if (rval)
goto out_free;
if (v)
rval = xfs_dir2_leaf_addname(args);
else else
rval = xfs_dir2_node_addname(&args); rval = xfs_dir2_node_addname(args);
out_free:
kmem_free(args);
return rval; return rval;
} }
...@@ -282,46 +304,66 @@ xfs_dir_lookup( ...@@ -282,46 +304,66 @@ xfs_dir_lookup(
xfs_ino_t *inum, /* out: inode number */ xfs_ino_t *inum, /* out: inode number */
struct xfs_name *ci_name) /* out: actual name if CI match */ struct xfs_name *ci_name) /* out: actual name if CI match */
{ {
xfs_da_args_t args; struct xfs_da_args *args;
int rval; int rval;
int v; /* type-checking value */ int v; /* type-checking value */
ASSERT(S_ISDIR(dp->i_d.di_mode)); ASSERT(S_ISDIR(dp->i_d.di_mode));
XFS_STATS_INC(xs_dir_lookup); XFS_STATS_INC(xs_dir_lookup);
memset(&args, 0, sizeof(xfs_da_args_t)); /*
args.name = name->name; * We need to use KM_NOFS here so that lockdep will not throw false
args.namelen = name->len; * positive deadlock warnings on a non-transactional lookup path. It is
args.filetype = name->type; * safe to recurse into inode recalim in that case, but lockdep can't
args.hashval = dp->i_mount->m_dirnameops->hashname(name); * easily be taught about it. Hence KM_NOFS avoids having to add more
args.dp = dp; * lockdep Doing this avoids having to add a bunch of lockdep class
args.whichfork = XFS_DATA_FORK; * annotations into the reclaim path for the ilock.
args.trans = tp; */
args.op_flags = XFS_DA_OP_OKNOENT; args = kmem_zalloc(sizeof(*args), KM_SLEEP | KM_NOFS);
args->name = name->name;
args->namelen = name->len;
args->filetype = name->type;
args->hashval = dp->i_mount->m_dirnameops->hashname(name);
args->dp = dp;
args->whichfork = XFS_DATA_FORK;
args->trans = tp;
args->op_flags = XFS_DA_OP_OKNOENT;
if (ci_name) if (ci_name)
args.op_flags |= XFS_DA_OP_CILOOKUP; args->op_flags |= XFS_DA_OP_CILOOKUP;
if (dp->i_d.di_format == XFS_DINODE_FMT_LOCAL) if (dp->i_d.di_format == XFS_DINODE_FMT_LOCAL) {
rval = xfs_dir2_sf_lookup(&args); rval = xfs_dir2_sf_lookup(args);
else if ((rval = xfs_dir2_isblock(tp, dp, &v))) goto out_check_rval;
return rval; }
else if (v)
rval = xfs_dir2_block_lookup(&args); rval = xfs_dir2_isblock(tp, dp, &v);
else if ((rval = xfs_dir2_isleaf(tp, dp, &v))) if (rval)
return rval; goto out_free;
else if (v) if (v) {
rval = xfs_dir2_leaf_lookup(&args); rval = xfs_dir2_block_lookup(args);
goto out_check_rval;
}
rval = xfs_dir2_isleaf(tp, dp, &v);
if (rval)
goto out_free;
if (v)
rval = xfs_dir2_leaf_lookup(args);
else else
rval = xfs_dir2_node_lookup(&args); rval = xfs_dir2_node_lookup(args);
out_check_rval:
if (rval == EEXIST) if (rval == EEXIST)
rval = 0; rval = 0;
if (!rval) { if (!rval) {
*inum = args.inumber; *inum = args->inumber;
if (ci_name) { if (ci_name) {
ci_name->name = args.value; ci_name->name = args->value;
ci_name->len = args.valuelen; ci_name->len = args->valuelen;
} }
} }
out_free:
kmem_free(args);
return rval; return rval;
} }
...@@ -338,38 +380,51 @@ xfs_dir_removename( ...@@ -338,38 +380,51 @@ xfs_dir_removename(
xfs_bmap_free_t *flist, /* bmap's freeblock list */ xfs_bmap_free_t *flist, /* bmap's freeblock list */
xfs_extlen_t total) /* bmap's total block count */ xfs_extlen_t total) /* bmap's total block count */
{ {
xfs_da_args_t args; struct xfs_da_args *args;
int rval; int rval;
int v; /* type-checking value */ int v; /* type-checking value */
ASSERT(S_ISDIR(dp->i_d.di_mode)); ASSERT(S_ISDIR(dp->i_d.di_mode));
XFS_STATS_INC(xs_dir_remove); XFS_STATS_INC(xs_dir_remove);
memset(&args, 0, sizeof(xfs_da_args_t)); args = kmem_zalloc(sizeof(*args), KM_SLEEP | KM_NOFS);
args.name = name->name; if (!args)
args.namelen = name->len; return ENOMEM;
args.filetype = name->type;
args.hashval = dp->i_mount->m_dirnameops->hashname(name); args->name = name->name;
args.inumber = ino; args->namelen = name->len;
args.dp = dp; args->filetype = name->type;
args.firstblock = first; args->hashval = dp->i_mount->m_dirnameops->hashname(name);
args.flist = flist; args->inumber = ino;
args.total = total; args->dp = dp;
args.whichfork = XFS_DATA_FORK; args->firstblock = first;
args.trans = tp; args->flist = flist;
args->total = total;
if (dp->i_d.di_format == XFS_DINODE_FMT_LOCAL) args->whichfork = XFS_DATA_FORK;
rval = xfs_dir2_sf_removename(&args); args->trans = tp;
else if ((rval = xfs_dir2_isblock(tp, dp, &v)))
return rval; if (dp->i_d.di_format == XFS_DINODE_FMT_LOCAL) {
else if (v) rval = xfs_dir2_sf_removename(args);
rval = xfs_dir2_block_removename(&args); goto out_free;
else if ((rval = xfs_dir2_isleaf(tp, dp, &v))) }
return rval;
else if (v) rval = xfs_dir2_isblock(tp, dp, &v);
rval = xfs_dir2_leaf_removename(&args); if (rval)
goto out_free;
if (v) {
rval = xfs_dir2_block_removename(args);
goto out_free;
}
rval = xfs_dir2_isleaf(tp, dp, &v);
if (rval)
goto out_free;
if (v)
rval = xfs_dir2_leaf_removename(args);
else else
rval = xfs_dir2_node_removename(&args); rval = xfs_dir2_node_removename(args);
out_free:
kmem_free(args);
return rval; return rval;
} }
...@@ -386,40 +441,54 @@ xfs_dir_replace( ...@@ -386,40 +441,54 @@ xfs_dir_replace(
xfs_bmap_free_t *flist, /* bmap's freeblock list */ xfs_bmap_free_t *flist, /* bmap's freeblock list */
xfs_extlen_t total) /* bmap's total block count */ xfs_extlen_t total) /* bmap's total block count */
{ {
xfs_da_args_t args; struct xfs_da_args *args;
int rval; int rval;
int v; /* type-checking value */ int v; /* type-checking value */
ASSERT(S_ISDIR(dp->i_d.di_mode)); ASSERT(S_ISDIR(dp->i_d.di_mode));
if ((rval = xfs_dir_ino_validate(tp->t_mountp, inum))) rval = xfs_dir_ino_validate(tp->t_mountp, inum);
if (rval)
return rval; return rval;
memset(&args, 0, sizeof(xfs_da_args_t)); args = kmem_zalloc(sizeof(*args), KM_SLEEP | KM_NOFS);
args.name = name->name; if (!args)
args.namelen = name->len; return ENOMEM;
args.filetype = name->type;
args.hashval = dp->i_mount->m_dirnameops->hashname(name); args->name = name->name;
args.inumber = inum; args->namelen = name->len;
args.dp = dp; args->filetype = name->type;
args.firstblock = first; args->hashval = dp->i_mount->m_dirnameops->hashname(name);
args.flist = flist; args->inumber = inum;
args.total = total; args->dp = dp;
args.whichfork = XFS_DATA_FORK; args->firstblock = first;
args.trans = tp; args->flist = flist;
args->total = total;
if (dp->i_d.di_format == XFS_DINODE_FMT_LOCAL) args->whichfork = XFS_DATA_FORK;
rval = xfs_dir2_sf_replace(&args); args->trans = tp;
else if ((rval = xfs_dir2_isblock(tp, dp, &v)))
return rval; if (dp->i_d.di_format == XFS_DINODE_FMT_LOCAL) {
else if (v) rval = xfs_dir2_sf_replace(args);
rval = xfs_dir2_block_replace(&args); goto out_free;
else if ((rval = xfs_dir2_isleaf(tp, dp, &v))) }
return rval;
else if (v) rval = xfs_dir2_isblock(tp, dp, &v);
rval = xfs_dir2_leaf_replace(&args); if (rval)
goto out_free;
if (v) {
rval = xfs_dir2_block_replace(args);
goto out_free;
}
rval = xfs_dir2_isleaf(tp, dp, &v);
if (rval)
goto out_free;
if (v)
rval = xfs_dir2_leaf_replace(args);
else else
rval = xfs_dir2_node_replace(&args); rval = xfs_dir2_node_replace(args);
out_free:
kmem_free(args);
return rval; return rval;
} }
...@@ -434,7 +503,7 @@ xfs_dir_canenter( ...@@ -434,7 +503,7 @@ xfs_dir_canenter(
struct xfs_name *name, /* name of entry to add */ struct xfs_name *name, /* name of entry to add */
uint resblks) uint resblks)
{ {
xfs_da_args_t args; struct xfs_da_args *args;
int rval; int rval;
int v; /* type-checking value */ int v; /* type-checking value */
...@@ -443,29 +512,42 @@ xfs_dir_canenter( ...@@ -443,29 +512,42 @@ xfs_dir_canenter(
ASSERT(S_ISDIR(dp->i_d.di_mode)); ASSERT(S_ISDIR(dp->i_d.di_mode));
memset(&args, 0, sizeof(xfs_da_args_t)); args = kmem_zalloc(sizeof(*args), KM_SLEEP | KM_NOFS);
args.name = name->name; if (!args)
args.namelen = name->len; return ENOMEM;
args.filetype = name->type;
args.hashval = dp->i_mount->m_dirnameops->hashname(name); args->name = name->name;
args.dp = dp; args->namelen = name->len;
args.whichfork = XFS_DATA_FORK; args->filetype = name->type;
args.trans = tp; args->hashval = dp->i_mount->m_dirnameops->hashname(name);
args.op_flags = XFS_DA_OP_JUSTCHECK | XFS_DA_OP_ADDNAME | args->dp = dp;
args->whichfork = XFS_DATA_FORK;
args->trans = tp;
args->op_flags = XFS_DA_OP_JUSTCHECK | XFS_DA_OP_ADDNAME |
XFS_DA_OP_OKNOENT; XFS_DA_OP_OKNOENT;
if (dp->i_d.di_format == XFS_DINODE_FMT_LOCAL) if (dp->i_d.di_format == XFS_DINODE_FMT_LOCAL) {
rval = xfs_dir2_sf_addname(&args); rval = xfs_dir2_sf_addname(args);
else if ((rval = xfs_dir2_isblock(tp, dp, &v))) goto out_free;
return rval; }
else if (v)
rval = xfs_dir2_block_addname(&args); rval = xfs_dir2_isblock(tp, dp, &v);
else if ((rval = xfs_dir2_isleaf(tp, dp, &v))) if (rval)
return rval; goto out_free;
else if (v) if (v) {
rval = xfs_dir2_leaf_addname(&args); rval = xfs_dir2_block_addname(args);
goto out_free;
}
rval = xfs_dir2_isleaf(tp, dp, &v);
if (rval)
goto out_free;
if (v)
rval = xfs_dir2_leaf_addname(args);
else else
rval = xfs_dir2_node_addname(&args); rval = xfs_dir2_node_addname(args);
out_free:
kmem_free(args);
return rval; return rval;
} }
......
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