All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chandan Rajendra <chandan@linux.ibm.com>
To: Christoph Hellwig <hch@lst.de>
Cc: linux-xfs@vger.kernel.org,
	Allison Collins <allison.henderson@oracle.com>,
	"Darrick J . Wong" <darrick.wong@oracle.com>
Subject: Re: [PATCH 11/30] xfs: pass an initialized xfs_da_args structure to xfs_attr_set
Date: Fri, 07 Feb 2020 15:12:06 +0530	[thread overview]
Message-ID: <3555829.Ga2YY0DfQR@localhost.localdomain> (raw)
In-Reply-To: <20200129170310.51370-12-hch@lst.de>

On Wednesday, January 29, 2020 10:32 PM Christoph Hellwig wrote: 
> 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: Darrick J. Wong <darrick.wong@oracle.com>
> ---
>  fs/xfs/libxfs/xfs_attr.c | 69 ++++++++++++++++++----------------------
>  fs/xfs/libxfs/xfs_attr.h |  3 +-
>  fs/xfs/xfs_acl.c         | 31 +++++++++---------
>  fs/xfs/xfs_ioctl.c       | 20 +++++++-----
>  fs/xfs/xfs_iops.c        | 13 +++++---
>  fs/xfs/xfs_xattr.c       | 19 +++++++----
>  6 files changed, 81 insertions(+), 74 deletions(-)
> 
> diff --git a/fs/xfs/libxfs/xfs_attr.c b/fs/xfs/libxfs/xfs_attr.c
> index f887d62e0956..eea6d90af276 100644
> --- a/fs/xfs/libxfs/xfs_attr.c
> +++ b/fs/xfs/libxfs/xfs_attr.c
> @@ -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.
>   */
>  int
>  xfs_attr_set(
> -	struct xfs_inode	*dp,
> -	const unsigned char	*name,
> -	size_t			namelen,
> -	unsigned char		*value,
> -	int			valuelen,
> -	int			flags)
> +	struct xfs_da_args	*args)
>  {
> +	struct xfs_inode	*dp = args->dp;
>  	struct xfs_mount	*mp = dp->i_mount;
> -	struct xfs_da_args	args;
>  	struct xfs_trans_res	tres;
> -	int			rsvd = (flags & ATTR_ROOT) != 0;
> +	int			rsvd = (args->flags & ATTR_ROOT) != 0;
>  	int			error, local;
>  	unsigned int		total;
> 
> @@ -356,25 +351,22 @@ xfs_attr_set(
>  	if (error)
>  		return error;
> 
> -	error = xfs_attr_args_init(&args, dp, name, namelen, flags);
> -	if (error)
> -		return error;
> -
> -	args.value = value;
> -	args.valuelen = valuelen;
> +	args->geo = mp->m_attr_geo;
> +	args->whichfork = XFS_ATTR_FORK;
> +	args->hashval = xfs_da_hashname(args->name, args->namelen);
> 
>  	/*
>  	 * 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
>  	 * 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);
> 
> -		args.op_flags |= XFS_DA_OP_ADDNAME;
> -		args.total = xfs_attr_calc_size(&args, &local);
> +		args->op_flags |= XFS_DA_OP_ADDNAME;
> +		args->total = xfs_attr_calc_size(args, &local);
> 
>  		/*
>  		 * If the inode doesn't have an attribute fork, add one.
> @@ -382,8 +374,8 @@ xfs_attr_set(
>  		 */
>  		if (XFS_IFORK_Q(dp) == 0) {
>  			int sf_size = sizeof(struct xfs_attr_sf_hdr) +
> -				XFS_ATTR_SF_ENTSIZE_BYNAME(args.namelen,
> -						valuelen);
> +				XFS_ATTR_SF_ENTSIZE_BYNAME(args->namelen,
> +						args->valuelen);
> 
>  			error = xfs_bmap_add_attrfork(dp, sf_size, rsvd);
>  			if (error)
> @@ -391,10 +383,11 @@ xfs_attr_set(
>  		}
> 
>  		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_logflags = XFS_TRANS_PERM_LOG_RES;
> -		total = args.total;
> +		total = args->total;
>  	} else {
>  		XFS_STATS_INC(mp, xs_attr_remove);
> 
> @@ -407,29 +400,29 @@ xfs_attr_set(
>  	 * operation if necessary
>  	 */
>  	error = xfs_trans_alloc(mp, &tres, total, 0,
> -			rsvd ? XFS_TRANS_RESERVE : 0, &args.trans);
> +			rsvd ? XFS_TRANS_RESERVE : 0, &args->trans);
>  	if (error)
>  		return error;
> 
>  	xfs_ilock(dp, XFS_ILOCK_EXCL);
> -	xfs_trans_ijoin(args.trans, dp, 0);
> -	if (value) {
> +	xfs_trans_ijoin(args->trans, dp, 0);
> +	if (args->value) {
>  		unsigned int	quota_flags = XFS_QMOPT_RES_REGBLKS;
> 
>  		if (rsvd)
>  			quota_flags |= XFS_QMOPT_FORCE_RES;
> -		error = xfs_trans_reserve_quota_nblks(args.trans, dp,
> -				args.total, 0, quota_flags);
> +		error = xfs_trans_reserve_quota_nblks(args->trans, dp,
> +				args->total, 0, quota_flags);
>  		if (error)
>  			goto out_trans_cancel;
> -		error = xfs_attr_set_args(&args);
> +		error = xfs_attr_set_args(args);
>  		if (error)
>  			goto out_trans_cancel;
>  		/* shortform attribute has already been committed */
> -		if (!args.trans)
> +		if (!args->trans)
>  			goto out_unlock;
>  	} else {
> -		error = xfs_attr_remove_args(&args);
> +		error = xfs_attr_remove_args(args);
>  		if (error)
>  			goto out_trans_cancel;
>  	}
> @@ -439,23 +432,23 @@ xfs_attr_set(
>  	 * transaction goes to disk before returning to the user.
>  	 */
>  	if (mp->m_flags & XFS_MOUNT_WSYNC)
> -		xfs_trans_set_sync(args.trans);
> +		xfs_trans_set_sync(args->trans);
> 
> -	if ((flags & ATTR_KERNOTIME) == 0)
> -		xfs_trans_ichgtime(args.trans, dp, XFS_ICHGTIME_CHG);
> +	if ((args->flags & ATTR_KERNOTIME) == 0)
> +		xfs_trans_ichgtime(args->trans, dp, XFS_ICHGTIME_CHG);
> 
>  	/*
>  	 * Commit the last in the sequence of transactions.
>  	 */
> -	xfs_trans_log_inode(args.trans, dp, XFS_ILOG_CORE);
> -	error = xfs_trans_commit(args.trans);
> +	xfs_trans_log_inode(args->trans, dp, XFS_ILOG_CORE);
> +	error = xfs_trans_commit(args->trans);
>  out_unlock:
>  	xfs_iunlock(dp, XFS_ILOCK_EXCL);
>  	return error;
> 
>  out_trans_cancel:
> -	if (args.trans)
> -		xfs_trans_cancel(args.trans);
> +	if (args->trans)
> +		xfs_trans_cancel(args->trans);
>  	goto out_unlock;
>  }
> 
> diff --git a/fs/xfs/libxfs/xfs_attr.h b/fs/xfs/libxfs/xfs_attr.h
> index db58a6c7dea5..07ca543db831 100644
> --- a/fs/xfs/libxfs/xfs_attr.h
> +++ b/fs/xfs/libxfs/xfs_attr.h
> @@ -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,
>  		 size_t namelen, unsigned char **value, int *valuelenp,
>  		 int flags);
> -int xfs_attr_set(struct xfs_inode *dp, const unsigned char *name,
> -		 size_t namelen, unsigned char *value, int valuelen, int flags);
> +int xfs_attr_set(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_list(struct xfs_inode *dp, char *buffer, int bufsize,
> diff --git a/fs/xfs/xfs_acl.c b/fs/xfs/xfs_acl.c
> index 4e76063ff956..e9ae7cbe1973 100644
> --- a/fs/xfs/xfs_acl.c
> +++ b/fs/xfs/xfs_acl.c
> @@ -166,41 +166,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.
> diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
> index cfdd80b4ea2d..47a88b5cfa63 100644
> --- a/fs/xfs/xfs_ioctl.c
> +++ b/fs/xfs/xfs_ioctl.c
> @@ -389,9 +389,13 @@ xfs_attrmulti_attr_set(
>  	uint32_t		len,
>  	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;
> -	size_t			namelen;
> 
>  	if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
>  		return -EPERM;
> @@ -399,16 +403,16 @@ xfs_attrmulti_attr_set(
>  	if (ubuf) {
>  		if (len > XFS_XATTR_SIZE_MAX)
>  			return -EINVAL;
> -		kbuf = memdup_user(ubuf, len);
> -		if (IS_ERR(kbuf))
> -			return PTR_ERR(kbuf);
> +		args.value = memdup_user(ubuf, len);
> +		if (IS_ERR(args.value))
> +			return PTR_ERR(args.value);
> +		args.valuelen = len;
>  	}
> 
> -	namelen = strlen(name);
> -	error = xfs_attr_set(XFS_I(inode), name, namelen, kbuf, len, flags);
> +	error = xfs_attr_set(&args);
>  	if (!error)
>  		xfs_forget_acl(inode, name, flags);
> -	kfree(kbuf);
> +	kfree(args.value);
>  	return error;
>  }
> 
> diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
> index 81f2f93caec0..94cd4254656c 100644
> --- a/fs/xfs/xfs_iops.c
> +++ b/fs/xfs/xfs_iops.c
> @@ -50,10 +50,15 @@ xfs_initxattrs(
>  	int			error = 0;
> 
>  	for (xattr = xattr_array; xattr->name != NULL; xattr++) {
> -		error = xfs_attr_set(ip, xattr->name,
> -				     strlen(xattr->name),
> -				     xattr->value, xattr->value_len,
> -				     ATTR_SECURE);
> +		struct xfs_da_args	args = {
> +			.dp		= ip,
> +			.flags		= ATTR_SECURE,
> +			.name		= xattr->name,
> +			.namelen	= strlen(xattr->name),
> +			.value		= xattr->value,
> +			.valuelen	= xattr->value_len,
> +		};
> +		error = xfs_attr_set(&args);
>  		if (error < 0)
>  			break;
>  	}
> diff --git a/fs/xfs/xfs_xattr.c b/fs/xfs/xfs_xattr.c
> index 1670bfbc9ad2..09f967f97699 100644
> --- a/fs/xfs/xfs_xattr.c
> +++ b/fs/xfs/xfs_xattr.c
> @@ -66,20 +66,25 @@ xfs_xattr_set(const struct xattr_handler *handler, struct dentry *unused,
>  		struct inode *inode, const char *name, const void *value,
>  		size_t size, int flags)
>  {
> -	int			xflags = handler->flags;
> -	struct xfs_inode	*ip = XFS_I(inode);
> +	struct xfs_da_args	args = {
> +		.dp		= XFS_I(inode),
> +		.flags		= handler->flags,
> +		.name		= name,
> +		.namelen	= strlen(name),
> +		.value		= (unsigned char *)value,

Since xfs_da_args.value is of type "void *', Wouldn't it be more uniform if
'value' is typecasted with (void *)? 

Apart from the above very trival nit, the changes look good to me,

Reviewed-by: Chandan Rajendra <chandanrlinux@gmail.com>

> +		.valuelen	= size,
> +	};
>  	int			error;
> 
>  	/* Convert Linux syscall to XFS internal ATTR flags */
>  	if (flags & XATTR_CREATE)
> -		xflags |= ATTR_CREATE;
> +		args.flags |= ATTR_CREATE;
>  	if (flags & XATTR_REPLACE)
> -		xflags |= ATTR_REPLACE;
> +		args.flags |= ATTR_REPLACE;
> 
> -	error = xfs_attr_set(ip, (unsigned char *)name, strlen(name),
> -				(void *)value, size, xflags);
> +	error = xfs_attr_set(&args);
>  	if (!error)
> -		xfs_forget_acl(inode, name, xflags);
> +		xfs_forget_acl(inode, name, args.flags);
>  	return error;
>  }
> 
> 


-- 
chandan




  reply	other threads:[~2020-02-07  9:39 UTC|newest]

Thread overview: 60+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-29 17:02 clean up the attr interface v3 Christoph Hellwig
2020-01-29 17:02 ` [PATCH 01/30] xfs: reject invalid flags combinations in XFS_IOC_ATTRLIST_BY_HANDLE Christoph Hellwig
2020-02-05 13:46   ` Chandan Rajendra
2020-01-29 17:02 ` [PATCH 02/30] xfs: remove the ATTR_INCOMPLETE flag Christoph Hellwig
2020-01-29 17:02 ` [PATCH 03/30] xfs: merge xfs_attr_remove into xfs_attr_set Christoph Hellwig
2020-02-06  8:00   ` Chandan Rajendra
2020-01-29 17:02 ` [PATCH 04/30] xfs: merge xfs_attrmulti_attr_remove into xfs_attrmulti_attr_set Christoph Hellwig
2020-02-06  9:21   ` Chandan Rajendra
2020-01-29 17:02 ` [PATCH 05/30] xfs: use strndup_user in XFS_IOC_ATTRMULTI_BY_HANDLE Christoph Hellwig
2020-02-06 10:33   ` Chandan Rajendra
2020-01-29 17:02 ` [PATCH 06/30] xfs: factor out a helper for a single XFS_IOC_ATTRMULTI_BY_HANDLE op Christoph Hellwig
2020-02-07  5:20   ` Chandan Rajendra
2020-01-29 17:02 ` [PATCH 07/30] xfs: remove the name == NULL check from xfs_attr_args_init Christoph Hellwig
2020-02-07  6:15   ` Chandan Rajendra
2020-01-29 17:02 ` [PATCH 08/30] xfs: remove the MAXNAMELEN " Christoph Hellwig
2020-02-07  6:56   ` Chandan Rajendra
2020-01-29 17:02 ` [PATCH 09/30] xfs: move struct xfs_da_args to xfs_types.h Christoph Hellwig
2020-01-29 17:02 ` [PATCH 10/30] xfs: turn xfs_da_args.value into a void pointer Christoph Hellwig
2020-01-29 17:02 ` [PATCH 11/30] xfs: pass an initialized xfs_da_args structure to xfs_attr_set Christoph Hellwig
2020-02-07  9:42   ` Chandan Rajendra [this message]
2020-02-17 13:48     ` Christoph Hellwig
2020-01-29 17:02 ` [PATCH 12/30] xfs: pass an initialized xfs_da_args to xfs_attr_get Christoph Hellwig
2020-02-07 13:13   ` Chandan Rajendra
2020-01-29 17:02 ` [PATCH 13/30] xfs: remove the xfs_inode argument to xfs_attr_get_ilocked Christoph Hellwig
2020-02-07 13:19   ` Chandan Rajendra
2020-01-29 17:02 ` [PATCH 14/30] xfs: remove ATTR_KERNOVAL Christoph Hellwig
2020-02-08  4:36   ` Chandan Rajendra
2020-01-29 17:02 ` [PATCH 15/30] xfs: remove ATTR_ALLOC and XFS_DA_OP_ALLOCVAL Christoph Hellwig
2020-02-08  5:13   ` Chandan Rajendra
2020-01-29 17:02 ` [PATCH 16/30] xfs: replace ATTR_KERNOTIME with XFS_DA_OP_NOTIME Christoph Hellwig
2020-02-08 11:35   ` Chandan Rajendra
2020-01-29 17:02 ` [PATCH 17/30] xfs: factor out a xfs_attr_match helper Christoph Hellwig
2020-02-08 12:48   ` Chandan Rajendra
2020-01-29 17:02 ` [PATCH 18/30] xfs: cleanup struct xfs_attr_list_context Christoph Hellwig
2020-02-08 15:53   ` Chandan Rajendra
2020-01-29 17:02 ` [PATCH 19/30] xfs: remove the unused ATTR_ENTRY macro Christoph Hellwig
2020-01-29 17:02 ` [PATCH 20/30] xfs: open code ATTR_ENTSIZE Christoph Hellwig
2020-02-09  6:57   ` Chandan Rajendra
2020-01-29 17:03 ` [PATCH 21/30] xfs: move the legacy xfs_attr_list to xfs_ioctl.c Christoph Hellwig
2020-02-09  7:44   ` Chandan Rajendra
2020-02-17 13:48     ` Christoph Hellwig
2020-01-29 17:03 ` [PATCH 22/30] xfs: rename xfs_attr_list_int to xfs_attr_list Christoph Hellwig
2020-02-09  7:52   ` Chandan Rajendra
2020-01-29 17:03 ` [PATCH 23/30] xfs: lift common checks into xfs_ioc_attr_list Christoph Hellwig
2020-02-09  8:03   ` Chandan Rajendra
2020-01-29 17:03 ` [PATCH 24/30] xfs: lift buffer allocation " Christoph Hellwig
2020-02-09  8:24   ` Chandan Rajendra
2020-01-29 17:03 ` [PATCH 25/30] xfs: lift cursor copy in/out " Christoph Hellwig
2020-02-10  6:02   ` Chandan Rajendra
2020-01-29 17:03 ` [PATCH 26/30] xfs: improve xfs_forget_acl Christoph Hellwig
2020-02-10  6:45   ` Chandan Rajendra
2020-02-17 13:48     ` Christoph Hellwig
2020-01-29 17:03 ` [PATCH 27/30] xfs: clean up the ATTR_REPLACE checks Christoph Hellwig
2020-02-10  6:57   ` Chandan Rajendra
2020-01-29 17:03 ` [PATCH 28/30] xfs: clean up the attr flag confusion Christoph Hellwig
2020-02-10 13:19   ` Chandan Rajendra
2020-01-29 17:03 ` [PATCH 29/30] xfs: remove XFS_DA_OP_INCOMPLETE Christoph Hellwig
2020-02-10 13:59   ` Chandan Rajendra
2020-01-29 17:03 ` [PATCH 30/30] xfs: embedded the attrlist cursor into struct xfs_attr_list_context Christoph Hellwig
2020-02-10 14:57   ` Chandan Rajendra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3555829.Ga2YY0DfQR@localhost.localdomain \
    --to=chandan@linux.ibm.com \
    --cc=allison.henderson@oracle.com \
    --cc=darrick.wong@oracle.com \
    --cc=hch@lst.de \
    --cc=linux-xfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.