Commit 67fd718f authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Dave Chinner

xfs: simplify attr name setup

Replace xfs_attr_name_to_xname with a new xfs_attr_args_init helper that
sets up the basic da_args structure without using a temporary xfs_name
structure.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-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 1bc426a7
...@@ -77,17 +77,26 @@ STATIC int xfs_attr_refillstate(xfs_da_state_t *state); ...@@ -77,17 +77,26 @@ STATIC int xfs_attr_refillstate(xfs_da_state_t *state);
STATIC int STATIC int
xfs_attr_name_to_xname( xfs_attr_args_init(
struct xfs_name *xname, struct xfs_da_args *args,
const unsigned char *aname) struct xfs_inode *dp,
const unsigned char *name,
int flags)
{ {
if (!aname)
if (!name)
return EINVAL; return EINVAL;
xname->name = aname;
xname->len = strlen((char *)aname); memset(args, 0, sizeof(*args));
if (xname->len >= MAXNAMELEN) args->whichfork = XFS_ATTR_FORK;
args->dp = dp;
args->flags = flags;
args->name = name;
args->namelen = strlen((const char *)name);
if (args->namelen >= MAXNAMELEN)
return EFAULT; /* match IRIX behaviour */ return EFAULT; /* match IRIX behaviour */
args->hashval = xfs_da_hashname(args->name, args->namelen);
return 0; return 0;
} }
...@@ -115,7 +124,6 @@ xfs_attr_get( ...@@ -115,7 +124,6 @@ xfs_attr_get(
int flags) int flags)
{ {
struct xfs_da_args args; struct xfs_da_args args;
struct xfs_name xname;
uint lock_mode; uint lock_mode;
int error; int error;
...@@ -127,19 +135,12 @@ xfs_attr_get( ...@@ -127,19 +135,12 @@ xfs_attr_get(
if (!xfs_inode_hasattr(ip)) if (!xfs_inode_hasattr(ip))
return ENOATTR; return ENOATTR;
error = xfs_attr_name_to_xname(&xname, name); error = xfs_attr_args_init(&args, ip, name, flags);
if (error) if (error)
return error; return error;
memset(&args, 0, sizeof(args));
args.name = xname.name;
args.namelen = xname.len;
args.value = value; args.value = value;
args.valuelen = *valuelenp; args.valuelen = *valuelenp;
args.flags = flags;
args.hashval = xfs_da_hashname(args.name, args.namelen);
args.dp = ip;
args.whichfork = XFS_ATTR_FORK;
lock_mode = xfs_ilock_attr_map_shared(ip); lock_mode = xfs_ilock_attr_map_shared(ip);
if (!xfs_inode_hasattr(ip)) if (!xfs_inode_hasattr(ip))
...@@ -208,7 +209,6 @@ xfs_attr_set( ...@@ -208,7 +209,6 @@ xfs_attr_set(
struct xfs_da_args args; struct xfs_da_args args;
struct xfs_bmap_free flist; struct xfs_bmap_free flist;
struct xfs_trans_res tres; struct xfs_trans_res tres;
struct xfs_name xname;
xfs_fsblock_t firstblock; xfs_fsblock_t firstblock;
int rsvd = (flags & ATTR_ROOT) != 0; int rsvd = (flags & ATTR_ROOT) != 0;
int error, err2, committed, local; int error, err2, committed, local;
...@@ -218,10 +218,19 @@ xfs_attr_set( ...@@ -218,10 +218,19 @@ xfs_attr_set(
if (XFS_FORCED_SHUTDOWN(dp->i_mount)) if (XFS_FORCED_SHUTDOWN(dp->i_mount))
return EIO; return EIO;
error = xfs_attr_name_to_xname(&xname, name); error = xfs_attr_args_init(&args, dp, name, flags);
if (error) if (error)
return error; return error;
args.value = value;
args.valuelen = valuelen;
args.firstblock = &firstblock;
args.flist = &flist;
args.op_flags = XFS_DA_OP_ADDNAME | XFS_DA_OP_OKNOENT;
/* Size is now blocks for attribute data */
args.total = xfs_attr_calc_size(dp, args.namelen, valuelen, &local);
error = xfs_qm_dqattach(dp, 0); error = xfs_qm_dqattach(dp, 0);
if (error) if (error)
return error; return error;
...@@ -232,29 +241,13 @@ xfs_attr_set( ...@@ -232,29 +241,13 @@ xfs_attr_set(
*/ */
if (XFS_IFORK_Q(dp) == 0) { if (XFS_IFORK_Q(dp) == 0) {
int sf_size = sizeof(xfs_attr_sf_hdr_t) + int sf_size = sizeof(xfs_attr_sf_hdr_t) +
XFS_ATTR_SF_ENTSIZE_BYNAME(xname.len, valuelen); XFS_ATTR_SF_ENTSIZE_BYNAME(args.namelen, valuelen);
error = xfs_bmap_add_attrfork(dp, sf_size, rsvd); error = xfs_bmap_add_attrfork(dp, sf_size, rsvd);
if (error) if (error)
return error; return error;
} }
memset(&args, 0, sizeof(args));
args.name = xname.name;
args.namelen = xname.len;
args.value = value;
args.valuelen = valuelen;
args.flags = flags;
args.hashval = xfs_da_hashname(args.name, args.namelen);
args.dp = dp;
args.firstblock = &firstblock;
args.flist = &flist;
args.whichfork = XFS_ATTR_FORK;
args.op_flags = XFS_DA_OP_ADDNAME | XFS_DA_OP_OKNOENT;
/* Size is now blocks for attribute data */
args.total = xfs_attr_calc_size(dp, xname.len, valuelen, &local);
/* /*
* Start our first transaction of the day. * Start our first transaction of the day.
* *
...@@ -425,7 +418,6 @@ xfs_attr_remove( ...@@ -425,7 +418,6 @@ xfs_attr_remove(
struct xfs_mount *mp = dp->i_mount; struct xfs_mount *mp = dp->i_mount;
struct xfs_da_args args; struct xfs_da_args args;
struct xfs_bmap_free flist; struct xfs_bmap_free flist;
struct xfs_name xname;
xfs_fsblock_t firstblock; xfs_fsblock_t firstblock;
int error; int error;
...@@ -437,20 +429,12 @@ xfs_attr_remove( ...@@ -437,20 +429,12 @@ xfs_attr_remove(
if (!xfs_inode_hasattr(dp)) if (!xfs_inode_hasattr(dp))
return ENOATTR; return ENOATTR;
error = xfs_attr_name_to_xname(&xname, name); error = xfs_attr_args_init(&args, dp, name, flags);
if (error) if (error)
return error; return error;
memset(&args, 0, sizeof(args));
args.name = xname.name;
args.namelen = xname.len;
args.flags = flags;
args.hashval = xfs_da_hashname(args.name, args.namelen);
args.dp = dp;
args.firstblock = &firstblock; args.firstblock = &firstblock;
args.flist = &flist; args.flist = &flist;
args.total = 0;
args.whichfork = XFS_ATTR_FORK;
/* /*
* we have no control over the attribute names that userspace passes us * we have no control over the attribute names that userspace passes us
......
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