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

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