Skip to contentSkip to conversation

Delayed Attributes

PATCH Superseded Allison Collins 4 participants 64 messages Sep 5, 2019 – Sep 25, 2019 XFS filesystem Page 1 of 2

v3 of 29 Superseded Latest is v29 →

lore
Share & tools
lore
#0 lore raw

v3 cover Delayed Attributes

Hi all,

This set is a subset of a larger series for parent pointers. Delayed attributes allow attribute operations (set and remove) to be logged and committed in the same way that other delayed operations do. This will help break up more complex operations when we later introduce parent pointers which can be used in a number of optimizations. Since delayed attributes can be implemented as a stand alone feature, I've decided to subdivide the set to help make it more manageable. Delayed attributes may also provide the infastructure to later break up large attributes into smaller transactions instead of one large bwrite.

Changes since v2:
Mostly review updates collected since v2. Patch 17 is new and adds a new feature bit that is enabled through mkfs.xfs -n delattr. Attr renames have been simplified into separate remove and set opertaions which removes the need for the INCOMPLETE state used in non delayed operations

I've also made the corresponding updates to the user space side, and xfstests as well.

Question, comment and feedback appreciated!

Thanks all!
Allison

Allison Collins (15):
xfs: Replace attribute parameters with struct xfs_name
xfs: Embed struct xfs_name in xfs_da_args
xfs: Add xfs_dabuf defines
xfs: Factor out new helper functions xfs_attr_rmtval_set
xfs: Factor up trans handling in xfs_attr3_leaf_flipflags
xfs: Factor out xfs_attr_leaf_addname helper
xfs: Factor up commit from xfs_attr_try_sf_addname
xfs: Factor up trans roll from xfs_attr3_leaf_setflag
xfs: Add xfs_attr3_leaf helper functions
xfs: Factor out xfs_attr_rmtval_invalidate
xfs: Factor up trans roll in xfs_attr3_leaf_clearflag
xfs: Add delay context to xfs_da_args
xfs: Add delayed attribute routines
xfs: Add feature bit XFS_SB_FEAT_INCOMPAT_LOG_DELATTR
xfs: Enable delayed attributes

Allison Henderson (4):
xfs: Add xfs_has_attr and subroutines
xfs: Set up infastructure for deferred attribute operations
xfs: Add xfs_attr_set_deferred and xfs_attr_remove_deferred
xfs_io: Add delayed attributes error tag

 fs/xfs/Makefile                 |    2 +-
 fs/xfs/libxfs/xfs_attr.c        | 1068 ++++++++++++++++++++++++++++++++++-----
 fs/xfs/libxfs/xfs_attr.h        |   53 +-
 fs/xfs/libxfs/xfs_attr_leaf.c   |  277 ++++++----
 fs/xfs/libxfs/xfs_attr_leaf.h   |    7 +
 fs/xfs/libxfs/xfs_attr_remote.c |  103 +++-
 fs/xfs/libxfs/xfs_attr_remote.h |    4 +-
 fs/xfs/libxfs/xfs_da_btree.c    |    8 +-
 fs/xfs/libxfs/xfs_da_btree.h    |   27 +-
 fs/xfs/libxfs/xfs_defer.c       |    1 +
 fs/xfs/libxfs/xfs_defer.h       |    3 +
 fs/xfs/libxfs/xfs_dir2.c        |   22 +-
 fs/xfs/libxfs/xfs_dir2_block.c  |    6 +-
 fs/xfs/libxfs/xfs_dir2_leaf.c   |    6 +-
 fs/xfs/libxfs/xfs_dir2_node.c   |    8 +-
 fs/xfs/libxfs/xfs_dir2_sf.c     |   30 +-
 fs/xfs/libxfs/xfs_errortag.h    |    4 +-
 fs/xfs/libxfs/xfs_format.h      |   11 +-
 fs/xfs/libxfs/xfs_fs.h          |    1 +
 fs/xfs/libxfs/xfs_log_format.h  |   44 +-
 fs/xfs/libxfs/xfs_sb.c          |    2 +
 fs/xfs/libxfs/xfs_types.h       |    1 +
 fs/xfs/scrub/attr.c             |   12 +-
 fs/xfs/scrub/common.c           |    2 +
 fs/xfs/xfs_acl.c                |   29 +-
 fs/xfs/xfs_attr_item.c          |  764 ++++++++++++++++++++++++++++
 fs/xfs/xfs_attr_item.h          |   88 ++++
 fs/xfs/xfs_attr_list.c          |    1 +
 fs/xfs/xfs_error.c              |    3 +
 fs/xfs/xfs_ioctl.c              |   30 +-
 fs/xfs/xfs_ioctl32.c            |    2 +
 fs/xfs/xfs_iops.c               |   14 +-
 fs/xfs/xfs_log.c                |    4 +
 fs/xfs/xfs_log_recover.c        |  173 +++++++
 fs/xfs/xfs_ondisk.h             |    2 +
 fs/xfs/xfs_super.c              |    4 +
 fs/xfs/xfs_trace.h              |   20 +-
 fs/xfs/xfs_trans.h              |    1 -
 fs/xfs/xfs_xattr.c              |   31 +-
 39 files changed, 2509 insertions(+), 359 deletions(-)
 create mode 100644 fs/xfs/xfs_attr_item.c
 create mode 100644 fs/xfs/xfs_attr_item.h
Signature · 1 line
2.7.4
#1 lore raw

PATCH v3 1/19 xfs: Replace attribute parameters with struct xfs_name

This patch replaces the attribute name, length and flags parameters with a single struct xfs_name parameter. This helps to clean up the numbers of parameters being passed around and pre-simplifies the code some.

---
 fs/xfs/libxfs/xfs_attr.c | 46 +++++++++++++++++++---------------------------
 fs/xfs/libxfs/xfs_attr.h | 12 +++++-------
 fs/xfs/xfs_acl.c         | 27 +++++++++++++--------------
 fs/xfs/xfs_ioctl.c       | 28 ++++++++++++++++++----------
 fs/xfs/xfs_iops.c        | 12 ++++++++----
 fs/xfs/xfs_xattr.c       | 30 +++++++++++++++++-------------
 6 files changed, 80 insertions(+), 75 deletions(-)
fs/xfs/libxfs/xfs_attr.c +19 -27
index 7589cb7..d0308d6 100644
@@ -61,9 +61,7 @@ STATIC int
 xfs_attr_args_init(
 	struct xfs_da_args	*args,
 	struct xfs_inode	*dp,
-	const unsigned char	*name,
-	size_t			namelen,
-	int			flags)
+	struct xfs_name		*name)
 {
 
 	if (!name)
@@ -73,9 +71,9 @@ xfs_attr_args_init(
 	args->geo = dp->i_mount->m_attr_geo;
 	args->whichfork = XFS_ATTR_FORK;
 	args->dp = dp;
-	args->flags = flags;
-	args->name = name;
-	args->namelen = namelen;
+	args->flags = name->type;
+	args->name = name->name;
+	args->namelen = name->len;
 	if (args->namelen >= MAXNAMELEN)
 		return -EFAULT;		/* match IRIX behaviour */
 
@@ -139,30 +137,28 @@ xfs_attr_get_ilocked(
 int
 xfs_attr_get(
 	struct xfs_inode	*ip,
-	const unsigned char	*name,
-	size_t			namelen,
+	struct xfs_name		*name,
 	unsigned char		**value,
-	int			*valuelenp,
-	int			flags)
+	int			*valuelenp)
 {
 	struct xfs_da_args	args;
 	uint			lock_mode;
 	int			error;
 
-	ASSERT((flags & (ATTR_ALLOC | ATTR_KERNOVAL)) || *value);
+	ASSERT((name->type & (ATTR_ALLOC | ATTR_KERNOVAL)) || *value);
 
 	XFS_STATS_INC(ip->i_mount, xs_attr_get);
 
 	if (XFS_FORCED_SHUTDOWN(ip->i_mount))
 		return -EIO;
 
-	error = xfs_attr_args_init(&args, ip, name, namelen, flags);
+	error = xfs_attr_args_init(&args, ip, name);
 	if (error)
 		return error;
 
 	/* Entirely possible to look up a name which doesn't exist */
 	args.op_flags = XFS_DA_OP_OKNOENT;
-	if (flags & ATTR_ALLOC)
+	if (name->type & ATTR_ALLOC)
 		args.op_flags |= XFS_DA_OP_ALLOCVAL;
 	else
 		args.value = *value;
@@ -175,7 +171,7 @@ xfs_attr_get(
 
 	/* on error, we have to clean up allocated value buffers */
 	if (error) {
-		if (flags & ATTR_ALLOC) {
+		if (name->type & ATTR_ALLOC) {
 			kmem_free(args.value);
 			*value = NULL;
 		}
@@ -339,16 +335,14 @@ xfs_attr_remove_args(
 int
 xfs_attr_set(
 	struct xfs_inode	*dp,
-	const unsigned char	*name,
-	size_t			namelen,
+	struct xfs_name		*name,
 	unsigned char		*value,
-	int			valuelen,
-	int			flags)
+	int			valuelen)
 {
 	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 = (name->type & ATTR_ROOT) != 0;
 	int			error, local;
 
 	XFS_STATS_INC(mp, xs_attr_set);
@@ -356,7 +350,7 @@ xfs_attr_set(
 	if (XFS_FORCED_SHUTDOWN(dp->i_mount))
 		return -EIO;
 
-	error = xfs_attr_args_init(&args, dp, name, namelen, flags);
+	error = xfs_attr_args_init(&args, dp, name);
 	if (error)
 		return error;
 
@@ -419,7 +413,7 @@ xfs_attr_set(
 	if (mp->m_flags & XFS_MOUNT_WSYNC)
 		xfs_trans_set_sync(args.trans);
 
-	if ((flags & ATTR_KERNOTIME) == 0)
+	if ((name->type & ATTR_KERNOTIME) == 0)
 		xfs_trans_ichgtime(args.trans, dp, XFS_ICHGTIME_CHG);
 
 	/*
@@ -444,9 +438,7 @@ xfs_attr_set(
 int
 xfs_attr_remove(
 	struct xfs_inode	*dp,
-	const unsigned char	*name,
-	size_t			namelen,
-	int			flags)
+	struct xfs_name		*name)
 {
 	struct xfs_mount	*mp = dp->i_mount;
 	struct xfs_da_args	args;
@@ -457,7 +449,7 @@ xfs_attr_remove(
 	if (XFS_FORCED_SHUTDOWN(dp->i_mount))
 		return -EIO;
 
-	error = xfs_attr_args_init(&args, dp, name, namelen, flags);
+	error = xfs_attr_args_init(&args, dp, name);
 	if (error)
 		return error;
 
@@ -478,7 +470,7 @@ xfs_attr_remove(
 	 */
 	error = xfs_trans_alloc(mp, &M_RES(mp)->tr_attrrm,
 			XFS_ATTRRM_SPACE_RES(mp), 0,
-			(flags & ATTR_ROOT) ? XFS_TRANS_RESERVE : 0,
+			(name->type & ATTR_ROOT) ? XFS_TRANS_RESERVE : 0,
 			&args.trans);
 	if (error)
 		return error;
@@ -501,7 +493,7 @@ xfs_attr_remove(
 	if (mp->m_flags & XFS_MOUNT_WSYNC)
 		xfs_trans_set_sync(args.trans);
 
-	if ((flags & ATTR_KERNOTIME) == 0)
+	if ((name->type & ATTR_KERNOTIME) == 0)
 		xfs_trans_ichgtime(args.trans, dp, XFS_ICHGTIME_CHG);
 
 	/*
fs/xfs/libxfs/xfs_attr.h +5 -7
index 106a2f2..cedb4e2 100644
@@ -144,14 +144,12 @@ int xfs_attr_list_int_ilocked(struct xfs_attr_list_context *);
 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,
-		 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_get(struct xfs_inode *ip, struct xfs_name *name,
+		 unsigned char **value, int *valuelenp);
+int xfs_attr_set(struct xfs_inode *dp, struct xfs_name *name,
+		 unsigned char *value, int valuelen);
 int xfs_attr_set_args(struct xfs_da_args *args);
-int xfs_attr_remove(struct xfs_inode *dp, const unsigned char *name,
-		    size_t namelen, int flags);
+int xfs_attr_remove(struct xfs_inode *dp, struct xfs_name *name);
 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);
fs/xfs/xfs_acl.c +13 -14
index 12be708..f8fb6e10 100644
@@ -113,7 +113,7 @@ xfs_get_acl(struct inode *inode, int type)
 	struct xfs_inode *ip = XFS_I(inode);
 	struct posix_acl *acl = NULL;
 	struct xfs_acl *xfs_acl = NULL;
-	unsigned char *ea_name;
+	struct xfs_name name;
 	int error;
 	int len;
 
@@ -121,10 +121,10 @@ xfs_get_acl(struct inode *inode, int type)
 
 	switch (type) {
 	case ACL_TYPE_ACCESS:
-		ea_name = SGI_ACL_FILE;
+		name.name = SGI_ACL_FILE;
 		break;
 	case ACL_TYPE_DEFAULT:
-		ea_name = SGI_ACL_DEFAULT;
+		name.name = SGI_ACL_DEFAULT;
 		break;
 	default:
 		BUG();
@@ -135,9 +135,9 @@ 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, strlen(ea_name), 
-				(unsigned char **)&xfs_acl, &len,
-				ATTR_ALLOC | ATTR_ROOT);
+	name.len = strlen(name.name);
+	name.type = ATTR_ALLOC | ATTR_ROOT;
+	error = xfs_attr_get(ip, &name, (unsigned char **)&xfs_acl, &len);
 	if (error) {
 		/*
 		 * If the attribute doesn't exist make sure we have a negative
@@ -157,17 +157,17 @@ 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_name name;
 	int error;
 
 	switch (type) {
 	case ACL_TYPE_ACCESS:
-		ea_name = SGI_ACL_FILE;
+		name.name = SGI_ACL_FILE;
 		break;
 	case ACL_TYPE_DEFAULT:
 		if (!S_ISDIR(inode->i_mode))
 			return acl ? -EACCES : 0;
-		ea_name = SGI_ACL_DEFAULT;
+		name.name = SGI_ACL_DEFAULT;
 		break;
 	default:
 		return -EINVAL;
@@ -187,17 +187,16 @@ __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, strlen(ea_name),
-				     (unsigned char *)xfs_acl, len, ATTR_ROOT);
+		name.len = strlen(name.name);
+		name.type = ATTR_ROOT;
+		error = xfs_attr_set(ip, &name, (unsigned char *)xfs_acl, len);
 
 		kmem_free(xfs_acl);
 	} else {
 		/*
 		 * A NULL ACL argument means we want to remove the ACL.
 		 */
-		error = xfs_attr_remove(ip, ea_name,
-					strlen(ea_name),
-					ATTR_ROOT);
+		error = xfs_attr_remove(ip, &name);
 
 		/*
 		 * If the attribute didn't exist to start with that's fine.
fs/xfs/xfs_ioctl.c +18 -10
index d440426..626420d 100644
@@ -431,7 +431,11 @@ xfs_attrmulti_attr_get(
 {
 	unsigned char		*kbuf;
 	int			error = -EFAULT;
-	size_t			namelen;
+	struct xfs_name		xname = {
+		.name		= name,
+		.len		= strlen(name),
+		.type		= flags,
+	};
 
 	if (*len > XFS_XATTR_SIZE_MAX)
 		return -EINVAL;
@@ -439,9 +443,7 @@ xfs_attrmulti_attr_get(
 	if (!kbuf)
 		return -ENOMEM;
 
-	namelen = strlen(name);
-	error = xfs_attr_get(XFS_I(inode), name, namelen, &kbuf, (int *)len,
-			     flags);
+	error = xfs_attr_get(XFS_I(inode), &xname, &kbuf, (int *)len);
 	if (error)
 		goto out_kfree;
 
@@ -463,7 +465,7 @@ xfs_attrmulti_attr_set(
 {
 	unsigned char		*kbuf;
 	int			error;
-	size_t			namelen;
+	struct xfs_name		xname;
 
 	if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
 		return -EPERM;
@@ -474,8 +476,10 @@ xfs_attrmulti_attr_set(
 	if (IS_ERR(kbuf))
 		return PTR_ERR(kbuf);
 
-	namelen = strlen(name);
-	error = xfs_attr_set(XFS_I(inode), name, namelen, kbuf, len, flags);
+	xname.name = name;
+	xname.len = strlen(name);
+	xname.type = flags;
+	error = xfs_attr_set(XFS_I(inode), &xname, kbuf, len);
 	if (!error)
 		xfs_forget_acl(inode, name, flags);
 	kfree(kbuf);
@@ -489,12 +493,16 @@ xfs_attrmulti_attr_remove(
 	uint32_t		flags)
 {
 	int			error;
-	size_t			namelen;
+	struct xfs_name		xname = {
+		.name		= name,
+		.len		= strlen(name),
+		.type		= flags,
+	};
 
 	if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
 		return -EPERM;
-	namelen = strlen(name);
-	error = xfs_attr_remove(XFS_I(inode), name, namelen, flags);
+
+	error = xfs_attr_remove(XFS_I(inode), &xname);
 	if (!error)
 		xfs_forget_acl(inode, name, flags);
 	return error;
fs/xfs/xfs_iops.c +8 -4
index 92de0a7..469e8e2 100644
@@ -49,10 +49,14 @@ 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_name	name = {
+			.name	= xattr->name,
+			.len	= strlen(xattr->name),
+			.type	= ATTR_SECURE,
+		};
+
+		error = xfs_attr_set(ip, &name,
+				     xattr->value, xattr->value_len);
 		if (error < 0)
 			break;
 	}
fs/xfs/xfs_xattr.c +17 -13
index 59ffe6c..6309da4 100644
@@ -20,19 +20,21 @@ static int
 xfs_xattr_get(const struct xattr_handler *handler, struct dentry *unused,
 		struct inode *inode, const char *name, void *value, size_t size)
 {
-	int xflags = handler->flags;
 	struct xfs_inode *ip = XFS_I(inode);
 	int error, asize = size;
-	size_t namelen = strlen(name);
+	struct xfs_name xname = {
+		.name	= name,
+		.len	= strlen(name),
+		.type	= handler->flags
+	};
 
 	/* Convert Linux syscall to XFS internal ATTR flags */
 	if (!size) {
-		xflags |= ATTR_KERNOVAL;
+		xname.type |= ATTR_KERNOVAL;
 		value = NULL;
 	}
 
-	error = xfs_attr_get(ip, name, namelen, (unsigned char **)&value,
-			     &asize, xflags);
+	error = xfs_attr_get(ip, &xname, (unsigned char **)&value, &asize);
 	if (error)
 		return error;
 	return asize;
@@ -65,23 +67,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);
 	int			error;
-	size_t			namelen = strlen(name);
+	struct xfs_name		xname = {
+		.name		= name,
+		.len		= strlen(name),
+		.type		= handler->flags,
+	};
 
 	/* Convert Linux syscall to XFS internal ATTR flags */
 	if (flags & XATTR_CREATE)
-		xflags |= ATTR_CREATE;
+		xname.type |= ATTR_CREATE;
 	if (flags & XATTR_REPLACE)
-		xflags |= ATTR_REPLACE;
+		xname.type |= ATTR_REPLACE;
 
 	if (!value)
-		return xfs_attr_remove(ip, name,
-				       namelen, xflags);
-	error = xfs_attr_set(ip, name, namelen, (void *)value, size, xflags);
+		return xfs_attr_remove(ip, &xname);
+	error = xfs_attr_set(ip, &xname, (void *)value, size);
 	if (!error)
-		xfs_forget_acl(inode, name, xflags);
+		xfs_forget_acl(inode, name, xname.type);
 
 	return error;
 }
Signature · 1 line
2.7.4
#2 lore raw

Re: [PATCH v3 01/19] xfs: Replace attribute parameters with struct xfs_name

Quoted 18 lines · Allison Collins

This patch replaces the attribute name, length and flags parameters with a single struct xfs_name parameter. This helps to clean up the numbers of parameters being passed around and pre-simplifies the code some.

---
 fs/xfs/libxfs/xfs_attr.c | 46 +++++++++++++++++++---------------------------
 fs/xfs/libxfs/xfs_attr.h | 12 +++++-------
 fs/xfs/xfs_acl.c         | 27 +++++++++++++--------------
 fs/xfs/xfs_ioctl.c       | 28 ++++++++++++++++++----------
 fs/xfs/xfs_iops.c        | 12 ++++++++----
 fs/xfs/xfs_xattr.c       | 30 +++++++++++++++++-------------
 6 files changed, 80 insertions(+), 75 deletions(-)
fs/xfs/libxfs/xfs_attr.c +0 -0
index 7589cb7..d0308d6 100644

...

Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c +1 -2
@@ -139,30 +137,28 @@ xfs_attr_get_ilocked(
 int
 xfs_attr_get(
 	struct xfs_inode	*ip,
-	const unsigned char	*name,
-	size_t			namelen,
+	struct xfs_name		*name,
 	unsigned char		**value,

fs/xfs/libxfs/xfs_attr.c xfs_attr_get_ilocked( · line 148

Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +2 -3
-	int			*valuelenp,
-	int			flags)
+	int			*valuelenp)
 {
 	struct xfs_da_args	args;
 	uint			lock_mode;
 	int			error;
 
-	ASSERT((flags & (ATTR_ALLOC | ATTR_KERNOVAL)) || *value);
+	ASSERT((name->type & (ATTR_ALLOC | ATTR_KERNOVAL)) || *value);

While this looks like a nice cleanup, I'm not a huge fan of burying the attr flags in the xfs_name like this. To me they are distinct parameters and the interface isn't as clear for new callers. Other than that the patch looks good.

BTW after looking at the next patch, a reasonable compromise might be to leave the flags param for the top level xfs_attr_*() functions and then bury the value in args->name.type for the rest of the lower level code to use. Just a thought..

Brian

Quoted 370 lines
fs/xfs/libxfs/xfs_attr.c +12 -16
 	XFS_STATS_INC(ip->i_mount, xs_attr_get);
 
 	if (XFS_FORCED_SHUTDOWN(ip->i_mount))
 		return -EIO;
 
-	error = xfs_attr_args_init(&args, ip, name, namelen, flags);
+	error = xfs_attr_args_init(&args, ip, name);
 	if (error)
 		return error;
 
 	/* Entirely possible to look up a name which doesn't exist */
 	args.op_flags = XFS_DA_OP_OKNOENT;
-	if (flags & ATTR_ALLOC)
+	if (name->type & ATTR_ALLOC)
 		args.op_flags |= XFS_DA_OP_ALLOCVAL;
 	else
 		args.value = *value;
@@ -175,7 +171,7 @@ xfs_attr_get(
 
 	/* on error, we have to clean up allocated value buffers */
 	if (error) {
-		if (flags & ATTR_ALLOC) {
+		if (name->type & ATTR_ALLOC) {
 			kmem_free(args.value);
 			*value = NULL;
 		}
@@ -339,16 +335,14 @@ xfs_attr_remove_args(
 int
 xfs_attr_set(
 	struct xfs_inode	*dp,
-	const unsigned char	*name,
-	size_t			namelen,
+	struct xfs_name		*name,
 	unsigned char		*value,
-	int			valuelen,
-	int			flags)
+	int			valuelen)
 {
 	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 = (name->type & ATTR_ROOT) != 0;
 	int			error, local;
 
 	XFS_STATS_INC(mp, xs_attr_set);
@@ -356,7 +350,7 @@ xfs_attr_set(
 	if (XFS_FORCED_SHUTDOWN(dp->i_mount))
 		return -EIO;
 
-	error = xfs_attr_args_init(&args, dp, name, namelen, flags);
+	error = xfs_attr_args_init(&args, dp, name);
 	if (error)
 		return error;
 
@@ -419,7 +413,7 @@ xfs_attr_set(
 	if (mp->m_flags & XFS_MOUNT_WSYNC)
 		xfs_trans_set_sync(args.trans);
 
-	if ((flags & ATTR_KERNOTIME) == 0)
+	if ((name->type & ATTR_KERNOTIME) == 0)
 		xfs_trans_ichgtime(args.trans, dp, XFS_ICHGTIME_CHG);
 
 	/*
@@ -444,9 +438,7 @@ xfs_attr_set(
 int
 xfs_attr_remove(
 	struct xfs_inode	*dp,
-	const unsigned char	*name,
-	size_t			namelen,
-	int			flags)
+	struct xfs_name		*name)
 {
 	struct xfs_mount	*mp = dp->i_mount;
 	struct xfs_da_args	args;
@@ -457,7 +449,7 @@ xfs_attr_remove(
 	if (XFS_FORCED_SHUTDOWN(dp->i_mount))
 		return -EIO;
 
-	error = xfs_attr_args_init(&args, dp, name, namelen, flags);
+	error = xfs_attr_args_init(&args, dp, name);
 	if (error)
 		return error;
 
@@ -478,7 +470,7 @@ xfs_attr_remove(
 	 */
 	error = xfs_trans_alloc(mp, &M_RES(mp)->tr_attrrm,
 			XFS_ATTRRM_SPACE_RES(mp), 0,
-			(flags & ATTR_ROOT) ? XFS_TRANS_RESERVE : 0,
+			(name->type & ATTR_ROOT) ? XFS_TRANS_RESERVE : 0,
 			&args.trans);
 	if (error)
 		return error;
@@ -501,7 +493,7 @@ xfs_attr_remove(
 	if (mp->m_flags & XFS_MOUNT_WSYNC)
 		xfs_trans_set_sync(args.trans);
 
-	if ((flags & ATTR_KERNOTIME) == 0)
+	if ((name->type & ATTR_KERNOTIME) == 0)
 		xfs_trans_ichgtime(args.trans, dp, XFS_ICHGTIME_CHG);
 
 	/*
fs/xfs/libxfs/xfs_attr.h +5 -7
index 106a2f2..cedb4e2 100644
@@ -144,14 +144,12 @@ int xfs_attr_list_int_ilocked(struct xfs_attr_list_context *);
 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,
-		 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_get(struct xfs_inode *ip, struct xfs_name *name,
+		 unsigned char **value, int *valuelenp);
+int xfs_attr_set(struct xfs_inode *dp, struct xfs_name *name,
+		 unsigned char *value, int valuelen);
 int xfs_attr_set_args(struct xfs_da_args *args);
-int xfs_attr_remove(struct xfs_inode *dp, const unsigned char *name,
-		    size_t namelen, int flags);
+int xfs_attr_remove(struct xfs_inode *dp, struct xfs_name *name);
 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);
fs/xfs/xfs_acl.c +13 -14
index 12be708..f8fb6e10 100644
@@ -113,7 +113,7 @@ xfs_get_acl(struct inode *inode, int type)
 	struct xfs_inode *ip = XFS_I(inode);
 	struct posix_acl *acl = NULL;
 	struct xfs_acl *xfs_acl = NULL;
-	unsigned char *ea_name;
+	struct xfs_name name;
 	int error;
 	int len;
 
@@ -121,10 +121,10 @@ xfs_get_acl(struct inode *inode, int type)
 
 	switch (type) {
 	case ACL_TYPE_ACCESS:
-		ea_name = SGI_ACL_FILE;
+		name.name = SGI_ACL_FILE;
 		break;
 	case ACL_TYPE_DEFAULT:
-		ea_name = SGI_ACL_DEFAULT;
+		name.name = SGI_ACL_DEFAULT;
 		break;
 	default:
 		BUG();
@@ -135,9 +135,9 @@ 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, strlen(ea_name), 
-				(unsigned char **)&xfs_acl, &len,
-				ATTR_ALLOC | ATTR_ROOT);
+	name.len = strlen(name.name);
+	name.type = ATTR_ALLOC | ATTR_ROOT;
+	error = xfs_attr_get(ip, &name, (unsigned char **)&xfs_acl, &len);
 	if (error) {
 		/*
 		 * If the attribute doesn't exist make sure we have a negative
@@ -157,17 +157,17 @@ 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_name name;
 	int error;
 
 	switch (type) {
 	case ACL_TYPE_ACCESS:
-		ea_name = SGI_ACL_FILE;
+		name.name = SGI_ACL_FILE;
 		break;
 	case ACL_TYPE_DEFAULT:
 		if (!S_ISDIR(inode->i_mode))
 			return acl ? -EACCES : 0;
-		ea_name = SGI_ACL_DEFAULT;
+		name.name = SGI_ACL_DEFAULT;
 		break;
 	default:
 		return -EINVAL;
@@ -187,17 +187,16 @@ __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, strlen(ea_name),
-				     (unsigned char *)xfs_acl, len, ATTR_ROOT);
+		name.len = strlen(name.name);
+		name.type = ATTR_ROOT;
+		error = xfs_attr_set(ip, &name, (unsigned char *)xfs_acl, len);
 
 		kmem_free(xfs_acl);
 	} else {
 		/*
 		 * A NULL ACL argument means we want to remove the ACL.
 		 */
-		error = xfs_attr_remove(ip, ea_name,
-					strlen(ea_name),
-					ATTR_ROOT);
+		error = xfs_attr_remove(ip, &name);
 
 		/*
 		 * If the attribute didn't exist to start with that's fine.
fs/xfs/xfs_ioctl.c +18 -10
index d440426..626420d 100644
@@ -431,7 +431,11 @@ xfs_attrmulti_attr_get(
 {
 	unsigned char		*kbuf;
 	int			error = -EFAULT;
-	size_t			namelen;
+	struct xfs_name		xname = {
+		.name		= name,
+		.len		= strlen(name),
+		.type		= flags,
+	};
 
 	if (*len > XFS_XATTR_SIZE_MAX)
 		return -EINVAL;
@@ -439,9 +443,7 @@ xfs_attrmulti_attr_get(
 	if (!kbuf)
 		return -ENOMEM;
 
-	namelen = strlen(name);
-	error = xfs_attr_get(XFS_I(inode), name, namelen, &kbuf, (int *)len,
-			     flags);
+	error = xfs_attr_get(XFS_I(inode), &xname, &kbuf, (int *)len);
 	if (error)
 		goto out_kfree;
 
@@ -463,7 +465,7 @@ xfs_attrmulti_attr_set(
 {
 	unsigned char		*kbuf;
 	int			error;
-	size_t			namelen;
+	struct xfs_name		xname;
 
 	if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
 		return -EPERM;
@@ -474,8 +476,10 @@ xfs_attrmulti_attr_set(
 	if (IS_ERR(kbuf))
 		return PTR_ERR(kbuf);
 
-	namelen = strlen(name);
-	error = xfs_attr_set(XFS_I(inode), name, namelen, kbuf, len, flags);
+	xname.name = name;
+	xname.len = strlen(name);
+	xname.type = flags;
+	error = xfs_attr_set(XFS_I(inode), &xname, kbuf, len);
 	if (!error)
 		xfs_forget_acl(inode, name, flags);
 	kfree(kbuf);
@@ -489,12 +493,16 @@ xfs_attrmulti_attr_remove(
 	uint32_t		flags)
 {
 	int			error;
-	size_t			namelen;
+	struct xfs_name		xname = {
+		.name		= name,
+		.len		= strlen(name),
+		.type		= flags,
+	};
 
 	if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
 		return -EPERM;
-	namelen = strlen(name);
-	error = xfs_attr_remove(XFS_I(inode), name, namelen, flags);
+
+	error = xfs_attr_remove(XFS_I(inode), &xname);
 	if (!error)
 		xfs_forget_acl(inode, name, flags);
 	return error;
fs/xfs/xfs_iops.c +8 -4
index 92de0a7..469e8e2 100644
@@ -49,10 +49,14 @@ 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_name	name = {
+			.name	= xattr->name,
+			.len	= strlen(xattr->name),
+			.type	= ATTR_SECURE,
+		};
+
+		error = xfs_attr_set(ip, &name,
+				     xattr->value, xattr->value_len);
 		if (error < 0)
 			break;
 	}
fs/xfs/xfs_xattr.c +17 -13
index 59ffe6c..6309da4 100644
@@ -20,19 +20,21 @@ static int
 xfs_xattr_get(const struct xattr_handler *handler, struct dentry *unused,
 		struct inode *inode, const char *name, void *value, size_t size)
 {
-	int xflags = handler->flags;
 	struct xfs_inode *ip = XFS_I(inode);
 	int error, asize = size;
-	size_t namelen = strlen(name);
+	struct xfs_name xname = {
+		.name	= name,
+		.len	= strlen(name),
+		.type	= handler->flags
+	};
 
 	/* Convert Linux syscall to XFS internal ATTR flags */
 	if (!size) {
-		xflags |= ATTR_KERNOVAL;
+		xname.type |= ATTR_KERNOVAL;
 		value = NULL;
 	}
 
-	error = xfs_attr_get(ip, name, namelen, (unsigned char **)&value,
-			     &asize, xflags);
+	error = xfs_attr_get(ip, &xname, (unsigned char **)&value, &asize);
 	if (error)
 		return error;
 	return asize;
@@ -65,23 +67,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);
 	int			error;
-	size_t			namelen = strlen(name);
+	struct xfs_name		xname = {
+		.name		= name,
+		.len		= strlen(name),
+		.type		= handler->flags,
+	};
 
 	/* Convert Linux syscall to XFS internal ATTR flags */
 	if (flags & XATTR_CREATE)
-		xflags |= ATTR_CREATE;
+		xname.type |= ATTR_CREATE;
 	if (flags & XATTR_REPLACE)
-		xflags |= ATTR_REPLACE;
+		xname.type |= ATTR_REPLACE;
 
 	if (!value)
-		return xfs_attr_remove(ip, name,
-				       namelen, xflags);
-	error = xfs_attr_set(ip, name, namelen, (void *)value, size, xflags);
+		return xfs_attr_remove(ip, &xname);
+	error = xfs_attr_set(ip, &xname, (void *)value, size);
 	if (!error)
-		xfs_forget_acl(inode, name, xflags);
+		xfs_forget_acl(inode, name, xname.type);
 
 	return error;
 }
Signature · 1 line
2.7.4
#3 lore raw

Re: [PATCH v3 01/19] xfs: Replace attribute parameters with struct xfs_name

Quoted 44 lines · Brian Foster
Quoted 18 lines · Allison Collins

This patch replaces the attribute name, length and flags parameters with a single struct xfs_name parameter. This helps to clean up the numbers of parameters being passed around and pre-simplifies the code some.

---
  fs/xfs/libxfs/xfs_attr.c | 46 +++++++++++++++++++---------------------------
  fs/xfs/libxfs/xfs_attr.h | 12 +++++-------
  fs/xfs/xfs_acl.c         | 27 +++++++++++++--------------
  fs/xfs/xfs_ioctl.c       | 28 ++++++++++++++++++----------
  fs/xfs/xfs_iops.c        | 12 ++++++++----
  fs/xfs/xfs_xattr.c       | 30 +++++++++++++++++-------------
  6 files changed, 80 insertions(+), 75 deletions(-)
fs/xfs/libxfs/xfs_attr.c +0 -0
index 7589cb7..d0308d6 100644

...

Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c +1 -2
@@ -139,30 +137,28 @@ xfs_attr_get_ilocked(
  int
  xfs_attr_get(
  	struct xfs_inode	*ip,
-	const unsigned char	*name,
-	size_t			namelen,
+	struct xfs_name		*name,
  	unsigned char		**value,

fs/xfs/libxfs/xfs_attr.c xfs_attr_get_ilocked( · line 148

Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +2 -3
-	int			*valuelenp,
-	int			flags)
+	int			*valuelenp)
  {
  	struct xfs_da_args	args;
  	uint			lock_mode;
  	int			error;
 
-	ASSERT((flags & (ATTR_ALLOC | ATTR_KERNOVAL)) || *value);
+	ASSERT((name->type & (ATTR_ALLOC | ATTR_KERNOVAL)) || *value);

While this looks like a nice cleanup, I'm not a huge fan of burying the attr flags in the xfs_name like this. To me they are distinct parameters and the interface isn't as clear for new callers. Other than that the patch looks good.

Quoted 6 lines

BTW after looking at the next patch, a reasonable compromise might be to leave the flags param for the top level xfs_attr_*() functions and then bury the value in args->name.type for the rest of the lower level code to use. Just a thought..

Brian

Yes, this was a sort of cleanup suggested in the last review. While it is nice to have less parameters, I ended up having mixed feels about using type for flags. Mostly just because a name of "type" generally implies that the field should be handled like an enumeration, and a "flag" implies that is should be handled like a bitmask. So I found myself doing a lot of double takes just in looking at it. I am fine with moving flags back out, but I would like folks to weigh in so that we have a consensus on what people are comfortable with.

I'm not sure I like the idea of putting "value" in "type" though. Generally a "value" implies a sort of payload with a length (of which we have). But but I think separating value and valuelen would look all sorts of weird. I think either value should stay outside with valuelen, or we should probably bite the bullet and introduce a new struct for the purpose. Thoughts?

Allison

Quoted 371 lines
Quoted 371 lines
fs/xfs/libxfs/xfs_attr.c +12 -16
  	XFS_STATS_INC(ip->i_mount, xs_attr_get);
 
  	if (XFS_FORCED_SHUTDOWN(ip->i_mount))
  		return -EIO;
 
-	error = xfs_attr_args_init(&args, ip, name, namelen, flags);
+	error = xfs_attr_args_init(&args, ip, name);
  	if (error)
  		return error;
 
  	/* Entirely possible to look up a name which doesn't exist */
  	args.op_flags = XFS_DA_OP_OKNOENT;
-	if (flags & ATTR_ALLOC)
+	if (name->type & ATTR_ALLOC)
  		args.op_flags |= XFS_DA_OP_ALLOCVAL;
  	else
  		args.value = *value;
@@ -175,7 +171,7 @@ xfs_attr_get(
 
  	/* on error, we have to clean up allocated value buffers */
  	if (error) {
-		if (flags & ATTR_ALLOC) {
+		if (name->type & ATTR_ALLOC) {
  			kmem_free(args.value);
  			*value = NULL;
  		}
@@ -339,16 +335,14 @@ xfs_attr_remove_args(
  int
  xfs_attr_set(
  	struct xfs_inode	*dp,
-	const unsigned char	*name,
-	size_t			namelen,
+	struct xfs_name		*name,
  	unsigned char		*value,
-	int			valuelen,
-	int			flags)
+	int			valuelen)
  {
  	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 = (name->type & ATTR_ROOT) != 0;
  	int			error, local;
 
  	XFS_STATS_INC(mp, xs_attr_set);
@@ -356,7 +350,7 @@ xfs_attr_set(
  	if (XFS_FORCED_SHUTDOWN(dp->i_mount))
  		return -EIO;
 
-	error = xfs_attr_args_init(&args, dp, name, namelen, flags);
+	error = xfs_attr_args_init(&args, dp, name);
  	if (error)
  		return error;
 
@@ -419,7 +413,7 @@ xfs_attr_set(
  	if (mp->m_flags & XFS_MOUNT_WSYNC)
  		xfs_trans_set_sync(args.trans);
 
-	if ((flags & ATTR_KERNOTIME) == 0)
+	if ((name->type & ATTR_KERNOTIME) == 0)
  		xfs_trans_ichgtime(args.trans, dp, XFS_ICHGTIME_CHG);
 
  	/*
@@ -444,9 +438,7 @@ xfs_attr_set(
  int
  xfs_attr_remove(
  	struct xfs_inode	*dp,
-	const unsigned char	*name,
-	size_t			namelen,
-	int			flags)
+	struct xfs_name		*name)
  {
  	struct xfs_mount	*mp = dp->i_mount;
  	struct xfs_da_args	args;
@@ -457,7 +449,7 @@ xfs_attr_remove(
  	if (XFS_FORCED_SHUTDOWN(dp->i_mount))
  		return -EIO;
 
-	error = xfs_attr_args_init(&args, dp, name, namelen, flags);
+	error = xfs_attr_args_init(&args, dp, name);
  	if (error)
  		return error;
 
@@ -478,7 +470,7 @@ xfs_attr_remove(
  	 */
  	error = xfs_trans_alloc(mp, &M_RES(mp)->tr_attrrm,
  			XFS_ATTRRM_SPACE_RES(mp), 0,
-			(flags & ATTR_ROOT) ? XFS_TRANS_RESERVE : 0,
+			(name->type & ATTR_ROOT) ? XFS_TRANS_RESERVE : 0,
  			&args.trans);
  	if (error)
  		return error;
@@ -501,7 +493,7 @@ xfs_attr_remove(
  	if (mp->m_flags & XFS_MOUNT_WSYNC)
  		xfs_trans_set_sync(args.trans);
 
-	if ((flags & ATTR_KERNOTIME) == 0)
+	if ((name->type & ATTR_KERNOTIME) == 0)
  		xfs_trans_ichgtime(args.trans, dp, XFS_ICHGTIME_CHG);
 
  	/*
fs/xfs/libxfs/xfs_attr.h +5 -7
index 106a2f2..cedb4e2 100644
@@ -144,14 +144,12 @@ int xfs_attr_list_int_ilocked(struct xfs_attr_list_context *);
  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,
-		 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_get(struct xfs_inode *ip, struct xfs_name *name,
+		 unsigned char **value, int *valuelenp);
+int xfs_attr_set(struct xfs_inode *dp, struct xfs_name *name,
+		 unsigned char *value, int valuelen);
  int xfs_attr_set_args(struct xfs_da_args *args);
-int xfs_attr_remove(struct xfs_inode *dp, const unsigned char *name,
-		    size_t namelen, int flags);
+int xfs_attr_remove(struct xfs_inode *dp, struct xfs_name *name);
  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);
fs/xfs/xfs_acl.c +13 -14
index 12be708..f8fb6e10 100644
@@ -113,7 +113,7 @@ xfs_get_acl(struct inode *inode, int type)
  	struct xfs_inode *ip = XFS_I(inode);
  	struct posix_acl *acl = NULL;
  	struct xfs_acl *xfs_acl = NULL;
-	unsigned char *ea_name;
+	struct xfs_name name;
  	int error;
  	int len;
 
@@ -121,10 +121,10 @@ xfs_get_acl(struct inode *inode, int type)
 
  	switch (type) {
  	case ACL_TYPE_ACCESS:
-		ea_name = SGI_ACL_FILE;
+		name.name = SGI_ACL_FILE;
  		break;
  	case ACL_TYPE_DEFAULT:
-		ea_name = SGI_ACL_DEFAULT;
+		name.name = SGI_ACL_DEFAULT;
  		break;
  	default:
  		BUG();
@@ -135,9 +135,9 @@ 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, strlen(ea_name),
-				(unsigned char **)&xfs_acl, &len,
-				ATTR_ALLOC | ATTR_ROOT);
+	name.len = strlen(name.name);
+	name.type = ATTR_ALLOC | ATTR_ROOT;
+	error = xfs_attr_get(ip, &name, (unsigned char **)&xfs_acl, &len);
  	if (error) {
  		/*
  		 * If the attribute doesn't exist make sure we have a negative
@@ -157,17 +157,17 @@ 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_name name;
  	int error;
 
  	switch (type) {
  	case ACL_TYPE_ACCESS:
-		ea_name = SGI_ACL_FILE;
+		name.name = SGI_ACL_FILE;
  		break;
  	case ACL_TYPE_DEFAULT:
  		if (!S_ISDIR(inode->i_mode))
  			return acl ? -EACCES : 0;
-		ea_name = SGI_ACL_DEFAULT;
+		name.name = SGI_ACL_DEFAULT;
  		break;
  	default:
  		return -EINVAL;
@@ -187,17 +187,16 @@ __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, strlen(ea_name),
-				     (unsigned char *)xfs_acl, len, ATTR_ROOT);
+		name.len = strlen(name.name);
+		name.type = ATTR_ROOT;
+		error = xfs_attr_set(ip, &name, (unsigned char *)xfs_acl, len);
 
  		kmem_free(xfs_acl);
  	} else {
  		/*
  		 * A NULL ACL argument means we want to remove the ACL.
  		 */
-		error = xfs_attr_remove(ip, ea_name,
-					strlen(ea_name),
-					ATTR_ROOT);
+		error = xfs_attr_remove(ip, &name);
 
  		/*
  		 * If the attribute didn't exist to start with that's fine.
fs/xfs/xfs_ioctl.c +18 -10
index d440426..626420d 100644
@@ -431,7 +431,11 @@ xfs_attrmulti_attr_get(
  {
  	unsigned char		*kbuf;
  	int			error = -EFAULT;
-	size_t			namelen;
+	struct xfs_name		xname = {
+		.name		= name,
+		.len		= strlen(name),
+		.type		= flags,
+	};
 
  	if (*len > XFS_XATTR_SIZE_MAX)
  		return -EINVAL;
@@ -439,9 +443,7 @@ xfs_attrmulti_attr_get(
  	if (!kbuf)
  		return -ENOMEM;
 
-	namelen = strlen(name);
-	error = xfs_attr_get(XFS_I(inode), name, namelen, &kbuf, (int *)len,
-			     flags);
+	error = xfs_attr_get(XFS_I(inode), &xname, &kbuf, (int *)len);
  	if (error)
  		goto out_kfree;
 
@@ -463,7 +465,7 @@ xfs_attrmulti_attr_set(
  {
  	unsigned char		*kbuf;
  	int			error;
-	size_t			namelen;
+	struct xfs_name		xname;
 
  	if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
  		return -EPERM;
@@ -474,8 +476,10 @@ xfs_attrmulti_attr_set(
  	if (IS_ERR(kbuf))
  		return PTR_ERR(kbuf);
 
-	namelen = strlen(name);
-	error = xfs_attr_set(XFS_I(inode), name, namelen, kbuf, len, flags);
+	xname.name = name;
+	xname.len = strlen(name);
+	xname.type = flags;
+	error = xfs_attr_set(XFS_I(inode), &xname, kbuf, len);
  	if (!error)
  		xfs_forget_acl(inode, name, flags);
  	kfree(kbuf);
@@ -489,12 +493,16 @@ xfs_attrmulti_attr_remove(
  	uint32_t		flags)
  {
  	int			error;
-	size_t			namelen;
+	struct xfs_name		xname = {
+		.name		= name,
+		.len		= strlen(name),
+		.type		= flags,
+	};
 
  	if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
  		return -EPERM;
-	namelen = strlen(name);
-	error = xfs_attr_remove(XFS_I(inode), name, namelen, flags);
+
+	error = xfs_attr_remove(XFS_I(inode), &xname);
  	if (!error)
  		xfs_forget_acl(inode, name, flags);
  	return error;
fs/xfs/xfs_iops.c +8 -4
index 92de0a7..469e8e2 100644
@@ -49,10 +49,14 @@ 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_name	name = {
+			.name	= xattr->name,
+			.len	= strlen(xattr->name),
+			.type	= ATTR_SECURE,
+		};
+
+		error = xfs_attr_set(ip, &name,
+				     xattr->value, xattr->value_len);
  		if (error < 0)
  			break;
  	}
fs/xfs/xfs_xattr.c +17 -13
index 59ffe6c..6309da4 100644
@@ -20,19 +20,21 @@ static int
  xfs_xattr_get(const struct xattr_handler *handler, struct dentry *unused,
  		struct inode *inode, const char *name, void *value, size_t size)
  {
-	int xflags = handler->flags;
  	struct xfs_inode *ip = XFS_I(inode);
  	int error, asize = size;
-	size_t namelen = strlen(name);
+	struct xfs_name xname = {
+		.name	= name,
+		.len	= strlen(name),
+		.type	= handler->flags
+	};
 
  	/* Convert Linux syscall to XFS internal ATTR flags */
  	if (!size) {
-		xflags |= ATTR_KERNOVAL;
+		xname.type |= ATTR_KERNOVAL;
  		value = NULL;
  	}
 
-	error = xfs_attr_get(ip, name, namelen, (unsigned char **)&value,
-			     &asize, xflags);
+	error = xfs_attr_get(ip, &xname, (unsigned char **)&value, &asize);
  	if (error)
  		return error;
  	return asize;
@@ -65,23 +67,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);
  	int			error;
-	size_t			namelen = strlen(name);
+	struct xfs_name		xname = {
+		.name		= name,
+		.len		= strlen(name),
+		.type		= handler->flags,
+	};
 
  	/* Convert Linux syscall to XFS internal ATTR flags */
  	if (flags & XATTR_CREATE)
-		xflags |= ATTR_CREATE;
+		xname.type |= ATTR_CREATE;
  	if (flags & XATTR_REPLACE)
-		xflags |= ATTR_REPLACE;
+		xname.type |= ATTR_REPLACE;
 
  	if (!value)
-		return xfs_attr_remove(ip, name,
-				       namelen, xflags);
-	error = xfs_attr_set(ip, name, namelen, (void *)value, size, xflags);
+		return xfs_attr_remove(ip, &xname);
+	error = xfs_attr_set(ip, &xname, (void *)value, size);
  	if (!error)
-		xfs_forget_acl(inode, name, xflags);
+		xfs_forget_acl(inode, name, xname.type);
 
  	return error;
  }
Signature · 1 line
2.7.4
#4 lore raw

Re: [PATCH v3 01/19] xfs: Replace attribute parameters with struct xfs_name

Quoted 53 lines · Allison Collins
Quoted 43 lines · Brian Foster
Quoted 18 lines · Allison Collins

This patch replaces the attribute name, length and flags parameters with a single struct xfs_name parameter. This helps to clean up the numbers of parameters being passed around and pre-simplifies the code some.

---
  fs/xfs/libxfs/xfs_attr.c | 46 +++++++++++++++++++---------------------------
  fs/xfs/libxfs/xfs_attr.h | 12 +++++-------
  fs/xfs/xfs_acl.c         | 27 +++++++++++++--------------
  fs/xfs/xfs_ioctl.c       | 28 ++++++++++++++++++----------
  fs/xfs/xfs_iops.c        | 12 ++++++++----
  fs/xfs/xfs_xattr.c       | 30 +++++++++++++++++-------------
  6 files changed, 80 insertions(+), 75 deletions(-)
fs/xfs/libxfs/xfs_attr.c +0 -0
index 7589cb7..d0308d6 100644

...

Quoted 7 lines
fs/xfs/libxfs/xfs_attr.c +1 -2
@@ -139,30 +137,28 @@ xfs_attr_get_ilocked(
  int
  xfs_attr_get(
  	struct xfs_inode	*ip,
-	const unsigned char	*name,
-	size_t			namelen,
+	struct xfs_name		*name,

fs/xfs/libxfs/xfs_attr.c xfs_attr_get_ilocked( · line 147

Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +2 -3
  	unsigned char		**value,
-	int			*valuelenp,
-	int			flags)
+	int			*valuelenp)
  {
  	struct xfs_da_args	args;
  	uint			lock_mode;
  	int			error;
-	ASSERT((flags & (ATTR_ALLOC | ATTR_KERNOVAL)) || *value);
+	ASSERT((name->type & (ATTR_ALLOC | ATTR_KERNOVAL)) || *value);

While this looks like a nice cleanup, I'm not a huge fan of burying the attr flags in the xfs_name like this. To me they are distinct parameters and the interface isn't as clear for new callers. Other than that the patch looks good.

Quoted 6 lines

BTW after looking at the next patch, a reasonable compromise might be to leave the flags param for the top level xfs_attr_*() functions and then bury the value in args->name.type for the rest of the lower level code to use. Just a thought..

Brian

Quoted 9 lines

Yes, this was a sort of cleanup suggested in the last review. While it is nice to have less parameters, I ended up having mixed feels about using type for flags. Mostly just because a name of "type" generally implies that the field should be handled like an enumeration, and a "flag" implies that is should be handled like a bitmask. So I found myself doing a lot of double takes just in looking at it. I am fine with moving flags back out, but I would like folks to weigh in so that we have a consensus on what people are comfortable with.

Sure..

Quoted 6 lines

I'm not sure I like the idea of putting "value" in "type" though. Generally a "value" implies a sort of payload with a length (of which we have). But but I think separating value and valuelen would look all sorts of weird. I think either value should stay outside with valuelen, or we should probably bite the bullet and introduce a new struct for the purpose. Thoughts?

Note that I was referring to the flags value in a general sense, not the actual attr value. I.e., leave the xfs_attr_() flags param, then store flags in args->name.type if you really wanted to save the extra field from args and remove the rest of the flags passing beneath the top level functions.

Brian

Quoted 341 lines

Allison

Quoted 339 lines
Quoted 339 lines
fs/xfs/libxfs/xfs_attr.c +12 -16
  	XFS_STATS_INC(ip->i_mount, xs_attr_get);
  	if (XFS_FORCED_SHUTDOWN(ip->i_mount))
  		return -EIO;
-	error = xfs_attr_args_init(&args, ip, name, namelen, flags);
+	error = xfs_attr_args_init(&args, ip, name);
  	if (error)
  		return error;
  	/* Entirely possible to look up a name which doesn't exist */
  	args.op_flags = XFS_DA_OP_OKNOENT;
-	if (flags & ATTR_ALLOC)
+	if (name->type & ATTR_ALLOC)
  		args.op_flags |= XFS_DA_OP_ALLOCVAL;
  	else
  		args.value = *value;
@@ -175,7 +171,7 @@ xfs_attr_get(
  	/* on error, we have to clean up allocated value buffers */
  	if (error) {
-		if (flags & ATTR_ALLOC) {
+		if (name->type & ATTR_ALLOC) {
  			kmem_free(args.value);
  			*value = NULL;
  		}
@@ -339,16 +335,14 @@ xfs_attr_remove_args(
  int
  xfs_attr_set(
  	struct xfs_inode	*dp,
-	const unsigned char	*name,
-	size_t			namelen,
+	struct xfs_name		*name,
  	unsigned char		*value,
-	int			valuelen,
-	int			flags)
+	int			valuelen)
  {
  	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 = (name->type & ATTR_ROOT) != 0;
  	int			error, local;
  	XFS_STATS_INC(mp, xs_attr_set);
@@ -356,7 +350,7 @@ xfs_attr_set(
  	if (XFS_FORCED_SHUTDOWN(dp->i_mount))
  		return -EIO;
-	error = xfs_attr_args_init(&args, dp, name, namelen, flags);
+	error = xfs_attr_args_init(&args, dp, name);
  	if (error)
  		return error;
@@ -419,7 +413,7 @@ xfs_attr_set(
  	if (mp->m_flags & XFS_MOUNT_WSYNC)
  		xfs_trans_set_sync(args.trans);
-	if ((flags & ATTR_KERNOTIME) == 0)
+	if ((name->type & ATTR_KERNOTIME) == 0)
  		xfs_trans_ichgtime(args.trans, dp, XFS_ICHGTIME_CHG);
  	/*
@@ -444,9 +438,7 @@ xfs_attr_set(
  int
  xfs_attr_remove(
  	struct xfs_inode	*dp,
-	const unsigned char	*name,
-	size_t			namelen,
-	int			flags)
+	struct xfs_name		*name)
  {
  	struct xfs_mount	*mp = dp->i_mount;
  	struct xfs_da_args	args;
@@ -457,7 +449,7 @@ xfs_attr_remove(
  	if (XFS_FORCED_SHUTDOWN(dp->i_mount))
  		return -EIO;
-	error = xfs_attr_args_init(&args, dp, name, namelen, flags);
+	error = xfs_attr_args_init(&args, dp, name);
  	if (error)
  		return error;
@@ -478,7 +470,7 @@ xfs_attr_remove(
  	 */
  	error = xfs_trans_alloc(mp, &M_RES(mp)->tr_attrrm,
  			XFS_ATTRRM_SPACE_RES(mp), 0,
-			(flags & ATTR_ROOT) ? XFS_TRANS_RESERVE : 0,
+			(name->type & ATTR_ROOT) ? XFS_TRANS_RESERVE : 0,
  			&args.trans);
  	if (error)
  		return error;
@@ -501,7 +493,7 @@ xfs_attr_remove(
  	if (mp->m_flags & XFS_MOUNT_WSYNC)
  		xfs_trans_set_sync(args.trans);
-	if ((flags & ATTR_KERNOTIME) == 0)
+	if ((name->type & ATTR_KERNOTIME) == 0)
  		xfs_trans_ichgtime(args.trans, dp, XFS_ICHGTIME_CHG);
  	/*
fs/xfs/libxfs/xfs_attr.h +5 -7
index 106a2f2..cedb4e2 100644
@@ -144,14 +144,12 @@ int xfs_attr_list_int_ilocked(struct xfs_attr_list_context *);
  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,
-		 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_get(struct xfs_inode *ip, struct xfs_name *name,
+		 unsigned char **value, int *valuelenp);
+int xfs_attr_set(struct xfs_inode *dp, struct xfs_name *name,
+		 unsigned char *value, int valuelen);
  int xfs_attr_set_args(struct xfs_da_args *args);
-int xfs_attr_remove(struct xfs_inode *dp, const unsigned char *name,
-		    size_t namelen, int flags);
+int xfs_attr_remove(struct xfs_inode *dp, struct xfs_name *name);
  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);
fs/xfs/xfs_acl.c +13 -14
index 12be708..f8fb6e10 100644
@@ -113,7 +113,7 @@ xfs_get_acl(struct inode *inode, int type)
  	struct xfs_inode *ip = XFS_I(inode);
  	struct posix_acl *acl = NULL;
  	struct xfs_acl *xfs_acl = NULL;
-	unsigned char *ea_name;
+	struct xfs_name name;
  	int error;
  	int len;
@@ -121,10 +121,10 @@ xfs_get_acl(struct inode *inode, int type)
  	switch (type) {
  	case ACL_TYPE_ACCESS:
-		ea_name = SGI_ACL_FILE;
+		name.name = SGI_ACL_FILE;
  		break;
  	case ACL_TYPE_DEFAULT:
-		ea_name = SGI_ACL_DEFAULT;
+		name.name = SGI_ACL_DEFAULT;
  		break;
  	default:
  		BUG();
@@ -135,9 +135,9 @@ 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, strlen(ea_name),
-				(unsigned char **)&xfs_acl, &len,
-				ATTR_ALLOC | ATTR_ROOT);
+	name.len = strlen(name.name);
+	name.type = ATTR_ALLOC | ATTR_ROOT;
+	error = xfs_attr_get(ip, &name, (unsigned char **)&xfs_acl, &len);
  	if (error) {
  		/*
  		 * If the attribute doesn't exist make sure we have a negative
@@ -157,17 +157,17 @@ 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_name name;
  	int error;
  	switch (type) {
  	case ACL_TYPE_ACCESS:
-		ea_name = SGI_ACL_FILE;
+		name.name = SGI_ACL_FILE;
  		break;
  	case ACL_TYPE_DEFAULT:
  		if (!S_ISDIR(inode->i_mode))
  			return acl ? -EACCES : 0;
-		ea_name = SGI_ACL_DEFAULT;
+		name.name = SGI_ACL_DEFAULT;
  		break;
  	default:
  		return -EINVAL;
@@ -187,17 +187,16 @@ __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, strlen(ea_name),
-				     (unsigned char *)xfs_acl, len, ATTR_ROOT);
+		name.len = strlen(name.name);
+		name.type = ATTR_ROOT;
+		error = xfs_attr_set(ip, &name, (unsigned char *)xfs_acl, len);
  		kmem_free(xfs_acl);
  	} else {
  		/*
  		 * A NULL ACL argument means we want to remove the ACL.
  		 */
-		error = xfs_attr_remove(ip, ea_name,
-					strlen(ea_name),
-					ATTR_ROOT);
+		error = xfs_attr_remove(ip, &name);
  		/*
  		 * If the attribute didn't exist to start with that's fine.
fs/xfs/xfs_ioctl.c +18 -10
index d440426..626420d 100644
@@ -431,7 +431,11 @@ xfs_attrmulti_attr_get(
  {
  	unsigned char		*kbuf;
  	int			error = -EFAULT;
-	size_t			namelen;
+	struct xfs_name		xname = {
+		.name		= name,
+		.len		= strlen(name),
+		.type		= flags,
+	};
  	if (*len > XFS_XATTR_SIZE_MAX)
  		return -EINVAL;
@@ -439,9 +443,7 @@ xfs_attrmulti_attr_get(
  	if (!kbuf)
  		return -ENOMEM;
-	namelen = strlen(name);
-	error = xfs_attr_get(XFS_I(inode), name, namelen, &kbuf, (int *)len,
-			     flags);
+	error = xfs_attr_get(XFS_I(inode), &xname, &kbuf, (int *)len);
  	if (error)
  		goto out_kfree;
@@ -463,7 +465,7 @@ xfs_attrmulti_attr_set(
  {
  	unsigned char		*kbuf;
  	int			error;
-	size_t			namelen;
+	struct xfs_name		xname;
  	if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
  		return -EPERM;
@@ -474,8 +476,10 @@ xfs_attrmulti_attr_set(
  	if (IS_ERR(kbuf))
  		return PTR_ERR(kbuf);
-	namelen = strlen(name);
-	error = xfs_attr_set(XFS_I(inode), name, namelen, kbuf, len, flags);
+	xname.name = name;
+	xname.len = strlen(name);
+	xname.type = flags;
+	error = xfs_attr_set(XFS_I(inode), &xname, kbuf, len);
  	if (!error)
  		xfs_forget_acl(inode, name, flags);
  	kfree(kbuf);
@@ -489,12 +493,16 @@ xfs_attrmulti_attr_remove(
  	uint32_t		flags)
  {
  	int			error;
-	size_t			namelen;
+	struct xfs_name		xname = {
+		.name		= name,
+		.len		= strlen(name),
+		.type		= flags,
+	};
  	if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
  		return -EPERM;
-	namelen = strlen(name);
-	error = xfs_attr_remove(XFS_I(inode), name, namelen, flags);
+
+	error = xfs_attr_remove(XFS_I(inode), &xname);
  	if (!error)
  		xfs_forget_acl(inode, name, flags);
  	return error;
fs/xfs/xfs_iops.c +8 -4
index 92de0a7..469e8e2 100644
@@ -49,10 +49,14 @@ 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_name	name = {
+			.name	= xattr->name,
+			.len	= strlen(xattr->name),
+			.type	= ATTR_SECURE,
+		};
+
+		error = xfs_attr_set(ip, &name,
+				     xattr->value, xattr->value_len);
  		if (error < 0)
  			break;
  	}
fs/xfs/xfs_xattr.c +17 -13
index 59ffe6c..6309da4 100644
@@ -20,19 +20,21 @@ static int
  xfs_xattr_get(const struct xattr_handler *handler, struct dentry *unused,
  		struct inode *inode, const char *name, void *value, size_t size)
  {
-	int xflags = handler->flags;
  	struct xfs_inode *ip = XFS_I(inode);
  	int error, asize = size;
-	size_t namelen = strlen(name);
+	struct xfs_name xname = {
+		.name	= name,
+		.len	= strlen(name),
+		.type	= handler->flags
+	};
  	/* Convert Linux syscall to XFS internal ATTR flags */
  	if (!size) {
-		xflags |= ATTR_KERNOVAL;
+		xname.type |= ATTR_KERNOVAL;
  		value = NULL;
  	}
-	error = xfs_attr_get(ip, name, namelen, (unsigned char **)&value,
-			     &asize, xflags);
+	error = xfs_attr_get(ip, &xname, (unsigned char **)&value, &asize);
  	if (error)
  		return error;
  	return asize;
@@ -65,23 +67,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);
  	int			error;
-	size_t			namelen = strlen(name);
+	struct xfs_name		xname = {
+		.name		= name,
+		.len		= strlen(name),
+		.type		= handler->flags,
+	};
  	/* Convert Linux syscall to XFS internal ATTR flags */
  	if (flags & XATTR_CREATE)
-		xflags |= ATTR_CREATE;
+		xname.type |= ATTR_CREATE;
  	if (flags & XATTR_REPLACE)
-		xflags |= ATTR_REPLACE;
+		xname.type |= ATTR_REPLACE;
  	if (!value)
-		return xfs_attr_remove(ip, name,
-				       namelen, xflags);
-	error = xfs_attr_set(ip, name, namelen, (void *)value, size, xflags);
+		return xfs_attr_remove(ip, &xname);
+	error = xfs_attr_set(ip, &xname, (void *)value, size);
  	if (!error)
-		xfs_forget_acl(inode, name, xflags);
+		xfs_forget_acl(inode, name, xname.type);
  	return error;
  }
Signature · 1 line
2.7.4
#5 lore raw

Re: [PATCH v3 01/19] xfs: Replace attribute parameters with struct xfs_name

Quoted 73 lines · Brian Foster
Quoted 53 lines · Allison Collins
Quoted 43 lines · Brian Foster
Quoted 18 lines · Allison Collins

This patch replaces the attribute name, length and flags parameters with a single struct xfs_name parameter. This helps to clean up the numbers of parameters being passed around and pre-simplifies the code some.

---
   fs/xfs/libxfs/xfs_attr.c | 46 +++++++++++++++++++---------------------------
   fs/xfs/libxfs/xfs_attr.h | 12 +++++-------
   fs/xfs/xfs_acl.c         | 27 +++++++++++++--------------
   fs/xfs/xfs_ioctl.c       | 28 ++++++++++++++++++----------
   fs/xfs/xfs_iops.c        | 12 ++++++++----
   fs/xfs/xfs_xattr.c       | 30 +++++++++++++++++-------------
   6 files changed, 80 insertions(+), 75 deletions(-)
fs/xfs/libxfs/xfs_attr.c +0 -0
index 7589cb7..d0308d6 100644

...

Quoted 7 lines
fs/xfs/libxfs/xfs_attr.c +1 -2
@@ -139,30 +137,28 @@ xfs_attr_get_ilocked(
   int
   xfs_attr_get(
   	struct xfs_inode	*ip,
-	const unsigned char	*name,
-	size_t			namelen,
+	struct xfs_name		*name,

fs/xfs/libxfs/xfs_attr.c xfs_attr_get_ilocked( · line 147

Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +2 -3
   	unsigned char		**value,
-	int			*valuelenp,
-	int			flags)
+	int			*valuelenp)
   {
   	struct xfs_da_args	args;
   	uint			lock_mode;
   	int			error;
-	ASSERT((flags & (ATTR_ALLOC | ATTR_KERNOVAL)) || *value);
+	ASSERT((name->type & (ATTR_ALLOC | ATTR_KERNOVAL)) || *value);

While this looks like a nice cleanup, I'm not a huge fan of burying the attr flags in the xfs_name like this. To me they are distinct parameters and the interface isn't as clear for new callers. Other than that the patch looks good.

Quoted 6 lines

BTW after looking at the next patch, a reasonable compromise might be to leave the flags param for the top level xfs_attr_*() functions and then bury the value in args->name.type for the rest of the lower level code to use. Just a thought..

Brian

Quoted 9 lines

Yes, this was a sort of cleanup suggested in the last review. While it is nice to have less parameters, I ended up having mixed feels about using type for flags. Mostly just because a name of "type" generally implies that the field should be handled like an enumeration, and a "flag" implies that is should be handled like a bitmask. So I found myself doing a lot of double takes just in looking at it. I am fine with moving flags back out, but I would like folks to weigh in so that we have a consensus on what people are comfortable with.

Sure..

Quoted 6 lines

I'm not sure I like the idea of putting "value" in "type" though. Generally a "value" implies a sort of payload with a length (of which we have). But but I think separating value and valuelen would look all sorts of weird. I think either value should stay outside with valuelen, or we should probably bite the bullet and introduce a new struct for the purpose. Thoughts?

Quoted 7 lines

Note that I was referring to the flags value in a general sense, not the actual attr value. I.e., leave the xfs_attr_() flags param, then store flags in args->name.type if you really wanted to save the extra field from args and remove the rest of the flags passing beneath the top level functions.

Brian

Oh, I see, I misunderstood what you meant. That makes more sense :-) Sure that seems like a reasonable compromise. Lets see if we can get a consensus from folks though, because little stuff like this tends to pepper small changes up through the set, and it would be nice to get everyone settled on the same page. :-)

Allison

Quoted 342 lines
Quoted 342 lines

Allison

Quoted 339 lines
Quoted 339 lines
fs/xfs/libxfs/xfs_attr.c +12 -16
   	XFS_STATS_INC(ip->i_mount, xs_attr_get);
   	if (XFS_FORCED_SHUTDOWN(ip->i_mount))
   		return -EIO;
-	error = xfs_attr_args_init(&args, ip, name, namelen, flags);
+	error = xfs_attr_args_init(&args, ip, name);
   	if (error)
   		return error;
   	/* Entirely possible to look up a name which doesn't exist */
   	args.op_flags = XFS_DA_OP_OKNOENT;
-	if (flags & ATTR_ALLOC)
+	if (name->type & ATTR_ALLOC)
   		args.op_flags |= XFS_DA_OP_ALLOCVAL;
   	else
   		args.value = *value;
@@ -175,7 +171,7 @@ xfs_attr_get(
   	/* on error, we have to clean up allocated value buffers */
   	if (error) {
-		if (flags & ATTR_ALLOC) {
+		if (name->type & ATTR_ALLOC) {
   			kmem_free(args.value);
   			*value = NULL;
   		}
@@ -339,16 +335,14 @@ xfs_attr_remove_args(
   int
   xfs_attr_set(
   	struct xfs_inode	*dp,
-	const unsigned char	*name,
-	size_t			namelen,
+	struct xfs_name		*name,
   	unsigned char		*value,
-	int			valuelen,
-	int			flags)
+	int			valuelen)
   {
   	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 = (name->type & ATTR_ROOT) != 0;
   	int			error, local;
   	XFS_STATS_INC(mp, xs_attr_set);
@@ -356,7 +350,7 @@ xfs_attr_set(
   	if (XFS_FORCED_SHUTDOWN(dp->i_mount))
   		return -EIO;
-	error = xfs_attr_args_init(&args, dp, name, namelen, flags);
+	error = xfs_attr_args_init(&args, dp, name);
   	if (error)
   		return error;
@@ -419,7 +413,7 @@ xfs_attr_set(
   	if (mp->m_flags & XFS_MOUNT_WSYNC)
   		xfs_trans_set_sync(args.trans);
-	if ((flags & ATTR_KERNOTIME) == 0)
+	if ((name->type & ATTR_KERNOTIME) == 0)
   		xfs_trans_ichgtime(args.trans, dp, XFS_ICHGTIME_CHG);
   	/*
@@ -444,9 +438,7 @@ xfs_attr_set(
   int
   xfs_attr_remove(
   	struct xfs_inode	*dp,
-	const unsigned char	*name,
-	size_t			namelen,
-	int			flags)
+	struct xfs_name		*name)
   {
   	struct xfs_mount	*mp = dp->i_mount;
   	struct xfs_da_args	args;
@@ -457,7 +449,7 @@ xfs_attr_remove(
   	if (XFS_FORCED_SHUTDOWN(dp->i_mount))
   		return -EIO;
-	error = xfs_attr_args_init(&args, dp, name, namelen, flags);
+	error = xfs_attr_args_init(&args, dp, name);
   	if (error)
   		return error;
@@ -478,7 +470,7 @@ xfs_attr_remove(
   	 */
   	error = xfs_trans_alloc(mp, &M_RES(mp)->tr_attrrm,
   			XFS_ATTRRM_SPACE_RES(mp), 0,
-			(flags & ATTR_ROOT) ? XFS_TRANS_RESERVE : 0,
+			(name->type & ATTR_ROOT) ? XFS_TRANS_RESERVE : 0,
   			&args.trans);
   	if (error)
   		return error;
@@ -501,7 +493,7 @@ xfs_attr_remove(
   	if (mp->m_flags & XFS_MOUNT_WSYNC)
   		xfs_trans_set_sync(args.trans);
-	if ((flags & ATTR_KERNOTIME) == 0)
+	if ((name->type & ATTR_KERNOTIME) == 0)
   		xfs_trans_ichgtime(args.trans, dp, XFS_ICHGTIME_CHG);
   	/*
fs/xfs/libxfs/xfs_attr.h +5 -7
index 106a2f2..cedb4e2 100644
@@ -144,14 +144,12 @@ int xfs_attr_list_int_ilocked(struct xfs_attr_list_context *);
   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,
-		 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_get(struct xfs_inode *ip, struct xfs_name *name,
+		 unsigned char **value, int *valuelenp);
+int xfs_attr_set(struct xfs_inode *dp, struct xfs_name *name,
+		 unsigned char *value, int valuelen);
   int xfs_attr_set_args(struct xfs_da_args *args);
-int xfs_attr_remove(struct xfs_inode *dp, const unsigned char *name,
-		    size_t namelen, int flags);
+int xfs_attr_remove(struct xfs_inode *dp, struct xfs_name *name);
   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);
fs/xfs/xfs_acl.c +13 -14
index 12be708..f8fb6e10 100644
@@ -113,7 +113,7 @@ xfs_get_acl(struct inode *inode, int type)
   	struct xfs_inode *ip = XFS_I(inode);
   	struct posix_acl *acl = NULL;
   	struct xfs_acl *xfs_acl = NULL;
-	unsigned char *ea_name;
+	struct xfs_name name;
   	int error;
   	int len;
@@ -121,10 +121,10 @@ xfs_get_acl(struct inode *inode, int type)
   	switch (type) {
   	case ACL_TYPE_ACCESS:
-		ea_name = SGI_ACL_FILE;
+		name.name = SGI_ACL_FILE;
   		break;
   	case ACL_TYPE_DEFAULT:
-		ea_name = SGI_ACL_DEFAULT;
+		name.name = SGI_ACL_DEFAULT;
   		break;
   	default:
   		BUG();
@@ -135,9 +135,9 @@ 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, strlen(ea_name),
-				(unsigned char **)&xfs_acl, &len,
-				ATTR_ALLOC | ATTR_ROOT);
+	name.len = strlen(name.name);
+	name.type = ATTR_ALLOC | ATTR_ROOT;
+	error = xfs_attr_get(ip, &name, (unsigned char **)&xfs_acl, &len);
   	if (error) {
   		/*
   		 * If the attribute doesn't exist make sure we have a negative
@@ -157,17 +157,17 @@ 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_name name;
   	int error;
   	switch (type) {
   	case ACL_TYPE_ACCESS:
-		ea_name = SGI_ACL_FILE;
+		name.name = SGI_ACL_FILE;
   		break;
   	case ACL_TYPE_DEFAULT:
   		if (!S_ISDIR(inode->i_mode))
   			return acl ? -EACCES : 0;
-		ea_name = SGI_ACL_DEFAULT;
+		name.name = SGI_ACL_DEFAULT;
   		break;
   	default:
   		return -EINVAL;
@@ -187,17 +187,16 @@ __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, strlen(ea_name),
-				     (unsigned char *)xfs_acl, len, ATTR_ROOT);
+		name.len = strlen(name.name);
+		name.type = ATTR_ROOT;
+		error = xfs_attr_set(ip, &name, (unsigned char *)xfs_acl, len);
   		kmem_free(xfs_acl);
   	} else {
   		/*
   		 * A NULL ACL argument means we want to remove the ACL.
   		 */
-		error = xfs_attr_remove(ip, ea_name,
-					strlen(ea_name),
-					ATTR_ROOT);
+		error = xfs_attr_remove(ip, &name);
   		/*
   		 * If the attribute didn't exist to start with that's fine.
fs/xfs/xfs_ioctl.c +18 -10
index d440426..626420d 100644
@@ -431,7 +431,11 @@ xfs_attrmulti_attr_get(
   {
   	unsigned char		*kbuf;
   	int			error = -EFAULT;
-	size_t			namelen;
+	struct xfs_name		xname = {
+		.name		= name,
+		.len		= strlen(name),
+		.type		= flags,
+	};
   	if (*len > XFS_XATTR_SIZE_MAX)
   		return -EINVAL;
@@ -439,9 +443,7 @@ xfs_attrmulti_attr_get(
   	if (!kbuf)
   		return -ENOMEM;
-	namelen = strlen(name);
-	error = xfs_attr_get(XFS_I(inode), name, namelen, &kbuf, (int *)len,
-			     flags);
+	error = xfs_attr_get(XFS_I(inode), &xname, &kbuf, (int *)len);
   	if (error)
   		goto out_kfree;
@@ -463,7 +465,7 @@ xfs_attrmulti_attr_set(
   {
   	unsigned char		*kbuf;
   	int			error;
-	size_t			namelen;
+	struct xfs_name		xname;
   	if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
   		return -EPERM;
@@ -474,8 +476,10 @@ xfs_attrmulti_attr_set(
   	if (IS_ERR(kbuf))
   		return PTR_ERR(kbuf);
-	namelen = strlen(name);
-	error = xfs_attr_set(XFS_I(inode), name, namelen, kbuf, len, flags);
+	xname.name = name;
+	xname.len = strlen(name);
+	xname.type = flags;
+	error = xfs_attr_set(XFS_I(inode), &xname, kbuf, len);
   	if (!error)
   		xfs_forget_acl(inode, name, flags);
   	kfree(kbuf);
@@ -489,12 +493,16 @@ xfs_attrmulti_attr_remove(
   	uint32_t		flags)
   {
   	int			error;
-	size_t			namelen;
+	struct xfs_name		xname = {
+		.name		= name,
+		.len		= strlen(name),
+		.type		= flags,
+	};
   	if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
   		return -EPERM;
-	namelen = strlen(name);
-	error = xfs_attr_remove(XFS_I(inode), name, namelen, flags);
+
+	error = xfs_attr_remove(XFS_I(inode), &xname);
   	if (!error)
   		xfs_forget_acl(inode, name, flags);
   	return error;
fs/xfs/xfs_iops.c +8 -4
index 92de0a7..469e8e2 100644
@@ -49,10 +49,14 @@ 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_name	name = {
+			.name	= xattr->name,
+			.len	= strlen(xattr->name),
+			.type	= ATTR_SECURE,
+		};
+
+		error = xfs_attr_set(ip, &name,
+				     xattr->value, xattr->value_len);
   		if (error < 0)
   			break;
   	}
fs/xfs/xfs_xattr.c +17 -13
index 59ffe6c..6309da4 100644
@@ -20,19 +20,21 @@ static int
   xfs_xattr_get(const struct xattr_handler *handler, struct dentry *unused,
   		struct inode *inode, const char *name, void *value, size_t size)
   {
-	int xflags = handler->flags;
   	struct xfs_inode *ip = XFS_I(inode);
   	int error, asize = size;
-	size_t namelen = strlen(name);
+	struct xfs_name xname = {
+		.name	= name,
+		.len	= strlen(name),
+		.type	= handler->flags
+	};
   	/* Convert Linux syscall to XFS internal ATTR flags */
   	if (!size) {
-		xflags |= ATTR_KERNOVAL;
+		xname.type |= ATTR_KERNOVAL;
   		value = NULL;
   	}
-	error = xfs_attr_get(ip, name, namelen, (unsigned char **)&value,
-			     &asize, xflags);
+	error = xfs_attr_get(ip, &xname, (unsigned char **)&value, &asize);
   	if (error)
   		return error;
   	return asize;
@@ -65,23 +67,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);
   	int			error;
-	size_t			namelen = strlen(name);
+	struct xfs_name		xname = {
+		.name		= name,
+		.len		= strlen(name),
+		.type		= handler->flags,
+	};
   	/* Convert Linux syscall to XFS internal ATTR flags */
   	if (flags & XATTR_CREATE)
-		xflags |= ATTR_CREATE;
+		xname.type |= ATTR_CREATE;
   	if (flags & XATTR_REPLACE)
-		xflags |= ATTR_REPLACE;
+		xname.type |= ATTR_REPLACE;
   	if (!value)
-		return xfs_attr_remove(ip, name,
-				       namelen, xflags);
-	error = xfs_attr_set(ip, name, namelen, (void *)value, size, xflags);
+		return xfs_attr_remove(ip, &xname);
+	error = xfs_attr_set(ip, &xname, (void *)value, size);
   	if (!error)
-		xfs_forget_acl(inode, name, xflags);
+		xfs_forget_acl(inode, name, xname.type);
   	return error;
   }
Signature · 1 line
2.7.4
#6 lore raw

Re: [PATCH v3 01/19] xfs: Replace attribute parameters with struct xfs_name

Quoted 80 lines · Allison Collins
Quoted 79 lines · Brian Foster
Quoted 53 lines · Allison Collins
Quoted 43 lines · Brian Foster
Quoted 18 lines · Allison Collins

This patch replaces the attribute name, length and flags parameters with a single struct xfs_name parameter. This helps to clean up the numbers of parameters being passed around and pre-simplifies the code some.

---
   fs/xfs/libxfs/xfs_attr.c | 46 +++++++++++++++++++---------------------------
   fs/xfs/libxfs/xfs_attr.h | 12 +++++-------
   fs/xfs/xfs_acl.c         | 27 +++++++++++++--------------
   fs/xfs/xfs_ioctl.c       | 28 ++++++++++++++++++----------
   fs/xfs/xfs_iops.c        | 12 ++++++++----
   fs/xfs/xfs_xattr.c       | 30 +++++++++++++++++-------------
   6 files changed, 80 insertions(+), 75 deletions(-)
fs/xfs/libxfs/xfs_attr.c +0 -0
index 7589cb7..d0308d6 100644

...

Quoted 7 lines
fs/xfs/libxfs/xfs_attr.c +1 -2
@@ -139,30 +137,28 @@ xfs_attr_get_ilocked(
   int
   xfs_attr_get(
   	struct xfs_inode	*ip,
-	const unsigned char	*name,
-	size_t			namelen,
+	struct xfs_name		*name,

fs/xfs/libxfs/xfs_attr.c xfs_attr_get_ilocked( · line 147

Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +2 -3
   	unsigned char		**value,
-	int			*valuelenp,
-	int			flags)
+	int			*valuelenp)
   {
   	struct xfs_da_args	args;
   	uint			lock_mode;
   	int			error;
-	ASSERT((flags & (ATTR_ALLOC | ATTR_KERNOVAL)) || *value);
+	ASSERT((name->type & (ATTR_ALLOC | ATTR_KERNOVAL)) || *value);

While this looks like a nice cleanup, I'm not a huge fan of burying the attr flags in the xfs_name like this. To me they are distinct parameters and the interface isn't as clear for new callers. Other than that the patch looks good.

Quoted 6 lines

BTW after looking at the next patch, a reasonable compromise might be to leave the flags param for the top level xfs_attr_*() functions and then bury the value in args->name.type for the rest of the lower level code to use. Just a thought..

Brian

Quoted 9 lines

Yes, this was a sort of cleanup suggested in the last review. While it is nice to have less parameters, I ended up having mixed feels about using type for flags. Mostly just because a name of "type" generally implies that the field should be handled like an enumeration, and a "flag" implies that is should be handled like a bitmask. So I found myself doing a lot of double takes just in looking at it. I am fine with moving flags back out, but I would like folks to weigh in so that we have a consensus on what people are comfortable with.

Sure..

Quoted 6 lines

I'm not sure I like the idea of putting "value" in "type" though. Generally a "value" implies a sort of payload with a length (of which we have). But but I think separating value and valuelen would look all sorts of weird. I think either value should stay outside with valuelen, or we should probably bite the bullet and introduce a new struct for the purpose. Thoughts?

Note that I was referring to the flags value in a general sense, not the actual attr value. I.e., leave the xfs_attr_() flags param, then store flags in args->name.type if you really wanted to save the extra field from args and remove the rest of the flags passing beneath the top level functions.

Quoted 7 lines
Quoted 1 line

Brian

Oh, I see, I misunderstood what you meant. That makes more sense :-) Sure that seems like a reasonable compromise. Lets see if we can get a consensus from folks though, because little stuff like this tends to pepper small changes up through the set, and it would be nice to get everyone settled on the same page. :-)

/me agrees with Brian, the top level xfs_attr_[gs]et functions should take a separate flags argument, even if internally it stuffs them into the "type" argument of the name to save space in the args structure.

--D

Quoted 344 lines

Allison

Quoted 342 lines
Quoted 342 lines

Allison

Quoted 339 lines
Quoted 339 lines
fs/xfs/libxfs/xfs_attr.c +12 -16
   	XFS_STATS_INC(ip->i_mount, xs_attr_get);
   	if (XFS_FORCED_SHUTDOWN(ip->i_mount))
   		return -EIO;
-	error = xfs_attr_args_init(&args, ip, name, namelen, flags);
+	error = xfs_attr_args_init(&args, ip, name);
   	if (error)
   		return error;
   	/* Entirely possible to look up a name which doesn't exist */
   	args.op_flags = XFS_DA_OP_OKNOENT;
-	if (flags & ATTR_ALLOC)
+	if (name->type & ATTR_ALLOC)
   		args.op_flags |= XFS_DA_OP_ALLOCVAL;
   	else
   		args.value = *value;
@@ -175,7 +171,7 @@ xfs_attr_get(
   	/* on error, we have to clean up allocated value buffers */
   	if (error) {
-		if (flags & ATTR_ALLOC) {
+		if (name->type & ATTR_ALLOC) {
   			kmem_free(args.value);
   			*value = NULL;
   		}
@@ -339,16 +335,14 @@ xfs_attr_remove_args(
   int
   xfs_attr_set(
   	struct xfs_inode	*dp,
-	const unsigned char	*name,
-	size_t			namelen,
+	struct xfs_name		*name,
   	unsigned char		*value,
-	int			valuelen,
-	int			flags)
+	int			valuelen)
   {
   	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 = (name->type & ATTR_ROOT) != 0;
   	int			error, local;
   	XFS_STATS_INC(mp, xs_attr_set);
@@ -356,7 +350,7 @@ xfs_attr_set(
   	if (XFS_FORCED_SHUTDOWN(dp->i_mount))
   		return -EIO;
-	error = xfs_attr_args_init(&args, dp, name, namelen, flags);
+	error = xfs_attr_args_init(&args, dp, name);
   	if (error)
   		return error;
@@ -419,7 +413,7 @@ xfs_attr_set(
   	if (mp->m_flags & XFS_MOUNT_WSYNC)
   		xfs_trans_set_sync(args.trans);
-	if ((flags & ATTR_KERNOTIME) == 0)
+	if ((name->type & ATTR_KERNOTIME) == 0)
   		xfs_trans_ichgtime(args.trans, dp, XFS_ICHGTIME_CHG);
   	/*
@@ -444,9 +438,7 @@ xfs_attr_set(
   int
   xfs_attr_remove(
   	struct xfs_inode	*dp,
-	const unsigned char	*name,
-	size_t			namelen,
-	int			flags)
+	struct xfs_name		*name)
   {
   	struct xfs_mount	*mp = dp->i_mount;
   	struct xfs_da_args	args;
@@ -457,7 +449,7 @@ xfs_attr_remove(
   	if (XFS_FORCED_SHUTDOWN(dp->i_mount))
   		return -EIO;
-	error = xfs_attr_args_init(&args, dp, name, namelen, flags);
+	error = xfs_attr_args_init(&args, dp, name);
   	if (error)
   		return error;
@@ -478,7 +470,7 @@ xfs_attr_remove(
   	 */
   	error = xfs_trans_alloc(mp, &M_RES(mp)->tr_attrrm,
   			XFS_ATTRRM_SPACE_RES(mp), 0,
-			(flags & ATTR_ROOT) ? XFS_TRANS_RESERVE : 0,
+			(name->type & ATTR_ROOT) ? XFS_TRANS_RESERVE : 0,
   			&args.trans);
   	if (error)
   		return error;
@@ -501,7 +493,7 @@ xfs_attr_remove(
   	if (mp->m_flags & XFS_MOUNT_WSYNC)
   		xfs_trans_set_sync(args.trans);
-	if ((flags & ATTR_KERNOTIME) == 0)
+	if ((name->type & ATTR_KERNOTIME) == 0)
   		xfs_trans_ichgtime(args.trans, dp, XFS_ICHGTIME_CHG);
   	/*
fs/xfs/libxfs/xfs_attr.h +5 -7
index 106a2f2..cedb4e2 100644
@@ -144,14 +144,12 @@ int xfs_attr_list_int_ilocked(struct xfs_attr_list_context *);
   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,
-		 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_get(struct xfs_inode *ip, struct xfs_name *name,
+		 unsigned char **value, int *valuelenp);
+int xfs_attr_set(struct xfs_inode *dp, struct xfs_name *name,
+		 unsigned char *value, int valuelen);
   int xfs_attr_set_args(struct xfs_da_args *args);
-int xfs_attr_remove(struct xfs_inode *dp, const unsigned char *name,
-		    size_t namelen, int flags);
+int xfs_attr_remove(struct xfs_inode *dp, struct xfs_name *name);
   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);
fs/xfs/xfs_acl.c +13 -14
index 12be708..f8fb6e10 100644
@@ -113,7 +113,7 @@ xfs_get_acl(struct inode *inode, int type)
   	struct xfs_inode *ip = XFS_I(inode);
   	struct posix_acl *acl = NULL;
   	struct xfs_acl *xfs_acl = NULL;
-	unsigned char *ea_name;
+	struct xfs_name name;
   	int error;
   	int len;
@@ -121,10 +121,10 @@ xfs_get_acl(struct inode *inode, int type)
   	switch (type) {
   	case ACL_TYPE_ACCESS:
-		ea_name = SGI_ACL_FILE;
+		name.name = SGI_ACL_FILE;
   		break;
   	case ACL_TYPE_DEFAULT:
-		ea_name = SGI_ACL_DEFAULT;
+		name.name = SGI_ACL_DEFAULT;
   		break;
   	default:
   		BUG();
@@ -135,9 +135,9 @@ 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, strlen(ea_name),
-				(unsigned char **)&xfs_acl, &len,
-				ATTR_ALLOC | ATTR_ROOT);
+	name.len = strlen(name.name);
+	name.type = ATTR_ALLOC | ATTR_ROOT;
+	error = xfs_attr_get(ip, &name, (unsigned char **)&xfs_acl, &len);
   	if (error) {
   		/*
   		 * If the attribute doesn't exist make sure we have a negative
@@ -157,17 +157,17 @@ 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_name name;
   	int error;
   	switch (type) {
   	case ACL_TYPE_ACCESS:
-		ea_name = SGI_ACL_FILE;
+		name.name = SGI_ACL_FILE;
   		break;
   	case ACL_TYPE_DEFAULT:
   		if (!S_ISDIR(inode->i_mode))
   			return acl ? -EACCES : 0;
-		ea_name = SGI_ACL_DEFAULT;
+		name.name = SGI_ACL_DEFAULT;
   		break;
   	default:
   		return -EINVAL;
@@ -187,17 +187,16 @@ __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, strlen(ea_name),
-				     (unsigned char *)xfs_acl, len, ATTR_ROOT);
+		name.len = strlen(name.name);
+		name.type = ATTR_ROOT;
+		error = xfs_attr_set(ip, &name, (unsigned char *)xfs_acl, len);
   		kmem_free(xfs_acl);
   	} else {
   		/*
   		 * A NULL ACL argument means we want to remove the ACL.
   		 */
-		error = xfs_attr_remove(ip, ea_name,
-					strlen(ea_name),
-					ATTR_ROOT);
+		error = xfs_attr_remove(ip, &name);
   		/*
   		 * If the attribute didn't exist to start with that's fine.
fs/xfs/xfs_ioctl.c +18 -10
index d440426..626420d 100644
@@ -431,7 +431,11 @@ xfs_attrmulti_attr_get(
   {
   	unsigned char		*kbuf;
   	int			error = -EFAULT;
-	size_t			namelen;
+	struct xfs_name		xname = {
+		.name		= name,
+		.len		= strlen(name),
+		.type		= flags,
+	};
   	if (*len > XFS_XATTR_SIZE_MAX)
   		return -EINVAL;
@@ -439,9 +443,7 @@ xfs_attrmulti_attr_get(
   	if (!kbuf)
   		return -ENOMEM;
-	namelen = strlen(name);
-	error = xfs_attr_get(XFS_I(inode), name, namelen, &kbuf, (int *)len,
-			     flags);
+	error = xfs_attr_get(XFS_I(inode), &xname, &kbuf, (int *)len);
   	if (error)
   		goto out_kfree;
@@ -463,7 +465,7 @@ xfs_attrmulti_attr_set(
   {
   	unsigned char		*kbuf;
   	int			error;
-	size_t			namelen;
+	struct xfs_name		xname;
   	if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
   		return -EPERM;
@@ -474,8 +476,10 @@ xfs_attrmulti_attr_set(
   	if (IS_ERR(kbuf))
   		return PTR_ERR(kbuf);
-	namelen = strlen(name);
-	error = xfs_attr_set(XFS_I(inode), name, namelen, kbuf, len, flags);
+	xname.name = name;
+	xname.len = strlen(name);
+	xname.type = flags;
+	error = xfs_attr_set(XFS_I(inode), &xname, kbuf, len);
   	if (!error)
   		xfs_forget_acl(inode, name, flags);
   	kfree(kbuf);
@@ -489,12 +493,16 @@ xfs_attrmulti_attr_remove(
   	uint32_t		flags)
   {
   	int			error;
-	size_t			namelen;
+	struct xfs_name		xname = {
+		.name		= name,
+		.len		= strlen(name),
+		.type		= flags,
+	};
   	if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
   		return -EPERM;
-	namelen = strlen(name);
-	error = xfs_attr_remove(XFS_I(inode), name, namelen, flags);
+
+	error = xfs_attr_remove(XFS_I(inode), &xname);
   	if (!error)
   		xfs_forget_acl(inode, name, flags);
   	return error;
fs/xfs/xfs_iops.c +8 -4
index 92de0a7..469e8e2 100644
@@ -49,10 +49,14 @@ 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_name	name = {
+			.name	= xattr->name,
+			.len	= strlen(xattr->name),
+			.type	= ATTR_SECURE,
+		};
+
+		error = xfs_attr_set(ip, &name,
+				     xattr->value, xattr->value_len);
   		if (error < 0)
   			break;
   	}
fs/xfs/xfs_xattr.c +17 -13
index 59ffe6c..6309da4 100644
@@ -20,19 +20,21 @@ static int
   xfs_xattr_get(const struct xattr_handler *handler, struct dentry *unused,
   		struct inode *inode, const char *name, void *value, size_t size)
   {
-	int xflags = handler->flags;
   	struct xfs_inode *ip = XFS_I(inode);
   	int error, asize = size;
-	size_t namelen = strlen(name);
+	struct xfs_name xname = {
+		.name	= name,
+		.len	= strlen(name),
+		.type	= handler->flags
+	};
   	/* Convert Linux syscall to XFS internal ATTR flags */
   	if (!size) {
-		xflags |= ATTR_KERNOVAL;
+		xname.type |= ATTR_KERNOVAL;
   		value = NULL;
   	}
-	error = xfs_attr_get(ip, name, namelen, (unsigned char **)&value,
-			     &asize, xflags);
+	error = xfs_attr_get(ip, &xname, (unsigned char **)&value, &asize);
   	if (error)
   		return error;
   	return asize;
@@ -65,23 +67,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);
   	int			error;
-	size_t			namelen = strlen(name);
+	struct xfs_name		xname = {
+		.name		= name,
+		.len		= strlen(name),
+		.type		= handler->flags,
+	};
   	/* Convert Linux syscall to XFS internal ATTR flags */
   	if (flags & XATTR_CREATE)
-		xflags |= ATTR_CREATE;
+		xname.type |= ATTR_CREATE;
   	if (flags & XATTR_REPLACE)
-		xflags |= ATTR_REPLACE;
+		xname.type |= ATTR_REPLACE;
   	if (!value)
-		return xfs_attr_remove(ip, name,
-				       namelen, xflags);
-	error = xfs_attr_set(ip, name, namelen, (void *)value, size, xflags);
+		return xfs_attr_remove(ip, &xname);
+	error = xfs_attr_set(ip, &xname, (void *)value, size);
   	if (!error)
-		xfs_forget_acl(inode, name, xflags);
+		xfs_forget_acl(inode, name, xname.type);
   	return error;
   }
Signature · 1 line
2.7.4
#7 lore raw

PATCH v3 2/19 xfs: Embed struct xfs_name in xfs_da_args

In reply to Allison Collins

This patch embeds an xfs_name in xfs_da_args, replacing the name, namelen, and flags members. This helps to clean up the xfs_da_args structure and make it more uniform with the new xfs_name parameter being passed around.

---
 fs/xfs/libxfs/xfs_attr.c        |  34 ++++++-------
 fs/xfs/libxfs/xfs_attr_leaf.c   | 106 +++++++++++++++++++++-------------------
 fs/xfs/libxfs/xfs_attr_remote.c |   2 +-
 fs/xfs/libxfs/xfs_da_btree.c    |   5 +-
 fs/xfs/libxfs/xfs_da_btree.h    |   4 +-
 fs/xfs/libxfs/xfs_dir2.c        |  22 ++++-----
 fs/xfs/libxfs/xfs_dir2_block.c  |   6 +--
 fs/xfs/libxfs/xfs_dir2_leaf.c   |   6 +--
 fs/xfs/libxfs/xfs_dir2_node.c   |   8 +--
 fs/xfs/libxfs/xfs_dir2_sf.c     |  30 ++++++------
 fs/xfs/scrub/attr.c             |  12 ++---
 fs/xfs/xfs_trace.h              |  20 ++++----
 12 files changed, 130 insertions(+), 125 deletions(-)
fs/xfs/libxfs/xfs_attr.c +17 -17
index d0308d6..50e099f 100644
@@ -71,13 +71,13 @@ xfs_attr_args_init(
 	args->geo = dp->i_mount->m_attr_geo;
 	args->whichfork = XFS_ATTR_FORK;
 	args->dp = dp;
-	args->flags = name->type;
-	args->name = name->name;
-	args->namelen = name->len;
-	if (args->namelen >= MAXNAMELEN)
+	args->name.type = name->type;
+	args->name.name = name->name;
+	args->name.len = name->len;
+	if (args->name.len >= MAXNAMELEN)
 		return -EFAULT;		/* match IRIX behaviour */
 
-	args->hashval = xfs_da_hashname(args->name, args->namelen);
+	args->hashval = xfs_da_hashname(args->name.name, args->name.len);
 	return 0;
 }
 
@@ -234,7 +234,7 @@ xfs_attr_try_sf_addname(
 	 * Commit the shortform mods, and we're done.
 	 * NOTE: this is also the error path (EEXIST, etc).
 	 */
-	if (!error && (args->flags & ATTR_KERNOTIME) == 0)
+	if (!error && (args->name.type & ATTR_KERNOTIME) == 0)
 		xfs_trans_ichgtime(args->trans, dp, XFS_ICHGTIME_CHG);
 
 	if (mp->m_flags & XFS_MOUNT_WSYNC)
@@ -369,7 +369,7 @@ xfs_attr_set(
 	 */
 	if (XFS_IFORK_Q(dp) == 0) {
 		int sf_size = sizeof(xfs_attr_sf_hdr_t) +
-			XFS_ATTR_SF_ENTSIZE_BYNAME(args.namelen, valuelen);
+			XFS_ATTR_SF_ENTSIZE_BYNAME(args.name.len, valuelen);
 
 		error = xfs_bmap_add_attrfork(dp, sf_size, rsvd);
 		if (error)
@@ -528,10 +528,10 @@ xfs_attr_shortform_addname(xfs_da_args_t *args)
 	trace_xfs_attr_sf_addname(args);
 
 	retval = xfs_attr_shortform_lookup(args);
-	if ((args->flags & ATTR_REPLACE) && (retval == -ENOATTR)) {
+	if ((args->name.type & ATTR_REPLACE) && (retval == -ENOATTR)) {
 		return retval;
 	} else if (retval == -EEXIST) {
-		if (args->flags & ATTR_CREATE)
+		if (args->name.type & ATTR_CREATE)
 			return retval;
 		retval = xfs_attr_shortform_remove(args);
 		if (retval)
@@ -541,15 +541,15 @@ xfs_attr_shortform_addname(xfs_da_args_t *args)
 		 * that the leaf format add routine won't trip over the attr
 		 * not being around.
 		 */
-		args->flags &= ~ATTR_REPLACE;
+		args->name.type &= ~ATTR_REPLACE;
 	}
 
-	if (args->namelen >= XFS_ATTR_SF_ENTSIZE_MAX ||
+	if (args->name.len >= XFS_ATTR_SF_ENTSIZE_MAX ||
 	    args->valuelen >= XFS_ATTR_SF_ENTSIZE_MAX)
 		return -ENOSPC;
 
 	newsize = XFS_ATTR_SF_TOTSIZE(args->dp);
-	newsize += XFS_ATTR_SF_ENTSIZE_BYNAME(args->namelen, args->valuelen);
+	newsize += XFS_ATTR_SF_ENTSIZE_BYNAME(args->name.len, args->valuelen);
 
 	forkoff = xfs_attr_shortform_bytesfit(args->dp, newsize);
 	if (!forkoff)
@@ -594,11 +594,11 @@ xfs_attr_leaf_addname(
 	 * the given flags produce an error or call for an atomic rename.
 	 */
 	retval = xfs_attr3_leaf_lookup_int(bp, args);
-	if ((args->flags & ATTR_REPLACE) && (retval == -ENOATTR)) {
+	if ((args->name.type & ATTR_REPLACE) && (retval == -ENOATTR)) {
 		xfs_trans_brelse(args->trans, bp);
 		return retval;
 	} else if (retval == -EEXIST) {
-		if (args->flags & ATTR_CREATE) {	/* pure create op */
+		if (args->name.type & ATTR_CREATE) {	/* pure create op */
 			xfs_trans_brelse(args->trans, bp);
 			return retval;
 		}
@@ -868,10 +868,10 @@ xfs_attr_node_addname(
 		goto out;
 	blk = &state->path.blk[ state->path.active-1 ];
 	ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
-	if ((args->flags & ATTR_REPLACE) && (retval == -ENOATTR)) {
+	if ((args->name.type & ATTR_REPLACE) && (retval == -ENOATTR)) {
 		goto out;
 	} else if (retval == -EEXIST) {
-		if (args->flags & ATTR_CREATE)
+		if (args->name.type & ATTR_CREATE)
 			goto out;
 
 		trace_xfs_attr_node_replace(args);
@@ -1003,7 +1003,7 @@ xfs_attr_node_addname(
 		 * The INCOMPLETE flag means that we will find the "old"
 		 * attr, not the "new" one.
 		 */
-		args->flags |= XFS_ATTR_INCOMPLETE;
+		args->name.type |= XFS_ATTR_INCOMPLETE;
 		state = xfs_da_state_alloc();
 		state->args = args;
 		state->mp = mp;
fs/xfs/libxfs/xfs_attr_leaf.c +55 -51

238 lines not on this page · raw message

fs/xfs/libxfs/xfs_attr_remote.c +1 -1
index 3e39b7d..db9247a 100644
@@ -379,7 +379,7 @@ xfs_attr_rmtval_get(
 
 	trace_xfs_attr_rmtval_get(args);
 
-	ASSERT(!(args->flags & ATTR_KERNOVAL));
+	ASSERT(!(args->name.type & ATTR_KERNOVAL));
 	ASSERT(args->rmtvaluelen == args->valuelen);
 
 	valuelen = args->rmtvaluelen;
fs/xfs/libxfs/xfs_da_btree.c +3 -2
index 4fd1223..129ec09 100644
@@ -2040,8 +2040,9 @@ xfs_da_compname(
 	const unsigned char *name,
 	int		len)
 {
-	return (args->namelen == len && memcmp(args->name, name, len) == 0) ?
-					XFS_CMP_EXACT : XFS_CMP_DIFFERENT;
+	return (args->name.len == len &&
+		memcmp(args->name.name, name, len) == 0) ? XFS_CMP_EXACT :
+		XFS_CMP_DIFFERENT;
 }
 
 static xfs_dahash_t
fs/xfs/libxfs/xfs_da_btree.h +1 -3
index ae0bbd2..bed4f40 100644
@@ -47,12 +47,10 @@ enum xfs_dacmp {
  */
 typedef struct xfs_da_args {
 	struct xfs_da_geometry *geo;	/* da block geometry */
-	const uint8_t		*name;		/* string (maybe not NULL terminated) */
-	int		namelen;	/* length of string (maybe no NULL) */
+	struct xfs_name	name;		/* name, length and argument  flags*/
 	uint8_t		filetype;	/* filetype of inode for directories */
 	uint8_t		*value;		/* set of bytes (maybe contain NULLs) */
 	int		valuelen;	/* length of value */
-	int		flags;		/* argument flags (eg: ATTR_NOCREATE) */
 	xfs_dahash_t	hashval;	/* hash value of name */
 	xfs_ino_t	inumber;	/* input/output inode number */
 	struct xfs_inode *dp;		/* directory inode to manipulate */
fs/xfs/libxfs/xfs_dir2.c +11 -11
index 867c5de..e8d6721 100644
@@ -74,14 +74,14 @@ xfs_ascii_ci_compname(
 	enum xfs_dacmp	result;
 	int		i;
 
-	if (args->namelen != len)
+	if (args->name.len != len)
 		return XFS_CMP_DIFFERENT;
 
 	result = XFS_CMP_EXACT;
 	for (i = 0; i < len; i++) {
-		if (args->name[i] == name[i])
+		if (args->name.name[i] == name[i])
 			continue;
-		if (tolower(args->name[i]) != tolower(name[i]))
+		if (tolower(args->name.name[i]) != tolower(name[i]))
 			return XFS_CMP_DIFFERENT;
 		result = XFS_CMP_CASE;
 	}
@@ -259,8 +259,8 @@ xfs_dir_createname(
 		return -ENOMEM;
 
 	args->geo = dp->i_mount->m_dir_geo;
-	args->name = name->name;
-	args->namelen = name->len;
+	args->name.name = name->name;
+	args->name.len = name->len;
 	args->filetype = name->type;
 	args->hashval = dp->i_mount->m_dirnameops->hashname(name);
 	args->inumber = inum;
@@ -355,8 +355,8 @@ xfs_dir_lookup(
 	 */
 	args = kmem_zalloc(sizeof(*args), KM_NOFS);
 	args->geo = dp->i_mount->m_dir_geo;
-	args->name = name->name;
-	args->namelen = name->len;
+	args->name.name = name->name;
+	args->name.len = name->len;
 	args->filetype = name->type;
 	args->hashval = dp->i_mount->m_dirnameops->hashname(name);
 	args->dp = dp;
@@ -427,8 +427,8 @@ xfs_dir_removename(
 		return -ENOMEM;
 
 	args->geo = dp->i_mount->m_dir_geo;
-	args->name = name->name;
-	args->namelen = name->len;
+	args->name.name = name->name;
+	args->name.len = name->len;
 	args->filetype = name->type;
 	args->hashval = dp->i_mount->m_dirnameops->hashname(name);
 	args->inumber = ino;
@@ -488,8 +488,8 @@ xfs_dir_replace(
 		return -ENOMEM;
 
 	args->geo = dp->i_mount->m_dir_geo;
-	args->name = name->name;
-	args->namelen = name->len;
+	args->name.name = name->name;
+	args->name.len = name->len;
 	args->filetype = name->type;
 	args->hashval = dp->i_mount->m_dirnameops->hashname(name);
 	args->inumber = inum;
fs/xfs/libxfs/xfs_dir2_block.c +3 -3
index 9595ced..94269b9 100644
@@ -355,7 +355,7 @@ xfs_dir2_block_addname(
 	if (error)
 		return error;
 
-	len = dp->d_ops->data_entsize(args->namelen);
+	len = dp->d_ops->data_entsize(args->name.len);
 
 	/*
 	 * Set up pointers to parts of the block.
@@ -539,8 +539,8 @@ xfs_dir2_block_addname(
 	 * Create the new data entry.
 	 */
 	dep->inumber = cpu_to_be64(args->inumber);
-	dep->namelen = args->namelen;
-	memcpy(dep->name, args->name, args->namelen);
+	dep->namelen = args->name.len;
+	memcpy(dep->name, args->name.name, args->name.len);
 	dp->d_ops->data_put_ftype(dep, args->filetype);
 	tagp = dp->d_ops->data_entry_tag_p(dep);
 	*tagp = cpu_to_be16((char *)dep - (char *)hdr);
fs/xfs/libxfs/xfs_dir2_leaf.c +3 -3
index a53e458..b7046e2 100644
@@ -610,7 +610,7 @@ xfs_dir2_leaf_addname(
 	ents = dp->d_ops->leaf_ents_p(leaf);
 	dp->d_ops->leaf_hdr_from_disk(&leafhdr, leaf);
 	bestsp = xfs_dir2_leaf_bests_p(ltp);
-	length = dp->d_ops->data_entsize(args->namelen);
+	length = dp->d_ops->data_entsize(args->name.len);
 
 	/*
 	 * See if there are any entries with the same hash value
@@ -813,8 +813,8 @@ xfs_dir2_leaf_addname(
 	 */
 	dep = (xfs_dir2_data_entry_t *)dup;
 	dep->inumber = cpu_to_be64(args->inumber);
-	dep->namelen = args->namelen;
-	memcpy(dep->name, args->name, dep->namelen);
+	dep->namelen = args->name.len;
+	memcpy(dep->name, args->name.name, dep->namelen);
 	dp->d_ops->data_put_ftype(dep, args->filetype);
 	tagp = dp->d_ops->data_entry_tag_p(dep);
 	*tagp = cpu_to_be16((char *)dep - (char *)hdr);
fs/xfs/libxfs/xfs_dir2_node.c +4 -4
index 705c4f5..8bbd742 100644
@@ -604,7 +604,7 @@ xfs_dir2_leafn_lookup_for_addname(
 		ASSERT(free->hdr.magic == cpu_to_be32(XFS_DIR2_FREE_MAGIC) ||
 		       free->hdr.magic == cpu_to_be32(XFS_DIR3_FREE_MAGIC));
 	}
-	length = dp->d_ops->data_entsize(args->namelen);
+	length = dp->d_ops->data_entsize(args->name.len);
 	/*
 	 * Loop over leaf entries with the right hash value.
 	 */
@@ -1869,7 +1869,7 @@ xfs_dir2_node_addname_int(
 	__be16			*tagp;		/* data entry tag pointer */
 	__be16			*bests;
 
-	length = dp->d_ops->data_entsize(args->namelen);
+	length = dp->d_ops->data_entsize(args->name.len);
 	error = xfs_dir2_node_find_freeblk(args, fblk, &dbno, &fbp, &findex,
 					   length);
 	if (error)
@@ -1924,8 +1924,8 @@ xfs_dir2_node_addname_int(
 	/* Fill in the new entry and log it. */
 	dep = (xfs_dir2_data_entry_t *)dup;
 	dep->inumber = cpu_to_be64(args->inumber);
-	dep->namelen = args->namelen;
-	memcpy(dep->name, args->name, dep->namelen);
+	dep->namelen = args->name.len;
+	memcpy(dep->name, args->name.name, dep->namelen);
 	dp->d_ops->data_put_ftype(dep, args->filetype);
 	tagp = dp->d_ops->data_entry_tag_p(dep);
 	*tagp = cpu_to_be16((char *)dep - (char *)hdr);
fs/xfs/libxfs/xfs_dir2_sf.c +15 -15
index 85f14fc..fdc1431 100644
@@ -291,7 +291,7 @@ xfs_dir2_sf_addname(
 	/*
 	 * Compute entry (and change in) size.
 	 */
-	incr_isize = dp->d_ops->sf_entsize(sfp, args->namelen);
+	incr_isize = dp->d_ops->sf_entsize(sfp, args->name.len);
 	objchange = 0;
 
 	/*
@@ -375,7 +375,7 @@ xfs_dir2_sf_addname_easy(
 	/*
 	 * Grow the in-inode space.
 	 */
-	xfs_idata_realloc(dp, dp->d_ops->sf_entsize(sfp, args->namelen),
+	xfs_idata_realloc(dp, dp->d_ops->sf_entsize(sfp, args->name.len),
 			  XFS_DATA_FORK);
 	/*
 	 * Need to set up again due to realloc of the inode data.
@@ -385,9 +385,9 @@ xfs_dir2_sf_addname_easy(
 	/*
 	 * Fill in the new entry.
 	 */
-	sfep->namelen = args->namelen;
+	sfep->namelen = args->name.len;
 	xfs_dir2_sf_put_offset(sfep, offset);
-	memcpy(sfep->name, args->name, sfep->namelen);
+	memcpy(sfep->name, args->name.name, sfep->namelen);
 	dp->d_ops->sf_put_ino(sfp, sfep, args->inumber);
 	dp->d_ops->sf_put_ftype(sfep, args->filetype);
 
@@ -446,7 +446,7 @@ xfs_dir2_sf_addname_hard(
 	 */
 	for (offset = dp->d_ops->data_first_offset,
 	      oldsfep = xfs_dir2_sf_firstentry(oldsfp),
-	      add_datasize = dp->d_ops->data_entsize(args->namelen),
+	      add_datasize = dp->d_ops->data_entsize(args->name.len),
 	      eof = (char *)oldsfep == &buf[old_isize];
 	     !eof;
 	     offset = new_offset + dp->d_ops->data_entsize(oldsfep->namelen),
@@ -476,9 +476,9 @@ xfs_dir2_sf_addname_hard(
 	/*
 	 * Fill in the new entry, and update the header counts.
 	 */
-	sfep->namelen = args->namelen;
+	sfep->namelen = args->name.len;
 	xfs_dir2_sf_put_offset(sfep, offset);
-	memcpy(sfep->name, args->name, sfep->namelen);
+	memcpy(sfep->name, args->name.name, sfep->namelen);
 	dp->d_ops->sf_put_ino(sfp, sfep, args->inumber);
 	dp->d_ops->sf_put_ftype(sfep, args->filetype);
 	sfp->count++;
@@ -522,7 +522,7 @@ xfs_dir2_sf_addname_pick(
 	dp = args->dp;
 
 	sfp = (xfs_dir2_sf_hdr_t *)dp->i_df.if_u1.if_data;
-	size = dp->d_ops->data_entsize(args->namelen);
+	size = dp->d_ops->data_entsize(args->name.len);
 	offset = dp->d_ops->data_first_offset;
 	sfep = xfs_dir2_sf_firstentry(sfp);
 	holefit = 0;
@@ -807,7 +807,7 @@ xfs_dir2_sf_lookup(
 	/*
 	 * Special case for .
 	 */
-	if (args->namelen == 1 && args->name[0] == '.') {
+	if (args->name.len == 1 && args->name.name[0] == '.') {
 		args->inumber = dp->i_ino;
 		args->cmpresult = XFS_CMP_EXACT;
 		args->filetype = XFS_DIR3_FT_DIR;
@@ -816,8 +816,8 @@ xfs_dir2_sf_lookup(
 	/*
 	 * Special case for ..
 	 */
-	if (args->namelen == 2 &&
-	    args->name[0] == '.' && args->name[1] == '.') {
+	if (args->name.len == 2 &&
+	    args->name.name[0] == '.' && args->name.name[1] == '.') {
 		args->inumber = dp->d_ops->sf_get_parent_ino(sfp);
 		args->cmpresult = XFS_CMP_EXACT;
 		args->filetype = XFS_DIR3_FT_DIR;
@@ -912,7 +912,7 @@ xfs_dir2_sf_removename(
 	 * Calculate sizes.
 	 */
 	byteoff = (int)((char *)sfep - (char *)sfp);
-	entsize = dp->d_ops->sf_entsize(sfp, args->namelen);
+	entsize = dp->d_ops->sf_entsize(sfp, args->name.len);
 	newsize = oldsize - entsize;
 	/*
 	 * Copy the part if any after the removed entry, sliding it down.
@@ -1002,12 +1002,12 @@ xfs_dir2_sf_replace(
 	} else
 		i8elevated = 0;
 
-	ASSERT(args->namelen != 1 || args->name[0] != '.');
+	ASSERT(args->name.len != 1 || args->name.name[0] != '.');
 	/*
 	 * Replace ..'s entry.
 	 */
-	if (args->namelen == 2 &&
-	    args->name[0] == '.' && args->name[1] == '.') {
+	if (args->name.len == 2 &&
+	    args->name.name[0] == '.' && args->name.name[1] == '.') {
 		ino = dp->d_ops->sf_get_parent_ino(sfp);
 		ASSERT(args->inumber != ino);
 		dp->d_ops->sf_put_parent_ino(sfp, args->inumber);
fs/xfs/scrub/attr.c +6 -6
index 0edc7f8..42f7c07 100644
@@ -147,17 +147,17 @@ xchk_xattr_listent(
 		return;
 	}
 
-	args.flags = ATTR_KERNOTIME;
+	args.name.type = ATTR_KERNOTIME;
 	if (flags & XFS_ATTR_ROOT)
-		args.flags |= ATTR_ROOT;
+		args.name.type |= ATTR_ROOT;
 	else if (flags & XFS_ATTR_SECURE)
-		args.flags |= ATTR_SECURE;
+		args.name.type |= ATTR_SECURE;
 	args.geo = context->dp->i_mount->m_attr_geo;
 	args.whichfork = XFS_ATTR_FORK;
 	args.dp = context->dp;
-	args.name = name;
-	args.namelen = namelen;
-	args.hashval = xfs_da_hashname(args.name, args.namelen);
+	args.name.name = name;
+	args.name.len = namelen;
+	args.hashval = xfs_da_hashname(args.name.name, args.name.len);
 	args.trans = context->tp;
 	args.value = xchk_xattr_valuebuf(sx->sc);
 	args.valuelen = valuelen;
fs/xfs/xfs_trace.h +11 -9
index eaae275..e0f524d 100644
@@ -1669,7 +1669,7 @@ DECLARE_EVENT_CLASS(xfs_da_class,
 	TP_STRUCT__entry(
 		__field(dev_t, dev)
 		__field(xfs_ino_t, ino)
-		__dynamic_array(char, name, args->namelen)
+		__dynamic_array(char, name, args->name.len)
 		__field(int, namelen)
 		__field(xfs_dahash_t, hashval)
 		__field(xfs_ino_t, inumber)
@@ -1678,9 +1678,10 @@ DECLARE_EVENT_CLASS(xfs_da_class,
 	TP_fast_assign(
 		__entry->dev = VFS_I(args->dp)->i_sb->s_dev;
 		__entry->ino = args->dp->i_ino;
-		if (args->namelen)
-			memcpy(__get_str(name), args->name, args->namelen);
-		__entry->namelen = args->namelen;
+		if (args->name.len)
+			memcpy(__get_str(name), args->name.name,
+			       args->name.len);
+		__entry->namelen = args->name.len;
 		__entry->hashval = args->hashval;
 		__entry->inumber = args->inumber;
 		__entry->op_flags = args->op_flags;
@@ -1733,7 +1734,7 @@ DECLARE_EVENT_CLASS(xfs_attr_class,
 	TP_STRUCT__entry(
 		__field(dev_t, dev)
 		__field(xfs_ino_t, ino)
-		__dynamic_array(char, name, args->namelen)
+		__dynamic_array(char, name, args->name.len)
 		__field(int, namelen)
 		__field(int, valuelen)
 		__field(xfs_dahash_t, hashval)
@@ -1743,12 +1744,13 @@ DECLARE_EVENT_CLASS(xfs_attr_class,
 	TP_fast_assign(
 		__entry->dev = VFS_I(args->dp)->i_sb->s_dev;
 		__entry->ino = args->dp->i_ino;
-		if (args->namelen)
-			memcpy(__get_str(name), args->name, args->namelen);
-		__entry->namelen = args->namelen;
+		if (args->name.len)
+			memcpy(__get_str(name), args->name.name,
+			       args->name.len);
+		__entry->namelen = args->name.len;
 		__entry->valuelen = args->valuelen;
 		__entry->hashval = args->hashval;
-		__entry->flags = args->flags;
+		__entry->flags = args->name.type;
 		__entry->op_flags = args->op_flags;
 	),
 	TP_printk("dev %d:%d ino 0x%llx name %.*s namelen %d valuelen %d "
Signature · 1 line
2.7.4
Reviewed-by on v3 2/19
#8 lore raw

Re: [PATCH v3 02/19] xfs: Embed struct xfs_name in xfs_da_args

Quoted 26 lines · Allison Collins

This patch embeds an xfs_name in xfs_da_args, replacing the name, namelen, and flags members. This helps to clean up the xfs_da_args structure and make it more uniform with the new xfs_name parameter being passed around.

---
 fs/xfs/libxfs/xfs_attr.c        |  34 ++++++-------
 fs/xfs/libxfs/xfs_attr_leaf.c   | 106 +++++++++++++++++++++-------------------
 fs/xfs/libxfs/xfs_attr_remote.c |   2 +-
 fs/xfs/libxfs/xfs_da_btree.c    |   5 +-
 fs/xfs/libxfs/xfs_da_btree.h    |   4 +-
 fs/xfs/libxfs/xfs_dir2.c        |  22 ++++-----
 fs/xfs/libxfs/xfs_dir2_block.c  |   6 +--
 fs/xfs/libxfs/xfs_dir2_leaf.c   |   6 +--
 fs/xfs/libxfs/xfs_dir2_node.c   |   8 +--
 fs/xfs/libxfs/xfs_dir2_sf.c     |  30 ++++++------
 fs/xfs/scrub/attr.c             |  12 ++---
 fs/xfs/xfs_trace.h              |  20 ++++----
 12 files changed, 130 insertions(+), 125 deletions(-)
fs/xfs/libxfs/xfs_attr.c +0 -0
index d0308d6..50e099f 100644

fs/xfs/libxfs/xfs_attr.c xfs_attr_args_init( · line 76

Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +3 -4
@@ -71,13 +71,13 @@ xfs_attr_args_init(
 	args->geo = dp->i_mount->m_attr_geo;
 	args->whichfork = XFS_ATTR_FORK;
 	args->dp = dp;
-	args->flags = name->type;
-	args->name = name->name;
-	args->namelen = name->len;
-	if (args->namelen >= MAXNAMELEN)
+	args->name.type = name->type;
+	args->name.name = name->name;
+	args->name.len = name->len;

Looks like this could be a struct copy:

	args->name = *name;
Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c +2 -1
+	if (args->name.len >= MAXNAMELEN)
 		return -EFAULT;		/* match IRIX behaviour */
 
-	args->hashval = xfs_da_hashname(args->name, args->namelen);
+	args->hashval = xfs_da_hashname(args->name.name, args->name.len);
 	return 0;
 }
 

...

Quoted 4 lines
fs/xfs/libxfs/xfs_dir2.c +0 -0
index 867c5de..e8d6721 100644

...

Quoted 34 lines
fs/xfs/libxfs/xfs_dir2.c +6 -6
@@ -259,8 +259,8 @@ xfs_dir_createname(
 		return -ENOMEM;
 
 	args->geo = dp->i_mount->m_dir_geo;
-	args->name = name->name;
-	args->namelen = name->len;
+	args->name.name = name->name;
+	args->name.len = name->len;
 	args->filetype = name->type;
 	args->hashval = dp->i_mount->m_dirnameops->hashname(name);
 	args->inumber = inum;
@@ -355,8 +355,8 @@ xfs_dir_lookup(
 	 */
 	args = kmem_zalloc(sizeof(*args), KM_NOFS);
 	args->geo = dp->i_mount->m_dir_geo;
-	args->name = name->name;
-	args->namelen = name->len;
+	args->name.name = name->name;
+	args->name.len = name->len;
 	args->filetype = name->type;
 	args->hashval = dp->i_mount->m_dirnameops->hashname(name);
 	args->dp = dp;
@@ -427,8 +427,8 @@ xfs_dir_removename(
 		return -ENOMEM;
 
 	args->geo = dp->i_mount->m_dir_geo;
-	args->name = name->name;
-	args->namelen = name->len;
+	args->name.name = name->name;
+	args->name.len = name->len;
 	args->filetype = name->type;
 	args->hashval = dp->i_mount->m_dirnameops->hashname(name);
 	args->inumber = ino;

fs/xfs/libxfs/xfs_dir2.c xfs_dir_replace( · line 495

Quoted 10 lines
fs/xfs/libxfs/xfs_dir2.c +2 -2
@@ -488,8 +488,8 @@ xfs_dir_replace(
 		return -ENOMEM;
 
 	args->geo = dp->i_mount->m_dir_geo;
-	args->name = name->name;
-	args->namelen = name->len;
+	args->name.name = name->name;
+	args->name.len = name->len;
 	args->filetype = name->type;
 	args->hashval = dp->i_mount->m_dirnameops->hashname(name);
 	args->inumber = inum;

More struct copy candidates above. Modulo that and the comments on the previous patch, the rest LGTM:

Quoted 275 lines
fs/xfs/libxfs/xfs_dir2_block.c +3 -3
index 9595ced..94269b9 100644
@@ -355,7 +355,7 @@ xfs_dir2_block_addname(
 	if (error)
 		return error;
 
-	len = dp->d_ops->data_entsize(args->namelen);
+	len = dp->d_ops->data_entsize(args->name.len);
 
 	/*
 	 * Set up pointers to parts of the block.
@@ -539,8 +539,8 @@ xfs_dir2_block_addname(
 	 * Create the new data entry.
 	 */
 	dep->inumber = cpu_to_be64(args->inumber);
-	dep->namelen = args->namelen;
-	memcpy(dep->name, args->name, args->namelen);
+	dep->namelen = args->name.len;
+	memcpy(dep->name, args->name.name, args->name.len);
 	dp->d_ops->data_put_ftype(dep, args->filetype);
 	tagp = dp->d_ops->data_entry_tag_p(dep);
 	*tagp = cpu_to_be16((char *)dep - (char *)hdr);
fs/xfs/libxfs/xfs_dir2_leaf.c +3 -3
index a53e458..b7046e2 100644
@@ -610,7 +610,7 @@ xfs_dir2_leaf_addname(
 	ents = dp->d_ops->leaf_ents_p(leaf);
 	dp->d_ops->leaf_hdr_from_disk(&leafhdr, leaf);
 	bestsp = xfs_dir2_leaf_bests_p(ltp);
-	length = dp->d_ops->data_entsize(args->namelen);
+	length = dp->d_ops->data_entsize(args->name.len);
 
 	/*
 	 * See if there are any entries with the same hash value
@@ -813,8 +813,8 @@ xfs_dir2_leaf_addname(
 	 */
 	dep = (xfs_dir2_data_entry_t *)dup;
 	dep->inumber = cpu_to_be64(args->inumber);
-	dep->namelen = args->namelen;
-	memcpy(dep->name, args->name, dep->namelen);
+	dep->namelen = args->name.len;
+	memcpy(dep->name, args->name.name, dep->namelen);
 	dp->d_ops->data_put_ftype(dep, args->filetype);
 	tagp = dp->d_ops->data_entry_tag_p(dep);
 	*tagp = cpu_to_be16((char *)dep - (char *)hdr);
fs/xfs/libxfs/xfs_dir2_node.c +4 -4
index 705c4f5..8bbd742 100644
@@ -604,7 +604,7 @@ xfs_dir2_leafn_lookup_for_addname(
 		ASSERT(free->hdr.magic == cpu_to_be32(XFS_DIR2_FREE_MAGIC) ||
 		       free->hdr.magic == cpu_to_be32(XFS_DIR3_FREE_MAGIC));
 	}
-	length = dp->d_ops->data_entsize(args->namelen);
+	length = dp->d_ops->data_entsize(args->name.len);
 	/*
 	 * Loop over leaf entries with the right hash value.
 	 */
@@ -1869,7 +1869,7 @@ xfs_dir2_node_addname_int(
 	__be16			*tagp;		/* data entry tag pointer */
 	__be16			*bests;
 
-	length = dp->d_ops->data_entsize(args->namelen);
+	length = dp->d_ops->data_entsize(args->name.len);
 	error = xfs_dir2_node_find_freeblk(args, fblk, &dbno, &fbp, &findex,
 					   length);
 	if (error)
@@ -1924,8 +1924,8 @@ xfs_dir2_node_addname_int(
 	/* Fill in the new entry and log it. */
 	dep = (xfs_dir2_data_entry_t *)dup;
 	dep->inumber = cpu_to_be64(args->inumber);
-	dep->namelen = args->namelen;
-	memcpy(dep->name, args->name, dep->namelen);
+	dep->namelen = args->name.len;
+	memcpy(dep->name, args->name.name, dep->namelen);
 	dp->d_ops->data_put_ftype(dep, args->filetype);
 	tagp = dp->d_ops->data_entry_tag_p(dep);
 	*tagp = cpu_to_be16((char *)dep - (char *)hdr);
fs/xfs/libxfs/xfs_dir2_sf.c +15 -15
index 85f14fc..fdc1431 100644
@@ -291,7 +291,7 @@ xfs_dir2_sf_addname(
 	/*
 	 * Compute entry (and change in) size.
 	 */
-	incr_isize = dp->d_ops->sf_entsize(sfp, args->namelen);
+	incr_isize = dp->d_ops->sf_entsize(sfp, args->name.len);
 	objchange = 0;
 
 	/*
@@ -375,7 +375,7 @@ xfs_dir2_sf_addname_easy(
 	/*
 	 * Grow the in-inode space.
 	 */
-	xfs_idata_realloc(dp, dp->d_ops->sf_entsize(sfp, args->namelen),
+	xfs_idata_realloc(dp, dp->d_ops->sf_entsize(sfp, args->name.len),
 			  XFS_DATA_FORK);
 	/*
 	 * Need to set up again due to realloc of the inode data.
@@ -385,9 +385,9 @@ xfs_dir2_sf_addname_easy(
 	/*
 	 * Fill in the new entry.
 	 */
-	sfep->namelen = args->namelen;
+	sfep->namelen = args->name.len;
 	xfs_dir2_sf_put_offset(sfep, offset);
-	memcpy(sfep->name, args->name, sfep->namelen);
+	memcpy(sfep->name, args->name.name, sfep->namelen);
 	dp->d_ops->sf_put_ino(sfp, sfep, args->inumber);
 	dp->d_ops->sf_put_ftype(sfep, args->filetype);
 
@@ -446,7 +446,7 @@ xfs_dir2_sf_addname_hard(
 	 */
 	for (offset = dp->d_ops->data_first_offset,
 	      oldsfep = xfs_dir2_sf_firstentry(oldsfp),
-	      add_datasize = dp->d_ops->data_entsize(args->namelen),
+	      add_datasize = dp->d_ops->data_entsize(args->name.len),
 	      eof = (char *)oldsfep == &buf[old_isize];
 	     !eof;
 	     offset = new_offset + dp->d_ops->data_entsize(oldsfep->namelen),
@@ -476,9 +476,9 @@ xfs_dir2_sf_addname_hard(
 	/*
 	 * Fill in the new entry, and update the header counts.
 	 */
-	sfep->namelen = args->namelen;
+	sfep->namelen = args->name.len;
 	xfs_dir2_sf_put_offset(sfep, offset);
-	memcpy(sfep->name, args->name, sfep->namelen);
+	memcpy(sfep->name, args->name.name, sfep->namelen);
 	dp->d_ops->sf_put_ino(sfp, sfep, args->inumber);
 	dp->d_ops->sf_put_ftype(sfep, args->filetype);
 	sfp->count++;
@@ -522,7 +522,7 @@ xfs_dir2_sf_addname_pick(
 	dp = args->dp;
 
 	sfp = (xfs_dir2_sf_hdr_t *)dp->i_df.if_u1.if_data;
-	size = dp->d_ops->data_entsize(args->namelen);
+	size = dp->d_ops->data_entsize(args->name.len);
 	offset = dp->d_ops->data_first_offset;
 	sfep = xfs_dir2_sf_firstentry(sfp);
 	holefit = 0;
@@ -807,7 +807,7 @@ xfs_dir2_sf_lookup(
 	/*
 	 * Special case for .
 	 */
-	if (args->namelen == 1 && args->name[0] == '.') {
+	if (args->name.len == 1 && args->name.name[0] == '.') {
 		args->inumber = dp->i_ino;
 		args->cmpresult = XFS_CMP_EXACT;
 		args->filetype = XFS_DIR3_FT_DIR;
@@ -816,8 +816,8 @@ xfs_dir2_sf_lookup(
 	/*
 	 * Special case for ..
 	 */
-	if (args->namelen == 2 &&
-	    args->name[0] == '.' && args->name[1] == '.') {
+	if (args->name.len == 2 &&
+	    args->name.name[0] == '.' && args->name.name[1] == '.') {
 		args->inumber = dp->d_ops->sf_get_parent_ino(sfp);
 		args->cmpresult = XFS_CMP_EXACT;
 		args->filetype = XFS_DIR3_FT_DIR;
@@ -912,7 +912,7 @@ xfs_dir2_sf_removename(
 	 * Calculate sizes.
 	 */
 	byteoff = (int)((char *)sfep - (char *)sfp);
-	entsize = dp->d_ops->sf_entsize(sfp, args->namelen);
+	entsize = dp->d_ops->sf_entsize(sfp, args->name.len);
 	newsize = oldsize - entsize;
 	/*
 	 * Copy the part if any after the removed entry, sliding it down.
@@ -1002,12 +1002,12 @@ xfs_dir2_sf_replace(
 	} else
 		i8elevated = 0;
 
-	ASSERT(args->namelen != 1 || args->name[0] != '.');
+	ASSERT(args->name.len != 1 || args->name.name[0] != '.');
 	/*
 	 * Replace ..'s entry.
 	 */
-	if (args->namelen == 2 &&
-	    args->name[0] == '.' && args->name[1] == '.') {
+	if (args->name.len == 2 &&
+	    args->name.name[0] == '.' && args->name.name[1] == '.') {
 		ino = dp->d_ops->sf_get_parent_ino(sfp);
 		ASSERT(args->inumber != ino);
 		dp->d_ops->sf_put_parent_ino(sfp, args->inumber);
fs/xfs/scrub/attr.c +6 -6
index 0edc7f8..42f7c07 100644
@@ -147,17 +147,17 @@ xchk_xattr_listent(
 		return;
 	}
 
-	args.flags = ATTR_KERNOTIME;
+	args.name.type = ATTR_KERNOTIME;
 	if (flags & XFS_ATTR_ROOT)
-		args.flags |= ATTR_ROOT;
+		args.name.type |= ATTR_ROOT;
 	else if (flags & XFS_ATTR_SECURE)
-		args.flags |= ATTR_SECURE;
+		args.name.type |= ATTR_SECURE;
 	args.geo = context->dp->i_mount->m_attr_geo;
 	args.whichfork = XFS_ATTR_FORK;
 	args.dp = context->dp;
-	args.name = name;
-	args.namelen = namelen;
-	args.hashval = xfs_da_hashname(args.name, args.namelen);
+	args.name.name = name;
+	args.name.len = namelen;
+	args.hashval = xfs_da_hashname(args.name.name, args.name.len);
 	args.trans = context->tp;
 	args.value = xchk_xattr_valuebuf(sx->sc);
 	args.valuelen = valuelen;
fs/xfs/xfs_trace.h +11 -9
index eaae275..e0f524d 100644
@@ -1669,7 +1669,7 @@ DECLARE_EVENT_CLASS(xfs_da_class,
 	TP_STRUCT__entry(
 		__field(dev_t, dev)
 		__field(xfs_ino_t, ino)
-		__dynamic_array(char, name, args->namelen)
+		__dynamic_array(char, name, args->name.len)
 		__field(int, namelen)
 		__field(xfs_dahash_t, hashval)
 		__field(xfs_ino_t, inumber)
@@ -1678,9 +1678,10 @@ DECLARE_EVENT_CLASS(xfs_da_class,
 	TP_fast_assign(
 		__entry->dev = VFS_I(args->dp)->i_sb->s_dev;
 		__entry->ino = args->dp->i_ino;
-		if (args->namelen)
-			memcpy(__get_str(name), args->name, args->namelen);
-		__entry->namelen = args->namelen;
+		if (args->name.len)
+			memcpy(__get_str(name), args->name.name,
+			       args->name.len);
+		__entry->namelen = args->name.len;
 		__entry->hashval = args->hashval;
 		__entry->inumber = args->inumber;
 		__entry->op_flags = args->op_flags;
@@ -1733,7 +1734,7 @@ DECLARE_EVENT_CLASS(xfs_attr_class,
 	TP_STRUCT__entry(
 		__field(dev_t, dev)
 		__field(xfs_ino_t, ino)
-		__dynamic_array(char, name, args->namelen)
+		__dynamic_array(char, name, args->name.len)
 		__field(int, namelen)
 		__field(int, valuelen)
 		__field(xfs_dahash_t, hashval)
@@ -1743,12 +1744,13 @@ DECLARE_EVENT_CLASS(xfs_attr_class,
 	TP_fast_assign(
 		__entry->dev = VFS_I(args->dp)->i_sb->s_dev;
 		__entry->ino = args->dp->i_ino;
-		if (args->namelen)
-			memcpy(__get_str(name), args->name, args->namelen);
-		__entry->namelen = args->namelen;
+		if (args->name.len)
+			memcpy(__get_str(name), args->name.name,
+			       args->name.len);
+		__entry->namelen = args->name.len;
 		__entry->valuelen = args->valuelen;
 		__entry->hashval = args->hashval;
-		__entry->flags = args->flags;
+		__entry->flags = args->name.type;
 		__entry->op_flags = args->op_flags;
 	),
 	TP_printk("dev %d:%d ino 0x%llx name %.*s namelen %d valuelen %d "
Signature · 1 line
2.7.4
#9 lore raw

Re: [PATCH v3 02/19] xfs: Embed struct xfs_name in xfs_da_args

Quoted 5 lines · Brian Foster

fs/xfs/libxfs/xfs_attr.c xfs_attr_args_init( · line 76

Quoted 3 lines
fs/xfs/libxfs/xfs_attr.c +3 -0
+	args->name.type = name->type;
+	args->name.name = name->name;
+	args->name.len = name->len;

Looks like this could be a struct copy:

Would it make sense to include a pointer instead so that we don't have to copy the structure?

#10 lore raw

Re: [PATCH v3 02/19] xfs: Embed struct xfs_name in xfs_da_args

In reply to Brian Foster
Quoted 104 lines · Brian Foster
Quoted 26 lines · Allison Collins

This patch embeds an xfs_name in xfs_da_args, replacing the name, namelen, and flags members. This helps to clean up the xfs_da_args structure and make it more uniform with the new xfs_name parameter being passed around.

---
  fs/xfs/libxfs/xfs_attr.c        |  34 ++++++-------
  fs/xfs/libxfs/xfs_attr_leaf.c   | 106 +++++++++++++++++++++-------------------
  fs/xfs/libxfs/xfs_attr_remote.c |   2 +-
  fs/xfs/libxfs/xfs_da_btree.c    |   5 +-
  fs/xfs/libxfs/xfs_da_btree.h    |   4 +-
  fs/xfs/libxfs/xfs_dir2.c        |  22 ++++-----
  fs/xfs/libxfs/xfs_dir2_block.c  |   6 +--
  fs/xfs/libxfs/xfs_dir2_leaf.c   |   6 +--
  fs/xfs/libxfs/xfs_dir2_node.c   |   8 +--
  fs/xfs/libxfs/xfs_dir2_sf.c     |  30 ++++++------
  fs/xfs/scrub/attr.c             |  12 ++---
  fs/xfs/xfs_trace.h              |  20 ++++----
  12 files changed, 130 insertions(+), 125 deletions(-)
fs/xfs/libxfs/xfs_attr.c +0 -0
index d0308d6..50e099f 100644

fs/xfs/libxfs/xfs_attr.c xfs_attr_args_init( · line 76

Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +3 -4
@@ -71,13 +71,13 @@ xfs_attr_args_init(
  	args->geo = dp->i_mount->m_attr_geo;
  	args->whichfork = XFS_ATTR_FORK;
  	args->dp = dp;
-	args->flags = name->type;
-	args->name = name->name;
-	args->namelen = name->len;
-	if (args->namelen >= MAXNAMELEN)
+	args->name.type = name->type;
+	args->name.name = name->name;
+	args->name.len = name->len;

Looks like this could be a struct copy:

	args->name = *name;
Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c +2 -1
+	if (args->name.len >= MAXNAMELEN)
  		return -EFAULT;		/* match IRIX behaviour */
 
-	args->hashval = xfs_da_hashname(args->name, args->namelen);
+	args->hashval = xfs_da_hashname(args->name.name, args->name.len);
  	return 0;
  }
 

...

Quoted 4 lines
fs/xfs/libxfs/xfs_dir2.c +0 -0
index 867c5de..e8d6721 100644

...

Quoted 34 lines
fs/xfs/libxfs/xfs_dir2.c +6 -6
@@ -259,8 +259,8 @@ xfs_dir_createname(
  		return -ENOMEM;
 
  	args->geo = dp->i_mount->m_dir_geo;
-	args->name = name->name;
-	args->namelen = name->len;
+	args->name.name = name->name;
+	args->name.len = name->len;
  	args->filetype = name->type;
  	args->hashval = dp->i_mount->m_dirnameops->hashname(name);
  	args->inumber = inum;
@@ -355,8 +355,8 @@ xfs_dir_lookup(
  	 */
  	args = kmem_zalloc(sizeof(*args), KM_NOFS);
  	args->geo = dp->i_mount->m_dir_geo;
-	args->name = name->name;
-	args->namelen = name->len;
+	args->name.name = name->name;
+	args->name.len = name->len;
  	args->filetype = name->type;
  	args->hashval = dp->i_mount->m_dirnameops->hashname(name);
  	args->dp = dp;
@@ -427,8 +427,8 @@ xfs_dir_removename(
  		return -ENOMEM;
 
  	args->geo = dp->i_mount->m_dir_geo;
-	args->name = name->name;
-	args->namelen = name->len;
+	args->name.name = name->name;
+	args->name.len = name->len;
  	args->filetype = name->type;
  	args->hashval = dp->i_mount->m_dirnameops->hashname(name);
  	args->inumber = ino;

fs/xfs/libxfs/xfs_dir2.c xfs_dir_replace( · line 495

Quoted 10 lines
fs/xfs/libxfs/xfs_dir2.c +2 -2
@@ -488,8 +488,8 @@ xfs_dir_replace(
  		return -ENOMEM;
 
  	args->geo = dp->i_mount->m_dir_geo;
-	args->name = name->name;
-	args->namelen = name->len;
+	args->name.name = name->name;
+	args->name.len = name->len;
  	args->filetype = name->type;
  	args->hashval = dp->i_mount->m_dirnameops->hashname(name);
  	args->inumber = inum;

More struct copy candidates above. Modulo that and the comments on the previous patch, the rest LGTM:

Quoted 1 line

i

Alrighty, will do. Thanks for the review ;-)

Allison

Quoted 276 lines
Quoted 276 lines
fs/xfs/libxfs/xfs_dir2_block.c +3 -3
index 9595ced..94269b9 100644
@@ -355,7 +355,7 @@ xfs_dir2_block_addname(
  	if (error)
  		return error;
 
-	len = dp->d_ops->data_entsize(args->namelen);
+	len = dp->d_ops->data_entsize(args->name.len);
 
  	/*
  	 * Set up pointers to parts of the block.
@@ -539,8 +539,8 @@ xfs_dir2_block_addname(
  	 * Create the new data entry.
  	 */
  	dep->inumber = cpu_to_be64(args->inumber);
-	dep->namelen = args->namelen;
-	memcpy(dep->name, args->name, args->namelen);
+	dep->namelen = args->name.len;
+	memcpy(dep->name, args->name.name, args->name.len);
  	dp->d_ops->data_put_ftype(dep, args->filetype);
  	tagp = dp->d_ops->data_entry_tag_p(dep);
  	*tagp = cpu_to_be16((char *)dep - (char *)hdr);
fs/xfs/libxfs/xfs_dir2_leaf.c +3 -3
index a53e458..b7046e2 100644
@@ -610,7 +610,7 @@ xfs_dir2_leaf_addname(
  	ents = dp->d_ops->leaf_ents_p(leaf);
  	dp->d_ops->leaf_hdr_from_disk(&leafhdr, leaf);
  	bestsp = xfs_dir2_leaf_bests_p(ltp);
-	length = dp->d_ops->data_entsize(args->namelen);
+	length = dp->d_ops->data_entsize(args->name.len);
 
  	/*
  	 * See if there are any entries with the same hash value
@@ -813,8 +813,8 @@ xfs_dir2_leaf_addname(
  	 */
  	dep = (xfs_dir2_data_entry_t *)dup;
  	dep->inumber = cpu_to_be64(args->inumber);
-	dep->namelen = args->namelen;
-	memcpy(dep->name, args->name, dep->namelen);
+	dep->namelen = args->name.len;
+	memcpy(dep->name, args->name.name, dep->namelen);
  	dp->d_ops->data_put_ftype(dep, args->filetype);
  	tagp = dp->d_ops->data_entry_tag_p(dep);
  	*tagp = cpu_to_be16((char *)dep - (char *)hdr);
fs/xfs/libxfs/xfs_dir2_node.c +4 -4
index 705c4f5..8bbd742 100644
@@ -604,7 +604,7 @@ xfs_dir2_leafn_lookup_for_addname(
  		ASSERT(free->hdr.magic == cpu_to_be32(XFS_DIR2_FREE_MAGIC) ||
  		       free->hdr.magic == cpu_to_be32(XFS_DIR3_FREE_MAGIC));
  	}
-	length = dp->d_ops->data_entsize(args->namelen);
+	length = dp->d_ops->data_entsize(args->name.len);
  	/*
  	 * Loop over leaf entries with the right hash value.
  	 */
@@ -1869,7 +1869,7 @@ xfs_dir2_node_addname_int(
  	__be16			*tagp;		/* data entry tag pointer */
  	__be16			*bests;
 
-	length = dp->d_ops->data_entsize(args->namelen);
+	length = dp->d_ops->data_entsize(args->name.len);
  	error = xfs_dir2_node_find_freeblk(args, fblk, &dbno, &fbp, &findex,
  					   length);
  	if (error)
@@ -1924,8 +1924,8 @@ xfs_dir2_node_addname_int(
  	/* Fill in the new entry and log it. */
  	dep = (xfs_dir2_data_entry_t *)dup;
  	dep->inumber = cpu_to_be64(args->inumber);
-	dep->namelen = args->namelen;
-	memcpy(dep->name, args->name, dep->namelen);
+	dep->namelen = args->name.len;
+	memcpy(dep->name, args->name.name, dep->namelen);
  	dp->d_ops->data_put_ftype(dep, args->filetype);
  	tagp = dp->d_ops->data_entry_tag_p(dep);
  	*tagp = cpu_to_be16((char *)dep - (char *)hdr);
fs/xfs/libxfs/xfs_dir2_sf.c +15 -15
index 85f14fc..fdc1431 100644
@@ -291,7 +291,7 @@ xfs_dir2_sf_addname(
  	/*
  	 * Compute entry (and change in) size.
  	 */
-	incr_isize = dp->d_ops->sf_entsize(sfp, args->namelen);
+	incr_isize = dp->d_ops->sf_entsize(sfp, args->name.len);
  	objchange = 0;
 
  	/*
@@ -375,7 +375,7 @@ xfs_dir2_sf_addname_easy(
  	/*
  	 * Grow the in-inode space.
  	 */
-	xfs_idata_realloc(dp, dp->d_ops->sf_entsize(sfp, args->namelen),
+	xfs_idata_realloc(dp, dp->d_ops->sf_entsize(sfp, args->name.len),
  			  XFS_DATA_FORK);
  	/*
  	 * Need to set up again due to realloc of the inode data.
@@ -385,9 +385,9 @@ xfs_dir2_sf_addname_easy(
  	/*
  	 * Fill in the new entry.
  	 */
-	sfep->namelen = args->namelen;
+	sfep->namelen = args->name.len;
  	xfs_dir2_sf_put_offset(sfep, offset);
-	memcpy(sfep->name, args->name, sfep->namelen);
+	memcpy(sfep->name, args->name.name, sfep->namelen);
  	dp->d_ops->sf_put_ino(sfp, sfep, args->inumber);
  	dp->d_ops->sf_put_ftype(sfep, args->filetype);
 
@@ -446,7 +446,7 @@ xfs_dir2_sf_addname_hard(
  	 */
  	for (offset = dp->d_ops->data_first_offset,
  	      oldsfep = xfs_dir2_sf_firstentry(oldsfp),
-	      add_datasize = dp->d_ops->data_entsize(args->namelen),
+	      add_datasize = dp->d_ops->data_entsize(args->name.len),
  	      eof = (char *)oldsfep == &buf[old_isize];
  	     !eof;
  	     offset = new_offset + dp->d_ops->data_entsize(oldsfep->namelen),
@@ -476,9 +476,9 @@ xfs_dir2_sf_addname_hard(
  	/*
  	 * Fill in the new entry, and update the header counts.
  	 */
-	sfep->namelen = args->namelen;
+	sfep->namelen = args->name.len;
  	xfs_dir2_sf_put_offset(sfep, offset);
-	memcpy(sfep->name, args->name, sfep->namelen);
+	memcpy(sfep->name, args->name.name, sfep->namelen);
  	dp->d_ops->sf_put_ino(sfp, sfep, args->inumber);
  	dp->d_ops->sf_put_ftype(sfep, args->filetype);
  	sfp->count++;
@@ -522,7 +522,7 @@ xfs_dir2_sf_addname_pick(
  	dp = args->dp;
 
  	sfp = (xfs_dir2_sf_hdr_t *)dp->i_df.if_u1.if_data;
-	size = dp->d_ops->data_entsize(args->namelen);
+	size = dp->d_ops->data_entsize(args->name.len);
  	offset = dp->d_ops->data_first_offset;
  	sfep = xfs_dir2_sf_firstentry(sfp);
  	holefit = 0;
@@ -807,7 +807,7 @@ xfs_dir2_sf_lookup(
  	/*
  	 * Special case for .
  	 */
-	if (args->namelen == 1 && args->name[0] == '.') {
+	if (args->name.len == 1 && args->name.name[0] == '.') {
  		args->inumber = dp->i_ino;
  		args->cmpresult = XFS_CMP_EXACT;
  		args->filetype = XFS_DIR3_FT_DIR;
@@ -816,8 +816,8 @@ xfs_dir2_sf_lookup(
  	/*
  	 * Special case for ..
  	 */
-	if (args->namelen == 2 &&
-	    args->name[0] == '.' && args->name[1] == '.') {
+	if (args->name.len == 2 &&
+	    args->name.name[0] == '.' && args->name.name[1] == '.') {
  		args->inumber = dp->d_ops->sf_get_parent_ino(sfp);
  		args->cmpresult = XFS_CMP_EXACT;
  		args->filetype = XFS_DIR3_FT_DIR;
@@ -912,7 +912,7 @@ xfs_dir2_sf_removename(
  	 * Calculate sizes.
  	 */
  	byteoff = (int)((char *)sfep - (char *)sfp);
-	entsize = dp->d_ops->sf_entsize(sfp, args->namelen);
+	entsize = dp->d_ops->sf_entsize(sfp, args->name.len);
  	newsize = oldsize - entsize;
  	/*
  	 * Copy the part if any after the removed entry, sliding it down.
@@ -1002,12 +1002,12 @@ xfs_dir2_sf_replace(
  	} else
  		i8elevated = 0;
 
-	ASSERT(args->namelen != 1 || args->name[0] != '.');
+	ASSERT(args->name.len != 1 || args->name.name[0] != '.');
  	/*
  	 * Replace ..'s entry.
  	 */
-	if (args->namelen == 2 &&
-	    args->name[0] == '.' && args->name[1] == '.') {
+	if (args->name.len == 2 &&
+	    args->name.name[0] == '.' && args->name.name[1] == '.') {
  		ino = dp->d_ops->sf_get_parent_ino(sfp);
  		ASSERT(args->inumber != ino);
  		dp->d_ops->sf_put_parent_ino(sfp, args->inumber);
fs/xfs/scrub/attr.c +6 -6
index 0edc7f8..42f7c07 100644
@@ -147,17 +147,17 @@ xchk_xattr_listent(
  		return;
  	}
 
-	args.flags = ATTR_KERNOTIME;
+	args.name.type = ATTR_KERNOTIME;
  	if (flags & XFS_ATTR_ROOT)
-		args.flags |= ATTR_ROOT;
+		args.name.type |= ATTR_ROOT;
  	else if (flags & XFS_ATTR_SECURE)
-		args.flags |= ATTR_SECURE;
+		args.name.type |= ATTR_SECURE;
  	args.geo = context->dp->i_mount->m_attr_geo;
  	args.whichfork = XFS_ATTR_FORK;
  	args.dp = context->dp;
-	args.name = name;
-	args.namelen = namelen;
-	args.hashval = xfs_da_hashname(args.name, args.namelen);
+	args.name.name = name;
+	args.name.len = namelen;
+	args.hashval = xfs_da_hashname(args.name.name, args.name.len);
  	args.trans = context->tp;
  	args.value = xchk_xattr_valuebuf(sx->sc);
  	args.valuelen = valuelen;
fs/xfs/xfs_trace.h +11 -9
index eaae275..e0f524d 100644
@@ -1669,7 +1669,7 @@ DECLARE_EVENT_CLASS(xfs_da_class,
  	TP_STRUCT__entry(
  		__field(dev_t, dev)
  		__field(xfs_ino_t, ino)
-		__dynamic_array(char, name, args->namelen)
+		__dynamic_array(char, name, args->name.len)
  		__field(int, namelen)
  		__field(xfs_dahash_t, hashval)
  		__field(xfs_ino_t, inumber)
@@ -1678,9 +1678,10 @@ DECLARE_EVENT_CLASS(xfs_da_class,
  	TP_fast_assign(
  		__entry->dev = VFS_I(args->dp)->i_sb->s_dev;
  		__entry->ino = args->dp->i_ino;
-		if (args->namelen)
-			memcpy(__get_str(name), args->name, args->namelen);
-		__entry->namelen = args->namelen;
+		if (args->name.len)
+			memcpy(__get_str(name), args->name.name,
+			       args->name.len);
+		__entry->namelen = args->name.len;
  		__entry->hashval = args->hashval;
  		__entry->inumber = args->inumber;
  		__entry->op_flags = args->op_flags;
@@ -1733,7 +1734,7 @@ DECLARE_EVENT_CLASS(xfs_attr_class,
  	TP_STRUCT__entry(
  		__field(dev_t, dev)
  		__field(xfs_ino_t, ino)
-		__dynamic_array(char, name, args->namelen)
+		__dynamic_array(char, name, args->name.len)
  		__field(int, namelen)
  		__field(int, valuelen)
  		__field(xfs_dahash_t, hashval)
@@ -1743,12 +1744,13 @@ DECLARE_EVENT_CLASS(xfs_attr_class,
  	TP_fast_assign(
  		__entry->dev = VFS_I(args->dp)->i_sb->s_dev;
  		__entry->ino = args->dp->i_ino;
-		if (args->namelen)
-			memcpy(__get_str(name), args->name, args->namelen);
-		__entry->namelen = args->namelen;
+		if (args->name.len)
+			memcpy(__get_str(name), args->name.name,
+			       args->name.len);
+		__entry->namelen = args->name.len;
  		__entry->valuelen = args->valuelen;
  		__entry->hashval = args->hashval;
-		__entry->flags = args->flags;
+		__entry->flags = args->name.type;
  		__entry->op_flags = args->op_flags;
  	),
  	TP_printk("dev %d:%d ino 0x%llx name %.*s namelen %d valuelen %d "
Signature · 1 line
2.7.4
#11 lore raw

PATCH v3 3/19 xfs: Add xfs_dabuf defines

In reply to Allison Collins

This patch adds two new defines XFS_DABUF_MAP_NOMAPPING and XFS_DABUF_MAP_HOLE_OK. This helps to clean up hard numbers and makes the code easier to read

---
 fs/xfs/libxfs/xfs_attr_leaf.h | 3 +++
 fs/xfs/libxfs/xfs_da_btree.c  | 3 ++-
 2 files changed, 5 insertions(+), 1 deletion(-)
fs/xfs/libxfs/xfs_attr_leaf.h +3 -0
index 7b74e18..536a290 100644
@@ -16,6 +16,9 @@ struct xfs_da_state_blk;
 struct xfs_inode;
 struct xfs_trans;
 
+#define XFS_DABUF_MAP_NOMAPPING	(-1) /* Caller doesn't have a mapping. */
+#define XFS_DABUF_MAP_HOLE_OK	(-2) /* don't complain if we land in a hole. */
+
 /*
  * Used to keep a list of "remote value" extents when unlinking an inode.
  */
fs/xfs/libxfs/xfs_da_btree.c +2 -1
index 129ec09..2b94685 100644
@@ -2534,7 +2534,8 @@ xfs_dabuf_map(
 	 * Caller doesn't have a mapping.  -2 means don't complain
 	 * if we land in a hole.
 	 */
-	if (mappedbno == -1 || mappedbno == -2) {
+	if (mappedbno == XFS_DABUF_MAP_NOMAPPING ||
+	    mappedbno == XFS_DABUF_MAP_HOLE_OK) {
 		/*
 		 * Optimize the one-block case.
 		 */
Signature · 1 line
2.7.4
#12 lore raw

Re: [PATCH v3 03/19] xfs: Add xfs_dabuf defines

Quoted 29 lines · Allison Collins

This patch adds two new defines XFS_DABUF_MAP_NOMAPPING and XFS_DABUF_MAP_HOLE_OK. This helps to clean up hard numbers and makes the code easier to read

---
 fs/xfs/libxfs/xfs_attr_leaf.h | 3 +++
 fs/xfs/libxfs/xfs_da_btree.c  | 3 ++-
 2 files changed, 5 insertions(+), 1 deletion(-)
fs/xfs/libxfs/xfs_attr_leaf.h +3 -0
index 7b74e18..536a290 100644
@@ -16,6 +16,9 @@ struct xfs_da_state_blk;
 struct xfs_inode;
 struct xfs_trans;
 
+#define XFS_DABUF_MAP_NOMAPPING	(-1) /* Caller doesn't have a mapping. */
+#define XFS_DABUF_MAP_HOLE_OK	(-2) /* don't complain if we land in a hole. */
+
 /*
  * Used to keep a list of "remote value" extents when unlinking an inode.
  */
fs/xfs/libxfs/xfs_da_btree.c +0 -0
index 129ec09..2b94685 100644

fs/xfs/libxfs/xfs_da_btree.c xfs_dabuf_map( · line 2538

Quoted 6 lines
fs/xfs/libxfs/xfs_da_btree.c +2 -1
@@ -2534,7 +2534,8 @@ xfs_dabuf_map(
 	 * Caller doesn't have a mapping.  -2 means don't complain
 	 * if we land in a hole.
 	 */
-	if (mappedbno == -1 || mappedbno == -2) {
+	if (mappedbno == XFS_DABUF_MAP_NOMAPPING ||
+	    mappedbno == XFS_DABUF_MAP_HOLE_OK) {

Er... convert the users of -1 and -2 too, please...

--D

Quoted 6 lines
fs/xfs/libxfs/xfs_da_btree.c +0 -0
 		/*
 		 * Optimize the one-block case.
 		 */
Signature · 1 line
2.7.4
#13 lore raw

PATCH v3 4/19 xfs: Add xfs_has_attr and subroutines

In reply to Allison Collins

From: Allison Henderson <[email protected]>

This patch adds a new functions to check for the existence of an attribute. Subroutines are also added to handle the cases of leaf blocks, nodes or shortform. Common code that appears in existing attr add and remove functions have been factored out to help reduce the appearence of duplicated code. We will need these routines later for delayed attributes since delayed operations cannot return error codes.

---
 fs/xfs/libxfs/xfs_attr.c      | 150 +++++++++++++++++++++++++++---------------
 fs/xfs/libxfs/xfs_attr.h      |   1 +
 fs/xfs/libxfs/xfs_attr_leaf.c |  92 +++++++++++++++++---------
 fs/xfs/libxfs/xfs_attr_leaf.h |   2 +
 4 files changed, 161 insertions(+), 84 deletions(-)
fs/xfs/libxfs/xfs_attr.c +97 -53
index 50e099f..a297857 100644
@@ -46,6 +46,7 @@ STATIC int xfs_attr_shortform_addname(xfs_da_args_t *args);
 STATIC int xfs_attr_leaf_get(xfs_da_args_t *args);
 STATIC int xfs_attr_leaf_addname(xfs_da_args_t *args);
 STATIC int xfs_attr_leaf_removename(xfs_da_args_t *args);
+STATIC int xfs_leaf_has_attr(struct xfs_da_args *args, struct xfs_buf **bp);
 
 /*
  * Internal routines when attribute list is more than one block.
@@ -53,6 +54,8 @@ STATIC int xfs_attr_leaf_removename(xfs_da_args_t *args);
 STATIC int xfs_attr_node_get(xfs_da_args_t *args);
 STATIC int xfs_attr_node_addname(xfs_da_args_t *args);
 STATIC int xfs_attr_node_removename(xfs_da_args_t *args);
+STATIC int xfs_attr_node_hasname(xfs_da_args_t *args,
+				 struct xfs_da_state **state);
 STATIC int xfs_attr_fillstate(xfs_da_state_t *state);
 STATIC int xfs_attr_refillstate(xfs_da_state_t *state);
 
@@ -309,6 +312,32 @@ xfs_attr_set_args(
 }
 
 /*
+ * Return EEXIST if attr is found, or ENOATTR if not
+ */
+int
+xfs_has_attr(
+	struct xfs_da_args      *args)
+{
+	struct xfs_inode        *dp = args->dp;
+	struct xfs_buf		*bp;
+	int                     error;
+
+	if (!xfs_inode_hasattr(dp)) {
+		error = -ENOATTR;
+	} else if (dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) {
+		ASSERT(dp->i_afp->if_flags & XFS_IFINLINE);
+		error = xfs_shortform_has_attr(args, NULL, NULL);
+	} else if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
+		error = xfs_leaf_has_attr(args, &bp);
+		xfs_trans_brelse(args->trans, bp);
+	} else {
+		error = xfs_attr_node_hasname(args, NULL);
+	}
+
+	return error;
+}
+
+/*
  * Remove the attribute specified in @args.
  */
 int
@@ -574,26 +603,17 @@ STATIC int
 xfs_attr_leaf_addname(
 	struct xfs_da_args	*args)
 {
-	struct xfs_inode	*dp;
 	struct xfs_buf		*bp;
 	int			retval, error, forkoff;
+	struct xfs_inode	*dp = args->dp;
 
 	trace_xfs_attr_leaf_addname(args);
 
 	/*
-	 * Read the (only) block in the attribute list in.
-	 */
-	dp = args->dp;
-	args->blkno = 0;
-	error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno, -1, &bp);
-	if (error)
-		return error;
-
-	/*
 	 * Look up the given attribute in the leaf block.  Figure out if
 	 * the given flags produce an error or call for an atomic rename.
 	 */
-	retval = xfs_attr3_leaf_lookup_int(bp, args);
+	retval = xfs_leaf_has_attr(args, &bp);
 	if ((args->name.type & ATTR_REPLACE) && (retval == -ENOATTR)) {
 		xfs_trans_brelse(args->trans, bp);
 		return retval;
@@ -745,6 +765,25 @@ xfs_attr_leaf_addname(
 }
 
 /*
+ * Return EEXIST if attr is found, or ENOATTR if not
+ */
+STATIC int
+xfs_leaf_has_attr(
+	struct xfs_da_args      *args,
+	struct xfs_buf		**bp)
+{
+	int                     error = 0;
+
+	args->blkno = 0;
+	error = xfs_attr3_leaf_read(args->trans, args->dp,
+			args->blkno, XFS_DABUF_MAP_NOMAPPING, bp);
+	if (error)
+		return error;
+
+	return xfs_attr3_leaf_lookup_int(*bp, args);
+}
+
+/*
  * Remove a name from the leaf attribute list structure
  *
  * This leaf block cannot have a "remote" value, we only call this routine
@@ -764,12 +803,8 @@ xfs_attr_leaf_removename(
 	 * Remove the attribute.
 	 */
 	dp = args->dp;
-	args->blkno = 0;
-	error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno, -1, &bp);
-	if (error)
-		return error;
 
-	error = xfs_attr3_leaf_lookup_int(bp, args);
+	error = xfs_leaf_has_attr(args, &bp);
 	if (error == -ENOATTR) {
 		xfs_trans_brelse(args->trans, bp);
 		return error;
@@ -808,12 +843,7 @@ xfs_attr_leaf_get(xfs_da_args_t *args)
 
 	trace_xfs_attr_leaf_get(args);
 
-	args->blkno = 0;
-	error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno, -1, &bp);
-	if (error)
-		return error;
-
-	error = xfs_attr3_leaf_lookup_int(bp, args);
+	error = xfs_leaf_has_attr(args, &bp);
 	if (error != -EEXIST)  {
 		xfs_trans_brelse(args->trans, bp);
 		return error;
@@ -823,6 +853,43 @@ xfs_attr_leaf_get(xfs_da_args_t *args)
 	return error;
 }
 
+/*
+ * Return EEXIST if attr is found, or ENOATTR if not
+ * statep: If not null is set to point at the found state.  Caller will
+ * 	   be responsible for freeing the state in this case.
+ */
+STATIC int
+xfs_attr_node_hasname(
+	struct xfs_da_args	*args,
+	struct xfs_da_state	**statep)
+{
+	struct xfs_da_state	*state;
+	struct xfs_inode	*dp;
+	int			retval, error;
+
+	/*
+	 * Tie a string around our finger to remind us where we are.
+	 */
+	dp = args->dp;
+	state = xfs_da_state_alloc();
+	state->args = args;
+	state->mp = dp->i_mount;
+
+	/*
+	 * Search to see if name exists, and get back a pointer to it.
+	 */
+	error = xfs_da3_node_lookup_int(state, &retval);
+	if (error == 0)
+		error = retval;
+
+	if (statep != NULL)
+		*statep = state;
+	else
+		xfs_da_state_free(state);
+
+	return error;
+}
+
 /*========================================================================
  * External routines when attribute list size > geo->blksize
  *========================================================================*/
@@ -855,17 +922,14 @@ xfs_attr_node_addname(
 	dp = args->dp;
 	mp = dp->i_mount;
 restart:
-	state = xfs_da_state_alloc();
-	state->args = args;
-	state->mp = mp;
-
 	/*
 	 * Search to see if name already exists, and get back a pointer
 	 * to where it should go.
 	 */
-	error = xfs_da3_node_lookup_int(state, &retval);
-	if (error)
+	error = xfs_attr_node_hasname(args, &state);
+	if (error == -EEXIST)
 		goto out;
+
 	blk = &state->path.blk[ state->path.active-1 ];
 	ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
 	if ((args->name.type & ATTR_REPLACE) && (retval == -ENOATTR)) {
@@ -1070,29 +1134,15 @@ xfs_attr_node_removename(
 {
 	struct xfs_da_state	*state;
 	struct xfs_da_state_blk	*blk;
-	struct xfs_inode	*dp;
 	struct xfs_buf		*bp;
 	int			retval, error, forkoff;
+	struct xfs_inode	*dp = args->dp;
 
 	trace_xfs_attr_node_removename(args);
 
-	/*
-	 * Tie a string around our finger to remind us where we are.
-	 */
-	dp = args->dp;
-	state = xfs_da_state_alloc();
-	state->args = args;
-	state->mp = dp->i_mount;
-
-	/*
-	 * Search to see if name exists, and get back a pointer to it.
-	 */
-	error = xfs_da3_node_lookup_int(state, &retval);
-	if (error || (retval != -EEXIST)) {
-		if (error == 0)
-			error = retval;
+	error = xfs_attr_node_hasname(args, &state);
+	if (error != -EEXIST)
 		goto out;
-	}
 
 	/*
 	 * If there is an out-of-line value, de-allocate the blocks.
@@ -1314,20 +1364,14 @@ xfs_attr_node_get(xfs_da_args_t *args)
 
 	trace_xfs_attr_node_get(args);
 
-	state = xfs_da_state_alloc();
-	state->args = args;
-	state->mp = args->dp->i_mount;
-
 	/*
 	 * Search to see if name exists, and get back a pointer to it.
 	 */
-	error = xfs_da3_node_lookup_int(state, &retval);
-	if (error) {
+	error = xfs_attr_node_hasname(args, &state);
+	if (error != -EEXIST) {
 		retval = error;
 		goto out_release;
 	}
-	if (retval != -EEXIST)
-		goto out_release;
 
 	/*
 	 * Get the value, local or "remote"
fs/xfs/libxfs/xfs_attr.h +1 -0
index cedb4e2..fb56d81 100644
@@ -150,6 +150,7 @@ int xfs_attr_set(struct xfs_inode *dp, struct xfs_name *name,
 		 unsigned char *value, int valuelen);
 int xfs_attr_set_args(struct xfs_da_args *args);
 int xfs_attr_remove(struct xfs_inode *dp, struct xfs_name *name);
+int xfs_has_attr(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 flags, struct attrlist_cursor_kern *cursor);
fs/xfs/libxfs/xfs_attr_leaf.c +61 -31

125 lines not on this page · raw message

fs/xfs/libxfs/xfs_attr_leaf.h +2 -0
index 536a290..58e9327 100644
@@ -42,6 +42,8 @@ int	xfs_attr_shortform_getvalue(struct xfs_da_args *args);
 int	xfs_attr_shortform_to_leaf(struct xfs_da_args *args,
 			struct xfs_buf **leaf_bp);
 int	xfs_attr_shortform_remove(struct xfs_da_args *args);
+int	xfs_shortform_has_attr(struct xfs_da_args *args,
+			       struct xfs_attr_sf_entry **sfep, int *basep);
 int	xfs_attr_shortform_allfit(struct xfs_buf *bp, struct xfs_inode *dp);
 int	xfs_attr_shortform_bytesfit(struct xfs_inode *dp, int bytes);
 xfs_failaddr_t xfs_attr_shortform_verify(struct xfs_inode *ip);
Signature · 1 line
2.7.4
#14 lore raw

Re: [PATCH v3 04/19] xfs: Add xfs_has_attr and subroutines

Quoted 10 lines · Allison Collins

From: Allison Henderson <[email protected]>

This patch adds a new functions to check for the existence of an attribute. Subroutines are also added to handle the cases of leaf blocks, nodes or shortform. Common code that appears in existing attr add and remove functions have been factored out to help reduce the appearence of duplicated code. We will need these routines later for delayed attributes since delayed operations cannot return error codes.

Quoted 2 lines

Extra s-o-b tag?

Quoted 12 lines
---
 fs/xfs/libxfs/xfs_attr.c      | 150 +++++++++++++++++++++++++++---------------
 fs/xfs/libxfs/xfs_attr.h      |   1 +
 fs/xfs/libxfs/xfs_attr_leaf.c |  92 +++++++++++++++++---------
 fs/xfs/libxfs/xfs_attr_leaf.h |   2 +
 4 files changed, 161 insertions(+), 84 deletions(-)
fs/xfs/libxfs/xfs_attr.c +0 -0
index 50e099f..a297857 100644

fs/xfs/libxfs/xfs_attr.c STATIC int xfs_attr_shortform_addname(xfs_da_args_t *args); · line 50

Quoted 5 lines
fs/xfs/libxfs/xfs_attr.c +1 -0
@@ -46,6 +46,7 @@ STATIC int xfs_attr_shortform_addname(xfs_da_args_t *args);
 STATIC int xfs_attr_leaf_get(xfs_da_args_t *args);
 STATIC int xfs_attr_leaf_addname(xfs_da_args_t *args);
 STATIC int xfs_attr_leaf_removename(xfs_da_args_t *args);
+STATIC int xfs_leaf_has_attr(struct xfs_da_args *args, struct xfs_buf **bp);
 

The fact that this is not named xfs_attr_leaf_*() kind of stands out here, particularly since the node variant uses the xfs_attr_* prefix. Hm? (Same goes for xfs_shortform_has_attr() I suppose..).

Quoted 30 lines
fs/xfs/libxfs/xfs_attr.c +17 -0
 /*
  * Internal routines when attribute list is more than one block.
@@ -53,6 +54,8 @@ STATIC int xfs_attr_leaf_removename(xfs_da_args_t *args);
 STATIC int xfs_attr_node_get(xfs_da_args_t *args);
 STATIC int xfs_attr_node_addname(xfs_da_args_t *args);
 STATIC int xfs_attr_node_removename(xfs_da_args_t *args);
+STATIC int xfs_attr_node_hasname(xfs_da_args_t *args,
+				 struct xfs_da_state **state);
 STATIC int xfs_attr_fillstate(xfs_da_state_t *state);
 STATIC int xfs_attr_refillstate(xfs_da_state_t *state);
 
@@ -309,6 +312,32 @@ xfs_attr_set_args(
 }
 
 /*
+ * Return EEXIST if attr is found, or ENOATTR if not
+ */
+int
+xfs_has_attr(
+	struct xfs_da_args      *args)
+{
+	struct xfs_inode        *dp = args->dp;
+	struct xfs_buf		*bp;
+	int                     error;
+
+	if (!xfs_inode_hasattr(dp)) {
+		error = -ENOATTR;
+	} else if (dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) {
+		ASSERT(dp->i_afp->if_flags & XFS_IFINLINE);
+		error = xfs_shortform_has_attr(args, NULL, NULL);

fs/xfs/libxfs/xfs_attr.c xfs_attr_set_args( · line 339

Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10 -0
+	} else if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
+		error = xfs_leaf_has_attr(args, &bp);
+		xfs_trans_brelse(args->trans, bp);
+	} else {
+		error = xfs_attr_node_hasname(args, NULL);
+	}
+
+	return error;
+}
+

FWIW, I think it's preferable to include new functions like this with the first user. I'm a bit curious about the use of error codes here as opposed to returning a boolean. I could see being able to handle unexpected errors as a good reason for doing that, but taking a quick look ahead, it appears neither caller of xfs_has_attr() does so. ;)

(To be clear, I think keeping the function as is and fixing up the eventual callers to handle unexpected errors is probably the right thing to do.).

Quoted 14 lines
fs/xfs/libxfs/xfs_attr.c +2 -1
+/*
  * Remove the attribute specified in @args.
  */
 int
@@ -574,26 +603,17 @@ STATIC int
 xfs_attr_leaf_addname(
 	struct xfs_da_args	*args)
 {
-	struct xfs_inode	*dp;
 	struct xfs_buf		*bp;
 	int			retval, error, forkoff;
+	struct xfs_inode	*dp = args->dp;
 
 	trace_xfs_attr_leaf_addname(args);

fs/xfs/libxfs/xfs_attr.c STATIC int · line 591

Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +0 -8
 
 	/*
-	 * Read the (only) block in the attribute list in.
-	 */
-	dp = args->dp;
-	args->blkno = 0;
-	error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno, -1, &bp);
-	if (error)
-		return error;
-

It looks like we lose this unexpected error check here (i.e. suppose we got -ENOMEM or -EFSCORRUPTED or something that indicates we shouldn't continue). FWIW, this seems to repeat throughout this patch where we've invoked the new helpers..

Quoted 13 lines
fs/xfs/libxfs/xfs_attr.c +1 -2
-	/*
 	 * Look up the given attribute in the leaf block.  Figure out if
 	 * the given flags produce an error or call for an atomic rename.
 	 */
-	retval = xfs_attr3_leaf_lookup_int(bp, args);
+	retval = xfs_leaf_has_attr(args, &bp);
 	if ((args->name.type & ATTR_REPLACE) && (retval == -ENOATTR)) {
 		xfs_trans_brelse(args->trans, bp);
 		return retval;
@@ -745,6 +765,25 @@ xfs_attr_leaf_addname(
 }
 
 /*

fs/xfs/libxfs/xfs_attr.c xfs_attr_leaf_addname( · line 777

Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10 -0
+ * Return EEXIST if attr is found, or ENOATTR if not
+ */
+STATIC int
+xfs_leaf_has_attr(
+	struct xfs_da_args      *args,
+	struct xfs_buf		**bp)
+{
+	int                     error = 0;
+
+	args->blkno = 0;

This seems misplaced for a helper, but I could be missing context. Why not just pass zero directly and leave the args->blkno assignment to the caller?

Quoted 13 lines
fs/xfs/libxfs/xfs_attr.c +9 -0
+	error = xfs_attr3_leaf_read(args->trans, args->dp,
+			args->blkno, XFS_DABUF_MAP_NOMAPPING, bp);
+	if (error)
+		return error;
+
+	return xfs_attr3_leaf_lookup_int(*bp, args);
+}
+
+/*
  * Remove a name from the leaf attribute list structure
  *
  * This leaf block cannot have a "remote" value, we only call this routine

fs/xfs/libxfs/xfs_attr.c xfs_attr_leaf_removename( · line 770

Quoted 7 lines
fs/xfs/libxfs/xfs_attr.c +0 -4
@@ -764,12 +803,8 @@ xfs_attr_leaf_removename(
 	 * Remove the attribute.
 	 */
 	dp = args->dp;
-	args->blkno = 0;
-	error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno, -1, &bp);
-	if (error)
-		return error;

Lost error check.

Quoted 7 lines
fs/xfs/libxfs/xfs_attr.c +1 -1
-	error = xfs_attr3_leaf_lookup_int(bp, args);
+	error = xfs_leaf_has_attr(args, &bp);
 	if (error == -ENOATTR) {
 		xfs_trans_brelse(args->trans, bp);
 		return error;

fs/xfs/libxfs/xfs_attr.c xfs_attr_leaf_get(xfs_da_args_t *args) · line 815

Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c +0 -5
@@ -808,12 +843,7 @@ xfs_attr_leaf_get(xfs_da_args_t *args)
 
 	trace_xfs_attr_leaf_get(args);
 
-	args->blkno = 0;
-	error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno, -1, &bp);
-	if (error)
-		return error;
-

^ here too. Not sure if I caught them all, but you get the idea. ;)

Quoted 21 lines
fs/xfs/libxfs/xfs_attr.c +13 -1
-	error = xfs_attr3_leaf_lookup_int(bp, args);
+	error = xfs_leaf_has_attr(args, &bp);
 	if (error != -EEXIST)  {
 		xfs_trans_brelse(args->trans, bp);
 		return error;
@@ -823,6 +853,43 @@ xfs_attr_leaf_get(xfs_da_args_t *args)
 	return error;
 }
 
+/*
+ * Return EEXIST if attr is found, or ENOATTR if not
+ * statep: If not null is set to point at the found state.  Caller will
+ * 	   be responsible for freeing the state in this case.
+ */
+STATIC int
+xfs_attr_node_hasname(
+	struct xfs_da_args	*args,
+	struct xfs_da_state	**statep)
+{
+	struct xfs_da_state	*state;
+	struct xfs_inode	*dp;

fs/xfs/libxfs/xfs_attr.c xfs_attr_leaf_get(xfs_da_args_t *args) · line 877

Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10 -0
+	int			retval, error;
+
+	/*
+	 * Tie a string around our finger to remind us where we are.
+	 */
+	dp = args->dp;
+	state = xfs_da_state_alloc();
+	state->args = args;
+	state->mp = dp->i_mount;
+

No real need for the dp local variable here if it's just to reference ->i_mount. Also I know that comment isn't introduced by this patch, but any idea what it actually means? It doesn't make much sense to me at a glance. :P

Quoted 22 lines
fs/xfs/libxfs/xfs_attr.c +15 -0
+	/*
+	 * Search to see if name exists, and get back a pointer to it.
+	 */
+	error = xfs_da3_node_lookup_int(state, &retval);
+	if (error == 0)
+		error = retval;
+
+	if (statep != NULL)
+		*statep = state;
+	else
+		xfs_da_state_free(state);
+
+	return error;
+}
+
 /*========================================================================
  * External routines when attribute list size > geo->blksize
  *========================================================================*/
@@ -855,17 +922,14 @@ xfs_attr_node_addname(
 	dp = args->dp;
 	mp = dp->i_mount;
 restart:

fs/xfs/libxfs/xfs_attr.c xfs_attr_node_addname( · line 867

Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +0 -6
-	state = xfs_da_state_alloc();
-	state->args = args;
-	state->mp = mp;
-
 	/*
 	 * Search to see if name already exists, and get back a pointer
 	 * to where it should go.
 	 */
-	error = xfs_da3_node_lookup_int(state, &retval);
-	if (error)

Error check again.

Quoted 117 lines
fs/xfs/libxfs/xfs_attr.c +8 -25
+	error = xfs_attr_node_hasname(args, &state);
+	if (error == -EEXIST)
 		goto out;
+
 	blk = &state->path.blk[ state->path.active-1 ];
 	ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
 	if ((args->name.type & ATTR_REPLACE) && (retval == -ENOATTR)) {
@@ -1070,29 +1134,15 @@ xfs_attr_node_removename(
 {
 	struct xfs_da_state	*state;
 	struct xfs_da_state_blk	*blk;
-	struct xfs_inode	*dp;
 	struct xfs_buf		*bp;
 	int			retval, error, forkoff;
+	struct xfs_inode	*dp = args->dp;
 
 	trace_xfs_attr_node_removename(args);
 
-	/*
-	 * Tie a string around our finger to remind us where we are.
-	 */
-	dp = args->dp;
-	state = xfs_da_state_alloc();
-	state->args = args;
-	state->mp = dp->i_mount;
-
-	/*
-	 * Search to see if name exists, and get back a pointer to it.
-	 */
-	error = xfs_da3_node_lookup_int(state, &retval);
-	if (error || (retval != -EEXIST)) {
-		if (error == 0)
-			error = retval;
+	error = xfs_attr_node_hasname(args, &state);
+	if (error != -EEXIST)
 		goto out;
-	}
 
 	/*
 	 * If there is an out-of-line value, de-allocate the blocks.
@@ -1314,20 +1364,14 @@ xfs_attr_node_get(xfs_da_args_t *args)
 
 	trace_xfs_attr_node_get(args);
 
-	state = xfs_da_state_alloc();
-	state->args = args;
-	state->mp = args->dp->i_mount;
-
 	/*
 	 * Search to see if name exists, and get back a pointer to it.
 	 */
-	error = xfs_da3_node_lookup_int(state, &retval);
-	if (error) {
+	error = xfs_attr_node_hasname(args, &state);
+	if (error != -EEXIST) {
 		retval = error;
 		goto out_release;
 	}
-	if (retval != -EEXIST)
-		goto out_release;
 
 	/*
 	 * Get the value, local or "remote"
fs/xfs/libxfs/xfs_attr.h +1 -0
index cedb4e2..fb56d81 100644
@@ -150,6 +150,7 @@ int xfs_attr_set(struct xfs_inode *dp, struct xfs_name *name,
 		 unsigned char *value, int valuelen);
 int xfs_attr_set_args(struct xfs_da_args *args);
 int xfs_attr_remove(struct xfs_inode *dp, struct xfs_name *name);
+int xfs_has_attr(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 flags, struct attrlist_cursor_kern *cursor);
fs/xfs/libxfs/xfs_attr_leaf.c +34 -0
index 07ce320..a501538 100644
@@ -590,6 +590,53 @@ xfs_attr_shortform_create(xfs_da_args_t *args)
 }
 
 /*
+ * Return EEXIST if attr is found, or ENOATTR if not
+ * args:  args containing attribute name and namelen
+ * sfep:  If not null, pointer will be set to the last attr entry found
+ * basep: If not null, pointer is set to the byte offset of the entry in the
+ *	  list
+ */
+int
+xfs_shortform_has_attr(
+	struct xfs_da_args	 *args,
+	struct xfs_attr_sf_entry **sfep,
+	int			 *basep)
+{
+	struct xfs_attr_shortform *sf;
+	struct xfs_attr_sf_entry *sfe;
+	int			base = sizeof(struct xfs_attr_sf_hdr);
+	int			size = 0;
+	int			end;
+	int			i;
+
+	base = sizeof(struct xfs_attr_sf_hdr);
+	sf = (struct xfs_attr_shortform *)args->dp->i_afp->if_u1.if_data;
+	sfe = &sf->list[0];
+	end = sf->hdr.count;
+	for (i = 0; i < end; sfe = XFS_ATTR_SF_NEXTENTRY(sfe),
+			base += size, i++) {
+		size = XFS_ATTR_SF_ENTSIZE(sfe);
+		if (sfe->namelen != args->name.len)
+			continue;
+		if (memcmp(sfe->nameval, args->name.name, args->name.len) != 0)
+			continue;
+		if (!xfs_attr_namesp_match(args->name.type, sfe->flags))
+			continue;
+		break;
+	}

fs/xfs/libxfs/xfs_attr_leaf.c xfs_attr_shortform_create(xfs_da_args_t *args) · line 636

Quoted 10 lines
fs/xfs/libxfs/xfs_attr_leaf.c +10 -0
+
+	if (sfep != NULL)
+		*sfep = sfe;
+
+	if (basep != NULL)
+		*basep = base;
+
+	if (i == end)
+		return -ENOATTR;
+	return -EEXIST;

This function seems like it could just return a bool. Eh, I suppose it's better to be consistent with the other variants if those ones can return unrelated errors.

Quoted 7 lines
fs/xfs/libxfs/xfs_attr_leaf.c +3 -0
+}
+
+/*
  * Add a name/value pair to the shortform attribute list.
  * Overflow from the inode has already been checked for.
  */

fs/xfs/libxfs/xfs_attr_leaf.c xfs_attr_shortform_add(xfs_da_args_t *args, int forkoff) · line 650

Quoted 7 lines
fs/xfs/libxfs/xfs_attr_leaf.c +1 -1
@@ -598,7 +645,7 @@ xfs_attr_shortform_add(xfs_da_args_t *args, int forkoff)
 {
 	xfs_attr_shortform_t *sf;
 	xfs_attr_sf_entry_t *sfe;
-	int i, offset, size;
+	int offset, size, error;
 	xfs_mount_t *mp;
 	xfs_inode_t *dp;

Nit: might be good to clean up the typedefs here since you do it in the remove function as well.

Quoted 8 lines
fs/xfs/libxfs/xfs_attr_leaf.c +1 -2
 	struct xfs_ifork *ifp;
@@ -612,18 +659,10 @@ xfs_attr_shortform_add(xfs_da_args_t *args, int forkoff)
 	ifp = dp->i_afp;
 	ASSERT(ifp->if_flags & XFS_IFINLINE);
 	sf = (xfs_attr_shortform_t *)ifp->if_u1.if_data;
-	sfe = &sf->list[0];
-	for (i = 0; i < sf->hdr.count; sfe = XFS_ATTR_SF_NEXTENTRY(sfe), i++) {
+	error = xfs_shortform_has_attr(args, &sfe, NULL);

fs/xfs/libxfs/xfs_attr_leaf.c xfs_attr_shortform_add(xfs_da_args_t *args, int forkoff) · line 665

Quoted 10 lines
fs/xfs/libxfs/xfs_attr_leaf.c +1 -7
 #ifdef DEBUG
-		if (sfe->namelen != args->name.len)
-			continue;
-		if (memcmp(args->name.name, sfe->nameval, args->name.len) != 0)
-			continue;
-		if (!xfs_attr_namesp_match(args->name.type, sfe->flags))
-			continue;
-		ASSERT(0);
+	ASSERT(error != -EEXIST);
 #endif

Hmm, interesting. So basically this code walks to the end of the list for the purpose of placement of the new attr and the debug code simply asserts that we don't find an existing attr. The only thing that concerns me is that nothing about xfs_shortform_has_attr() indicates that the output values are important when the lookup fails. The comment only explains what the values are when a lookup succeeds. Could we update the comment to elaborate on this use case to prevent somebody from unknowingly breaking it down the road?

Also, there's no need for the #ifdef DEBUG any more with just the assert check in that block.

Quoted 18 lines
fs/xfs/libxfs/xfs_attr_leaf.c +5 -6
-	}
 
 	offset = (char *)sfe - (char *)sf;
 	size = XFS_ATTR_SF_ENTSIZE_BYNAME(args->name.len, args->valuelen);
@@ -668,33 +707,24 @@ xfs_attr_fork_remove(
 int
 xfs_attr_shortform_remove(xfs_da_args_t *args)
 {
-	xfs_attr_shortform_t *sf;
-	xfs_attr_sf_entry_t *sfe;
-	int base, size=0, end, totsize, i;
-	xfs_mount_t *mp;
-	xfs_inode_t *dp;
+	struct xfs_attr_shortform	*sf;
+	struct xfs_attr_sf_entry	*sfe;
+	int				base, size = 0, end, totsize;
+	struct xfs_mount		*mp;
+	struct xfs_inode		*dp;

fs/xfs/libxfs/xfs_attr_leaf.c xfs_attr_fork_remove( · line 722

Quoted 10 lines
fs/xfs/libxfs/xfs_attr_leaf.c +1 -2
+	int				error;
 
 	trace_xfs_attr_sf_remove(args);
 
 	dp = args->dp;
 	mp = dp->i_mount;
-	base = sizeof(xfs_attr_sf_hdr_t);
 	sf = (xfs_attr_shortform_t *)dp->i_afp->if_u1.if_data;
-	sfe = &sf->list[0];
 	end = sf->hdr.count;

This value of end is unused (end is immediately reassigned further down in the function).

Brian

Quoted 37 lines
fs/xfs/libxfs/xfs_attr_leaf.c +5 -13
-	for (i = 0; i < end; sfe = XFS_ATTR_SF_NEXTENTRY(sfe),
-					base += size, i++) {
-		size = XFS_ATTR_SF_ENTSIZE(sfe);
-		if (sfe->namelen != args->name.len)
-			continue;
-		if (memcmp(sfe->nameval, args->name.name, args->name.len) != 0)
-			continue;
-		if (!xfs_attr_namesp_match(args->name.type, sfe->flags))
-			continue;
-		break;
-	}
-	if (i == end)
-		return -ENOATTR;
+
+	error = xfs_shortform_has_attr(args, &sfe, &base);
+	if (error == -ENOATTR)
+		return error;
+	size = XFS_ATTR_SF_ENTSIZE(sfe);
 
 	/*
 	 * Fix up the attribute fork data, covering the hole
fs/xfs/libxfs/xfs_attr_leaf.h +2 -0
index 536a290..58e9327 100644
@@ -42,6 +42,8 @@ int	xfs_attr_shortform_getvalue(struct xfs_da_args *args);
 int	xfs_attr_shortform_to_leaf(struct xfs_da_args *args,
 			struct xfs_buf **leaf_bp);
 int	xfs_attr_shortform_remove(struct xfs_da_args *args);
+int	xfs_shortform_has_attr(struct xfs_da_args *args,
+			       struct xfs_attr_sf_entry **sfep, int *basep);
 int	xfs_attr_shortform_allfit(struct xfs_buf *bp, struct xfs_inode *dp);
 int	xfs_attr_shortform_bytesfit(struct xfs_inode *dp, int bytes);
 xfs_failaddr_t xfs_attr_shortform_verify(struct xfs_inode *ip);
Signature · 1 line
2.7.4
#15 lore raw

Re: [PATCH v3 04/19] xfs: Add xfs_has_attr and subroutines

Quoted 11 lines · Brian Foster
Quoted 10 lines · Allison Collins

From: Allison Henderson <[email protected]>

This patch adds a new functions to check for the existence of an attribute. Subroutines are also added to handle the cases of leaf blocks, nodes or shortform. Common code that appears in existing attr add and remove functions have been factored out to help reduce the appearence of duplicated code. We will need these routines later for delayed attributes since delayed operations cannot return error codes.

Quoted 4 lines
Quoted 2 lines

Extra s-o-b tag?

Oops, I thought I had caught all the old names. Will clean out :-)

Quoted 8 lines
Quoted 8 lines
---
  fs/xfs/libxfs/xfs_attr.c      | 150 +++++++++++++++++++++++++++---------------
  fs/xfs/libxfs/xfs_attr.h      |   1 +
  fs/xfs/libxfs/xfs_attr_leaf.c |  92 +++++++++++++++++---------
  fs/xfs/libxfs/xfs_attr_leaf.h |   2 +
  4 files changed, 161 insertions(+), 84 deletions(-)
Quoted 14 lines

fs/xfs/libxfs/xfs_attr.c STATIC int xfs_attr_shortform_addname(xfs_da_args_t *args); · line 50

Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +1 -0
index 50e099f..a297857 100644
@@ -46,6 +46,7 @@ STATIC int xfs_attr_shortform_addname(xfs_da_args_t *args);
  STATIC int xfs_attr_leaf_get(xfs_da_args_t *args);
  STATIC int xfs_attr_leaf_addname(xfs_da_args_t *args);
  STATIC int xfs_attr_leaf_removename(xfs_da_args_t *args);
+STATIC int xfs_leaf_has_attr(struct xfs_da_args *args, struct xfs_buf **bp);
 

The fact that this is not named xfs_attr_leaf_*() kind of stands out here, particularly since the node variant uses the xfs_attr_* prefix. Hm? (Same goes for xfs_shortform_has_attr() I suppose..).

Sure, I can flip the prefixes around to look a little more consistent

Quoted 48 lines
Quoted 31 lines
fs/xfs/libxfs/xfs_attr.c +17 -0
  /*
   * Internal routines when attribute list is more than one block.
@@ -53,6 +54,8 @@ STATIC int xfs_attr_leaf_removename(xfs_da_args_t *args);
  STATIC int xfs_attr_node_get(xfs_da_args_t *args);
  STATIC int xfs_attr_node_addname(xfs_da_args_t *args);
  STATIC int xfs_attr_node_removename(xfs_da_args_t *args);
+STATIC int xfs_attr_node_hasname(xfs_da_args_t *args,
+				 struct xfs_da_state **state);
  STATIC int xfs_attr_fillstate(xfs_da_state_t *state);
  STATIC int xfs_attr_refillstate(xfs_da_state_t *state);
 
@@ -309,6 +312,32 @@ xfs_attr_set_args(
  }
 
  /*
+ * Return EEXIST if attr is found, or ENOATTR if not
+ */
+int
+xfs_has_attr(
+	struct xfs_da_args      *args)
+{
+	struct xfs_inode        *dp = args->dp;
+	struct xfs_buf		*bp;
+	int                     error;
+
+	if (!xfs_inode_hasattr(dp)) {
+		error = -ENOATTR;
+	} else if (dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) {
+		ASSERT(dp->i_afp->if_flags & XFS_IFINLINE);
+		error = xfs_shortform_has_attr(args, NULL, NULL);

fs/xfs/libxfs/xfs_attr.c xfs_attr_set_args( · line 339

Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10 -0
+	} else if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
+		error = xfs_leaf_has_attr(args, &bp);
+		xfs_trans_brelse(args->trans, bp);
+	} else {
+		error = xfs_attr_node_hasname(args, NULL);
+	}
+
+	return error;
+}
+

FWIW, I think it's preferable to include new functions like this with the first user. I'm a bit curious about the use of error codes here as opposed to returning a boolean. I could see being able to handle unexpected errors as a good reason for doing that, but taking a quick look ahead, it appears neither caller of xfs_has_attr() does so. ;)

Quoted 3 lines

(To be clear, I think keeping the function as is and fixing up the eventual callers to handle unexpected errors is probably the right thing to do.).

The new top level function actually doesnt get used until patch 18, but I guess I try to keep the patch sizes small to make them easier for people to review. Basically we use it to see if there is/isnt an attribute present, and then return the appropriate error code right away. IE, trying to remove an attribute that isnt there immediately return EENOATTR rather than trying to start a delayed operation that isnt going to be successful. The is because delayed operations are not supposed to return error codes. If they do, they cause a shut down, which is not correct here.

Initially I think I had it returning booleans, but it means the top level function needs to do extra handling to translate the error codes, and I thought it looked messy. So I decided to stick with the scheme that the rest of the code was using.

I skipped ahead about unexpected error codes and see what you mean, so I will add some extra handlers there.

Quoted 16 lines
Quoted 16 lines
fs/xfs/libxfs/xfs_attr.c +2 -1
+/*
   * Remove the attribute specified in @args.
   */
  int
@@ -574,26 +603,17 @@ STATIC int
  xfs_attr_leaf_addname(
  	struct xfs_da_args	*args)
  {
-	struct xfs_inode	*dp;
  	struct xfs_buf		*bp;
  	int			retval, error, forkoff;
+	struct xfs_inode	*dp = args->dp;
 
  	trace_xfs_attr_leaf_addname(args);
 
Quoted 14 lines

fs/xfs/libxfs/xfs_attr.c STATIC int · line 591

Quoted 9 lines
fs/xfs/libxfs/xfs_attr.c +0 -8
  	/*
-	 * Read the (only) block in the attribute list in.
-	 */
-	dp = args->dp;
-	args->blkno = 0;
-	error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno, -1, &bp);
-	if (error)
-		return error;
-

It looks like we lose this unexpected error check here (i.e. suppose we got -ENOMEM or -EFSCORRUPTED or something that indicates we shouldn't continue). FWIW, this seems to repeat throughout this patch where we've invoked the new helpers..

Ok, I'll add in an explicit check for (retval != -ENOATTR && retval != -EEXIST)

Quoted 13 lines
Quoted 13 lines
fs/xfs/libxfs/xfs_attr.c +1 -2
-	/*
  	 * Look up the given attribute in the leaf block.  Figure out if
  	 * the given flags produce an error or call for an atomic rename.
  	 */
-	retval = xfs_attr3_leaf_lookup_int(bp, args);
+	retval = xfs_leaf_has_attr(args, &bp);
  	if ((args->name.type & ATTR_REPLACE) && (retval == -ENOATTR)) {
  		xfs_trans_brelse(args->trans, bp);
  		return retval;
@@ -745,6 +765,25 @@ xfs_attr_leaf_addname(
  }
 
Quoted 15 lines

fs/xfs/libxfs/xfs_attr.c xfs_attr_leaf_addname( · line 777

Quoted 11 lines
fs/xfs/libxfs/xfs_attr.c +10 -0
  /*
+ * Return EEXIST if attr is found, or ENOATTR if not
+ */
+STATIC int
+xfs_leaf_has_attr(
+	struct xfs_da_args      *args,
+	struct xfs_buf		**bp)
+{
+	int                     error = 0;
+
+	args->blkno = 0;

This seems misplaced for a helper, but I could be missing context. Why not just pass zero directly and leave the args->blkno assignment to the caller?

I guess just I kept these two lines together since that's was how they initially appeared before factoring them out, but it does look a bit off. It should be ok leave the assignment to the caller. I can push it back up.

Quoted 34 lines
Quoted 14 lines
fs/xfs/libxfs/xfs_attr.c +9 -0
+	error = xfs_attr3_leaf_read(args->trans, args->dp,
+			args->blkno, XFS_DABUF_MAP_NOMAPPING, bp);
+	if (error)
+		return error;
+
+	return xfs_attr3_leaf_lookup_int(*bp, args);
+}
+
+/*
   * Remove a name from the leaf attribute list structure
   *
   * This leaf block cannot have a "remote" value, we only call this routine

fs/xfs/libxfs/xfs_attr.c xfs_attr_leaf_removename( · line 770

Quoted 7 lines
fs/xfs/libxfs/xfs_attr.c +0 -4
@@ -764,12 +803,8 @@ xfs_attr_leaf_removename(
  	 * Remove the attribute.
  	 */
  	dp = args->dp;
-	args->blkno = 0;
-	error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno, -1, &bp);
-	if (error)
-		return error;

Lost error check.

Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +1 -1
-	error = xfs_attr3_leaf_lookup_int(bp, args);
+	error = xfs_leaf_has_attr(args, &bp);
  	if (error == -ENOATTR) {
  		xfs_trans_brelse(args->trans, bp);
  		return error;
@@ -808,12 +843,7 @@ xfs_attr_leaf_get(xfs_da_args_t *args)
 
  	trace_xfs_attr_leaf_get(args);
 
Quoted 7 lines

fs/xfs/libxfs/xfs_attr.c STATIC int · line 591

Quoted 5 lines
fs/xfs/libxfs/xfs_attr.c +0 -5
-	args->blkno = 0;
-	error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno, -1, &bp);
-	if (error)
-		return error;
-

^ here too. Not sure if I caught them all, but you get the idea. ;)

Ok,I'll sweep through and find them :-)

Quoted 29 lines
Quoted 29 lines
fs/xfs/libxfs/xfs_attr.c +20 -1
-	error = xfs_attr3_leaf_lookup_int(bp, args);
+	error = xfs_leaf_has_attr(args, &bp);
  	if (error != -EEXIST)  {
  		xfs_trans_brelse(args->trans, bp);
  		return error;
@@ -823,6 +853,43 @@ xfs_attr_leaf_get(xfs_da_args_t *args)
  	return error;
  }
 
+/*
+ * Return EEXIST if attr is found, or ENOATTR if not
+ * statep: If not null is set to point at the found state.  Caller will
+ * 	   be responsible for freeing the state in this case.
+ */
+STATIC int
+xfs_attr_node_hasname(
+	struct xfs_da_args	*args,
+	struct xfs_da_state	**statep)
+{
+	struct xfs_da_state	*state;
+	struct xfs_inode	*dp;
+	int			retval, error;
+
+	/*
+	 * Tie a string around our finger to remind us where we are.
+	 */
+	dp = args->dp;
+	state = xfs_da_state_alloc();
Quoted 8 lines

fs/xfs/libxfs/xfs_attr.c xfs_attr_leaf_get(xfs_da_args_t *args) · line 877

Quoted 3 lines
fs/xfs/libxfs/xfs_attr.c +3 -0
+	state->args = args;
+	state->mp = dp->i_mount;
+

No real need for the dp local variable here if it's just to reference ->i_mount. Also I know that comment isn't introduced by this patch, but any idea what it actually means? It doesn't make much sense to me at a glance. :P

Ok, will clean out assignment. I'm actually not sure as to the comments origins either, I assumed it was in reference the the state? I suppose state is used to keep track of a lot of things going on in the calling function. But even in that context, I don't find the comment particularly descriptive. Should I clean it out?

Quoted 159 lines
Quoted 23 lines
fs/xfs/libxfs/xfs_attr.c +15 -0
+	/*
+	 * Search to see if name exists, and get back a pointer to it.
+	 */
+	error = xfs_da3_node_lookup_int(state, &retval);
+	if (error == 0)
+		error = retval;
+
+	if (statep != NULL)
+		*statep = state;
+	else
+		xfs_da_state_free(state);
+
+	return error;
+}
+
  /*========================================================================
   * External routines when attribute list size > geo->blksize
   *========================================================================*/
@@ -855,17 +922,14 @@ xfs_attr_node_addname(
  	dp = args->dp;
  	mp = dp->i_mount;
  restart:

fs/xfs/libxfs/xfs_attr.c xfs_attr_node_addname( · line 867

Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +0 -6
-	state = xfs_da_state_alloc();
-	state->args = args;
-	state->mp = mp;
-
  	/*
  	 * Search to see if name already exists, and get back a pointer
  	 * to where it should go.
  	 */
-	error = xfs_da3_node_lookup_int(state, &retval);
-	if (error)

Error check again.

Quoted 123 lines
fs/xfs/libxfs/xfs_attr.c +8 -25
+	error = xfs_attr_node_hasname(args, &state);
+	if (error == -EEXIST)
  		goto out;
+
  	blk = &state->path.blk[ state->path.active-1 ];
  	ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
  	if ((args->name.type & ATTR_REPLACE) && (retval == -ENOATTR)) {
@@ -1070,29 +1134,15 @@ xfs_attr_node_removename(
  {
  	struct xfs_da_state	*state;
  	struct xfs_da_state_blk	*blk;
-	struct xfs_inode	*dp;
  	struct xfs_buf		*bp;
  	int			retval, error, forkoff;
+	struct xfs_inode	*dp = args->dp;
 
  	trace_xfs_attr_node_removename(args);
 
-	/*
-	 * Tie a string around our finger to remind us where we are.
-	 */
-	dp = args->dp;
-	state = xfs_da_state_alloc();
-	state->args = args;
-	state->mp = dp->i_mount;
-
-	/*
-	 * Search to see if name exists, and get back a pointer to it.
-	 */
-	error = xfs_da3_node_lookup_int(state, &retval);
-	if (error || (retval != -EEXIST)) {
-		if (error == 0)
-			error = retval;
+	error = xfs_attr_node_hasname(args, &state);
+	if (error != -EEXIST)
  		goto out;
-	}
 
  	/*
  	 * If there is an out-of-line value, de-allocate the blocks.
@@ -1314,20 +1364,14 @@ xfs_attr_node_get(xfs_da_args_t *args)
 
  	trace_xfs_attr_node_get(args);
 
-	state = xfs_da_state_alloc();
-	state->args = args;
-	state->mp = args->dp->i_mount;
-
  	/*
  	 * Search to see if name exists, and get back a pointer to it.
  	 */
-	error = xfs_da3_node_lookup_int(state, &retval);
-	if (error) {
+	error = xfs_attr_node_hasname(args, &state);
+	if (error != -EEXIST) {
  		retval = error;
  		goto out_release;
  	}
-	if (retval != -EEXIST)
-		goto out_release;
 
  	/*
  	 * Get the value, local or "remote"
fs/xfs/libxfs/xfs_attr.h +1 -0
index cedb4e2..fb56d81 100644
@@ -150,6 +150,7 @@ int xfs_attr_set(struct xfs_inode *dp, struct xfs_name *name,
  		 unsigned char *value, int valuelen);
  int xfs_attr_set_args(struct xfs_da_args *args);
  int xfs_attr_remove(struct xfs_inode *dp, struct xfs_name *name);
+int xfs_has_attr(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 flags, struct attrlist_cursor_kern *cursor);
fs/xfs/libxfs/xfs_attr_leaf.c +40 -0
index 07ce320..a501538 100644
@@ -590,6 +590,53 @@ xfs_attr_shortform_create(xfs_da_args_t *args)
  }
 
  /*
+ * Return EEXIST if attr is found, or ENOATTR if not
+ * args:  args containing attribute name and namelen
+ * sfep:  If not null, pointer will be set to the last attr entry found
+ * basep: If not null, pointer is set to the byte offset of the entry in the
+ *	  list
+ */
+int
+xfs_shortform_has_attr(
+	struct xfs_da_args	 *args,
+	struct xfs_attr_sf_entry **sfep,
+	int			 *basep)
+{
+	struct xfs_attr_shortform *sf;
+	struct xfs_attr_sf_entry *sfe;
+	int			base = sizeof(struct xfs_attr_sf_hdr);
+	int			size = 0;
+	int			end;
+	int			i;
+
+	base = sizeof(struct xfs_attr_sf_hdr);
+	sf = (struct xfs_attr_shortform *)args->dp->i_afp->if_u1.if_data;
+	sfe = &sf->list[0];
+	end = sf->hdr.count;
+	for (i = 0; i < end; sfe = XFS_ATTR_SF_NEXTENTRY(sfe),
+			base += size, i++) {
+		size = XFS_ATTR_SF_ENTSIZE(sfe);
+		if (sfe->namelen != args->name.len)
+			continue;
+		if (memcmp(sfe->nameval, args->name.name, args->name.len) != 0)
+			continue;
+		if (!xfs_attr_namesp_match(args->name.type, sfe->flags))
+			continue;
+		break;
+	}
+
+	if (sfep != NULL)
+		*sfep = sfe;
+
+	if (basep != NULL)
+		*basep = base;
Quoted 8 lines

fs/xfs/libxfs/xfs_attr_leaf.c xfs_attr_shortform_create(xfs_da_args_t *args) · line 636

Quoted 4 lines
fs/xfs/libxfs/xfs_attr_leaf.c +4 -0
+
+	if (i == end)
+		return -ENOATTR;
+	return -EEXIST;

This function seems like it could just return a bool. Eh, I suppose it's better to be consistent with the other variants if those ones can return unrelated errors.

Ok, I prefer the consistency as well.

Quoted 10 lines
Quoted 10 lines
fs/xfs/libxfs/xfs_attr_leaf.c +3 -0
+}
+
+/*
   * Add a name/value pair to the shortform attribute list.
   * Overflow from the inode has already been checked for.
   */
@@ -598,7 +645,7 @@ xfs_attr_shortform_add(xfs_da_args_t *args, int forkoff)
  {
  	xfs_attr_shortform_t *sf;
Quoted 8 lines

fs/xfs/libxfs/xfs_attr_leaf.c xfs_attr_shortform_add(xfs_da_args_t *args, int forkoff) · line 650

Quoted 5 lines
fs/xfs/libxfs/xfs_attr_leaf.c +1 -1
  	xfs_attr_sf_entry_t *sfe;
-	int i, offset, size;
+	int offset, size, error;
  	xfs_mount_t *mp;
  	xfs_inode_t *dp;

Nit: might be good to clean up the typedefs here since you do it in the remove function as well.

Sure, will do.

Quoted 29 lines
Quoted 9 lines
fs/xfs/libxfs/xfs_attr_leaf.c +1 -2
  	struct xfs_ifork *ifp;
@@ -612,18 +659,10 @@ xfs_attr_shortform_add(xfs_da_args_t *args, int forkoff)
  	ifp = dp->i_afp;
  	ASSERT(ifp->if_flags & XFS_IFINLINE);
  	sf = (xfs_attr_shortform_t *)ifp->if_u1.if_data;
-	sfe = &sf->list[0];
-	for (i = 0; i < sf->hdr.count; sfe = XFS_ATTR_SF_NEXTENTRY(sfe), i++) {
+	error = xfs_shortform_has_attr(args, &sfe, NULL);

fs/xfs/libxfs/xfs_attr_leaf.c xfs_attr_shortform_add(xfs_da_args_t *args, int forkoff) · line 665

Quoted 10 lines
fs/xfs/libxfs/xfs_attr_leaf.c +1 -7
  #ifdef DEBUG
-		if (sfe->namelen != args->name.len)
-			continue;
-		if (memcmp(args->name.name, sfe->nameval, args->name.len) != 0)
-			continue;
-		if (!xfs_attr_namesp_match(args->name.type, sfe->flags))
-			continue;
-		ASSERT(0);
+	ASSERT(error != -EEXIST);
  #endif

Hmm, interesting. So basically this code walks to the end of the list for the purpose of placement of the new attr and the debug code simply asserts that we don't find an existing attr. The only thing that concerns me is that nothing about xfs_shortform_has_attr() indicates that the output values are important when the lookup fails. The comment only explains what the values are when a lookup succeeds. Could we update the comment to elaborate on this use case to prevent somebody from unknowingly breaking it down the road?

Quoted 2 lines

Also, there's no need for the #ifdef DEBUG any more with just the assert check in that block.

Sure, I will clearify the comments and pull out the DEBUG

Quoted 33 lines
Quoted 19 lines
fs/xfs/libxfs/xfs_attr_leaf.c +5 -6
-	}
 
  	offset = (char *)sfe - (char *)sf;
  	size = XFS_ATTR_SF_ENTSIZE_BYNAME(args->name.len, args->valuelen);
@@ -668,33 +707,24 @@ xfs_attr_fork_remove(
  int
  xfs_attr_shortform_remove(xfs_da_args_t *args)
  {
-	xfs_attr_shortform_t *sf;
-	xfs_attr_sf_entry_t *sfe;
-	int base, size=0, end, totsize, i;
-	xfs_mount_t *mp;
-	xfs_inode_t *dp;
+	struct xfs_attr_shortform	*sf;
+	struct xfs_attr_sf_entry	*sfe;
+	int				base, size = 0, end, totsize;
+	struct xfs_mount		*mp;
+	struct xfs_inode		*dp;

fs/xfs/libxfs/xfs_attr_leaf.c xfs_attr_fork_remove( · line 722

Quoted 10 lines
fs/xfs/libxfs/xfs_attr_leaf.c +1 -2
+	int				error;
 
  	trace_xfs_attr_sf_remove(args);
 
  	dp = args->dp;
  	mp = dp->i_mount;
-	base = sizeof(xfs_attr_sf_hdr_t);
  	sf = (xfs_attr_shortform_t *)dp->i_afp->if_u1.if_data;
-	sfe = &sf->list[0];
  	end = sf->hdr.count;

This value of end is unused (end is immediately reassigned further down in the function).

Quoted 1 line

Brian

Ok, I will pick that out. Thank you for the thorough reviews!

Allison

Quoted 38 lines
Quoted 38 lines
fs/xfs/libxfs/xfs_attr_leaf.c +5 -13
-	for (i = 0; i < end; sfe = XFS_ATTR_SF_NEXTENTRY(sfe),
-					base += size, i++) {
-		size = XFS_ATTR_SF_ENTSIZE(sfe);
-		if (sfe->namelen != args->name.len)
-			continue;
-		if (memcmp(sfe->nameval, args->name.name, args->name.len) != 0)
-			continue;
-		if (!xfs_attr_namesp_match(args->name.type, sfe->flags))
-			continue;
-		break;
-	}
-	if (i == end)
-		return -ENOATTR;
+
+	error = xfs_shortform_has_attr(args, &sfe, &base);
+	if (error == -ENOATTR)
+		return error;
+	size = XFS_ATTR_SF_ENTSIZE(sfe);
 
  	/*
  	 * Fix up the attribute fork data, covering the hole
fs/xfs/libxfs/xfs_attr_leaf.h +2 -0
index 536a290..58e9327 100644
@@ -42,6 +42,8 @@ int	xfs_attr_shortform_getvalue(struct xfs_da_args *args);
  int	xfs_attr_shortform_to_leaf(struct xfs_da_args *args,
  			struct xfs_buf **leaf_bp);
  int	xfs_attr_shortform_remove(struct xfs_da_args *args);
+int	xfs_shortform_has_attr(struct xfs_da_args *args,
+			       struct xfs_attr_sf_entry **sfep, int *basep);
  int	xfs_attr_shortform_allfit(struct xfs_buf *bp, struct xfs_inode *dp);
  int	xfs_attr_shortform_bytesfit(struct xfs_inode *dp, int bytes);
  xfs_failaddr_t xfs_attr_shortform_verify(struct xfs_inode *ip);
Signature · 1 line
2.7.4
#16 lore raw

Re: [PATCH v3 04/19] xfs: Add xfs_has_attr and subroutines

Quoted 92 lines · Allison Collins
Quoted 11 lines · Brian Foster
Quoted 10 lines · Allison Collins

From: Allison Henderson <[email protected]>

This patch adds a new functions to check for the existence of an attribute. Subroutines are also added to handle the cases of leaf blocks, nodes or shortform. Common code that appears in existing attr add and remove functions have been factored out to help reduce the appearence of duplicated code. We will need these routines later for delayed attributes since delayed operations cannot return error codes.

Quoted 4 lines
Quoted 2 lines

Extra s-o-b tag?

Oops, I thought I had caught all the old names. Will clean out :-)

Quoted 8 lines
Quoted 8 lines
---
  fs/xfs/libxfs/xfs_attr.c      | 150 +++++++++++++++++++++++++++---------------
  fs/xfs/libxfs/xfs_attr.h      |   1 +
  fs/xfs/libxfs/xfs_attr_leaf.c |  92 +++++++++++++++++---------
  fs/xfs/libxfs/xfs_attr_leaf.h |   2 +
  4 files changed, 161 insertions(+), 84 deletions(-)
Quoted 13 lines

fs/xfs/libxfs/xfs_attr.c STATIC int xfs_attr_shortform_addname(xfs_da_args_t *args); · line 49

Quoted 9 lines
fs/xfs/libxfs/xfs_attr.c +1 -0
index 50e099f..a297857 100644
@@ -46,6 +46,7 @@ STATIC int xfs_attr_shortform_addname(xfs_da_args_t *args);
  STATIC int xfs_attr_leaf_get(xfs_da_args_t *args);
  STATIC int xfs_attr_leaf_addname(xfs_da_args_t *args);
  STATIC int xfs_attr_leaf_removename(xfs_da_args_t *args);
+STATIC int xfs_leaf_has_attr(struct xfs_da_args *args, struct xfs_buf **bp);

The fact that this is not named xfs_attr_leaf_*() kind of stands out here, particularly since the node variant uses the xfs_attr_* prefix. Hm? (Same goes for xfs_shortform_has_attr() I suppose..).

Sure, I can flip the prefixes around to look a little more consistent

Quoted 46 lines
Quoted 29 lines
fs/xfs/libxfs/xfs_attr.c +17 -0
  /*
   * Internal routines when attribute list is more than one block.
@@ -53,6 +54,8 @@ STATIC int xfs_attr_leaf_removename(xfs_da_args_t *args);
  STATIC int xfs_attr_node_get(xfs_da_args_t *args);
  STATIC int xfs_attr_node_addname(xfs_da_args_t *args);
  STATIC int xfs_attr_node_removename(xfs_da_args_t *args);
+STATIC int xfs_attr_node_hasname(xfs_da_args_t *args,
+				 struct xfs_da_state **state);
  STATIC int xfs_attr_fillstate(xfs_da_state_t *state);
  STATIC int xfs_attr_refillstate(xfs_da_state_t *state);
@@ -309,6 +312,32 @@ xfs_attr_set_args(
  }
  /*
+ * Return EEXIST if attr is found, or ENOATTR if not
+ */
+int
+xfs_has_attr(
+	struct xfs_da_args      *args)
+{
+	struct xfs_inode        *dp = args->dp;
+	struct xfs_buf		*bp;
+	int                     error;
+
+	if (!xfs_inode_hasattr(dp)) {
+		error = -ENOATTR;
+	} else if (dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) {
+		ASSERT(dp->i_afp->if_flags & XFS_IFINLINE);
+		error = xfs_shortform_has_attr(args, NULL, NULL);

fs/xfs/libxfs/xfs_attr.c xfs_attr_set_args( · line 338

Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10 -0
+	} else if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
+		error = xfs_leaf_has_attr(args, &bp);
+		xfs_trans_brelse(args->trans, bp);
+	} else {
+		error = xfs_attr_node_hasname(args, NULL);
+	}
+
+	return error;
+}
+

FWIW, I think it's preferable to include new functions like this with the first user. I'm a bit curious about the use of error codes here as opposed to returning a boolean. I could see being able to handle unexpected errors as a good reason for doing that, but taking a quick look ahead, it appears neither caller of xfs_has_attr() does so. ;)

Quoted 3 lines

(To be clear, I think keeping the function as is and fixing up the eventual callers to handle unexpected errors is probably the right thing to do.).

Quoted 9 lines

The new top level function actually doesnt get used until patch 18, but I guess I try to keep the patch sizes small to make them easier for people to review. Basically we use it to see if there is/isnt an attribute present, and then return the appropriate error code right away. IE, trying to remove an attribute that isnt there immediately return EENOATTR rather than trying to start a delayed operation that isnt going to be successful. The is because delayed operations are not supposed to return error codes. If they do, they cause a shut down, which is not correct here.

Makes sense. It might be fine to leave the associated refactoring and just defer the new helper to the later patch, fwiw.

Quoted 5 lines

Initially I think I had it returning booleans, but it means the top level function needs to do extra handling to translate the error codes, and I thought it looked messy. So I decided to stick with the scheme that the rest of the code was using.

Yeah, it's strange at first, but seems prevalent throughout the xattr code. Perhaps that's something we can clean up a bit down the road.

Quoted 144 lines

I skipped ahead about unexpected error codes and see what you mean, so I will add some extra handlers there.

Quoted 20 lines
Quoted 20 lines
fs/xfs/libxfs/xfs_attr.c +2 -6
+/*
   * Remove the attribute specified in @args.
   */
  int
@@ -574,26 +603,17 @@ STATIC int
  xfs_attr_leaf_addname(
  	struct xfs_da_args	*args)
  {
-	struct xfs_inode	*dp;
  	struct xfs_buf		*bp;
  	int			retval, error, forkoff;
+	struct xfs_inode	*dp = args->dp;
  	trace_xfs_attr_leaf_addname(args);
  	/*
-	 * Read the (only) block in the attribute list in.
-	 */
-	dp = args->dp;
-	args->blkno = 0;
-	error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno, -1, &bp);
Quoted 8 lines

fs/xfs/libxfs/xfs_attr.c STATIC int · line 591

Quoted 3 lines
fs/xfs/libxfs/xfs_attr.c +0 -3
-	if (error)
-		return error;
-

It looks like we lose this unexpected error check here (i.e. suppose we got -ENOMEM or -EFSCORRUPTED or something that indicates we shouldn't continue). FWIW, this seems to repeat throughout this patch where we've invoked the new helpers..

Ok, I'll add in an explicit check for (retval != -ENOATTR && retval != -EEXIST)

Quoted 19 lines
Quoted 19 lines
fs/xfs/libxfs/xfs_attr.c +7 -2
-	/*
  	 * Look up the given attribute in the leaf block.  Figure out if
  	 * the given flags produce an error or call for an atomic rename.
  	 */
-	retval = xfs_attr3_leaf_lookup_int(bp, args);
+	retval = xfs_leaf_has_attr(args, &bp);
  	if ((args->name.type & ATTR_REPLACE) && (retval == -ENOATTR)) {
  		xfs_trans_brelse(args->trans, bp);
  		return retval;
@@ -745,6 +765,25 @@ xfs_attr_leaf_addname(
  }
  /*
+ * Return EEXIST if attr is found, or ENOATTR if not
+ */
+STATIC int
+xfs_leaf_has_attr(
+	struct xfs_da_args      *args,
+	struct xfs_buf		**bp)
Quoted 8 lines

fs/xfs/libxfs/xfs_attr.c xfs_attr_leaf_addname( · line 777

Quoted 4 lines
fs/xfs/libxfs/xfs_attr.c +4 -0
+{
+	int                     error = 0;
+
+	args->blkno = 0;

This seems misplaced for a helper, but I could be missing context. Why not just pass zero directly and leave the args->blkno assignment to the caller?

I guess just I kept these two lines together since that's was how they initially appeared before factoring them out, but it does look a bit off. It should be ok leave the assignment to the caller. I can push it back up.

Quoted 24 lines
Quoted 14 lines
fs/xfs/libxfs/xfs_attr.c +9 -0
+	error = xfs_attr3_leaf_read(args->trans, args->dp,
+			args->blkno, XFS_DABUF_MAP_NOMAPPING, bp);
+	if (error)
+		return error;
+
+	return xfs_attr3_leaf_lookup_int(*bp, args);
+}
+
+/*
   * Remove a name from the leaf attribute list structure
   *
   * This leaf block cannot have a "remote" value, we only call this routine

fs/xfs/libxfs/xfs_attr.c xfs_attr_leaf_removename( · line 770

Quoted 7 lines
fs/xfs/libxfs/xfs_attr.c +0 -4
@@ -764,12 +803,8 @@ xfs_attr_leaf_removename(
  	 * Remove the attribute.
  	 */
  	dp = args->dp;
-	args->blkno = 0;
-	error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno, -1, &bp);
-	if (error)
-		return error;

Lost error check.

Quoted 14 lines

fs/xfs/libxfs/xfs_attr.c xfs_attr_leaf_get(xfs_da_args_t *args) · line 813

Quoted 12 lines
fs/xfs/libxfs/xfs_attr.c +1 -6
-	error = xfs_attr3_leaf_lookup_int(bp, args);
+	error = xfs_leaf_has_attr(args, &bp);
  	if (error == -ENOATTR) {
  		xfs_trans_brelse(args->trans, bp);
  		return error;
@@ -808,12 +843,7 @@ xfs_attr_leaf_get(xfs_da_args_t *args)
  	trace_xfs_attr_leaf_get(args);
-	args->blkno = 0;
-	error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno, -1, &bp);
-	if (error)
-		return error;
-

^ here too. Not sure if I caught them all, but you get the idea. ;)

Ok,I'll sweep through and find them :-)

Quoted 28 lines
Quoted 28 lines
fs/xfs/libxfs/xfs_attr.c +20 -1
-	error = xfs_attr3_leaf_lookup_int(bp, args);
+	error = xfs_leaf_has_attr(args, &bp);
  	if (error != -EEXIST)  {
  		xfs_trans_brelse(args->trans, bp);
  		return error;
@@ -823,6 +853,43 @@ xfs_attr_leaf_get(xfs_da_args_t *args)
  	return error;
  }
+/*
+ * Return EEXIST if attr is found, or ENOATTR if not
+ * statep: If not null is set to point at the found state.  Caller will
+ * 	   be responsible for freeing the state in this case.
+ */
+STATIC int
+xfs_attr_node_hasname(
+	struct xfs_da_args	*args,
+	struct xfs_da_state	**statep)
+{
+	struct xfs_da_state	*state;
+	struct xfs_inode	*dp;
+	int			retval, error;
+
+	/*
+	 * Tie a string around our finger to remind us where we are.
+	 */
+	dp = args->dp;
+	state = xfs_da_state_alloc();
Quoted 8 lines

fs/xfs/libxfs/xfs_attr.c xfs_attr_leaf_get(xfs_da_args_t *args) · line 877

Quoted 3 lines
fs/xfs/libxfs/xfs_attr.c +3 -0
+	state->args = args;
+	state->mp = dp->i_mount;
+

No real need for the dp local variable here if it's just to reference ->i_mount. Also I know that comment isn't introduced by this patch, but any idea what it actually means? It doesn't make much sense to me at a glance. :P

Quoted 6 lines

Ok, will clean out assignment. I'm actually not sure as to the comments origins either, I assumed it was in reference the the state? I suppose state is used to keep track of a lot of things going on in the calling function. But even in that context, I don't find the comment particularly descriptive. Should I clean it out?

Unless somebody can chime in and explain what it means (so perhaps we could reword it), I'd probably just remove it.

Brian

Quoted 289 lines
Quoted 152 lines
Quoted 23 lines
fs/xfs/libxfs/xfs_attr.c +15 -0
+	/*
+	 * Search to see if name exists, and get back a pointer to it.
+	 */
+	error = xfs_da3_node_lookup_int(state, &retval);
+	if (error == 0)
+		error = retval;
+
+	if (statep != NULL)
+		*statep = state;
+	else
+		xfs_da_state_free(state);
+
+	return error;
+}
+
  /*========================================================================
   * External routines when attribute list size > geo->blksize
   *========================================================================*/
@@ -855,17 +922,14 @@ xfs_attr_node_addname(
  	dp = args->dp;
  	mp = dp->i_mount;
  restart:

fs/xfs/libxfs/xfs_attr.c xfs_attr_node_addname( · line 867

Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +0 -6
-	state = xfs_da_state_alloc();
-	state->args = args;
-	state->mp = mp;
-
  	/*
  	 * Search to see if name already exists, and get back a pointer
  	 * to where it should go.
  	 */
-	error = xfs_da3_node_lookup_int(state, &retval);
-	if (error)

Error check again.

Quoted 116 lines
fs/xfs/libxfs/xfs_attr.c +8 -25
+	error = xfs_attr_node_hasname(args, &state);
+	if (error == -EEXIST)
  		goto out;
+
  	blk = &state->path.blk[ state->path.active-1 ];
  	ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
  	if ((args->name.type & ATTR_REPLACE) && (retval == -ENOATTR)) {
@@ -1070,29 +1134,15 @@ xfs_attr_node_removename(
  {
  	struct xfs_da_state	*state;
  	struct xfs_da_state_blk	*blk;
-	struct xfs_inode	*dp;
  	struct xfs_buf		*bp;
  	int			retval, error, forkoff;
+	struct xfs_inode	*dp = args->dp;
  	trace_xfs_attr_node_removename(args);
-	/*
-	 * Tie a string around our finger to remind us where we are.
-	 */
-	dp = args->dp;
-	state = xfs_da_state_alloc();
-	state->args = args;
-	state->mp = dp->i_mount;
-
-	/*
-	 * Search to see if name exists, and get back a pointer to it.
-	 */
-	error = xfs_da3_node_lookup_int(state, &retval);
-	if (error || (retval != -EEXIST)) {
-		if (error == 0)
-			error = retval;
+	error = xfs_attr_node_hasname(args, &state);
+	if (error != -EEXIST)
  		goto out;
-	}
  	/*
  	 * If there is an out-of-line value, de-allocate the blocks.
@@ -1314,20 +1364,14 @@ xfs_attr_node_get(xfs_da_args_t *args)
  	trace_xfs_attr_node_get(args);
-	state = xfs_da_state_alloc();
-	state->args = args;
-	state->mp = args->dp->i_mount;
-
  	/*
  	 * Search to see if name exists, and get back a pointer to it.
  	 */
-	error = xfs_da3_node_lookup_int(state, &retval);
-	if (error) {
+	error = xfs_attr_node_hasname(args, &state);
+	if (error != -EEXIST) {
  		retval = error;
  		goto out_release;
  	}
-	if (retval != -EEXIST)
-		goto out_release;
  	/*
  	 * Get the value, local or "remote"
fs/xfs/libxfs/xfs_attr.h +1 -0
index cedb4e2..fb56d81 100644
@@ -150,6 +150,7 @@ int xfs_attr_set(struct xfs_inode *dp, struct xfs_name *name,
  		 unsigned char *value, int valuelen);
  int xfs_attr_set_args(struct xfs_da_args *args);
  int xfs_attr_remove(struct xfs_inode *dp, struct xfs_name *name);
+int xfs_has_attr(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 flags, struct attrlist_cursor_kern *cursor);
fs/xfs/libxfs/xfs_attr_leaf.c +40 -0
index 07ce320..a501538 100644
@@ -590,6 +590,53 @@ xfs_attr_shortform_create(xfs_da_args_t *args)
  }
  /*
+ * Return EEXIST if attr is found, or ENOATTR if not
+ * args:  args containing attribute name and namelen
+ * sfep:  If not null, pointer will be set to the last attr entry found
+ * basep: If not null, pointer is set to the byte offset of the entry in the
+ *	  list
+ */
+int
+xfs_shortform_has_attr(
+	struct xfs_da_args	 *args,
+	struct xfs_attr_sf_entry **sfep,
+	int			 *basep)
+{
+	struct xfs_attr_shortform *sf;
+	struct xfs_attr_sf_entry *sfe;
+	int			base = sizeof(struct xfs_attr_sf_hdr);
+	int			size = 0;
+	int			end;
+	int			i;
+
+	base = sizeof(struct xfs_attr_sf_hdr);
+	sf = (struct xfs_attr_shortform *)args->dp->i_afp->if_u1.if_data;
+	sfe = &sf->list[0];
+	end = sf->hdr.count;
+	for (i = 0; i < end; sfe = XFS_ATTR_SF_NEXTENTRY(sfe),
+			base += size, i++) {
+		size = XFS_ATTR_SF_ENTSIZE(sfe);
+		if (sfe->namelen != args->name.len)
+			continue;
+		if (memcmp(sfe->nameval, args->name.name, args->name.len) != 0)
+			continue;
+		if (!xfs_attr_namesp_match(args->name.type, sfe->flags))
+			continue;
+		break;
+	}
+
+	if (sfep != NULL)
+		*sfep = sfe;
+
+	if (basep != NULL)
+		*basep = base;
Quoted 8 lines

fs/xfs/libxfs/xfs_attr_leaf.c xfs_attr_shortform_create(xfs_da_args_t *args) · line 636

Quoted 4 lines
fs/xfs/libxfs/xfs_attr_leaf.c +4 -0
+
+	if (i == end)
+		return -ENOATTR;
+	return -EEXIST;

This function seems like it could just return a bool. Eh, I suppose it's better to be consistent with the other variants if those ones can return unrelated errors.

Ok, I prefer the consistency as well.

Quoted 10 lines
Quoted 10 lines
fs/xfs/libxfs/xfs_attr_leaf.c +3 -0
+}
+
+/*
   * Add a name/value pair to the shortform attribute list.
   * Overflow from the inode has already been checked for.
   */
@@ -598,7 +645,7 @@ xfs_attr_shortform_add(xfs_da_args_t *args, int forkoff)
  {
  	xfs_attr_shortform_t *sf;
Quoted 8 lines

fs/xfs/libxfs/xfs_attr_leaf.c xfs_attr_shortform_add(xfs_da_args_t *args, int forkoff) · line 650

Quoted 5 lines
fs/xfs/libxfs/xfs_attr_leaf.c +1 -1
  	xfs_attr_sf_entry_t *sfe;
-	int i, offset, size;
+	int offset, size, error;
  	xfs_mount_t *mp;
  	xfs_inode_t *dp;

Nit: might be good to clean up the typedefs here since you do it in the remove function as well.

Sure, will do.

Quoted 29 lines
Quoted 9 lines
fs/xfs/libxfs/xfs_attr_leaf.c +1 -2
  	struct xfs_ifork *ifp;
@@ -612,18 +659,10 @@ xfs_attr_shortform_add(xfs_da_args_t *args, int forkoff)
  	ifp = dp->i_afp;
  	ASSERT(ifp->if_flags & XFS_IFINLINE);
  	sf = (xfs_attr_shortform_t *)ifp->if_u1.if_data;
-	sfe = &sf->list[0];
-	for (i = 0; i < sf->hdr.count; sfe = XFS_ATTR_SF_NEXTENTRY(sfe), i++) {
+	error = xfs_shortform_has_attr(args, &sfe, NULL);

fs/xfs/libxfs/xfs_attr_leaf.c xfs_attr_shortform_add(xfs_da_args_t *args, int forkoff) · line 665

Quoted 10 lines
fs/xfs/libxfs/xfs_attr_leaf.c +1 -7
  #ifdef DEBUG
-		if (sfe->namelen != args->name.len)
-			continue;
-		if (memcmp(args->name.name, sfe->nameval, args->name.len) != 0)
-			continue;
-		if (!xfs_attr_namesp_match(args->name.type, sfe->flags))
-			continue;
-		ASSERT(0);
+	ASSERT(error != -EEXIST);
  #endif

Hmm, interesting. So basically this code walks to the end of the list for the purpose of placement of the new attr and the debug code simply asserts that we don't find an existing attr. The only thing that concerns me is that nothing about xfs_shortform_has_attr() indicates that the output values are important when the lookup fails. The comment only explains what the values are when a lookup succeeds. Could we update the comment to elaborate on this use case to prevent somebody from unknowingly breaking it down the road?

Quoted 2 lines

Also, there's no need for the #ifdef DEBUG any more with just the assert check in that block.

Sure, I will clearify the comments and pull out the DEBUG

Quoted 30 lines
Quoted 16 lines
fs/xfs/libxfs/xfs_attr_leaf.c +3 -6
-	}
  	offset = (char *)sfe - (char *)sf;
  	size = XFS_ATTR_SF_ENTSIZE_BYNAME(args->name.len, args->valuelen);
@@ -668,33 +707,24 @@ xfs_attr_fork_remove(
  int
  xfs_attr_shortform_remove(xfs_da_args_t *args)
  {
-	xfs_attr_shortform_t *sf;
-	xfs_attr_sf_entry_t *sfe;
-	int base, size=0, end, totsize, i;
-	xfs_mount_t *mp;
-	xfs_inode_t *dp;
+	struct xfs_attr_shortform	*sf;
+	struct xfs_attr_sf_entry	*sfe;
+	int				base, size = 0, end, totsize;

fs/xfs/libxfs/xfs_attr_leaf.c xfs_attr_fork_remove( · line 720

Quoted 10 lines
fs/xfs/libxfs/xfs_attr_leaf.c +3 -2
+	struct xfs_mount		*mp;
+	struct xfs_inode		*dp;
+	int				error;
  	trace_xfs_attr_sf_remove(args);
  	dp = args->dp;
  	mp = dp->i_mount;
-	base = sizeof(xfs_attr_sf_hdr_t);
  	sf = (xfs_attr_shortform_t *)dp->i_afp->if_u1.if_data;
-	sfe = &sf->list[0];
  	end = sf->hdr.count;

This value of end is unused (end is immediately reassigned further down in the function).

Quoted 1 line

Brian

Ok, I will pick that out. Thank you for the thorough reviews!

Allison

Quoted 37 lines
Quoted 37 lines
fs/xfs/libxfs/xfs_attr_leaf.c +5 -13
-	for (i = 0; i < end; sfe = XFS_ATTR_SF_NEXTENTRY(sfe),
-					base += size, i++) {
-		size = XFS_ATTR_SF_ENTSIZE(sfe);
-		if (sfe->namelen != args->name.len)
-			continue;
-		if (memcmp(sfe->nameval, args->name.name, args->name.len) != 0)
-			continue;
-		if (!xfs_attr_namesp_match(args->name.type, sfe->flags))
-			continue;
-		break;
-	}
-	if (i == end)
-		return -ENOATTR;
+
+	error = xfs_shortform_has_attr(args, &sfe, &base);
+	if (error == -ENOATTR)
+		return error;
+	size = XFS_ATTR_SF_ENTSIZE(sfe);
  	/*
  	 * Fix up the attribute fork data, covering the hole
fs/xfs/libxfs/xfs_attr_leaf.h +2 -0
index 536a290..58e9327 100644
@@ -42,6 +42,8 @@ int	xfs_attr_shortform_getvalue(struct xfs_da_args *args);
  int	xfs_attr_shortform_to_leaf(struct xfs_da_args *args,
  			struct xfs_buf **leaf_bp);
  int	xfs_attr_shortform_remove(struct xfs_da_args *args);
+int	xfs_shortform_has_attr(struct xfs_da_args *args,
+			       struct xfs_attr_sf_entry **sfep, int *basep);
  int	xfs_attr_shortform_allfit(struct xfs_buf *bp, struct xfs_inode *dp);
  int	xfs_attr_shortform_bytesfit(struct xfs_inode *dp, int bytes);
  xfs_failaddr_t xfs_attr_shortform_verify(struct xfs_inode *ip);
Signature · 1 line
2.7.4
#17 lore raw

PATCH v3 5/19 xfs: Factor out new helper functions xfs_attr_rmtval_set

In reply to Allison Collins

Break xfs_attr_rmtval_set into two helper functions xfs_attr_rmt_find_hole and xfs_attr_rmtval_set_value. xfs_attr_rmtval_set rolls the transaction between the helpers, but delayed operations cannot. We will use the helpers later when constructing new delayed attribute routines.

---
 fs/xfs/libxfs/xfs_attr_remote.c | 72 +++++++++++++++++++++++++++++++----------
 fs/xfs/libxfs/xfs_attr_remote.h |  3 +-
 2 files changed, 57 insertions(+), 18 deletions(-)
fs/xfs/libxfs/xfs_attr_remote.c +55 -17
index db9247a..080a284 100644
@@ -21,6 +21,7 @@
 #include "xfs_attr.h"
 #include "xfs_trace.h"
 #include "xfs_error.h"
+#include "xfs_attr_remote.h"
 
 #define ATTR_RMTVALUE_MAPSIZE	1	/* # of map entries at once */
 
@@ -432,34 +433,20 @@ xfs_attr_rmtval_set(
 	struct xfs_da_args	*args)
 {
 	struct xfs_inode	*dp = args->dp;
-	struct xfs_mount	*mp = dp->i_mount;
 	struct xfs_bmbt_irec	map;
 	xfs_dablk_t		lblkno;
-	xfs_fileoff_t		lfileoff = 0;
-	uint8_t			*src = args->value;
 	int			blkcnt;
-	int			valuelen;
 	int			nmap;
 	int			error;
-	int			offset = 0;
 
 	trace_xfs_attr_rmtval_set(args);
 
-	/*
-	 * Find a "hole" in the attribute address space large enough for
-	 * us to drop the new attribute's value into. Because CRC enable
-	 * attributes have headers, we can't just do a straight byte to FSB
-	 * conversion and have to take the header space into account.
-	 */
-	blkcnt = xfs_attr3_rmt_blocks(mp, args->rmtvaluelen);
-	error = xfs_bmap_first_unused(args->trans, args->dp, blkcnt, &lfileoff,
-						   XFS_ATTR_FORK);
+	error = xfs_attr_rmt_find_hole(args);
 	if (error)
 		return error;
 
-	args->rmtblkno = lblkno = (xfs_dablk_t)lfileoff;
-	args->rmtblkcnt = blkcnt;
-
+	blkcnt = args->rmtblkcnt;
+	lblkno = (xfs_dablk_t)args->rmtblkno;
 	/*
 	 * Roll through the "value", allocating blocks on disk as required.
 	 */
@@ -500,6 +487,57 @@ xfs_attr_rmtval_set(
 			return error;
 	}
 
+	error = xfs_attr_rmtval_set_value(args);
+	return error;
+}
+
+
+/*
+ * Find a "hole" in the attribute address space large enough for us to drop the
+ * new attribute's value into
+ */
+int
+xfs_attr_rmt_find_hole(
+	struct xfs_da_args	*args)
+{
+	struct xfs_inode        *dp = args->dp;
+	struct xfs_mount	*mp = dp->i_mount;
+	int			error;
+	int			blkcnt;
+	xfs_fileoff_t		lfileoff = args->rmtblkno;
+
+	/*
+	 * Because CRC enable attributes have headers, we can't just do a
+	 * straight byte to FSB conversion and have to take the header space
+	 * into account.
+	 */
+	blkcnt = xfs_attr3_rmt_blocks(mp, args->rmtvaluelen);
+	error = xfs_bmap_first_unused(args->trans, args->dp, blkcnt, &lfileoff,
+						   XFS_ATTR_FORK);
+	if (error)
+		return error;
+
+	args->rmtblkno = (xfs_dablk_t)lfileoff;
+	args->rmtblkcnt = blkcnt;
+
+	return 0;
+}
+
+int
+xfs_attr_rmtval_set_value(
+	struct xfs_da_args	*args)
+{
+	struct xfs_inode	*dp = args->dp;
+	struct xfs_mount	*mp = dp->i_mount;
+	struct xfs_bmbt_irec	map;
+	xfs_dablk_t		lblkno;
+	uint8_t			*src = args->value;
+	int			blkcnt;
+	int			valuelen;
+	int			nmap;
+	int			error;
+	int			offset = 0;
+
 	/*
 	 * Roll through the "value", copying the attribute value to the
 	 * already-allocated blocks.  Blocks are written synchronously
fs/xfs/libxfs/xfs_attr_remote.h +2 -1
index 9d20b66..cd7670d 100644
@@ -11,5 +11,6 @@ int xfs_attr3_rmt_blocks(struct xfs_mount *mp, int attrlen);
 int xfs_attr_rmtval_get(struct xfs_da_args *args);
 int xfs_attr_rmtval_set(struct xfs_da_args *args);
 int xfs_attr_rmtval_remove(struct xfs_da_args *args);
-
+int xfs_attr_rmtval_set_value(struct xfs_da_args *args);
+int xfs_attr_rmt_find_hole(struct xfs_da_args *args);
 #endif /* __XFS_ATTR_REMOTE_H__ */
Signature · 1 line
2.7.4
Reviewed-by on v3 5/19
#18 lore raw

Re: [PATCH v3 05/19] xfs: Factor out new helper functions xfs_attr_rmtval_set

Quoted 17 lines · Allison Collins

Break xfs_attr_rmtval_set into two helper functions xfs_attr_rmt_find_hole and xfs_attr_rmtval_set_value. xfs_attr_rmtval_set rolls the transaction between the helpers, but delayed operations cannot. We will use the helpers later when constructing new delayed attribute routines.

---
 fs/xfs/libxfs/xfs_attr_remote.c | 72 +++++++++++++++++++++++++++++++----------
 fs/xfs/libxfs/xfs_attr_remote.h |  3 +-
 2 files changed, 57 insertions(+), 18 deletions(-)
fs/xfs/libxfs/xfs_attr_remote.c +0 -0
index db9247a..080a284 100644

...

fs/xfs/libxfs/xfs_attr_remote.c xfs_attr_rmtval_set( · line 491

Quoted 6 lines
fs/xfs/libxfs/xfs_attr_remote.c +2 -0
@@ -500,6 +487,57 @@ xfs_attr_rmtval_set(
 			return error;
 	}
 
+	error = xfs_attr_rmtval_set_value(args);
+	return error;
	return xfs_attr_rmtval_set_value(args);
Quoted 6 lines
fs/xfs/libxfs/xfs_attr_remote.c +6 -0
+}
+
+
+/*
+ * Find a "hole" in the attribute address space large enough for us to drop the
+ * new attribute's value into

fs/xfs/libxfs/xfs_attr_remote.c xfs_attr_rmtval_set( · line 507

Quoted 10 lines
fs/xfs/libxfs/xfs_attr_remote.c +10 -0
+ */
+int
+xfs_attr_rmt_find_hole(
+	struct xfs_da_args	*args)
+{
+	struct xfs_inode        *dp = args->dp;
+	struct xfs_mount	*mp = dp->i_mount;
+	int			error;
+	int			blkcnt;
+	xfs_fileoff_t		lfileoff = args->rmtblkno;

The init of lfileoff looks a little strange here. It was originally initialized to zero, passed into the call below and then assigned to ->rmtblkno. Is this change intentional?

With those nits fixed:

Quoted 51 lines
fs/xfs/libxfs/xfs_attr_remote.c +33 -0
+
+	/*
+	 * Because CRC enable attributes have headers, we can't just do a
+	 * straight byte to FSB conversion and have to take the header space
+	 * into account.
+	 */
+	blkcnt = xfs_attr3_rmt_blocks(mp, args->rmtvaluelen);
+	error = xfs_bmap_first_unused(args->trans, args->dp, blkcnt, &lfileoff,
+						   XFS_ATTR_FORK);
+	if (error)
+		return error;
+
+	args->rmtblkno = (xfs_dablk_t)lfileoff;
+	args->rmtblkcnt = blkcnt;
+
+	return 0;
+}
+
+int
+xfs_attr_rmtval_set_value(
+	struct xfs_da_args	*args)
+{
+	struct xfs_inode	*dp = args->dp;
+	struct xfs_mount	*mp = dp->i_mount;
+	struct xfs_bmbt_irec	map;
+	xfs_dablk_t		lblkno;
+	uint8_t			*src = args->value;
+	int			blkcnt;
+	int			valuelen;
+	int			nmap;
+	int			error;
+	int			offset = 0;
+
 	/*
 	 * Roll through the "value", copying the attribute value to the
 	 * already-allocated blocks.  Blocks are written synchronously
fs/xfs/libxfs/xfs_attr_remote.h +2 -1
index 9d20b66..cd7670d 100644
@@ -11,5 +11,6 @@ int xfs_attr3_rmt_blocks(struct xfs_mount *mp, int attrlen);
 int xfs_attr_rmtval_get(struct xfs_da_args *args);
 int xfs_attr_rmtval_set(struct xfs_da_args *args);
 int xfs_attr_rmtval_remove(struct xfs_da_args *args);
-
+int xfs_attr_rmtval_set_value(struct xfs_da_args *args);
+int xfs_attr_rmt_find_hole(struct xfs_da_args *args);
 #endif /* __XFS_ATTR_REMOTE_H__ */
Signature · 1 line
2.7.4
#19 lore raw

Re: [PATCH v3 05/19] xfs: Factor out new helper functions xfs_attr_rmtval_set

Quoted 19 lines · Brian Foster
Quoted 17 lines · Allison Collins

Break xfs_attr_rmtval_set into two helper functions xfs_attr_rmt_find_hole and xfs_attr_rmtval_set_value. xfs_attr_rmtval_set rolls the transaction between the helpers, but delayed operations cannot. We will use the helpers later when constructing new delayed attribute routines.

---
  fs/xfs/libxfs/xfs_attr_remote.c | 72 +++++++++++++++++++++++++++++++----------
  fs/xfs/libxfs/xfs_attr_remote.h |  3 +-
  2 files changed, 57 insertions(+), 18 deletions(-)
fs/xfs/libxfs/xfs_attr_remote.c +0 -0
index db9247a..080a284 100644

...

Quoted 8 lines

fs/xfs/libxfs/xfs_attr_remote.c xfs_attr_rmtval_set( · line 491

Quoted 6 lines
fs/xfs/libxfs/xfs_attr_remote.c +2 -0
@@ -500,6 +487,57 @@ xfs_attr_rmtval_set(
  			return error;
  	}
 
+	error = xfs_attr_rmtval_set_value(args);
+	return error;
	return xfs_attr_rmtval_set_value(args);

Ok, will fix

Quoted 13 lines
Quoted 13 lines
fs/xfs/libxfs/xfs_attr_remote.c +12 -0
+}
+
+
+/*
+ * Find a "hole" in the attribute address space large enough for us to drop the
+ * new attribute's value into
+ */
+int
+xfs_attr_rmt_find_hole(
+	struct xfs_da_args	*args)
+{
+	struct xfs_inode        *dp = args->dp;
Quoted 9 lines

fs/xfs/libxfs/xfs_attr_remote.c xfs_attr_rmtval_set( · line 507

Quoted 4 lines
fs/xfs/libxfs/xfs_attr_remote.c +4 -0
+	struct xfs_mount	*mp = dp->i_mount;
+	int			error;
+	int			blkcnt;
+	xfs_fileoff_t		lfileoff = args->rmtblkno;

The init of lfileoff looks a little strange here. It was originally initialized to zero, passed into the call below and then assigned to ->rmtblkno. Is this change intentional?

I see, no I probably mistakenly adopted the assignment, but it's likely not needed. Will clean out.

Thanks again for all the reviews!
Allison

Quoted 55 lines

With those nits fixed:

Quoted 51 lines
fs/xfs/libxfs/xfs_attr_remote.c +33 -0
+
+	/*
+	 * Because CRC enable attributes have headers, we can't just do a
+	 * straight byte to FSB conversion and have to take the header space
+	 * into account.
+	 */
+	blkcnt = xfs_attr3_rmt_blocks(mp, args->rmtvaluelen);
+	error = xfs_bmap_first_unused(args->trans, args->dp, blkcnt, &lfileoff,
+						   XFS_ATTR_FORK);
+	if (error)
+		return error;
+
+	args->rmtblkno = (xfs_dablk_t)lfileoff;
+	args->rmtblkcnt = blkcnt;
+
+	return 0;
+}
+
+int
+xfs_attr_rmtval_set_value(
+	struct xfs_da_args	*args)
+{
+	struct xfs_inode	*dp = args->dp;
+	struct xfs_mount	*mp = dp->i_mount;
+	struct xfs_bmbt_irec	map;
+	xfs_dablk_t		lblkno;
+	uint8_t			*src = args->value;
+	int			blkcnt;
+	int			valuelen;
+	int			nmap;
+	int			error;
+	int			offset = 0;
+
  	/*
  	 * Roll through the "value", copying the attribute value to the
  	 * already-allocated blocks.  Blocks are written synchronously
fs/xfs/libxfs/xfs_attr_remote.h +2 -1
index 9d20b66..cd7670d 100644
@@ -11,5 +11,6 @@ int xfs_attr3_rmt_blocks(struct xfs_mount *mp, int attrlen);
  int xfs_attr_rmtval_get(struct xfs_da_args *args);
  int xfs_attr_rmtval_set(struct xfs_da_args *args);
  int xfs_attr_rmtval_remove(struct xfs_da_args *args);
-
+int xfs_attr_rmtval_set_value(struct xfs_da_args *args);
+int xfs_attr_rmt_find_hole(struct xfs_da_args *args);
  #endif /* __XFS_ATTR_REMOTE_H__ */
Signature · 1 line
2.7.4
#20 lore raw

PATCH v3 6/19 xfs: Factor up trans handling in xfs_attr3_leaf_flipflags

In reply to Allison Collins

Since delayed operations cannot roll transactions, factor up the transaction handling into the calling function

---
 fs/xfs/libxfs/xfs_attr.c      | 14 ++++++++++++++
 fs/xfs/libxfs/xfs_attr_leaf.c |  5 -----
 2 files changed, 14 insertions(+), 5 deletions(-)
fs/xfs/libxfs/xfs_attr.c +14 -0
index a297857..7a6dd37 100644
@@ -710,6 +710,13 @@ xfs_attr_leaf_addname(
 		error = xfs_attr3_leaf_flipflags(args);
 		if (error)
 			return error;
+		/*
+		 * Commit the flag value change and start the next trans in
+		 * series.
+		 */
+		error = xfs_trans_roll_inode(&args->trans, args->dp);
+		if (error)
+			return error;
 
 		/*
 		 * Dismantle the "old" attribute/value pair by removing
@@ -1046,6 +1053,13 @@ xfs_attr_node_addname(
 		error = xfs_attr3_leaf_flipflags(args);
 		if (error)
 			goto out;
+		/*
+		 * Commit the flag value change and start the next trans in
+		 * series
+		 */
+		error = xfs_trans_roll_inode(&args->trans, args->dp);
+		if (error)
+			goto out;
 
 		/*
 		 * Dismantle the "old" attribute/value pair by removing
fs/xfs/libxfs/xfs_attr_leaf.c +0 -5
index a501538..3903e5c 100644
@@ -2919,10 +2919,5 @@ xfs_attr3_leaf_flipflags(
 			 XFS_DA_LOGRANGE(leaf2, name_rmt, sizeof(*name_rmt)));
 	}
 
-	/*
-	 * Commit the flag value change and start the next trans in series.
-	 */
-	error = xfs_trans_roll_inode(&args->trans, args->dp);
-
 	return error;
 }
Signature · 1 line
2.7.4
Reviewed-by on v3 6/19
#21 lore raw

Re: [PATCH v3 06/19] xfs: Factor up trans handling in xfs_attr3_leaf_flipflags

Quoted 5 lines · Allison Collins

Since delayed operations cannot roll transactions, factor up the transaction handling into the calling function

---

Quoted 54 lines
 fs/xfs/libxfs/xfs_attr.c      | 14 ++++++++++++++
 fs/xfs/libxfs/xfs_attr_leaf.c |  5 -----
 2 files changed, 14 insertions(+), 5 deletions(-)
fs/xfs/libxfs/xfs_attr.c +14 -0
index a297857..7a6dd37 100644
@@ -710,6 +710,13 @@ xfs_attr_leaf_addname(
 		error = xfs_attr3_leaf_flipflags(args);
 		if (error)
 			return error;
+		/*
+		 * Commit the flag value change and start the next trans in
+		 * series.
+		 */
+		error = xfs_trans_roll_inode(&args->trans, args->dp);
+		if (error)
+			return error;
 
 		/*
 		 * Dismantle the "old" attribute/value pair by removing
@@ -1046,6 +1053,13 @@ xfs_attr_node_addname(
 		error = xfs_attr3_leaf_flipflags(args);
 		if (error)
 			goto out;
+		/*
+		 * Commit the flag value change and start the next trans in
+		 * series
+		 */
+		error = xfs_trans_roll_inode(&args->trans, args->dp);
+		if (error)
+			goto out;
 
 		/*
 		 * Dismantle the "old" attribute/value pair by removing
fs/xfs/libxfs/xfs_attr_leaf.c +0 -5
index a501538..3903e5c 100644
@@ -2919,10 +2919,5 @@ xfs_attr3_leaf_flipflags(
 			 XFS_DA_LOGRANGE(leaf2, name_rmt, sizeof(*name_rmt)));
 	}
 
-	/*
-	 * Commit the flag value change and start the next trans in series.
-	 */
-	error = xfs_trans_roll_inode(&args->trans, args->dp);
-
 	return error;
 }
Signature · 1 line
2.7.4
#22 lore raw

Re: [PATCH v3 06/19] xfs: Factor up trans handling in xfs_attr3_leaf_flipflags

Quoted 8 lines · Brian Foster
Quoted 5 lines · Allison Collins

Since delayed operations cannot roll transactions, factor up the transaction handling into the calling function

---

Thank you!!

Allison

Quoted 55 lines
Quoted 55 lines
  fs/xfs/libxfs/xfs_attr.c      | 14 ++++++++++++++
  fs/xfs/libxfs/xfs_attr_leaf.c |  5 -----
  2 files changed, 14 insertions(+), 5 deletions(-)
fs/xfs/libxfs/xfs_attr.c +14 -0
index a297857..7a6dd37 100644
@@ -710,6 +710,13 @@ xfs_attr_leaf_addname(
  		error = xfs_attr3_leaf_flipflags(args);
  		if (error)
  			return error;
+		/*
+		 * Commit the flag value change and start the next trans in
+		 * series.
+		 */
+		error = xfs_trans_roll_inode(&args->trans, args->dp);
+		if (error)
+			return error;
 
  		/*
  		 * Dismantle the "old" attribute/value pair by removing
@@ -1046,6 +1053,13 @@ xfs_attr_node_addname(
  		error = xfs_attr3_leaf_flipflags(args);
  		if (error)
  			goto out;
+		/*
+		 * Commit the flag value change and start the next trans in
+		 * series
+		 */
+		error = xfs_trans_roll_inode(&args->trans, args->dp);
+		if (error)
+			goto out;
 
  		/*
  		 * Dismantle the "old" attribute/value pair by removing
fs/xfs/libxfs/xfs_attr_leaf.c +0 -5
index a501538..3903e5c 100644
@@ -2919,10 +2919,5 @@ xfs_attr3_leaf_flipflags(
  			 XFS_DA_LOGRANGE(leaf2, name_rmt, sizeof(*name_rmt)));
  	}
 
-	/*
-	 * Commit the flag value change and start the next trans in series.
-	 */
-	error = xfs_trans_roll_inode(&args->trans, args->dp);
-
  	return error;
  }
Signature · 1 line
2.7.4
#23 lore raw

PATCH v3 7/19 xfs: Factor out xfs_attr_leaf_addname helper

In reply to Allison Collins

Factor out new helper function xfs_attr_leaf_try_add. Because new delayed attribute routines cannot roll transactions, we carve off the parts of xfs_attr_leaf_addname that we can use. This will help to reduce repetitive code later when we introduce delayed attributes.

---
 fs/xfs/libxfs/xfs_attr.c | 43 +++++++++++++++++++++++++++++--------------
 1 file changed, 29 insertions(+), 14 deletions(-)
fs/xfs/libxfs/xfs_attr.c +29 -14
index 7a6dd37..f27e2c6 100644
@@ -593,19 +593,12 @@ xfs_attr_shortform_addname(xfs_da_args_t *args)
  * External routines when attribute list is one block
  *========================================================================*/
 
-/*
- * Add a name to the leaf attribute list structure
- *
- * This leaf block cannot have a "remote" value, we only call this routine
- * if bmap_one_block() says there is only one block (ie: no remote blks).
- */
 STATIC int
-xfs_attr_leaf_addname(
-	struct xfs_da_args	*args)
+xfs_attr_leaf_try_add(
+	struct xfs_da_args	*args,
+	struct xfs_buf		*bp)
 {
-	struct xfs_buf		*bp;
-	int			retval, error, forkoff;
-	struct xfs_inode	*dp = args->dp;
+	int			retval, error;
 
 	trace_xfs_attr_leaf_addname(args);
 
@@ -650,13 +643,35 @@ xfs_attr_leaf_addname(
 	retval = xfs_attr3_leaf_add(bp, args);
 	if (retval == -ENOSPC) {
 		/*
-		 * Promote the attribute list to the Btree format, then
-		 * Commit that transaction so that the node_addname() call
-		 * can manage its own transactions.
+		 * Promote the attribute list to the Btree format.
 		 */
 		error = xfs_attr3_leaf_to_node(args);
 		if (error)
 			return error;
+	}
+	return retval;
+}
+
+
+/*
+ * Add a name to the leaf attribute list structure
+ *
+ * This leaf block cannot have a "remote" value, we only call this routine
+ * if bmap_one_block() says there is only one block (ie: no remote blks).
+ */
+STATIC int
+xfs_attr_leaf_addname(struct xfs_da_args	*args)
+{
+	int			retval, error, forkoff;
+	struct xfs_buf		*bp = NULL;
+	struct xfs_inode	*dp = args->dp;
+
+	retval = xfs_attr_leaf_try_add(args, bp);
+	if (retval == -ENOSPC) {
+		/*
+		 * Commit that transaction so that the node_addname() call
+		 * can manage its own transactions.
+		 */
 		error = xfs_defer_finish(&args->trans);
 		if (error)
 			return error;
Signature · 1 line
2.7.4
#24 lore raw

Re: [PATCH v3 07/19] xfs: Factor out xfs_attr_leaf_addname helper

Quoted 27 lines · Allison Collins

Factor out new helper function xfs_attr_leaf_try_add. Because new delayed attribute routines cannot roll transactions, we carve off the parts of xfs_attr_leaf_addname that we can use. This will help to reduce repetitive code later when we introduce delayed attributes.

---
 fs/xfs/libxfs/xfs_attr.c | 43 +++++++++++++++++++++++++++++--------------
 1 file changed, 29 insertions(+), 14 deletions(-)
fs/xfs/libxfs/xfs_attr.c +0 -6
index 7a6dd37..f27e2c6 100644
@@ -593,19 +593,12 @@ xfs_attr_shortform_addname(xfs_da_args_t *args)
  * External routines when attribute list is one block
  *========================================================================*/
 
-/*
- * Add a name to the leaf attribute list structure
- *
- * This leaf block cannot have a "remote" value, we only call this routine
- * if bmap_one_block() says there is only one block (ie: no remote blks).
- */
 STATIC int

fs/xfs/libxfs/xfs_attr.c xfs_attr_shortform_addname(xfs_da_args_t *args) · line 601

Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +4 -5
-xfs_attr_leaf_addname(
-	struct xfs_da_args	*args)
+xfs_attr_leaf_try_add(
+	struct xfs_da_args	*args,
+	struct xfs_buf		*bp)
 {
-	struct xfs_buf		*bp;
-	int			retval, error, forkoff;
-	struct xfs_inode	*dp = args->dp;
+	int			retval, error;

It looks like we could pick either retval or error and use it consistently throughout the new function.

fs/xfs/libxfs/xfs_attr.c xfs_attr_shortform_addname(xfs_da_args_t *args) · line 604

Quoted 3 lines
fs/xfs/libxfs/xfs_attr.c +0 -0
 	trace_xfs_attr_leaf_addname(args);
 

I also wonder if this tracepoint should remain in the caller.

Quoted 29 lines
fs/xfs/libxfs/xfs_attr.c +18 -3
@@ -650,13 +643,35 @@ xfs_attr_leaf_addname(
 	retval = xfs_attr3_leaf_add(bp, args);
 	if (retval == -ENOSPC) {
 		/*
-		 * Promote the attribute list to the Btree format, then
-		 * Commit that transaction so that the node_addname() call
-		 * can manage its own transactions.
+		 * Promote the attribute list to the Btree format.
 		 */
 		error = xfs_attr3_leaf_to_node(args);
 		if (error)
 			return error;
+	}
+	return retval;
+}
+
+
+/*
+ * Add a name to the leaf attribute list structure
+ *
+ * This leaf block cannot have a "remote" value, we only call this routine
+ * if bmap_one_block() says there is only one block (ie: no remote blks).
+ */
+STATIC int
+xfs_attr_leaf_addname(struct xfs_da_args	*args)
+{
+	int			retval, error, forkoff;
+	struct xfs_buf		*bp = NULL;
+	struct xfs_inode	*dp = args->dp;

fs/xfs/libxfs/xfs_attr.c xfs_attr_leaf_addname( · line 677

Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +7 -0
+
+	retval = xfs_attr_leaf_try_add(args, bp);
+	if (retval == -ENOSPC) {
+		/*
+		 * Commit that transaction so that the node_addname() call
+		 * can manage its own transactions.
+		 */
 		error = xfs_defer_finish(&args->trans);
 		if (error)
 			return error;

Hmm.. I find this bit of factoring a little strange. We do part of the -ENOSPC handling (leaf to node) in one place and another part (xfs_defer_finish()) in the caller. I'm assuming we intentionally don't finish dfops in the new helper because the delayed attr bits shouldn't do that, but I'm wondering whether the helper should just return -ENOSPC and the caller should be responsible for whatever needs to happen based on that in the associated context. Hm?

Brian

Quoted 3 lines
Signature · 1 line
2.7.4
#25 lore raw

Re: [PATCH v3 07/19] xfs: Factor out xfs_attr_leaf_addname helper

Quoted 43 lines · Brian Foster
Quoted 27 lines · Allison Collins

Factor out new helper function xfs_attr_leaf_try_add. Because new delayed attribute routines cannot roll transactions, we carve off the parts of xfs_attr_leaf_addname that we can use. This will help to reduce repetitive code later when we introduce delayed attributes.

---
  fs/xfs/libxfs/xfs_attr.c | 43 +++++++++++++++++++++++++++++--------------
  1 file changed, 29 insertions(+), 14 deletions(-)
fs/xfs/libxfs/xfs_attr.c +0 -6
index 7a6dd37..f27e2c6 100644
@@ -593,19 +593,12 @@ xfs_attr_shortform_addname(xfs_da_args_t *args)
   * External routines when attribute list is one block
   *========================================================================*/
 
-/*
- * Add a name to the leaf attribute list structure
- *
- * This leaf block cannot have a "remote" value, we only call this routine
- * if bmap_one_block() says there is only one block (ie: no remote blks).
- */
  STATIC int

fs/xfs/libxfs/xfs_attr.c xfs_attr_shortform_addname(xfs_da_args_t *args) · line 601

Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +4 -5
-xfs_attr_leaf_addname(
-	struct xfs_da_args	*args)
+xfs_attr_leaf_try_add(
+	struct xfs_da_args	*args,
+	struct xfs_buf		*bp)
  {
-	struct xfs_buf		*bp;
-	int			retval, error, forkoff;
-	struct xfs_inode	*dp = args->dp;
+	int			retval, error;

It looks like we could pick either retval or error and use it consistently throughout the new function.

Quoted 1 line
Quoted 4 lines
Quoted 2 lines
  	trace_xfs_attr_leaf_addname(args);

I also wonder if this tracepoint should remain in the caller.

Alrihty, will clean out retval and move trace point

Quoted 49 lines
Quoted 30 lines
fs/xfs/libxfs/xfs_attr.c +18 -3
@@ -650,13 +643,35 @@ xfs_attr_leaf_addname(
  	retval = xfs_attr3_leaf_add(bp, args);
  	if (retval == -ENOSPC) {
  		/*
-		 * Promote the attribute list to the Btree format, then
-		 * Commit that transaction so that the node_addname() call
-		 * can manage its own transactions.
+		 * Promote the attribute list to the Btree format.
  		 */
  		error = xfs_attr3_leaf_to_node(args);
  		if (error)
  			return error;
+	}
+	return retval;
+}
+
+
+/*
+ * Add a name to the leaf attribute list structure
+ *
+ * This leaf block cannot have a "remote" value, we only call this routine
+ * if bmap_one_block() says there is only one block (ie: no remote blks).
+ */
+STATIC int
+xfs_attr_leaf_addname(struct xfs_da_args	*args)
+{
+	int			retval, error, forkoff;
+	struct xfs_buf		*bp = NULL;
+	struct xfs_inode	*dp = args->dp;

fs/xfs/libxfs/xfs_attr.c xfs_attr_leaf_addname( · line 677

Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +7 -0
+
+	retval = xfs_attr_leaf_try_add(args, bp);
+	if (retval == -ENOSPC) {
+		/*
+		 * Commit that transaction so that the node_addname() call
+		 * can manage its own transactions.
+		 */
  		error = xfs_defer_finish(&args->trans);
  		if (error)
  			return error;

Hmm.. I find this bit of factoring a little strange. We do part of the -ENOSPC handling (leaf to node) in one place and another part (xfs_defer_finish()) in the caller. I'm assuming we intentionally don't finish dfops in the new helper because the delayed attr bits shouldn't do that, but I'm wondering whether the helper should just return -ENOSPC and the caller should be responsible for whatever needs to happen based on that in the associated context. Hm?

Quoted 1 line

Brian

Yes, the idea is that the new helper function avoids anything with transactions. We could factor up the ENOSPC handling into the caller, that may look cleaner. I think there's really only one place it's called.

Thanks!
Allison

Quoted 4 lines
Quoted 4 lines
Signature · 2 lines
-- 
2.7.4
#26 lore raw

PATCH v3 8/19 xfs: Factor up commit from xfs_attr_try_sf_addname

In reply to Allison Collins

New delayed attribute routines cannot handle transactions, so factor this up to the calling function.

---
 fs/xfs/libxfs/xfs_attr.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
fs/xfs/libxfs/xfs_attr.c +8 -7
index f27e2c6..318c543 100644
@@ -227,7 +227,7 @@ xfs_attr_try_sf_addname(
 {
 
 	struct xfs_mount	*mp = dp->i_mount;
-	int			error, error2;
+	int			error;
 
 	error = xfs_attr_shortform_addname(args);
 	if (error == -ENOSPC)
@@ -243,9 +243,7 @@ xfs_attr_try_sf_addname(
 	if (mp->m_flags & XFS_MOUNT_WSYNC)
 		xfs_trans_set_sync(args->trans);
 
-	error2 = xfs_trans_commit(args->trans);
-	args->trans = NULL;
-	return error ? error : error2;
+	return error;
 }
 
 /*
@@ -257,7 +255,7 @@ xfs_attr_set_args(
 {
 	struct xfs_inode	*dp = args->dp;
 	struct xfs_buf          *leaf_bp = NULL;
-	int			error;
+	int			error, error2 = 0;;
 
 	/*
 	 * If the attribute list is non-existent or a shortform list,
@@ -277,8 +275,11 @@ xfs_attr_set_args(
 		 * Try to add the attr to the attribute list in the inode.
 		 */
 		error = xfs_attr_try_sf_addname(dp, args);
-		if (error != -ENOSPC)
-			return error;
+		if (!error) {
+			error2 = xfs_trans_commit(args->trans);
+			args->trans = NULL;
+			return error ? error : error2;
+		}
 
 		/*
 		 * It won't fit in the shortform, transform to a leaf block.
Signature · 1 line
2.7.4
#27 lore raw

Re: [PATCH v3 08/19] xfs: Factor up commit from xfs_attr_try_sf_addname

Quoted 22 lines · Allison Collins

New delayed attribute routines cannot handle transactions, so factor this up to the calling function.

---
 fs/xfs/libxfs/xfs_attr.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
fs/xfs/libxfs/xfs_attr.c +1 -1
index f27e2c6..318c543 100644
@@ -227,7 +227,7 @@ xfs_attr_try_sf_addname(
 {
 
 	struct xfs_mount	*mp = dp->i_mount;
-	int			error, error2;
+	int			error;
 
 	error = xfs_attr_shortform_addname(args);
 	if (error == -ENOSPC)

fs/xfs/libxfs/xfs_attr.c xfs_attr_try_sf_addname( · line 245

Quoted 3 lines
fs/xfs/libxfs/xfs_attr.c +0 -0
@@ -243,9 +243,7 @@ xfs_attr_try_sf_addname(
 	if (mp->m_flags & XFS_MOUNT_WSYNC)
 		xfs_trans_set_sync(args->trans);
 

Perhaps the above check should stay along with the tx commit code..?

Quoted 17 lines
fs/xfs/libxfs/xfs_attr.c +2 -4
-	error2 = xfs_trans_commit(args->trans);
-	args->trans = NULL;
-	return error ? error : error2;
+	return error;
 }
 
 /*
@@ -257,7 +255,7 @@ xfs_attr_set_args(
 {
 	struct xfs_inode	*dp = args->dp;
 	struct xfs_buf          *leaf_bp = NULL;
-	int			error;
+	int			error, error2 = 0;;
 
 	/*
 	 * If the attribute list is non-existent or a shortform list,

fs/xfs/libxfs/xfs_attr.c xfs_attr_set_args( · line 281

Quoted 9 lines
fs/xfs/libxfs/xfs_attr.c +4 -2
@@ -277,8 +275,11 @@ xfs_attr_set_args(
 		 * Try to add the attr to the attribute list in the inode.
 		 */
 		error = xfs_attr_try_sf_addname(dp, args);
-		if (error != -ENOSPC)
-			return error;
+		if (!error) {
+			error2 = xfs_trans_commit(args->trans);
+			args->trans = NULL;
+			return error ? error : error2;

We've already checked that error == 0 here, so this can be simplified. Hmm.. that said, the original code looks like it commits the transaction on error != -ENOSPC, which means this slightly changes behavior when (error && error != -ENOSPC) is true. So perhaps it is the error check that should be fixed up and not the error2 logic..

Brian

Quoted 7 lines
fs/xfs/libxfs/xfs_attr.c +1 -0
+		}
 
 		/*
 		 * It won't fit in the shortform, transform to a leaf block.
Signature · 1 line
2.7.4
#28 lore raw

Re: [PATCH v3 08/19] xfs: Factor up commit from xfs_attr_try_sf_addname

Quoted 20 lines · Brian Foster
Quoted 19 lines · Allison Collins

New delayed attribute routines cannot handle transactions, so factor this up to the calling function.

---
  fs/xfs/libxfs/xfs_attr.c | 15 ++++++++-------
  1 file changed, 8 insertions(+), 7 deletions(-)
fs/xfs/libxfs/xfs_attr.c +1 -1
index f27e2c6..318c543 100644
@@ -227,7 +227,7 @@ xfs_attr_try_sf_addname(
  {
 
  	struct xfs_mount	*mp = dp->i_mount;
-	int			error, error2;
+	int			error;
 
Quoted 8 lines

fs/xfs/libxfs/xfs_attr.c xfs_attr_try_sf_addname( · line 245

Quoted 6 lines
fs/xfs/libxfs/xfs_attr.c +0 -0
  	error = xfs_attr_shortform_addname(args);
  	if (error == -ENOSPC)
@@ -243,9 +243,7 @@ xfs_attr_try_sf_addname(
  	if (mp->m_flags & XFS_MOUNT_WSYNC)
  		xfs_trans_set_sync(args->trans);
 

Perhaps the above check should stay along with the tx commit code..?

That makes sense, I will move it upwards

Quoted 25 lines
Quoted 25 lines
fs/xfs/libxfs/xfs_attr.c +4 -6
-	error2 = xfs_trans_commit(args->trans);
-	args->trans = NULL;
-	return error ? error : error2;
+	return error;
  }
 
  /*
@@ -257,7 +255,7 @@ xfs_attr_set_args(
  {
  	struct xfs_inode	*dp = args->dp;
  	struct xfs_buf          *leaf_bp = NULL;
-	int			error;
+	int			error, error2 = 0;;
 
  	/*
  	 * If the attribute list is non-existent or a shortform list,
@@ -277,8 +275,11 @@ xfs_attr_set_args(
  		 * Try to add the attr to the attribute list in the inode.
  		 */
  		error = xfs_attr_try_sf_addname(dp, args);
-		if (error != -ENOSPC)
-			return error;
+		if (!error) {
+			error2 = xfs_trans_commit(args->trans);
Quoted 8 lines

fs/xfs/libxfs/xfs_attr.c xfs_attr_set_args( · line 281

Quoted 2 lines
fs/xfs/libxfs/xfs_attr.c +2 -0
+			args->trans = NULL;
+			return error ? error : error2;

We've already checked that error == 0 here, so this can be simplified. Hmm.. that said, the original code looks like it commits the transaction on error != -ENOSPC, which means this slightly changes behavior when (error && error != -ENOSPC) is true. So perhaps it is the error check that should be fixed up and not the error2 logic..

Yes, I believe this got some attention in the last review. While it is different logic now, I think we reasoned that committing on say -EIO or some other such unexpected error didn't make much sense either, so we cleaned it up a bit. Though you're probably right about the simplification now with the change. Is there a reason we would want to commit in the case of unexpected errors?

Allison

Quoted 10 lines

Brian

Quoted 7 lines
fs/xfs/libxfs/xfs_attr.c +1 -0
+		}
 
  		/*
  		 * It won't fit in the shortform, transform to a leaf block.
Signature · 1 line
2.7.4
#29 lore raw

Re: [PATCH v3 08/19] xfs: Factor up commit from xfs_attr_try_sf_addname

Quoted 61 lines · Allison Collins
Quoted 9 lines · Brian Foster
Quoted 8 lines · Allison Collins

New delayed attribute routines cannot handle transactions, so factor this up to the calling function.

---
  fs/xfs/libxfs/xfs_attr.c | 15 ++++++++-------
  1 file changed, 8 insertions(+), 7 deletions(-)
Quoted 16 lines
Quoted 12 lines
fs/xfs/libxfs/xfs_attr.c +1 -1
index f27e2c6..318c543 100644
@@ -227,7 +227,7 @@ xfs_attr_try_sf_addname(
  {
  	struct xfs_mount	*mp = dp->i_mount;
-	int			error, error2;
+	int			error;
  	error = xfs_attr_shortform_addname(args);
  	if (error == -ENOSPC)

fs/xfs/libxfs/xfs_attr.c xfs_attr_try_sf_addname( · line 244

Quoted 2 lines
fs/xfs/libxfs/xfs_attr.c +0 -0
@@ -243,9 +243,7 @@ xfs_attr_try_sf_addname(
  	if (mp->m_flags & XFS_MOUNT_WSYNC)
  		xfs_trans_set_sync(args->trans);

Perhaps the above check should stay along with the tx commit code..?

That makes sense, I will move it upwards

Quoted 23 lines
Quoted 23 lines
fs/xfs/libxfs/xfs_attr.c +4 -6
-	error2 = xfs_trans_commit(args->trans);
-	args->trans = NULL;
-	return error ? error : error2;
+	return error;
  }
  /*
@@ -257,7 +255,7 @@ xfs_attr_set_args(
  {
  	struct xfs_inode	*dp = args->dp;
  	struct xfs_buf          *leaf_bp = NULL;
-	int			error;
+	int			error, error2 = 0;;
  	/*
  	 * If the attribute list is non-existent or a shortform list,
@@ -277,8 +275,11 @@ xfs_attr_set_args(
  		 * Try to add the attr to the attribute list in the inode.
  		 */
  		error = xfs_attr_try_sf_addname(dp, args);
-		if (error != -ENOSPC)
-			return error;
+		if (!error) {
+			error2 = xfs_trans_commit(args->trans);
Quoted 8 lines

fs/xfs/libxfs/xfs_attr.c xfs_attr_set_args( · line 281

Quoted 2 lines
fs/xfs/libxfs/xfs_attr.c +2 -0
+			args->trans = NULL;
+			return error ? error : error2;

We've already checked that error == 0 here, so this can be simplified. Hmm.. that said, the original code looks like it commits the transaction on error != -ENOSPC, which means this slightly changes behavior when (error && error != -ENOSPC) is true. So perhaps it is the error check that should be fixed up and not the error2 logic..

Quoted 7 lines

Yes, I believe this got some attention in the last review. While it is different logic now, I think we reasoned that committing on say -EIO or some other such unexpected error didn't make much sense either, so we cleaned it up a bit. Though you're probably right about the simplification now with the change. Is there a reason we would want to commit in the case of unexpected errors?

I'm not 100% sure tbh. There is a comment that acknowledges unrelated errors so it might be intentional, at least for some errors. I'd at least suggest to preserve the existing logic in the refactoring patch and if you think there's a bug, perhaps tack on a separate patch later for independent review. That way if we find we broke something down the line, it's easier to identify and test the logic change separately from the broader rework.

Brian

Quoted 11 lines

Allison

Quoted 9 lines

Brian

Quoted 6 lines
fs/xfs/libxfs/xfs_attr.c +1 -0
+		}
  		/*
  		 * It won't fit in the shortform, transform to a leaf block.
Signature · 1 line
2.7.4
#30 lore raw

PATCH v3 9/19 xfs: Factor up trans roll from xfs_attr3_leaf_setflag

In reply to Allison Collins

New delayed allocation routines cannot be handling transactions so factor them up into the calling functions

---
 fs/xfs/libxfs/xfs_attr.c      | 5 +++++
 fs/xfs/libxfs/xfs_attr_leaf.c | 5 +----
 2 files changed, 6 insertions(+), 4 deletions(-)
fs/xfs/libxfs/xfs_attr.c +5 -0
index 318c543..5e5b688 100644
@@ -1199,6 +1199,11 @@ xfs_attr_node_removename(
 		error = xfs_attr3_leaf_setflag(args);
 		if (error)
 			goto out;
+
+		error = xfs_trans_roll_inode(&args->trans, args->dp);
+		if (error)
+			goto out;
+
 		error = xfs_attr_rmtval_remove(args);
 		if (error)
 			goto out;
fs/xfs/libxfs/xfs_attr_leaf.c +1 -4
index 3903e5c..bcd86c3 100644
@@ -2801,10 +2801,7 @@ xfs_attr3_leaf_setflag(
 			 XFS_DA_LOGRANGE(leaf, name_rmt, sizeof(*name_rmt)));
 	}
 
-	/*
-	 * Commit the flag value change and start the next trans in series.
-	 */
-	return xfs_trans_roll_inode(&args->trans, args->dp);
+	return error;
 }
 
 /*
Signature · 1 line
2.7.4
Reviewed-by on v3 9/19
#31 lore raw

Re: [PATCH v3 09/19] xfs: Factor up trans roll from xfs_attr3_leaf_setflag

Quoted 6 lines · Allison Collins

New delayed allocation routines cannot be handling transactions so factor them up into the calling functions

---

Quoted 39 lines
 fs/xfs/libxfs/xfs_attr.c      | 5 +++++
 fs/xfs/libxfs/xfs_attr_leaf.c | 5 +----
 2 files changed, 6 insertions(+), 4 deletions(-)
fs/xfs/libxfs/xfs_attr.c +5 -0
index 318c543..5e5b688 100644
@@ -1199,6 +1199,11 @@ xfs_attr_node_removename(
 		error = xfs_attr3_leaf_setflag(args);
 		if (error)
 			goto out;
+
+		error = xfs_trans_roll_inode(&args->trans, args->dp);
+		if (error)
+			goto out;
+
 		error = xfs_attr_rmtval_remove(args);
 		if (error)
 			goto out;
fs/xfs/libxfs/xfs_attr_leaf.c +1 -4
index 3903e5c..bcd86c3 100644
@@ -2801,10 +2801,7 @@ xfs_attr3_leaf_setflag(
 			 XFS_DA_LOGRANGE(leaf, name_rmt, sizeof(*name_rmt)));
 	}
 
-	/*
-	 * Commit the flag value change and start the next trans in series.
-	 */
-	return xfs_trans_roll_inode(&args->trans, args->dp);
+	return error;
 }
 
 /*
Signature · 1 line
2.7.4
#32 lore raw

PATCH v3 10/19 xfs: Add xfs_attr3_leaf helper functions

In reply to Allison Collins

And new helper functions xfs_attr3_leaf_flag_is_set and xfs_attr3_leaf_flagsflipped. These routines check to see if xfs_attr3_leaf_setflag or xfs_attr3_leaf_flipflags have already been run. We will need this later for delayed attributes since routines may be recalled several times when -EAGAIN is returned.

---
 fs/xfs/libxfs/xfs_attr_leaf.c | 84 +++++++++++++++++++++++++++++++++++++++++++
 fs/xfs/libxfs/xfs_attr_leaf.h |  2 ++
 2 files changed, 86 insertions(+)
fs/xfs/libxfs/xfs_attr_leaf.c +84 -0
index bcd86c3..79650c9 100644
@@ -2757,6 +2757,36 @@ xfs_attr3_leaf_clearflag(
 }
 
 /*
+ * Check if the INCOMPLETE flag on an entry in a leaf block is set.
+ */
+int
+xfs_attr3_leaf_flag_is_set(
+	struct xfs_da_args		*args,
+	bool				*isset)
+{
+	struct xfs_attr_leafblock	*leaf;
+	struct xfs_attr_leaf_entry	*entry;
+	struct xfs_buf			*bp;
+	struct xfs_inode		*dp = args->dp;
+	int				error = 0;
+
+	trace_xfs_attr_leaf_setflag(args);
+
+	/*
+	 * Set up the operation.
+	 */
+	error = xfs_attr3_leaf_read(args->trans, dp, args->blkno, -1, &bp);
+	if (error)
+		return error;
+
+	leaf = bp->b_addr;
+	entry = &xfs_attr3_leaf_entryp(leaf)[args->index];
+
+	*isset = ((entry->flags & XFS_ATTR_INCOMPLETE) != 0);
+	return 0;
+}
+
+/*
  * Set the INCOMPLETE flag on an entry in a leaf block.
  */
 int
@@ -2918,3 +2948,57 @@ xfs_attr3_leaf_flipflags(
 
 	return error;
 }
+
+/*
+ * On a leaf entry, check to see if the INCOMPLETE flag is cleared
+ * in args->blkno/index and set in args->blkno2/index2.
+ * Note that they could be in different blocks, or in the same block.
+ *
+ * isflipped is set to true if flags are flipped or false otherwise
+ */
+int
+xfs_attr3_leaf_flagsflipped(
+	struct xfs_da_args		*args,
+	bool				*isflipped)
+{
+	struct xfs_attr_leafblock	*leaf1;
+	struct xfs_attr_leafblock	*leaf2;
+	struct xfs_attr_leaf_entry	*entry1;
+	struct xfs_attr_leaf_entry	*entry2;
+	struct xfs_buf			*bp1;
+	struct xfs_buf			*bp2;
+	struct xfs_inode		*dp = args->dp;
+	int				error = 0;
+
+	trace_xfs_attr_leaf_flipflags(args);
+
+	/*
+	 * Read the block containing the "old" attr
+	 */
+	error = xfs_attr3_leaf_read(args->trans, dp, args->blkno, -1, &bp1);
+	if (error)
+		return error;
+
+	/*
+	 * Read the block containing the "new" attr, if it is different
+	 */
+	if (args->blkno2 != args->blkno) {
+		error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno2,
+					   -1, &bp2);
+		if (error)
+			return error;
+	} else {
+		bp2 = bp1;
+	}
+
+	leaf1 = bp1->b_addr;
+	entry1 = &xfs_attr3_leaf_entryp(leaf1)[args->index];
+
+	leaf2 = bp2->b_addr;
+	entry2 = &xfs_attr3_leaf_entryp(leaf2)[args->index2];
+
+	*isflipped = (((entry1->flags & XFS_ATTR_INCOMPLETE) == 0) &&
+		      (entry2->flags & XFS_ATTR_INCOMPLETE));
+
+	return 0;
+}
fs/xfs/libxfs/xfs_attr_leaf.h +2 -0
index 58e9327..d82229b 100644
@@ -57,7 +57,9 @@ int	xfs_attr3_leaf_to_shortform(struct xfs_buf *bp,
 				   struct xfs_da_args *args, int forkoff);
 int	xfs_attr3_leaf_clearflag(struct xfs_da_args *args);
 int	xfs_attr3_leaf_setflag(struct xfs_da_args *args);
+int	xfs_attr3_leaf_flag_is_set(struct xfs_da_args *args, bool *isset);
 int	xfs_attr3_leaf_flipflags(struct xfs_da_args *args);
+int	xfs_attr3_leaf_flagsflipped(struct xfs_da_args *args, bool *isflipped);
 
 /*
  * Routines used for growing the Btree.
Signature · 1 line
2.7.4
#33 lore raw

Re: [PATCH v3 10/19] xfs: Add xfs_attr3_leaf helper functions

Quoted 26 lines · Allison Collins

And new helper functions xfs_attr3_leaf_flag_is_set and xfs_attr3_leaf_flagsflipped. These routines check to see if xfs_attr3_leaf_setflag or xfs_attr3_leaf_flipflags have already been run. We will need this later for delayed attributes since routines may be recalled several times when -EAGAIN is returned.

---
 fs/xfs/libxfs/xfs_attr_leaf.c | 84 +++++++++++++++++++++++++++++++++++++++++++
 fs/xfs/libxfs/xfs_attr_leaf.h |  2 ++
 2 files changed, 86 insertions(+)
fs/xfs/libxfs/xfs_attr_leaf.c +5 -0
index bcd86c3..79650c9 100644
@@ -2757,6 +2757,36 @@ xfs_attr3_leaf_clearflag(
 }
 
 /*
+ * Check if the INCOMPLETE flag on an entry in a leaf block is set.
+ */
+int
+xfs_attr3_leaf_flag_is_set(
+	struct xfs_da_args		*args,

fs/xfs/libxfs/xfs_attr_leaf.c xfs_attr3_leaf_clearflag( · line 2774

Quoted 10 lines
fs/xfs/libxfs/xfs_attr_leaf.c +10 -0
+	bool				*isset)
+{
+	struct xfs_attr_leafblock	*leaf;
+	struct xfs_attr_leaf_entry	*entry;
+	struct xfs_buf			*bp;
+	struct xfs_inode		*dp = args->dp;
+	int				error = 0;
+
+	trace_xfs_attr_leaf_setflag(args);
+

Tracepoint seems misplaced.. This is just a flag checking helper, right?

fs/xfs/libxfs/xfs_attr_leaf.c xfs_attr3_leaf_clearflag( · line 2777

Quoted 3 lines
fs/xfs/libxfs/xfs_attr_leaf.c +3 -0
+	/*
+	 * Set up the operation.
+	 */

Not sure what the comment means. The code seems self-explanatory here anyways, so you could probably just drop it.

fs/xfs/libxfs/xfs_attr_leaf.c xfs_attr3_leaf_clearflag( · line 2778

Quoted 1 line
fs/xfs/libxfs/xfs_attr_leaf.c +1 -0
+	error = xfs_attr3_leaf_read(args->trans, dp, args->blkno, -1, &bp);

Didn't you create a #define for this -1 earlier in the series?

fs/xfs/libxfs/xfs_attr_leaf.c xfs_attr3_leaf_clearflag( · line 2786

Quoted 8 lines
fs/xfs/libxfs/xfs_attr_leaf.c +8 -0
+	if (error)
+		return error;
+
+	leaf = bp->b_addr;
+	entry = &xfs_attr3_leaf_entryp(leaf)[args->index];
+
+	*isset = ((entry->flags & XFS_ATTR_INCOMPLETE) != 0);
+	return 0;

What about bp? Should we release it before returning? If not, the comment above the function should elaborate.

Quoted 7 lines
fs/xfs/libxfs/xfs_attr_leaf.c +3 -0
+}
+
+/*
  * Set the INCOMPLETE flag on an entry in a leaf block.
  */
 int

fs/xfs/libxfs/xfs_attr_leaf.c xfs_attr3_leaf_flipflags( · line 2956

Quoted 9 lines
fs/xfs/libxfs/xfs_attr_leaf.c +6 -0
@@ -2918,3 +2948,57 @@ xfs_attr3_leaf_flipflags(
 
 	return error;
 }
+
+/*
+ * On a leaf entry, check to see if the INCOMPLETE flag is cleared
+ * in args->blkno/index and set in args->blkno2/index2.
+ * Note that they could be in different blocks, or in the same block.
+ *

A sentence or two on what this check is for would be helpful. Relocation of an xattr or something..?

Quoted 15 lines
fs/xfs/libxfs/xfs_attr_leaf.c +15 -0
+ * isflipped is set to true if flags are flipped or false otherwise
+ */
+int
+xfs_attr3_leaf_flagsflipped(
+	struct xfs_da_args		*args,
+	bool				*isflipped)
+{
+	struct xfs_attr_leafblock	*leaf1;
+	struct xfs_attr_leafblock	*leaf2;
+	struct xfs_attr_leaf_entry	*entry1;
+	struct xfs_attr_leaf_entry	*entry2;
+	struct xfs_buf			*bp1;
+	struct xfs_buf			*bp2;
+	struct xfs_inode		*dp = args->dp;
+	int				error = 0;

fs/xfs/libxfs/xfs_attr_leaf.c xfs_attr3_leaf_flipflags( · line 2981

Quoted 10 lines
fs/xfs/libxfs/xfs_attr_leaf.c +10 -0
+
+	trace_xfs_attr_leaf_flipflags(args);
+
+	/*
+	 * Read the block containing the "old" attr
+	 */
+	error = xfs_attr3_leaf_read(args->trans, dp, args->blkno, -1, &bp1);
+	if (error)
+		return error;
+

Similar comments about the tracepoint, -1 usage and buffers.

Brian

Quoted 40 lines
fs/xfs/libxfs/xfs_attr_leaf.c +23 -0
+	/*
+	 * Read the block containing the "new" attr, if it is different
+	 */
+	if (args->blkno2 != args->blkno) {
+		error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno2,
+					   -1, &bp2);
+		if (error)
+			return error;
+	} else {
+		bp2 = bp1;
+	}
+
+	leaf1 = bp1->b_addr;
+	entry1 = &xfs_attr3_leaf_entryp(leaf1)[args->index];
+
+	leaf2 = bp2->b_addr;
+	entry2 = &xfs_attr3_leaf_entryp(leaf2)[args->index2];
+
+	*isflipped = (((entry1->flags & XFS_ATTR_INCOMPLETE) == 0) &&
+		      (entry2->flags & XFS_ATTR_INCOMPLETE));
+
+	return 0;
+}
fs/xfs/libxfs/xfs_attr_leaf.h +2 -0
index 58e9327..d82229b 100644
@@ -57,7 +57,9 @@ int	xfs_attr3_leaf_to_shortform(struct xfs_buf *bp,
 				   struct xfs_da_args *args, int forkoff);
 int	xfs_attr3_leaf_clearflag(struct xfs_da_args *args);
 int	xfs_attr3_leaf_setflag(struct xfs_da_args *args);
+int	xfs_attr3_leaf_flag_is_set(struct xfs_da_args *args, bool *isset);
 int	xfs_attr3_leaf_flipflags(struct xfs_da_args *args);
+int	xfs_attr3_leaf_flagsflipped(struct xfs_da_args *args, bool *isflipped);
 
 /*
  * Routines used for growing the Btree.
Signature · 1 line
2.7.4
#34 lore raw

Re: [PATCH v3 10/19] xfs: Add xfs_attr3_leaf helper functions

Quoted 31 lines · Brian Foster
Quoted 30 lines · Allison Collins

And new helper functions xfs_attr3_leaf_flag_is_set and xfs_attr3_leaf_flagsflipped. These routines check to see if xfs_attr3_leaf_setflag or xfs_attr3_leaf_flipflags have already been run. We will need this later for delayed attributes since routines may be recalled several times when -EAGAIN is returned.

---
  fs/xfs/libxfs/xfs_attr_leaf.c | 84 +++++++++++++++++++++++++++++++++++++++++++
  fs/xfs/libxfs/xfs_attr_leaf.h |  2 ++
  2 files changed, 86 insertions(+)
fs/xfs/libxfs/xfs_attr_leaf.c +9 -0
index bcd86c3..79650c9 100644
@@ -2757,6 +2757,36 @@ xfs_attr3_leaf_clearflag(
  }
 
  /*
+ * Check if the INCOMPLETE flag on an entry in a leaf block is set.
+ */
+int
+xfs_attr3_leaf_flag_is_set(
+	struct xfs_da_args		*args,
+	bool				*isset)
+{
+	struct xfs_attr_leafblock	*leaf;
+	struct xfs_attr_leaf_entry	*entry;
Quoted 9 lines

fs/xfs/libxfs/xfs_attr_leaf.c xfs_attr3_leaf_clearflag( · line 2774

Quoted 6 lines
fs/xfs/libxfs/xfs_attr_leaf.c +6 -0
+	struct xfs_buf			*bp;
+	struct xfs_inode		*dp = args->dp;
+	int				error = 0;
+
+	trace_xfs_attr_leaf_setflag(args);
+

Tracepoint seems misplaced.. This is just a flag checking helper, right?

Yes, I likely scooped it up with the rest to consolidate code, but it probably should have stayed in setflag

Quoted 6 lines

fs/xfs/libxfs/xfs_attr_leaf.c xfs_attr3_leaf_clearflag( · line 2777

Quoted 3 lines
fs/xfs/libxfs/xfs_attr_leaf.c +3 -0
+	/*
+	 * Set up the operation.
+	 */

Not sure what the comment means. The code seems self-explanatory here anyways, so you could probably just drop it.

Alrighty then, will clean out

Quoted 4 lines

fs/xfs/libxfs/xfs_attr_leaf.c xfs_attr3_leaf_clearflag( · line 2778

Quoted 2 lines
fs/xfs/libxfs/xfs_attr_leaf.c +1 -0
+	error = xfs_attr3_leaf_read(args->trans, dp, args->blkno, -1, &bp);

Didn't you create a #define for this -1 earlier in the series?

Yes, I missed applying it here. Will fix

Quoted 12 lines

fs/xfs/libxfs/xfs_attr_leaf.c xfs_attr3_leaf_clearflag( · line 2786

Quoted 9 lines
fs/xfs/libxfs/xfs_attr_leaf.c +8 -0
+	if (error)
+		return error;
+
+	leaf = bp->b_addr;
+	entry = &xfs_attr3_leaf_entryp(leaf)[args->index];
+
+	*isset = ((entry->flags & XFS_ATTR_INCOMPLETE) != 0);
+	return 0;

What about bp? Should we release it before returning? If not, the comment above the function should elaborate.

I think you're probably right. It's only used in the delayed code path and I think the logging routines may have done the release so I didn't notice

Quoted 9 lines
Quoted 9 lines
fs/xfs/libxfs/xfs_attr_leaf.c +3 -0
+}
+
+/*
   * Set the INCOMPLETE flag on an entry in a leaf block.
   */
  int
@@ -2918,3 +2948,57 @@ xfs_attr3_leaf_flipflags(
 
Quoted 11 lines

fs/xfs/libxfs/xfs_attr_leaf.c xfs_attr3_leaf_flipflags( · line 2956

Quoted 8 lines
fs/xfs/libxfs/xfs_attr_leaf.c +6 -0
  	return error;
  }
+
+/*
+ * On a leaf entry, check to see if the INCOMPLETE flag is cleared
+ * in args->blkno/index and set in args->blkno2/index2.
+ * Note that they could be in different blocks, or in the same block.
+ *

A sentence or two on what this check is for would be helpful. Relocation of an xattr or something..?

It's just a check to see if the two flags mentioned above have been swapped before proceeding to swap them with xfs_attr3_leaf_flipflags. I believe it's used in attr renames. I will add in some extra commentary to reference the other routine, that might help make a little more sense.

Quoted 20 lines
Quoted 20 lines
fs/xfs/libxfs/xfs_attr_leaf.c +19 -0
+ * isflipped is set to true if flags are flipped or false otherwise
+ */
+int
+xfs_attr3_leaf_flagsflipped(
+	struct xfs_da_args		*args,
+	bool				*isflipped)
+{
+	struct xfs_attr_leafblock	*leaf1;
+	struct xfs_attr_leafblock	*leaf2;
+	struct xfs_attr_leaf_entry	*entry1;
+	struct xfs_attr_leaf_entry	*entry2;
+	struct xfs_buf			*bp1;
+	struct xfs_buf			*bp2;
+	struct xfs_inode		*dp = args->dp;
+	int				error = 0;
+
+	trace_xfs_attr_leaf_flipflags(args);
+
+	/*
Quoted 8 lines

fs/xfs/libxfs/xfs_attr_leaf.c xfs_attr3_leaf_flipflags( · line 2981

Quoted 6 lines
fs/xfs/libxfs/xfs_attr_leaf.c +6 -0
+	 * Read the block containing the "old" attr
+	 */
+	error = xfs_attr3_leaf_read(args->trans, dp, args->blkno, -1, &bp1);
+	if (error)
+		return error;
+

Similar comments about the tracepoint, -1 usage and buffers.

Sure, will fix. Thanks!

Allison

Quoted 43 lines

Brian

Quoted 40 lines
fs/xfs/libxfs/xfs_attr_leaf.c +23 -0
+	/*
+	 * Read the block containing the "new" attr, if it is different
+	 */
+	if (args->blkno2 != args->blkno) {
+		error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno2,
+					   -1, &bp2);
+		if (error)
+			return error;
+	} else {
+		bp2 = bp1;
+	}
+
+	leaf1 = bp1->b_addr;
+	entry1 = &xfs_attr3_leaf_entryp(leaf1)[args->index];
+
+	leaf2 = bp2->b_addr;
+	entry2 = &xfs_attr3_leaf_entryp(leaf2)[args->index2];
+
+	*isflipped = (((entry1->flags & XFS_ATTR_INCOMPLETE) == 0) &&
+		      (entry2->flags & XFS_ATTR_INCOMPLETE));
+
+	return 0;
+}
fs/xfs/libxfs/xfs_attr_leaf.h +2 -0
index 58e9327..d82229b 100644
@@ -57,7 +57,9 @@ int	xfs_attr3_leaf_to_shortform(struct xfs_buf *bp,
  				   struct xfs_da_args *args, int forkoff);
  int	xfs_attr3_leaf_clearflag(struct xfs_da_args *args);
  int	xfs_attr3_leaf_setflag(struct xfs_da_args *args);
+int	xfs_attr3_leaf_flag_is_set(struct xfs_da_args *args, bool *isset);
  int	xfs_attr3_leaf_flipflags(struct xfs_da_args *args);
+int	xfs_attr3_leaf_flagsflipped(struct xfs_da_args *args, bool *isflipped);
 
  /*
   * Routines used for growing the Btree.
Signature · 1 line
2.7.4
#35 lore raw

PATCH v3 11/19 xfs: Factor out xfs_attr_rmtval_invalidate

In reply to Allison Collins

Because new delayed attribute routines cannot roll transactions, we carve off the parts of xfs_attr_rmtval_remove that we can use. This will help to reduce repetitive code later when we introduce delayed attributes.

---
 fs/xfs/libxfs/xfs_attr_remote.c | 29 +++++++++++++++++++++--------
 fs/xfs/libxfs/xfs_attr_remote.h |  1 +
 2 files changed, 22 insertions(+), 8 deletions(-)
fs/xfs/libxfs/xfs_attr_remote.c +21 -8
index 080a284..1b13795 100644
@@ -589,21 +589,14 @@ xfs_attr_rmtval_set_value(
 	return 0;
 }
 
-/*
- * Remove the value associated with an attribute by deleting the
- * out-of-line buffer that it is stored on.
- */
 int
-xfs_attr_rmtval_remove(
+xfs_attr_rmtval_invalidate(
 	struct xfs_da_args	*args)
 {
 	struct xfs_mount	*mp = args->dp->i_mount;
 	xfs_dablk_t		lblkno;
 	int			blkcnt;
 	int			error;
-	int			done;
-
-	trace_xfs_attr_rmtval_remove(args);
 
 	/*
 	 * Roll through the "value", invalidating the attribute value's blocks.
@@ -645,7 +638,27 @@ xfs_attr_rmtval_remove(
 		lblkno += map.br_blockcount;
 		blkcnt -= map.br_blockcount;
 	}
+	return 0;
+}
 
+/*
+ * Remove the value associated with an attribute by deleting the
+ * out-of-line buffer that it is stored on.
+ */
+int
+xfs_attr_rmtval_remove(
+	struct xfs_da_args      *args)
+{
+	xfs_dablk_t		lblkno;
+	int			blkcnt;
+	int			error = 0;
+	int			done = 0;
+
+	trace_xfs_attr_rmtval_remove(args);
+
+	error = xfs_attr_rmtval_invalidate(args);
+	if (error)
+		return error;
 	/*
 	 * Keep de-allocating extents until the remote-value region is gone.
 	 */
fs/xfs/libxfs/xfs_attr_remote.h +1 -0
index cd7670d..b6fd35a 100644
@@ -11,6 +11,7 @@ int xfs_attr3_rmt_blocks(struct xfs_mount *mp, int attrlen);
 int xfs_attr_rmtval_get(struct xfs_da_args *args);
 int xfs_attr_rmtval_set(struct xfs_da_args *args);
 int xfs_attr_rmtval_remove(struct xfs_da_args *args);
+int xfs_attr_rmtval_invalidate(struct xfs_da_args *args);
 int xfs_attr_rmtval_set_value(struct xfs_da_args *args);
 int xfs_attr_rmt_find_hole(struct xfs_da_args *args);
 #endif /* __XFS_ATTR_REMOTE_H__ */
Signature · 1 line
2.7.4
Reviewed-by on v3 11/19
#36 lore raw

Re: [PATCH v3 11/19] xfs: Factor out xfs_attr_rmtval_invalidate

Quoted 16 lines · Allison Collins

Because new delayed attribute routines cannot roll transactions, we carve off the parts of xfs_attr_rmtval_remove that we can use. This will help to reduce repetitive code later when we introduce delayed attributes.

---
 fs/xfs/libxfs/xfs_attr_remote.c | 29 +++++++++++++++++++++--------
 fs/xfs/libxfs/xfs_attr_remote.h |  1 +
 2 files changed, 22 insertions(+), 8 deletions(-)
fs/xfs/libxfs/xfs_attr_remote.c +0 -0
index 080a284..1b13795 100644

...

Quoted 9 lines
fs/xfs/libxfs/xfs_attr_remote.c +4 -0
@@ -645,7 +638,27 @@ xfs_attr_rmtval_remove(
 		lblkno += map.br_blockcount;
 		blkcnt -= map.br_blockcount;
 	}
+	return 0;
+}
 
+/*
+ * Remove the value associated with an attribute by deleting the

fs/xfs/libxfs/xfs_attr_remote.c xfs_attr_rmtval_remove( · line 655

Quoted 10 lines
fs/xfs/libxfs/xfs_attr_remote.c +10 -0
+ * out-of-line buffer that it is stored on.
+ */
+int
+xfs_attr_rmtval_remove(
+	struct xfs_da_args      *args)
+{
+	xfs_dablk_t		lblkno;
+	int			blkcnt;
+	int			error = 0;
+	int			done = 0;

Nit: with done initialized here, you can remove the done = 0 further down in the function. That aside:

Quoted 24 lines
fs/xfs/libxfs/xfs_attr_remote.c +6 -0
+
+	trace_xfs_attr_rmtval_remove(args);
+
+	error = xfs_attr_rmtval_invalidate(args);
+	if (error)
+		return error;
 	/*
 	 * Keep de-allocating extents until the remote-value region is gone.
 	 */
fs/xfs/libxfs/xfs_attr_remote.h +1 -0
index cd7670d..b6fd35a 100644
@@ -11,6 +11,7 @@ int xfs_attr3_rmt_blocks(struct xfs_mount *mp, int attrlen);
 int xfs_attr_rmtval_get(struct xfs_da_args *args);
 int xfs_attr_rmtval_set(struct xfs_da_args *args);
 int xfs_attr_rmtval_remove(struct xfs_da_args *args);
+int xfs_attr_rmtval_invalidate(struct xfs_da_args *args);
 int xfs_attr_rmtval_set_value(struct xfs_da_args *args);
 int xfs_attr_rmt_find_hole(struct xfs_da_args *args);
 #endif /* __XFS_ATTR_REMOTE_H__ */
Signature · 1 line
2.7.4
#37 lore raw

Re: [PATCH v3 11/19] xfs: Factor out xfs_attr_rmtval_invalidate

Quoted 41 lines · Brian Foster
Quoted 16 lines · Allison Collins

Because new delayed attribute routines cannot roll transactions, we carve off the parts of xfs_attr_rmtval_remove that we can use. This will help to reduce repetitive code later when we introduce delayed attributes.

---
  fs/xfs/libxfs/xfs_attr_remote.c | 29 +++++++++++++++++++++--------
  fs/xfs/libxfs/xfs_attr_remote.h |  1 +
  2 files changed, 22 insertions(+), 8 deletions(-)
fs/xfs/libxfs/xfs_attr_remote.c +0 -0
index 080a284..1b13795 100644

...

Quoted 9 lines
fs/xfs/libxfs/xfs_attr_remote.c +4 -0
@@ -645,7 +638,27 @@ xfs_attr_rmtval_remove(
  		lblkno += map.br_blockcount;
  		blkcnt -= map.br_blockcount;
  	}
+	return 0;
+}
 
+/*
+ * Remove the value associated with an attribute by deleting the

fs/xfs/libxfs/xfs_attr_remote.c xfs_attr_rmtval_remove( · line 655

Quoted 10 lines
fs/xfs/libxfs/xfs_attr_remote.c +10 -0
+ * out-of-line buffer that it is stored on.
+ */
+int
+xfs_attr_rmtval_remove(
+	struct xfs_da_args      *args)
+{
+	xfs_dablk_t		lblkno;
+	int			blkcnt;
+	int			error = 0;
+	int			done = 0;

Nit: with done initialized here, you can remove the done = 0 further down in the function. That aside:

Quoted 1 line

Ok, I will pick out that little bit. Thank you for the reviews!

Allison

Quoted 25 lines
Quoted 25 lines
fs/xfs/libxfs/xfs_attr_remote.c +6 -0
+
+	trace_xfs_attr_rmtval_remove(args);
+
+	error = xfs_attr_rmtval_invalidate(args);
+	if (error)
+		return error;
  	/*
  	 * Keep de-allocating extents until the remote-value region is gone.
  	 */
fs/xfs/libxfs/xfs_attr_remote.h +1 -0
index cd7670d..b6fd35a 100644
@@ -11,6 +11,7 @@ int xfs_attr3_rmt_blocks(struct xfs_mount *mp, int attrlen);
  int xfs_attr_rmtval_get(struct xfs_da_args *args);
  int xfs_attr_rmtval_set(struct xfs_da_args *args);
  int xfs_attr_rmtval_remove(struct xfs_da_args *args);
+int xfs_attr_rmtval_invalidate(struct xfs_da_args *args);
  int xfs_attr_rmtval_set_value(struct xfs_da_args *args);
  int xfs_attr_rmt_find_hole(struct xfs_da_args *args);
  #endif /* __XFS_ATTR_REMOTE_H__ */
Signature · 1 line
2.7.4
#38 lore raw

PATCH v3 12/19 xfs: Factor up trans roll in xfs_attr3_leaf_clearflag

In reply to Allison Collins

New delayed allocation routines cannot be handling transactions so factor them up into the calling functions

---
 fs/xfs/libxfs/xfs_attr.c      | 14 ++++++++++++++
 fs/xfs/libxfs/xfs_attr_leaf.c |  5 +----
 2 files changed, 15 insertions(+), 4 deletions(-)
fs/xfs/libxfs/xfs_attr.c +14 -0
index 5e5b688..781dd8a 100644
@@ -783,6 +783,12 @@ xfs_attr_leaf_addname(struct xfs_da_args	*args)
 		 * Added a "remote" value, just clear the incomplete flag.
 		 */
 		error = xfs_attr3_leaf_clearflag(args);
+
+		/*
+		 * Commit the flag value change and start the next trans in
+		 * series.
+		 */
+		error = xfs_trans_roll_inode(&args->trans, args->dp);
 	}
 	return error;
 }
@@ -1140,6 +1146,14 @@ xfs_attr_node_addname(
 		error = xfs_attr3_leaf_clearflag(args);
 		if (error)
 			goto out;
+
+		 /*
+		  * Commit the flag value change and start the next trans in
+		  * series.
+		  */
+		error = xfs_trans_roll_inode(&args->trans, args->dp);
+		if (error)
+			goto out;
 	}
 	retval = error = 0;
 
fs/xfs/libxfs/xfs_attr_leaf.c +1 -4
index 79650c9..786b851 100644
@@ -2750,10 +2750,7 @@ xfs_attr3_leaf_clearflag(
 			 XFS_DA_LOGRANGE(leaf, name_rmt, sizeof(*name_rmt)));
 	}
 
-	/*
-	 * Commit the flag value change and start the next trans in series.
-	 */
-	return xfs_trans_roll_inode(&args->trans, args->dp);
+	return error;
 }
 
 /*
Signature · 1 line
2.7.4
#39 lore raw

Re: [PATCH v3 12/19] xfs: Factor up trans roll in xfs_attr3_leaf_clearflag

Quoted 14 lines · Allison Collins

New delayed allocation routines cannot be handling transactions so factor them up into the calling functions

---
 fs/xfs/libxfs/xfs_attr.c      | 14 ++++++++++++++
 fs/xfs/libxfs/xfs_attr_leaf.c |  5 +----
 2 files changed, 15 insertions(+), 4 deletions(-)
fs/xfs/libxfs/xfs_attr.c +0 -0
index 5e5b688..781dd8a 100644

fs/xfs/libxfs/xfs_attr.c xfs_attr_leaf_addname(struct xfs_da_args *args) · line 785

Quoted 3 lines
fs/xfs/libxfs/xfs_attr.c +0 -0
@@ -783,6 +783,12 @@ xfs_attr_leaf_addname(struct xfs_da_args	*args)
 		 * Added a "remote" value, just clear the incomplete flag.
 		 */
 		error = xfs_attr3_leaf_clearflag(args);

Need an error check here now that this isn't the last call in the function before we return.

Brian

Quoted 43 lines
fs/xfs/libxfs/xfs_attr.c +14 -0
+
+		/*
+		 * Commit the flag value change and start the next trans in
+		 * series.
+		 */
+		error = xfs_trans_roll_inode(&args->trans, args->dp);
 	}
 	return error;
 }
@@ -1140,6 +1146,14 @@ xfs_attr_node_addname(
 		error = xfs_attr3_leaf_clearflag(args);
 		if (error)
 			goto out;
+
+		 /*
+		  * Commit the flag value change and start the next trans in
+		  * series.
+		  */
+		error = xfs_trans_roll_inode(&args->trans, args->dp);
+		if (error)
+			goto out;
 	}
 	retval = error = 0;
 
fs/xfs/libxfs/xfs_attr_leaf.c +1 -4
index 79650c9..786b851 100644
@@ -2750,10 +2750,7 @@ xfs_attr3_leaf_clearflag(
 			 XFS_DA_LOGRANGE(leaf, name_rmt, sizeof(*name_rmt)));
 	}
 
-	/*
-	 * Commit the flag value change and start the next trans in series.
-	 */
-	return xfs_trans_roll_inode(&args->trans, args->dp);
+	return error;
 }
 
 /*
Signature · 1 line
2.7.4
#40 lore raw

Re: [PATCH v3 12/19] xfs: Factor up trans roll in xfs_attr3_leaf_clearflag

Quoted 10 lines · Brian Foster
Quoted 9 lines · Allison Collins

New delayed allocation routines cannot be handling transactions so factor them up into the calling functions

---
  fs/xfs/libxfs/xfs_attr.c      | 14 ++++++++++++++
  fs/xfs/libxfs/xfs_attr_leaf.c |  5 +----
  2 files changed, 15 insertions(+), 4 deletions(-)
Quoted 9 lines

fs/xfs/libxfs/xfs_attr.c xfs_attr_leaf_addname(struct xfs_da_args *args) · line 785

Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c +0 -0
index 5e5b688..781dd8a 100644
@@ -783,6 +783,12 @@ xfs_attr_leaf_addname(struct xfs_da_args	*args)
  		 * Added a "remote" value, just clear the incomplete flag.
  		 */
  		error = xfs_attr3_leaf_clearflag(args);

Alrighty, will fix.
Allison

Quoted 48 lines

Need an error check here now that this isn't the last call in the function before we return.

Brian

Quoted 43 lines
fs/xfs/libxfs/xfs_attr.c +14 -0
+
+		/*
+		 * Commit the flag value change and start the next trans in
+		 * series.
+		 */
+		error = xfs_trans_roll_inode(&args->trans, args->dp);
  	}
  	return error;
  }
@@ -1140,6 +1146,14 @@ xfs_attr_node_addname(
  		error = xfs_attr3_leaf_clearflag(args);
  		if (error)
  			goto out;
+
+		 /*
+		  * Commit the flag value change and start the next trans in
+		  * series.
+		  */
+		error = xfs_trans_roll_inode(&args->trans, args->dp);
+		if (error)
+			goto out;
  	}
  	retval = error = 0;
 
fs/xfs/libxfs/xfs_attr_leaf.c +1 -4
index 79650c9..786b851 100644
@@ -2750,10 +2750,7 @@ xfs_attr3_leaf_clearflag(
  			 XFS_DA_LOGRANGE(leaf, name_rmt, sizeof(*name_rmt)));
  	}
 
-	/*
-	 * Commit the flag value change and start the next trans in series.
-	 */
-	return xfs_trans_roll_inode(&args->trans, args->dp);
+	return error;
  }
 
  /*
Signature · 1 line
2.7.4
#41 lore raw

PATCH v3 13/19 xfs: Add delay context to xfs_da_args

In reply to Allison Collins

This patch adds a new struct xfs_delay_context, which we will use to keep track of the current state of a delayed attribute operation.

The flags member is used to track various operations that are in progress so that we know not to repeat them, and resume where we left off before EAGAIN was returned to cycle out the transaction. Other members take the place of local variables that need to retain their values across multiple function recalls.

---
 fs/xfs/libxfs/xfs_da_btree.h | 23 +++++++++++++++++++++++
 fs/xfs/scrub/common.c        |  2 ++
 fs/xfs/xfs_acl.c             |  2 ++
 fs/xfs/xfs_attr_list.c       |  1 +
 fs/xfs/xfs_ioctl.c           |  2 ++
 fs/xfs/xfs_ioctl32.c         |  2 ++
 fs/xfs/xfs_iops.c            |  2 ++
 fs/xfs/xfs_xattr.c           |  1 +
 8 files changed, 35 insertions(+)
fs/xfs/libxfs/xfs_da_btree.h +23 -0
index bed4f40..ebe1295 100644
@@ -42,6 +42,28 @@ enum xfs_dacmp {
 	XFS_CMP_CASE		/* names are same but differ in case */
 };
 
+#define		XFS_DC_INIT		0x01 /* Init delay info */
+#define		XFS_DC_FOUND_LBLK	0x02 /* We found leaf blk for attr */
+#define		XFS_DC_FOUND_NBLK	0x04 /* We found node blk for attr */
+#define		XFS_DC_ALLOC_LEAF	0x08 /* We are allocating leaf blocks */
+#define		XFS_DC_ALLOC_NODE	0x10 /* We are allocating node blocks */
+#define		XFS_DC_RM_LEAF_BLKS	0x20 /* We are removing leaf blocks */
+#define		XFS_DC_RM_NODE_BLKS	0x40 /* We are removing node blocks */
+
+/*
+ * Context used for keeping track of delayed attribute operations
+ */
+struct xfs_delay_context {
+	unsigned int		flags;
+	struct xfs_buf		*leaf_bp;
+	struct xfs_bmbt_irec	map;
+	xfs_dablk_t		lblkno;
+	xfs_fileoff_t		lfileoff;
+	int			blkcnt;
+	struct xfs_da_state	*state;
+	struct xfs_da_state_blk *blk;
+};
+
 /*
  * Structure to ease passing around component names.
  */
@@ -69,6 +91,7 @@ typedef struct xfs_da_args {
 	int		rmtvaluelen2;	/* remote attr value length in bytes */
 	int		op_flags;	/* operation flags */
 	enum xfs_dacmp	cmpresult;	/* name compare result for lookups */
+	struct xfs_delay_context  dc;	/* context used for delay attr ops */
 } xfs_da_args_t;
 
 /*
fs/xfs/scrub/common.c +2 -0
index 1887605..9a649d1 100644
@@ -24,6 +24,8 @@
 #include "xfs_rmap_btree.h"
 #include "xfs_log.h"
 #include "xfs_trans_priv.h"
+#include "xfs_da_format.h"
+#include "xfs_da_btree.h"
 #include "xfs_attr.h"
 #include "xfs_reflink.h"
 #include "scrub/scrub.h"
fs/xfs/xfs_acl.c +2 -0
index f8fb6e10..4e85b38 100644
@@ -10,6 +10,8 @@
 #include "xfs_trans_resv.h"
 #include "xfs_mount.h"
 #include "xfs_inode.h"
+#include "xfs_da_format.h"
+#include "xfs_da_btree.h"
 #include "xfs_attr.h"
 #include "xfs_trace.h"
 #include <linux/posix_acl_xattr.h>
fs/xfs/xfs_attr_list.c +1 -0
index 00758fd..467c53c 100644
@@ -12,6 +12,7 @@
 #include "xfs_trans_resv.h"
 #include "xfs_mount.h"
 #include "xfs_da_format.h"
+#include "xfs_da_btree.h"
 #include "xfs_inode.h"
 #include "xfs_trans.h"
 #include "xfs_bmap.h"
fs/xfs/xfs_ioctl.c +2 -0
index 626420d..2cabdc2 100644
@@ -15,6 +15,8 @@
 #include "xfs_iwalk.h"
 #include "xfs_itable.h"
 #include "xfs_error.h"
+#include "xfs_da_format.h"
+#include "xfs_da_btree.h"
 #include "xfs_attr.h"
 #include "xfs_bmap.h"
 #include "xfs_bmap_util.h"
fs/xfs/xfs_ioctl32.c +2 -0
index 1e08bf7..7153780 100644
@@ -17,6 +17,8 @@
 #include "xfs_itable.h"
 #include "xfs_fsops.h"
 #include "xfs_rtalloc.h"
+#include "xfs_da_format.h"
+#include "xfs_da_btree.h"
 #include "xfs_attr.h"
 #include "xfs_ioctl.h"
 #include "xfs_ioctl32.h"
fs/xfs/xfs_iops.c +2 -0
index 469e8e2..57de5f1 100644
@@ -13,6 +13,8 @@
 #include "xfs_inode.h"
 #include "xfs_acl.h"
 #include "xfs_quota.h"
+#include "xfs_da_format.h"
+#include "xfs_da_btree.h"
 #include "xfs_attr.h"
 #include "xfs_trans.h"
 #include "xfs_trace.h"
fs/xfs/xfs_xattr.c +1 -0
index 6309da4..470e605 100644
@@ -10,6 +10,7 @@
 #include "xfs_log_format.h"
 #include "xfs_da_format.h"
 #include "xfs_inode.h"
+#include "xfs_da_btree.h"
 #include "xfs_attr.h"
 
 #include <linux/posix_acl_xattr.h>
Signature · 1 line
2.7.4
#42 lore raw

Re: [PATCH v3 13/19] xfs: Add delay context to xfs_da_args

Quoted 11 lines · Allison Collins

This patch adds a new struct xfs_delay_context, which we will use to keep track of the current state of a delayed attribute operation.

The flags member is used to track various operations that are in progress so that we know not to repeat them, and resume where we left off before EAGAIN was returned to cycle out the transaction. Other members take the place of local variables that need to retain their values across multiple function recalls.

Quoted 2 lines

---

Ok, I'll have to get further along in the usage of these bits to fully grok this one. One quick note in the meantime...

Quoted 30 lines
 fs/xfs/libxfs/xfs_da_btree.h | 23 +++++++++++++++++++++++
 fs/xfs/scrub/common.c        |  2 ++
 fs/xfs/xfs_acl.c             |  2 ++
 fs/xfs/xfs_attr_list.c       |  1 +
 fs/xfs/xfs_ioctl.c           |  2 ++
 fs/xfs/xfs_ioctl32.c         |  2 ++
 fs/xfs/xfs_iops.c            |  2 ++
 fs/xfs/xfs_xattr.c           |  1 +
 8 files changed, 35 insertions(+)
fs/xfs/libxfs/xfs_da_btree.h +12 -0
index bed4f40..ebe1295 100644
@@ -42,6 +42,28 @@ enum xfs_dacmp {
 	XFS_CMP_CASE		/* names are same but differ in case */
 };
 
+#define		XFS_DC_INIT		0x01 /* Init delay info */
+#define		XFS_DC_FOUND_LBLK	0x02 /* We found leaf blk for attr */
+#define		XFS_DC_FOUND_NBLK	0x04 /* We found node blk for attr */
+#define		XFS_DC_ALLOC_LEAF	0x08 /* We are allocating leaf blocks */
+#define		XFS_DC_ALLOC_NODE	0x10 /* We are allocating node blocks */
+#define		XFS_DC_RM_LEAF_BLKS	0x20 /* We are removing leaf blocks */
+#define		XFS_DC_RM_NODE_BLKS	0x40 /* We are removing node blocks */
+
+/*
+ * Context used for keeping track of delayed attribute operations
+ */
+struct xfs_delay_context {

fs/xfs/libxfs/xfs_da_btree.h enum xfs_dacmp { · line 66

Quoted 10 lines
fs/xfs/libxfs/xfs_da_btree.h +10 -0
+	unsigned int		flags;
+	struct xfs_buf		*leaf_bp;
+	struct xfs_bmbt_irec	map;
+	xfs_dablk_t		lblkno;
+	xfs_fileoff_t		lfileoff;
+	int			blkcnt;
+	struct xfs_da_state	*state;
+	struct xfs_da_state_blk *blk;
+};
+

The mixed size of the various fields leaves some holes in the structure. See 'pahole xfs.ko' output for how this struct could be reordered to reduce the overall size a bit..

Brian

Quoted 103 lines
fs/xfs/libxfs/xfs_da_btree.h +1 -0
 /*
  * Structure to ease passing around component names.
  */
@@ -69,6 +91,7 @@ typedef struct xfs_da_args {
 	int		rmtvaluelen2;	/* remote attr value length in bytes */
 	int		op_flags;	/* operation flags */
 	enum xfs_dacmp	cmpresult;	/* name compare result for lookups */
+	struct xfs_delay_context  dc;	/* context used for delay attr ops */
 } xfs_da_args_t;
 
 /*
fs/xfs/scrub/common.c +2 -0
index 1887605..9a649d1 100644
@@ -24,6 +24,8 @@
 #include "xfs_rmap_btree.h"
 #include "xfs_log.h"
 #include "xfs_trans_priv.h"
+#include "xfs_da_format.h"
+#include "xfs_da_btree.h"
 #include "xfs_attr.h"
 #include "xfs_reflink.h"
 #include "scrub/scrub.h"
fs/xfs/xfs_acl.c +2 -0
index f8fb6e10..4e85b38 100644
@@ -10,6 +10,8 @@
 #include "xfs_trans_resv.h"
 #include "xfs_mount.h"
 #include "xfs_inode.h"
+#include "xfs_da_format.h"
+#include "xfs_da_btree.h"
 #include "xfs_attr.h"
 #include "xfs_trace.h"
 #include <linux/posix_acl_xattr.h>
fs/xfs/xfs_attr_list.c +1 -0
index 00758fd..467c53c 100644
@@ -12,6 +12,7 @@
 #include "xfs_trans_resv.h"
 #include "xfs_mount.h"
 #include "xfs_da_format.h"
+#include "xfs_da_btree.h"
 #include "xfs_inode.h"
 #include "xfs_trans.h"
 #include "xfs_bmap.h"
fs/xfs/xfs_ioctl.c +2 -0
index 626420d..2cabdc2 100644
@@ -15,6 +15,8 @@
 #include "xfs_iwalk.h"
 #include "xfs_itable.h"
 #include "xfs_error.h"
+#include "xfs_da_format.h"
+#include "xfs_da_btree.h"
 #include "xfs_attr.h"
 #include "xfs_bmap.h"
 #include "xfs_bmap_util.h"
fs/xfs/xfs_ioctl32.c +2 -0
index 1e08bf7..7153780 100644
@@ -17,6 +17,8 @@
 #include "xfs_itable.h"
 #include "xfs_fsops.h"
 #include "xfs_rtalloc.h"
+#include "xfs_da_format.h"
+#include "xfs_da_btree.h"
 #include "xfs_attr.h"
 #include "xfs_ioctl.h"
 #include "xfs_ioctl32.h"
fs/xfs/xfs_iops.c +2 -0
index 469e8e2..57de5f1 100644
@@ -13,6 +13,8 @@
 #include "xfs_inode.h"
 #include "xfs_acl.h"
 #include "xfs_quota.h"
+#include "xfs_da_format.h"
+#include "xfs_da_btree.h"
 #include "xfs_attr.h"
 #include "xfs_trans.h"
 #include "xfs_trace.h"
fs/xfs/xfs_xattr.c +1 -0
index 6309da4..470e605 100644
@@ -10,6 +10,7 @@
 #include "xfs_log_format.h"
 #include "xfs_da_format.h"
 #include "xfs_inode.h"
+#include "xfs_da_btree.h"
 #include "xfs_attr.h"
 
 #include <linux/posix_acl_xattr.h>
Signature · 1 line
2.7.4
#43 lore raw

Re: [PATCH v3 13/19] xfs: Add delay context to xfs_da_args

Quoted 12 lines · Brian Foster
Quoted 11 lines · Allison Collins

This patch adds a new struct xfs_delay_context, which we will use to keep track of the current state of a delayed attribute operation.

The flags member is used to track various operations that are in progress so that we know not to repeat them, and resume where we left off before EAGAIN was returned to cycle out the transaction. Other members take the place of local variables that need to retain their values across multiple function recalls.

Quoted 5 lines
Quoted 2 lines

---

Ok, I'll have to get further along in the usage of these bits to fully grok this one. One quick note in the meantime...

Ok, yeah a lot of whats in here is dependent on what we decide in the next patch, but I will take a look through the pahole output. Thanks!

Allison

Quoted 151 lines
Quoted 31 lines
  fs/xfs/libxfs/xfs_da_btree.h | 23 +++++++++++++++++++++++
  fs/xfs/scrub/common.c        |  2 ++
  fs/xfs/xfs_acl.c             |  2 ++
  fs/xfs/xfs_attr_list.c       |  1 +
  fs/xfs/xfs_ioctl.c           |  2 ++
  fs/xfs/xfs_ioctl32.c         |  2 ++
  fs/xfs/xfs_iops.c            |  2 ++
  fs/xfs/xfs_xattr.c           |  1 +
  8 files changed, 35 insertions(+)
fs/xfs/libxfs/xfs_da_btree.h +12 -0
index bed4f40..ebe1295 100644
@@ -42,6 +42,28 @@ enum xfs_dacmp {
  	XFS_CMP_CASE		/* names are same but differ in case */
  };
 
+#define		XFS_DC_INIT		0x01 /* Init delay info */
+#define		XFS_DC_FOUND_LBLK	0x02 /* We found leaf blk for attr */
+#define		XFS_DC_FOUND_NBLK	0x04 /* We found node blk for attr */
+#define		XFS_DC_ALLOC_LEAF	0x08 /* We are allocating leaf blocks */
+#define		XFS_DC_ALLOC_NODE	0x10 /* We are allocating node blocks */
+#define		XFS_DC_RM_LEAF_BLKS	0x20 /* We are removing leaf blocks */
+#define		XFS_DC_RM_NODE_BLKS	0x40 /* We are removing node blocks */
+
+/*
+ * Context used for keeping track of delayed attribute operations
+ */
+struct xfs_delay_context {

fs/xfs/libxfs/xfs_da_btree.h enum xfs_dacmp { · line 66

Quoted 10 lines
fs/xfs/libxfs/xfs_da_btree.h +10 -0
+	unsigned int		flags;
+	struct xfs_buf		*leaf_bp;
+	struct xfs_bmbt_irec	map;
+	xfs_dablk_t		lblkno;
+	xfs_fileoff_t		lfileoff;
+	int			blkcnt;
+	struct xfs_da_state	*state;
+	struct xfs_da_state_blk *blk;
+};
+

The mixed size of the various fields leaves some holes in the structure. See 'pahole xfs.ko' output for how this struct could be reordered to reduce the overall size a bit..

Brian

Quoted 103 lines
fs/xfs/libxfs/xfs_da_btree.h +1 -0
  /*
   * Structure to ease passing around component names.
   */
@@ -69,6 +91,7 @@ typedef struct xfs_da_args {
  	int		rmtvaluelen2;	/* remote attr value length in bytes */
  	int		op_flags;	/* operation flags */
  	enum xfs_dacmp	cmpresult;	/* name compare result for lookups */
+	struct xfs_delay_context  dc;	/* context used for delay attr ops */
  } xfs_da_args_t;
 
  /*
fs/xfs/scrub/common.c +2 -0
index 1887605..9a649d1 100644
@@ -24,6 +24,8 @@
  #include "xfs_rmap_btree.h"
  #include "xfs_log.h"
  #include "xfs_trans_priv.h"
+#include "xfs_da_format.h"
+#include "xfs_da_btree.h"
  #include "xfs_attr.h"
  #include "xfs_reflink.h"
  #include "scrub/scrub.h"
fs/xfs/xfs_acl.c +2 -0
index f8fb6e10..4e85b38 100644
@@ -10,6 +10,8 @@
  #include "xfs_trans_resv.h"
  #include "xfs_mount.h"
  #include "xfs_inode.h"
+#include "xfs_da_format.h"
+#include "xfs_da_btree.h"
  #include "xfs_attr.h"
  #include "xfs_trace.h"
  #include <linux/posix_acl_xattr.h>
fs/xfs/xfs_attr_list.c +1 -0
index 00758fd..467c53c 100644
@@ -12,6 +12,7 @@
  #include "xfs_trans_resv.h"
  #include "xfs_mount.h"
  #include "xfs_da_format.h"
+#include "xfs_da_btree.h"
  #include "xfs_inode.h"
  #include "xfs_trans.h"
  #include "xfs_bmap.h"
fs/xfs/xfs_ioctl.c +2 -0
index 626420d..2cabdc2 100644
@@ -15,6 +15,8 @@
  #include "xfs_iwalk.h"
  #include "xfs_itable.h"
  #include "xfs_error.h"
+#include "xfs_da_format.h"
+#include "xfs_da_btree.h"
  #include "xfs_attr.h"
  #include "xfs_bmap.h"
  #include "xfs_bmap_util.h"
fs/xfs/xfs_ioctl32.c +2 -0
index 1e08bf7..7153780 100644
@@ -17,6 +17,8 @@
  #include "xfs_itable.h"
  #include "xfs_fsops.h"
  #include "xfs_rtalloc.h"
+#include "xfs_da_format.h"
+#include "xfs_da_btree.h"
  #include "xfs_attr.h"
  #include "xfs_ioctl.h"
  #include "xfs_ioctl32.h"
fs/xfs/xfs_iops.c +2 -0
index 469e8e2..57de5f1 100644
@@ -13,6 +13,8 @@
  #include "xfs_inode.h"
  #include "xfs_acl.h"
  #include "xfs_quota.h"
+#include "xfs_da_format.h"
+#include "xfs_da_btree.h"
  #include "xfs_attr.h"
  #include "xfs_trans.h"
  #include "xfs_trace.h"
fs/xfs/xfs_xattr.c +1 -0
index 6309da4..470e605 100644
@@ -10,6 +10,7 @@
  #include "xfs_log_format.h"
  #include "xfs_da_format.h"
  #include "xfs_inode.h"
+#include "xfs_da_btree.h"
  #include "xfs_attr.h"
 
  #include <linux/posix_acl_xattr.h>
Signature · 1 line
2.7.4
#44 lore raw

PATCH v3 14/19 xfs: Add delayed attribute routines

In reply to Allison Collins

This patch adds new delayed attribute routines:

xfs_attr_set_later
xfs_attr_remove_later
xfs_leaf_addname_later
xfs_node_addname_later
xfs_node_removename_later

These routines are similar to their existing counter parts, but they do not roll or commit transactions. They instead return -EAGAIN to allow the calling function to roll the transaction and recall the function. This allows the attribute operations to be logged in multiple smaller transactions.

---
 fs/xfs/libxfs/xfs_attr.c | 591 ++++++++++++++++++++++++++++++++++++++++++++++-
 fs/xfs/libxfs/xfs_attr.h |   2 +
 2 files changed, 592 insertions(+), 1 deletion(-)
fs/xfs/libxfs/xfs_attr.c +590 -1
index 781dd8a..310f5b2 100644
@@ -45,6 +45,7 @@ STATIC int xfs_attr_shortform_addname(xfs_da_args_t *args);
  */
 STATIC int xfs_attr_leaf_get(xfs_da_args_t *args);
 STATIC int xfs_attr_leaf_addname(xfs_da_args_t *args);
+STATIC int xfs_leaf_addname_later(xfs_da_args_t *args);
 STATIC int xfs_attr_leaf_removename(xfs_da_args_t *args);
 STATIC int xfs_leaf_has_attr(struct xfs_da_args *args, struct xfs_buf **bp);
 
@@ -53,12 +54,14 @@ STATIC int xfs_leaf_has_attr(struct xfs_da_args *args, struct xfs_buf **bp);
  */
 STATIC int xfs_attr_node_get(xfs_da_args_t *args);
 STATIC int xfs_attr_node_addname(xfs_da_args_t *args);
+STATIC int xfs_node_addname_later(xfs_da_args_t *args);
 STATIC int xfs_attr_node_removename(xfs_da_args_t *args);
+STATIC int xfs_node_removename_later(xfs_da_args_t *args);
 STATIC int xfs_attr_node_hasname(xfs_da_args_t *args,
 				 struct xfs_da_state **state);
 STATIC int xfs_attr_fillstate(xfs_da_state_t *state);
 STATIC int xfs_attr_refillstate(xfs_da_state_t *state);
-
+STATIC int xfs_attr_leaf_try_add(struct xfs_da_args *args, struct xfs_buf *bp);
 
 STATIC int
 xfs_attr_args_init(
@@ -313,6 +316,112 @@ xfs_attr_set_args(
 }
 
 /*
+ * Set the attribute specified in @args.
+ * This routine is meant to function as a delayed operation, and may return
+ * -EGAIN when the transaction needs to be rolled.  Calling functions will need
+ * to handle this, and recall the function until a successful error code is
+ * returned.
+ */
+int
+xfs_attr_set_later(
+	struct xfs_da_args	*args,
+	struct xfs_buf          **leaf_bp)
+{
+	struct xfs_inode	*dp = args->dp;
+	int			error = 0;
+	int			sf_size;
+
+	/*
+	 * New inodes may not have an attribute fork yet. So set the attribute
+	 * fork appropriately
+	 */
+	if (XFS_IFORK_Q((args->dp)) == 0) {
+		sf_size = sizeof(struct xfs_attr_sf_hdr) +
+		     XFS_ATTR_SF_ENTSIZE_BYNAME(args->name.len, args->valuelen);
+		xfs_bmap_set_attrforkoff(args->dp, sf_size, NULL);
+		args->dp->i_afp = kmem_zone_zalloc(xfs_ifork_zone, 0);
+		args->dp->i_afp->if_flags = XFS_IFEXTENTS;
+	}
+
+	/*
+	 * If the attribute list is non-existent or a shortform list,
+	 * upgrade it to a single-leaf-block attribute list.
+	 */
+	if (dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL ||
+	    (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS &&
+	     dp->i_d.di_anextents == 0)) {
+		/*
+		 * Build initial attribute list (if required).
+		 */
+		if (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS)
+			xfs_attr_shortform_create(args);
+
+		/*
+		 * Try to add the attr to the attribute list in the inode.
+		 */
+		error = xfs_attr_try_sf_addname(dp, args);
+		if (error != -ENOSPC)
+			return error;
+
+		/*
+		 * It won't fit in the shortform, transform to a leaf block.
+		 * GROT: another possible req'mt for a double-split btree op.
+		 */
+		error = xfs_attr_shortform_to_leaf(args, leaf_bp);
+		if (error)
+			return error;
+
+		/*
+		 * Prevent the leaf buffer from being unlocked so that a
+		 * concurrent AIL push cannot grab the half-baked leaf
+		 * buffer and run into problems with the write verifier.
+		 */
+
+		xfs_trans_bhold(args->trans, *leaf_bp);
+		return -EAGAIN;
+	}
+
+	/*
+	 * After a shortform to leaf conversion, we need to hold the leaf and
+	 * cylce out the transaction.  When we get back, we need to release
+	 * the leaf.
+	 */
+	if (*leaf_bp != NULL) {
+		xfs_trans_brelse(args->trans, *leaf_bp);
+		*leaf_bp = NULL;
+	}
+
+	/*
+	 * If we fit in a block, or we are in the middle of adding a leaf name.
+	 * xfs_attr_da_leaf_addname will set the XFS_DC_ALLOC_LEAF to indicate
+	 * that it is not done yet, and need to be recalled to finish up from
+	 * the last EAGAIN it returned
+	 */
+	if (xfs_bmap_one_block(dp, XFS_ATTR_FORK) ||
+	    args->dc.flags & XFS_DC_ALLOC_LEAF) {
+		if (!(args->dc.flags & XFS_DC_FOUND_LBLK)) {
+			error = xfs_attr_leaf_try_add(args, *leaf_bp);
+			args->dc.flags |= XFS_DC_FOUND_LBLK;
+
+			if (error && error != -ENOSPC)
+				return error;
+
+			return -EAGAIN;
+		}
+
+		error = xfs_leaf_addname_later(args);
+		if (error && error != -ENOSPC)
+			return error;
+	} else {
+		error = xfs_node_addname_later(args);
+	}
+
+	return error;
+}
+
+
+
+/*
  * Return EEXIST if attr is found, or ENOATTR if not
  */
 int
@@ -362,6 +471,57 @@ xfs_attr_remove_args(
 	return error;
 }
 
+/*
+ * Remove the attribute specified in @args.
+ * This routine is meant to function as a delayed operation, and may return
+ * -EGAIN when the transaction needs to be rolled.  Calling functions will need
+ * to handle this, and recall the function until a successful error code is
+ * returned.
+ */
+int
+xfs_attr_remove_later(
+	struct xfs_da_args      *args)
+{
+	struct xfs_inode	*dp = args->dp;
+	struct xfs_buf		*bp;
+	int			forkoff, error = 0;
+
+	if (!xfs_inode_hasattr(dp)) {
+		error = -ENOATTR;
+	} else if (dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) {
+		ASSERT(dp->i_afp->if_flags & XFS_IFINLINE);
+		error = xfs_attr_shortform_remove(args);
+	} else if (xfs_bmap_one_block(dp, XFS_ATTR_FORK) &&
+		   !(args->dc.flags & XFS_DC_RM_NODE_BLKS)) {
+		/*
+		 * If we fit in a block AND we are not in the middle of
+		 * removing node blocks, remove the leaf attribute.
+		 * xfs_attr_da_node_removename will set XFS_DC_RM_NODE_BLKS to
+		 * signal that it is not done yet, and needs to be recalled to
+		 * to finish up from the last -EAGAIN
+		 */
+		error = xfs_leaf_has_attr(args, &bp);
+		if (error == -ENOATTR) {
+			xfs_trans_brelse(args->trans, bp);
+			return error;
+		}
+		error = 0;
+
+		xfs_attr3_leaf_remove(bp, args);
+
+		/* If the result is small enough, shrink it into the inode.*/
+		forkoff = xfs_attr_shortform_allfit(bp, dp);
+		if (forkoff)
+			error = xfs_attr3_leaf_to_shortform(bp, args, forkoff);
+	} else {
+		error = xfs_node_removename_later(args);
+	}
+
+	return error;
+}
+
+
+
 int
 xfs_attr_set(
 	struct xfs_inode	*dp,
@@ -794,6 +954,87 @@ xfs_attr_leaf_addname(struct xfs_da_args	*args)
 }
 
 /*
+ * Add a name to the leaf attribute list structure
+ *
+ * This leaf block cannot have a "remote" value, we only call this routine
+ * if bmap_one_block() says there is only one block (ie: no remote blks).
+ *
+ * This routine is meant to function as a delayed operation, and may return
+ * -EGAIN when the transaction needs to be rolled.  Calling functions will need
+ * to handle this, and recall the function until a successful error code is
+ * returned.
+ */
+STATIC int
+xfs_leaf_addname_later(
+	struct xfs_da_args	*args)
+{
+	int			error, nmap;
+	struct xfs_inode	*dp = args->dp;
+	struct xfs_bmbt_irec	*map = &args->dc.map;
+
+	/*
+	 * If there was an out-of-line value, allocate the blocks we
+	 * identified for its storage and copy the value.  This is done
+	 * after we create the attribute so that we don't overflow the
+	 * maximum size of a transaction and/or hit a deadlock.
+	 */
+	if (args->rmtblkno > 0) {
+		if (!(args->dc.flags & XFS_DC_ALLOC_LEAF)) {
+			args->dc.lfileoff = 0;
+			args->dc.lblkno = 0;
+			args->dc.blkcnt = 0;
+			args->rmtblkcnt = 0;
+			args->rmtblkno = 0;
+			memset(map, 0, sizeof(struct xfs_bmbt_irec));
+
+			error = xfs_attr_rmt_find_hole(args);
+			if (error)
+				return error;
+
+			args->dc.blkcnt = args->rmtblkcnt;
+			args->dc.lblkno = args->rmtblkno;
+			args->dc.flags |= XFS_DC_ALLOC_LEAF;
+		}
+
+		/*
+		 * Roll through the "value", allocating blocks on disk as
+		 * required.
+		 */
+		while (args->dc.blkcnt > 0) {
+			nmap = 1;
+			error = xfs_bmapi_write(args->trans, dp,
+				  (xfs_fileoff_t)args->dc.lblkno,
+				  args->dc.blkcnt, XFS_BMAPI_ATTRFORK,
+				  args->total, map, &nmap);
+			if (error)
+				return error;
+			ASSERT(nmap == 1);
+			ASSERT((map->br_startblock != DELAYSTARTBLOCK) &&
+			       (map->br_startblock != HOLESTARTBLOCK));
+
+			/* roll attribute extent map forwards */
+			args->dc.lblkno += map->br_blockcount;
+			args->dc.blkcnt -= map->br_blockcount;
+
+			return -EAGAIN;
+		}
+
+		error = xfs_attr_rmtval_set_value(args);
+		if (error)
+			return error;
+	}
+
+	if (args->rmtblkno > 0) {
+		/*
+		 * Added a "remote" value, just clear the incomplete flag.
+		 */
+		error = xfs_attr3_leaf_clearflag(args);
+	}
+	args->dc.flags &= ~XFS_DC_ALLOC_LEAF;
+	return error;
+}
+
+/*
  * Return EEXIST if attr is found, or ENOATTR if not
  */
 STATIC int
@@ -1291,6 +1532,354 @@ xfs_attr_node_removename(
 }
 
 /*
+ * Remove a name from a B-tree attribute list.
+ *
+ * This will involve walking down the Btree, and may involve joining
+ * leaf nodes and even joining intermediate nodes up to and including
+ * the root node (a special case of an intermediate node).
+ *
+ * This routine is meant to function as a delayed operation, and may return
+ * -EGAIN when the transaction needs to be rolled.  Calling functions
+ * will need to handle this, and recall the function until a successful error
+ * code is returned.
+ */
+STATIC int
+xfs_node_removename_later(
+	struct xfs_da_args	*args)
+{
+	struct xfs_da_state	*state = NULL;
+	struct xfs_da_state_blk	*blk;
+	struct xfs_buf		*bp;
+	int			error, forkoff, retval = 0;
+	struct xfs_inode	*dp = args->dp;
+	int			done = 0;
+
+	trace_xfs_attr_node_removename(args);
+
+	if (args->dc.state == NULL) {
+		error = xfs_attr_node_hasname(args, &args->dc.state);
+		if (error != -EEXIST)
+			goto out;
+		else
+			error = 0;
+
+		/*
+		 * If there is an out-of-line value, de-allocate the blocks.
+		 * This is done before we remove the attribute so that we don't
+		 * overflow the maximum size of a transaction and/or hit a
+		 * deadlock.
+		 */
+		state = args->dc.state;
+		args->dc.blk = &state->path.blk[state->path.active - 1];
+		ASSERT(args->dc.blk->bp != NULL);
+		ASSERT(args->dc.blk->magic == XFS_ATTR_LEAF_MAGIC);
+	}
+	state = args->dc.state;
+	blk = args->dc.blk;
+
+	if (args->rmtblkno > 0 && !(args->dc.flags & XFS_DC_RM_LEAF_BLKS)) {
+		bool isset;
+
+		error = xfs_attr3_leaf_flag_is_set(args, &isset);
+		if (error)
+			goto out;
+		if (!isset) {
+			/*
+			 * Fill in disk block numbers in the state structure
+			 * so that we can get the buffers back after we commit
+			 * several transactions in the following calls.
+			 */
+			error = xfs_attr_fillstate(state);
+			if (error)
+				goto out;
+
+			/*
+			 * Mark the attribute as INCOMPLETE, then bunmapi() the
+			 * remote value.
+			 */
+			error = xfs_attr3_leaf_setflag(args);
+			if (error)
+				goto out;
+
+			return -EAGAIN;
+		}
+
+		if (!(args->dc.flags & XFS_DC_RM_NODE_BLKS)) {
+			args->dc.flags |= XFS_DC_RM_NODE_BLKS;
+			error = xfs_attr_rmtval_invalidate(args);
+			if (error)
+				goto out;
+		}
+
+		/*
+		 * Unmap value blocks for this attr.  This is similar to
+		 * xfs_attr_rmtval_remove, but open coded here to return EAGAIN
+		 * for new transactions
+		 */
+		while (!done && !error) {
+			error = xfs_bunmapi(args->trans, args->dp,
+				    args->rmtblkno, args->rmtblkcnt,
+				    XFS_BMAPI_ATTRFORK, 1, &done);
+			if (error)
+				return error;
+
+			if (!done)
+				return -EAGAIN;
+		}
+
+		if (error)
+			goto out;
+
+		/*
+		 * Refill the state structure with buffers, the prior calls
+		 * released our buffers.
+		 */
+		error = xfs_attr_refillstate(state);
+		if (error)
+			goto out;
+	}
+
+	/*
+	 * Remove the name and update the hashvals in the tree.
+	 */
+	if (!(args->dc.flags & XFS_DC_RM_LEAF_BLKS)) {
+		blk = &state->path.blk[state->path.active - 1];
+		ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
+		retval = xfs_attr3_leaf_remove(blk->bp, args);
+		xfs_da3_fixhashpath(state, &state->path);
+
+		args->dc.flags |= XFS_DC_RM_LEAF_BLKS;
+	}
+
+	/*
+	 * Check to see if the tree needs to be collapsed.
+	 */
+	if (retval && (state->path.active > 1)) {
+		args->dc.flags |= XFS_DC_RM_NODE_BLKS;
+		error = xfs_da3_join(state);
+		if (error)
+			goto out;
+
+		return -EAGAIN;
+	}
+
+	/*
+	 * If the result is small enough, push it all into the inode.
+	 */
+	if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
+		/*
+		 * Have to get rid of the copy of this dabuf in the state.
+		 */
+		ASSERT(state->path.active == 1);
+		ASSERT(state->path.blk[0].bp);
+		state->path.blk[0].bp = NULL;
+
+		error = xfs_attr3_leaf_read(args->trans, args->dp, 0, -1, &bp);
+		if (error)
+			goto out;
+
+		forkoff = xfs_attr_shortform_allfit(bp, dp);
+		if (forkoff) {
+			error = xfs_attr3_leaf_to_shortform(bp, args, forkoff);
+			/* bp is gone due to xfs_da_shrink_inode */
+			if (error)
+				goto out;
+		} else
+			xfs_trans_brelse(args->trans, bp);
+	}
+out:
+	if (state != NULL)
+		xfs_da_state_free(state);
+
+	return error;
+}
+
+/*
+ * Add a name to a Btree-format attribute list.
+ *
+ * This will involve walking down the Btree, and may involve splitting
+ * leaf nodes and even splitting intermediate nodes up to and including
+ * the root node (a special case of an intermediate node).
+ *
+ * "Remote" attribute values confuse the issue and atomic rename operations
+ * add a whole extra layer of confusion on top of that.
+ *
+ * This routine is meant to function as a delayed operation, and may return
+ * -EGAIN when the transaction needs to be rolled.  Calling functions will need
+ * to handle this, and recall the function until a successful error code is
+ *returned.
+ */
+STATIC int
+xfs_node_addname_later(
+	struct xfs_da_args	*args)
+{
+	struct xfs_da_state	*state = NULL;
+	struct xfs_da_state_blk	*blk;
+	struct xfs_inode	*dp;
+	int			retval, error = 0;
+	int			nmap;
+	struct xfs_bmbt_irec    *map = &args->dc.map;
+
+	trace_xfs_attr_node_addname(args);
+
+	/*
+	 * Fill in bucket of arguments/results/context to carry around.
+	 */
+	dp = args->dp;
+
+	if (args->dc.flags & XFS_DC_FOUND_NBLK)
+		goto found_blk;
+
+	/*
+	 * Search to see if name already exists, and get back a pointer
+	 * to where it should go.
+	 */
+	retval = xfs_attr_node_hasname(args, &state);
+	blk = &state->path.blk[state->path.active-1];
+	ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
+	if ((args->name.type & ATTR_REPLACE) && (retval == -ENOATTR)) {
+		goto out;
+	} else if (retval == -EEXIST) {
+		if (args->name.type & ATTR_CREATE)
+			goto out;
+
+		trace_xfs_attr_node_replace(args);
+
+		/* save the attribute state for later removal*/
+		args->op_flags |= XFS_DA_OP_RENAME;	/* atomic rename op */
+		args->blkno2 = args->blkno;		/* set 2nd entry info*/
+		args->index2 = args->index;
+		args->rmtblkno2 = args->rmtblkno;
+		args->rmtblkcnt2 = args->rmtblkcnt;
+		args->rmtvaluelen2 = args->rmtvaluelen;
+
+		/*
+		 * clear the remote attr state now that it is saved so that the
+		 * values reflect the state of the attribute we are about to
+		 * add, not the attribute we just found and will remove later.
+		 */
+		args->rmtblkno = 0;
+		args->rmtblkcnt = 0;
+		args->rmtvaluelen = 0;
+	}
+
+	retval = xfs_attr3_leaf_add(blk->bp, state->args);
+	if (retval == -ENOSPC) {
+		if (state->path.active == 1) {
+			/*
+			 * Its really a single leaf node, but it had
+			 * out-of-line values so it looked like it *might*
+			 * have been a b-tree.
+			 */
+			xfs_da_state_free(state);
+			state = NULL;
+			error = xfs_attr3_leaf_to_node(args);
+			if (error)
+				goto out;
+
+			return -EAGAIN;
+		}
+
+		/*
+		 * Split as many Btree elements as required.
+		 * This code tracks the new and old attr's location
+		 * in the index/blkno/rmtblkno/rmtblkcnt fields and
+		 * in the index2/blkno2/rmtblkno2/rmtblkcnt2 fields.
+		 */
+		error = xfs_da3_split(state);
+		if (error)
+			goto out;
+	} else {
+		/*
+		 * Addition succeeded, update Btree hashvals.
+		 */
+		xfs_da3_fixhashpath(state, &state->path);
+	}
+
+	/*
+	 * Kill the state structure, we're done with it and need to
+	 * allow the buffers to come back later.
+	 */
+	xfs_da_state_free(state);
+	state = NULL;
+
+	args->dc.flags |= XFS_DC_FOUND_NBLK;
+	return -EAGAIN;
+found_blk:
+
+	/*
+	 * If there was an out-of-line value, allocate the blocks we
+	 * identified for its storage and copy the value.  This is done
+	 * after we create the attribute so that we don't overflow the
+	 * maximum size of a transaction and/or hit a deadlock.
+	 */
+	if (args->rmtblkno > 0) {
+		if (!(args->dc.flags & XFS_DC_ALLOC_NODE)) {
+			args->dc.flags |= XFS_DC_ALLOC_NODE;
+			args->dc.lblkno = 0;
+			args->dc.lfileoff = 0;
+			args->dc.blkcnt = 0;
+			args->rmtblkcnt = 0;
+			args->rmtblkno = 0;
+			memset(map, 0, sizeof(struct xfs_bmbt_irec));
+
+			error = xfs_attr_rmt_find_hole(args);
+			if (error)
+				return error;
+
+			args->dc.blkcnt = args->rmtblkcnt;
+			args->dc.lblkno = args->rmtblkno;
+		}
+		/*
+		 * Roll through the "value", allocating blocks on disk as
+		 * required.
+		 */
+		while (args->dc.blkcnt > 0) {
+			nmap = 1;
+			error = xfs_bmapi_write(args->trans, dp,
+				(xfs_fileoff_t)args->dc.lblkno, args->dc.blkcnt,
+				XFS_BMAPI_ATTRFORK, args->total, map, &nmap);
+			if (error)
+				return error;
+
+			ASSERT(nmap == 1);
+			ASSERT((map->br_startblock != DELAYSTARTBLOCK) &&
+			       (map->br_startblock != HOLESTARTBLOCK));
+
+			/* roll attribute extent map forwards */
+			args->dc.lblkno += map->br_blockcount;
+			args->dc.blkcnt -= map->br_blockcount;
+
+			return -EAGAIN;
+		}
+
+		error = xfs_attr_rmtval_set_value(args);
+		if (error)
+			return error;
+	}
+
+	if (args->rmtblkno > 0) {
+		/*
+		 * Added a "remote" value, just clear the incomplete flag.
+		 */
+		error = xfs_attr3_leaf_clearflag(args);
+		if (error)
+			goto out;
+	}
+	retval = error = 0;
+
+out:
+	if (state)
+		xfs_da_state_free(state);
+	if (error)
+		return error;
+
+	return retval;
+}
+
+
+
+/*
  * Fill in the disk block numbers in the state structure for the buffers
  * that are attached to the state structure.
  * This is done so that we can quickly reattach ourselves to those buffers
fs/xfs/libxfs/xfs_attr.h +2 -0
index fb56d81..6203766 100644
@@ -149,9 +149,11 @@ int xfs_attr_get(struct xfs_inode *ip, struct xfs_name *name,
 int xfs_attr_set(struct xfs_inode *dp, struct xfs_name *name,
 		 unsigned char *value, int valuelen);
 int xfs_attr_set_args(struct xfs_da_args *args);
+int xfs_attr_set_later(struct xfs_da_args *args, struct xfs_buf **leaf_bp);
 int xfs_attr_remove(struct xfs_inode *dp, struct xfs_name *name);
 int xfs_has_attr(struct xfs_da_args *args);
 int xfs_attr_remove_args(struct xfs_da_args *args);
+int xfs_attr_remove_later(struct xfs_da_args *args);
 int xfs_attr_list(struct xfs_inode *dp, char *buffer, int bufsize,
 		  int flags, struct attrlist_cursor_kern *cursor);
 bool xfs_attr_namecheck(const void *name, size_t length);
Signature · 1 line
2.7.4
#45 lore raw

Re: [PATCH v3 14/19] xfs: Add delayed attribute routines

Quoted 25 lines · Allison Collins

This patch adds new delayed attribute routines:

xfs_attr_set_later
xfs_attr_remove_later
xfs_leaf_addname_later
xfs_node_addname_later
xfs_node_removename_later

These routines are similar to their existing counter parts, but they do not roll or commit transactions. They instead return -EAGAIN to allow the calling function to roll the transaction and recall the function. This allows the attribute operations to be logged in multiple smaller transactions.

---
 fs/xfs/libxfs/xfs_attr.c | 591 ++++++++++++++++++++++++++++++++++++++++++++++-
 fs/xfs/libxfs/xfs_attr.h |   2 +
 2 files changed, 592 insertions(+), 1 deletion(-)
fs/xfs/libxfs/xfs_attr.c +0 -0
index 781dd8a..310f5b2 100644

...

Quoted 58 lines
fs/xfs/libxfs/xfs_attr.c +54 -0
@@ -313,6 +316,112 @@ xfs_attr_set_args(
 }
 
 /*
+ * Set the attribute specified in @args.
+ * This routine is meant to function as a delayed operation, and may return
+ * -EGAIN when the transaction needs to be rolled.  Calling functions will need
+ * to handle this, and recall the function until a successful error code is
+ * returned.
+ */
+int
+xfs_attr_set_later(
+	struct xfs_da_args	*args,
+	struct xfs_buf          **leaf_bp)
+{
+	struct xfs_inode	*dp = args->dp;
+	int			error = 0;
+	int			sf_size;
+
+	/*
+	 * New inodes may not have an attribute fork yet. So set the attribute
+	 * fork appropriately
+	 */
+	if (XFS_IFORK_Q((args->dp)) == 0) {
+		sf_size = sizeof(struct xfs_attr_sf_hdr) +
+		     XFS_ATTR_SF_ENTSIZE_BYNAME(args->name.len, args->valuelen);
+		xfs_bmap_set_attrforkoff(args->dp, sf_size, NULL);
+		args->dp->i_afp = kmem_zone_zalloc(xfs_ifork_zone, 0);
+		args->dp->i_afp->if_flags = XFS_IFEXTENTS;
+	}
+
+	/*
+	 * If the attribute list is non-existent or a shortform list,
+	 * upgrade it to a single-leaf-block attribute list.
+	 */
+	if (dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL ||
+	    (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS &&
+	     dp->i_d.di_anextents == 0)) {
+		/*
+		 * Build initial attribute list (if required).
+		 */
+		if (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS)
+			xfs_attr_shortform_create(args);
+
+		/*
+		 * Try to add the attr to the attribute list in the inode.
+		 */
+		error = xfs_attr_try_sf_addname(dp, args);
+		if (error != -ENOSPC)
+			return error;
+
+		/*
+		 * It won't fit in the shortform, transform to a leaf block.
+		 * GROT: another possible req'mt for a double-split btree op.
+		 */
+		error = xfs_attr_shortform_to_leaf(args, leaf_bp);
+		if (error)
+			return error;

fs/xfs/libxfs/xfs_attr.c xfs_attr_set_args( · line 382

Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10 -0
+
+		/*
+		 * Prevent the leaf buffer from being unlocked so that a
+		 * concurrent AIL push cannot grab the half-baked leaf
+		 * buffer and run into problems with the write verifier.
+		 */
+
+		xfs_trans_bhold(args->trans, *leaf_bp);
+		return -EAGAIN;
+	}

I haven't actually reviewed the code in this patch yet, but rather I skipped ahead to try and get an understanding of the design approach and flow of a deferred xattr operation. IIUC, we basically duplicate a bunch of xattr code into these dfops oriented functions but instead of rolling transactions, return -EAGAIN and use the XFS_DC_ state flags to manage reentrancy into the xfs_trans_attr() function.

If I'm following that correctly, I'm concerned about a couple things with the general approach. First, I think the complexity is high and maintainability is low/difficult for this kind of reentrant approach. The state is managed/changed all throughout the call tree and so the risk and complexity of changing one particular bit in the sequence requires subtle consideration to make sure it doesn't cause problems if the function is reentered. For example, I'd prefer to see something like xfs_trans_attr() broken down into smaller granularity functions with higher level state that is managed and readable in one place, if possible. Perhaps we could do that based on attr fork format, but I need to stare at the code and think about this some more (it might be that some degree of reentrancy is inevitable, or we just need to break things down to even smaller states...).

Second, it seems like a lot of this code duplication between deferred and non-deferred operations should be unnecessary, particularly since the only difference between the contexts is how transactions are managed. For example, if you follow the xattr set code path in both contexts, we can see that functions like xfs_attr_set_args() are basically duplicated in the xfs_attr_set_later() deferred variant just so we can change the xfs_defer_finish() call in the former to a return -EAGAIN in the latter.

Instead, what I think we should strive for is a common xattr mechanism that consists of the lowest common denominator between the two contexts (or IOW, core infrastructure that can be invoked from either context). For example, on a kernel without deferred xattr support, could we find a way to call the deferred variants directly and just let the context-specific caller do the transaction rolls on -EAGAIN instead of relying on the dfops infrastructure? ISTM that should be possible, it just requires further breaking down the existing/non-deferred mechanism into smaller bits that uses the new state management logic and implements -EAGAIN handling for when the lower level code requires a transaction roll. At that point, deferred support should basically just consist of the dfops and log (i.e. intents) code to plug into the associated infrastructure. I think another side effect of that approach is that we shouldn't need these patches that add a bunch of new xattr infrastructure code, but rather we'd just continue refactoring the existing code and eventually implement a new high level function that returns -EAGAIN directly to the dfops code instead of rolling transactions explicitly. Thoughts?

Brian

Quoted 565 lines
fs/xfs/libxfs/xfs_attr.c +522 -0
+
+	/*
+	 * After a shortform to leaf conversion, we need to hold the leaf and
+	 * cylce out the transaction.  When we get back, we need to release
+	 * the leaf.
+	 */
+	if (*leaf_bp != NULL) {
+		xfs_trans_brelse(args->trans, *leaf_bp);
+		*leaf_bp = NULL;
+	}
+
+	/*
+	 * If we fit in a block, or we are in the middle of adding a leaf name.
+	 * xfs_attr_da_leaf_addname will set the XFS_DC_ALLOC_LEAF to indicate
+	 * that it is not done yet, and need to be recalled to finish up from
+	 * the last EAGAIN it returned
+	 */
+	if (xfs_bmap_one_block(dp, XFS_ATTR_FORK) ||
+	    args->dc.flags & XFS_DC_ALLOC_LEAF) {
+		if (!(args->dc.flags & XFS_DC_FOUND_LBLK)) {
+			error = xfs_attr_leaf_try_add(args, *leaf_bp);
+			args->dc.flags |= XFS_DC_FOUND_LBLK;
+
+			if (error && error != -ENOSPC)
+				return error;
+
+			return -EAGAIN;
+		}
+
+		error = xfs_leaf_addname_later(args);
+		if (error && error != -ENOSPC)
+			return error;
+	} else {
+		error = xfs_node_addname_later(args);
+	}
+
+	return error;
+}
+
+
+
+/*
  * Return EEXIST if attr is found, or ENOATTR if not
  */
 int
@@ -362,6 +471,57 @@ xfs_attr_remove_args(
 	return error;
 }
 
+/*
+ * Remove the attribute specified in @args.
+ * This routine is meant to function as a delayed operation, and may return
+ * -EGAIN when the transaction needs to be rolled.  Calling functions will need
+ * to handle this, and recall the function until a successful error code is
+ * returned.
+ */
+int
+xfs_attr_remove_later(
+	struct xfs_da_args      *args)
+{
+	struct xfs_inode	*dp = args->dp;
+	struct xfs_buf		*bp;
+	int			forkoff, error = 0;
+
+	if (!xfs_inode_hasattr(dp)) {
+		error = -ENOATTR;
+	} else if (dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) {
+		ASSERT(dp->i_afp->if_flags & XFS_IFINLINE);
+		error = xfs_attr_shortform_remove(args);
+	} else if (xfs_bmap_one_block(dp, XFS_ATTR_FORK) &&
+		   !(args->dc.flags & XFS_DC_RM_NODE_BLKS)) {
+		/*
+		 * If we fit in a block AND we are not in the middle of
+		 * removing node blocks, remove the leaf attribute.
+		 * xfs_attr_da_node_removename will set XFS_DC_RM_NODE_BLKS to
+		 * signal that it is not done yet, and needs to be recalled to
+		 * to finish up from the last -EAGAIN
+		 */
+		error = xfs_leaf_has_attr(args, &bp);
+		if (error == -ENOATTR) {
+			xfs_trans_brelse(args->trans, bp);
+			return error;
+		}
+		error = 0;
+
+		xfs_attr3_leaf_remove(bp, args);
+
+		/* If the result is small enough, shrink it into the inode.*/
+		forkoff = xfs_attr_shortform_allfit(bp, dp);
+		if (forkoff)
+			error = xfs_attr3_leaf_to_shortform(bp, args, forkoff);
+	} else {
+		error = xfs_node_removename_later(args);
+	}
+
+	return error;
+}
+
+
+
 int
 xfs_attr_set(
 	struct xfs_inode	*dp,
@@ -794,6 +954,87 @@ xfs_attr_leaf_addname(struct xfs_da_args	*args)
 }
 
 /*
+ * Add a name to the leaf attribute list structure
+ *
+ * This leaf block cannot have a "remote" value, we only call this routine
+ * if bmap_one_block() says there is only one block (ie: no remote blks).
+ *
+ * This routine is meant to function as a delayed operation, and may return
+ * -EGAIN when the transaction needs to be rolled.  Calling functions will need
+ * to handle this, and recall the function until a successful error code is
+ * returned.
+ */
+STATIC int
+xfs_leaf_addname_later(
+	struct xfs_da_args	*args)
+{
+	int			error, nmap;
+	struct xfs_inode	*dp = args->dp;
+	struct xfs_bmbt_irec	*map = &args->dc.map;
+
+	/*
+	 * If there was an out-of-line value, allocate the blocks we
+	 * identified for its storage and copy the value.  This is done
+	 * after we create the attribute so that we don't overflow the
+	 * maximum size of a transaction and/or hit a deadlock.
+	 */
+	if (args->rmtblkno > 0) {
+		if (!(args->dc.flags & XFS_DC_ALLOC_LEAF)) {
+			args->dc.lfileoff = 0;
+			args->dc.lblkno = 0;
+			args->dc.blkcnt = 0;
+			args->rmtblkcnt = 0;
+			args->rmtblkno = 0;
+			memset(map, 0, sizeof(struct xfs_bmbt_irec));
+
+			error = xfs_attr_rmt_find_hole(args);
+			if (error)
+				return error;
+
+			args->dc.blkcnt = args->rmtblkcnt;
+			args->dc.lblkno = args->rmtblkno;
+			args->dc.flags |= XFS_DC_ALLOC_LEAF;
+		}
+
+		/*
+		 * Roll through the "value", allocating blocks on disk as
+		 * required.
+		 */
+		while (args->dc.blkcnt > 0) {
+			nmap = 1;
+			error = xfs_bmapi_write(args->trans, dp,
+				  (xfs_fileoff_t)args->dc.lblkno,
+				  args->dc.blkcnt, XFS_BMAPI_ATTRFORK,
+				  args->total, map, &nmap);
+			if (error)
+				return error;
+			ASSERT(nmap == 1);
+			ASSERT((map->br_startblock != DELAYSTARTBLOCK) &&
+			       (map->br_startblock != HOLESTARTBLOCK));
+
+			/* roll attribute extent map forwards */
+			args->dc.lblkno += map->br_blockcount;
+			args->dc.blkcnt -= map->br_blockcount;
+
+			return -EAGAIN;
+		}
+
+		error = xfs_attr_rmtval_set_value(args);
+		if (error)
+			return error;
+	}
+
+	if (args->rmtblkno > 0) {
+		/*
+		 * Added a "remote" value, just clear the incomplete flag.
+		 */
+		error = xfs_attr3_leaf_clearflag(args);
+	}
+	args->dc.flags &= ~XFS_DC_ALLOC_LEAF;
+	return error;
+}
+
+/*
  * Return EEXIST if attr is found, or ENOATTR if not
  */
 STATIC int
@@ -1291,6 +1532,354 @@ xfs_attr_node_removename(
 }
 
 /*
+ * Remove a name from a B-tree attribute list.
+ *
+ * This will involve walking down the Btree, and may involve joining
+ * leaf nodes and even joining intermediate nodes up to and including
+ * the root node (a special case of an intermediate node).
+ *
+ * This routine is meant to function as a delayed operation, and may return
+ * -EGAIN when the transaction needs to be rolled.  Calling functions
+ * will need to handle this, and recall the function until a successful error
+ * code is returned.
+ */
+STATIC int
+xfs_node_removename_later(
+	struct xfs_da_args	*args)
+{
+	struct xfs_da_state	*state = NULL;
+	struct xfs_da_state_blk	*blk;
+	struct xfs_buf		*bp;
+	int			error, forkoff, retval = 0;
+	struct xfs_inode	*dp = args->dp;
+	int			done = 0;
+
+	trace_xfs_attr_node_removename(args);
+
+	if (args->dc.state == NULL) {
+		error = xfs_attr_node_hasname(args, &args->dc.state);
+		if (error != -EEXIST)
+			goto out;
+		else
+			error = 0;
+
+		/*
+		 * If there is an out-of-line value, de-allocate the blocks.
+		 * This is done before we remove the attribute so that we don't
+		 * overflow the maximum size of a transaction and/or hit a
+		 * deadlock.
+		 */
+		state = args->dc.state;
+		args->dc.blk = &state->path.blk[state->path.active - 1];
+		ASSERT(args->dc.blk->bp != NULL);
+		ASSERT(args->dc.blk->magic == XFS_ATTR_LEAF_MAGIC);
+	}
+	state = args->dc.state;
+	blk = args->dc.blk;
+
+	if (args->rmtblkno > 0 && !(args->dc.flags & XFS_DC_RM_LEAF_BLKS)) {
+		bool isset;
+
+		error = xfs_attr3_leaf_flag_is_set(args, &isset);
+		if (error)
+			goto out;
+		if (!isset) {
+			/*
+			 * Fill in disk block numbers in the state structure
+			 * so that we can get the buffers back after we commit
+			 * several transactions in the following calls.
+			 */
+			error = xfs_attr_fillstate(state);
+			if (error)
+				goto out;
+
+			/*
+			 * Mark the attribute as INCOMPLETE, then bunmapi() the
+			 * remote value.
+			 */
+			error = xfs_attr3_leaf_setflag(args);
+			if (error)
+				goto out;
+
+			return -EAGAIN;
+		}
+
+		if (!(args->dc.flags & XFS_DC_RM_NODE_BLKS)) {
+			args->dc.flags |= XFS_DC_RM_NODE_BLKS;
+			error = xfs_attr_rmtval_invalidate(args);
+			if (error)
+				goto out;
+		}
+
+		/*
+		 * Unmap value blocks for this attr.  This is similar to
+		 * xfs_attr_rmtval_remove, but open coded here to return EAGAIN
+		 * for new transactions
+		 */
+		while (!done && !error) {
+			error = xfs_bunmapi(args->trans, args->dp,
+				    args->rmtblkno, args->rmtblkcnt,
+				    XFS_BMAPI_ATTRFORK, 1, &done);
+			if (error)
+				return error;
+
+			if (!done)
+				return -EAGAIN;
+		}
+
+		if (error)
+			goto out;
+
+		/*
+		 * Refill the state structure with buffers, the prior calls
+		 * released our buffers.
+		 */
+		error = xfs_attr_refillstate(state);
+		if (error)
+			goto out;
+	}
+
+	/*
+	 * Remove the name and update the hashvals in the tree.
+	 */
+	if (!(args->dc.flags & XFS_DC_RM_LEAF_BLKS)) {
+		blk = &state->path.blk[state->path.active - 1];
+		ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
+		retval = xfs_attr3_leaf_remove(blk->bp, args);
+		xfs_da3_fixhashpath(state, &state->path);
+
+		args->dc.flags |= XFS_DC_RM_LEAF_BLKS;
+	}
+
+	/*
+	 * Check to see if the tree needs to be collapsed.
+	 */
+	if (retval && (state->path.active > 1)) {
+		args->dc.flags |= XFS_DC_RM_NODE_BLKS;
+		error = xfs_da3_join(state);
+		if (error)
+			goto out;
+
+		return -EAGAIN;
+	}
+
+	/*
+	 * If the result is small enough, push it all into the inode.
+	 */
+	if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
+		/*
+		 * Have to get rid of the copy of this dabuf in the state.
+		 */
+		ASSERT(state->path.active == 1);
+		ASSERT(state->path.blk[0].bp);
+		state->path.blk[0].bp = NULL;
+
+		error = xfs_attr3_leaf_read(args->trans, args->dp, 0, -1, &bp);
+		if (error)
+			goto out;
+
+		forkoff = xfs_attr_shortform_allfit(bp, dp);
+		if (forkoff) {
+			error = xfs_attr3_leaf_to_shortform(bp, args, forkoff);
+			/* bp is gone due to xfs_da_shrink_inode */
+			if (error)
+				goto out;
+		} else
+			xfs_trans_brelse(args->trans, bp);
+	}
+out:
+	if (state != NULL)
+		xfs_da_state_free(state);
+
+	return error;
+}
+
+/*
+ * Add a name to a Btree-format attribute list.
+ *
+ * This will involve walking down the Btree, and may involve splitting
+ * leaf nodes and even splitting intermediate nodes up to and including
+ * the root node (a special case of an intermediate node).
+ *
+ * "Remote" attribute values confuse the issue and atomic rename operations
+ * add a whole extra layer of confusion on top of that.
+ *
+ * This routine is meant to function as a delayed operation, and may return
+ * -EGAIN when the transaction needs to be rolled.  Calling functions will need
+ * to handle this, and recall the function until a successful error code is
+ *returned.
+ */
+STATIC int
+xfs_node_addname_later(
+	struct xfs_da_args	*args)
+{
+	struct xfs_da_state	*state = NULL;
+	struct xfs_da_state_blk	*blk;
+	struct xfs_inode	*dp;
+	int			retval, error = 0;
+	int			nmap;
+	struct xfs_bmbt_irec    *map = &args->dc.map;
+
+	trace_xfs_attr_node_addname(args);
+
+	/*
+	 * Fill in bucket of arguments/results/context to carry around.
+	 */
+	dp = args->dp;
+
+	if (args->dc.flags & XFS_DC_FOUND_NBLK)
+		goto found_blk;
+
+	/*
+	 * Search to see if name already exists, and get back a pointer
+	 * to where it should go.
+	 */
+	retval = xfs_attr_node_hasname(args, &state);
+	blk = &state->path.blk[state->path.active-1];
+	ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
+	if ((args->name.type & ATTR_REPLACE) && (retval == -ENOATTR)) {
+		goto out;
+	} else if (retval == -EEXIST) {
+		if (args->name.type & ATTR_CREATE)
+			goto out;
+
+		trace_xfs_attr_node_replace(args);
+
+		/* save the attribute state for later removal*/
+		args->op_flags |= XFS_DA_OP_RENAME;	/* atomic rename op */
+		args->blkno2 = args->blkno;		/* set 2nd entry info*/
+		args->index2 = args->index;
+		args->rmtblkno2 = args->rmtblkno;
+		args->rmtblkcnt2 = args->rmtblkcnt;
+		args->rmtvaluelen2 = args->rmtvaluelen;
+
+		/*
+		 * clear the remote attr state now that it is saved so that the
+		 * values reflect the state of the attribute we are about to
+		 * add, not the attribute we just found and will remove later.
+		 */
+		args->rmtblkno = 0;
+		args->rmtblkcnt = 0;
+		args->rmtvaluelen = 0;
+	}
+
+	retval = xfs_attr3_leaf_add(blk->bp, state->args);
+	if (retval == -ENOSPC) {
+		if (state->path.active == 1) {
+			/*
+			 * Its really a single leaf node, but it had
+			 * out-of-line values so it looked like it *might*
+			 * have been a b-tree.
+			 */
+			xfs_da_state_free(state);
+			state = NULL;
+			error = xfs_attr3_leaf_to_node(args);
+			if (error)
+				goto out;
+
+			return -EAGAIN;
+		}
+
+		/*
+		 * Split as many Btree elements as required.
+		 * This code tracks the new and old attr's location
+		 * in the index/blkno/rmtblkno/rmtblkcnt fields and
+		 * in the index2/blkno2/rmtblkno2/rmtblkcnt2 fields.
+		 */
+		error = xfs_da3_split(state);
+		if (error)
+			goto out;
+	} else {
+		/*
+		 * Addition succeeded, update Btree hashvals.
+		 */
+		xfs_da3_fixhashpath(state, &state->path);
+	}
+
+	/*
+	 * Kill the state structure, we're done with it and need to
+	 * allow the buffers to come back later.
+	 */
+	xfs_da_state_free(state);
+	state = NULL;
+
+	args->dc.flags |= XFS_DC_FOUND_NBLK;
+	return -EAGAIN;
+found_blk:
+
+	/*
+	 * If there was an out-of-line value, allocate the blocks we
+	 * identified for its storage and copy the value.  This is done
+	 * after we create the attribute so that we don't overflow the
+	 * maximum size of a transaction and/or hit a deadlock.
+	 */
+	if (args->rmtblkno > 0) {
+		if (!(args->dc.flags & XFS_DC_ALLOC_NODE)) {
+			args->dc.flags |= XFS_DC_ALLOC_NODE;
+			args->dc.lblkno = 0;
+			args->dc.lfileoff = 0;
+			args->dc.blkcnt = 0;
+			args->rmtblkcnt = 0;
+			args->rmtblkno = 0;
+			memset(map, 0, sizeof(struct xfs_bmbt_irec));
+
+			error = xfs_attr_rmt_find_hole(args);
+			if (error)
+				return error;
+
+			args->dc.blkcnt = args->rmtblkcnt;
+			args->dc.lblkno = args->rmtblkno;
+		}
+		/*
+		 * Roll through the "value", allocating blocks on disk as
+		 * required.
+		 */
+		while (args->dc.blkcnt > 0) {
+			nmap = 1;
+			error = xfs_bmapi_write(args->trans, dp,
+				(xfs_fileoff_t)args->dc.lblkno, args->dc.blkcnt,
+				XFS_BMAPI_ATTRFORK, args->total, map, &nmap);
+			if (error)
+				return error;
+
+			ASSERT(nmap == 1);
+			ASSERT((map->br_startblock != DELAYSTARTBLOCK) &&
+			       (map->br_startblock != HOLESTARTBLOCK));
+
+			/* roll attribute extent map forwards */
+			args->dc.lblkno += map->br_blockcount;
+			args->dc.blkcnt -= map->br_blockcount;
+
+			return -EAGAIN;
+		}
+
+		error = xfs_attr_rmtval_set_value(args);
+		if (error)
+			return error;
+	}
+
+	if (args->rmtblkno > 0) {
+		/*
+		 * Added a "remote" value, just clear the incomplete flag.
+		 */
+		error = xfs_attr3_leaf_clearflag(args);
+		if (error)
+			goto out;
+	}
+	retval = error = 0;
+
+out:
+	if (state)
+		xfs_da_state_free(state);
+	if (error)
+		return error;
+
+	return retval;
+}
+
+
+
+/*
  * Fill in the disk block numbers in the state structure for the buffers
  * that are attached to the state structure.
  * This is done so that we can quickly reattach ourselves to those buffers
fs/xfs/libxfs/xfs_attr.h +2 -0
index fb56d81..6203766 100644
@@ -149,9 +149,11 @@ int xfs_attr_get(struct xfs_inode *ip, struct xfs_name *name,
 int xfs_attr_set(struct xfs_inode *dp, struct xfs_name *name,
 		 unsigned char *value, int valuelen);
 int xfs_attr_set_args(struct xfs_da_args *args);
+int xfs_attr_set_later(struct xfs_da_args *args, struct xfs_buf **leaf_bp);
 int xfs_attr_remove(struct xfs_inode *dp, struct xfs_name *name);
 int xfs_has_attr(struct xfs_da_args *args);
 int xfs_attr_remove_args(struct xfs_da_args *args);
+int xfs_attr_remove_later(struct xfs_da_args *args);
 int xfs_attr_list(struct xfs_inode *dp, char *buffer, int bufsize,
 		  int flags, struct attrlist_cursor_kern *cursor);
 bool xfs_attr_namecheck(const void *name, size_t length);
Signature · 1 line
2.7.4
#46 lore raw

Re: [PATCH v3 14/19] xfs: Add delayed attribute routines

Quoted 94 lines · Brian Foster
Quoted 25 lines · Allison Collins

This patch adds new delayed attribute routines:

xfs_attr_set_later
xfs_attr_remove_later
xfs_leaf_addname_later
xfs_node_addname_later
xfs_node_removename_later

These routines are similar to their existing counter parts, but they do not roll or commit transactions. They instead return -EAGAIN to allow the calling function to roll the transaction and recall the function. This allows the attribute operations to be logged in multiple smaller transactions.

---
  fs/xfs/libxfs/xfs_attr.c | 591 ++++++++++++++++++++++++++++++++++++++++++++++-
  fs/xfs/libxfs/xfs_attr.h |   2 +
  2 files changed, 592 insertions(+), 1 deletion(-)
fs/xfs/libxfs/xfs_attr.c +0 -0
index 781dd8a..310f5b2 100644

...

Quoted 67 lines
fs/xfs/libxfs/xfs_attr.c +63 -0
@@ -313,6 +316,112 @@ xfs_attr_set_args(
  }
 
  /*
+ * Set the attribute specified in @args.
+ * This routine is meant to function as a delayed operation, and may return
+ * -EGAIN when the transaction needs to be rolled.  Calling functions will need
+ * to handle this, and recall the function until a successful error code is
+ * returned.
+ */
+int
+xfs_attr_set_later(
+	struct xfs_da_args	*args,
+	struct xfs_buf          **leaf_bp)
+{
+	struct xfs_inode	*dp = args->dp;
+	int			error = 0;
+	int			sf_size;
+
+	/*
+	 * New inodes may not have an attribute fork yet. So set the attribute
+	 * fork appropriately
+	 */
+	if (XFS_IFORK_Q((args->dp)) == 0) {
+		sf_size = sizeof(struct xfs_attr_sf_hdr) +
+		     XFS_ATTR_SF_ENTSIZE_BYNAME(args->name.len, args->valuelen);
+		xfs_bmap_set_attrforkoff(args->dp, sf_size, NULL);
+		args->dp->i_afp = kmem_zone_zalloc(xfs_ifork_zone, 0);
+		args->dp->i_afp->if_flags = XFS_IFEXTENTS;
+	}
+
+	/*
+	 * If the attribute list is non-existent or a shortform list,
+	 * upgrade it to a single-leaf-block attribute list.
+	 */
+	if (dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL ||
+	    (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS &&
+	     dp->i_d.di_anextents == 0)) {
+		/*
+		 * Build initial attribute list (if required).
+		 */
+		if (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS)
+			xfs_attr_shortform_create(args);
+
+		/*
+		 * Try to add the attr to the attribute list in the inode.
+		 */
+		error = xfs_attr_try_sf_addname(dp, args);
+		if (error != -ENOSPC)
+			return error;
+
+		/*
+		 * It won't fit in the shortform, transform to a leaf block.
+		 * GROT: another possible req'mt for a double-split btree op.
+		 */
+		error = xfs_attr_shortform_to_leaf(args, leaf_bp);
+		if (error)
+			return error;
+
+		/*
+		 * Prevent the leaf buffer from being unlocked so that a
+		 * concurrent AIL push cannot grab the half-baked leaf
+		 * buffer and run into problems with the write verifier.
+		 */
+
+		xfs_trans_bhold(args->trans, *leaf_bp);
+		return -EAGAIN;
Quoted 8 lines

fs/xfs/libxfs/xfs_attr.c xfs_attr_set_args( · line 382

Quoted 1 line
fs/xfs/libxfs/xfs_attr.c +1 -0
+	}

I haven't actually reviewed the code in this patch yet, but rather I skipped ahead to try and get an understanding of the design approach and flow of a deferred xattr operation. IIUC, we basically duplicate a bunch of xattr code into these dfops oriented functions but instead of rolling transactions, return -EAGAIN and use the XFS_DC_ state flags to manage reentrancy into the xfs_trans_attr() function.

Yes. If it helps to know a little more background about how it came into being...
Initially I had started out with the code paths merged, and had a boolean switch to control the alternate behavior (much like the "roll_trans" boolean from the prior sets, if you recall them). In a way, the boolean acted like a sort of marker of where things needed to get factored up. The goal being to pull the boolean into the higher level routines as much as possible and leaving behind all the little helpers which is what you see now in now patches 5 - 12.

After I got done with all the refactoring, the parts that still had the boolean were a sort of hybrid of the two paths you see now. At one point I made a judgment that continuing to factor up the boolean would be more complicated than not. I know people disliked the boolean toggle from the prior sets. So the *_later routines we have now are a result of the hybrid having been gutted of the boolean and split then off into its separate path.

Quoted 4 lines

If I'm following that correctly, I'm concerned about a couple things with the general approach. First, I think the complexity is high and maintainability is low/difficult for this kind of reentrant approach.

Yes. And I did very much anticipate a similar response. Thats certainly not to imply that I did all this for giggles, but because I think sometimes it's easy for designs to sound like good ideas in theory, until people see them in practice. And then the design takes a different direction. In a way I think the prototypes are a sort of necessary step for the design to evolve, even if the prototypes are sort of ugly. :-)

Quoted 4 lines

The state is managed/changed all throughout the call tree and so the risk and complexity of changing one particular bit in the sequence requires subtle consideration to make sure it doesn't cause problems if the function is reentered.

Yes, it's still very much a state machine in practice. But I think we may be stuck with at least some variant of state machine if we still want to adhere to the EAGAIN interface which requires the stack to back out. I have pondered the idea of introducing a call back to cycle out the transactions mid flight so that we dont need to stop and return. This would escape the state machine concept, but may require alternate surgery to the calling log routines too. So that may just turn into a different type of monster

For example, I'd prefer to see something like

Quoted 6 lines

xfs_trans_attr() broken down into smaller granularity functions with higher level state that is managed and readable in one place, if possible. Perhaps we could do that based on attr fork format, but I need to stare at the code and think about this some more (it might be that some degree of reentrancy is inevitable, or we just need to break things down to even smaller states...).

Yes, and I did go through a phase of trying to simplify the statemachine by trying to grab onto anything about the state of the fork that could be used instead. But its not always enough particularly in the case of routines that are in the middle of allocating or removing blocks. If you see any other mechanics that could help out, please call them out.

Quoted 9 lines

Second, it seems like a lot of this code duplication between deferred and non-deferred operations should be unnecessary, particularly since the only difference between the contexts is how transactions are managed. For example, if you follow the xattr set code path in both contexts, we can see that functions like xfs_attr_set_args() are basically duplicated in the xfs_attr_set_later() deferred variant just so we can change the xfs_defer_finish() call in the former to a return -EAGAIN in the latter.

Yes, they still carry some similarities. I guess I reasoned that continuing to carve things up into smaller and smaller helpers with out a generalized purpose (other than de-dup reduction) was starting to look a little weird, and maybe leaving things in their appropriate context might have been preferred? Folks are welcome to chime in with opinions though.

Quoted 8 lines

Instead, what I think we should strive for is a common xattr mechanism that consists of the lowest common denominator between the two contexts (or IOW, core infrastructure that can be invoked from either context). For example, on a kernel without deferred xattr support, could we find a way to call the deferred variants directly and just let the context-specific caller do the transaction rolls on -EAGAIN instead of relying on the dfops infrastructure?

I think I did that somewhere in the older parent pointer sets. At the time, we sort of forgot that we cant completely scrap non delayed attrs (because we need them for older versions). But then protofiles needed to create pptrs with out the delay mechanic, so I opened coded a sort of loop to deal with the EAGAIN. In fact, I ended up doing the same sort of loop in patch 15 for xfs_attri_recover, which has the same challenge. Maybe we could make a sort of general purpose wrapper?

ISTM that should be possible, it

Quoted 11 lines

just requires further breaking down the existing/non-deferred mechanism into smaller bits that uses the new state management logic and implements -EAGAIN handling for when the lower level code requires a transaction roll. At that point, deferred support should basically just consist of the dfops and log (i.e. intents) code to plug into the associated infrastructure. I think another side effect of that approach is that we shouldn't need these patches that add a bunch of new xattr infrastructure code, but rather we'd just continue refactoring the existing code and eventually implement a new high level function that returns -EAGAIN directly to the dfops code instead of rolling transactions explicitly. Thoughts?

Ok, I think I understand what you're trying to describe here. Maybe take a look at xfs_attri_recover in patch 15, and let me know if that was similar to what you were thinking?

Thank you for all the thorough reviewing here, I know it's a lot! Allison

Quoted 568 lines

Brian

Quoted 565 lines
fs/xfs/libxfs/xfs_attr.c +522 -0
+
+	/*
+	 * After a shortform to leaf conversion, we need to hold the leaf and
+	 * cylce out the transaction.  When we get back, we need to release
+	 * the leaf.
+	 */
+	if (*leaf_bp != NULL) {
+		xfs_trans_brelse(args->trans, *leaf_bp);
+		*leaf_bp = NULL;
+	}
+
+	/*
+	 * If we fit in a block, or we are in the middle of adding a leaf name.
+	 * xfs_attr_da_leaf_addname will set the XFS_DC_ALLOC_LEAF to indicate
+	 * that it is not done yet, and need to be recalled to finish up from
+	 * the last EAGAIN it returned
+	 */
+	if (xfs_bmap_one_block(dp, XFS_ATTR_FORK) ||
+	    args->dc.flags & XFS_DC_ALLOC_LEAF) {
+		if (!(args->dc.flags & XFS_DC_FOUND_LBLK)) {
+			error = xfs_attr_leaf_try_add(args, *leaf_bp);
+			args->dc.flags |= XFS_DC_FOUND_LBLK;
+
+			if (error && error != -ENOSPC)
+				return error;
+
+			return -EAGAIN;
+		}
+
+		error = xfs_leaf_addname_later(args);
+		if (error && error != -ENOSPC)
+			return error;
+	} else {
+		error = xfs_node_addname_later(args);
+	}
+
+	return error;
+}
+
+
+
+/*
   * Return EEXIST if attr is found, or ENOATTR if not
   */
  int
@@ -362,6 +471,57 @@ xfs_attr_remove_args(
  	return error;
  }
 
+/*
+ * Remove the attribute specified in @args.
+ * This routine is meant to function as a delayed operation, and may return
+ * -EGAIN when the transaction needs to be rolled.  Calling functions will need
+ * to handle this, and recall the function until a successful error code is
+ * returned.
+ */
+int
+xfs_attr_remove_later(
+	struct xfs_da_args      *args)
+{
+	struct xfs_inode	*dp = args->dp;
+	struct xfs_buf		*bp;
+	int			forkoff, error = 0;
+
+	if (!xfs_inode_hasattr(dp)) {
+		error = -ENOATTR;
+	} else if (dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) {
+		ASSERT(dp->i_afp->if_flags & XFS_IFINLINE);
+		error = xfs_attr_shortform_remove(args);
+	} else if (xfs_bmap_one_block(dp, XFS_ATTR_FORK) &&
+		   !(args->dc.flags & XFS_DC_RM_NODE_BLKS)) {
+		/*
+		 * If we fit in a block AND we are not in the middle of
+		 * removing node blocks, remove the leaf attribute.
+		 * xfs_attr_da_node_removename will set XFS_DC_RM_NODE_BLKS to
+		 * signal that it is not done yet, and needs to be recalled to
+		 * to finish up from the last -EAGAIN
+		 */
+		error = xfs_leaf_has_attr(args, &bp);
+		if (error == -ENOATTR) {
+			xfs_trans_brelse(args->trans, bp);
+			return error;
+		}
+		error = 0;
+
+		xfs_attr3_leaf_remove(bp, args);
+
+		/* If the result is small enough, shrink it into the inode.*/
+		forkoff = xfs_attr_shortform_allfit(bp, dp);
+		if (forkoff)
+			error = xfs_attr3_leaf_to_shortform(bp, args, forkoff);
+	} else {
+		error = xfs_node_removename_later(args);
+	}
+
+	return error;
+}
+
+
+
  int
  xfs_attr_set(
  	struct xfs_inode	*dp,
@@ -794,6 +954,87 @@ xfs_attr_leaf_addname(struct xfs_da_args	*args)
  }
 
  /*
+ * Add a name to the leaf attribute list structure
+ *
+ * This leaf block cannot have a "remote" value, we only call this routine
+ * if bmap_one_block() says there is only one block (ie: no remote blks).
+ *
+ * This routine is meant to function as a delayed operation, and may return
+ * -EGAIN when the transaction needs to be rolled.  Calling functions will need
+ * to handle this, and recall the function until a successful error code is
+ * returned.
+ */
+STATIC int
+xfs_leaf_addname_later(
+	struct xfs_da_args	*args)
+{
+	int			error, nmap;
+	struct xfs_inode	*dp = args->dp;
+	struct xfs_bmbt_irec	*map = &args->dc.map;
+
+	/*
+	 * If there was an out-of-line value, allocate the blocks we
+	 * identified for its storage and copy the value.  This is done
+	 * after we create the attribute so that we don't overflow the
+	 * maximum size of a transaction and/or hit a deadlock.
+	 */
+	if (args->rmtblkno > 0) {
+		if (!(args->dc.flags & XFS_DC_ALLOC_LEAF)) {
+			args->dc.lfileoff = 0;
+			args->dc.lblkno = 0;
+			args->dc.blkcnt = 0;
+			args->rmtblkcnt = 0;
+			args->rmtblkno = 0;
+			memset(map, 0, sizeof(struct xfs_bmbt_irec));
+
+			error = xfs_attr_rmt_find_hole(args);
+			if (error)
+				return error;
+
+			args->dc.blkcnt = args->rmtblkcnt;
+			args->dc.lblkno = args->rmtblkno;
+			args->dc.flags |= XFS_DC_ALLOC_LEAF;
+		}
+
+		/*
+		 * Roll through the "value", allocating blocks on disk as
+		 * required.
+		 */
+		while (args->dc.blkcnt > 0) {
+			nmap = 1;
+			error = xfs_bmapi_write(args->trans, dp,
+				  (xfs_fileoff_t)args->dc.lblkno,
+				  args->dc.blkcnt, XFS_BMAPI_ATTRFORK,
+				  args->total, map, &nmap);
+			if (error)
+				return error;
+			ASSERT(nmap == 1);
+			ASSERT((map->br_startblock != DELAYSTARTBLOCK) &&
+			       (map->br_startblock != HOLESTARTBLOCK));
+
+			/* roll attribute extent map forwards */
+			args->dc.lblkno += map->br_blockcount;
+			args->dc.blkcnt -= map->br_blockcount;
+
+			return -EAGAIN;
+		}
+
+		error = xfs_attr_rmtval_set_value(args);
+		if (error)
+			return error;
+	}
+
+	if (args->rmtblkno > 0) {
+		/*
+		 * Added a "remote" value, just clear the incomplete flag.
+		 */
+		error = xfs_attr3_leaf_clearflag(args);
+	}
+	args->dc.flags &= ~XFS_DC_ALLOC_LEAF;
+	return error;
+}
+
+/*
   * Return EEXIST if attr is found, or ENOATTR if not
   */
  STATIC int
@@ -1291,6 +1532,354 @@ xfs_attr_node_removename(
  }
 
  /*
+ * Remove a name from a B-tree attribute list.
+ *
+ * This will involve walking down the Btree, and may involve joining
+ * leaf nodes and even joining intermediate nodes up to and including
+ * the root node (a special case of an intermediate node).
+ *
+ * This routine is meant to function as a delayed operation, and may return
+ * -EGAIN when the transaction needs to be rolled.  Calling functions
+ * will need to handle this, and recall the function until a successful error
+ * code is returned.
+ */
+STATIC int
+xfs_node_removename_later(
+	struct xfs_da_args	*args)
+{
+	struct xfs_da_state	*state = NULL;
+	struct xfs_da_state_blk	*blk;
+	struct xfs_buf		*bp;
+	int			error, forkoff, retval = 0;
+	struct xfs_inode	*dp = args->dp;
+	int			done = 0;
+
+	trace_xfs_attr_node_removename(args);
+
+	if (args->dc.state == NULL) {
+		error = xfs_attr_node_hasname(args, &args->dc.state);
+		if (error != -EEXIST)
+			goto out;
+		else
+			error = 0;
+
+		/*
+		 * If there is an out-of-line value, de-allocate the blocks.
+		 * This is done before we remove the attribute so that we don't
+		 * overflow the maximum size of a transaction and/or hit a
+		 * deadlock.
+		 */
+		state = args->dc.state;
+		args->dc.blk = &state->path.blk[state->path.active - 1];
+		ASSERT(args->dc.blk->bp != NULL);
+		ASSERT(args->dc.blk->magic == XFS_ATTR_LEAF_MAGIC);
+	}
+	state = args->dc.state;
+	blk = args->dc.blk;
+
+	if (args->rmtblkno > 0 && !(args->dc.flags & XFS_DC_RM_LEAF_BLKS)) {
+		bool isset;
+
+		error = xfs_attr3_leaf_flag_is_set(args, &isset);
+		if (error)
+			goto out;
+		if (!isset) {
+			/*
+			 * Fill in disk block numbers in the state structure
+			 * so that we can get the buffers back after we commit
+			 * several transactions in the following calls.
+			 */
+			error = xfs_attr_fillstate(state);
+			if (error)
+				goto out;
+
+			/*
+			 * Mark the attribute as INCOMPLETE, then bunmapi() the
+			 * remote value.
+			 */
+			error = xfs_attr3_leaf_setflag(args);
+			if (error)
+				goto out;
+
+			return -EAGAIN;
+		}
+
+		if (!(args->dc.flags & XFS_DC_RM_NODE_BLKS)) {
+			args->dc.flags |= XFS_DC_RM_NODE_BLKS;
+			error = xfs_attr_rmtval_invalidate(args);
+			if (error)
+				goto out;
+		}
+
+		/*
+		 * Unmap value blocks for this attr.  This is similar to
+		 * xfs_attr_rmtval_remove, but open coded here to return EAGAIN
+		 * for new transactions
+		 */
+		while (!done && !error) {
+			error = xfs_bunmapi(args->trans, args->dp,
+				    args->rmtblkno, args->rmtblkcnt,
+				    XFS_BMAPI_ATTRFORK, 1, &done);
+			if (error)
+				return error;
+
+			if (!done)
+				return -EAGAIN;
+		}
+
+		if (error)
+			goto out;
+
+		/*
+		 * Refill the state structure with buffers, the prior calls
+		 * released our buffers.
+		 */
+		error = xfs_attr_refillstate(state);
+		if (error)
+			goto out;
+	}
+
+	/*
+	 * Remove the name and update the hashvals in the tree.
+	 */
+	if (!(args->dc.flags & XFS_DC_RM_LEAF_BLKS)) {
+		blk = &state->path.blk[state->path.active - 1];
+		ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
+		retval = xfs_attr3_leaf_remove(blk->bp, args);
+		xfs_da3_fixhashpath(state, &state->path);
+
+		args->dc.flags |= XFS_DC_RM_LEAF_BLKS;
+	}
+
+	/*
+	 * Check to see if the tree needs to be collapsed.
+	 */
+	if (retval && (state->path.active > 1)) {
+		args->dc.flags |= XFS_DC_RM_NODE_BLKS;
+		error = xfs_da3_join(state);
+		if (error)
+			goto out;
+
+		return -EAGAIN;
+	}
+
+	/*
+	 * If the result is small enough, push it all into the inode.
+	 */
+	if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
+		/*
+		 * Have to get rid of the copy of this dabuf in the state.
+		 */
+		ASSERT(state->path.active == 1);
+		ASSERT(state->path.blk[0].bp);
+		state->path.blk[0].bp = NULL;
+
+		error = xfs_attr3_leaf_read(args->trans, args->dp, 0, -1, &bp);
+		if (error)
+			goto out;
+
+		forkoff = xfs_attr_shortform_allfit(bp, dp);
+		if (forkoff) {
+			error = xfs_attr3_leaf_to_shortform(bp, args, forkoff);
+			/* bp is gone due to xfs_da_shrink_inode */
+			if (error)
+				goto out;
+		} else
+			xfs_trans_brelse(args->trans, bp);
+	}
+out:
+	if (state != NULL)
+		xfs_da_state_free(state);
+
+	return error;
+}
+
+/*
+ * Add a name to a Btree-format attribute list.
+ *
+ * This will involve walking down the Btree, and may involve splitting
+ * leaf nodes and even splitting intermediate nodes up to and including
+ * the root node (a special case of an intermediate node).
+ *
+ * "Remote" attribute values confuse the issue and atomic rename operations
+ * add a whole extra layer of confusion on top of that.
+ *
+ * This routine is meant to function as a delayed operation, and may return
+ * -EGAIN when the transaction needs to be rolled.  Calling functions will need
+ * to handle this, and recall the function until a successful error code is
+ *returned.
+ */
+STATIC int
+xfs_node_addname_later(
+	struct xfs_da_args	*args)
+{
+	struct xfs_da_state	*state = NULL;
+	struct xfs_da_state_blk	*blk;
+	struct xfs_inode	*dp;
+	int			retval, error = 0;
+	int			nmap;
+	struct xfs_bmbt_irec    *map = &args->dc.map;
+
+	trace_xfs_attr_node_addname(args);
+
+	/*
+	 * Fill in bucket of arguments/results/context to carry around.
+	 */
+	dp = args->dp;
+
+	if (args->dc.flags & XFS_DC_FOUND_NBLK)
+		goto found_blk;
+
+	/*
+	 * Search to see if name already exists, and get back a pointer
+	 * to where it should go.
+	 */
+	retval = xfs_attr_node_hasname(args, &state);
+	blk = &state->path.blk[state->path.active-1];
+	ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
+	if ((args->name.type & ATTR_REPLACE) && (retval == -ENOATTR)) {
+		goto out;
+	} else if (retval == -EEXIST) {
+		if (args->name.type & ATTR_CREATE)
+			goto out;
+
+		trace_xfs_attr_node_replace(args);
+
+		/* save the attribute state for later removal*/
+		args->op_flags |= XFS_DA_OP_RENAME;	/* atomic rename op */
+		args->blkno2 = args->blkno;		/* set 2nd entry info*/
+		args->index2 = args->index;
+		args->rmtblkno2 = args->rmtblkno;
+		args->rmtblkcnt2 = args->rmtblkcnt;
+		args->rmtvaluelen2 = args->rmtvaluelen;
+
+		/*
+		 * clear the remote attr state now that it is saved so that the
+		 * values reflect the state of the attribute we are about to
+		 * add, not the attribute we just found and will remove later.
+		 */
+		args->rmtblkno = 0;
+		args->rmtblkcnt = 0;
+		args->rmtvaluelen = 0;
+	}
+
+	retval = xfs_attr3_leaf_add(blk->bp, state->args);
+	if (retval == -ENOSPC) {
+		if (state->path.active == 1) {
+			/*
+			 * Its really a single leaf node, but it had
+			 * out-of-line values so it looked like it *might*
+			 * have been a b-tree.
+			 */
+			xfs_da_state_free(state);
+			state = NULL;
+			error = xfs_attr3_leaf_to_node(args);
+			if (error)
+				goto out;
+
+			return -EAGAIN;
+		}
+
+		/*
+		 * Split as many Btree elements as required.
+		 * This code tracks the new and old attr's location
+		 * in the index/blkno/rmtblkno/rmtblkcnt fields and
+		 * in the index2/blkno2/rmtblkno2/rmtblkcnt2 fields.
+		 */
+		error = xfs_da3_split(state);
+		if (error)
+			goto out;
+	} else {
+		/*
+		 * Addition succeeded, update Btree hashvals.
+		 */
+		xfs_da3_fixhashpath(state, &state->path);
+	}
+
+	/*
+	 * Kill the state structure, we're done with it and need to
+	 * allow the buffers to come back later.
+	 */
+	xfs_da_state_free(state);
+	state = NULL;
+
+	args->dc.flags |= XFS_DC_FOUND_NBLK;
+	return -EAGAIN;
+found_blk:
+
+	/*
+	 * If there was an out-of-line value, allocate the blocks we
+	 * identified for its storage and copy the value.  This is done
+	 * after we create the attribute so that we don't overflow the
+	 * maximum size of a transaction and/or hit a deadlock.
+	 */
+	if (args->rmtblkno > 0) {
+		if (!(args->dc.flags & XFS_DC_ALLOC_NODE)) {
+			args->dc.flags |= XFS_DC_ALLOC_NODE;
+			args->dc.lblkno = 0;
+			args->dc.lfileoff = 0;
+			args->dc.blkcnt = 0;
+			args->rmtblkcnt = 0;
+			args->rmtblkno = 0;
+			memset(map, 0, sizeof(struct xfs_bmbt_irec));
+
+			error = xfs_attr_rmt_find_hole(args);
+			if (error)
+				return error;
+
+			args->dc.blkcnt = args->rmtblkcnt;
+			args->dc.lblkno = args->rmtblkno;
+		}
+		/*
+		 * Roll through the "value", allocating blocks on disk as
+		 * required.
+		 */
+		while (args->dc.blkcnt > 0) {
+			nmap = 1;
+			error = xfs_bmapi_write(args->trans, dp,
+				(xfs_fileoff_t)args->dc.lblkno, args->dc.blkcnt,
+				XFS_BMAPI_ATTRFORK, args->total, map, &nmap);
+			if (error)
+				return error;
+
+			ASSERT(nmap == 1);
+			ASSERT((map->br_startblock != DELAYSTARTBLOCK) &&
+			       (map->br_startblock != HOLESTARTBLOCK));
+
+			/* roll attribute extent map forwards */
+			args->dc.lblkno += map->br_blockcount;
+			args->dc.blkcnt -= map->br_blockcount;
+
+			return -EAGAIN;
+		}
+
+		error = xfs_attr_rmtval_set_value(args);
+		if (error)
+			return error;
+	}
+
+	if (args->rmtblkno > 0) {
+		/*
+		 * Added a "remote" value, just clear the incomplete flag.
+		 */
+		error = xfs_attr3_leaf_clearflag(args);
+		if (error)
+			goto out;
+	}
+	retval = error = 0;
+
+out:
+	if (state)
+		xfs_da_state_free(state);
+	if (error)
+		return error;
+
+	return retval;
+}
+
+
+
+/*
   * Fill in the disk block numbers in the state structure for the buffers
   * that are attached to the state structure.
   * This is done so that we can quickly reattach ourselves to those buffers
fs/xfs/libxfs/xfs_attr.h +2 -0
index fb56d81..6203766 100644
@@ -149,9 +149,11 @@ int xfs_attr_get(struct xfs_inode *ip, struct xfs_name *name,
  int xfs_attr_set(struct xfs_inode *dp, struct xfs_name *name,
  		 unsigned char *value, int valuelen);
  int xfs_attr_set_args(struct xfs_da_args *args);
+int xfs_attr_set_later(struct xfs_da_args *args, struct xfs_buf **leaf_bp);
  int xfs_attr_remove(struct xfs_inode *dp, struct xfs_name *name);
  int xfs_has_attr(struct xfs_da_args *args);
  int xfs_attr_remove_args(struct xfs_da_args *args);
+int xfs_attr_remove_later(struct xfs_da_args *args);
  int xfs_attr_list(struct xfs_inode *dp, char *buffer, int bufsize,
  		  int flags, struct attrlist_cursor_kern *cursor);
  bool xfs_attr_namecheck(const void *name, size_t length);
Signature · 1 line
2.7.4
#47 lore raw

Re: [PATCH v3 14/19] xfs: Add delayed attribute routines

Quoted 126 lines · Allison Collins
Quoted 93 lines · Brian Foster
Quoted 25 lines · Allison Collins

This patch adds new delayed attribute routines:

xfs_attr_set_later
xfs_attr_remove_later
xfs_leaf_addname_later
xfs_node_addname_later
xfs_node_removename_later

These routines are similar to their existing counter parts, but they do not roll or commit transactions. They instead return -EAGAIN to allow the calling function to roll the transaction and recall the function. This allows the attribute operations to be logged in multiple smaller transactions.

---
  fs/xfs/libxfs/xfs_attr.c | 591 ++++++++++++++++++++++++++++++++++++++++++++++-
  fs/xfs/libxfs/xfs_attr.h |   2 +
  2 files changed, 592 insertions(+), 1 deletion(-)
fs/xfs/libxfs/xfs_attr.c +0 -0
index 781dd8a..310f5b2 100644

...

Quoted 66 lines
fs/xfs/libxfs/xfs_attr.c +63 -0
@@ -313,6 +316,112 @@ xfs_attr_set_args(
  }
  /*
+ * Set the attribute specified in @args.
+ * This routine is meant to function as a delayed operation, and may return
+ * -EGAIN when the transaction needs to be rolled.  Calling functions will need
+ * to handle this, and recall the function until a successful error code is
+ * returned.
+ */
+int
+xfs_attr_set_later(
+	struct xfs_da_args	*args,
+	struct xfs_buf          **leaf_bp)
+{
+	struct xfs_inode	*dp = args->dp;
+	int			error = 0;
+	int			sf_size;
+
+	/*
+	 * New inodes may not have an attribute fork yet. So set the attribute
+	 * fork appropriately
+	 */
+	if (XFS_IFORK_Q((args->dp)) == 0) {
+		sf_size = sizeof(struct xfs_attr_sf_hdr) +
+		     XFS_ATTR_SF_ENTSIZE_BYNAME(args->name.len, args->valuelen);
+		xfs_bmap_set_attrforkoff(args->dp, sf_size, NULL);
+		args->dp->i_afp = kmem_zone_zalloc(xfs_ifork_zone, 0);
+		args->dp->i_afp->if_flags = XFS_IFEXTENTS;
+	}
+
+	/*
+	 * If the attribute list is non-existent or a shortform list,
+	 * upgrade it to a single-leaf-block attribute list.
+	 */
+	if (dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL ||
+	    (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS &&
+	     dp->i_d.di_anextents == 0)) {
+		/*
+		 * Build initial attribute list (if required).
+		 */
+		if (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS)
+			xfs_attr_shortform_create(args);
+
+		/*
+		 * Try to add the attr to the attribute list in the inode.
+		 */
+		error = xfs_attr_try_sf_addname(dp, args);
+		if (error != -ENOSPC)
+			return error;
+
+		/*
+		 * It won't fit in the shortform, transform to a leaf block.
+		 * GROT: another possible req'mt for a double-split btree op.
+		 */
+		error = xfs_attr_shortform_to_leaf(args, leaf_bp);
+		if (error)
+			return error;
+
+		/*
+		 * Prevent the leaf buffer from being unlocked so that a
+		 * concurrent AIL push cannot grab the half-baked leaf
+		 * buffer and run into problems with the write verifier.
+		 */
+
+		xfs_trans_bhold(args->trans, *leaf_bp);
+		return -EAGAIN;
Quoted 8 lines

fs/xfs/libxfs/xfs_attr.c xfs_attr_set_args( · line 381

Quoted 1 line
fs/xfs/libxfs/xfs_attr.c +1 -0
+	}

I haven't actually reviewed the code in this patch yet, but rather I skipped ahead to try and get an understanding of the design approach and flow of a deferred xattr operation. IIUC, we basically duplicate a bunch of xattr code into these dfops oriented functions but instead of rolling transactions, return -EAGAIN and use the XFS_DC_ state flags to manage reentrancy into the xfs_trans_attr() function.

Yes. If it helps to know a little more background about how it came into being...
Initially I had started out with the code paths merged, and had a boolean switch to control the alternate behavior (much like the "roll_trans" boolean from the prior sets, if you recall them). In a way, the boolean acted like a sort of marker of where things needed to get factored up. The goal being to pull the boolean into the higher level routines as much as possible and leaving behind all the little helpers which is what you see now in now patches 5 - 12.

After I got done with all the refactoring, the parts that still had the boolean were a sort of hybrid of the two paths you see now. At one point I made a judgment that continuing to factor up the boolean would be more complicated than not. I know people disliked the boolean toggle from the prior sets. So the *_later routines we have now are a result of the hybrid having been gutted of the boolean and split then off into its separate path.

Quoted 4 lines

If I'm following that correctly, I'm concerned about a couple things with the general approach. First, I think the complexity is high and maintainability is low/difficult for this kind of reentrant approach.

Quoted 7 lines

Yes. And I did very much anticipate a similar response. Thats certainly not to imply that I did all this for giggles, but because I think sometimes it's easy for designs to sound like good ideas in theory, until people see them in practice. And then the design takes a different direction. In a way I think the prototypes are a sort of necessary step for the design to evolve, even if the prototypes are sort of ugly. :-)

Yeah, tbh I suspect that anything we come up with at first is going to have an ugliness factor due to the simple fact of how the code is currently implemented. IMO, the right approach is to take the current code apart as much as possible (without too much regard for aesthetic), identify/isolate the smallest functional components required to support both direct rolling and deferred operation rolling, and then from there think about cleaning up the design for how to fit those pieces back together. We might be able to do that in one patch series, but I wouldn't be surprised (or object to) doing it in several.

IOW, I think it would be reasonable to split off the effort of refactoring the existing xattr code to be "deferred capable" as an independent series if you didn't want to have to continue rebasing the follow on deferred xattr bits and wanted to try and get more rapid development+review cycles of the refactoring, but that's up to you. The whole idea for the refactoring is to not change existing behavior, so I don't see why that couldn't be a mergeable component on its own.

Quoted 4 lines
Quoted 4 lines

The state is managed/changed all throughout the call tree and so the risk and complexity of changing one particular bit in the sequence requires subtle consideration to make sure it doesn't cause problems if the function is reentered.

Quoted 8 lines

Yes, it's still very much a state machine in practice. But I think we may be stuck with at least some variant of state machine if we still want to adhere to the EAGAIN interface which requires the stack to back out. I have pondered the idea of introducing a call back to cycle out the transactions mid flight so that we dont need to stop and return. This would escape the state machine concept, but may require alternate surgery to the calling log routines too. So that may just turn into a different type of monster

To be clear, I'm pretty much expecting it to continue to be a state machine. That seems to be the most simple way to break things down, I think. I'd rather not get into things like callbacks or whatever until we've broken down the functional components and have a more clear picture of things.

BTW, I thought one of your previous series' had a start on this in terms of just defining some quick and dirty states based on an enum or something and sticking them in a switch statement..? The point I'm trying to make is that while those kind of simple enumerated low level states are probably not where we want to leave things at the end, it might be a reasonable approach to break the existing code into those states and then try and polish things from there. I definitely think it would be easier to review from a design perspective...

Quoted 7 lines

For example, I'd prefer to see something like

Quoted 6 lines

xfs_trans_attr() broken down into smaller granularity functions with higher level state that is managed and readable in one place, if possible. Perhaps we could do that based on attr fork format, but I need to stare at the code and think about this some more (it might be that some degree of reentrancy is inevitable, or we just need to break things down to even smaller states...).

Quoted 6 lines

Yes, and I did go through a phase of trying to simplify the statemachine by trying to grab onto anything about the state of the fork that could be used instead. But its not always enough particularly in the case of routines that are in the middle of allocating or removing blocks. If you see any other mechanics that could help out, please call them out.

One of the things I'm wondering is if we'll be able to reduce the number of unique (sub-)states required by reordering some of the existing logic between the higher level states. For a quick example, the current series uses the XFS_DC_ALLOC_LEAF state for a one-time operation that's part of a state that can be reentered over and over. This raises the question to me of whether that _ALLOC_LEAF thing could eventually just be folded into the tail of the previous state.

To reiterate, for now I think it would be perfectly reasonable to make _ALLOC_LEAF its own independent state so the flag management isn't buried so deep in the xattr code...

Quoted 10 lines
Quoted 10 lines

Second, it seems like a lot of this code duplication between deferred and non-deferred operations should be unnecessary, particularly since the only difference between the contexts is how transactions are managed. For example, if you follow the xattr set code path in both contexts, we can see that functions like xfs_attr_set_args() are basically duplicated in the xfs_attr_set_later() deferred variant just so we can change the xfs_defer_finish() call in the former to a return -EAGAIN in the latter.

Quoted 6 lines

Yes, they still carry some similarities. I guess I reasoned that continuing to carve things up into smaller and smaller helpers with out a generalized purpose (other than de-dup reduction) was starting to look a little weird, and maybe leaving things in their appropriate context might have been preferred? Folks are welcome to chime in with opinions though.

As mentioned above, I think weird is to be expected, at least if we break things down into an intermediary state. That's just my .02 though. Maybe others have different ideas..

Quoted 28 lines
Quoted 8 lines

Instead, what I think we should strive for is a common xattr mechanism that consists of the lowest common denominator between the two contexts (or IOW, core infrastructure that can be invoked from either context). For example, on a kernel without deferred xattr support, could we find a way to call the deferred variants directly and just let the context-specific caller do the transaction rolls on -EAGAIN instead of relying on the dfops infrastructure?

I think I did that somewhere in the older parent pointer sets. At the time, we sort of forgot that we cant completely scrap non delayed attrs (because we need them for older versions). But then protofiles needed to create pptrs with out the delay mechanic, so I opened coded a sort of loop to deal with the EAGAIN. In fact, I ended up doing the same sort of loop in patch 15 for xfs_attri_recover, which has the same challenge. Maybe we could make a sort of general purpose wrapper?

ISTM that should be possible, it

Quoted 11 lines

just requires further breaking down the existing/non-deferred mechanism into smaller bits that uses the new state management logic and implements -EAGAIN handling for when the lower level code requires a transaction roll. At that point, deferred support should basically just consist of the dfops and log (i.e. intents) code to plug into the associated infrastructure. I think another side effect of that approach is that we shouldn't need these patches that add a bunch of new xattr infrastructure code, but rather we'd just continue refactoring the existing code and eventually implement a new high level function that returns -EAGAIN directly to the dfops code instead of rolling transactions explicitly. Thoughts?

Quoted 4 lines

Ok, I think I understand what you're trying to describe here. Maybe take a look at xfs_attri_recover in patch 15, and let me know if that was similar to what you were thinking?

Yep, pretty much. Outside of the whole xfs_trans_attr() thing, I'd expect the direct xattr path to have to do something very similar in terms of invoking the xattr state machine and handling transaction rolls where the dfops mechanism isn't there to do it for us.

Brian

Quoted 568 lines

Thank you for all the thorough reviewing here, I know it's a lot! Allison

Quoted 565 lines

Brian

Quoted 562 lines
fs/xfs/libxfs/xfs_attr.c +522 -0
+
+	/*
+	 * After a shortform to leaf conversion, we need to hold the leaf and
+	 * cylce out the transaction.  When we get back, we need to release
+	 * the leaf.
+	 */
+	if (*leaf_bp != NULL) {
+		xfs_trans_brelse(args->trans, *leaf_bp);
+		*leaf_bp = NULL;
+	}
+
+	/*
+	 * If we fit in a block, or we are in the middle of adding a leaf name.
+	 * xfs_attr_da_leaf_addname will set the XFS_DC_ALLOC_LEAF to indicate
+	 * that it is not done yet, and need to be recalled to finish up from
+	 * the last EAGAIN it returned
+	 */
+	if (xfs_bmap_one_block(dp, XFS_ATTR_FORK) ||
+	    args->dc.flags & XFS_DC_ALLOC_LEAF) {
+		if (!(args->dc.flags & XFS_DC_FOUND_LBLK)) {
+			error = xfs_attr_leaf_try_add(args, *leaf_bp);
+			args->dc.flags |= XFS_DC_FOUND_LBLK;
+
+			if (error && error != -ENOSPC)
+				return error;
+
+			return -EAGAIN;
+		}
+
+		error = xfs_leaf_addname_later(args);
+		if (error && error != -ENOSPC)
+			return error;
+	} else {
+		error = xfs_node_addname_later(args);
+	}
+
+	return error;
+}
+
+
+
+/*
   * Return EEXIST if attr is found, or ENOATTR if not
   */
  int
@@ -362,6 +471,57 @@ xfs_attr_remove_args(
  	return error;
  }
+/*
+ * Remove the attribute specified in @args.
+ * This routine is meant to function as a delayed operation, and may return
+ * -EGAIN when the transaction needs to be rolled.  Calling functions will need
+ * to handle this, and recall the function until a successful error code is
+ * returned.
+ */
+int
+xfs_attr_remove_later(
+	struct xfs_da_args      *args)
+{
+	struct xfs_inode	*dp = args->dp;
+	struct xfs_buf		*bp;
+	int			forkoff, error = 0;
+
+	if (!xfs_inode_hasattr(dp)) {
+		error = -ENOATTR;
+	} else if (dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) {
+		ASSERT(dp->i_afp->if_flags & XFS_IFINLINE);
+		error = xfs_attr_shortform_remove(args);
+	} else if (xfs_bmap_one_block(dp, XFS_ATTR_FORK) &&
+		   !(args->dc.flags & XFS_DC_RM_NODE_BLKS)) {
+		/*
+		 * If we fit in a block AND we are not in the middle of
+		 * removing node blocks, remove the leaf attribute.
+		 * xfs_attr_da_node_removename will set XFS_DC_RM_NODE_BLKS to
+		 * signal that it is not done yet, and needs to be recalled to
+		 * to finish up from the last -EAGAIN
+		 */
+		error = xfs_leaf_has_attr(args, &bp);
+		if (error == -ENOATTR) {
+			xfs_trans_brelse(args->trans, bp);
+			return error;
+		}
+		error = 0;
+
+		xfs_attr3_leaf_remove(bp, args);
+
+		/* If the result is small enough, shrink it into the inode.*/
+		forkoff = xfs_attr_shortform_allfit(bp, dp);
+		if (forkoff)
+			error = xfs_attr3_leaf_to_shortform(bp, args, forkoff);
+	} else {
+		error = xfs_node_removename_later(args);
+	}
+
+	return error;
+}
+
+
+
  int
  xfs_attr_set(
  	struct xfs_inode	*dp,
@@ -794,6 +954,87 @@ xfs_attr_leaf_addname(struct xfs_da_args	*args)
  }
  /*
+ * Add a name to the leaf attribute list structure
+ *
+ * This leaf block cannot have a "remote" value, we only call this routine
+ * if bmap_one_block() says there is only one block (ie: no remote blks).
+ *
+ * This routine is meant to function as a delayed operation, and may return
+ * -EGAIN when the transaction needs to be rolled.  Calling functions will need
+ * to handle this, and recall the function until a successful error code is
+ * returned.
+ */
+STATIC int
+xfs_leaf_addname_later(
+	struct xfs_da_args	*args)
+{
+	int			error, nmap;
+	struct xfs_inode	*dp = args->dp;
+	struct xfs_bmbt_irec	*map = &args->dc.map;
+
+	/*
+	 * If there was an out-of-line value, allocate the blocks we
+	 * identified for its storage and copy the value.  This is done
+	 * after we create the attribute so that we don't overflow the
+	 * maximum size of a transaction and/or hit a deadlock.
+	 */
+	if (args->rmtblkno > 0) {
+		if (!(args->dc.flags & XFS_DC_ALLOC_LEAF)) {
+			args->dc.lfileoff = 0;
+			args->dc.lblkno = 0;
+			args->dc.blkcnt = 0;
+			args->rmtblkcnt = 0;
+			args->rmtblkno = 0;
+			memset(map, 0, sizeof(struct xfs_bmbt_irec));
+
+			error = xfs_attr_rmt_find_hole(args);
+			if (error)
+				return error;
+
+			args->dc.blkcnt = args->rmtblkcnt;
+			args->dc.lblkno = args->rmtblkno;
+			args->dc.flags |= XFS_DC_ALLOC_LEAF;
+		}
+
+		/*
+		 * Roll through the "value", allocating blocks on disk as
+		 * required.
+		 */
+		while (args->dc.blkcnt > 0) {
+			nmap = 1;
+			error = xfs_bmapi_write(args->trans, dp,
+				  (xfs_fileoff_t)args->dc.lblkno,
+				  args->dc.blkcnt, XFS_BMAPI_ATTRFORK,
+				  args->total, map, &nmap);
+			if (error)
+				return error;
+			ASSERT(nmap == 1);
+			ASSERT((map->br_startblock != DELAYSTARTBLOCK) &&
+			       (map->br_startblock != HOLESTARTBLOCK));
+
+			/* roll attribute extent map forwards */
+			args->dc.lblkno += map->br_blockcount;
+			args->dc.blkcnt -= map->br_blockcount;
+
+			return -EAGAIN;
+		}
+
+		error = xfs_attr_rmtval_set_value(args);
+		if (error)
+			return error;
+	}
+
+	if (args->rmtblkno > 0) {
+		/*
+		 * Added a "remote" value, just clear the incomplete flag.
+		 */
+		error = xfs_attr3_leaf_clearflag(args);
+	}
+	args->dc.flags &= ~XFS_DC_ALLOC_LEAF;
+	return error;
+}
+
+/*
   * Return EEXIST if attr is found, or ENOATTR if not
   */
  STATIC int
@@ -1291,6 +1532,354 @@ xfs_attr_node_removename(
  }
  /*
+ * Remove a name from a B-tree attribute list.
+ *
+ * This will involve walking down the Btree, and may involve joining
+ * leaf nodes and even joining intermediate nodes up to and including
+ * the root node (a special case of an intermediate node).
+ *
+ * This routine is meant to function as a delayed operation, and may return
+ * -EGAIN when the transaction needs to be rolled.  Calling functions
+ * will need to handle this, and recall the function until a successful error
+ * code is returned.
+ */
+STATIC int
+xfs_node_removename_later(
+	struct xfs_da_args	*args)
+{
+	struct xfs_da_state	*state = NULL;
+	struct xfs_da_state_blk	*blk;
+	struct xfs_buf		*bp;
+	int			error, forkoff, retval = 0;
+	struct xfs_inode	*dp = args->dp;
+	int			done = 0;
+
+	trace_xfs_attr_node_removename(args);
+
+	if (args->dc.state == NULL) {
+		error = xfs_attr_node_hasname(args, &args->dc.state);
+		if (error != -EEXIST)
+			goto out;
+		else
+			error = 0;
+
+		/*
+		 * If there is an out-of-line value, de-allocate the blocks.
+		 * This is done before we remove the attribute so that we don't
+		 * overflow the maximum size of a transaction and/or hit a
+		 * deadlock.
+		 */
+		state = args->dc.state;
+		args->dc.blk = &state->path.blk[state->path.active - 1];
+		ASSERT(args->dc.blk->bp != NULL);
+		ASSERT(args->dc.blk->magic == XFS_ATTR_LEAF_MAGIC);
+	}
+	state = args->dc.state;
+	blk = args->dc.blk;
+
+	if (args->rmtblkno > 0 && !(args->dc.flags & XFS_DC_RM_LEAF_BLKS)) {
+		bool isset;
+
+		error = xfs_attr3_leaf_flag_is_set(args, &isset);
+		if (error)
+			goto out;
+		if (!isset) {
+			/*
+			 * Fill in disk block numbers in the state structure
+			 * so that we can get the buffers back after we commit
+			 * several transactions in the following calls.
+			 */
+			error = xfs_attr_fillstate(state);
+			if (error)
+				goto out;
+
+			/*
+			 * Mark the attribute as INCOMPLETE, then bunmapi() the
+			 * remote value.
+			 */
+			error = xfs_attr3_leaf_setflag(args);
+			if (error)
+				goto out;
+
+			return -EAGAIN;
+		}
+
+		if (!(args->dc.flags & XFS_DC_RM_NODE_BLKS)) {
+			args->dc.flags |= XFS_DC_RM_NODE_BLKS;
+			error = xfs_attr_rmtval_invalidate(args);
+			if (error)
+				goto out;
+		}
+
+		/*
+		 * Unmap value blocks for this attr.  This is similar to
+		 * xfs_attr_rmtval_remove, but open coded here to return EAGAIN
+		 * for new transactions
+		 */
+		while (!done && !error) {
+			error = xfs_bunmapi(args->trans, args->dp,
+				    args->rmtblkno, args->rmtblkcnt,
+				    XFS_BMAPI_ATTRFORK, 1, &done);
+			if (error)
+				return error;
+
+			if (!done)
+				return -EAGAIN;
+		}
+
+		if (error)
+			goto out;
+
+		/*
+		 * Refill the state structure with buffers, the prior calls
+		 * released our buffers.
+		 */
+		error = xfs_attr_refillstate(state);
+		if (error)
+			goto out;
+	}
+
+	/*
+	 * Remove the name and update the hashvals in the tree.
+	 */
+	if (!(args->dc.flags & XFS_DC_RM_LEAF_BLKS)) {
+		blk = &state->path.blk[state->path.active - 1];
+		ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
+		retval = xfs_attr3_leaf_remove(blk->bp, args);
+		xfs_da3_fixhashpath(state, &state->path);
+
+		args->dc.flags |= XFS_DC_RM_LEAF_BLKS;
+	}
+
+	/*
+	 * Check to see if the tree needs to be collapsed.
+	 */
+	if (retval && (state->path.active > 1)) {
+		args->dc.flags |= XFS_DC_RM_NODE_BLKS;
+		error = xfs_da3_join(state);
+		if (error)
+			goto out;
+
+		return -EAGAIN;
+	}
+
+	/*
+	 * If the result is small enough, push it all into the inode.
+	 */
+	if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
+		/*
+		 * Have to get rid of the copy of this dabuf in the state.
+		 */
+		ASSERT(state->path.active == 1);
+		ASSERT(state->path.blk[0].bp);
+		state->path.blk[0].bp = NULL;
+
+		error = xfs_attr3_leaf_read(args->trans, args->dp, 0, -1, &bp);
+		if (error)
+			goto out;
+
+		forkoff = xfs_attr_shortform_allfit(bp, dp);
+		if (forkoff) {
+			error = xfs_attr3_leaf_to_shortform(bp, args, forkoff);
+			/* bp is gone due to xfs_da_shrink_inode */
+			if (error)
+				goto out;
+		} else
+			xfs_trans_brelse(args->trans, bp);
+	}
+out:
+	if (state != NULL)
+		xfs_da_state_free(state);
+
+	return error;
+}
+
+/*
+ * Add a name to a Btree-format attribute list.
+ *
+ * This will involve walking down the Btree, and may involve splitting
+ * leaf nodes and even splitting intermediate nodes up to and including
+ * the root node (a special case of an intermediate node).
+ *
+ * "Remote" attribute values confuse the issue and atomic rename operations
+ * add a whole extra layer of confusion on top of that.
+ *
+ * This routine is meant to function as a delayed operation, and may return
+ * -EGAIN when the transaction needs to be rolled.  Calling functions will need
+ * to handle this, and recall the function until a successful error code is
+ *returned.
+ */
+STATIC int
+xfs_node_addname_later(
+	struct xfs_da_args	*args)
+{
+	struct xfs_da_state	*state = NULL;
+	struct xfs_da_state_blk	*blk;
+	struct xfs_inode	*dp;
+	int			retval, error = 0;
+	int			nmap;
+	struct xfs_bmbt_irec    *map = &args->dc.map;
+
+	trace_xfs_attr_node_addname(args);
+
+	/*
+	 * Fill in bucket of arguments/results/context to carry around.
+	 */
+	dp = args->dp;
+
+	if (args->dc.flags & XFS_DC_FOUND_NBLK)
+		goto found_blk;
+
+	/*
+	 * Search to see if name already exists, and get back a pointer
+	 * to where it should go.
+	 */
+	retval = xfs_attr_node_hasname(args, &state);
+	blk = &state->path.blk[state->path.active-1];
+	ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
+	if ((args->name.type & ATTR_REPLACE) && (retval == -ENOATTR)) {
+		goto out;
+	} else if (retval == -EEXIST) {
+		if (args->name.type & ATTR_CREATE)
+			goto out;
+
+		trace_xfs_attr_node_replace(args);
+
+		/* save the attribute state for later removal*/
+		args->op_flags |= XFS_DA_OP_RENAME;	/* atomic rename op */
+		args->blkno2 = args->blkno;		/* set 2nd entry info*/
+		args->index2 = args->index;
+		args->rmtblkno2 = args->rmtblkno;
+		args->rmtblkcnt2 = args->rmtblkcnt;
+		args->rmtvaluelen2 = args->rmtvaluelen;
+
+		/*
+		 * clear the remote attr state now that it is saved so that the
+		 * values reflect the state of the attribute we are about to
+		 * add, not the attribute we just found and will remove later.
+		 */
+		args->rmtblkno = 0;
+		args->rmtblkcnt = 0;
+		args->rmtvaluelen = 0;
+	}
+
+	retval = xfs_attr3_leaf_add(blk->bp, state->args);
+	if (retval == -ENOSPC) {
+		if (state->path.active == 1) {
+			/*
+			 * Its really a single leaf node, but it had
+			 * out-of-line values so it looked like it *might*
+			 * have been a b-tree.
+			 */
+			xfs_da_state_free(state);
+			state = NULL;
+			error = xfs_attr3_leaf_to_node(args);
+			if (error)
+				goto out;
+
+			return -EAGAIN;
+		}
+
+		/*
+		 * Split as many Btree elements as required.
+		 * This code tracks the new and old attr's location
+		 * in the index/blkno/rmtblkno/rmtblkcnt fields and
+		 * in the index2/blkno2/rmtblkno2/rmtblkcnt2 fields.
+		 */
+		error = xfs_da3_split(state);
+		if (error)
+			goto out;
+	} else {
+		/*
+		 * Addition succeeded, update Btree hashvals.
+		 */
+		xfs_da3_fixhashpath(state, &state->path);
+	}
+
+	/*
+	 * Kill the state structure, we're done with it and need to
+	 * allow the buffers to come back later.
+	 */
+	xfs_da_state_free(state);
+	state = NULL;
+
+	args->dc.flags |= XFS_DC_FOUND_NBLK;
+	return -EAGAIN;
+found_blk:
+
+	/*
+	 * If there was an out-of-line value, allocate the blocks we
+	 * identified for its storage and copy the value.  This is done
+	 * after we create the attribute so that we don't overflow the
+	 * maximum size of a transaction and/or hit a deadlock.
+	 */
+	if (args->rmtblkno > 0) {
+		if (!(args->dc.flags & XFS_DC_ALLOC_NODE)) {
+			args->dc.flags |= XFS_DC_ALLOC_NODE;
+			args->dc.lblkno = 0;
+			args->dc.lfileoff = 0;
+			args->dc.blkcnt = 0;
+			args->rmtblkcnt = 0;
+			args->rmtblkno = 0;
+			memset(map, 0, sizeof(struct xfs_bmbt_irec));
+
+			error = xfs_attr_rmt_find_hole(args);
+			if (error)
+				return error;
+
+			args->dc.blkcnt = args->rmtblkcnt;
+			args->dc.lblkno = args->rmtblkno;
+		}
+		/*
+		 * Roll through the "value", allocating blocks on disk as
+		 * required.
+		 */
+		while (args->dc.blkcnt > 0) {
+			nmap = 1;
+			error = xfs_bmapi_write(args->trans, dp,
+				(xfs_fileoff_t)args->dc.lblkno, args->dc.blkcnt,
+				XFS_BMAPI_ATTRFORK, args->total, map, &nmap);
+			if (error)
+				return error;
+
+			ASSERT(nmap == 1);
+			ASSERT((map->br_startblock != DELAYSTARTBLOCK) &&
+			       (map->br_startblock != HOLESTARTBLOCK));
+
+			/* roll attribute extent map forwards */
+			args->dc.lblkno += map->br_blockcount;
+			args->dc.blkcnt -= map->br_blockcount;
+
+			return -EAGAIN;
+		}
+
+		error = xfs_attr_rmtval_set_value(args);
+		if (error)
+			return error;
+	}
+
+	if (args->rmtblkno > 0) {
+		/*
+		 * Added a "remote" value, just clear the incomplete flag.
+		 */
+		error = xfs_attr3_leaf_clearflag(args);
+		if (error)
+			goto out;
+	}
+	retval = error = 0;
+
+out:
+	if (state)
+		xfs_da_state_free(state);
+	if (error)
+		return error;
+
+	return retval;
+}
+
+
+
+/*
   * Fill in the disk block numbers in the state structure for the buffers
   * that are attached to the state structure.
   * This is done so that we can quickly reattach ourselves to those buffers
fs/xfs/libxfs/xfs_attr.h +2 -0
index fb56d81..6203766 100644
@@ -149,9 +149,11 @@ int xfs_attr_get(struct xfs_inode *ip, struct xfs_name *name,
  int xfs_attr_set(struct xfs_inode *dp, struct xfs_name *name,
  		 unsigned char *value, int valuelen);
  int xfs_attr_set_args(struct xfs_da_args *args);
+int xfs_attr_set_later(struct xfs_da_args *args, struct xfs_buf **leaf_bp);
  int xfs_attr_remove(struct xfs_inode *dp, struct xfs_name *name);
  int xfs_has_attr(struct xfs_da_args *args);
  int xfs_attr_remove_args(struct xfs_da_args *args);
+int xfs_attr_remove_later(struct xfs_da_args *args);
  int xfs_attr_list(struct xfs_inode *dp, char *buffer, int bufsize,
  		  int flags, struct attrlist_cursor_kern *cursor);
  bool xfs_attr_namecheck(const void *name, size_t length);
Signature · 1 line
2.7.4
#48 lore raw

Re: [PATCH v3 14/19] xfs: Add delayed attribute routines

Quoted 145 lines · Brian Foster
Quoted 126 lines · Allison Collins
Quoted 93 lines · Brian Foster
Quoted 25 lines · Allison Collins

This patch adds new delayed attribute routines:

xfs_attr_set_later
xfs_attr_remove_later
xfs_leaf_addname_later
xfs_node_addname_later
xfs_node_removename_later

These routines are similar to their existing counter parts, but they do not roll or commit transactions. They instead return -EAGAIN to allow the calling function to roll the transaction and recall the function. This allows the attribute operations to be logged in multiple smaller transactions.

---
   fs/xfs/libxfs/xfs_attr.c | 591 ++++++++++++++++++++++++++++++++++++++++++++++-
   fs/xfs/libxfs/xfs_attr.h |   2 +
   2 files changed, 592 insertions(+), 1 deletion(-)
fs/xfs/libxfs/xfs_attr.c +0 -0
index 781dd8a..310f5b2 100644

...

Quoted 66 lines
fs/xfs/libxfs/xfs_attr.c +63 -0
@@ -313,6 +316,112 @@ xfs_attr_set_args(
   }
   /*
+ * Set the attribute specified in @args.
+ * This routine is meant to function as a delayed operation, and may return
+ * -EGAIN when the transaction needs to be rolled.  Calling functions will need
+ * to handle this, and recall the function until a successful error code is
+ * returned.
+ */
+int
+xfs_attr_set_later(
+	struct xfs_da_args	*args,
+	struct xfs_buf          **leaf_bp)
+{
+	struct xfs_inode	*dp = args->dp;
+	int			error = 0;
+	int			sf_size;
+
+	/*
+	 * New inodes may not have an attribute fork yet. So set the attribute
+	 * fork appropriately
+	 */
+	if (XFS_IFORK_Q((args->dp)) == 0) {
+		sf_size = sizeof(struct xfs_attr_sf_hdr) +
+		     XFS_ATTR_SF_ENTSIZE_BYNAME(args->name.len, args->valuelen);
+		xfs_bmap_set_attrforkoff(args->dp, sf_size, NULL);
+		args->dp->i_afp = kmem_zone_zalloc(xfs_ifork_zone, 0);
+		args->dp->i_afp->if_flags = XFS_IFEXTENTS;
+	}
+
+	/*
+	 * If the attribute list is non-existent or a shortform list,
+	 * upgrade it to a single-leaf-block attribute list.
+	 */
+	if (dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL ||
+	    (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS &&
+	     dp->i_d.di_anextents == 0)) {
+		/*
+		 * Build initial attribute list (if required).
+		 */
+		if (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS)
+			xfs_attr_shortform_create(args);
+
+		/*
+		 * Try to add the attr to the attribute list in the inode.
+		 */
+		error = xfs_attr_try_sf_addname(dp, args);
+		if (error != -ENOSPC)
+			return error;
+
+		/*
+		 * It won't fit in the shortform, transform to a leaf block.
+		 * GROT: another possible req'mt for a double-split btree op.
+		 */
+		error = xfs_attr_shortform_to_leaf(args, leaf_bp);
+		if (error)
+			return error;
+
+		/*
+		 * Prevent the leaf buffer from being unlocked so that a
+		 * concurrent AIL push cannot grab the half-baked leaf
+		 * buffer and run into problems with the write verifier.
+		 */
+
+		xfs_trans_bhold(args->trans, *leaf_bp);
+		return -EAGAIN;
Quoted 8 lines

fs/xfs/libxfs/xfs_attr.c xfs_attr_set_args( · line 381

Quoted 1 line
fs/xfs/libxfs/xfs_attr.c +1 -0
+	}

I haven't actually reviewed the code in this patch yet, but rather I skipped ahead to try and get an understanding of the design approach and flow of a deferred xattr operation. IIUC, we basically duplicate a bunch of xattr code into these dfops oriented functions but instead of rolling transactions, return -EAGAIN and use the XFS_DC_ state flags to manage reentrancy into the xfs_trans_attr() function.

Yes. If it helps to know a little more background about how it came into being...
Initially I had started out with the code paths merged, and had a boolean switch to control the alternate behavior (much like the "roll_trans" boolean from the prior sets, if you recall them). In a way, the boolean acted like a sort of marker of where things needed to get factored up. The goal being to pull the boolean into the higher level routines as much as possible and leaving behind all the little helpers which is what you see now in now patches 5 - 12.

After I got done with all the refactoring, the parts that still had the boolean were a sort of hybrid of the two paths you see now. At one point I made a judgment that continuing to factor up the boolean would be more complicated than not. I know people disliked the boolean toggle from the prior sets. So the *_later routines we have now are a result of the hybrid having been gutted of the boolean and split then off into its separate path.

Quoted 4 lines

If I'm following that correctly, I'm concerned about a couple things with the general approach. First, I think the complexity is high and maintainability is low/difficult for this kind of reentrant approach.

Quoted 7 lines

Yes. And I did very much anticipate a similar response. Thats certainly not to imply that I did all this for giggles, but because I think sometimes it's easy for designs to sound like good ideas in theory, until people see them in practice. And then the design takes a different direction. In a way I think the prototypes are a sort of necessary step for the design to evolve, even if the prototypes are sort of ugly. :-)

Yeah, tbh I suspect that anything we come up with at first is going to have an ugliness factor due to the simple fact of how the code is currently implemented. IMO, the right approach is to take the current code apart as much as possible (without too much regard for aesthetic), identify/isolate the smallest functional components required to support both direct rolling and deferred operation rolling, and then from there think about cleaning up the design for how to fit those pieces back together. We might be able to do that in one patch series, but I wouldn't be surprised (or object to) doing it in several.

Quoted 7 lines

IOW, I think it would be reasonable to split off the effort of refactoring the existing xattr code to be "deferred capable" as an independent series if you didn't want to have to continue rebasing the follow on deferred xattr bits and wanted to try and get more rapid development+review cycles of the refactoring, but that's up to you. The whole idea for the refactoring is to not change existing behavior, so I don't see why that couldn't be a mergeable component on its own.

Ok, maybe I could break up the set after patch 14, and add a wrapper loop like the one we have in the recover routine. That might be a good way to introduce some of the set in smaller pieces.

Quoted 20 lines
Quoted 5 lines
Quoted 5 lines

The state is managed/changed all throughout the call tree and so the risk and complexity of changing one particular bit in the sequence requires subtle consideration to make sure it doesn't cause problems if the function is reentered.

Quoted 8 lines

Yes, it's still very much a state machine in practice. But I think we may be stuck with at least some variant of state machine if we still want to adhere to the EAGAIN interface which requires the stack to back out. I have pondered the idea of introducing a call back to cycle out the transactions mid flight so that we dont need to stop and return. This would escape the state machine concept, but may require alternate surgery to the calling log routines too. So that may just turn into a different type of monster

To be clear, I'm pretty much expecting it to continue to be a state machine. That seems to be the most simple way to break things down, I think. I'd rather not get into things like callbacks or whatever until we've broken down the functional components and have a more clear picture of things.

Quoted 8 lines

BTW, I thought one of your previous series' had a start on this in terms of just defining some quick and dirty states based on an enum or something and sticking them in a switch statement..? The point I'm trying to make is that while those kind of simple enumerated low level states are probably not where we want to leave things at the end, it might be a reasonable approach to break the existing code into those states and then try and polish things from there. I definitely think it would be easier to review from a design perspective...

Sure, I can bring back the state switch if people prefer. I got the impression that people thought it was odd, so I replaced it with the XFS_DC_* flags in this one. I figured that might be a little more like what people are used to seeing. IMHO I think the state switch might have been little cleaner in that it doesn't have to re-run over the same block of code multiple times to achieve the same end goal of getting back to where it was. If people have other opinions though please feel free to chime in.

Quoted 23 lines
Quoted 8 lines

For example, I'd prefer to see something like

Quoted 6 lines

xfs_trans_attr() broken down into smaller granularity functions with higher level state that is managed and readable in one place, if possible. Perhaps we could do that based on attr fork format, but I need to stare at the code and think about this some more (it might be that some degree of reentrancy is inevitable, or we just need to break things down to even smaller states...).

Quoted 6 lines

Yes, and I did go through a phase of trying to simplify the statemachine by trying to grab onto anything about the state of the fork that could be used instead. But its not always enough particularly in the case of routines that are in the middle of allocating or removing blocks. If you see any other mechanics that could help out, please call them out.

One of the things I'm wondering is if we'll be able to reduce the number of unique (sub-)states required by reordering some of the existing logic between the higher level states. For a quick example, the current series uses the XFS_DC_ALLOC_LEAF state for a one-time operation that's part of a state that can be reentered over and over. This raises the question to me of whether that _ALLOC_LEAF thing could eventually just be folded into the tail of the previous state.

Quoted 3 lines

To reiterate, for now I think it would be perfectly reasonable to make _ALLOC_LEAF its own independent state so the flag management isn't buried so deep in the xattr code...

Yes, it is one of the examples where trying to use the fork to control the state does not work out so well because we're in the middle of altering things. So in those cases, using the state machine to give it its own state starts to make more sense.

Quoted 55 lines
Quoted 11 lines
Quoted 11 lines

Second, it seems like a lot of this code duplication between deferred and non-deferred operations should be unnecessary, particularly since the only difference between the contexts is how transactions are managed. For example, if you follow the xattr set code path in both contexts, we can see that functions like xfs_attr_set_args() are basically duplicated in the xfs_attr_set_later() deferred variant just so we can change the xfs_defer_finish() call in the former to a return -EAGAIN in the latter.

Quoted 6 lines

Yes, they still carry some similarities. I guess I reasoned that continuing to carve things up into smaller and smaller helpers with out a generalized purpose (other than de-dup reduction) was starting to look a little weird, and maybe leaving things in their appropriate context might have been preferred? Folks are welcome to chime in with opinions though.

As mentioned above, I think weird is to be expected, at least if we break things down into an intermediary state. That's just my .02 though. Maybe others have different ideas..

Quoted 28 lines
Quoted 8 lines

Instead, what I think we should strive for is a common xattr mechanism that consists of the lowest common denominator between the two contexts (or IOW, core infrastructure that can be invoked from either context). For example, on a kernel without deferred xattr support, could we find a way to call the deferred variants directly and just let the context-specific caller do the transaction rolls on -EAGAIN instead of relying on the dfops infrastructure?

I think I did that somewhere in the older parent pointer sets. At the time, we sort of forgot that we cant completely scrap non delayed attrs (because we need them for older versions). But then protofiles needed to create pptrs with out the delay mechanic, so I opened coded a sort of loop to deal with the EAGAIN. In fact, I ended up doing the same sort of loop in patch 15 for xfs_attri_recover, which has the same challenge. Maybe we could make a sort of general purpose wrapper?

ISTM that should be possible, it

Quoted 11 lines

just requires further breaking down the existing/non-deferred mechanism into smaller bits that uses the new state management logic and implements -EAGAIN handling for when the lower level code requires a transaction roll. At that point, deferred support should basically just consist of the dfops and log (i.e. intents) code to plug into the associated infrastructure. I think another side effect of that approach is that we shouldn't need these patches that add a bunch of new xattr infrastructure code, but rather we'd just continue refactoring the existing code and eventually implement a new high level function that returns -EAGAIN directly to the dfops code instead of rolling transactions explicitly. Thoughts?

Quoted 4 lines

Ok, I think I understand what you're trying to describe here. Maybe take a look at xfs_attri_recover in patch 15, and let me know if that was similar to what you were thinking?

Quoted 6 lines

Yep, pretty much. Outside of the whole xfs_trans_attr() thing, I'd expect the direct xattr path to have to do something very similar in terms of invoking the xattr state machine and handling transaction rolls where the dfops mechanism isn't there to do it for us.

Brian

Sure, that shouldn't be to hard to make a high level wrapper like that. Then we can let go of the old code path.

Thanks again for the all the reviewing! :-)

Allison

Quoted 569 lines
Quoted 569 lines

Thank you for all the thorough reviewing here, I know it's a lot! Allison

Quoted 565 lines

Brian

Quoted 562 lines
fs/xfs/libxfs/xfs_attr.c +522 -0
+
+	/*
+	 * After a shortform to leaf conversion, we need to hold the leaf and
+	 * cylce out the transaction.  When we get back, we need to release
+	 * the leaf.
+	 */
+	if (*leaf_bp != NULL) {
+		xfs_trans_brelse(args->trans, *leaf_bp);
+		*leaf_bp = NULL;
+	}
+
+	/*
+	 * If we fit in a block, or we are in the middle of adding a leaf name.
+	 * xfs_attr_da_leaf_addname will set the XFS_DC_ALLOC_LEAF to indicate
+	 * that it is not done yet, and need to be recalled to finish up from
+	 * the last EAGAIN it returned
+	 */
+	if (xfs_bmap_one_block(dp, XFS_ATTR_FORK) ||
+	    args->dc.flags & XFS_DC_ALLOC_LEAF) {
+		if (!(args->dc.flags & XFS_DC_FOUND_LBLK)) {
+			error = xfs_attr_leaf_try_add(args, *leaf_bp);
+			args->dc.flags |= XFS_DC_FOUND_LBLK;
+
+			if (error && error != -ENOSPC)
+				return error;
+
+			return -EAGAIN;
+		}
+
+		error = xfs_leaf_addname_later(args);
+		if (error && error != -ENOSPC)
+			return error;
+	} else {
+		error = xfs_node_addname_later(args);
+	}
+
+	return error;
+}
+
+
+
+/*
    * Return EEXIST if attr is found, or ENOATTR if not
    */
   int
@@ -362,6 +471,57 @@ xfs_attr_remove_args(
   	return error;
   }
+/*
+ * Remove the attribute specified in @args.
+ * This routine is meant to function as a delayed operation, and may return
+ * -EGAIN when the transaction needs to be rolled.  Calling functions will need
+ * to handle this, and recall the function until a successful error code is
+ * returned.
+ */
+int
+xfs_attr_remove_later(
+	struct xfs_da_args      *args)
+{
+	struct xfs_inode	*dp = args->dp;
+	struct xfs_buf		*bp;
+	int			forkoff, error = 0;
+
+	if (!xfs_inode_hasattr(dp)) {
+		error = -ENOATTR;
+	} else if (dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) {
+		ASSERT(dp->i_afp->if_flags & XFS_IFINLINE);
+		error = xfs_attr_shortform_remove(args);
+	} else if (xfs_bmap_one_block(dp, XFS_ATTR_FORK) &&
+		   !(args->dc.flags & XFS_DC_RM_NODE_BLKS)) {
+		/*
+		 * If we fit in a block AND we are not in the middle of
+		 * removing node blocks, remove the leaf attribute.
+		 * xfs_attr_da_node_removename will set XFS_DC_RM_NODE_BLKS to
+		 * signal that it is not done yet, and needs to be recalled to
+		 * to finish up from the last -EAGAIN
+		 */
+		error = xfs_leaf_has_attr(args, &bp);
+		if (error == -ENOATTR) {
+			xfs_trans_brelse(args->trans, bp);
+			return error;
+		}
+		error = 0;
+
+		xfs_attr3_leaf_remove(bp, args);
+
+		/* If the result is small enough, shrink it into the inode.*/
+		forkoff = xfs_attr_shortform_allfit(bp, dp);
+		if (forkoff)
+			error = xfs_attr3_leaf_to_shortform(bp, args, forkoff);
+	} else {
+		error = xfs_node_removename_later(args);
+	}
+
+	return error;
+}
+
+
+
   int
   xfs_attr_set(
   	struct xfs_inode	*dp,
@@ -794,6 +954,87 @@ xfs_attr_leaf_addname(struct xfs_da_args	*args)
   }
   /*
+ * Add a name to the leaf attribute list structure
+ *
+ * This leaf block cannot have a "remote" value, we only call this routine
+ * if bmap_one_block() says there is only one block (ie: no remote blks).
+ *
+ * This routine is meant to function as a delayed operation, and may return
+ * -EGAIN when the transaction needs to be rolled.  Calling functions will need
+ * to handle this, and recall the function until a successful error code is
+ * returned.
+ */
+STATIC int
+xfs_leaf_addname_later(
+	struct xfs_da_args	*args)
+{
+	int			error, nmap;
+	struct xfs_inode	*dp = args->dp;
+	struct xfs_bmbt_irec	*map = &args->dc.map;
+
+	/*
+	 * If there was an out-of-line value, allocate the blocks we
+	 * identified for its storage and copy the value.  This is done
+	 * after we create the attribute so that we don't overflow the
+	 * maximum size of a transaction and/or hit a deadlock.
+	 */
+	if (args->rmtblkno > 0) {
+		if (!(args->dc.flags & XFS_DC_ALLOC_LEAF)) {
+			args->dc.lfileoff = 0;
+			args->dc.lblkno = 0;
+			args->dc.blkcnt = 0;
+			args->rmtblkcnt = 0;
+			args->rmtblkno = 0;
+			memset(map, 0, sizeof(struct xfs_bmbt_irec));
+
+			error = xfs_attr_rmt_find_hole(args);
+			if (error)
+				return error;
+
+			args->dc.blkcnt = args->rmtblkcnt;
+			args->dc.lblkno = args->rmtblkno;
+			args->dc.flags |= XFS_DC_ALLOC_LEAF;
+		}
+
+		/*
+		 * Roll through the "value", allocating blocks on disk as
+		 * required.
+		 */
+		while (args->dc.blkcnt > 0) {
+			nmap = 1;
+			error = xfs_bmapi_write(args->trans, dp,
+				  (xfs_fileoff_t)args->dc.lblkno,
+				  args->dc.blkcnt, XFS_BMAPI_ATTRFORK,
+				  args->total, map, &nmap);
+			if (error)
+				return error;
+			ASSERT(nmap == 1);
+			ASSERT((map->br_startblock != DELAYSTARTBLOCK) &&
+			       (map->br_startblock != HOLESTARTBLOCK));
+
+			/* roll attribute extent map forwards */
+			args->dc.lblkno += map->br_blockcount;
+			args->dc.blkcnt -= map->br_blockcount;
+
+			return -EAGAIN;
+		}
+
+		error = xfs_attr_rmtval_set_value(args);
+		if (error)
+			return error;
+	}
+
+	if (args->rmtblkno > 0) {
+		/*
+		 * Added a "remote" value, just clear the incomplete flag.
+		 */
+		error = xfs_attr3_leaf_clearflag(args);
+	}
+	args->dc.flags &= ~XFS_DC_ALLOC_LEAF;
+	return error;
+}
+
+/*
    * Return EEXIST if attr is found, or ENOATTR if not
    */
   STATIC int
@@ -1291,6 +1532,354 @@ xfs_attr_node_removename(
   }
   /*
+ * Remove a name from a B-tree attribute list.
+ *
+ * This will involve walking down the Btree, and may involve joining
+ * leaf nodes and even joining intermediate nodes up to and including
+ * the root node (a special case of an intermediate node).
+ *
+ * This routine is meant to function as a delayed operation, and may return
+ * -EGAIN when the transaction needs to be rolled.  Calling functions
+ * will need to handle this, and recall the function until a successful error
+ * code is returned.
+ */
+STATIC int
+xfs_node_removename_later(
+	struct xfs_da_args	*args)
+{
+	struct xfs_da_state	*state = NULL;
+	struct xfs_da_state_blk	*blk;
+	struct xfs_buf		*bp;
+	int			error, forkoff, retval = 0;
+	struct xfs_inode	*dp = args->dp;
+	int			done = 0;
+
+	trace_xfs_attr_node_removename(args);
+
+	if (args->dc.state == NULL) {
+		error = xfs_attr_node_hasname(args, &args->dc.state);
+		if (error != -EEXIST)
+			goto out;
+		else
+			error = 0;
+
+		/*
+		 * If there is an out-of-line value, de-allocate the blocks.
+		 * This is done before we remove the attribute so that we don't
+		 * overflow the maximum size of a transaction and/or hit a
+		 * deadlock.
+		 */
+		state = args->dc.state;
+		args->dc.blk = &state->path.blk[state->path.active - 1];
+		ASSERT(args->dc.blk->bp != NULL);
+		ASSERT(args->dc.blk->magic == XFS_ATTR_LEAF_MAGIC);
+	}
+	state = args->dc.state;
+	blk = args->dc.blk;
+
+	if (args->rmtblkno > 0 && !(args->dc.flags & XFS_DC_RM_LEAF_BLKS)) {
+		bool isset;
+
+		error = xfs_attr3_leaf_flag_is_set(args, &isset);
+		if (error)
+			goto out;
+		if (!isset) {
+			/*
+			 * Fill in disk block numbers in the state structure
+			 * so that we can get the buffers back after we commit
+			 * several transactions in the following calls.
+			 */
+			error = xfs_attr_fillstate(state);
+			if (error)
+				goto out;
+
+			/*
+			 * Mark the attribute as INCOMPLETE, then bunmapi() the
+			 * remote value.
+			 */
+			error = xfs_attr3_leaf_setflag(args);
+			if (error)
+				goto out;
+
+			return -EAGAIN;
+		}
+
+		if (!(args->dc.flags & XFS_DC_RM_NODE_BLKS)) {
+			args->dc.flags |= XFS_DC_RM_NODE_BLKS;
+			error = xfs_attr_rmtval_invalidate(args);
+			if (error)
+				goto out;
+		}
+
+		/*
+		 * Unmap value blocks for this attr.  This is similar to
+		 * xfs_attr_rmtval_remove, but open coded here to return EAGAIN
+		 * for new transactions
+		 */
+		while (!done && !error) {
+			error = xfs_bunmapi(args->trans, args->dp,
+				    args->rmtblkno, args->rmtblkcnt,
+				    XFS_BMAPI_ATTRFORK, 1, &done);
+			if (error)
+				return error;
+
+			if (!done)
+				return -EAGAIN;
+		}
+
+		if (error)
+			goto out;
+
+		/*
+		 * Refill the state structure with buffers, the prior calls
+		 * released our buffers.
+		 */
+		error = xfs_attr_refillstate(state);
+		if (error)
+			goto out;
+	}
+
+	/*
+	 * Remove the name and update the hashvals in the tree.
+	 */
+	if (!(args->dc.flags & XFS_DC_RM_LEAF_BLKS)) {
+		blk = &state->path.blk[state->path.active - 1];
+		ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
+		retval = xfs_attr3_leaf_remove(blk->bp, args);
+		xfs_da3_fixhashpath(state, &state->path);
+
+		args->dc.flags |= XFS_DC_RM_LEAF_BLKS;
+	}
+
+	/*
+	 * Check to see if the tree needs to be collapsed.
+	 */
+	if (retval && (state->path.active > 1)) {
+		args->dc.flags |= XFS_DC_RM_NODE_BLKS;
+		error = xfs_da3_join(state);
+		if (error)
+			goto out;
+
+		return -EAGAIN;
+	}
+
+	/*
+	 * If the result is small enough, push it all into the inode.
+	 */
+	if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
+		/*
+		 * Have to get rid of the copy of this dabuf in the state.
+		 */
+		ASSERT(state->path.active == 1);
+		ASSERT(state->path.blk[0].bp);
+		state->path.blk[0].bp = NULL;
+
+		error = xfs_attr3_leaf_read(args->trans, args->dp, 0, -1, &bp);
+		if (error)
+			goto out;
+
+		forkoff = xfs_attr_shortform_allfit(bp, dp);
+		if (forkoff) {
+			error = xfs_attr3_leaf_to_shortform(bp, args, forkoff);
+			/* bp is gone due to xfs_da_shrink_inode */
+			if (error)
+				goto out;
+		} else
+			xfs_trans_brelse(args->trans, bp);
+	}
+out:
+	if (state != NULL)
+		xfs_da_state_free(state);
+
+	return error;
+}
+
+/*
+ * Add a name to a Btree-format attribute list.
+ *
+ * This will involve walking down the Btree, and may involve splitting
+ * leaf nodes and even splitting intermediate nodes up to and including
+ * the root node (a special case of an intermediate node).
+ *
+ * "Remote" attribute values confuse the issue and atomic rename operations
+ * add a whole extra layer of confusion on top of that.
+ *
+ * This routine is meant to function as a delayed operation, and may return
+ * -EGAIN when the transaction needs to be rolled.  Calling functions will need
+ * to handle this, and recall the function until a successful error code is
+ *returned.
+ */
+STATIC int
+xfs_node_addname_later(
+	struct xfs_da_args	*args)
+{
+	struct xfs_da_state	*state = NULL;
+	struct xfs_da_state_blk	*blk;
+	struct xfs_inode	*dp;
+	int			retval, error = 0;
+	int			nmap;
+	struct xfs_bmbt_irec    *map = &args->dc.map;
+
+	trace_xfs_attr_node_addname(args);
+
+	/*
+	 * Fill in bucket of arguments/results/context to carry around.
+	 */
+	dp = args->dp;
+
+	if (args->dc.flags & XFS_DC_FOUND_NBLK)
+		goto found_blk;
+
+	/*
+	 * Search to see if name already exists, and get back a pointer
+	 * to where it should go.
+	 */
+	retval = xfs_attr_node_hasname(args, &state);
+	blk = &state->path.blk[state->path.active-1];
+	ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
+	if ((args->name.type & ATTR_REPLACE) && (retval == -ENOATTR)) {
+		goto out;
+	} else if (retval == -EEXIST) {
+		if (args->name.type & ATTR_CREATE)
+			goto out;
+
+		trace_xfs_attr_node_replace(args);
+
+		/* save the attribute state for later removal*/
+		args->op_flags |= XFS_DA_OP_RENAME;	/* atomic rename op */
+		args->blkno2 = args->blkno;		/* set 2nd entry info*/
+		args->index2 = args->index;
+		args->rmtblkno2 = args->rmtblkno;
+		args->rmtblkcnt2 = args->rmtblkcnt;
+		args->rmtvaluelen2 = args->rmtvaluelen;
+
+		/*
+		 * clear the remote attr state now that it is saved so that the
+		 * values reflect the state of the attribute we are about to
+		 * add, not the attribute we just found and will remove later.
+		 */
+		args->rmtblkno = 0;
+		args->rmtblkcnt = 0;
+		args->rmtvaluelen = 0;
+	}
+
+	retval = xfs_attr3_leaf_add(blk->bp, state->args);
+	if (retval == -ENOSPC) {
+		if (state->path.active == 1) {
+			/*
+			 * Its really a single leaf node, but it had
+			 * out-of-line values so it looked like it *might*
+			 * have been a b-tree.
+			 */
+			xfs_da_state_free(state);
+			state = NULL;
+			error = xfs_attr3_leaf_to_node(args);
+			if (error)
+				goto out;
+
+			return -EAGAIN;
+		}
+
+		/*
+		 * Split as many Btree elements as required.
+		 * This code tracks the new and old attr's location
+		 * in the index/blkno/rmtblkno/rmtblkcnt fields and
+		 * in the index2/blkno2/rmtblkno2/rmtblkcnt2 fields.
+		 */
+		error = xfs_da3_split(state);
+		if (error)
+			goto out;
+	} else {
+		/*
+		 * Addition succeeded, update Btree hashvals.
+		 */
+		xfs_da3_fixhashpath(state, &state->path);
+	}
+
+	/*
+	 * Kill the state structure, we're done with it and need to
+	 * allow the buffers to come back later.
+	 */
+	xfs_da_state_free(state);
+	state = NULL;
+
+	args->dc.flags |= XFS_DC_FOUND_NBLK;
+	return -EAGAIN;
+found_blk:
+
+	/*
+	 * If there was an out-of-line value, allocate the blocks we
+	 * identified for its storage and copy the value.  This is done
+	 * after we create the attribute so that we don't overflow the
+	 * maximum size of a transaction and/or hit a deadlock.
+	 */
+	if (args->rmtblkno > 0) {
+		if (!(args->dc.flags & XFS_DC_ALLOC_NODE)) {
+			args->dc.flags |= XFS_DC_ALLOC_NODE;
+			args->dc.lblkno = 0;
+			args->dc.lfileoff = 0;
+			args->dc.blkcnt = 0;
+			args->rmtblkcnt = 0;
+			args->rmtblkno = 0;
+			memset(map, 0, sizeof(struct xfs_bmbt_irec));
+
+			error = xfs_attr_rmt_find_hole(args);
+			if (error)
+				return error;
+
+			args->dc.blkcnt = args->rmtblkcnt;
+			args->dc.lblkno = args->rmtblkno;
+		}
+		/*
+		 * Roll through the "value", allocating blocks on disk as
+		 * required.
+		 */
+		while (args->dc.blkcnt > 0) {
+			nmap = 1;
+			error = xfs_bmapi_write(args->trans, dp,
+				(xfs_fileoff_t)args->dc.lblkno, args->dc.blkcnt,
+				XFS_BMAPI_ATTRFORK, args->total, map, &nmap);
+			if (error)
+				return error;
+
+			ASSERT(nmap == 1);
+			ASSERT((map->br_startblock != DELAYSTARTBLOCK) &&
+			       (map->br_startblock != HOLESTARTBLOCK));
+
+			/* roll attribute extent map forwards */
+			args->dc.lblkno += map->br_blockcount;
+			args->dc.blkcnt -= map->br_blockcount;
+
+			return -EAGAIN;
+		}
+
+		error = xfs_attr_rmtval_set_value(args);
+		if (error)
+			return error;
+	}
+
+	if (args->rmtblkno > 0) {
+		/*
+		 * Added a "remote" value, just clear the incomplete flag.
+		 */
+		error = xfs_attr3_leaf_clearflag(args);
+		if (error)
+			goto out;
+	}
+	retval = error = 0;
+
+out:
+	if (state)
+		xfs_da_state_free(state);
+	if (error)
+		return error;
+
+	return retval;
+}
+
+
+
+/*
    * Fill in the disk block numbers in the state structure for the buffers
    * that are attached to the state structure.
    * This is done so that we can quickly reattach ourselves to those buffers
fs/xfs/libxfs/xfs_attr.h +2 -0
index fb56d81..6203766 100644
@@ -149,9 +149,11 @@ int xfs_attr_get(struct xfs_inode *ip, struct xfs_name *name,
   int xfs_attr_set(struct xfs_inode *dp, struct xfs_name *name,
   		 unsigned char *value, int valuelen);
   int xfs_attr_set_args(struct xfs_da_args *args);
+int xfs_attr_set_later(struct xfs_da_args *args, struct xfs_buf **leaf_bp);
   int xfs_attr_remove(struct xfs_inode *dp, struct xfs_name *name);
   int xfs_has_attr(struct xfs_da_args *args);
   int xfs_attr_remove_args(struct xfs_da_args *args);
+int xfs_attr_remove_later(struct xfs_da_args *args);
   int xfs_attr_list(struct xfs_inode *dp, char *buffer, int bufsize,
   		  int flags, struct attrlist_cursor_kern *cursor);
   bool xfs_attr_namecheck(const void *name, size_t length);
Signature · 1 line
2.7.4
#49 lore raw

Re: [PATCH v3 14/19] xfs: Add delayed attribute routines

Quoted 187 lines · Allison Collins
Quoted 145 lines · Brian Foster
Quoted 126 lines · Allison Collins
Quoted 93 lines · Brian Foster
Quoted 25 lines · Allison Collins

This patch adds new delayed attribute routines:

xfs_attr_set_later
xfs_attr_remove_later
xfs_leaf_addname_later
xfs_node_addname_later
xfs_node_removename_later

These routines are similar to their existing counter parts, but they do not roll or commit transactions. They instead return -EAGAIN to allow the calling function to roll the transaction and recall the function. This allows the attribute operations to be logged in multiple smaller transactions.

---
   fs/xfs/libxfs/xfs_attr.c | 591 ++++++++++++++++++++++++++++++++++++++++++++++-
   fs/xfs/libxfs/xfs_attr.h |   2 +
   2 files changed, 592 insertions(+), 1 deletion(-)
fs/xfs/libxfs/xfs_attr.c +0 -0
index 781dd8a..310f5b2 100644

...

Quoted 66 lines
fs/xfs/libxfs/xfs_attr.c +63 -0
@@ -313,6 +316,112 @@ xfs_attr_set_args(
   }
   /*
+ * Set the attribute specified in @args.
+ * This routine is meant to function as a delayed operation, and may return
+ * -EGAIN when the transaction needs to be rolled.  Calling functions will need
+ * to handle this, and recall the function until a successful error code is
+ * returned.
+ */
+int
+xfs_attr_set_later(
+	struct xfs_da_args	*args,
+	struct xfs_buf          **leaf_bp)
+{
+	struct xfs_inode	*dp = args->dp;
+	int			error = 0;
+	int			sf_size;
+
+	/*
+	 * New inodes may not have an attribute fork yet. So set the attribute
+	 * fork appropriately
+	 */
+	if (XFS_IFORK_Q((args->dp)) == 0) {
+		sf_size = sizeof(struct xfs_attr_sf_hdr) +
+		     XFS_ATTR_SF_ENTSIZE_BYNAME(args->name.len, args->valuelen);
+		xfs_bmap_set_attrforkoff(args->dp, sf_size, NULL);
+		args->dp->i_afp = kmem_zone_zalloc(xfs_ifork_zone, 0);
+		args->dp->i_afp->if_flags = XFS_IFEXTENTS;
+	}
+
+	/*
+	 * If the attribute list is non-existent or a shortform list,
+	 * upgrade it to a single-leaf-block attribute list.
+	 */
+	if (dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL ||
+	    (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS &&
+	     dp->i_d.di_anextents == 0)) {
+		/*
+		 * Build initial attribute list (if required).
+		 */
+		if (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS)
+			xfs_attr_shortform_create(args);
+
+		/*
+		 * Try to add the attr to the attribute list in the inode.
+		 */
+		error = xfs_attr_try_sf_addname(dp, args);
+		if (error != -ENOSPC)
+			return error;
+
+		/*
+		 * It won't fit in the shortform, transform to a leaf block.
+		 * GROT: another possible req'mt for a double-split btree op.
+		 */
+		error = xfs_attr_shortform_to_leaf(args, leaf_bp);
+		if (error)
+			return error;
+
+		/*
+		 * Prevent the leaf buffer from being unlocked so that a
+		 * concurrent AIL push cannot grab the half-baked leaf
+		 * buffer and run into problems with the write verifier.
+		 */
+
+		xfs_trans_bhold(args->trans, *leaf_bp);
+		return -EAGAIN;
Quoted 8 lines

fs/xfs/libxfs/xfs_attr.c xfs_attr_set_args( · line 381

Quoted 1 line
fs/xfs/libxfs/xfs_attr.c +1 -0
+	}

I haven't actually reviewed the code in this patch yet, but rather I skipped ahead to try and get an understanding of the design approach and flow of a deferred xattr operation. IIUC, we basically duplicate a bunch of xattr code into these dfops oriented functions but instead of rolling transactions, return -EAGAIN and use the XFS_DC_ state flags to manage reentrancy into the xfs_trans_attr() function.

Yes. If it helps to know a little more background about how it came into being...
Initially I had started out with the code paths merged, and had a boolean switch to control the alternate behavior (much like the "roll_trans" boolean from the prior sets, if you recall them). In a way, the boolean acted like a sort of marker of where things needed to get factored up. The goal being to pull the boolean into the higher level routines as much as possible and leaving behind all the little helpers which is what you see now in now patches 5 - 12.

After I got done with all the refactoring, the parts that still had the boolean were a sort of hybrid of the two paths you see now. At one point I made a judgment that continuing to factor up the boolean would be more complicated than not. I know people disliked the boolean toggle from the prior sets. So the *_later routines we have now are a result of the hybrid having been gutted of the boolean and split then off into its separate path.

Quoted 4 lines

If I'm following that correctly, I'm concerned about a couple things with the general approach. First, I think the complexity is high and maintainability is low/difficult for this kind of reentrant approach.

Quoted 7 lines

Yes. And I did very much anticipate a similar response. Thats certainly not to imply that I did all this for giggles, but because I think sometimes it's easy for designs to sound like good ideas in theory, until people see them in practice. And then the design takes a different direction. In a way I think the prototypes are a sort of necessary step for the design to evolve, even if the prototypes are sort of ugly. :-)

Yeah, tbh I suspect that anything we come up with at first is going to have an ugliness factor due to the simple fact of how the code is currently implemented. IMO, the right approach is to take the current code apart as much as possible (without too much regard for aesthetic), identify/isolate the smallest functional components required to support both direct rolling and deferred operation rolling, and then from there think about cleaning up the design for how to fit those pieces back together. We might be able to do that in one patch series, but I wouldn't be surprised (or object to) doing it in several.

Quoted 7 lines

IOW, I think it would be reasonable to split off the effort of refactoring the existing xattr code to be "deferred capable" as an independent series if you didn't want to have to continue rebasing the follow on deferred xattr bits and wanted to try and get more rapid development+review cycles of the refactoring, but that's up to you. The whole idea for the refactoring is to not change existing behavior, so I don't see why that couldn't be a mergeable component on its own.

Ok, maybe I could break up the set after patch 14, and add a wrapper loop like the one we have in the recover routine. That might be a good way to introduce some of the set in smaller pieces.

Quoted 20 lines
Quoted 5 lines
Quoted 5 lines

The state is managed/changed all throughout the call tree and so the risk and complexity of changing one particular bit in the sequence requires subtle consideration to make sure it doesn't cause problems if the function is reentered.

Quoted 8 lines

Yes, it's still very much a state machine in practice. But I think we may be stuck with at least some variant of state machine if we still want to adhere to the EAGAIN interface which requires the stack to back out. I have pondered the idea of introducing a call back to cycle out the transactions mid flight so that we dont need to stop and return. This would escape the state machine concept, but may require alternate surgery to the calling log routines too. So that may just turn into a different type of monster

To be clear, I'm pretty much expecting it to continue to be a state machine. That seems to be the most simple way to break things down, I think. I'd rather not get into things like callbacks or whatever until we've broken down the functional components and have a more clear picture of things.

Quoted 8 lines

BTW, I thought one of your previous series' had a start on this in terms of just defining some quick and dirty states based on an enum or something and sticking them in a switch statement..? The point I'm trying to make is that while those kind of simple enumerated low level states are probably not where we want to leave things at the end, it might be a reasonable approach to break the existing code into those states and then try and polish things from there. I definitely think it would be easier to review from a design perspective...

Quoted 8 lines

Sure, I can bring back the state switch if people prefer. I got the impression that people thought it was odd, so I replaced it with the XFS_DC_* flags in this one. I figured that might be a little more like what people are used to seeing. IMHO I think the state switch might have been little cleaner in that it doesn't have to re-run over the same block of code multiple times to achieve the same end goal of getting back to where it was. If people have other opinions though please feel free to chime in.

To me, it's not so much preference as it is just thinking that's the best approach to get the code refactored and reviewed. I agree that the state machine approach is a bit more straightforward, even if crude, due to the elimination of the repeated function calls and flags controlling random blocks of code. As noted previously, my hope is that once we break things down mechanically into the crude states that exist in the current code, we'll come up with some nice ways to continue refactoring things, reduce the number of states required and/or maybe even think of a way to eliminate the state machine entirely.

It's definitely worth soliciting other opinions, though, before significantly refactoring things one way or the other..

Quoted 87 lines
Quoted 23 lines
Quoted 8 lines

For example, I'd prefer to see something like

Quoted 6 lines

xfs_trans_attr() broken down into smaller granularity functions with higher level state that is managed and readable in one place, if possible. Perhaps we could do that based on attr fork format, but I need to stare at the code and think about this some more (it might be that some degree of reentrancy is inevitable, or we just need to break things down to even smaller states...).

Quoted 6 lines

Yes, and I did go through a phase of trying to simplify the statemachine by trying to grab onto anything about the state of the fork that could be used instead. But its not always enough particularly in the case of routines that are in the middle of allocating or removing blocks. If you see any other mechanics that could help out, please call them out.

One of the things I'm wondering is if we'll be able to reduce the number of unique (sub-)states required by reordering some of the existing logic between the higher level states. For a quick example, the current series uses the XFS_DC_ALLOC_LEAF state for a one-time operation that's part of a state that can be reentered over and over. This raises the question to me of whether that _ALLOC_LEAF thing could eventually just be folded into the tail of the previous state.

Quoted 3 lines

To reiterate, for now I think it would be perfectly reasonable to make _ALLOC_LEAF its own independent state so the flag management isn't buried so deep in the xattr code...

Yes, it is one of the examples where trying to use the fork to control the state does not work out so well because we're in the middle of altering things. So in those cases, using the state machine to give it its own state starts to make more sense.

Quoted 55 lines
Quoted 11 lines
Quoted 11 lines

Second, it seems like a lot of this code duplication between deferred and non-deferred operations should be unnecessary, particularly since the only difference between the contexts is how transactions are managed. For example, if you follow the xattr set code path in both contexts, we can see that functions like xfs_attr_set_args() are basically duplicated in the xfs_attr_set_later() deferred variant just so we can change the xfs_defer_finish() call in the former to a return -EAGAIN in the latter.

Quoted 6 lines

Yes, they still carry some similarities. I guess I reasoned that continuing to carve things up into smaller and smaller helpers with out a generalized purpose (other than de-dup reduction) was starting to look a little weird, and maybe leaving things in their appropriate context might have been preferred? Folks are welcome to chime in with opinions though.

As mentioned above, I think weird is to be expected, at least if we break things down into an intermediary state. That's just my .02 though. Maybe others have different ideas..

Quoted 32 lines
Quoted 8 lines

Instead, what I think we should strive for is a common xattr mechanism that consists of the lowest common denominator between the two contexts (or IOW, core infrastructure that can be invoked from either context). For example, on a kernel without deferred xattr support, could we find a way to call the deferred variants directly and just let the context-specific caller do the transaction rolls on -EAGAIN instead of relying on the dfops infrastructure?

I think I did that somewhere in the older parent pointer sets. At the time, we sort of forgot that we cant completely scrap non delayed attrs (because we need them for older versions). But then protofiles needed to create pptrs with out the delay mechanic, so I opened coded a sort of loop to deal with the EAGAIN. In fact, I ended up doing the same sort of loop in patch 15 for xfs_attri_recover, which has the same challenge. Maybe we could make a sort of general purpose wrapper?

ISTM that should be possible, it

Quoted 11 lines

just requires further breaking down the existing/non-deferred mechanism into smaller bits that uses the new state management logic and implements -EAGAIN handling for when the lower level code requires a transaction roll. At that point, deferred support should basically just consist of the dfops and log (i.e. intents) code to plug into the associated infrastructure. I think another side effect of that approach is that we shouldn't need these patches that add a bunch of new xattr infrastructure code, but rather we'd just continue refactoring the existing code and eventually implement a new high level function that returns -EAGAIN directly to the dfops code instead of rolling transactions explicitly. Thoughts?

Ok, I think I understand what you're trying to describe here. Maybe take a look at xfs_attri_recover in patch 15, and let me know if that was similar to what you were thinking?

Quoted 9 lines
Quoted 6 lines

Yep, pretty much. Outside of the whole xfs_trans_attr() thing, I'd expect the direct xattr path to have to do something very similar in terms of invoking the xattr state machine and handling transaction rolls where the dfops mechanism isn't there to do it for us.

Brian

Sure, that shouldn't be to hard to make a high level wrapper like that. Then we can let go of the old code path.

I view it as more like reorganizing and reusing the old code path. ;)

Brian

Quoted 573 lines

Thanks again for the all the reviewing! :-)

Allison

Quoted 569 lines
Quoted 569 lines

Thank you for all the thorough reviewing here, I know it's a lot! Allison

Quoted 565 lines

Brian

Quoted 562 lines
fs/xfs/libxfs/xfs_attr.c +522 -0
+
+	/*
+	 * After a shortform to leaf conversion, we need to hold the leaf and
+	 * cylce out the transaction.  When we get back, we need to release
+	 * the leaf.
+	 */
+	if (*leaf_bp != NULL) {
+		xfs_trans_brelse(args->trans, *leaf_bp);
+		*leaf_bp = NULL;
+	}
+
+	/*
+	 * If we fit in a block, or we are in the middle of adding a leaf name.
+	 * xfs_attr_da_leaf_addname will set the XFS_DC_ALLOC_LEAF to indicate
+	 * that it is not done yet, and need to be recalled to finish up from
+	 * the last EAGAIN it returned
+	 */
+	if (xfs_bmap_one_block(dp, XFS_ATTR_FORK) ||
+	    args->dc.flags & XFS_DC_ALLOC_LEAF) {
+		if (!(args->dc.flags & XFS_DC_FOUND_LBLK)) {
+			error = xfs_attr_leaf_try_add(args, *leaf_bp);
+			args->dc.flags |= XFS_DC_FOUND_LBLK;
+
+			if (error && error != -ENOSPC)
+				return error;
+
+			return -EAGAIN;
+		}
+
+		error = xfs_leaf_addname_later(args);
+		if (error && error != -ENOSPC)
+			return error;
+	} else {
+		error = xfs_node_addname_later(args);
+	}
+
+	return error;
+}
+
+
+
+/*
    * Return EEXIST if attr is found, or ENOATTR if not
    */
   int
@@ -362,6 +471,57 @@ xfs_attr_remove_args(
   	return error;
   }
+/*
+ * Remove the attribute specified in @args.
+ * This routine is meant to function as a delayed operation, and may return
+ * -EGAIN when the transaction needs to be rolled.  Calling functions will need
+ * to handle this, and recall the function until a successful error code is
+ * returned.
+ */
+int
+xfs_attr_remove_later(
+	struct xfs_da_args      *args)
+{
+	struct xfs_inode	*dp = args->dp;
+	struct xfs_buf		*bp;
+	int			forkoff, error = 0;
+
+	if (!xfs_inode_hasattr(dp)) {
+		error = -ENOATTR;
+	} else if (dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) {
+		ASSERT(dp->i_afp->if_flags & XFS_IFINLINE);
+		error = xfs_attr_shortform_remove(args);
+	} else if (xfs_bmap_one_block(dp, XFS_ATTR_FORK) &&
+		   !(args->dc.flags & XFS_DC_RM_NODE_BLKS)) {
+		/*
+		 * If we fit in a block AND we are not in the middle of
+		 * removing node blocks, remove the leaf attribute.
+		 * xfs_attr_da_node_removename will set XFS_DC_RM_NODE_BLKS to
+		 * signal that it is not done yet, and needs to be recalled to
+		 * to finish up from the last -EAGAIN
+		 */
+		error = xfs_leaf_has_attr(args, &bp);
+		if (error == -ENOATTR) {
+			xfs_trans_brelse(args->trans, bp);
+			return error;
+		}
+		error = 0;
+
+		xfs_attr3_leaf_remove(bp, args);
+
+		/* If the result is small enough, shrink it into the inode.*/
+		forkoff = xfs_attr_shortform_allfit(bp, dp);
+		if (forkoff)
+			error = xfs_attr3_leaf_to_shortform(bp, args, forkoff);
+	} else {
+		error = xfs_node_removename_later(args);
+	}
+
+	return error;
+}
+
+
+
   int
   xfs_attr_set(
   	struct xfs_inode	*dp,
@@ -794,6 +954,87 @@ xfs_attr_leaf_addname(struct xfs_da_args	*args)
   }
   /*
+ * Add a name to the leaf attribute list structure
+ *
+ * This leaf block cannot have a "remote" value, we only call this routine
+ * if bmap_one_block() says there is only one block (ie: no remote blks).
+ *
+ * This routine is meant to function as a delayed operation, and may return
+ * -EGAIN when the transaction needs to be rolled.  Calling functions will need
+ * to handle this, and recall the function until a successful error code is
+ * returned.
+ */
+STATIC int
+xfs_leaf_addname_later(
+	struct xfs_da_args	*args)
+{
+	int			error, nmap;
+	struct xfs_inode	*dp = args->dp;
+	struct xfs_bmbt_irec	*map = &args->dc.map;
+
+	/*
+	 * If there was an out-of-line value, allocate the blocks we
+	 * identified for its storage and copy the value.  This is done
+	 * after we create the attribute so that we don't overflow the
+	 * maximum size of a transaction and/or hit a deadlock.
+	 */
+	if (args->rmtblkno > 0) {
+		if (!(args->dc.flags & XFS_DC_ALLOC_LEAF)) {
+			args->dc.lfileoff = 0;
+			args->dc.lblkno = 0;
+			args->dc.blkcnt = 0;
+			args->rmtblkcnt = 0;
+			args->rmtblkno = 0;
+			memset(map, 0, sizeof(struct xfs_bmbt_irec));
+
+			error = xfs_attr_rmt_find_hole(args);
+			if (error)
+				return error;
+
+			args->dc.blkcnt = args->rmtblkcnt;
+			args->dc.lblkno = args->rmtblkno;
+			args->dc.flags |= XFS_DC_ALLOC_LEAF;
+		}
+
+		/*
+		 * Roll through the "value", allocating blocks on disk as
+		 * required.
+		 */
+		while (args->dc.blkcnt > 0) {
+			nmap = 1;
+			error = xfs_bmapi_write(args->trans, dp,
+				  (xfs_fileoff_t)args->dc.lblkno,
+				  args->dc.blkcnt, XFS_BMAPI_ATTRFORK,
+				  args->total, map, &nmap);
+			if (error)
+				return error;
+			ASSERT(nmap == 1);
+			ASSERT((map->br_startblock != DELAYSTARTBLOCK) &&
+			       (map->br_startblock != HOLESTARTBLOCK));
+
+			/* roll attribute extent map forwards */
+			args->dc.lblkno += map->br_blockcount;
+			args->dc.blkcnt -= map->br_blockcount;
+
+			return -EAGAIN;
+		}
+
+		error = xfs_attr_rmtval_set_value(args);
+		if (error)
+			return error;
+	}
+
+	if (args->rmtblkno > 0) {
+		/*
+		 * Added a "remote" value, just clear the incomplete flag.
+		 */
+		error = xfs_attr3_leaf_clearflag(args);
+	}
+	args->dc.flags &= ~XFS_DC_ALLOC_LEAF;
+	return error;
+}
+
+/*
    * Return EEXIST if attr is found, or ENOATTR if not
    */
   STATIC int
@@ -1291,6 +1532,354 @@ xfs_attr_node_removename(
   }
   /*
+ * Remove a name from a B-tree attribute list.
+ *
+ * This will involve walking down the Btree, and may involve joining
+ * leaf nodes and even joining intermediate nodes up to and including
+ * the root node (a special case of an intermediate node).
+ *
+ * This routine is meant to function as a delayed operation, and may return
+ * -EGAIN when the transaction needs to be rolled.  Calling functions
+ * will need to handle this, and recall the function until a successful error
+ * code is returned.
+ */
+STATIC int
+xfs_node_removename_later(
+	struct xfs_da_args	*args)
+{
+	struct xfs_da_state	*state = NULL;
+	struct xfs_da_state_blk	*blk;
+	struct xfs_buf		*bp;
+	int			error, forkoff, retval = 0;
+	struct xfs_inode	*dp = args->dp;
+	int			done = 0;
+
+	trace_xfs_attr_node_removename(args);
+
+	if (args->dc.state == NULL) {
+		error = xfs_attr_node_hasname(args, &args->dc.state);
+		if (error != -EEXIST)
+			goto out;
+		else
+			error = 0;
+
+		/*
+		 * If there is an out-of-line value, de-allocate the blocks.
+		 * This is done before we remove the attribute so that we don't
+		 * overflow the maximum size of a transaction and/or hit a
+		 * deadlock.
+		 */
+		state = args->dc.state;
+		args->dc.blk = &state->path.blk[state->path.active - 1];
+		ASSERT(args->dc.blk->bp != NULL);
+		ASSERT(args->dc.blk->magic == XFS_ATTR_LEAF_MAGIC);
+	}
+	state = args->dc.state;
+	blk = args->dc.blk;
+
+	if (args->rmtblkno > 0 && !(args->dc.flags & XFS_DC_RM_LEAF_BLKS)) {
+		bool isset;
+
+		error = xfs_attr3_leaf_flag_is_set(args, &isset);
+		if (error)
+			goto out;
+		if (!isset) {
+			/*
+			 * Fill in disk block numbers in the state structure
+			 * so that we can get the buffers back after we commit
+			 * several transactions in the following calls.
+			 */
+			error = xfs_attr_fillstate(state);
+			if (error)
+				goto out;
+
+			/*
+			 * Mark the attribute as INCOMPLETE, then bunmapi() the
+			 * remote value.
+			 */
+			error = xfs_attr3_leaf_setflag(args);
+			if (error)
+				goto out;
+
+			return -EAGAIN;
+		}
+
+		if (!(args->dc.flags & XFS_DC_RM_NODE_BLKS)) {
+			args->dc.flags |= XFS_DC_RM_NODE_BLKS;
+			error = xfs_attr_rmtval_invalidate(args);
+			if (error)
+				goto out;
+		}
+
+		/*
+		 * Unmap value blocks for this attr.  This is similar to
+		 * xfs_attr_rmtval_remove, but open coded here to return EAGAIN
+		 * for new transactions
+		 */
+		while (!done && !error) {
+			error = xfs_bunmapi(args->trans, args->dp,
+				    args->rmtblkno, args->rmtblkcnt,
+				    XFS_BMAPI_ATTRFORK, 1, &done);
+			if (error)
+				return error;
+
+			if (!done)
+				return -EAGAIN;
+		}
+
+		if (error)
+			goto out;
+
+		/*
+		 * Refill the state structure with buffers, the prior calls
+		 * released our buffers.
+		 */
+		error = xfs_attr_refillstate(state);
+		if (error)
+			goto out;
+	}
+
+	/*
+	 * Remove the name and update the hashvals in the tree.
+	 */
+	if (!(args->dc.flags & XFS_DC_RM_LEAF_BLKS)) {
+		blk = &state->path.blk[state->path.active - 1];
+		ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
+		retval = xfs_attr3_leaf_remove(blk->bp, args);
+		xfs_da3_fixhashpath(state, &state->path);
+
+		args->dc.flags |= XFS_DC_RM_LEAF_BLKS;
+	}
+
+	/*
+	 * Check to see if the tree needs to be collapsed.
+	 */
+	if (retval && (state->path.active > 1)) {
+		args->dc.flags |= XFS_DC_RM_NODE_BLKS;
+		error = xfs_da3_join(state);
+		if (error)
+			goto out;
+
+		return -EAGAIN;
+	}
+
+	/*
+	 * If the result is small enough, push it all into the inode.
+	 */
+	if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
+		/*
+		 * Have to get rid of the copy of this dabuf in the state.
+		 */
+		ASSERT(state->path.active == 1);
+		ASSERT(state->path.blk[0].bp);
+		state->path.blk[0].bp = NULL;
+
+		error = xfs_attr3_leaf_read(args->trans, args->dp, 0, -1, &bp);
+		if (error)
+			goto out;
+
+		forkoff = xfs_attr_shortform_allfit(bp, dp);
+		if (forkoff) {
+			error = xfs_attr3_leaf_to_shortform(bp, args, forkoff);
+			/* bp is gone due to xfs_da_shrink_inode */
+			if (error)
+				goto out;
+		} else
+			xfs_trans_brelse(args->trans, bp);
+	}
+out:
+	if (state != NULL)
+		xfs_da_state_free(state);
+
+	return error;
+}
+
+/*
+ * Add a name to a Btree-format attribute list.
+ *
+ * This will involve walking down the Btree, and may involve splitting
+ * leaf nodes and even splitting intermediate nodes up to and including
+ * the root node (a special case of an intermediate node).
+ *
+ * "Remote" attribute values confuse the issue and atomic rename operations
+ * add a whole extra layer of confusion on top of that.
+ *
+ * This routine is meant to function as a delayed operation, and may return
+ * -EGAIN when the transaction needs to be rolled.  Calling functions will need
+ * to handle this, and recall the function until a successful error code is
+ *returned.
+ */
+STATIC int
+xfs_node_addname_later(
+	struct xfs_da_args	*args)
+{
+	struct xfs_da_state	*state = NULL;
+	struct xfs_da_state_blk	*blk;
+	struct xfs_inode	*dp;
+	int			retval, error = 0;
+	int			nmap;
+	struct xfs_bmbt_irec    *map = &args->dc.map;
+
+	trace_xfs_attr_node_addname(args);
+
+	/*
+	 * Fill in bucket of arguments/results/context to carry around.
+	 */
+	dp = args->dp;
+
+	if (args->dc.flags & XFS_DC_FOUND_NBLK)
+		goto found_blk;
+
+	/*
+	 * Search to see if name already exists, and get back a pointer
+	 * to where it should go.
+	 */
+	retval = xfs_attr_node_hasname(args, &state);
+	blk = &state->path.blk[state->path.active-1];
+	ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
+	if ((args->name.type & ATTR_REPLACE) && (retval == -ENOATTR)) {
+		goto out;
+	} else if (retval == -EEXIST) {
+		if (args->name.type & ATTR_CREATE)
+			goto out;
+
+		trace_xfs_attr_node_replace(args);
+
+		/* save the attribute state for later removal*/
+		args->op_flags |= XFS_DA_OP_RENAME;	/* atomic rename op */
+		args->blkno2 = args->blkno;		/* set 2nd entry info*/
+		args->index2 = args->index;
+		args->rmtblkno2 = args->rmtblkno;
+		args->rmtblkcnt2 = args->rmtblkcnt;
+		args->rmtvaluelen2 = args->rmtvaluelen;
+
+		/*
+		 * clear the remote attr state now that it is saved so that the
+		 * values reflect the state of the attribute we are about to
+		 * add, not the attribute we just found and will remove later.
+		 */
+		args->rmtblkno = 0;
+		args->rmtblkcnt = 0;
+		args->rmtvaluelen = 0;
+	}
+
+	retval = xfs_attr3_leaf_add(blk->bp, state->args);
+	if (retval == -ENOSPC) {
+		if (state->path.active == 1) {
+			/*
+			 * Its really a single leaf node, but it had
+			 * out-of-line values so it looked like it *might*
+			 * have been a b-tree.
+			 */
+			xfs_da_state_free(state);
+			state = NULL;
+			error = xfs_attr3_leaf_to_node(args);
+			if (error)
+				goto out;
+
+			return -EAGAIN;
+		}
+
+		/*
+		 * Split as many Btree elements as required.
+		 * This code tracks the new and old attr's location
+		 * in the index/blkno/rmtblkno/rmtblkcnt fields and
+		 * in the index2/blkno2/rmtblkno2/rmtblkcnt2 fields.
+		 */
+		error = xfs_da3_split(state);
+		if (error)
+			goto out;
+	} else {
+		/*
+		 * Addition succeeded, update Btree hashvals.
+		 */
+		xfs_da3_fixhashpath(state, &state->path);
+	}
+
+	/*
+	 * Kill the state structure, we're done with it and need to
+	 * allow the buffers to come back later.
+	 */
+	xfs_da_state_free(state);
+	state = NULL;
+
+	args->dc.flags |= XFS_DC_FOUND_NBLK;
+	return -EAGAIN;
+found_blk:
+
+	/*
+	 * If there was an out-of-line value, allocate the blocks we
+	 * identified for its storage and copy the value.  This is done
+	 * after we create the attribute so that we don't overflow the
+	 * maximum size of a transaction and/or hit a deadlock.
+	 */
+	if (args->rmtblkno > 0) {
+		if (!(args->dc.flags & XFS_DC_ALLOC_NODE)) {
+			args->dc.flags |= XFS_DC_ALLOC_NODE;
+			args->dc.lblkno = 0;
+			args->dc.lfileoff = 0;
+			args->dc.blkcnt = 0;
+			args->rmtblkcnt = 0;
+			args->rmtblkno = 0;
+			memset(map, 0, sizeof(struct xfs_bmbt_irec));
+
+			error = xfs_attr_rmt_find_hole(args);
+			if (error)
+				return error;
+
+			args->dc.blkcnt = args->rmtblkcnt;
+			args->dc.lblkno = args->rmtblkno;
+		}
+		/*
+		 * Roll through the "value", allocating blocks on disk as
+		 * required.
+		 */
+		while (args->dc.blkcnt > 0) {
+			nmap = 1;
+			error = xfs_bmapi_write(args->trans, dp,
+				(xfs_fileoff_t)args->dc.lblkno, args->dc.blkcnt,
+				XFS_BMAPI_ATTRFORK, args->total, map, &nmap);
+			if (error)
+				return error;
+
+			ASSERT(nmap == 1);
+			ASSERT((map->br_startblock != DELAYSTARTBLOCK) &&
+			       (map->br_startblock != HOLESTARTBLOCK));
+
+			/* roll attribute extent map forwards */
+			args->dc.lblkno += map->br_blockcount;
+			args->dc.blkcnt -= map->br_blockcount;
+
+			return -EAGAIN;
+		}
+
+		error = xfs_attr_rmtval_set_value(args);
+		if (error)
+			return error;
+	}
+
+	if (args->rmtblkno > 0) {
+		/*
+		 * Added a "remote" value, just clear the incomplete flag.
+		 */
+		error = xfs_attr3_leaf_clearflag(args);
+		if (error)
+			goto out;
+	}
+	retval = error = 0;
+
+out:
+	if (state)
+		xfs_da_state_free(state);
+	if (error)
+		return error;
+
+	return retval;
+}
+
+
+
+/*
    * Fill in the disk block numbers in the state structure for the buffers
    * that are attached to the state structure.
    * This is done so that we can quickly reattach ourselves to those buffers
fs/xfs/libxfs/xfs_attr.h +2 -0
index fb56d81..6203766 100644
@@ -149,9 +149,11 @@ int xfs_attr_get(struct xfs_inode *ip, struct xfs_name *name,
   int xfs_attr_set(struct xfs_inode *dp, struct xfs_name *name,
   		 unsigned char *value, int valuelen);
   int xfs_attr_set_args(struct xfs_da_args *args);
+int xfs_attr_set_later(struct xfs_da_args *args, struct xfs_buf **leaf_bp);
   int xfs_attr_remove(struct xfs_inode *dp, struct xfs_name *name);
   int xfs_has_attr(struct xfs_da_args *args);
   int xfs_attr_remove_args(struct xfs_da_args *args);
+int xfs_attr_remove_later(struct xfs_da_args *args);
   int xfs_attr_list(struct xfs_inode *dp, char *buffer, int bufsize,
   		  int flags, struct attrlist_cursor_kern *cursor);
   bool xfs_attr_namecheck(const void *name, size_t length);
Signature · 1 line
2.7.4
#50 lore raw

Re: [PATCH v3 14/19] xfs: Add delayed attribute routines

Quoted 197 lines · Brian Foster
Quoted 187 lines · Allison Collins
Quoted 145 lines · Brian Foster
Quoted 126 lines · Allison Collins
Quoted 93 lines · Brian Foster
Quoted 25 lines · Allison Collins

This patch adds new delayed attribute routines:

xfs_attr_set_later
xfs_attr_remove_later
xfs_leaf_addname_later
xfs_node_addname_later
xfs_node_removename_later

These routines are similar to their existing counter parts, but they do not roll or commit transactions. They instead return -EAGAIN to allow the calling function to roll the transaction and recall the function. This allows the attribute operations to be logged in multiple smaller transactions.

---
   fs/xfs/libxfs/xfs_attr.c | 591 ++++++++++++++++++++++++++++++++++++++++++++++-
   fs/xfs/libxfs/xfs_attr.h |   2 +
   2 files changed, 592 insertions(+), 1 deletion(-)
fs/xfs/libxfs/xfs_attr.c +0 -0
index 781dd8a..310f5b2 100644

...

Quoted 66 lines
fs/xfs/libxfs/xfs_attr.c +63 -0
@@ -313,6 +316,112 @@ xfs_attr_set_args(
   }
   /*
+ * Set the attribute specified in @args.
+ * This routine is meant to function as a delayed operation, and may return
+ * -EGAIN when the transaction needs to be rolled.  Calling functions will need
+ * to handle this, and recall the function until a successful error code is
+ * returned.
+ */
+int
+xfs_attr_set_later(
+	struct xfs_da_args	*args,
+	struct xfs_buf          **leaf_bp)
+{
+	struct xfs_inode	*dp = args->dp;
+	int			error = 0;
+	int			sf_size;
+
+	/*
+	 * New inodes may not have an attribute fork yet. So set the attribute
+	 * fork appropriately
+	 */
+	if (XFS_IFORK_Q((args->dp)) == 0) {
+		sf_size = sizeof(struct xfs_attr_sf_hdr) +
+		     XFS_ATTR_SF_ENTSIZE_BYNAME(args->name.len, args->valuelen);
+		xfs_bmap_set_attrforkoff(args->dp, sf_size, NULL);
+		args->dp->i_afp = kmem_zone_zalloc(xfs_ifork_zone, 0);
+		args->dp->i_afp->if_flags = XFS_IFEXTENTS;
+	}
+
+	/*
+	 * If the attribute list is non-existent or a shortform list,
+	 * upgrade it to a single-leaf-block attribute list.
+	 */
+	if (dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL ||
+	    (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS &&
+	     dp->i_d.di_anextents == 0)) {
+		/*
+		 * Build initial attribute list (if required).
+		 */
+		if (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS)
+			xfs_attr_shortform_create(args);
+
+		/*
+		 * Try to add the attr to the attribute list in the inode.
+		 */
+		error = xfs_attr_try_sf_addname(dp, args);
+		if (error != -ENOSPC)
+			return error;
+
+		/*
+		 * It won't fit in the shortform, transform to a leaf block.
+		 * GROT: another possible req'mt for a double-split btree op.
+		 */
+		error = xfs_attr_shortform_to_leaf(args, leaf_bp);
+		if (error)
+			return error;
+
+		/*
+		 * Prevent the leaf buffer from being unlocked so that a
+		 * concurrent AIL push cannot grab the half-baked leaf
+		 * buffer and run into problems with the write verifier.
+		 */
+
+		xfs_trans_bhold(args->trans, *leaf_bp);
+		return -EAGAIN;
Quoted 8 lines

fs/xfs/libxfs/xfs_attr.c xfs_attr_set_args( · line 381

Quoted 1 line
fs/xfs/libxfs/xfs_attr.c +1 -0
+	}

I haven't actually reviewed the code in this patch yet, but rather I skipped ahead to try and get an understanding of the design approach and flow of a deferred xattr operation. IIUC, we basically duplicate a bunch of xattr code into these dfops oriented functions but instead of rolling transactions, return -EAGAIN and use the XFS_DC_ state flags to manage reentrancy into the xfs_trans_attr() function.

Yes. If it helps to know a little more background about how it came into being...
Initially I had started out with the code paths merged, and had a boolean switch to control the alternate behavior (much like the "roll_trans" boolean from the prior sets, if you recall them). In a way, the boolean acted like a sort of marker of where things needed to get factored up. The goal being to pull the boolean into the higher level routines as much as possible and leaving behind all the little helpers which is what you see now in now patches 5 - 12.

After I got done with all the refactoring, the parts that still had the boolean were a sort of hybrid of the two paths you see now. At one point I made a judgment that continuing to factor up the boolean would be more complicated than not. I know people disliked the boolean toggle from the prior sets. So the *_later routines we have now are a result of the hybrid having been gutted of the boolean and split then off into its separate path.

Quoted 4 lines

If I'm following that correctly, I'm concerned about a couple things with the general approach. First, I think the complexity is high and maintainability is low/difficult for this kind of reentrant approach.

Quoted 7 lines

Yes. And I did very much anticipate a similar response. Thats certainly not to imply that I did all this for giggles, but because I think sometimes it's easy for designs to sound like good ideas in theory, until people see them in practice. And then the design takes a different direction. In a way I think the prototypes are a sort of necessary step for the design to evolve, even if the prototypes are sort of ugly. :-)

Yeah, tbh I suspect that anything we come up with at first is going to have an ugliness factor due to the simple fact of how the code is currently implemented. IMO, the right approach is to take the current code apart as much as possible (without too much regard for aesthetic), identify/isolate the smallest functional components required to support both direct rolling and deferred operation rolling, and then from there think about cleaning up the design for how to fit those pieces back together. We might be able to do that in one patch series, but I wouldn't be surprised (or object to) doing it in several.

Quoted 7 lines

IOW, I think it would be reasonable to split off the effort of refactoring the existing xattr code to be "deferred capable" as an independent series if you didn't want to have to continue rebasing the follow on deferred xattr bits and wanted to try and get more rapid development+review cycles of the refactoring, but that's up to you. The whole idea for the refactoring is to not change existing behavior, so I don't see why that couldn't be a mergeable component on its own.

Ok, maybe I could break up the set after patch 14, and add a wrapper loop like the one we have in the recover routine. That might be a good way to introduce some of the set in smaller pieces.

Quoted 20 lines
Quoted 5 lines
Quoted 5 lines

The state is managed/changed all throughout the call tree and so the risk and complexity of changing one particular bit in the sequence requires subtle consideration to make sure it doesn't cause problems if the function is reentered.

Quoted 8 lines

Yes, it's still very much a state machine in practice. But I think we may be stuck with at least some variant of state machine if we still want to adhere to the EAGAIN interface which requires the stack to back out. I have pondered the idea of introducing a call back to cycle out the transactions mid flight so that we dont need to stop and return. This would escape the state machine concept, but may require alternate surgery to the calling log routines too. So that may just turn into a different type of monster

To be clear, I'm pretty much expecting it to continue to be a state machine. That seems to be the most simple way to break things down, I think. I'd rather not get into things like callbacks or whatever until we've broken down the functional components and have a more clear picture of things.

Quoted 8 lines

BTW, I thought one of your previous series' had a start on this in terms of just defining some quick and dirty states based on an enum or something and sticking them in a switch statement..? The point I'm trying to make is that while those kind of simple enumerated low level states are probably not where we want to leave things at the end, it might be a reasonable approach to break the existing code into those states and then try and polish things from there. I definitely think it would be easier to review from a design perspective...

Quoted 8 lines

Sure, I can bring back the state switch if people prefer. I got the impression that people thought it was odd, so I replaced it with the XFS_DC_* flags in this one. I figured that might be a little more like what people are used to seeing. IMHO I think the state switch might have been little cleaner in that it doesn't have to re-run over the same block of code multiple times to achieve the same end goal of getting back to where it was. If people have other opinions though please feel free to chime in.

Quoted 4 lines

To me, it's not so much preference as it is just thinking that's the best approach to get the code refactored and reviewed. I agree that the state machine approach is a bit more straightforward, even if crude, due to the elimination of the repeated function calls and flags controlling

Hmm. The downside of reviewing a lot of patches is that I have a hard time remembering what I've said before. Specifically, I don't remember if I was the one who complained about that... :/

So right now, xfs_attr_set_args encodes the sequence of "ensure attr fork" -> "try to add sf attr" -> "convert to leaf" -> "try to add leaf". Maybe each of those pieces should be separate functions, and each separate function is in charge of updating the @args with whichever function comes next in the sequence. With that, xfs_attr_set_args becomes:

	while (args->nextfunc) {
		error = args->nextfunc(args);
		if (error && error != -EAGAIN)
			return error;
		xfs_trans_roll_inode(...);
	}

and then xfs_trans_attr (i.e. the deferred version) becomes:

	while (args->nextfunc) {
		args->nextfunc(args);
		/*
		 * If error == -EAGAIN, we'll end up back here with a
		 * fresh transaction.
		 */
		if (error)
			return error;
	}

Though I guess a nice property of this current version is that it does all the checks every time, which means that at least in theory you could drop the ILOCK between rolls. The only reason I mention /that/ is due to our recent discovery that while most code blocks for transaction reservation before blocking on an ILOCK, xfs_trans_roll_inode holds the ILOCK and can block waiting for more transaction reservation, which can lead to trouble.

One other thing I noticed while walking through the attr code is that xfs_da_shrink_inode calls bunmapi to remove empty blocks. I don't know if the deferred code does this, but it seems like it could be promising to use the deferred bmap unmap operation instead. Dunno.

Quoted 5 lines

random blocks of code. As noted previously, my hope is that once we break things down mechanically into the crude states that exist in the current code, we'll come up with some nice ways to continue refactoring things, reduce the number of states required and/or maybe even think of a way to eliminate the state machine entirely.

(Hopefully the above was what Brian was getting at?)

--D

Quoted 677 lines

It's definitely worth soliciting other opinions, though, before significantly refactoring things one way or the other..

Quoted 87 lines
Quoted 23 lines
Quoted 8 lines

For example, I'd prefer to see something like

Quoted 6 lines

xfs_trans_attr() broken down into smaller granularity functions with higher level state that is managed and readable in one place, if possible. Perhaps we could do that based on attr fork format, but I need to stare at the code and think about this some more (it might be that some degree of reentrancy is inevitable, or we just need to break things down to even smaller states...).

Quoted 6 lines

Yes, and I did go through a phase of trying to simplify the statemachine by trying to grab onto anything about the state of the fork that could be used instead. But its not always enough particularly in the case of routines that are in the middle of allocating or removing blocks. If you see any other mechanics that could help out, please call them out.

One of the things I'm wondering is if we'll be able to reduce the number of unique (sub-)states required by reordering some of the existing logic between the higher level states. For a quick example, the current series uses the XFS_DC_ALLOC_LEAF state for a one-time operation that's part of a state that can be reentered over and over. This raises the question to me of whether that _ALLOC_LEAF thing could eventually just be folded into the tail of the previous state.

Quoted 3 lines

To reiterate, for now I think it would be perfectly reasonable to make _ALLOC_LEAF its own independent state so the flag management isn't buried so deep in the xattr code...

Yes, it is one of the examples where trying to use the fork to control the state does not work out so well because we're in the middle of altering things. So in those cases, using the state machine to give it its own state starts to make more sense.

Quoted 55 lines
Quoted 11 lines
Quoted 11 lines

Second, it seems like a lot of this code duplication between deferred and non-deferred operations should be unnecessary, particularly since the only difference between the contexts is how transactions are managed. For example, if you follow the xattr set code path in both contexts, we can see that functions like xfs_attr_set_args() are basically duplicated in the xfs_attr_set_later() deferred variant just so we can change the xfs_defer_finish() call in the former to a return -EAGAIN in the latter.

Quoted 6 lines

Yes, they still carry some similarities. I guess I reasoned that continuing to carve things up into smaller and smaller helpers with out a generalized purpose (other than de-dup reduction) was starting to look a little weird, and maybe leaving things in their appropriate context might have been preferred? Folks are welcome to chime in with opinions though.

As mentioned above, I think weird is to be expected, at least if we break things down into an intermediary state. That's just my .02 though. Maybe others have different ideas..

Quoted 32 lines
Quoted 8 lines

Instead, what I think we should strive for is a common xattr mechanism that consists of the lowest common denominator between the two contexts (or IOW, core infrastructure that can be invoked from either context). For example, on a kernel without deferred xattr support, could we find a way to call the deferred variants directly and just let the context-specific caller do the transaction rolls on -EAGAIN instead of relying on the dfops infrastructure?

I think I did that somewhere in the older parent pointer sets. At the time, we sort of forgot that we cant completely scrap non delayed attrs (because we need them for older versions). But then protofiles needed to create pptrs with out the delay mechanic, so I opened coded a sort of loop to deal with the EAGAIN. In fact, I ended up doing the same sort of loop in patch 15 for xfs_attri_recover, which has the same challenge. Maybe we could make a sort of general purpose wrapper?

ISTM that should be possible, it

Quoted 11 lines

just requires further breaking down the existing/non-deferred mechanism into smaller bits that uses the new state management logic and implements -EAGAIN handling for when the lower level code requires a transaction roll. At that point, deferred support should basically just consist of the dfops and log (i.e. intents) code to plug into the associated infrastructure. I think another side effect of that approach is that we shouldn't need these patches that add a bunch of new xattr infrastructure code, but rather we'd just continue refactoring the existing code and eventually implement a new high level function that returns -EAGAIN directly to the dfops code instead of rolling transactions explicitly. Thoughts?

Ok, I think I understand what you're trying to describe here. Maybe take a look at xfs_attri_recover in patch 15, and let me know if that was similar to what you were thinking?

Quoted 9 lines
Quoted 6 lines

Yep, pretty much. Outside of the whole xfs_trans_attr() thing, I'd expect the direct xattr path to have to do something very similar in terms of invoking the xattr state machine and handling transaction rolls where the dfops mechanism isn't there to do it for us.

Brian

Sure, that shouldn't be to hard to make a high level wrapper like that. Then we can let go of the old code path.

I view it as more like reorganizing and reusing the old code path. ;)

Brian

Quoted 573 lines

Thanks again for the all the reviewing! :-)

Allison

Quoted 569 lines
Quoted 569 lines

Thank you for all the thorough reviewing here, I know it's a lot! Allison

Quoted 565 lines

Brian

Quoted 562 lines
fs/xfs/libxfs/xfs_attr.c +522 -0
+
+	/*
+	 * After a shortform to leaf conversion, we need to hold the leaf and
+	 * cylce out the transaction.  When we get back, we need to release
+	 * the leaf.
+	 */
+	if (*leaf_bp != NULL) {
+		xfs_trans_brelse(args->trans, *leaf_bp);
+		*leaf_bp = NULL;
+	}
+
+	/*
+	 * If we fit in a block, or we are in the middle of adding a leaf name.
+	 * xfs_attr_da_leaf_addname will set the XFS_DC_ALLOC_LEAF to indicate
+	 * that it is not done yet, and need to be recalled to finish up from
+	 * the last EAGAIN it returned
+	 */
+	if (xfs_bmap_one_block(dp, XFS_ATTR_FORK) ||
+	    args->dc.flags & XFS_DC_ALLOC_LEAF) {
+		if (!(args->dc.flags & XFS_DC_FOUND_LBLK)) {
+			error = xfs_attr_leaf_try_add(args, *leaf_bp);
+			args->dc.flags |= XFS_DC_FOUND_LBLK;
+
+			if (error && error != -ENOSPC)
+				return error;
+
+			return -EAGAIN;
+		}
+
+		error = xfs_leaf_addname_later(args);
+		if (error && error != -ENOSPC)
+			return error;
+	} else {
+		error = xfs_node_addname_later(args);
+	}
+
+	return error;
+}
+
+
+
+/*
    * Return EEXIST if attr is found, or ENOATTR if not
    */
   int
@@ -362,6 +471,57 @@ xfs_attr_remove_args(
   	return error;
   }
+/*
+ * Remove the attribute specified in @args.
+ * This routine is meant to function as a delayed operation, and may return
+ * -EGAIN when the transaction needs to be rolled.  Calling functions will need
+ * to handle this, and recall the function until a successful error code is
+ * returned.
+ */
+int
+xfs_attr_remove_later(
+	struct xfs_da_args      *args)
+{
+	struct xfs_inode	*dp = args->dp;
+	struct xfs_buf		*bp;
+	int			forkoff, error = 0;
+
+	if (!xfs_inode_hasattr(dp)) {
+		error = -ENOATTR;
+	} else if (dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) {
+		ASSERT(dp->i_afp->if_flags & XFS_IFINLINE);
+		error = xfs_attr_shortform_remove(args);
+	} else if (xfs_bmap_one_block(dp, XFS_ATTR_FORK) &&
+		   !(args->dc.flags & XFS_DC_RM_NODE_BLKS)) {
+		/*
+		 * If we fit in a block AND we are not in the middle of
+		 * removing node blocks, remove the leaf attribute.
+		 * xfs_attr_da_node_removename will set XFS_DC_RM_NODE_BLKS to
+		 * signal that it is not done yet, and needs to be recalled to
+		 * to finish up from the last -EAGAIN
+		 */
+		error = xfs_leaf_has_attr(args, &bp);
+		if (error == -ENOATTR) {
+			xfs_trans_brelse(args->trans, bp);
+			return error;
+		}
+		error = 0;
+
+		xfs_attr3_leaf_remove(bp, args);
+
+		/* If the result is small enough, shrink it into the inode.*/
+		forkoff = xfs_attr_shortform_allfit(bp, dp);
+		if (forkoff)
+			error = xfs_attr3_leaf_to_shortform(bp, args, forkoff);
+	} else {
+		error = xfs_node_removename_later(args);
+	}
+
+	return error;
+}
+
+
+
   int
   xfs_attr_set(
   	struct xfs_inode	*dp,
@@ -794,6 +954,87 @@ xfs_attr_leaf_addname(struct xfs_da_args	*args)
   }
   /*
+ * Add a name to the leaf attribute list structure
+ *
+ * This leaf block cannot have a "remote" value, we only call this routine
+ * if bmap_one_block() says there is only one block (ie: no remote blks).
+ *
+ * This routine is meant to function as a delayed operation, and may return
+ * -EGAIN when the transaction needs to be rolled.  Calling functions will need
+ * to handle this, and recall the function until a successful error code is
+ * returned.
+ */
+STATIC int
+xfs_leaf_addname_later(
+	struct xfs_da_args	*args)
+{
+	int			error, nmap;
+	struct xfs_inode	*dp = args->dp;
+	struct xfs_bmbt_irec	*map = &args->dc.map;
+
+	/*
+	 * If there was an out-of-line value, allocate the blocks we
+	 * identified for its storage and copy the value.  This is done
+	 * after we create the attribute so that we don't overflow the
+	 * maximum size of a transaction and/or hit a deadlock.
+	 */
+	if (args->rmtblkno > 0) {
+		if (!(args->dc.flags & XFS_DC_ALLOC_LEAF)) {
+			args->dc.lfileoff = 0;
+			args->dc.lblkno = 0;
+			args->dc.blkcnt = 0;
+			args->rmtblkcnt = 0;
+			args->rmtblkno = 0;
+			memset(map, 0, sizeof(struct xfs_bmbt_irec));
+
+			error = xfs_attr_rmt_find_hole(args);
+			if (error)
+				return error;
+
+			args->dc.blkcnt = args->rmtblkcnt;
+			args->dc.lblkno = args->rmtblkno;
+			args->dc.flags |= XFS_DC_ALLOC_LEAF;
+		}
+
+		/*
+		 * Roll through the "value", allocating blocks on disk as
+		 * required.
+		 */
+		while (args->dc.blkcnt > 0) {
+			nmap = 1;
+			error = xfs_bmapi_write(args->trans, dp,
+				  (xfs_fileoff_t)args->dc.lblkno,
+				  args->dc.blkcnt, XFS_BMAPI_ATTRFORK,
+				  args->total, map, &nmap);
+			if (error)
+				return error;
+			ASSERT(nmap == 1);
+			ASSERT((map->br_startblock != DELAYSTARTBLOCK) &&
+			       (map->br_startblock != HOLESTARTBLOCK));
+
+			/* roll attribute extent map forwards */
+			args->dc.lblkno += map->br_blockcount;
+			args->dc.blkcnt -= map->br_blockcount;
+
+			return -EAGAIN;
+		}
+
+		error = xfs_attr_rmtval_set_value(args);
+		if (error)
+			return error;
+	}
+
+	if (args->rmtblkno > 0) {
+		/*
+		 * Added a "remote" value, just clear the incomplete flag.
+		 */
+		error = xfs_attr3_leaf_clearflag(args);
+	}
+	args->dc.flags &= ~XFS_DC_ALLOC_LEAF;
+	return error;
+}
+
+/*
    * Return EEXIST if attr is found, or ENOATTR if not
    */
   STATIC int
@@ -1291,6 +1532,354 @@ xfs_attr_node_removename(
   }
   /*
+ * Remove a name from a B-tree attribute list.
+ *
+ * This will involve walking down the Btree, and may involve joining
+ * leaf nodes and even joining intermediate nodes up to and including
+ * the root node (a special case of an intermediate node).
+ *
+ * This routine is meant to function as a delayed operation, and may return
+ * -EGAIN when the transaction needs to be rolled.  Calling functions
+ * will need to handle this, and recall the function until a successful error
+ * code is returned.
+ */
+STATIC int
+xfs_node_removename_later(
+	struct xfs_da_args	*args)
+{
+	struct xfs_da_state	*state = NULL;
+	struct xfs_da_state_blk	*blk;
+	struct xfs_buf		*bp;
+	int			error, forkoff, retval = 0;
+	struct xfs_inode	*dp = args->dp;
+	int			done = 0;
+
+	trace_xfs_attr_node_removename(args);
+
+	if (args->dc.state == NULL) {
+		error = xfs_attr_node_hasname(args, &args->dc.state);
+		if (error != -EEXIST)
+			goto out;
+		else
+			error = 0;
+
+		/*
+		 * If there is an out-of-line value, de-allocate the blocks.
+		 * This is done before we remove the attribute so that we don't
+		 * overflow the maximum size of a transaction and/or hit a
+		 * deadlock.
+		 */
+		state = args->dc.state;
+		args->dc.blk = &state->path.blk[state->path.active - 1];
+		ASSERT(args->dc.blk->bp != NULL);
+		ASSERT(args->dc.blk->magic == XFS_ATTR_LEAF_MAGIC);
+	}
+	state = args->dc.state;
+	blk = args->dc.blk;
+
+	if (args->rmtblkno > 0 && !(args->dc.flags & XFS_DC_RM_LEAF_BLKS)) {
+		bool isset;
+
+		error = xfs_attr3_leaf_flag_is_set(args, &isset);
+		if (error)
+			goto out;
+		if (!isset) {
+			/*
+			 * Fill in disk block numbers in the state structure
+			 * so that we can get the buffers back after we commit
+			 * several transactions in the following calls.
+			 */
+			error = xfs_attr_fillstate(state);
+			if (error)
+				goto out;
+
+			/*
+			 * Mark the attribute as INCOMPLETE, then bunmapi() the
+			 * remote value.
+			 */
+			error = xfs_attr3_leaf_setflag(args);
+			if (error)
+				goto out;
+
+			return -EAGAIN;
+		}
+
+		if (!(args->dc.flags & XFS_DC_RM_NODE_BLKS)) {
+			args->dc.flags |= XFS_DC_RM_NODE_BLKS;
+			error = xfs_attr_rmtval_invalidate(args);
+			if (error)
+				goto out;
+		}
+
+		/*
+		 * Unmap value blocks for this attr.  This is similar to
+		 * xfs_attr_rmtval_remove, but open coded here to return EAGAIN
+		 * for new transactions
+		 */
+		while (!done && !error) {
+			error = xfs_bunmapi(args->trans, args->dp,
+				    args->rmtblkno, args->rmtblkcnt,
+				    XFS_BMAPI_ATTRFORK, 1, &done);
+			if (error)
+				return error;
+
+			if (!done)
+				return -EAGAIN;
+		}
+
+		if (error)
+			goto out;
+
+		/*
+		 * Refill the state structure with buffers, the prior calls
+		 * released our buffers.
+		 */
+		error = xfs_attr_refillstate(state);
+		if (error)
+			goto out;
+	}
+
+	/*
+	 * Remove the name and update the hashvals in the tree.
+	 */
+	if (!(args->dc.flags & XFS_DC_RM_LEAF_BLKS)) {
+		blk = &state->path.blk[state->path.active - 1];
+		ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
+		retval = xfs_attr3_leaf_remove(blk->bp, args);
+		xfs_da3_fixhashpath(state, &state->path);
+
+		args->dc.flags |= XFS_DC_RM_LEAF_BLKS;
+	}
+
+	/*
+	 * Check to see if the tree needs to be collapsed.
+	 */
+	if (retval && (state->path.active > 1)) {
+		args->dc.flags |= XFS_DC_RM_NODE_BLKS;
+		error = xfs_da3_join(state);
+		if (error)
+			goto out;
+
+		return -EAGAIN;
+	}
+
+	/*
+	 * If the result is small enough, push it all into the inode.
+	 */
+	if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
+		/*
+		 * Have to get rid of the copy of this dabuf in the state.
+		 */
+		ASSERT(state->path.active == 1);
+		ASSERT(state->path.blk[0].bp);
+		state->path.blk[0].bp = NULL;
+
+		error = xfs_attr3_leaf_read(args->trans, args->dp, 0, -1, &bp);
+		if (error)
+			goto out;
+
+		forkoff = xfs_attr_shortform_allfit(bp, dp);
+		if (forkoff) {
+			error = xfs_attr3_leaf_to_shortform(bp, args, forkoff);
+			/* bp is gone due to xfs_da_shrink_inode */
+			if (error)
+				goto out;
+		} else
+			xfs_trans_brelse(args->trans, bp);
+	}
+out:
+	if (state != NULL)
+		xfs_da_state_free(state);
+
+	return error;
+}
+
+/*
+ * Add a name to a Btree-format attribute list.
+ *
+ * This will involve walking down the Btree, and may involve splitting
+ * leaf nodes and even splitting intermediate nodes up to and including
+ * the root node (a special case of an intermediate node).
+ *
+ * "Remote" attribute values confuse the issue and atomic rename operations
+ * add a whole extra layer of confusion on top of that.
+ *
+ * This routine is meant to function as a delayed operation, and may return
+ * -EGAIN when the transaction needs to be rolled.  Calling functions will need
+ * to handle this, and recall the function until a successful error code is
+ *returned.
+ */
+STATIC int
+xfs_node_addname_later(
+	struct xfs_da_args	*args)
+{
+	struct xfs_da_state	*state = NULL;
+	struct xfs_da_state_blk	*blk;
+	struct xfs_inode	*dp;
+	int			retval, error = 0;
+	int			nmap;
+	struct xfs_bmbt_irec    *map = &args->dc.map;
+
+	trace_xfs_attr_node_addname(args);
+
+	/*
+	 * Fill in bucket of arguments/results/context to carry around.
+	 */
+	dp = args->dp;
+
+	if (args->dc.flags & XFS_DC_FOUND_NBLK)
+		goto found_blk;
+
+	/*
+	 * Search to see if name already exists, and get back a pointer
+	 * to where it should go.
+	 */
+	retval = xfs_attr_node_hasname(args, &state);
+	blk = &state->path.blk[state->path.active-1];
+	ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
+	if ((args->name.type & ATTR_REPLACE) && (retval == -ENOATTR)) {
+		goto out;
+	} else if (retval == -EEXIST) {
+		if (args->name.type & ATTR_CREATE)
+			goto out;
+
+		trace_xfs_attr_node_replace(args);
+
+		/* save the attribute state for later removal*/
+		args->op_flags |= XFS_DA_OP_RENAME;	/* atomic rename op */
+		args->blkno2 = args->blkno;		/* set 2nd entry info*/
+		args->index2 = args->index;
+		args->rmtblkno2 = args->rmtblkno;
+		args->rmtblkcnt2 = args->rmtblkcnt;
+		args->rmtvaluelen2 = args->rmtvaluelen;
+
+		/*
+		 * clear the remote attr state now that it is saved so that the
+		 * values reflect the state of the attribute we are about to
+		 * add, not the attribute we just found and will remove later.
+		 */
+		args->rmtblkno = 0;
+		args->rmtblkcnt = 0;
+		args->rmtvaluelen = 0;
+	}
+
+	retval = xfs_attr3_leaf_add(blk->bp, state->args);
+	if (retval == -ENOSPC) {
+		if (state->path.active == 1) {
+			/*
+			 * Its really a single leaf node, but it had
+			 * out-of-line values so it looked like it *might*
+			 * have been a b-tree.
+			 */
+			xfs_da_state_free(state);
+			state = NULL;
+			error = xfs_attr3_leaf_to_node(args);
+			if (error)
+				goto out;
+
+			return -EAGAIN;
+		}
+
+		/*
+		 * Split as many Btree elements as required.
+		 * This code tracks the new and old attr's location
+		 * in the index/blkno/rmtblkno/rmtblkcnt fields and
+		 * in the index2/blkno2/rmtblkno2/rmtblkcnt2 fields.
+		 */
+		error = xfs_da3_split(state);
+		if (error)
+			goto out;
+	} else {
+		/*
+		 * Addition succeeded, update Btree hashvals.
+		 */
+		xfs_da3_fixhashpath(state, &state->path);
+	}
+
+	/*
+	 * Kill the state structure, we're done with it and need to
+	 * allow the buffers to come back later.
+	 */
+	xfs_da_state_free(state);
+	state = NULL;
+
+	args->dc.flags |= XFS_DC_FOUND_NBLK;
+	return -EAGAIN;
+found_blk:
+
+	/*
+	 * If there was an out-of-line value, allocate the blocks we
+	 * identified for its storage and copy the value.  This is done
+	 * after we create the attribute so that we don't overflow the
+	 * maximum size of a transaction and/or hit a deadlock.
+	 */
+	if (args->rmtblkno > 0) {
+		if (!(args->dc.flags & XFS_DC_ALLOC_NODE)) {
+			args->dc.flags |= XFS_DC_ALLOC_NODE;
+			args->dc.lblkno = 0;
+			args->dc.lfileoff = 0;
+			args->dc.blkcnt = 0;
+			args->rmtblkcnt = 0;
+			args->rmtblkno = 0;
+			memset(map, 0, sizeof(struct xfs_bmbt_irec));
+
+			error = xfs_attr_rmt_find_hole(args);
+			if (error)
+				return error;
+
+			args->dc.blkcnt = args->rmtblkcnt;
+			args->dc.lblkno = args->rmtblkno;
+		}
+		/*
+		 * Roll through the "value", allocating blocks on disk as
+		 * required.
+		 */
+		while (args->dc.blkcnt > 0) {
+			nmap = 1;
+			error = xfs_bmapi_write(args->trans, dp,
+				(xfs_fileoff_t)args->dc.lblkno, args->dc.blkcnt,
+				XFS_BMAPI_ATTRFORK, args->total, map, &nmap);
+			if (error)
+				return error;
+
+			ASSERT(nmap == 1);
+			ASSERT((map->br_startblock != DELAYSTARTBLOCK) &&
+			       (map->br_startblock != HOLESTARTBLOCK));
+
+			/* roll attribute extent map forwards */
+			args->dc.lblkno += map->br_blockcount;
+			args->dc.blkcnt -= map->br_blockcount;
+
+			return -EAGAIN;
+		}
+
+		error = xfs_attr_rmtval_set_value(args);
+		if (error)
+			return error;
+	}
+
+	if (args->rmtblkno > 0) {
+		/*
+		 * Added a "remote" value, just clear the incomplete flag.
+		 */
+		error = xfs_attr3_leaf_clearflag(args);
+		if (error)
+			goto out;
+	}
+	retval = error = 0;
+
+out:
+	if (state)
+		xfs_da_state_free(state);
+	if (error)
+		return error;
+
+	return retval;
+}
+
+
+
+/*
    * Fill in the disk block numbers in the state structure for the buffers
    * that are attached to the state structure.
    * This is done so that we can quickly reattach ourselves to those buffers
fs/xfs/libxfs/xfs_attr.h +2 -0
index fb56d81..6203766 100644
@@ -149,9 +149,11 @@ int xfs_attr_get(struct xfs_inode *ip, struct xfs_name *name,
   int xfs_attr_set(struct xfs_inode *dp, struct xfs_name *name,
   		 unsigned char *value, int valuelen);
   int xfs_attr_set_args(struct xfs_da_args *args);
+int xfs_attr_set_later(struct xfs_da_args *args, struct xfs_buf **leaf_bp);
   int xfs_attr_remove(struct xfs_inode *dp, struct xfs_name *name);
   int xfs_has_attr(struct xfs_da_args *args);
   int xfs_attr_remove_args(struct xfs_da_args *args);
+int xfs_attr_remove_later(struct xfs_da_args *args);
   int xfs_attr_list(struct xfs_inode *dp, char *buffer, int bufsize,
   		  int flags, struct attrlist_cursor_kern *cursor);
   bool xfs_attr_namecheck(const void *name, size_t length);
Signature · 1 line
2.7.4
#51 lore raw

Re: [PATCH v3 14/19] xfs: Add delayed attribute routines

Quoted 198 lines · Darrick J. Wong
Quoted 197 lines · Brian Foster
Quoted 195 lines · Allison Collins
Quoted 145 lines · Brian Foster
Quoted 126 lines · Allison Collins
Quoted 93 lines · Brian Foster
Quoted 25 lines · Allison Collins

This patch adds new delayed attribute routines:

xfs_attr_set_later
xfs_attr_remove_later
xfs_leaf_addname_later
xfs_node_addname_later
xfs_node_removename_later

These routines are similar to their existing counter parts, but they do not roll or commit transactions. They instead return -EAGAIN to allow the calling function to roll the transaction and recall the function. This allows the attribute operations to be logged in multiple smaller transactions.

---
   fs/xfs/libxfs/xfs_attr.c | 591 ++++++++++++++++++++++++++++++++++++++++++++++-
   fs/xfs/libxfs/xfs_attr.h |   2 +
   2 files changed, 592 insertions(+), 1 deletion(-)
fs/xfs/libxfs/xfs_attr.c +0 -0
index 781dd8a..310f5b2 100644

...

Quoted 66 lines
fs/xfs/libxfs/xfs_attr.c +63 -0
@@ -313,6 +316,112 @@ xfs_attr_set_args(
   }
   /*
+ * Set the attribute specified in @args.
+ * This routine is meant to function as a delayed operation, and may return
+ * -EGAIN when the transaction needs to be rolled.  Calling functions will need
+ * to handle this, and recall the function until a successful error code is
+ * returned.
+ */
+int
+xfs_attr_set_later(
+	struct xfs_da_args	*args,
+	struct xfs_buf          **leaf_bp)
+{
+	struct xfs_inode	*dp = args->dp;
+	int			error = 0;
+	int			sf_size;
+
+	/*
+	 * New inodes may not have an attribute fork yet. So set the attribute
+	 * fork appropriately
+	 */
+	if (XFS_IFORK_Q((args->dp)) == 0) {
+		sf_size = sizeof(struct xfs_attr_sf_hdr) +
+		     XFS_ATTR_SF_ENTSIZE_BYNAME(args->name.len, args->valuelen);
+		xfs_bmap_set_attrforkoff(args->dp, sf_size, NULL);
+		args->dp->i_afp = kmem_zone_zalloc(xfs_ifork_zone, 0);
+		args->dp->i_afp->if_flags = XFS_IFEXTENTS;
+	}
+
+	/*
+	 * If the attribute list is non-existent or a shortform list,
+	 * upgrade it to a single-leaf-block attribute list.
+	 */
+	if (dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL ||
+	    (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS &&
+	     dp->i_d.di_anextents == 0)) {
+		/*
+		 * Build initial attribute list (if required).
+		 */
+		if (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS)
+			xfs_attr_shortform_create(args);
+
+		/*
+		 * Try to add the attr to the attribute list in the inode.
+		 */
+		error = xfs_attr_try_sf_addname(dp, args);
+		if (error != -ENOSPC)
+			return error;
+
+		/*
+		 * It won't fit in the shortform, transform to a leaf block.
+		 * GROT: another possible req'mt for a double-split btree op.
+		 */
+		error = xfs_attr_shortform_to_leaf(args, leaf_bp);
+		if (error)
+			return error;
+
+		/*
+		 * Prevent the leaf buffer from being unlocked so that a
+		 * concurrent AIL push cannot grab the half-baked leaf
+		 * buffer and run into problems with the write verifier.
+		 */
+
+		xfs_trans_bhold(args->trans, *leaf_bp);
+		return -EAGAIN;
Quoted 8 lines

fs/xfs/libxfs/xfs_attr.c xfs_attr_set_args( · line 381

Quoted 1 line
fs/xfs/libxfs/xfs_attr.c +1 -0
+	}

I haven't actually reviewed the code in this patch yet, but rather I skipped ahead to try and get an understanding of the design approach and flow of a deferred xattr operation. IIUC, we basically duplicate a bunch of xattr code into these dfops oriented functions but instead of rolling transactions, return -EAGAIN and use the XFS_DC_ state flags to manage reentrancy into the xfs_trans_attr() function.

Yes. If it helps to know a little more background about how it came into being...
Initially I had started out with the code paths merged, and had a boolean switch to control the alternate behavior (much like the "roll_trans" boolean from the prior sets, if you recall them). In a way, the boolean acted like a sort of marker of where things needed to get factored up. The goal being to pull the boolean into the higher level routines as much as possible and leaving behind all the little helpers which is what you see now in now patches 5 - 12.

After I got done with all the refactoring, the parts that still had the boolean were a sort of hybrid of the two paths you see now. At one point I made a judgment that continuing to factor up the boolean would be more complicated than not. I know people disliked the boolean toggle from the prior sets. So the *_later routines we have now are a result of the hybrid having been gutted of the boolean and split then off into its separate path.

Quoted 4 lines

If I'm following that correctly, I'm concerned about a couple things with the general approach. First, I think the complexity is high and maintainability is low/difficult for this kind of reentrant approach.

Quoted 7 lines

Yes. And I did very much anticipate a similar response. Thats certainly not to imply that I did all this for giggles, but because I think sometimes it's easy for designs to sound like good ideas in theory, until people see them in practice. And then the design takes a different direction. In a way I think the prototypes are a sort of necessary step for the design to evolve, even if the prototypes are sort of ugly. :-)

Yeah, tbh I suspect that anything we come up with at first is going to have an ugliness factor due to the simple fact of how the code is currently implemented. IMO, the right approach is to take the current code apart as much as possible (without too much regard for aesthetic), identify/isolate the smallest functional components required to support both direct rolling and deferred operation rolling, and then from there think about cleaning up the design for how to fit those pieces back together. We might be able to do that in one patch series, but I wouldn't be surprised (or object to) doing it in several.

Quoted 7 lines

IOW, I think it would be reasonable to split off the effort of refactoring the existing xattr code to be "deferred capable" as an independent series if you didn't want to have to continue rebasing the follow on deferred xattr bits and wanted to try and get more rapid development+review cycles of the refactoring, but that's up to you. The whole idea for the refactoring is to not change existing behavior, so I don't see why that couldn't be a mergeable component on its own.

Ok, maybe I could break up the set after patch 14, and add a wrapper loop like the one we have in the recover routine. That might be a good way to introduce some of the set in smaller pieces.

Quoted 20 lines
Quoted 5 lines
Quoted 5 lines

The state is managed/changed all throughout the call tree and so the risk and complexity of changing one particular bit in the sequence requires subtle consideration to make sure it doesn't cause problems if the function is reentered.

Quoted 8 lines

Yes, it's still very much a state machine in practice. But I think we may be stuck with at least some variant of state machine if we still want to adhere to the EAGAIN interface which requires the stack to back out. I have pondered the idea of introducing a call back to cycle out the transactions mid flight so that we dont need to stop and return. This would escape the state machine concept, but may require alternate surgery to the calling log routines too. So that may just turn into a different type of monster

To be clear, I'm pretty much expecting it to continue to be a state machine. That seems to be the most simple way to break things down, I think. I'd rather not get into things like callbacks or whatever until we've broken down the functional components and have a more clear picture of things.

Quoted 8 lines

BTW, I thought one of your previous series' had a start on this in terms of just defining some quick and dirty states based on an enum or something and sticking them in a switch statement..? The point I'm trying to make is that while those kind of simple enumerated low level states are probably not where we want to leave things at the end, it might be a reasonable approach to break the existing code into those states and then try and polish things from there. I definitely think it would be easier to review from a design perspective...

Sure, I can bring back the state switch if people prefer. I got the impression that people thought it was odd, so I replaced it with the XFS_DC_* flags in this one. I figured that might be a little more like what people are used to seeing. IMHO I think the state switch might have been little cleaner in that it doesn't have to re-run over the same block of code multiple times to achieve the same end goal of getting back to where it was. If people have other opinions though please feel free to chime in.

Quoted 9 lines
Quoted 4 lines

To me, it's not so much preference as it is just thinking that's the best approach to get the code refactored and reviewed. I agree that the state machine approach is a bit more straightforward, even if crude, due to the elimination of the repeated function calls and flags controlling

Hmm. The downside of reviewing a lot of patches is that I have a hard time remembering what I've said before. Specifically, I don't remember if I was the one who complained about that... :/

Heh. I don't recall complaining about it, but I've agreed that it looks funny so who knows. In any event, it's probably best that we agree on an approach from here so we all know what to expect and don't waste development and review time...

Quoted 16 lines

So right now, xfs_attr_set_args encodes the sequence of "ensure attr fork" -> "try to add sf attr" -> "convert to leaf" -> "try to add leaf". Maybe each of those pieces should be separate functions, and each separate function is in charge of updating the @args with whichever function comes next in the sequence. With that, xfs_attr_set_args becomes:

	while (args->nextfunc) {
		error = args->nextfunc(args);
		if (error && error != -EAGAIN)
			return error;
		xfs_trans_roll_inode(...);
	}

and then xfs_trans_attr (i.e. the deferred version) becomes:

Quoted 10 lines
	while (args->nextfunc) {
		args->nextfunc(args);
		/*
		 * If error == -EAGAIN, we'll end up back here with a
		 * fresh transaction.
		 */
		if (error)
			return error;
	}

This seems like a potential final option to me, but I still think breaking things down into the most basic states (as one of the previous versions sort of did with a switch statement) is the most straightforward approach because it facilitates pure refactoring. Note that I'm definitely not trying to make the argument that we refactor everything as such and then be done with it, but rather that we evaluate next direction from that point.

Next direction includes consideration of things like whether the intermediate state is aesthetically reasonable enough to be mergeable (so we can make some development progress and stop holding up some of these earlier patches), whether we can combine/reorder code to reduce states, and if/how to actually redesign the broader mechanism to facilitate deferred operations and potentially deal with some of the things you call out below (transaction reservation/rolling and locking, etc). I find the current approach of trying to solve all of this at once unwieldy simply due to the big clump of code that the xattr mechanism happens to be. We know we have to factor out the transaction processing for deferred operations and take this thing apart, so why not just get that part done?

Quoted 8 lines

Though I guess a nice property of this current version is that it does all the checks every time, which means that at least in theory you could drop the ILOCK between rolls. The only reason I mention /that/ is due to our recent discovery that while most code blocks for transaction reservation before blocking on an ILOCK, xfs_trans_roll_inode holds the ILOCK and can block waiting for more transaction reservation, which can lead to trouble.

Indeed, though this is a problem with the current code too, right?

Quoted 5 lines

One other thing I noticed while walking through the attr code is that xfs_da_shrink_inode calls bunmapi to remove empty blocks. I don't know if the deferred code does this, but it seems like it could be promising to use the deferred bmap unmap operation instead. Dunno.

Another potential cleanup to consider. ;)

Quoted 8 lines
Quoted 5 lines

random blocks of code. As noted previously, my hope is that once we break things down mechanically into the crude states that exist in the current code, we'll come up with some nice ways to continue refactoring things, reduce the number of states required and/or maybe even think of a way to eliminate the state machine entirely.

(Hopefully the above was what Brian was getting at?)

It's definitely along the lines of what I was hoping for as a final result. I'm just arguing for a more deliberate approach to get to that point:

1.) Refactor existing code to lift out transaction processing using as simple and unclever programming constructs as possible (i.e., switch statements) and no functional changes.
2.) Simplify/refine what falls out from that as appropriate. 3.) Rework into a legitimate design (perhaps like what you propose above with function pointers).
4.) Plumb in deferred/intent item infrastructure such that the same xattr mechanism is used for direct and deferred xattrs.
5.) Profit.

Thoughts?

Brian

Quoted 679 lines

--D

Quoted 677 lines

It's definitely worth soliciting other opinions, though, before significantly refactoring things one way or the other..

Quoted 87 lines
Quoted 23 lines
Quoted 8 lines

For example, I'd prefer to see something like

Quoted 6 lines

xfs_trans_attr() broken down into smaller granularity functions with higher level state that is managed and readable in one place, if possible. Perhaps we could do that based on attr fork format, but I need to stare at the code and think about this some more (it might be that some degree of reentrancy is inevitable, or we just need to break things down to even smaller states...).

Quoted 6 lines

Yes, and I did go through a phase of trying to simplify the statemachine by trying to grab onto anything about the state of the fork that could be used instead. But its not always enough particularly in the case of routines that are in the middle of allocating or removing blocks. If you see any other mechanics that could help out, please call them out.

One of the things I'm wondering is if we'll be able to reduce the number of unique (sub-)states required by reordering some of the existing logic between the higher level states. For a quick example, the current series uses the XFS_DC_ALLOC_LEAF state for a one-time operation that's part of a state that can be reentered over and over. This raises the question to me of whether that _ALLOC_LEAF thing could eventually just be folded into the tail of the previous state.

Quoted 3 lines

To reiterate, for now I think it would be perfectly reasonable to make _ALLOC_LEAF its own independent state so the flag management isn't buried so deep in the xattr code...

Yes, it is one of the examples where trying to use the fork to control the state does not work out so well because we're in the middle of altering things. So in those cases, using the state machine to give it its own state starts to make more sense.

Quoted 55 lines
Quoted 11 lines
Quoted 11 lines

Second, it seems like a lot of this code duplication between deferred and non-deferred operations should be unnecessary, particularly since the only difference between the contexts is how transactions are managed. For example, if you follow the xattr set code path in both contexts, we can see that functions like xfs_attr_set_args() are basically duplicated in the xfs_attr_set_later() deferred variant just so we can change the xfs_defer_finish() call in the former to a return -EAGAIN in the latter.

Quoted 6 lines

Yes, they still carry some similarities. I guess I reasoned that continuing to carve things up into smaller and smaller helpers with out a generalized purpose (other than de-dup reduction) was starting to look a little weird, and maybe leaving things in their appropriate context might have been preferred? Folks are welcome to chime in with opinions though.

As mentioned above, I think weird is to be expected, at least if we break things down into an intermediary state. That's just my .02 though. Maybe others have different ideas..

Quoted 32 lines
Quoted 8 lines

Instead, what I think we should strive for is a common xattr mechanism that consists of the lowest common denominator between the two contexts (or IOW, core infrastructure that can be invoked from either context). For example, on a kernel without deferred xattr support, could we find a way to call the deferred variants directly and just let the context-specific caller do the transaction rolls on -EAGAIN instead of relying on the dfops infrastructure?

I think I did that somewhere in the older parent pointer sets. At the time, we sort of forgot that we cant completely scrap non delayed attrs (because we need them for older versions). But then protofiles needed to create pptrs with out the delay mechanic, so I opened coded a sort of loop to deal with the EAGAIN. In fact, I ended up doing the same sort of loop in patch 15 for xfs_attri_recover, which has the same challenge. Maybe we could make a sort of general purpose wrapper?

ISTM that should be possible, it

Quoted 11 lines

just requires further breaking down the existing/non-deferred mechanism into smaller bits that uses the new state management logic and implements -EAGAIN handling for when the lower level code requires a transaction roll. At that point, deferred support should basically just consist of the dfops and log (i.e. intents) code to plug into the associated infrastructure. I think another side effect of that approach is that we shouldn't need these patches that add a bunch of new xattr infrastructure code, but rather we'd just continue refactoring the existing code and eventually implement a new high level function that returns -EAGAIN directly to the dfops code instead of rolling transactions explicitly. Thoughts?

Ok, I think I understand what you're trying to describe here. Maybe take a look at xfs_attri_recover in patch 15, and let me know if that was similar to what you were thinking?

Quoted 9 lines
Quoted 6 lines

Yep, pretty much. Outside of the whole xfs_trans_attr() thing, I'd expect the direct xattr path to have to do something very similar in terms of invoking the xattr state machine and handling transaction rolls where the dfops mechanism isn't there to do it for us.

Brian

Sure, that shouldn't be to hard to make a high level wrapper like that. Then we can let go of the old code path.

I view it as more like reorganizing and reusing the old code path. ;)

Brian

Quoted 573 lines

Thanks again for the all the reviewing! :-)

Allison

Quoted 569 lines
Quoted 569 lines

Thank you for all the thorough reviewing here, I know it's a lot! Allison

Quoted 565 lines

Brian

Quoted 562 lines
fs/xfs/libxfs/xfs_attr.c +522 -0
+
+	/*
+	 * After a shortform to leaf conversion, we need to hold the leaf and
+	 * cylce out the transaction.  When we get back, we need to release
+	 * the leaf.
+	 */
+	if (*leaf_bp != NULL) {
+		xfs_trans_brelse(args->trans, *leaf_bp);
+		*leaf_bp = NULL;
+	}
+
+	/*
+	 * If we fit in a block, or we are in the middle of adding a leaf name.
+	 * xfs_attr_da_leaf_addname will set the XFS_DC_ALLOC_LEAF to indicate
+	 * that it is not done yet, and need to be recalled to finish up from
+	 * the last EAGAIN it returned
+	 */
+	if (xfs_bmap_one_block(dp, XFS_ATTR_FORK) ||
+	    args->dc.flags & XFS_DC_ALLOC_LEAF) {
+		if (!(args->dc.flags & XFS_DC_FOUND_LBLK)) {
+			error = xfs_attr_leaf_try_add(args, *leaf_bp);
+			args->dc.flags |= XFS_DC_FOUND_LBLK;
+
+			if (error && error != -ENOSPC)
+				return error;
+
+			return -EAGAIN;
+		}
+
+		error = xfs_leaf_addname_later(args);
+		if (error && error != -ENOSPC)
+			return error;
+	} else {
+		error = xfs_node_addname_later(args);
+	}
+
+	return error;
+}
+
+
+
+/*
    * Return EEXIST if attr is found, or ENOATTR if not
    */
   int
@@ -362,6 +471,57 @@ xfs_attr_remove_args(
   	return error;
   }
+/*
+ * Remove the attribute specified in @args.
+ * This routine is meant to function as a delayed operation, and may return
+ * -EGAIN when the transaction needs to be rolled.  Calling functions will need
+ * to handle this, and recall the function until a successful error code is
+ * returned.
+ */
+int
+xfs_attr_remove_later(
+	struct xfs_da_args      *args)
+{
+	struct xfs_inode	*dp = args->dp;
+	struct xfs_buf		*bp;
+	int			forkoff, error = 0;
+
+	if (!xfs_inode_hasattr(dp)) {
+		error = -ENOATTR;
+	} else if (dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) {
+		ASSERT(dp->i_afp->if_flags & XFS_IFINLINE);
+		error = xfs_attr_shortform_remove(args);
+	} else if (xfs_bmap_one_block(dp, XFS_ATTR_FORK) &&
+		   !(args->dc.flags & XFS_DC_RM_NODE_BLKS)) {
+		/*
+		 * If we fit in a block AND we are not in the middle of
+		 * removing node blocks, remove the leaf attribute.
+		 * xfs_attr_da_node_removename will set XFS_DC_RM_NODE_BLKS to
+		 * signal that it is not done yet, and needs to be recalled to
+		 * to finish up from the last -EAGAIN
+		 */
+		error = xfs_leaf_has_attr(args, &bp);
+		if (error == -ENOATTR) {
+			xfs_trans_brelse(args->trans, bp);
+			return error;
+		}
+		error = 0;
+
+		xfs_attr3_leaf_remove(bp, args);
+
+		/* If the result is small enough, shrink it into the inode.*/
+		forkoff = xfs_attr_shortform_allfit(bp, dp);
+		if (forkoff)
+			error = xfs_attr3_leaf_to_shortform(bp, args, forkoff);
+	} else {
+		error = xfs_node_removename_later(args);
+	}
+
+	return error;
+}
+
+
+
   int
   xfs_attr_set(
   	struct xfs_inode	*dp,
@@ -794,6 +954,87 @@ xfs_attr_leaf_addname(struct xfs_da_args	*args)
   }
   /*
+ * Add a name to the leaf attribute list structure
+ *
+ * This leaf block cannot have a "remote" value, we only call this routine
+ * if bmap_one_block() says there is only one block (ie: no remote blks).
+ *
+ * This routine is meant to function as a delayed operation, and may return
+ * -EGAIN when the transaction needs to be rolled.  Calling functions will need
+ * to handle this, and recall the function until a successful error code is
+ * returned.
+ */
+STATIC int
+xfs_leaf_addname_later(
+	struct xfs_da_args	*args)
+{
+	int			error, nmap;
+	struct xfs_inode	*dp = args->dp;
+	struct xfs_bmbt_irec	*map = &args->dc.map;
+
+	/*
+	 * If there was an out-of-line value, allocate the blocks we
+	 * identified for its storage and copy the value.  This is done
+	 * after we create the attribute so that we don't overflow the
+	 * maximum size of a transaction and/or hit a deadlock.
+	 */
+	if (args->rmtblkno > 0) {
+		if (!(args->dc.flags & XFS_DC_ALLOC_LEAF)) {
+			args->dc.lfileoff = 0;
+			args->dc.lblkno = 0;
+			args->dc.blkcnt = 0;
+			args->rmtblkcnt = 0;
+			args->rmtblkno = 0;
+			memset(map, 0, sizeof(struct xfs_bmbt_irec));
+
+			error = xfs_attr_rmt_find_hole(args);
+			if (error)
+				return error;
+
+			args->dc.blkcnt = args->rmtblkcnt;
+			args->dc.lblkno = args->rmtblkno;
+			args->dc.flags |= XFS_DC_ALLOC_LEAF;
+		}
+
+		/*
+		 * Roll through the "value", allocating blocks on disk as
+		 * required.
+		 */
+		while (args->dc.blkcnt > 0) {
+			nmap = 1;
+			error = xfs_bmapi_write(args->trans, dp,
+				  (xfs_fileoff_t)args->dc.lblkno,
+				  args->dc.blkcnt, XFS_BMAPI_ATTRFORK,
+				  args->total, map, &nmap);
+			if (error)
+				return error;
+			ASSERT(nmap == 1);
+			ASSERT((map->br_startblock != DELAYSTARTBLOCK) &&
+			       (map->br_startblock != HOLESTARTBLOCK));
+
+			/* roll attribute extent map forwards */
+			args->dc.lblkno += map->br_blockcount;
+			args->dc.blkcnt -= map->br_blockcount;
+
+			return -EAGAIN;
+		}
+
+		error = xfs_attr_rmtval_set_value(args);
+		if (error)
+			return error;
+	}
+
+	if (args->rmtblkno > 0) {
+		/*
+		 * Added a "remote" value, just clear the incomplete flag.
+		 */
+		error = xfs_attr3_leaf_clearflag(args);
+	}
+	args->dc.flags &= ~XFS_DC_ALLOC_LEAF;
+	return error;
+}
+
+/*
    * Return EEXIST if attr is found, or ENOATTR if not
    */
   STATIC int
@@ -1291,6 +1532,354 @@ xfs_attr_node_removename(
   }
   /*
+ * Remove a name from a B-tree attribute list.
+ *
+ * This will involve walking down the Btree, and may involve joining
+ * leaf nodes and even joining intermediate nodes up to and including
+ * the root node (a special case of an intermediate node).
+ *
+ * This routine is meant to function as a delayed operation, and may return
+ * -EGAIN when the transaction needs to be rolled.  Calling functions
+ * will need to handle this, and recall the function until a successful error
+ * code is returned.
+ */
+STATIC int
+xfs_node_removename_later(
+	struct xfs_da_args	*args)
+{
+	struct xfs_da_state	*state = NULL;
+	struct xfs_da_state_blk	*blk;
+	struct xfs_buf		*bp;
+	int			error, forkoff, retval = 0;
+	struct xfs_inode	*dp = args->dp;
+	int			done = 0;
+
+	trace_xfs_attr_node_removename(args);
+
+	if (args->dc.state == NULL) {
+		error = xfs_attr_node_hasname(args, &args->dc.state);
+		if (error != -EEXIST)
+			goto out;
+		else
+			error = 0;
+
+		/*
+		 * If there is an out-of-line value, de-allocate the blocks.
+		 * This is done before we remove the attribute so that we don't
+		 * overflow the maximum size of a transaction and/or hit a
+		 * deadlock.
+		 */
+		state = args->dc.state;
+		args->dc.blk = &state->path.blk[state->path.active - 1];
+		ASSERT(args->dc.blk->bp != NULL);
+		ASSERT(args->dc.blk->magic == XFS_ATTR_LEAF_MAGIC);
+	}
+	state = args->dc.state;
+	blk = args->dc.blk;
+
+	if (args->rmtblkno > 0 && !(args->dc.flags & XFS_DC_RM_LEAF_BLKS)) {
+		bool isset;
+
+		error = xfs_attr3_leaf_flag_is_set(args, &isset);
+		if (error)
+			goto out;
+		if (!isset) {
+			/*
+			 * Fill in disk block numbers in the state structure
+			 * so that we can get the buffers back after we commit
+			 * several transactions in the following calls.
+			 */
+			error = xfs_attr_fillstate(state);
+			if (error)
+				goto out;
+
+			/*
+			 * Mark the attribute as INCOMPLETE, then bunmapi() the
+			 * remote value.
+			 */
+			error = xfs_attr3_leaf_setflag(args);
+			if (error)
+				goto out;
+
+			return -EAGAIN;
+		}
+
+		if (!(args->dc.flags & XFS_DC_RM_NODE_BLKS)) {
+			args->dc.flags |= XFS_DC_RM_NODE_BLKS;
+			error = xfs_attr_rmtval_invalidate(args);
+			if (error)
+				goto out;
+		}
+
+		/*
+		 * Unmap value blocks for this attr.  This is similar to
+		 * xfs_attr_rmtval_remove, but open coded here to return EAGAIN
+		 * for new transactions
+		 */
+		while (!done && !error) {
+			error = xfs_bunmapi(args->trans, args->dp,
+				    args->rmtblkno, args->rmtblkcnt,
+				    XFS_BMAPI_ATTRFORK, 1, &done);
+			if (error)
+				return error;
+
+			if (!done)
+				return -EAGAIN;
+		}
+
+		if (error)
+			goto out;
+
+		/*
+		 * Refill the state structure with buffers, the prior calls
+		 * released our buffers.
+		 */
+		error = xfs_attr_refillstate(state);
+		if (error)
+			goto out;
+	}
+
+	/*
+	 * Remove the name and update the hashvals in the tree.
+	 */
+	if (!(args->dc.flags & XFS_DC_RM_LEAF_BLKS)) {
+		blk = &state->path.blk[state->path.active - 1];
+		ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
+		retval = xfs_attr3_leaf_remove(blk->bp, args);
+		xfs_da3_fixhashpath(state, &state->path);
+
+		args->dc.flags |= XFS_DC_RM_LEAF_BLKS;
+	}
+
+	/*
+	 * Check to see if the tree needs to be collapsed.
+	 */
+	if (retval && (state->path.active > 1)) {
+		args->dc.flags |= XFS_DC_RM_NODE_BLKS;
+		error = xfs_da3_join(state);
+		if (error)
+			goto out;
+
+		return -EAGAIN;
+	}
+
+	/*
+	 * If the result is small enough, push it all into the inode.
+	 */
+	if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
+		/*
+		 * Have to get rid of the copy of this dabuf in the state.
+		 */
+		ASSERT(state->path.active == 1);
+		ASSERT(state->path.blk[0].bp);
+		state->path.blk[0].bp = NULL;
+
+		error = xfs_attr3_leaf_read(args->trans, args->dp, 0, -1, &bp);
+		if (error)
+			goto out;
+
+		forkoff = xfs_attr_shortform_allfit(bp, dp);
+		if (forkoff) {
+			error = xfs_attr3_leaf_to_shortform(bp, args, forkoff);
+			/* bp is gone due to xfs_da_shrink_inode */
+			if (error)
+				goto out;
+		} else
+			xfs_trans_brelse(args->trans, bp);
+	}
+out:
+	if (state != NULL)
+		xfs_da_state_free(state);
+
+	return error;
+}
+
+/*
+ * Add a name to a Btree-format attribute list.
+ *
+ * This will involve walking down the Btree, and may involve splitting
+ * leaf nodes and even splitting intermediate nodes up to and including
+ * the root node (a special case of an intermediate node).
+ *
+ * "Remote" attribute values confuse the issue and atomic rename operations
+ * add a whole extra layer of confusion on top of that.
+ *
+ * This routine is meant to function as a delayed operation, and may return
+ * -EGAIN when the transaction needs to be rolled.  Calling functions will need
+ * to handle this, and recall the function until a successful error code is
+ *returned.
+ */
+STATIC int
+xfs_node_addname_later(
+	struct xfs_da_args	*args)
+{
+	struct xfs_da_state	*state = NULL;
+	struct xfs_da_state_blk	*blk;
+	struct xfs_inode	*dp;
+	int			retval, error = 0;
+	int			nmap;
+	struct xfs_bmbt_irec    *map = &args->dc.map;
+
+	trace_xfs_attr_node_addname(args);
+
+	/*
+	 * Fill in bucket of arguments/results/context to carry around.
+	 */
+	dp = args->dp;
+
+	if (args->dc.flags & XFS_DC_FOUND_NBLK)
+		goto found_blk;
+
+	/*
+	 * Search to see if name already exists, and get back a pointer
+	 * to where it should go.
+	 */
+	retval = xfs_attr_node_hasname(args, &state);
+	blk = &state->path.blk[state->path.active-1];
+	ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
+	if ((args->name.type & ATTR_REPLACE) && (retval == -ENOATTR)) {
+		goto out;
+	} else if (retval == -EEXIST) {
+		if (args->name.type & ATTR_CREATE)
+			goto out;
+
+		trace_xfs_attr_node_replace(args);
+
+		/* save the attribute state for later removal*/
+		args->op_flags |= XFS_DA_OP_RENAME;	/* atomic rename op */
+		args->blkno2 = args->blkno;		/* set 2nd entry info*/
+		args->index2 = args->index;
+		args->rmtblkno2 = args->rmtblkno;
+		args->rmtblkcnt2 = args->rmtblkcnt;
+		args->rmtvaluelen2 = args->rmtvaluelen;
+
+		/*
+		 * clear the remote attr state now that it is saved so that the
+		 * values reflect the state of the attribute we are about to
+		 * add, not the attribute we just found and will remove later.
+		 */
+		args->rmtblkno = 0;
+		args->rmtblkcnt = 0;
+		args->rmtvaluelen = 0;
+	}
+
+	retval = xfs_attr3_leaf_add(blk->bp, state->args);
+	if (retval == -ENOSPC) {
+		if (state->path.active == 1) {
+			/*
+			 * Its really a single leaf node, but it had
+			 * out-of-line values so it looked like it *might*
+			 * have been a b-tree.
+			 */
+			xfs_da_state_free(state);
+			state = NULL;
+			error = xfs_attr3_leaf_to_node(args);
+			if (error)
+				goto out;
+
+			return -EAGAIN;
+		}
+
+		/*
+		 * Split as many Btree elements as required.
+		 * This code tracks the new and old attr's location
+		 * in the index/blkno/rmtblkno/rmtblkcnt fields and
+		 * in the index2/blkno2/rmtblkno2/rmtblkcnt2 fields.
+		 */
+		error = xfs_da3_split(state);
+		if (error)
+			goto out;
+	} else {
+		/*
+		 * Addition succeeded, update Btree hashvals.
+		 */
+		xfs_da3_fixhashpath(state, &state->path);
+	}
+
+	/*
+	 * Kill the state structure, we're done with it and need to
+	 * allow the buffers to come back later.
+	 */
+	xfs_da_state_free(state);
+	state = NULL;
+
+	args->dc.flags |= XFS_DC_FOUND_NBLK;
+	return -EAGAIN;
+found_blk:
+
+	/*
+	 * If there was an out-of-line value, allocate the blocks we
+	 * identified for its storage and copy the value.  This is done
+	 * after we create the attribute so that we don't overflow the
+	 * maximum size of a transaction and/or hit a deadlock.
+	 */
+	if (args->rmtblkno > 0) {
+		if (!(args->dc.flags & XFS_DC_ALLOC_NODE)) {
+			args->dc.flags |= XFS_DC_ALLOC_NODE;
+			args->dc.lblkno = 0;
+			args->dc.lfileoff = 0;
+			args->dc.blkcnt = 0;
+			args->rmtblkcnt = 0;
+			args->rmtblkno = 0;
+			memset(map, 0, sizeof(struct xfs_bmbt_irec));
+
+			error = xfs_attr_rmt_find_hole(args);
+			if (error)
+				return error;
+
+			args->dc.blkcnt = args->rmtblkcnt;
+			args->dc.lblkno = args->rmtblkno;
+		}
+		/*
+		 * Roll through the "value", allocating blocks on disk as
+		 * required.
+		 */
+		while (args->dc.blkcnt > 0) {
+			nmap = 1;
+			error = xfs_bmapi_write(args->trans, dp,
+				(xfs_fileoff_t)args->dc.lblkno, args->dc.blkcnt,
+				XFS_BMAPI_ATTRFORK, args->total, map, &nmap);
+			if (error)
+				return error;
+
+			ASSERT(nmap == 1);
+			ASSERT((map->br_startblock != DELAYSTARTBLOCK) &&
+			       (map->br_startblock != HOLESTARTBLOCK));
+
+			/* roll attribute extent map forwards */
+			args->dc.lblkno += map->br_blockcount;
+			args->dc.blkcnt -= map->br_blockcount;
+
+			return -EAGAIN;
+		}
+
+		error = xfs_attr_rmtval_set_value(args);
+		if (error)
+			return error;
+	}
+
+	if (args->rmtblkno > 0) {
+		/*
+		 * Added a "remote" value, just clear the incomplete flag.
+		 */
+		error = xfs_attr3_leaf_clearflag(args);
+		if (error)
+			goto out;
+	}
+	retval = error = 0;
+
+out:
+	if (state)
+		xfs_da_state_free(state);
+	if (error)
+		return error;
+
+	return retval;
+}
+
+
+
+/*
    * Fill in the disk block numbers in the state structure for the buffers
    * that are attached to the state structure.
    * This is done so that we can quickly reattach ourselves to those buffers
fs/xfs/libxfs/xfs_attr.h +2 -0
index fb56d81..6203766 100644
@@ -149,9 +149,11 @@ int xfs_attr_get(struct xfs_inode *ip, struct xfs_name *name,
   int xfs_attr_set(struct xfs_inode *dp, struct xfs_name *name,
   		 unsigned char *value, int valuelen);
   int xfs_attr_set_args(struct xfs_da_args *args);
+int xfs_attr_set_later(struct xfs_da_args *args, struct xfs_buf **leaf_bp);
   int xfs_attr_remove(struct xfs_inode *dp, struct xfs_name *name);
   int xfs_has_attr(struct xfs_da_args *args);
   int xfs_attr_remove_args(struct xfs_da_args *args);
+int xfs_attr_remove_later(struct xfs_da_args *args);
   int xfs_attr_list(struct xfs_inode *dp, char *buffer, int bufsize,
   		  int flags, struct attrlist_cursor_kern *cursor);
   bool xfs_attr_namecheck(const void *name, size_t length);
Signature · 1 line
2.7.4