xfs: pass an initialized xfs_da_args structure to xfs_attr_set

Instead of converting from one style of arguments to another in
xfs_attr_set, pass the structure from higher up in the call chain.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Chandan Rajendra <chandanrlinux@gmail.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
This commit is contained in:
Christoph Hellwig 2020-02-26 17:30:33 -08:00 committed by Darrick J. Wong
parent ead189adb8
commit a254462243
6 changed files with 87 additions and 74 deletions

View File

@ -330,22 +330,17 @@ xfs_attr_remove_args(
} }
/* /*
* Note: If value is NULL the attribute will be removed, just like the * Note: If args->value is NULL the attribute will be removed, just like the
* Linux ->setattr API. * Linux ->setattr API.
*/ */
int int
xfs_attr_set( xfs_attr_set(
struct xfs_inode *dp, struct xfs_da_args *args)
const unsigned char *name,
size_t namelen,
unsigned char *value,
int valuelen,
int flags)
{ {
struct xfs_inode *dp = args->dp;
struct xfs_mount *mp = dp->i_mount; struct xfs_mount *mp = dp->i_mount;
struct xfs_da_args args;
struct xfs_trans_res tres; struct xfs_trans_res tres;
int rsvd = (flags & ATTR_ROOT) != 0; int rsvd = (args->flags & ATTR_ROOT) != 0;
int error, local; int error, local;
unsigned int total; unsigned int total;
@ -356,25 +351,22 @@ xfs_attr_set(
if (error) if (error)
return error; return error;
error = xfs_attr_args_init(&args, dp, name, namelen, flags); args->geo = mp->m_attr_geo;
if (error) args->whichfork = XFS_ATTR_FORK;
return error; args->hashval = xfs_da_hashname(args->name, args->namelen);
args.value = value;
args.valuelen = valuelen;
/* /*
* We have no control over the attribute names that userspace passes us * We have no control over the attribute names that userspace passes us
* to remove, so we have to allow the name lookup prior to attribute * to remove, so we have to allow the name lookup prior to attribute
* removal to fail as well. * removal to fail as well.
*/ */
args.op_flags = XFS_DA_OP_OKNOENT; args->op_flags = XFS_DA_OP_OKNOENT;
if (value) { if (args->value) {
XFS_STATS_INC(mp, xs_attr_set); XFS_STATS_INC(mp, xs_attr_set);
args.op_flags |= XFS_DA_OP_ADDNAME; args->op_flags |= XFS_DA_OP_ADDNAME;
args.total = xfs_attr_calc_size(&args, &local); args->total = xfs_attr_calc_size(args, &local);
/* /*
* If the inode doesn't have an attribute fork, add one. * If the inode doesn't have an attribute fork, add one.
@ -382,8 +374,8 @@ xfs_attr_set(
*/ */
if (XFS_IFORK_Q(dp) == 0) { if (XFS_IFORK_Q(dp) == 0) {
int sf_size = sizeof(struct xfs_attr_sf_hdr) + int sf_size = sizeof(struct xfs_attr_sf_hdr) +
XFS_ATTR_SF_ENTSIZE_BYNAME(args.namelen, XFS_ATTR_SF_ENTSIZE_BYNAME(args->namelen,
valuelen); args->valuelen);
error = xfs_bmap_add_attrfork(dp, sf_size, rsvd); error = xfs_bmap_add_attrfork(dp, sf_size, rsvd);
if (error) if (error)
@ -391,10 +383,11 @@ xfs_attr_set(
} }
tres.tr_logres = M_RES(mp)->tr_attrsetm.tr_logres + tres.tr_logres = M_RES(mp)->tr_attrsetm.tr_logres +
M_RES(mp)->tr_attrsetrt.tr_logres * args.total; M_RES(mp)->tr_attrsetrt.tr_logres *
args->total;
tres.tr_logcount = XFS_ATTRSET_LOG_COUNT; tres.tr_logcount = XFS_ATTRSET_LOG_COUNT;
tres.tr_logflags = XFS_TRANS_PERM_LOG_RES; tres.tr_logflags = XFS_TRANS_PERM_LOG_RES;
total = args.total; total = args->total;
} else { } else {
XFS_STATS_INC(mp, xs_attr_remove); XFS_STATS_INC(mp, xs_attr_remove);
@ -407,29 +400,29 @@ xfs_attr_set(
* operation if necessary * operation if necessary
*/ */
error = xfs_trans_alloc(mp, &tres, total, 0, error = xfs_trans_alloc(mp, &tres, total, 0,
rsvd ? XFS_TRANS_RESERVE : 0, &args.trans); rsvd ? XFS_TRANS_RESERVE : 0, &args->trans);
if (error) if (error)
return error; return error;
xfs_ilock(dp, XFS_ILOCK_EXCL); xfs_ilock(dp, XFS_ILOCK_EXCL);
xfs_trans_ijoin(args.trans, dp, 0); xfs_trans_ijoin(args->trans, dp, 0);
if (value) { if (args->value) {
unsigned int quota_flags = XFS_QMOPT_RES_REGBLKS; unsigned int quota_flags = XFS_QMOPT_RES_REGBLKS;
if (rsvd) if (rsvd)
quota_flags |= XFS_QMOPT_FORCE_RES; quota_flags |= XFS_QMOPT_FORCE_RES;
error = xfs_trans_reserve_quota_nblks(args.trans, dp, error = xfs_trans_reserve_quota_nblks(args->trans, dp,
args.total, 0, quota_flags); args->total, 0, quota_flags);
if (error) if (error)
goto out_trans_cancel; goto out_trans_cancel;
error = xfs_attr_set_args(&args); error = xfs_attr_set_args(args);
if (error) if (error)
goto out_trans_cancel; goto out_trans_cancel;
/* shortform attribute has already been committed */ /* shortform attribute has already been committed */
if (!args.trans) if (!args->trans)
goto out_unlock; goto out_unlock;
} else { } else {
error = xfs_attr_remove_args(&args); error = xfs_attr_remove_args(args);
if (error) if (error)
goto out_trans_cancel; goto out_trans_cancel;
} }
@ -439,23 +432,23 @@ xfs_attr_set(
* transaction goes to disk before returning to the user. * transaction goes to disk before returning to the user.
*/ */
if (mp->m_flags & XFS_MOUNT_WSYNC) if (mp->m_flags & XFS_MOUNT_WSYNC)
xfs_trans_set_sync(args.trans); xfs_trans_set_sync(args->trans);
if ((flags & ATTR_KERNOTIME) == 0) if ((args->flags & ATTR_KERNOTIME) == 0)
xfs_trans_ichgtime(args.trans, dp, XFS_ICHGTIME_CHG); xfs_trans_ichgtime(args->trans, dp, XFS_ICHGTIME_CHG);
/* /*
* Commit the last in the sequence of transactions. * Commit the last in the sequence of transactions.
*/ */
xfs_trans_log_inode(args.trans, dp, XFS_ILOG_CORE); xfs_trans_log_inode(args->trans, dp, XFS_ILOG_CORE);
error = xfs_trans_commit(args.trans); error = xfs_trans_commit(args->trans);
out_unlock: out_unlock:
xfs_iunlock(dp, XFS_ILOCK_EXCL); xfs_iunlock(dp, XFS_ILOCK_EXCL);
return error; return error;
out_trans_cancel: out_trans_cancel:
if (args.trans) if (args->trans)
xfs_trans_cancel(args.trans); xfs_trans_cancel(args->trans);
goto out_unlock; goto out_unlock;
} }

View File

@ -149,8 +149,7 @@ int xfs_attr_get_ilocked(struct xfs_inode *ip, struct xfs_da_args *args);
int xfs_attr_get(struct xfs_inode *ip, const unsigned char *name, int xfs_attr_get(struct xfs_inode *ip, const unsigned char *name,
size_t namelen, unsigned char **value, int *valuelenp, size_t namelen, unsigned char **value, int *valuelenp,
int flags); int flags);
int xfs_attr_set(struct xfs_inode *dp, const unsigned char *name, int xfs_attr_set(struct xfs_da_args *args);
size_t namelen, unsigned char *value, int valuelen, int flags);
int xfs_attr_set_args(struct xfs_da_args *args); int xfs_attr_set_args(struct xfs_da_args *args);
int xfs_attr_remove_args(struct xfs_da_args *args); int xfs_attr_remove_args(struct xfs_da_args *args);
int xfs_attr_list(struct xfs_inode *dp, char *buffer, int bufsize, int xfs_attr_list(struct xfs_inode *dp, char *buffer, int bufsize,

View File

@ -14,6 +14,8 @@
#include "xfs_trace.h" #include "xfs_trace.h"
#include "xfs_error.h" #include "xfs_error.h"
#include "xfs_acl.h" #include "xfs_acl.h"
#include "xfs_da_format.h"
#include "xfs_da_btree.h"
#include <linux/posix_acl_xattr.h> #include <linux/posix_acl_xattr.h>
@ -170,41 +172,42 @@ xfs_get_acl(struct inode *inode, int type)
int int
__xfs_set_acl(struct inode *inode, struct posix_acl *acl, int type) __xfs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
{ {
struct xfs_inode *ip = XFS_I(inode); struct xfs_inode *ip = XFS_I(inode);
unsigned char *ea_name; struct xfs_da_args args = {
struct xfs_acl *xfs_acl = NULL; .dp = ip,
int len = 0; .flags = ATTR_ROOT,
int error; };
int error;
switch (type) { switch (type) {
case ACL_TYPE_ACCESS: case ACL_TYPE_ACCESS:
ea_name = SGI_ACL_FILE; args.name = SGI_ACL_FILE;
break; break;
case ACL_TYPE_DEFAULT: case ACL_TYPE_DEFAULT:
if (!S_ISDIR(inode->i_mode)) if (!S_ISDIR(inode->i_mode))
return acl ? -EACCES : 0; return acl ? -EACCES : 0;
ea_name = SGI_ACL_DEFAULT; args.name = SGI_ACL_DEFAULT;
break; break;
default: default:
return -EINVAL; return -EINVAL;
} }
args.namelen = strlen(args.name);
if (acl) { if (acl) {
len = XFS_ACL_MAX_SIZE(ip->i_mount); args.valuelen = XFS_ACL_MAX_SIZE(ip->i_mount);
xfs_acl = kmem_zalloc_large(len, 0); args.value = kmem_zalloc_large(args.valuelen, 0);
if (!xfs_acl) if (!args.value)
return -ENOMEM; return -ENOMEM;
xfs_acl_to_disk(xfs_acl, acl); xfs_acl_to_disk(args.value, acl);
/* subtract away the unused acl entries */ /* subtract away the unused acl entries */
len -= sizeof(struct xfs_acl_entry) * args.valuelen -= sizeof(struct xfs_acl_entry) *
(XFS_ACL_MAX_ENTRIES(ip->i_mount) - acl->a_count); (XFS_ACL_MAX_ENTRIES(ip->i_mount) - acl->a_count);
} }
error = xfs_attr_set(ip, ea_name, strlen(ea_name), error = xfs_attr_set(&args);
(unsigned char *)xfs_acl, len, ATTR_ROOT); kmem_free(args.value);
kmem_free(xfs_acl);
/* /*
* If the attribute didn't exist to start with that's fine. * If the attribute didn't exist to start with that's fine.

View File

@ -35,6 +35,8 @@
#include "xfs_health.h" #include "xfs_health.h"
#include "xfs_reflink.h" #include "xfs_reflink.h"
#include "xfs_ioctl.h" #include "xfs_ioctl.h"
#include "xfs_da_format.h"
#include "xfs_da_btree.h"
#include <linux/mount.h> #include <linux/mount.h>
#include <linux/namei.h> #include <linux/namei.h>
@ -389,9 +391,13 @@ xfs_attrmulti_attr_set(
uint32_t len, uint32_t len,
uint32_t flags) uint32_t flags)
{ {
unsigned char *kbuf = NULL; struct xfs_da_args args = {
.dp = XFS_I(inode),
.flags = flags,
.name = name,
.namelen = strlen(name),
};
int error; int error;
size_t namelen;
if (IS_IMMUTABLE(inode) || IS_APPEND(inode)) if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
return -EPERM; return -EPERM;
@ -399,16 +405,16 @@ xfs_attrmulti_attr_set(
if (ubuf) { if (ubuf) {
if (len > XFS_XATTR_SIZE_MAX) if (len > XFS_XATTR_SIZE_MAX)
return -EINVAL; return -EINVAL;
kbuf = memdup_user(ubuf, len); args.value = memdup_user(ubuf, len);
if (IS_ERR(kbuf)) if (IS_ERR(args.value))
return PTR_ERR(kbuf); return PTR_ERR(args.value);
args.valuelen = len;
} }
namelen = strlen(name); error = xfs_attr_set(&args);
error = xfs_attr_set(XFS_I(inode), name, namelen, kbuf, len, flags);
if (!error) if (!error)
xfs_forget_acl(inode, name, flags); xfs_forget_acl(inode, name, flags);
kfree(kbuf); kfree(args.value);
return error; return error;
} }

View File

@ -50,10 +50,15 @@ xfs_initxattrs(
int error = 0; int error = 0;
for (xattr = xattr_array; xattr->name != NULL; xattr++) { for (xattr = xattr_array; xattr->name != NULL; xattr++) {
error = xfs_attr_set(ip, xattr->name, struct xfs_da_args args = {
strlen(xattr->name), .dp = ip,
xattr->value, xattr->value_len, .flags = ATTR_SECURE,
ATTR_SECURE); .name = xattr->name,
.namelen = strlen(xattr->name),
.value = xattr->value,
.valuelen = xattr->value_len,
};
error = xfs_attr_set(&args);
if (error < 0) if (error < 0)
break; break;
} }

View File

@ -12,6 +12,8 @@
#include "xfs_inode.h" #include "xfs_inode.h"
#include "xfs_attr.h" #include "xfs_attr.h"
#include "xfs_acl.h" #include "xfs_acl.h"
#include "xfs_da_format.h"
#include "xfs_da_btree.h"
#include <linux/posix_acl_xattr.h> #include <linux/posix_acl_xattr.h>
#include <linux/xattr.h> #include <linux/xattr.h>
@ -66,20 +68,25 @@ xfs_xattr_set(const struct xattr_handler *handler, struct dentry *unused,
struct inode *inode, const char *name, const void *value, struct inode *inode, const char *name, const void *value,
size_t size, int flags) size_t size, int flags)
{ {
int xflags = handler->flags; struct xfs_da_args args = {
struct xfs_inode *ip = XFS_I(inode); .dp = XFS_I(inode),
.flags = handler->flags,
.name = name,
.namelen = strlen(name),
.value = (void *)value,
.valuelen = size,
};
int error; int error;
/* Convert Linux syscall to XFS internal ATTR flags */ /* Convert Linux syscall to XFS internal ATTR flags */
if (flags & XATTR_CREATE) if (flags & XATTR_CREATE)
xflags |= ATTR_CREATE; args.flags |= ATTR_CREATE;
if (flags & XATTR_REPLACE) if (flags & XATTR_REPLACE)
xflags |= ATTR_REPLACE; args.flags |= ATTR_REPLACE;
error = xfs_attr_set(ip, (unsigned char *)name, strlen(name), error = xfs_attr_set(&args);
(void *)value, size, xflags);
if (!error) if (!error)
xfs_forget_acl(inode, name, xflags); xfs_forget_acl(inode, name, args.flags);
return error; return error;
} }