Commit d29f781c authored by Allison Henderson's avatar Allison Henderson Committed by Darrick J. Wong
Browse files

xfs: Remove all strlen in all xfs_attr_* functions for attr names.



This helps to pre-simplify the extra handling of the null terminator in
delayed operations which use memcpy rather than strlen.  Later
when we introduce parent pointers, attribute names will become binary,
so strlen will not work at all.  Removing uses of strlen now will
help reduce complexities later

Signed-off-by: default avatarAllison Collins <allison.henderson@oracle.com>
Reviewed-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: default avatarBrian Foster <bfoster@redhat.com>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
parent 780d2905
Loading
Loading
Loading
Loading
+8 −4
Original line number Diff line number Diff line
@@ -62,6 +62,7 @@ xfs_attr_args_init(
	struct xfs_da_args	*args,
	struct xfs_inode	*dp,
	const unsigned char	*name,
	size_t			namelen,
	int			flags)
{

@@ -74,7 +75,7 @@ xfs_attr_args_init(
	args->dp = dp;
	args->flags = flags;
	args->name = name;
	args->namelen = strlen((const char *)name);
	args->namelen = namelen;
	if (args->namelen >= MAXNAMELEN)
		return -EFAULT;		/* match IRIX behaviour */

@@ -139,6 +140,7 @@ int
xfs_attr_get(
	struct xfs_inode	*ip,
	const unsigned char	*name,
	size_t			namelen,
	unsigned char		**value,
	int			*valuelenp,
	int			flags)
@@ -154,7 +156,7 @@ xfs_attr_get(
	if (XFS_FORCED_SHUTDOWN(ip->i_mount))
		return -EIO;

	error = xfs_attr_args_init(&args, ip, name, flags);
	error = xfs_attr_args_init(&args, ip, name, namelen, flags);
	if (error)
		return error;

@@ -338,6 +340,7 @@ int
xfs_attr_set(
	struct xfs_inode	*dp,
	const unsigned char	*name,
	size_t			namelen,
	unsigned char		*value,
	int			valuelen,
	int			flags)
@@ -353,7 +356,7 @@ xfs_attr_set(
	if (XFS_FORCED_SHUTDOWN(dp->i_mount))
		return -EIO;

	error = xfs_attr_args_init(&args, dp, name, flags);
	error = xfs_attr_args_init(&args, dp, name, namelen, flags);
	if (error)
		return error;

@@ -442,6 +445,7 @@ int
xfs_attr_remove(
	struct xfs_inode	*dp,
	const unsigned char	*name,
	size_t			namelen,
	int			flags)
{
	struct xfs_mount	*mp = dp->i_mount;
@@ -453,7 +457,7 @@ xfs_attr_remove(
	if (XFS_FORCED_SHUTDOWN(dp->i_mount))
		return -EIO;

	error = xfs_attr_args_init(&args, dp, name, flags);
	error = xfs_attr_args_init(&args, dp, name, namelen, flags);
	if (error)
		return error;

+5 −3
Original line number Diff line number Diff line
@@ -148,11 +148,13 @@ int xfs_attr_list_int(struct xfs_attr_list_context *);
int xfs_inode_hasattr(struct xfs_inode *ip);
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,
		 unsigned char **value, int *valuelenp, int flags);
		 size_t namelen, unsigned char **value, int *valuelenp,
		 int flags);
int xfs_attr_set(struct xfs_inode *dp, const unsigned char *name,
		 unsigned char *value, int valuelen, int flags);
		 size_t namelen, unsigned char *value, int valuelen, int flags);
int xfs_attr_set_args(struct xfs_da_args *args);
int xfs_attr_remove(struct xfs_inode *dp, const unsigned char *name, int flags);
int xfs_attr_remove(struct xfs_inode *dp, const unsigned char *name,
		    size_t namelen, int flags);
int xfs_attr_remove_args(struct xfs_da_args *args);
int xfs_attr_list(struct xfs_inode *dp, char *buffer, int bufsize,
		  int flags, struct attrlist_cursor_kern *cursor);
+7 −4
Original line number Diff line number Diff line
@@ -145,7 +145,8 @@ xfs_get_acl(struct inode *inode, int type)
	 * go out to the disk.
	 */
	len = XFS_ACL_MAX_SIZE(ip->i_mount);
	error = xfs_attr_get(ip, ea_name, (unsigned char **)&xfs_acl, &len,
	error = xfs_attr_get(ip, ea_name, strlen(ea_name),
				(unsigned char **)&xfs_acl, &len,
				ATTR_ALLOC | ATTR_ROOT);
	if (error) {
		/*
@@ -196,15 +197,17 @@ __xfs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
		len -= sizeof(struct xfs_acl_entry) *
			 (XFS_ACL_MAX_ENTRIES(ip->i_mount) - acl->a_count);

		error = xfs_attr_set(ip, ea_name, (unsigned char *)xfs_acl,
				len, ATTR_ROOT);
		error = xfs_attr_set(ip, ea_name, strlen(ea_name),
				     (unsigned char *)xfs_acl, len, ATTR_ROOT);

		kmem_free(xfs_acl);
	} else {
		/*
		 * A NULL ACL argument means we want to remove the ACL.
		 */
		error = xfs_attr_remove(ip, ea_name, ATTR_ROOT);
		error = xfs_attr_remove(ip, ea_name,
					strlen(ea_name),
					ATTR_ROOT);

		/*
		 * If the attribute didn't exist to start with that's fine.
+10 −3
Original line number Diff line number Diff line
@@ -357,6 +357,7 @@ xfs_attrmulti_attr_get(
{
	unsigned char		*kbuf;
	int			error = -EFAULT;
	size_t			namelen;

	if (*len > XFS_XATTR_SIZE_MAX)
		return -EINVAL;
@@ -364,7 +365,9 @@ xfs_attrmulti_attr_get(
	if (!kbuf)
		return -ENOMEM;

	error = xfs_attr_get(XFS_I(inode), name, &kbuf, (int *)len, flags);
	namelen = strlen(name);
	error = xfs_attr_get(XFS_I(inode), name, namelen, &kbuf, (int *)len,
			     flags);
	if (error)
		goto out_kfree;

@@ -386,6 +389,7 @@ xfs_attrmulti_attr_set(
{
	unsigned char		*kbuf;
	int			error;
	size_t			namelen;

	if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
		return -EPERM;
@@ -396,7 +400,8 @@ xfs_attrmulti_attr_set(
	if (IS_ERR(kbuf))
		return PTR_ERR(kbuf);

	error = xfs_attr_set(XFS_I(inode), name, kbuf, len, flags);
	namelen = strlen(name);
	error = xfs_attr_set(XFS_I(inode), name, namelen, kbuf, len, flags);
	if (!error)
		xfs_forget_acl(inode, name, flags);
	kfree(kbuf);
@@ -410,10 +415,12 @@ xfs_attrmulti_attr_remove(
	uint32_t		flags)
{
	int			error;
	size_t			namelen;

	if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
		return -EPERM;
	error = xfs_attr_remove(XFS_I(inode), name, flags);
	namelen = strlen(name);
	error = xfs_attr_remove(XFS_I(inode), name, namelen, flags);
	if (!error)
		xfs_forget_acl(inode, name, flags);
	return error;
+4 −2
Original line number Diff line number Diff line
@@ -50,8 +50,10 @@ xfs_initxattrs(
	int			error = 0;

	for (xattr = xattr_array; xattr->name != NULL; xattr++) {
		error = xfs_attr_set(ip, xattr->name, xattr->value,
				      xattr->value_len, ATTR_SECURE);
		error = xfs_attr_set(ip, xattr->name,
				     strlen(xattr->name),
				     xattr->value, xattr->value_len,
				     ATTR_SECURE);
		if (error < 0)
			break;
	}
Loading