Skip to contentSkip to conversation

xfs: Delay Ready Attributes

PATCH Superseded Allison Collins 3 participants 76 messages Apr 30, 2020 – May 7, 2020 XFS filesystem Page 1 of 2

v9 of 29 Superseded Latest is v29 →

lore
Share & tools
lore
#0 lore raw

v9 cover xfs: Delay Ready Attributes

Hi all,

This set is a subset of a larger series for delayed attributes. Which is a subset of an even larger series, 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 allows more complex operations (like parent pointers) to be broken up into multiple smaller transactions. To do this, the existing attr operations must be modified to operate as either a delayed operation or a inline operation since older filesystems will not be able to use the new log entries. This means that they cannot roll, commit, or finish transactions. Instead, they return -EAGAIN to allow the calling function to handle the transaction. In this series, we focus on only the clean up and refactoring needed to accomplish this. We will introduce delayed attrs and parent pointers in a later set.

At the moment, I would like people to focus their review efforts on just this "delay ready" subseries, as I think that is a more conservative use of peoples review time. I also think the set is a bit much to manage all at once, and we need to get the infrastructure ironed out before we focus too much anything that depends on it. But I do have the extended series for folks that want to see the bigger picture of where this is going.

To help organize the set, I've arranged the patches to make sort of mini sets. I thought it would help reviewers break down the reviewing some. For reviewing purposes, the set could be broken up into 4 different phases:

Error code filtering (patches 1-2):
These two patches are all about finding and catching error codes that need to be sent back up to user space before starting delayed operations. Errors that happen during a delayed operation are treated like internal errors that cause a shutdown. But we wouldnt want that for example: when the user tries to rename a non existent attr. So the idea is that we need to find all such conditions, and take care of them before starting a delayed operation.
xfs: Add xfs_has_attr and subroutines
xfs: Check for -ENOATTR or -EEXIST

Move transactions upwards (patches 3-10):
The goal of this subset is to try and move all the transaction specific code up the call stack much as possible. The idea being that once we get them to the top, we can introduce the statemachine to handle the -EAGAIN logic where ever the transactions used to be.
xfs: Factor out new helper functions xfs_attr_rmtval_set
xfs: Pull up trans handling in xfs_attr3_leaf_flipflags
xfs: Split apart xfs_attr_leaf_addname
xfs: Refactor xfs_attr_try_sf_addname
xfs: Pull up trans roll from xfs_attr3_leaf_setflag
xfs: Factor out xfs_attr_rmtval_invalidate
xfs: Pull up trans roll in xfs_attr3_leaf_clearflag
xfs: Add helper function __xfs_attr_rmtval_remove

Modularizing and cleanups (patches 11-18):
Now that we have pulled the transactions up to where we need them, it's time to start breaking down the top level functions into new subfunctions. The goal being to work towards a top level function that deals mostly with the statemachine, and helpers for those states
xfs: Add helper function xfs_attr_node_shrink
xfs: Remove unneeded xfs_trans_roll_inode calls
xfs: Add helpers xfs_attr_is_shortform and xfs_attr_set_shortform
xfs: Add helper function xfs_attr_leaf_mark_incomplete
xfs: Add remote block helper functions
xfs: Add helper function xfs_attr_node_removename_setup
xfs: Add helper function xfs_attr_node_removename_rmt
xfs: Simplify xfs_attr_leaf_addname
xfs: Simplify xfs_attr_node_addname
xfs: Lift -ENOSPC handler from xfs_attr_leaf_addname

Introduce statemachine (patches 18-20):
Now that we have re-arranged the code such that we can remove the transaction handling, we proceed to do so. The behavior of the attr set/remove routines are now also compatible as a .finish_item callback
xfs: Add delay ready attr remove routines
xfs: Add delay ready attr set routines
xfs: Rename __xfs_attr_rmtval_remove

Changes since v8:
Theres a lot of activity that goes around with each set, so to help people recall the discussion I've outlined the changes for each patch, which are new, and which are unchanged:

xfs: Add xfs_has_attr and subroutines
Fixed ENOATTR check
Inverted error check handler in xfs_attr_node_hasname Indentation fixes

xfs: Check for -ENOATTR or -EEXIST
Removed whitespace

xfs: Factor out new helper functions xfs_attr_rmtval_set
xfs: Pull up trans handling in xfs_attr3_leaf_flipflags
xfs: Split apart xfs_attr_leaf_addname
xfs: Refactor xfs_attr_try_sf_addname
xfs: Pull up trans roll from xfs_attr3_leaf_setflag
xfs: Factor out xfs_attr_rmtval_invalidate
xfs: Pull up trans roll in xfs_attr3_leaf_clearflag
No change

xfs: Add helper function __xfs_attr_rmtval_remove
__xfs_attr_rmtval_remove becomes a helper function of xfs_attr_rmtval_remove instead of a new function
Retain xfs_defer_finish in the helper so that we can replace it with the DEFER_FINISH flag later

xfs: Add helper function xfs_attr_leaf_mark_incomplete
NEW

xfs: Add helper function xfs_attr_node_shrink
Removed trailing error = 0

xfs: Remove unneeded xfs_trans_roll_inode calls
More unneeded xfs_defer_finish calls removed
Commit message verbage fix

xfs: Add helpers xfs_attr_is_shortform and xfs_attr_set_shortform
Indentation adjustment
Fixed comment verbage

xfs: Add helper function xfs_attr_leaf_mark_incomplete
Simplified error handler

xfs: Add remote block helper functions
No change

xfs: Add helper function xfs_attr_node_removename_setup
Move the invalidate addd from new patch 12 into the helper function in this patch

xfs: Add helper function xfs_attr_node_removename_rmt
Widen comment
Simplify error handler

xfs: Simplify xfs_attr_leaf_addname
NEW

xfs: Simplify xfs_attr_node_addname
NEW

xfs: Lift -ENOSPC handler from xfs_attr_leaf_addname
NEW

xfs: Add delay ready attr remove routines
Replaced XFS_DAS_RMTVAL_REMOVE state with XFS_DAC_NODE_RMVNAME_INIT flag
Extra XFS_DAC_DEFER_FINISH set added to __xfs_attr_rmtval_remove
Temporary XFS_DAC_DEFER_FINISH hander plumbed into xfs_attr_rmtval_remove until we delete it in the next patch Simplify xfs_attr_remove_iter with less states to handle
New helper function xfs_attr_defer_finish
Indentation fixes
Comments added to xfs_delattr_context
Commit message update
Flow chart update
Added flow chart to xfs_attr.h

xfs: Add delay ready attr set routines
Add fork code moved further up the set into parent pointers Replace XFS_DAS_ADD_LEAF state with shortform check Replace XFS_DAS_LEAF_TO_NODE state with leaf form check Replace XFS_DAS_ALLOC_LEAF with XFS_DAC_LEAF_ADDNAME_INIT flag Comments added to xfs_delattr_context, some unused feilds removed Rebase adjustments
Flow chart update

xfs: Rename __xfs_attr_rmtval_remove
Rebase adjustments

This series can be viewed on github here:
https://github.com/allisonhenderson/xfs_work/tree/delay_ready_attrs_v9

As well as the extended delayed attribute and parent pointer series:
https://github.com/allisonhenderson/xfs_work/tree/delay_ready_attrs_v9_extended

And the test cases:
https://github.com/allisonhenderson/xfs_work/tree/pptr_xfstests

In order to run the test cases, you will need have the corresponding xfsprogs changes as well. Which can be found here:
https://github.com/allisonhenderson/xfs_work/tree/delay_ready_attrs_xfsprogs_v9
https://github.com/allisonhenderson/xfs_work/tree/delay_ready_attrs_xfsprogs_v9_extended

To run the xfs attributes tests run:
check -g attr

To run as delayed attributes run:
export MKFS_OPTIONS="-n delattr"
check -g attr

To run parent pointer tests:
check -g parent

I've also made the corresponding updates to the user space side as well, and ported anything they need to seat correctly.

Questions, comment and feedback appreciated!

Thanks all!
Allison

Allison Collins (24):
xfs: Add xfs_has_attr and subroutines
xfs: Check for -ENOATTR or -EEXIST
xfs: Factor out new helper functions xfs_attr_rmtval_set
xfs: Pull up trans handling in xfs_attr3_leaf_flipflags
xfs: Split apart xfs_attr_leaf_addname
xfs: Refactor xfs_attr_try_sf_addname
xfs: Pull up trans roll from xfs_attr3_leaf_setflag
xfs: Factor out xfs_attr_rmtval_invalidate
xfs: Pull up trans roll in xfs_attr3_leaf_clearflag
xfs: Add helper function __xfs_attr_rmtval_remove
xfs: Pull up xfs_attr_rmtval_invalidate
xfs: Add helper function xfs_attr_node_shrink
xfs: Remove unneeded xfs_trans_roll_inode calls
xfs: Add helpers xfs_attr_is_shortform and xfs_attr_set_shortform
xfs: Add helper function xfs_attr_leaf_mark_incomplete
xfs: Add remote block helper functions
xfs: Add helper function xfs_attr_node_removename_setup
xfs: Add helper function xfs_attr_node_removename_rmt
xfs: Simplify xfs_attr_leaf_addname
xfs: Simplify xfs_attr_node_addname
xfs: Lift -ENOSPC handler from xfs_attr_leaf_addname
xfs: Add delay ready attr remove routines
xfs: Add delay ready attr set routines
xfs: Rename __xfs_attr_rmtval_remove

 fs/xfs/libxfs/xfs_attr.c        | 1229 ++++++++++++++++++++++++++-------------
 fs/xfs/libxfs/xfs_attr.h        |  199 +++++++
 fs/xfs/libxfs/xfs_attr_leaf.c   |  116 ++--
 fs/xfs/libxfs/xfs_attr_leaf.h   |    3 +
 fs/xfs/libxfs/xfs_attr_remote.c |  259 ++++++---
 fs/xfs/libxfs/xfs_attr_remote.h |    8 +-
 fs/xfs/xfs_attr_inactive.c      |    2 +-
 fs/xfs/xfs_trace.h              |    1 -
 8 files changed, 1281 insertions(+), 536 deletions(-)
Signature · 1 line
2.7.4
#1 lore raw

PATCH v9 1/24 xfs: Add xfs_has_attr and subroutines

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 appearance 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      | 182 ++++++++++++++++++++++++++++--------------
 fs/xfs/libxfs/xfs_attr.h      |   1 +
 fs/xfs/libxfs/xfs_attr_leaf.c |  97 +++++++++++++++-------
 fs/xfs/libxfs/xfs_attr_leaf.h |   3 +
 4 files changed, 191 insertions(+), 92 deletions(-)
fs/xfs/libxfs/xfs_attr.c +120 -62
index e4fe3dc..a1deac6 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_attr_leaf_hasname(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);
 
@@ -261,6 +264,37 @@ 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 = NULL;
+	int			error;
+
+	if (!xfs_inode_hasattr(dp))
+		return -ENOATTR;
+
+	if (dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) {
+		ASSERT(dp->i_afp->if_flags & XFS_IFINLINE);
+		return xfs_attr_sf_findname(args, NULL, NULL);
+	}
+
+	if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
+		error = xfs_attr_leaf_hasname(args, &bp);
+
+		if (bp)
+			xfs_trans_brelse(args->trans, bp);
+
+		return error;
+	}
+
+	return xfs_attr_node_hasname(args, NULL);
+}
+
+/*
  * Remove the attribute specified in @args.
  */
 int
@@ -469,26 +503,19 @@ 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, &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_attr_leaf_hasname(args, &bp);
+	if (retval != -ENOATTR && retval != -EEXIST)
+		return retval;
 	if (retval == -ENOATTR && (args->attr_flags & XATTR_REPLACE))
 		goto out_brelse;
 	if (retval == -EEXIST) {
@@ -640,6 +667,27 @@ xfs_attr_leaf_addname(
 }
 
 /*
+ * Return EEXIST if attr is found, or ENOATTR if not
+ */
+STATIC int
+xfs_attr_leaf_hasname(
+	struct xfs_da_args      *args,
+	struct xfs_buf		**bp)
+{
+	int                     error = 0;
+
+	error = xfs_attr3_leaf_read(args->trans, args->dp, 0, bp);
+	if (error)
+		return error;
+
+	error = xfs_attr3_leaf_lookup_int(*bp, args);
+	if (error != -ENOATTR && error != -EEXIST)
+		xfs_trans_brelse(args->trans, *bp);
+
+	return error;
+}
+
+/*
  * Remove a name from the leaf attribute list structure
  *
  * This leaf block cannot have a "remote" value, we only call this routine
@@ -659,16 +707,14 @@ xfs_attr_leaf_removename(
 	 * Remove the attribute.
 	 */
 	dp = args->dp;
-	args->blkno = 0;
-	error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno, &bp);
-	if (error)
-		return error;
 
-	error = xfs_attr3_leaf_lookup_int(bp, args);
+	error = xfs_attr_leaf_hasname(args, &bp);
+
 	if (error == -ENOATTR) {
 		xfs_trans_brelse(args->trans, bp);
 		return error;
-	}
+	} else if (error != -EEXIST)
+		return error;
 
 	xfs_attr3_leaf_remove(bp, args);
 
@@ -703,21 +749,56 @@ 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, &bp);
-	if (error)
-		return error;
+	error = xfs_attr_leaf_hasname(args, &bp);
 
-	error = xfs_attr3_leaf_lookup_int(bp, args);
-	if (error != -EEXIST)  {
+	if (error == -ENOATTR)  {
 		xfs_trans_brelse(args->trans, bp);
 		return error;
-	}
+	} else if (error != -EEXIST)
+		return error;
+
+
 	error = xfs_attr3_leaf_getvalue(bp, args);
 	xfs_trans_brelse(args->trans, bp);
 	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;
+	int			retval, error;
+
+	state = xfs_da_state_alloc();
+	state->args = args;
+	state->mp = args->dp->i_mount;
+
+	if (statep != NULL)
+		*statep = NULL;
+
+	/*
+	 * Search to see if name exists, and get back a pointer to it.
+	 */
+	error = xfs_da3_node_lookup_int(state, &retval);
+	if (error) {
+		xfs_da_state_free(state);
+		return error;
+	}
+
+	if (statep != NULL)
+		*statep = state;
+	else
+		xfs_da_state_free(state);
+	return retval;
+}
+
 /*========================================================================
  * External routines when attribute list size > geo->blksize
  *========================================================================*/
@@ -750,17 +831,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)
+	retval = xfs_attr_node_hasname(args, &state);
+	if (retval != -ENOATTR && retval != -EEXIST)
 		goto out;
+
 	blk = &state->path.blk[ state->path.active-1 ];
 	ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
 	if (retval == -ENOATTR && (args->attr_flags & XATTR_REPLACE))
@@ -965,29 +1043,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.
@@ -1082,7 +1146,8 @@ xfs_attr_node_removename(
 	error = 0;
 
 out:
-	xfs_da_state_free(state);
+	if (state)
+		xfs_da_state_free(state);
 	return error;
 }
 
@@ -1202,31 +1267,23 @@ xfs_attr_node_get(xfs_da_args_t *args)
 {
 	xfs_da_state_t *state;
 	xfs_da_state_blk_t *blk;
-	int error, retval;
+	int error;
 	int i;
 
 	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) {
-		retval = error;
-		goto out_release;
-	}
-	if (retval != -EEXIST)
+	error = xfs_attr_node_hasname(args, &state);
+	if (error != -EEXIST)
 		goto out_release;
 
 	/*
 	 * Get the value, local or "remote"
 	 */
 	blk = &state->path.blk[state->path.active - 1];
-	retval = xfs_attr3_leaf_getvalue(blk->bp, args);
+	error = xfs_attr3_leaf_getvalue(blk->bp, args);
 
 	/*
 	 * If not in a transaction, we have to release all the buffers.
@@ -1237,8 +1294,9 @@ xfs_attr_node_get(xfs_da_args_t *args)
 		state->path.blk[i].bp = NULL;
 	}
 
-	xfs_da_state_free(state);
-	return retval;
+	if (state)
+		xfs_da_state_free(state);
+	return error;
 }
 
 /* Returns true if the attribute entry name is valid. */
fs/xfs/libxfs/xfs_attr.h +1 -0
index 0d2d059..66575b8 100644
@@ -89,6 +89,7 @@ int xfs_attr_get_ilocked(struct xfs_da_args *args);
 int xfs_attr_get(struct xfs_da_args *args);
 int xfs_attr_set(struct xfs_da_args *args);
 int xfs_attr_set_args(struct xfs_da_args *args);
+int xfs_has_attr(struct xfs_da_args *args);
 int xfs_attr_remove_args(struct xfs_da_args *args);
 bool xfs_attr_namecheck(const void *name, size_t length);
 
fs/xfs/libxfs/xfs_attr_leaf.c +67 -30

127 lines not on this page · raw message

fs/xfs/libxfs/xfs_attr_leaf.h +3 -0
index 6dd2d93..88ec042 100644
@@ -52,6 +52,9 @@ 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_attr_sf_findname(struct xfs_da_args *args,
+			     struct xfs_attr_sf_entry **sfep,
+			     unsigned 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
#2 lore raw

PATCH v9 2/24 xfs: Check for -ENOATTR or -EEXIST

In reply to Allison Collins

Delayed operations cannot return error codes. So we must check for these conditions first before starting set or remove operations

---
 fs/xfs/libxfs/xfs_attr.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
fs/xfs/libxfs/xfs_attr.c +13 -0
index a1deac6..5467af6 100644
@@ -404,6 +404,15 @@ xfs_attr_set(
 				args->total, 0, quota_flags);
 		if (error)
 			goto out_trans_cancel;
+
+		error = xfs_has_attr(args);
+		if (error == -EEXIST && (args->attr_flags & XATTR_CREATE))
+			goto out_trans_cancel;
+		if (error == -ENOATTR && (args->attr_flags & XATTR_REPLACE))
+			goto out_trans_cancel;
+		if (error != -ENOATTR && error != -EEXIST)
+			goto out_trans_cancel;
+
 		error = xfs_attr_set_args(args);
 		if (error)
 			goto out_trans_cancel;
@@ -411,6 +420,10 @@ xfs_attr_set(
 		if (!args->trans)
 			goto out_unlock;
 	} else {
+		error = xfs_has_attr(args);
+		if (error != -EEXIST)
+			goto out_trans_cancel;
+
 		error = xfs_attr_remove_args(args);
 		if (error)
 			goto out_trans_cancel;
Signature · 1 line
2.7.4
#3 lore raw

PATCH v9 3/24 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 | 149 +++++++++++++++++++++++++---------------
 1 file changed, 92 insertions(+), 57 deletions(-)
fs/xfs/libxfs/xfs_attr_remote.c +92 -57
index 01ad7f3..f825eed 100644
@@ -440,32 +440,23 @@ xfs_attr_rmtval_get(
 }
 
 /*
- * Write the value associated with an attribute into the out-of-line buffer
- * that we have defined for it.
+ * Find a "hole" in the attribute address space large enough for us to drop the
+ * new attribute's value into
  */
-int
-xfs_attr_rmtval_set(
+STATIC int
+xfs_attr_rmt_find_hole(
 	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);
+	int			blkcnt;
+	xfs_fileoff_t		lfileoff = 0;
 
 	/*
-	 * 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.
+	 * 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,
@@ -473,48 +464,26 @@ xfs_attr_rmtval_set(
 	if (error)
 		return error;
 
-	args->rmtblkno = lblkno = (xfs_dablk_t)lfileoff;
+	args->rmtblkno = (xfs_dablk_t)lfileoff;
 	args->rmtblkcnt = blkcnt;
 
-	/*
-	 * Roll through the "value", allocating blocks on disk as required.
-	 */
-	while (blkcnt > 0) {
-		/*
-		 * Allocate a single extent, up to the size of the value.
-		 *
-		 * Note that we have to consider this a data allocation as we
-		 * write the remote attribute without logging the contents.
-		 * Hence we must ensure that we aren't using blocks that are on
-		 * the busy list so that we don't overwrite blocks which have
-		 * recently been freed but their transactions are not yet
-		 * committed to disk. If we overwrite the contents of a busy
-		 * extent and then crash then the block may not contain the
-		 * correct metadata after log recovery occurs.
-		 */
-		nmap = 1;
-		error = xfs_bmapi_write(args->trans, dp, (xfs_fileoff_t)lblkno,
-				  blkcnt, XFS_BMAPI_ATTRFORK, args->total, &map,
-				  &nmap);
-		if (error)
-			return error;
-		error = xfs_defer_finish(&args->trans);
-		if (error)
-			return error;
-
-		ASSERT(nmap == 1);
-		ASSERT((map.br_startblock != DELAYSTARTBLOCK) &&
-		       (map.br_startblock != HOLESTARTBLOCK));
-		lblkno += map.br_blockcount;
-		blkcnt -= map.br_blockcount;
+	return 0;
+}
 
-		/*
-		 * Start the next trans in the chain.
-		 */
-		error = xfs_trans_roll_inode(&args->trans, dp);
-		if (error)
-			return error;
-	}
+STATIC 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
@@ -595,6 +564,72 @@ xfs_attr_rmtval_stale(
 }
 
 /*
+ * Write the value associated with an attribute into the out-of-line buffer
+ * that we have defined for it.
+ */
+int
+xfs_attr_rmtval_set(
+	struct xfs_da_args	*args)
+{
+	struct xfs_inode	*dp = args->dp;
+	struct xfs_bmbt_irec	map;
+	xfs_dablk_t		lblkno;
+	int			blkcnt;
+	int			nmap;
+	int			error;
+
+	trace_xfs_attr_rmtval_set(args);
+
+	error = xfs_attr_rmt_find_hole(args);
+	if (error)
+		return error;
+
+	blkcnt = args->rmtblkcnt;
+	lblkno = (xfs_dablk_t)args->rmtblkno;
+	/*
+	 * Roll through the "value", allocating blocks on disk as required.
+	 */
+	while (blkcnt > 0) {
+		/*
+		 * Allocate a single extent, up to the size of the value.
+		 *
+		 * Note that we have to consider this a data allocation as we
+		 * write the remote attribute without logging the contents.
+		 * Hence we must ensure that we aren't using blocks that are on
+		 * the busy list so that we don't overwrite blocks which have
+		 * recently been freed but their transactions are not yet
+		 * committed to disk. If we overwrite the contents of a busy
+		 * extent and then crash then the block may not contain the
+		 * correct metadata after log recovery occurs.
+		 */
+		nmap = 1;
+		error = xfs_bmapi_write(args->trans, dp, (xfs_fileoff_t)lblkno,
+				  blkcnt, XFS_BMAPI_ATTRFORK, args->total, &map,
+				  &nmap);
+		if (error)
+			return error;
+		error = xfs_defer_finish(&args->trans);
+		if (error)
+			return error;
+
+		ASSERT(nmap == 1);
+		ASSERT((map.br_startblock != DELAYSTARTBLOCK) &&
+		       (map.br_startblock != HOLESTARTBLOCK));
+		lblkno += map.br_blockcount;
+		blkcnt -= map.br_blockcount;
+
+		/*
+		 * Start the next trans in the chain.
+		 */
+		error = xfs_trans_roll_inode(&args->trans, dp);
+		if (error)
+			return error;
+	}
+
+	return xfs_attr_rmtval_set_value(args);
+}
+
+/*
  * Remove the value associated with an attribute by deleting the
  * out-of-line buffer that it is stored on.
  */
Signature · 1 line
2.7.4
#4 lore raw

PATCH v9 4/24 xfs: Pull up trans handling in xfs_attr3_leaf_flipflags

In reply to Allison Collins

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

---
 fs/xfs/libxfs/xfs_attr.c      | 14 ++++++++++++++
 fs/xfs/libxfs/xfs_attr_leaf.c |  7 +------
 2 files changed, 15 insertions(+), 6 deletions(-)
fs/xfs/libxfs/xfs_attr.c +14 -0
index 5467af6..dcbc475 100644
@@ -622,6 +622,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
@@ -968,6 +975,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 +1 -6
index 9f39e7a..ab87bae 100644
@@ -2953,10 +2953,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;
+	return 0;
 }
Signature · 1 line
2.7.4
#5 lore raw

PATCH v9 5/24 xfs: Split apart xfs_attr_leaf_addname

In reply to Allison Collins

Split out new helper function xfs_attr_leaf_try_add from xfs_attr_leaf_addname. Because new delayed attribute routines cannot roll transactions, we split off the parts of xfs_attr_leaf_addname that we can use, and move the commit into the calling function.

---
 fs/xfs/libxfs/xfs_attr.c | 94 ++++++++++++++++++++++++++++++------------------
 1 file changed, 60 insertions(+), 34 deletions(-)
fs/xfs/libxfs/xfs_attr.c +60 -34
index dcbc475..b3b21a7 100644
@@ -256,10 +256,30 @@ xfs_attr_set_args(
 		}
 	}
 
-	if (xfs_bmap_one_block(dp, XFS_ATTR_FORK))
+	if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
 		error = xfs_attr_leaf_addname(args);
-	else
-		error = xfs_attr_node_addname(args);
+		if (error != -ENOSPC)
+			return error;
+
+		/*
+		 * Commit that transaction so that the node_addname()
+		 * call can manage its own transactions.
+		 */
+		error = xfs_defer_finish(&args->trans);
+		if (error)
+			return error;
+
+		/*
+		 * Commit the current trans (including the inode) and
+		 * start a new one.
+		 */
+		error = xfs_trans_roll_inode(&args->trans, dp);
+		if (error)
+			return error;
+
+	}
+
+	error = xfs_attr_node_addname(args);
 	return error;
 }
 
@@ -507,20 +527,21 @@ xfs_attr_shortform_addname(xfs_da_args_t *args)
  *========================================================================*/
 
 /*
- * Add a name to the leaf attribute list structure
+ * Tries to add an attribute to an inode in leaf form
  *
- * 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 function is meant to execute as part of a delayed operation and leaves
+ * the transaction handling to the caller.  On success the attribute is added
+ * and the inode and transaction are left dirty.  If there is not enough space,
+ * the attr data is converted to node format and -ENOSPC is returned. Caller is
+ * responsible for handling the dirty inode and transaction or adding the attr
+ * in node format.
  */
 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;
-
-	trace_xfs_attr_leaf_addname(args);
+	int			retval, error;
 
 	/*
 	 * Look up the given attribute in the leaf block.  Figure out if
@@ -562,31 +583,39 @@ 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. Unless an
+		 * error occurs, retain the -ENOSPC retval
 		 */
 		error = xfs_attr3_leaf_to_node(args);
 		if (error)
 			return error;
-		error = xfs_defer_finish(&args->trans);
-		if (error)
-			return error;
+	}
+	return retval;
+out_brelse:
+	xfs_trans_brelse(args->trans, bp);
+	return retval;
+}
 
-		/*
-		 * Commit the current trans (including the inode) and start
-		 * a new one.
-		 */
-		error = xfs_trans_roll_inode(&args->trans, dp);
-		if (error)
-			return error;
 
-		/*
-		 * Fob the whole rest of the problem off on the Btree code.
-		 */
-		error = xfs_attr_node_addname(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).
+ */
+STATIC int
+xfs_attr_leaf_addname(
+	struct xfs_da_args	*args)
+{
+	int			error, forkoff;
+	struct xfs_buf		*bp = NULL;
+	struct xfs_inode	*dp = args->dp;
+
+	trace_xfs_attr_leaf_addname(args);
+
+	error = xfs_attr_leaf_try_add(args, bp);
+	if (error)
 		return error;
-	}
 
 	/*
 	 * Commit the transaction that added the attr name so that
@@ -681,9 +710,6 @@ xfs_attr_leaf_addname(
 		error = xfs_attr3_leaf_clearflag(args);
 	}
 	return error;
-out_brelse:
-	xfs_trans_brelse(args->trans, bp);
-	return retval;
 }
 
 /*
Signature · 1 line
2.7.4
#6 lore raw

Re: [PATCH v9 05/24] xfs: Split apart xfs_attr_leaf_addname

Quoted 8 lines · Allison Collins

Split out new helper function xfs_attr_leaf_try_add from xfs_attr_leaf_addname. Because new delayed attribute routines cannot roll transactions, we split off the parts of xfs_attr_leaf_addname that we can use, and move the commit into the calling function.

<groan> I just replied to the xfsprogs version of this patch by accident. :(

Modulo the comments I made in that reply, the rest of the patch looks ok.

--D

Quoted 145 lines
---
 fs/xfs/libxfs/xfs_attr.c | 94 ++++++++++++++++++++++++++++++------------------
 1 file changed, 60 insertions(+), 34 deletions(-)
fs/xfs/libxfs/xfs_attr.c +60 -34
index dcbc475..b3b21a7 100644
@@ -256,10 +256,30 @@ xfs_attr_set_args(
 		}
 	}
 
-	if (xfs_bmap_one_block(dp, XFS_ATTR_FORK))
+	if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
 		error = xfs_attr_leaf_addname(args);
-	else
-		error = xfs_attr_node_addname(args);
+		if (error != -ENOSPC)
+			return error;
+
+		/*
+		 * Commit that transaction so that the node_addname()
+		 * call can manage its own transactions.
+		 */
+		error = xfs_defer_finish(&args->trans);
+		if (error)
+			return error;
+
+		/*
+		 * Commit the current trans (including the inode) and
+		 * start a new one.
+		 */
+		error = xfs_trans_roll_inode(&args->trans, dp);
+		if (error)
+			return error;
+
+	}
+
+	error = xfs_attr_node_addname(args);
 	return error;
 }
 
@@ -507,20 +527,21 @@ xfs_attr_shortform_addname(xfs_da_args_t *args)
  *========================================================================*/
 
 /*
- * Add a name to the leaf attribute list structure
+ * Tries to add an attribute to an inode in leaf form
  *
- * 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 function is meant to execute as part of a delayed operation and leaves
+ * the transaction handling to the caller.  On success the attribute is added
+ * and the inode and transaction are left dirty.  If there is not enough space,
+ * the attr data is converted to node format and -ENOSPC is returned. Caller is
+ * responsible for handling the dirty inode and transaction or adding the attr
+ * in node format.
  */
 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;
-
-	trace_xfs_attr_leaf_addname(args);
+	int			retval, error;
 
 	/*
 	 * Look up the given attribute in the leaf block.  Figure out if
@@ -562,31 +583,39 @@ 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. Unless an
+		 * error occurs, retain the -ENOSPC retval
 		 */
 		error = xfs_attr3_leaf_to_node(args);
 		if (error)
 			return error;
-		error = xfs_defer_finish(&args->trans);
-		if (error)
-			return error;
+	}
+	return retval;
+out_brelse:
+	xfs_trans_brelse(args->trans, bp);
+	return retval;
+}
 
-		/*
-		 * Commit the current trans (including the inode) and start
-		 * a new one.
-		 */
-		error = xfs_trans_roll_inode(&args->trans, dp);
-		if (error)
-			return error;
 
-		/*
-		 * Fob the whole rest of the problem off on the Btree code.
-		 */
-		error = xfs_attr_node_addname(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).
+ */
+STATIC int
+xfs_attr_leaf_addname(
+	struct xfs_da_args	*args)
+{
+	int			error, forkoff;
+	struct xfs_buf		*bp = NULL;
+	struct xfs_inode	*dp = args->dp;
+
+	trace_xfs_attr_leaf_addname(args);
+
+	error = xfs_attr_leaf_try_add(args, bp);
+	if (error)
 		return error;
-	}
 
 	/*
 	 * Commit the transaction that added the attr name so that
@@ -681,9 +710,6 @@ xfs_attr_leaf_addname(
 		error = xfs_attr3_leaf_clearflag(args);
 	}
 	return error;
-out_brelse:
-	xfs_trans_brelse(args->trans, bp);
-	return retval;
 }
 
 /*
Signature · 1 line
2.7.4
#7 lore raw

Re: [PATCH v9 05/24] xfs: Split apart xfs_attr_leaf_addname

Quoted 10 lines · Darrick J. Wong
Quoted 8 lines · Allison Collins

Split out new helper function xfs_attr_leaf_try_add from xfs_attr_leaf_addname. Because new delayed attribute routines cannot roll transactions, we split off the parts of xfs_attr_leaf_addname that we can use, and move the commit into the calling function.

Quoted 6 lines

<groan> I just replied to the xfsprogs version of this patch by accident. :(

Modulo the comments I made in that reply, the rest of the patch looks ok.

--D

No worries, will apply same feed back here :-)

Allison

Quoted 146 lines
Quoted 146 lines
---
  fs/xfs/libxfs/xfs_attr.c | 94 ++++++++++++++++++++++++++++++------------------
  1 file changed, 60 insertions(+), 34 deletions(-)
fs/xfs/libxfs/xfs_attr.c +60 -34
index dcbc475..b3b21a7 100644
@@ -256,10 +256,30 @@ xfs_attr_set_args(
  		}
  	}
 
-	if (xfs_bmap_one_block(dp, XFS_ATTR_FORK))
+	if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
  		error = xfs_attr_leaf_addname(args);
-	else
-		error = xfs_attr_node_addname(args);
+		if (error != -ENOSPC)
+			return error;
+
+		/*
+		 * Commit that transaction so that the node_addname()
+		 * call can manage its own transactions.
+		 */
+		error = xfs_defer_finish(&args->trans);
+		if (error)
+			return error;
+
+		/*
+		 * Commit the current trans (including the inode) and
+		 * start a new one.
+		 */
+		error = xfs_trans_roll_inode(&args->trans, dp);
+		if (error)
+			return error;
+
+	}
+
+	error = xfs_attr_node_addname(args);
  	return error;
  }
 
@@ -507,20 +527,21 @@ xfs_attr_shortform_addname(xfs_da_args_t *args)
   *========================================================================*/
 
  /*
- * Add a name to the leaf attribute list structure
+ * Tries to add an attribute to an inode in leaf form
   *
- * 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 function is meant to execute as part of a delayed operation and leaves
+ * the transaction handling to the caller.  On success the attribute is added
+ * and the inode and transaction are left dirty.  If there is not enough space,
+ * the attr data is converted to node format and -ENOSPC is returned. Caller is
+ * responsible for handling the dirty inode and transaction or adding the attr
+ * in node format.
   */
  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;
-
-	trace_xfs_attr_leaf_addname(args);
+	int			retval, error;
 
  	/*
  	 * Look up the given attribute in the leaf block.  Figure out if
@@ -562,31 +583,39 @@ 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. Unless an
+		 * error occurs, retain the -ENOSPC retval
  		 */
  		error = xfs_attr3_leaf_to_node(args);
  		if (error)
  			return error;
-		error = xfs_defer_finish(&args->trans);
-		if (error)
-			return error;
+	}
+	return retval;
+out_brelse:
+	xfs_trans_brelse(args->trans, bp);
+	return retval;
+}
 
-		/*
-		 * Commit the current trans (including the inode) and start
-		 * a new one.
-		 */
-		error = xfs_trans_roll_inode(&args->trans, dp);
-		if (error)
-			return error;
 
-		/*
-		 * Fob the whole rest of the problem off on the Btree code.
-		 */
-		error = xfs_attr_node_addname(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).
+ */
+STATIC int
+xfs_attr_leaf_addname(
+	struct xfs_da_args	*args)
+{
+	int			error, forkoff;
+	struct xfs_buf		*bp = NULL;
+	struct xfs_inode	*dp = args->dp;
+
+	trace_xfs_attr_leaf_addname(args);
+
+	error = xfs_attr_leaf_try_add(args, bp);
+	if (error)
  		return error;
-	}
 
  	/*
  	 * Commit the transaction that added the attr name so that
@@ -681,9 +710,6 @@ xfs_attr_leaf_addname(
  		error = xfs_attr3_leaf_clearflag(args);
  	}
  	return error;
-out_brelse:
-	xfs_trans_brelse(args->trans, bp);
-	return retval;
  }
 
  /*
Signature · 1 line
2.7.4
#8 lore raw

PATCH v9 6/24 xfs: Refactor xfs_attr_try_sf_addname

In reply to Allison Collins

To help pre-simplify xfs_attr_set_args, we need to hoist transaction handling up, while modularizing the adjacent code down into helpers. In this patch, hoist the commit in xfs_attr_try_sf_addname up into the calling function, and also pull the attr list creation down.

---
 fs/xfs/libxfs/xfs_attr.c | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)
fs/xfs/libxfs/xfs_attr.c +15 -15
index b3b21a7..6eda505 100644
@@ -178,8 +178,13 @@ xfs_attr_try_sf_addname(
 	struct xfs_da_args	*args)
 {
 
-	struct xfs_mount	*mp = dp->i_mount;
-	int			error, error2;
+	int			error;
+
+	/*
+	 * Build initial attribute list (if required).
+	 */
+	if (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS)
+		xfs_attr_shortform_create(args);
 
 	error = xfs_attr_shortform_addname(args);
 	if (error == -ENOSPC)
@@ -192,12 +197,10 @@ xfs_attr_try_sf_addname(
 	if (!error && !(args->op_flags & XFS_DA_OP_NOTIME))
 		xfs_trans_ichgtime(args->trans, dp, XFS_ICHGTIME_CHG);
 
-	if (mp->m_flags & XFS_MOUNT_WSYNC)
+	if (dp->i_mount->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;
 }
 
 /*
@@ -209,7 +212,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,
@@ -220,17 +223,14 @@ xfs_attr_set_args(
 	     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;
+		if (error != -ENOSPC) {
+			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
#9 lore raw

PATCH v9 7/24 xfs: Pull up trans roll from xfs_attr3_leaf_setflag

In reply to Allison Collins

New delayed allocation routines cannot be handling transactions so pull 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 6eda505..f25493c 100644
@@ -1131,6 +1131,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 ab87bae..b588f8e 100644
@@ -2835,10 +2835,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 0;
 }
 
 /*
Signature · 1 line
2.7.4
#10 lore raw

PATCH v9 8/24 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 | 26 +++++++++++++++++++++-----
 fs/xfs/libxfs/xfs_attr_remote.h |  2 +-
 2 files changed, 22 insertions(+), 6 deletions(-)
fs/xfs/libxfs/xfs_attr_remote.c +21 -5
index f825eed..4d51969 100644
@@ -634,15 +634,12 @@ xfs_attr_rmtval_set(
  * out-of-line buffer that it is stored on.
  */
 int
-xfs_attr_rmtval_remove(
+xfs_attr_rmtval_invalidate(
 	struct xfs_da_args	*args)
 {
 	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.
@@ -670,13 +667,32 @@ 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.
 	 */
 	lblkno = args->rmtblkno;
 	blkcnt = args->rmtblkcnt;
-	done = 0;
 	while (!done) {
 		error = xfs_bunmapi(args->trans, args->dp, lblkno, blkcnt,
 				    XFS_BMAPI_ATTRFORK, 1, &done);
fs/xfs/libxfs/xfs_attr_remote.h +1 -1
index 6fb4572..eff5f95 100644
@@ -13,5 +13,5 @@ int xfs_attr_rmtval_set(struct xfs_da_args *args);
 int xfs_attr_rmtval_remove(struct xfs_da_args *args);
 int xfs_attr_rmtval_stale(struct xfs_inode *ip, struct xfs_bmbt_irec *map,
 		xfs_buf_flags_t incore_flags);
-
+int xfs_attr_rmtval_invalidate(struct xfs_da_args *args);
 #endif /* __XFS_ATTR_REMOTE_H__ */
Signature · 1 line
2.7.4
#11 lore raw

PATCH v9 9/24 xfs: Pull up trans roll in xfs_attr3_leaf_clearflag

In reply to Allison Collins

New delayed allocation routines cannot be handling transactions so pull them out into the calling functions

---
 fs/xfs/libxfs/xfs_attr.c      | 16 ++++++++++++++++
 fs/xfs/libxfs/xfs_attr_leaf.c |  5 +----
 2 files changed, 17 insertions(+), 4 deletions(-)
fs/xfs/libxfs/xfs_attr.c +16 -0
index f25493c..0fc6436 100644
@@ -708,6 +708,14 @@ xfs_attr_leaf_addname(
 		 * Added a "remote" value, just clear the incomplete flag.
 		 */
 		error = xfs_attr3_leaf_clearflag(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);
 	}
 	return error;
 }
@@ -1072,6 +1080,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 b588f8e..f55402b 100644
@@ -2784,10 +2784,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 0;
 }
 
 /*
Signature · 1 line
2.7.4
#12 lore raw

PATCH v9 10/24 xfs: Add helper function __xfs_attr_rmtval_remove

In reply to Allison Collins

This function is similar to xfs_attr_rmtval_remove, but adapted to return EAGAIN for new transactions. We will use this later when we introduce delayed attributes. This function will eventually replace xfs_attr_rmtval_remove

---
 fs/xfs/libxfs/xfs_attr_remote.c | 46 ++++++++++++++++++++++++++++++++---------
 fs/xfs/libxfs/xfs_attr_remote.h |  1 +
 2 files changed, 37 insertions(+), 10 deletions(-)
fs/xfs/libxfs/xfs_attr_remote.c +36 -10
index 4d51969..02d1a44 100644
@@ -681,7 +681,7 @@ xfs_attr_rmtval_remove(
 	xfs_dablk_t		lblkno;
 	int			blkcnt;
 	int			error = 0;
-	int			done = 0;
+	int			retval = 0;
 
 	trace_xfs_attr_rmtval_remove(args);
 
@@ -693,14 +693,10 @@ xfs_attr_rmtval_remove(
 	 */
 	lblkno = args->rmtblkno;
 	blkcnt = args->rmtblkcnt;
-	while (!done) {
-		error = xfs_bunmapi(args->trans, args->dp, lblkno, blkcnt,
-				    XFS_BMAPI_ATTRFORK, 1, &done);
-		if (error)
-			return error;
-		error = xfs_defer_finish(&args->trans);
-		if (error)
-			return error;
+	do {
+		retval = __xfs_attr_rmtval_remove(args);
+		if (retval && retval != EAGAIN)
+			return retval;
 
 		/*
 		 * Close out trans and start the next one in the chain.
@@ -708,6 +704,36 @@ xfs_attr_rmtval_remove(
 		error = xfs_trans_roll_inode(&args->trans, args->dp);
 		if (error)
 			return error;
-	}
+	} while (retval == -EAGAIN);
+
 	return 0;
 }
+
+/*
+ * Remove the value associated with an attribute by deleting the out-of-line
+ * buffer that it is stored on. Returns EAGAIN for the caller to refresh the
+ * transaction and recall the function
+ */
+int
+__xfs_attr_rmtval_remove(
+	struct xfs_da_args	*args)
+{
+	int			error, done;
+
+	/*
+	 * Unmap value blocks for this attr.
+	 */
+	error = xfs_bunmapi(args->trans, args->dp, args->rmtblkno,
+			    args->rmtblkcnt, XFS_BMAPI_ATTRFORK, 1, &done);
+	if (error)
+		return error;
+
+	error = xfs_defer_finish(&args->trans);
+	if (error)
+		return error;
+
+	if (!done)
+		return -EAGAIN;
+
+	return error;
+}
fs/xfs/libxfs/xfs_attr_remote.h +1 -0
index eff5f95..ee3337b 100644
@@ -14,4 +14,5 @@ int xfs_attr_rmtval_remove(struct xfs_da_args *args);
 int xfs_attr_rmtval_stale(struct xfs_inode *ip, struct xfs_bmbt_irec *map,
 		xfs_buf_flags_t incore_flags);
 int xfs_attr_rmtval_invalidate(struct xfs_da_args *args);
+int __xfs_attr_rmtval_remove(struct xfs_da_args *args);
 #endif /* __XFS_ATTR_REMOTE_H__ */
Signature · 1 line
2.7.4
Reviewed-by on v9 10/24
#13 lore raw

Re: [PATCH v9 10/24] xfs: Add helper function __xfs_attr_rmtval_remove

Quoted 8 lines · Allison Collins

This function is similar to xfs_attr_rmtval_remove, but adapted to return EAGAIN for new transactions. We will use this later when we introduce delayed attributes. This function will eventually replace xfs_attr_rmtval_remove

---

Looks like the commit log needs some rewording now that this is a refactor patch. With that fixed:

Quoted 87 lines
 fs/xfs/libxfs/xfs_attr_remote.c | 46 ++++++++++++++++++++++++++++++++---------
 fs/xfs/libxfs/xfs_attr_remote.h |  1 +
 2 files changed, 37 insertions(+), 10 deletions(-)
fs/xfs/libxfs/xfs_attr_remote.c +36 -10
index 4d51969..02d1a44 100644
@@ -681,7 +681,7 @@ xfs_attr_rmtval_remove(
 	xfs_dablk_t		lblkno;
 	int			blkcnt;
 	int			error = 0;
-	int			done = 0;
+	int			retval = 0;
 
 	trace_xfs_attr_rmtval_remove(args);
 
@@ -693,14 +693,10 @@ xfs_attr_rmtval_remove(
 	 */
 	lblkno = args->rmtblkno;
 	blkcnt = args->rmtblkcnt;
-	while (!done) {
-		error = xfs_bunmapi(args->trans, args->dp, lblkno, blkcnt,
-				    XFS_BMAPI_ATTRFORK, 1, &done);
-		if (error)
-			return error;
-		error = xfs_defer_finish(&args->trans);
-		if (error)
-			return error;
+	do {
+		retval = __xfs_attr_rmtval_remove(args);
+		if (retval && retval != EAGAIN)
+			return retval;
 
 		/*
 		 * Close out trans and start the next one in the chain.
@@ -708,6 +704,36 @@ xfs_attr_rmtval_remove(
 		error = xfs_trans_roll_inode(&args->trans, args->dp);
 		if (error)
 			return error;
-	}
+	} while (retval == -EAGAIN);
+
 	return 0;
 }
+
+/*
+ * Remove the value associated with an attribute by deleting the out-of-line
+ * buffer that it is stored on. Returns EAGAIN for the caller to refresh the
+ * transaction and recall the function
+ */
+int
+__xfs_attr_rmtval_remove(
+	struct xfs_da_args	*args)
+{
+	int			error, done;
+
+	/*
+	 * Unmap value blocks for this attr.
+	 */
+	error = xfs_bunmapi(args->trans, args->dp, args->rmtblkno,
+			    args->rmtblkcnt, XFS_BMAPI_ATTRFORK, 1, &done);
+	if (error)
+		return error;
+
+	error = xfs_defer_finish(&args->trans);
+	if (error)
+		return error;
+
+	if (!done)
+		return -EAGAIN;
+
+	return error;
+}
fs/xfs/libxfs/xfs_attr_remote.h +1 -0
index eff5f95..ee3337b 100644
@@ -14,4 +14,5 @@ int xfs_attr_rmtval_remove(struct xfs_da_args *args);
 int xfs_attr_rmtval_stale(struct xfs_inode *ip, struct xfs_bmbt_irec *map,
 		xfs_buf_flags_t incore_flags);
 int xfs_attr_rmtval_invalidate(struct xfs_da_args *args);
+int __xfs_attr_rmtval_remove(struct xfs_da_args *args);
 #endif /* __XFS_ATTR_REMOTE_H__ */
Signature · 1 line
2.7.4
#14 lore raw

Re: [PATCH v9 10/24] xfs: Add helper function __xfs_attr_rmtval_remove

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

This function is similar to xfs_attr_rmtval_remove, but adapted to return EAGAIN for new transactions. We will use this later when we introduce delayed attributes. This function will eventually replace xfs_attr_rmtval_remove

Quoted 6 lines
Quoted 3 lines

---

Looks like the commit log needs some rewording now that this is a refactor patch. With that fixed:

Ok, maybe just an extra line like "Refactor xfs_attr_rmtval_remove to add helper function __xfs_attr_rmtval_remove" ?

Quoted 2 lines

Alrighty, thank you!

Allison

Quoted 89 lines
Quoted 88 lines
  fs/xfs/libxfs/xfs_attr_remote.c | 46 ++++++++++++++++++++++++++++++++---------
  fs/xfs/libxfs/xfs_attr_remote.h |  1 +
  2 files changed, 37 insertions(+), 10 deletions(-)
fs/xfs/libxfs/xfs_attr_remote.c +36 -10
index 4d51969..02d1a44 100644
@@ -681,7 +681,7 @@ xfs_attr_rmtval_remove(
  	xfs_dablk_t		lblkno;
  	int			blkcnt;
  	int			error = 0;
-	int			done = 0;
+	int			retval = 0;
 
  	trace_xfs_attr_rmtval_remove(args);
 
@@ -693,14 +693,10 @@ xfs_attr_rmtval_remove(
  	 */
  	lblkno = args->rmtblkno;
  	blkcnt = args->rmtblkcnt;
-	while (!done) {
-		error = xfs_bunmapi(args->trans, args->dp, lblkno, blkcnt,
-				    XFS_BMAPI_ATTRFORK, 1, &done);
-		if (error)
-			return error;
-		error = xfs_defer_finish(&args->trans);
-		if (error)
-			return error;
+	do {
+		retval = __xfs_attr_rmtval_remove(args);
+		if (retval && retval != EAGAIN)
+			return retval;
 
  		/*
  		 * Close out trans and start the next one in the chain.
@@ -708,6 +704,36 @@ xfs_attr_rmtval_remove(
  		error = xfs_trans_roll_inode(&args->trans, args->dp);
  		if (error)
  			return error;
-	}
+	} while (retval == -EAGAIN);
+
  	return 0;
  }
+
+/*
+ * Remove the value associated with an attribute by deleting the out-of-line
+ * buffer that it is stored on. Returns EAGAIN for the caller to refresh the
+ * transaction and recall the function
+ */
+int
+__xfs_attr_rmtval_remove(
+	struct xfs_da_args	*args)
+{
+	int			error, done;
+
+	/*
+	 * Unmap value blocks for this attr.
+	 */
+	error = xfs_bunmapi(args->trans, args->dp, args->rmtblkno,
+			    args->rmtblkcnt, XFS_BMAPI_ATTRFORK, 1, &done);
+	if (error)
+		return error;
+
+	error = xfs_defer_finish(&args->trans);
+	if (error)
+		return error;
+
+	if (!done)
+		return -EAGAIN;
+
+	return error;
+}
fs/xfs/libxfs/xfs_attr_remote.h +1 -0
index eff5f95..ee3337b 100644
@@ -14,4 +14,5 @@ int xfs_attr_rmtval_remove(struct xfs_da_args *args);
  int xfs_attr_rmtval_stale(struct xfs_inode *ip, struct xfs_bmbt_irec *map,
  		xfs_buf_flags_t incore_flags);
  int xfs_attr_rmtval_invalidate(struct xfs_da_args *args);
+int __xfs_attr_rmtval_remove(struct xfs_da_args *args);
  #endif /* __XFS_ATTR_REMOTE_H__ */
Signature · 1 line
2.7.4
#15 lore raw

Re: [PATCH v9 10/24] xfs: Add helper function __xfs_attr_rmtval_remove

Quoted 9 lines · Allison Collins
Quoted 6 lines · Brian Foster
Quoted 5 lines · Allison Collins

This function is similar to xfs_attr_rmtval_remove, but adapted to return EAGAIN for new transactions. We will use this later when we introduce delayed attributes. This function will eventually replace xfs_attr_rmtval_remove

Quoted 9 lines
Quoted 6 lines
Quoted 3 lines

---

Looks like the commit log needs some rewording now that this is a refactor patch. With that fixed:

Ok, maybe just an extra line like "Refactor xfs_attr_rmtval_remove to add helper function __xfs_attr_rmtval_remove" ?

I'd update the first sentence to say something like that instead of how the function is similar to xfs_attr_rmtval_remove().

Brian

Quoted 93 lines
Quoted 2 lines

Alrighty, thank you!

Allison

Quoted 86 lines
Quoted 85 lines
  fs/xfs/libxfs/xfs_attr_remote.c | 46 ++++++++++++++++++++++++++++++++---------
  fs/xfs/libxfs/xfs_attr_remote.h |  1 +
  2 files changed, 37 insertions(+), 10 deletions(-)
fs/xfs/libxfs/xfs_attr_remote.c +36 -10
index 4d51969..02d1a44 100644
@@ -681,7 +681,7 @@ xfs_attr_rmtval_remove(
  	xfs_dablk_t		lblkno;
  	int			blkcnt;
  	int			error = 0;
-	int			done = 0;
+	int			retval = 0;
  	trace_xfs_attr_rmtval_remove(args);
@@ -693,14 +693,10 @@ xfs_attr_rmtval_remove(
  	 */
  	lblkno = args->rmtblkno;
  	blkcnt = args->rmtblkcnt;
-	while (!done) {
-		error = xfs_bunmapi(args->trans, args->dp, lblkno, blkcnt,
-				    XFS_BMAPI_ATTRFORK, 1, &done);
-		if (error)
-			return error;
-		error = xfs_defer_finish(&args->trans);
-		if (error)
-			return error;
+	do {
+		retval = __xfs_attr_rmtval_remove(args);
+		if (retval && retval != EAGAIN)
+			return retval;
  		/*
  		 * Close out trans and start the next one in the chain.
@@ -708,6 +704,36 @@ xfs_attr_rmtval_remove(
  		error = xfs_trans_roll_inode(&args->trans, args->dp);
  		if (error)
  			return error;
-	}
+	} while (retval == -EAGAIN);
+
  	return 0;
  }
+
+/*
+ * Remove the value associated with an attribute by deleting the out-of-line
+ * buffer that it is stored on. Returns EAGAIN for the caller to refresh the
+ * transaction and recall the function
+ */
+int
+__xfs_attr_rmtval_remove(
+	struct xfs_da_args	*args)
+{
+	int			error, done;
+
+	/*
+	 * Unmap value blocks for this attr.
+	 */
+	error = xfs_bunmapi(args->trans, args->dp, args->rmtblkno,
+			    args->rmtblkcnt, XFS_BMAPI_ATTRFORK, 1, &done);
+	if (error)
+		return error;
+
+	error = xfs_defer_finish(&args->trans);
+	if (error)
+		return error;
+
+	if (!done)
+		return -EAGAIN;
+
+	return error;
+}
fs/xfs/libxfs/xfs_attr_remote.h +1 -0
index eff5f95..ee3337b 100644
@@ -14,4 +14,5 @@ int xfs_attr_rmtval_remove(struct xfs_da_args *args);
  int xfs_attr_rmtval_stale(struct xfs_inode *ip, struct xfs_bmbt_irec *map,
  		xfs_buf_flags_t incore_flags);
  int xfs_attr_rmtval_invalidate(struct xfs_da_args *args);
+int __xfs_attr_rmtval_remove(struct xfs_da_args *args);
  #endif /* __XFS_ATTR_REMOTE_H__ */
Signature · 1 line
2.7.4
#16 lore raw

Re: [PATCH v9 10/24] xfs: Add helper function __xfs_attr_rmtval_remove

Quoted 16 lines · Brian Foster
Quoted 15 lines · Allison Collins
Quoted 12 lines · Brian Foster
Quoted 8 lines · Allison Collins

This function is similar to xfs_attr_rmtval_remove, but adapted to return EAGAIN for new transactions. We will use this later when we introduce delayed attributes. This function will eventually replace xfs_attr_rmtval_remove

---

Looks like the commit log needs some rewording now that this is a refactor patch. With that fixed:

Quoted 8 lines
Quoted 3 lines

Ok, maybe just an extra line like "Refactor xfs_attr_rmtval_remove to add helper function __xfs_attr_rmtval_remove" ?

I'd update the first sentence to say something like that instead of how the function is similar to xfs_attr_rmtval_remove().

Brian

Ok then, will update.

Allison

Quoted 95 lines
Quoted 94 lines
Quoted 3 lines

Alrighty, thank you!

Allison

Quoted 86 lines
Quoted 85 lines
   fs/xfs/libxfs/xfs_attr_remote.c | 46 ++++++++++++++++++++++++++++++++---------
   fs/xfs/libxfs/xfs_attr_remote.h |  1 +
   2 files changed, 37 insertions(+), 10 deletions(-)
fs/xfs/libxfs/xfs_attr_remote.c +36 -10
index 4d51969..02d1a44 100644
@@ -681,7 +681,7 @@ xfs_attr_rmtval_remove(
   	xfs_dablk_t		lblkno;
   	int			blkcnt;
   	int			error = 0;
-	int			done = 0;
+	int			retval = 0;
   	trace_xfs_attr_rmtval_remove(args);
@@ -693,14 +693,10 @@ xfs_attr_rmtval_remove(
   	 */
   	lblkno = args->rmtblkno;
   	blkcnt = args->rmtblkcnt;
-	while (!done) {
-		error = xfs_bunmapi(args->trans, args->dp, lblkno, blkcnt,
-				    XFS_BMAPI_ATTRFORK, 1, &done);
-		if (error)
-			return error;
-		error = xfs_defer_finish(&args->trans);
-		if (error)
-			return error;
+	do {
+		retval = __xfs_attr_rmtval_remove(args);
+		if (retval && retval != EAGAIN)
+			return retval;
   		/*
   		 * Close out trans and start the next one in the chain.
@@ -708,6 +704,36 @@ xfs_attr_rmtval_remove(
   		error = xfs_trans_roll_inode(&args->trans, args->dp);
   		if (error)
   			return error;
-	}
+	} while (retval == -EAGAIN);
+
   	return 0;
   }
+
+/*
+ * Remove the value associated with an attribute by deleting the out-of-line
+ * buffer that it is stored on. Returns EAGAIN for the caller to refresh the
+ * transaction and recall the function
+ */
+int
+__xfs_attr_rmtval_remove(
+	struct xfs_da_args	*args)
+{
+	int			error, done;
+
+	/*
+	 * Unmap value blocks for this attr.
+	 */
+	error = xfs_bunmapi(args->trans, args->dp, args->rmtblkno,
+			    args->rmtblkcnt, XFS_BMAPI_ATTRFORK, 1, &done);
+	if (error)
+		return error;
+
+	error = xfs_defer_finish(&args->trans);
+	if (error)
+		return error;
+
+	if (!done)
+		return -EAGAIN;
+
+	return error;
+}
fs/xfs/libxfs/xfs_attr_remote.h +1 -0
index eff5f95..ee3337b 100644
@@ -14,4 +14,5 @@ int xfs_attr_rmtval_remove(struct xfs_da_args *args);
   int xfs_attr_rmtval_stale(struct xfs_inode *ip, struct xfs_bmbt_irec *map,
   		xfs_buf_flags_t incore_flags);
   int xfs_attr_rmtval_invalidate(struct xfs_da_args *args);
+int __xfs_attr_rmtval_remove(struct xfs_da_args *args);
   #endif /* __XFS_ATTR_REMOTE_H__ */
Signature · 1 line
2.7.4
#17 lore raw

Re: [PATCH v9 10/24] xfs: Add helper function __xfs_attr_rmtval_remove

In reply to Allison Collins
Quoted 4 lines · Allison Collins

This function is similar to xfs_attr_rmtval_remove, but adapted to return EAGAIN for new transactions. We will use this later when we introduce delayed attributes. This function will eventually replace xfs_attr_rmtval_remove

Like Brian suggested, this changelog could probably just say that we're hoisting the loop body into a separate function so that delayed attrs can manage the transaction rolling.

Quoted 43 lines
---
 fs/xfs/libxfs/xfs_attr_remote.c | 46 ++++++++++++++++++++++++++++++++---------
 fs/xfs/libxfs/xfs_attr_remote.h |  1 +
 2 files changed, 37 insertions(+), 10 deletions(-)
fs/xfs/libxfs/xfs_attr_remote.c +5 -9
index 4d51969..02d1a44 100644
@@ -681,7 +681,7 @@ xfs_attr_rmtval_remove(
 	xfs_dablk_t		lblkno;
 	int			blkcnt;
 	int			error = 0;
-	int			done = 0;
+	int			retval = 0;
 
 	trace_xfs_attr_rmtval_remove(args);
 
@@ -693,14 +693,10 @@ xfs_attr_rmtval_remove(
 	 */
 	lblkno = args->rmtblkno;
 	blkcnt = args->rmtblkcnt;
-	while (!done) {
-		error = xfs_bunmapi(args->trans, args->dp, lblkno, blkcnt,
-				    XFS_BMAPI_ATTRFORK, 1, &done);
-		if (error)
-			return error;
-		error = xfs_defer_finish(&args->trans);
-		if (error)
-			return error;
+	do {
+		retval = __xfs_attr_rmtval_remove(args);
+		if (retval && retval != EAGAIN)
+			return retval;
 
 		/*
 		 * Close out trans and start the next one in the chain.
@@ -708,6 +704,36 @@ xfs_attr_rmtval_remove(
 		error = xfs_trans_roll_inode(&args->trans, args->dp);
 		if (error)
 			return error;

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

Quoted 10 lines
fs/xfs/libxfs/xfs_attr_remote.c +7 -1
-	}
+	} while (retval == -EAGAIN);
+
 	return 0;
 }
+
+/*
+ * Remove the value associated with an attribute by deleting the out-of-line
+ * buffer that it is stored on. Returns EAGAIN for the caller to refresh the
+ * transaction and recall the function

recall the function...?

Oh. "re-call" the function.

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

Quoted 3 lines
fs/xfs/libxfs/xfs_attr_remote.c +3 -0
+ */
+int
+__xfs_attr_rmtval_remove(

xfs_attr_rmtval_remove_extent() ?

--D

Quoted 34 lines
fs/xfs/libxfs/xfs_attr_remote.c +21 -0
+	struct xfs_da_args	*args)
+{
+	int			error, done;
+
+	/*
+	 * Unmap value blocks for this attr.
+	 */
+	error = xfs_bunmapi(args->trans, args->dp, args->rmtblkno,
+			    args->rmtblkcnt, XFS_BMAPI_ATTRFORK, 1, &done);
+	if (error)
+		return error;
+
+	error = xfs_defer_finish(&args->trans);
+	if (error)
+		return error;
+
+	if (!done)
+		return -EAGAIN;
+
+	return error;
+}
fs/xfs/libxfs/xfs_attr_remote.h +1 -0
index eff5f95..ee3337b 100644
@@ -14,4 +14,5 @@ int xfs_attr_rmtval_remove(struct xfs_da_args *args);
 int xfs_attr_rmtval_stale(struct xfs_inode *ip, struct xfs_bmbt_irec *map,
 		xfs_buf_flags_t incore_flags);
 int xfs_attr_rmtval_invalidate(struct xfs_da_args *args);
+int __xfs_attr_rmtval_remove(struct xfs_da_args *args);
 #endif /* __XFS_ATTR_REMOTE_H__ */
Signature · 1 line
2.7.4
#18 lore raw

Re: [PATCH v9 10/24] xfs: Add helper function __xfs_attr_rmtval_remove

Quoted 66 lines · Darrick J. Wong
Quoted 4 lines · Allison Collins

This function is similar to xfs_attr_rmtval_remove, but adapted to return EAGAIN for new transactions. We will use this later when we introduce delayed attributes. This function will eventually replace xfs_attr_rmtval_remove

Like Brian suggested, this changelog could probably just say that we're hoisting the loop body into a separate function so that delayed attrs can manage the transaction rolling.

Quoted 43 lines
---
  fs/xfs/libxfs/xfs_attr_remote.c | 46 ++++++++++++++++++++++++++++++++---------
  fs/xfs/libxfs/xfs_attr_remote.h |  1 +
  2 files changed, 37 insertions(+), 10 deletions(-)
fs/xfs/libxfs/xfs_attr_remote.c +5 -9
index 4d51969..02d1a44 100644
@@ -681,7 +681,7 @@ xfs_attr_rmtval_remove(
  	xfs_dablk_t		lblkno;
  	int			blkcnt;
  	int			error = 0;
-	int			done = 0;
+	int			retval = 0;
 
  	trace_xfs_attr_rmtval_remove(args);
 
@@ -693,14 +693,10 @@ xfs_attr_rmtval_remove(
  	 */
  	lblkno = args->rmtblkno;
  	blkcnt = args->rmtblkcnt;
-	while (!done) {
-		error = xfs_bunmapi(args->trans, args->dp, lblkno, blkcnt,
-				    XFS_BMAPI_ATTRFORK, 1, &done);
-		if (error)
-			return error;
-		error = xfs_defer_finish(&args->trans);
-		if (error)
-			return error;
+	do {
+		retval = __xfs_attr_rmtval_remove(args);
+		if (retval && retval != EAGAIN)
+			return retval;
 
  		/*
  		 * Close out trans and start the next one in the chain.
@@ -708,6 +704,36 @@ xfs_attr_rmtval_remove(
  		error = xfs_trans_roll_inode(&args->trans, args->dp);
  		if (error)
  			return error;

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

Quoted 10 lines
fs/xfs/libxfs/xfs_attr_remote.c +7 -1
-	}
+	} while (retval == -EAGAIN);
+
  	return 0;
  }
+
+/*
+ * Remove the value associated with an attribute by deleting the out-of-line
+ * buffer that it is stored on. Returns EAGAIN for the caller to refresh the
+ * transaction and recall the function

recall the function...?

Quoted 1 line

Oh. "re-call" the function.

Will fix

Quoted 6 lines

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

Quoted 4 lines
fs/xfs/libxfs/xfs_attr_remote.c +3 -0
+ */
+int
+__xfs_attr_rmtval_remove(

xfs_attr_rmtval_remove_extent() ?

Well, this would be the third rename for this function though. Initially I think we named it xfs_attr_rmtval_unmap, and then later we changed it to __xfs_attr_rmtval_remove. Ultimatly, it really doesn't matter what the name is, because it's going to get renamed at the end of the set anyway. Eventually it replaces the calling function and becomes xfs_attr_rmtval_remove.

So the name it gets here is just sort of a transient name, and it doesnt effect much in the greater scheme of things. If people really feel strongly about it though, it wont hurt much to change it again. I do try to point out the history of it though to avoid too much churn. :-)

Allison

Quoted 37 lines

--D

Quoted 34 lines
fs/xfs/libxfs/xfs_attr_remote.c +21 -0
+	struct xfs_da_args	*args)
+{
+	int			error, done;
+
+	/*
+	 * Unmap value blocks for this attr.
+	 */
+	error = xfs_bunmapi(args->trans, args->dp, args->rmtblkno,
+			    args->rmtblkcnt, XFS_BMAPI_ATTRFORK, 1, &done);
+	if (error)
+		return error;
+
+	error = xfs_defer_finish(&args->trans);
+	if (error)
+		return error;
+
+	if (!done)
+		return -EAGAIN;
+
+	return error;
+}
fs/xfs/libxfs/xfs_attr_remote.h +1 -0
index eff5f95..ee3337b 100644
@@ -14,4 +14,5 @@ int xfs_attr_rmtval_remove(struct xfs_da_args *args);
  int xfs_attr_rmtval_stale(struct xfs_inode *ip, struct xfs_bmbt_irec *map,
  		xfs_buf_flags_t incore_flags);
  int xfs_attr_rmtval_invalidate(struct xfs_da_args *args);
+int __xfs_attr_rmtval_remove(struct xfs_da_args *args);
  #endif /* __XFS_ATTR_REMOTE_H__ */
Signature · 1 line
2.7.4
#19 lore raw

Re: [PATCH v9 10/24] xfs: Add helper function __xfs_attr_rmtval_remove

Quoted 82 lines · Allison Collins
Quoted 63 lines · Darrick J. Wong
Quoted 4 lines · Allison Collins

This function is similar to xfs_attr_rmtval_remove, but adapted to return EAGAIN for new transactions. We will use this later when we introduce delayed attributes. This function will eventually replace xfs_attr_rmtval_remove

Like Brian suggested, this changelog could probably just say that we're hoisting the loop body into a separate function so that delayed attrs can manage the transaction rolling.

Quoted 40 lines
---
  fs/xfs/libxfs/xfs_attr_remote.c | 46 ++++++++++++++++++++++++++++++++---------
  fs/xfs/libxfs/xfs_attr_remote.h |  1 +
  2 files changed, 37 insertions(+), 10 deletions(-)
fs/xfs/libxfs/xfs_attr_remote.c +5 -9
index 4d51969..02d1a44 100644
@@ -681,7 +681,7 @@ xfs_attr_rmtval_remove(
  	xfs_dablk_t		lblkno;
  	int			blkcnt;
  	int			error = 0;
-	int			done = 0;
+	int			retval = 0;
  	trace_xfs_attr_rmtval_remove(args);
@@ -693,14 +693,10 @@ xfs_attr_rmtval_remove(
  	 */
  	lblkno = args->rmtblkno;
  	blkcnt = args->rmtblkcnt;
-	while (!done) {
-		error = xfs_bunmapi(args->trans, args->dp, lblkno, blkcnt,
-				    XFS_BMAPI_ATTRFORK, 1, &done);
-		if (error)
-			return error;
-		error = xfs_defer_finish(&args->trans);
-		if (error)
-			return error;
+	do {
+		retval = __xfs_attr_rmtval_remove(args);
+		if (retval && retval != EAGAIN)
+			return retval;
  		/*
  		 * Close out trans and start the next one in the chain.
@@ -708,6 +704,36 @@ xfs_attr_rmtval_remove(
  		error = xfs_trans_roll_inode(&args->trans, args->dp);
  		if (error)
  			return error;

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

Quoted 10 lines
fs/xfs/libxfs/xfs_attr_remote.c +7 -1
-	}
+	} while (retval == -EAGAIN);
+
  	return 0;
  }
+
+/*
+ * Remove the value associated with an attribute by deleting the out-of-line
+ * buffer that it is stored on. Returns EAGAIN for the caller to refresh the
+ * transaction and recall the function

recall the function...?

Quoted 1 line

Oh. "re-call" the function.

Will fix

Quoted 6 lines

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

Quoted 4 lines
fs/xfs/libxfs/xfs_attr_remote.c +3 -0
+ */
+int
+__xfs_attr_rmtval_remove(

xfs_attr_rmtval_remove_extent() ?

Well, this would be the third rename for this function though. Initially I think we named it xfs_attr_rmtval_unmap, and then later we changed it to __xfs_attr_rmtval_remove. Ultimatly, it really doesn't matter what the name is, because it's going to get renamed at the end of the set anyway. Eventually it replaces the calling function and becomes xfs_attr_rmtval_remove.

Quoted 4 lines

So the name it gets here is just sort of a transient name, and it doesnt effect much in the greater scheme of things. If people really feel strongly about it though, it wont hurt much to change it again. I do try to point out the history of it though to avoid too much churn. :-)

Heh, ok. /I/ don't care that much. :)

--D

Quoted 39 lines

Allison

Quoted 37 lines

--D

Quoted 34 lines
fs/xfs/libxfs/xfs_attr_remote.c +21 -0
+	struct xfs_da_args	*args)
+{
+	int			error, done;
+
+	/*
+	 * Unmap value blocks for this attr.
+	 */
+	error = xfs_bunmapi(args->trans, args->dp, args->rmtblkno,
+			    args->rmtblkcnt, XFS_BMAPI_ATTRFORK, 1, &done);
+	if (error)
+		return error;
+
+	error = xfs_defer_finish(&args->trans);
+	if (error)
+		return error;
+
+	if (!done)
+		return -EAGAIN;
+
+	return error;
+}
fs/xfs/libxfs/xfs_attr_remote.h +1 -0
index eff5f95..ee3337b 100644
@@ -14,4 +14,5 @@ int xfs_attr_rmtval_remove(struct xfs_da_args *args);
  int xfs_attr_rmtval_stale(struct xfs_inode *ip, struct xfs_bmbt_irec *map,
  		xfs_buf_flags_t incore_flags);
  int xfs_attr_rmtval_invalidate(struct xfs_da_args *args);
+int __xfs_attr_rmtval_remove(struct xfs_da_args *args);
  #endif /* __XFS_ATTR_REMOTE_H__ */
Signature · 1 line
2.7.4
#20 lore raw

PATCH v9 11/24 xfs: Pull up xfs_attr_rmtval_invalidate

In reply to Allison Collins

This patch pulls xfs_attr_rmtval_invalidate out of xfs_attr_rmtval_remove and into the calling functions. Eventually __xfs_attr_rmtval_remove will replace xfs_attr_rmtval_remove when we introduce delayed attributes. These functions are exepcted to return -EAGAIN when they need a new transaction. Because the invalidate does not need a new transaction, we need to separate it from the rest of the function that does. This will enable __xfs_attr_rmtval_remove to smoothly replace xfs_attr_rmtval_remove later.

---
 fs/xfs/libxfs/xfs_attr.c        | 12 ++++++++++++
 fs/xfs/libxfs/xfs_attr_remote.c |  3 ---
 2 files changed, 12 insertions(+), 3 deletions(-)
fs/xfs/libxfs/xfs_attr.c +12 -0
index 0fc6436..4fdfab9 100644
@@ -669,6 +669,10 @@ xfs_attr_leaf_addname(
 		args->rmtblkcnt = args->rmtblkcnt2;
 		args->rmtvaluelen = args->rmtvaluelen2;
 		if (args->rmtblkno) {
+			error = xfs_attr_rmtval_invalidate(args);
+			if (error)
+				return error;
+
 			error = xfs_attr_rmtval_remove(args);
 			if (error)
 				return error;
@@ -1027,6 +1031,10 @@ xfs_attr_node_addname(
 		args->rmtblkcnt = args->rmtblkcnt2;
 		args->rmtvaluelen = args->rmtvaluelen2;
 		if (args->rmtblkno) {
+			error = xfs_attr_rmtval_invalidate(args);
+			if (error)
+				return error;
+
 			error = xfs_attr_rmtval_remove(args);
 			if (error)
 				return error;
@@ -1152,6 +1160,10 @@ xfs_attr_node_removename(
 		if (error)
 			goto out;
 
+		error = xfs_attr_rmtval_invalidate(args);
+		if (error)
+			return error;
+
 		error = xfs_attr_rmtval_remove(args);
 		if (error)
 			goto out;
fs/xfs/libxfs/xfs_attr_remote.c +0 -3
index 02d1a44..f770159 100644
@@ -685,9 +685,6 @@ xfs_attr_rmtval_remove(
 
 	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.
 	 */
Signature · 1 line
2.7.4
Reviewed-by on v9 11/24
#21 lore raw

Re: [PATCH v9 11/24] xfs: Pull up xfs_attr_rmtval_invalidate

Quoted 11 lines · Allison Collins

This patch pulls xfs_attr_rmtval_invalidate out of xfs_attr_rmtval_remove and into the calling functions. Eventually __xfs_attr_rmtval_remove will replace xfs_attr_rmtval_remove when we introduce delayed attributes. These functions are exepcted to return -EAGAIN when they need a new transaction. Because the invalidate does not need a new transaction, we need to separate it from the rest of the function that does. This will enable __xfs_attr_rmtval_remove to smoothly replace xfs_attr_rmtval_remove later.

---

Quoted 58 lines
 fs/xfs/libxfs/xfs_attr.c        | 12 ++++++++++++
 fs/xfs/libxfs/xfs_attr_remote.c |  3 ---
 2 files changed, 12 insertions(+), 3 deletions(-)
fs/xfs/libxfs/xfs_attr.c +12 -0
index 0fc6436..4fdfab9 100644
@@ -669,6 +669,10 @@ xfs_attr_leaf_addname(
 		args->rmtblkcnt = args->rmtblkcnt2;
 		args->rmtvaluelen = args->rmtvaluelen2;
 		if (args->rmtblkno) {
+			error = xfs_attr_rmtval_invalidate(args);
+			if (error)
+				return error;
+
 			error = xfs_attr_rmtval_remove(args);
 			if (error)
 				return error;
@@ -1027,6 +1031,10 @@ xfs_attr_node_addname(
 		args->rmtblkcnt = args->rmtblkcnt2;
 		args->rmtvaluelen = args->rmtvaluelen2;
 		if (args->rmtblkno) {
+			error = xfs_attr_rmtval_invalidate(args);
+			if (error)
+				return error;
+
 			error = xfs_attr_rmtval_remove(args);
 			if (error)
 				return error;
@@ -1152,6 +1160,10 @@ xfs_attr_node_removename(
 		if (error)
 			goto out;
 
+		error = xfs_attr_rmtval_invalidate(args);
+		if (error)
+			return error;
+
 		error = xfs_attr_rmtval_remove(args);
 		if (error)
 			goto out;
fs/xfs/libxfs/xfs_attr_remote.c +0 -3
index 02d1a44..f770159 100644
@@ -685,9 +685,6 @@ xfs_attr_rmtval_remove(
 
 	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.
 	 */
Signature · 1 line
2.7.4
#22 lore raw

Re: [PATCH v9 11/24] xfs: Pull up xfs_attr_rmtval_invalidate

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

This patch pulls xfs_attr_rmtval_invalidate out of xfs_attr_rmtval_remove and into the calling functions. Eventually __xfs_attr_rmtval_remove will replace xfs_attr_rmtval_remove when we introduce delayed attributes. These functions are exepcted to return -EAGAIN when they need a new transaction. Because the invalidate does not need a new transaction, we need to separate it from the rest of the function that does. This will enable __xfs_attr_rmtval_remove to smoothly replace xfs_attr_rmtval_remove later.

Quoted 4 lines
Quoted 2 lines

---

Ok, thank you!

Allison

Quoted 60 lines
Quoted 59 lines
  fs/xfs/libxfs/xfs_attr.c        | 12 ++++++++++++
  fs/xfs/libxfs/xfs_attr_remote.c |  3 ---
  2 files changed, 12 insertions(+), 3 deletions(-)
fs/xfs/libxfs/xfs_attr.c +12 -0
index 0fc6436..4fdfab9 100644
@@ -669,6 +669,10 @@ xfs_attr_leaf_addname(
  		args->rmtblkcnt = args->rmtblkcnt2;
  		args->rmtvaluelen = args->rmtvaluelen2;
  		if (args->rmtblkno) {
+			error = xfs_attr_rmtval_invalidate(args);
+			if (error)
+				return error;
+
  			error = xfs_attr_rmtval_remove(args);
  			if (error)
  				return error;
@@ -1027,6 +1031,10 @@ xfs_attr_node_addname(
  		args->rmtblkcnt = args->rmtblkcnt2;
  		args->rmtvaluelen = args->rmtvaluelen2;
  		if (args->rmtblkno) {
+			error = xfs_attr_rmtval_invalidate(args);
+			if (error)
+				return error;
+
  			error = xfs_attr_rmtval_remove(args);
  			if (error)
  				return error;
@@ -1152,6 +1160,10 @@ xfs_attr_node_removename(
  		if (error)
  			goto out;
 
+		error = xfs_attr_rmtval_invalidate(args);
+		if (error)
+			return error;
+
  		error = xfs_attr_rmtval_remove(args);
  		if (error)
  			goto out;
fs/xfs/libxfs/xfs_attr_remote.c +0 -3
index 02d1a44..f770159 100644
@@ -685,9 +685,6 @@ xfs_attr_rmtval_remove(
 
  	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.
  	 */
Signature · 1 line
2.7.4
Reviewed-by on v9 11/24
#23 lore raw

Re: [PATCH v9 11/24] xfs: Pull up xfs_attr_rmtval_invalidate

In reply to Allison Collins
Quoted 10 lines · Allison Collins

This patch pulls xfs_attr_rmtval_invalidate out of xfs_attr_rmtval_remove and into the calling functions. Eventually __xfs_attr_rmtval_remove will replace xfs_attr_rmtval_remove when we introduce delayed attributes. These functions are exepcted to return -EAGAIN when they need a new transaction. Because the invalidate does not need a new transaction, we need to separate it from the rest of the function that does. This will enable __xfs_attr_rmtval_remove to smoothly replace xfs_attr_rmtval_remove later.

Looks good to me,

--D

Quoted 59 lines
---
 fs/xfs/libxfs/xfs_attr.c        | 12 ++++++++++++
 fs/xfs/libxfs/xfs_attr_remote.c |  3 ---
 2 files changed, 12 insertions(+), 3 deletions(-)
fs/xfs/libxfs/xfs_attr.c +12 -0
index 0fc6436..4fdfab9 100644
@@ -669,6 +669,10 @@ xfs_attr_leaf_addname(
 		args->rmtblkcnt = args->rmtblkcnt2;
 		args->rmtvaluelen = args->rmtvaluelen2;
 		if (args->rmtblkno) {
+			error = xfs_attr_rmtval_invalidate(args);
+			if (error)
+				return error;
+
 			error = xfs_attr_rmtval_remove(args);
 			if (error)
 				return error;
@@ -1027,6 +1031,10 @@ xfs_attr_node_addname(
 		args->rmtblkcnt = args->rmtblkcnt2;
 		args->rmtvaluelen = args->rmtvaluelen2;
 		if (args->rmtblkno) {
+			error = xfs_attr_rmtval_invalidate(args);
+			if (error)
+				return error;
+
 			error = xfs_attr_rmtval_remove(args);
 			if (error)
 				return error;
@@ -1152,6 +1160,10 @@ xfs_attr_node_removename(
 		if (error)
 			goto out;
 
+		error = xfs_attr_rmtval_invalidate(args);
+		if (error)
+			return error;
+
 		error = xfs_attr_rmtval_remove(args);
 		if (error)
 			goto out;
fs/xfs/libxfs/xfs_attr_remote.c +0 -3
index 02d1a44..f770159 100644
@@ -685,9 +685,6 @@ xfs_attr_rmtval_remove(
 
 	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.
 	 */
Signature · 1 line
2.7.4
#24 lore raw

Re: [PATCH v9 11/24] xfs: Pull up xfs_attr_rmtval_invalidate

Quoted 10 lines · Darrick J. Wong
Quoted 9 lines · Allison Collins

This patch pulls xfs_attr_rmtval_invalidate out of xfs_attr_rmtval_remove and into the calling functions. Eventually __xfs_attr_rmtval_remove will replace xfs_attr_rmtval_remove when we introduce delayed attributes. These functions are exepcted to return -EAGAIN when they need a new transaction. Because the invalidate does not need a new transaction, we need to separate it from the rest of the function that does. This will enable __xfs_attr_rmtval_remove to smoothly replace xfs_attr_rmtval_remove later.

Quoted 4 lines
Quoted 1 line

Looks good to me,

Thank you!

Allison

Quoted 62 lines

--D

Quoted 59 lines
---
  fs/xfs/libxfs/xfs_attr.c        | 12 ++++++++++++
  fs/xfs/libxfs/xfs_attr_remote.c |  3 ---
  2 files changed, 12 insertions(+), 3 deletions(-)
fs/xfs/libxfs/xfs_attr.c +12 -0
index 0fc6436..4fdfab9 100644
@@ -669,6 +669,10 @@ xfs_attr_leaf_addname(
  		args->rmtblkcnt = args->rmtblkcnt2;
  		args->rmtvaluelen = args->rmtvaluelen2;
  		if (args->rmtblkno) {
+			error = xfs_attr_rmtval_invalidate(args);
+			if (error)
+				return error;
+
  			error = xfs_attr_rmtval_remove(args);
  			if (error)
  				return error;
@@ -1027,6 +1031,10 @@ xfs_attr_node_addname(
  		args->rmtblkcnt = args->rmtblkcnt2;
  		args->rmtvaluelen = args->rmtvaluelen2;
  		if (args->rmtblkno) {
+			error = xfs_attr_rmtval_invalidate(args);
+			if (error)
+				return error;
+
  			error = xfs_attr_rmtval_remove(args);
  			if (error)
  				return error;
@@ -1152,6 +1160,10 @@ xfs_attr_node_removename(
  		if (error)
  			goto out;
 
+		error = xfs_attr_rmtval_invalidate(args);
+		if (error)
+			return error;
+
  		error = xfs_attr_rmtval_remove(args);
  		if (error)
  			goto out;
fs/xfs/libxfs/xfs_attr_remote.c +0 -3
index 02d1a44..f770159 100644
@@ -685,9 +685,6 @@ xfs_attr_rmtval_remove(
 
  	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.
  	 */
Signature · 1 line
2.7.4
#25 lore raw

PATCH v9 12/24 xfs: Add helper function xfs_attr_node_shrink

In reply to Allison Collins

This patch adds a new helper function xfs_attr_node_shrink used to shrink an attr name into an inode if it is small enough. This helps to modularize the greater calling function xfs_attr_node_removename.

---
 fs/xfs/libxfs/xfs_attr.c | 68 ++++++++++++++++++++++++++++++------------------
 1 file changed, 42 insertions(+), 26 deletions(-)
fs/xfs/libxfs/xfs_attr.c +42 -26
index 4fdfab9..d83443c 100644
@@ -1108,6 +1108,45 @@ xfs_attr_node_addname(
 }
 
 /*
+ * Shrink an attribute from leaf to shortform
+ */
+STATIC int
+xfs_attr_node_shrink(
+	struct xfs_da_args	*args,
+	struct xfs_da_state     *state)
+{
+	struct xfs_inode	*dp = args->dp;
+	int			error, forkoff;
+	struct xfs_buf		*bp;
+
+	/*
+	 * 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, &bp);
+	if (error)
+		return error;
+
+	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)
+			return error;
+
+		error = xfs_defer_finish(&args->trans);
+		if (error)
+			return error;
+	} else
+		xfs_trans_brelse(args->trans, bp);
+
+	return 0;
+}
+
+/*
  * Remove a name from a B-tree attribute list.
  *
  * This will involve walking down the Btree, and may involve joining
@@ -1120,8 +1159,7 @@ xfs_attr_node_removename(
 {
 	struct xfs_da_state	*state;
 	struct xfs_da_state_blk	*blk;
-	struct xfs_buf		*bp;
-	int			retval, error, forkoff;
+	int			retval, error;
 	struct xfs_inode	*dp = args->dp;
 
 	trace_xfs_attr_node_removename(args);
@@ -1206,30 +1244,8 @@ xfs_attr_node_removename(
 	/*
 	 * 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, &bp);
-		if (error)
-			goto out;
-
-		if ((forkoff = xfs_attr_shortform_allfit(bp, dp))) {
-			error = xfs_attr3_leaf_to_shortform(bp, args, forkoff);
-			/* bp is gone due to xfs_da_shrink_inode */
-			if (error)
-				goto out;
-			error = xfs_defer_finish(&args->trans);
-			if (error)
-				goto out;
-		} else
-			xfs_trans_brelse(args->trans, bp);
-	}
-	error = 0;
+	if (xfs_bmap_one_block(dp, XFS_ATTR_FORK))
+		error = xfs_attr_node_shrink(args, state);
 
 out:
 	if (state)
Signature · 1 line
2.7.4
Reviewed-by on v9 12/24
#26 lore raw

Re: [PATCH v9 12/24] xfs: Add helper function xfs_attr_node_shrink

Quoted 6 lines · Allison Collins

This patch adds a new helper function xfs_attr_node_shrink used to shrink an attr name into an inode if it is small enough. This helps to modularize the greater calling function xfs_attr_node_removename.

---

Quoted 99 lines
 fs/xfs/libxfs/xfs_attr.c | 68 ++++++++++++++++++++++++++++++------------------
 1 file changed, 42 insertions(+), 26 deletions(-)
fs/xfs/libxfs/xfs_attr.c +42 -26
index 4fdfab9..d83443c 100644
@@ -1108,6 +1108,45 @@ xfs_attr_node_addname(
 }
 
 /*
+ * Shrink an attribute from leaf to shortform
+ */
+STATIC int
+xfs_attr_node_shrink(
+	struct xfs_da_args	*args,
+	struct xfs_da_state     *state)
+{
+	struct xfs_inode	*dp = args->dp;
+	int			error, forkoff;
+	struct xfs_buf		*bp;
+
+	/*
+	 * 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, &bp);
+	if (error)
+		return error;
+
+	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)
+			return error;
+
+		error = xfs_defer_finish(&args->trans);
+		if (error)
+			return error;
+	} else
+		xfs_trans_brelse(args->trans, bp);
+
+	return 0;
+}
+
+/*
  * Remove a name from a B-tree attribute list.
  *
  * This will involve walking down the Btree, and may involve joining
@@ -1120,8 +1159,7 @@ xfs_attr_node_removename(
 {
 	struct xfs_da_state	*state;
 	struct xfs_da_state_blk	*blk;
-	struct xfs_buf		*bp;
-	int			retval, error, forkoff;
+	int			retval, error;
 	struct xfs_inode	*dp = args->dp;
 
 	trace_xfs_attr_node_removename(args);
@@ -1206,30 +1244,8 @@ xfs_attr_node_removename(
 	/*
 	 * 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, &bp);
-		if (error)
-			goto out;
-
-		if ((forkoff = xfs_attr_shortform_allfit(bp, dp))) {
-			error = xfs_attr3_leaf_to_shortform(bp, args, forkoff);
-			/* bp is gone due to xfs_da_shrink_inode */
-			if (error)
-				goto out;
-			error = xfs_defer_finish(&args->trans);
-			if (error)
-				goto out;
-		} else
-			xfs_trans_brelse(args->trans, bp);
-	}
-	error = 0;
+	if (xfs_bmap_one_block(dp, XFS_ATTR_FORK))
+		error = xfs_attr_node_shrink(args, state);
 
 out:
 	if (state)
Signature · 1 line
2.7.4
#27 lore raw

Re: [PATCH v9 12/24] xfs: Add helper function xfs_attr_node_shrink

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

This patch adds a new helper function xfs_attr_node_shrink used to shrink an attr name into an inode if it is small enough. This helps to modularize the greater calling function xfs_attr_node_removename.

---

Great! Thanks!

Allison

Quoted 101 lines
Quoted 100 lines
  fs/xfs/libxfs/xfs_attr.c | 68 ++++++++++++++++++++++++++++++------------------
  1 file changed, 42 insertions(+), 26 deletions(-)
fs/xfs/libxfs/xfs_attr.c +42 -26
index 4fdfab9..d83443c 100644
@@ -1108,6 +1108,45 @@ xfs_attr_node_addname(
  }
 
  /*
+ * Shrink an attribute from leaf to shortform
+ */
+STATIC int
+xfs_attr_node_shrink(
+	struct xfs_da_args	*args,
+	struct xfs_da_state     *state)
+{
+	struct xfs_inode	*dp = args->dp;
+	int			error, forkoff;
+	struct xfs_buf		*bp;
+
+	/*
+	 * 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, &bp);
+	if (error)
+		return error;
+
+	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)
+			return error;
+
+		error = xfs_defer_finish(&args->trans);
+		if (error)
+			return error;
+	} else
+		xfs_trans_brelse(args->trans, bp);
+
+	return 0;
+}
+
+/*
   * Remove a name from a B-tree attribute list.
   *
   * This will involve walking down the Btree, and may involve joining
@@ -1120,8 +1159,7 @@ xfs_attr_node_removename(
  {
  	struct xfs_da_state	*state;
  	struct xfs_da_state_blk	*blk;
-	struct xfs_buf		*bp;
-	int			retval, error, forkoff;
+	int			retval, error;
  	struct xfs_inode	*dp = args->dp;
 
  	trace_xfs_attr_node_removename(args);
@@ -1206,30 +1244,8 @@ xfs_attr_node_removename(
  	/*
  	 * 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, &bp);
-		if (error)
-			goto out;
-
-		if ((forkoff = xfs_attr_shortform_allfit(bp, dp))) {
-			error = xfs_attr3_leaf_to_shortform(bp, args, forkoff);
-			/* bp is gone due to xfs_da_shrink_inode */
-			if (error)
-				goto out;
-			error = xfs_defer_finish(&args->trans);
-			if (error)
-				goto out;
-		} else
-			xfs_trans_brelse(args->trans, bp);
-	}
-	error = 0;
+	if (xfs_bmap_one_block(dp, XFS_ATTR_FORK))
+		error = xfs_attr_node_shrink(args, state);
 
  out:
  	if (state)
Signature · 1 line
2.7.4
Reviewed-by on v9 12/24
#28 lore raw

Re: [PATCH v9 12/24] xfs: Add helper function xfs_attr_node_shrink

In reply to Allison Collins
Quoted 5 lines · Allison Collins

This patch adds a new helper function xfs_attr_node_shrink used to shrink an attr name into an inode if it is small enough. This helps to modularize the greater calling function xfs_attr_node_removename.

Simple enough looking hoist;

--D

Quoted 100 lines
---
 fs/xfs/libxfs/xfs_attr.c | 68 ++++++++++++++++++++++++++++++------------------
 1 file changed, 42 insertions(+), 26 deletions(-)
fs/xfs/libxfs/xfs_attr.c +42 -26
index 4fdfab9..d83443c 100644
@@ -1108,6 +1108,45 @@ xfs_attr_node_addname(
 }
 
 /*
+ * Shrink an attribute from leaf to shortform
+ */
+STATIC int
+xfs_attr_node_shrink(
+	struct xfs_da_args	*args,
+	struct xfs_da_state     *state)
+{
+	struct xfs_inode	*dp = args->dp;
+	int			error, forkoff;
+	struct xfs_buf		*bp;
+
+	/*
+	 * 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, &bp);
+	if (error)
+		return error;
+
+	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)
+			return error;
+
+		error = xfs_defer_finish(&args->trans);
+		if (error)
+			return error;
+	} else
+		xfs_trans_brelse(args->trans, bp);
+
+	return 0;
+}
+
+/*
  * Remove a name from a B-tree attribute list.
  *
  * This will involve walking down the Btree, and may involve joining
@@ -1120,8 +1159,7 @@ xfs_attr_node_removename(
 {
 	struct xfs_da_state	*state;
 	struct xfs_da_state_blk	*blk;
-	struct xfs_buf		*bp;
-	int			retval, error, forkoff;
+	int			retval, error;
 	struct xfs_inode	*dp = args->dp;
 
 	trace_xfs_attr_node_removename(args);
@@ -1206,30 +1244,8 @@ xfs_attr_node_removename(
 	/*
 	 * 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, &bp);
-		if (error)
-			goto out;
-
-		if ((forkoff = xfs_attr_shortform_allfit(bp, dp))) {
-			error = xfs_attr3_leaf_to_shortform(bp, args, forkoff);
-			/* bp is gone due to xfs_da_shrink_inode */
-			if (error)
-				goto out;
-			error = xfs_defer_finish(&args->trans);
-			if (error)
-				goto out;
-		} else
-			xfs_trans_brelse(args->trans, bp);
-	}
-	error = 0;
+	if (xfs_bmap_one_block(dp, XFS_ATTR_FORK))
+		error = xfs_attr_node_shrink(args, state);
 
 out:
 	if (state)
Signature · 1 line
2.7.4
#29 lore raw

Re: [PATCH v9 12/24] xfs: Add helper function xfs_attr_node_shrink

Quoted 9 lines · Darrick J. Wong
Quoted 5 lines · Allison Collins

This patch adds a new helper function xfs_attr_node_shrink used to shrink an attr name into an inode if it is small enough. This helps to modularize the greater calling function xfs_attr_node_removename.

Simple enough looking hoist;

Great, thanks!

Allison

Quoted 103 lines

--D

Quoted 100 lines
---
  fs/xfs/libxfs/xfs_attr.c | 68 ++++++++++++++++++++++++++++++------------------
  1 file changed, 42 insertions(+), 26 deletions(-)
fs/xfs/libxfs/xfs_attr.c +42 -26
index 4fdfab9..d83443c 100644
@@ -1108,6 +1108,45 @@ xfs_attr_node_addname(
  }
 
  /*
+ * Shrink an attribute from leaf to shortform
+ */
+STATIC int
+xfs_attr_node_shrink(
+	struct xfs_da_args	*args,
+	struct xfs_da_state     *state)
+{
+	struct xfs_inode	*dp = args->dp;
+	int			error, forkoff;
+	struct xfs_buf		*bp;
+
+	/*
+	 * 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, &bp);
+	if (error)
+		return error;
+
+	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)
+			return error;
+
+		error = xfs_defer_finish(&args->trans);
+		if (error)
+			return error;
+	} else
+		xfs_trans_brelse(args->trans, bp);
+
+	return 0;
+}
+
+/*
   * Remove a name from a B-tree attribute list.
   *
   * This will involve walking down the Btree, and may involve joining
@@ -1120,8 +1159,7 @@ xfs_attr_node_removename(
  {
  	struct xfs_da_state	*state;
  	struct xfs_da_state_blk	*blk;
-	struct xfs_buf		*bp;
-	int			retval, error, forkoff;
+	int			retval, error;
  	struct xfs_inode	*dp = args->dp;
 
  	trace_xfs_attr_node_removename(args);
@@ -1206,30 +1244,8 @@ xfs_attr_node_removename(
  	/*
  	 * 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, &bp);
-		if (error)
-			goto out;
-
-		if ((forkoff = xfs_attr_shortform_allfit(bp, dp))) {
-			error = xfs_attr3_leaf_to_shortform(bp, args, forkoff);
-			/* bp is gone due to xfs_da_shrink_inode */
-			if (error)
-				goto out;
-			error = xfs_defer_finish(&args->trans);
-			if (error)
-				goto out;
-		} else
-			xfs_trans_brelse(args->trans, bp);
-	}
-	error = 0;
+	if (xfs_bmap_one_block(dp, XFS_ATTR_FORK))
+		error = xfs_attr_node_shrink(args, state);
 
  out:
  	if (state)
Signature · 1 line
2.7.4
#30 lore raw

PATCH v9 13/24 xfs: Remove unneeded xfs_trans_roll_inode calls

In reply to Allison Collins

Some calls to xfs_trans_roll_inode and xfs_defer_finish routines are not needed. If they are the last operations executed in these functions, and no further changes are made, then higher level routines will roll or commit the tranactions. The xfs_trans_roll in _removename is also not needed because invalidating blocks is an incore-only change.

---
 fs/xfs/libxfs/xfs_attr.c | 40 ----------------------------------------
 1 file changed, 40 deletions(-)
fs/xfs/libxfs/xfs_attr.c +0 -40
index d83443c..af47566 100644
@@ -697,16 +697,8 @@ xfs_attr_leaf_addname(
 			/* bp is gone due to xfs_da_shrink_inode */
 			if (error)
 				return error;
-			error = xfs_defer_finish(&args->trans);
-			if (error)
-				return error;
 		}
 
-		/*
-		 * Commit the remove and start the next trans in series.
-		 */
-		error = xfs_trans_roll_inode(&args->trans, dp);
-
 	} else if (args->rmtblkno > 0) {
 		/*
 		 * Added a "remote" value, just clear the incomplete flag.
@@ -714,12 +706,6 @@ xfs_attr_leaf_addname(
 		error = xfs_attr3_leaf_clearflag(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);
 	}
 	return error;
 }
@@ -784,9 +770,6 @@ xfs_attr_leaf_removename(
 		/* bp is gone due to xfs_da_shrink_inode */
 		if (error)
 			return error;
-		error = xfs_defer_finish(&args->trans);
-		if (error)
-			return error;
 	}
 	return 0;
 }
@@ -1074,13 +1057,6 @@ xfs_attr_node_addname(
 				goto out;
 		}
 
-		/*
-		 * Commit and start the next trans in the chain.
-		 */
-		error = xfs_trans_roll_inode(&args->trans, dp);
-		if (error)
-			goto out;
-
 	} else if (args->rmtblkno > 0) {
 		/*
 		 * Added a "remote" value, just clear the incomplete flag.
@@ -1088,14 +1064,6 @@ 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;
 
@@ -1136,10 +1104,6 @@ xfs_attr_node_shrink(
 		/* bp is gone due to xfs_da_shrink_inode */
 		if (error)
 			return error;
-
-		error = xfs_defer_finish(&args->trans);
-		if (error)
-			return error;
 	} else
 		xfs_trans_brelse(args->trans, bp);
 
@@ -1194,10 +1158,6 @@ xfs_attr_node_removename(
 		if (error)
 			goto out;
 
-		error = xfs_trans_roll_inode(&args->trans, args->dp);
-		if (error)
-			goto out;
-
 		error = xfs_attr_rmtval_invalidate(args);
 		if (error)
 			return error;
Signature · 1 line
2.7.4
#31 lore raw

Re: [PATCH v9 13/24] xfs: Remove unneeded xfs_trans_roll_inode calls

Quoted 15 lines · Allison Collins

Some calls to xfs_trans_roll_inode and xfs_defer_finish routines are not needed. If they are the last operations executed in these functions, and no further changes are made, then higher level routines will roll or commit the tranactions. The xfs_trans_roll in _removename is also not needed because invalidating blocks is an incore-only change.

---
 fs/xfs/libxfs/xfs_attr.c | 40 ----------------------------------------
 1 file changed, 40 deletions(-)
fs/xfs/libxfs/xfs_attr.c +0 -0
index d83443c..af47566 100644

...

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

Quoted 9 lines
fs/xfs/libxfs/xfs_attr.c +0 -3
@@ -784,9 +770,6 @@ xfs_attr_leaf_removename(
 		/* bp is gone due to xfs_da_shrink_inode */
 		if (error)
 			return error;
-		error = xfs_defer_finish(&args->trans);
-		if (error)
-			return error;
 	}
 	return 0;

Looks like this could be simplified to return error at the end of the function. Some of the others might have similar simplifications available.

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

Quoted 12 lines
fs/xfs/libxfs/xfs_attr.c +0 -7
 }
@@ -1074,13 +1057,6 @@ xfs_attr_node_addname(
 				goto out;
 		}
 
-		/*
-		 * Commit and start the next trans in the chain.
-		 */
-		error = xfs_trans_roll_inode(&args->trans, dp);
-		if (error)
-			goto out;
-

There's an xfs_defer_finish() before this roll. Is that not also extraneous? It looks like we return straight up to xfs_attr_set() (trans commit) from here..

Quoted 3 lines
fs/xfs/libxfs/xfs_attr.c +0 -0
 	} else if (args->rmtblkno > 0) {
 		/*
 		 * Added a "remote" value, just clear the incomplete flag.

...

fs/xfs/libxfs/xfs_attr.c xfs_attr_node_removename( · line 1200

Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c +0 -4
@@ -1194,10 +1158,6 @@ xfs_attr_node_removename(
 		if (error)
 			goto out;
 
-		error = xfs_trans_roll_inode(&args->trans, args->dp);
-		if (error)
-			goto out;
-

I'm still a bit on the fence about this one. At first glance it looks like it's not necessary, but technically we're changing behavior by combining setting the inactive flag and the first remote block unmap, right? If so, that seems fairly reasonable, but it's hard to say for sure with the state of the xattr transaction reservations...

Looking around some more, I suppose this could be analogous to the !remote remove case where an entry is removed and a potential dabtree join occurs under the same transaction. If that's the best argument we have, however, I might suggest to split this one out into an independent patch and let the commit log describe what's going on in more detail. That way it's more obvious to reviewers and if it's wrong it's easier to revert.

Brian

Quoted 6 lines
fs/xfs/libxfs/xfs_attr.c +0 -0
 		error = xfs_attr_rmtval_invalidate(args);
 		if (error)
 			return error;
Signature · 1 line
2.7.4
#32 lore raw

Re: [PATCH v9 13/24] xfs: Remove unneeded xfs_trans_roll_inode calls

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

Some calls to xfs_trans_roll_inode and xfs_defer_finish routines are not needed. If they are the last operations executed in these functions, and no further changes are made, then higher level routines will roll or commit the tranactions. The xfs_trans_roll in _removename is also not needed because invalidating blocks is an incore-only change.

---
  fs/xfs/libxfs/xfs_attr.c | 40 ----------------------------------------
  1 file changed, 40 deletions(-)
fs/xfs/libxfs/xfs_attr.c +0 -0
index d83443c..af47566 100644

...

Quoted 13 lines

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

Quoted 9 lines
fs/xfs/libxfs/xfs_attr.c +0 -3
@@ -784,9 +770,6 @@ xfs_attr_leaf_removename(
  		/* bp is gone due to xfs_da_shrink_inode */
  		if (error)
  			return error;
-		error = xfs_defer_finish(&args->trans);
-		if (error)
-			return error;
  	}
  	return 0;

Looks like this could be simplified to return error at the end of the function. Some of the others might have similar simplifications available.

Sure, will do

Quoted 6 lines
Quoted 6 lines
fs/xfs/libxfs/xfs_attr.c +0 -0
  }
@@ -1074,13 +1057,6 @@ xfs_attr_node_addname(
  				goto out;
  		}
 
Quoted 11 lines

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

Quoted 7 lines
fs/xfs/libxfs/xfs_attr.c +0 -7
-		/*
-		 * Commit and start the next trans in the chain.
-		 */
-		error = xfs_trans_roll_inode(&args->trans, dp);
-		if (error)
-			goto out;
-

There's an xfs_defer_finish() before this roll. Is that not also extraneous? It looks like we return straight up to xfs_attr_set() (trans commit) from here..

Ok, I see it. Yes I think so, I will see if I can take it out

Quoted 9 lines
Quoted 4 lines
fs/xfs/libxfs/xfs_attr.c +0 -0
  	} else if (args->rmtblkno > 0) {
  		/*
  		 * Added a "remote" value, just clear the incomplete flag.

...

Quoted 4 lines
fs/xfs/libxfs/xfs_attr.c +0 -0
@@ -1194,10 +1158,6 @@ xfs_attr_node_removename(
  		if (error)
  			goto out;
 
Quoted 11 lines

fs/xfs/libxfs/xfs_attr.c xfs_attr_node_removename( · line 1200

Quoted 4 lines
fs/xfs/libxfs/xfs_attr.c +0 -4
-		error = xfs_trans_roll_inode(&args->trans, args->dp);
-		if (error)
-			goto out;
-

I'm still a bit on the fence about this one. At first glance it looks like it's not necessary, but technically we're changing behavior by combining setting the inactive flag and the first remote block unmap, right? If so, that seems fairly reasonable, but it's hard to say for sure with the state of the xattr transaction reservations...

As I recall, I had initially not removed this roll in v5, and I had an extra XFS_DAS_RM_INVALIDATE state to roll the transaction here. And then I think we reasoned that because invalidating blocks didnt have in core changes, we could just remove it, thus getting rid of the extra state. Later I split it out into this separate patch along with a few other transaction rolls that we identified as not being necessary.

link just for reference...
https://patchwork.kernel.org/patch/11287029/

Quoted 7 lines

Looking around some more, I suppose this could be analogous to the !remote remove case where an entry is removed and a potential dabtree join occurs under the same transaction. If that's the best argument we have, however, I might suggest to split this one out into an independent patch and let the commit log describe what's going on in more detail. That way it's more obvious to reviewers and if it's wrong it's easier to revert.

I'm not sure that was the argument at the time, but I think it makes sense. :-) Will split off into separate patch.

Thanks for the reviews!

Allison

Quoted 13 lines

Brian

Quoted 6 lines
fs/xfs/libxfs/xfs_attr.c +0 -0
  		error = xfs_attr_rmtval_invalidate(args);
  		if (error)
  			return error;
Signature · 1 line
2.7.4
#33 lore raw

PATCH v9 14/24 xfs: Add helpers xfs_attr_is_shortform and xfs_attr_set_shortform

In reply to Allison Collins

In this patch, we hoist code from xfs_attr_set_args into two new helpers xfs_attr_is_shortform and xfs_attr_set_shortform. These two will help to simplify xfs_attr_set_args when we get into delayed attrs later.

---
 fs/xfs/libxfs/xfs_attr.c | 107 +++++++++++++++++++++++++++++++----------------
 1 file changed, 72 insertions(+), 35 deletions(-)
fs/xfs/libxfs/xfs_attr.c +72 -35
index af47566..d112910 100644
@@ -204,6 +204,66 @@ xfs_attr_try_sf_addname(
 }
 
 /*
+ * Check to see if the attr should be upgraded from non-existent or shortform to
+ * single-leaf-block attribute list.
+ */
+static inline bool
+xfs_attr_is_shortform(
+	struct xfs_inode    *ip)
+{
+	return ip->i_d.di_aformat == XFS_DINODE_FMT_LOCAL ||
+	       (ip->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS &&
+	        ip->i_d.di_anextents == 0);
+}
+
+/*
+ * Attempts to set an attr in shortform, or converts short form to leaf form if
+ * there is not enough room.  If the attr is set, the transaction is committed
+ * and set to NULL.
+ */
+STATIC int
+xfs_attr_set_shortform(
+	struct xfs_da_args	*args,
+	struct xfs_buf		**leaf_bp)
+{
+	struct xfs_inode	*dp = args->dp;
+	int			error, error2 = 0;
+
+	/*
+	 * Try to add the attr to the attribute list in the inode.
+	 */
+	error = xfs_attr_try_sf_addname(dp, args);
+	if (error != -ENOSPC) {
+		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.  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. Once we're done rolling the transaction we
+	 * can release the hold and add the attr to the leaf.
+	 */
+	xfs_trans_bhold(args->trans, *leaf_bp);
+	error = xfs_defer_finish(&args->trans);
+	xfs_trans_bhold_release(args->trans, *leaf_bp);
+	if (error) {
+		xfs_trans_brelse(args->trans, *leaf_bp);
+		return error;
+	}
+
+	return 0;
+}
+
+/*
  * Set the attribute specified in @args.
  */
 int
@@ -212,48 +272,25 @@ xfs_attr_set_args(
 {
 	struct xfs_inode	*dp = args->dp;
 	struct xfs_buf          *leaf_bp = NULL;
-	int			error, error2 = 0;
+	int			error = 0;
 
 	/*
-	 * If the attribute list is non-existent or a shortform list,
-	 * upgrade it to a single-leaf-block attribute list.
+	 * If the attribute list is already in leaf format, jump straight to
+	 * leaf handling.  Otherwise, try to add the attribute to the shortform
+	 * list; if there's no room then convert the list to leaf format and try
+	 * again.
 	 */
-	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)) {
+	if (xfs_attr_is_shortform(dp)) {
 
 		/*
-		 * Try to add the attr to the attribute list in the inode.
+		 * If the attr was successfully set in shortform, the
+		 * transaction is committed and set to NULL.  Otherwise, is it
+		 * converted from shortform to leaf, and the transaction is
+		 * retained.
 		 */
-		error = xfs_attr_try_sf_addname(dp, args);
-		if (error != -ENOSPC) {
-			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.
-		 * 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.
-		 * Once we're done rolling the transaction we can release
-		 * the hold and add the attr to the leaf.
-		 */
-		xfs_trans_bhold(args->trans, leaf_bp);
-		error = xfs_defer_finish(&args->trans);
-		xfs_trans_bhold_release(args->trans, leaf_bp);
-		if (error) {
-			xfs_trans_brelse(args->trans, leaf_bp);
+		error = xfs_attr_set_shortform(args, &leaf_bp);
+		if (error || !args->trans)
 			return error;
-		}
 	}
 
 	if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
Signature · 1 line
2.7.4
Reviewed-by on v9 14/24
#34 lore raw

Re: [PATCH v9 14/24] xfs: Add helpers xfs_attr_is_shortform and xfs_attr_set_shortform

Quoted 7 lines · Allison Collins

In this patch, we hoist code from xfs_attr_set_args into two new helpers xfs_attr_is_shortform and xfs_attr_set_shortform. These two will help to simplify xfs_attr_set_args when we get into delayed attrs later.

Looks ok to me,

--D

Quoted 139 lines
---
 fs/xfs/libxfs/xfs_attr.c | 107 +++++++++++++++++++++++++++++++----------------
 1 file changed, 72 insertions(+), 35 deletions(-)
fs/xfs/libxfs/xfs_attr.c +72 -35
index af47566..d112910 100644
@@ -204,6 +204,66 @@ xfs_attr_try_sf_addname(
 }
 
 /*
+ * Check to see if the attr should be upgraded from non-existent or shortform to
+ * single-leaf-block attribute list.
+ */
+static inline bool
+xfs_attr_is_shortform(
+	struct xfs_inode    *ip)
+{
+	return ip->i_d.di_aformat == XFS_DINODE_FMT_LOCAL ||
+	       (ip->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS &&
+	        ip->i_d.di_anextents == 0);
+}
+
+/*
+ * Attempts to set an attr in shortform, or converts short form to leaf form if
+ * there is not enough room.  If the attr is set, the transaction is committed
+ * and set to NULL.
+ */
+STATIC int
+xfs_attr_set_shortform(
+	struct xfs_da_args	*args,
+	struct xfs_buf		**leaf_bp)
+{
+	struct xfs_inode	*dp = args->dp;
+	int			error, error2 = 0;
+
+	/*
+	 * Try to add the attr to the attribute list in the inode.
+	 */
+	error = xfs_attr_try_sf_addname(dp, args);
+	if (error != -ENOSPC) {
+		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.  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. Once we're done rolling the transaction we
+	 * can release the hold and add the attr to the leaf.
+	 */
+	xfs_trans_bhold(args->trans, *leaf_bp);
+	error = xfs_defer_finish(&args->trans);
+	xfs_trans_bhold_release(args->trans, *leaf_bp);
+	if (error) {
+		xfs_trans_brelse(args->trans, *leaf_bp);
+		return error;
+	}
+
+	return 0;
+}
+
+/*
  * Set the attribute specified in @args.
  */
 int
@@ -212,48 +272,25 @@ xfs_attr_set_args(
 {
 	struct xfs_inode	*dp = args->dp;
 	struct xfs_buf          *leaf_bp = NULL;
-	int			error, error2 = 0;
+	int			error = 0;
 
 	/*
-	 * If the attribute list is non-existent or a shortform list,
-	 * upgrade it to a single-leaf-block attribute list.
+	 * If the attribute list is already in leaf format, jump straight to
+	 * leaf handling.  Otherwise, try to add the attribute to the shortform
+	 * list; if there's no room then convert the list to leaf format and try
+	 * again.
 	 */
-	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)) {
+	if (xfs_attr_is_shortform(dp)) {
 
 		/*
-		 * Try to add the attr to the attribute list in the inode.
+		 * If the attr was successfully set in shortform, the
+		 * transaction is committed and set to NULL.  Otherwise, is it
+		 * converted from shortform to leaf, and the transaction is
+		 * retained.
 		 */
-		error = xfs_attr_try_sf_addname(dp, args);
-		if (error != -ENOSPC) {
-			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.
-		 * 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.
-		 * Once we're done rolling the transaction we can release
-		 * the hold and add the attr to the leaf.
-		 */
-		xfs_trans_bhold(args->trans, leaf_bp);
-		error = xfs_defer_finish(&args->trans);
-		xfs_trans_bhold_release(args->trans, leaf_bp);
-		if (error) {
-			xfs_trans_brelse(args->trans, leaf_bp);
+		error = xfs_attr_set_shortform(args, &leaf_bp);
+		if (error || !args->trans)
 			return error;
-		}
 	}
 
 	if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
Signature · 1 line
2.7.4
#35 lore raw

Re: [PATCH v9 14/24] xfs: Add helpers xfs_attr_is_shortform and xfs_attr_set_shortform

Quoted 5 lines · Darrick J. Wong
Quoted 4 lines · Allison Collins

In this patch, we hoist code from xfs_attr_set_args into two new helpers xfs_attr_is_shortform and xfs_attr_set_shortform. These two will help to simplify xfs_attr_set_args when we get into delayed attrs later.

Quoted 7 lines
Quoted 3 lines

Looks ok to me,

Thank yoU!

Allison

Quoted 141 lines

--D

Quoted 139 lines
---
  fs/xfs/libxfs/xfs_attr.c | 107 +++++++++++++++++++++++++++++++----------------
  1 file changed, 72 insertions(+), 35 deletions(-)
fs/xfs/libxfs/xfs_attr.c +72 -35
index af47566..d112910 100644
@@ -204,6 +204,66 @@ xfs_attr_try_sf_addname(
  }
 
  /*
+ * Check to see if the attr should be upgraded from non-existent or shortform to
+ * single-leaf-block attribute list.
+ */
+static inline bool
+xfs_attr_is_shortform(
+	struct xfs_inode    *ip)
+{
+	return ip->i_d.di_aformat == XFS_DINODE_FMT_LOCAL ||
+	       (ip->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS &&
+	        ip->i_d.di_anextents == 0);
+}
+
+/*
+ * Attempts to set an attr in shortform, or converts short form to leaf form if
+ * there is not enough room.  If the attr is set, the transaction is committed
+ * and set to NULL.
+ */
+STATIC int
+xfs_attr_set_shortform(
+	struct xfs_da_args	*args,
+	struct xfs_buf		**leaf_bp)
+{
+	struct xfs_inode	*dp = args->dp;
+	int			error, error2 = 0;
+
+	/*
+	 * Try to add the attr to the attribute list in the inode.
+	 */
+	error = xfs_attr_try_sf_addname(dp, args);
+	if (error != -ENOSPC) {
+		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.  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. Once we're done rolling the transaction we
+	 * can release the hold and add the attr to the leaf.
+	 */
+	xfs_trans_bhold(args->trans, *leaf_bp);
+	error = xfs_defer_finish(&args->trans);
+	xfs_trans_bhold_release(args->trans, *leaf_bp);
+	if (error) {
+		xfs_trans_brelse(args->trans, *leaf_bp);
+		return error;
+	}
+
+	return 0;
+}
+
+/*
   * Set the attribute specified in @args.
   */
  int
@@ -212,48 +272,25 @@ xfs_attr_set_args(
  {
  	struct xfs_inode	*dp = args->dp;
  	struct xfs_buf          *leaf_bp = NULL;
-	int			error, error2 = 0;
+	int			error = 0;
 
  	/*
-	 * If the attribute list is non-existent or a shortform list,
-	 * upgrade it to a single-leaf-block attribute list.
+	 * If the attribute list is already in leaf format, jump straight to
+	 * leaf handling.  Otherwise, try to add the attribute to the shortform
+	 * list; if there's no room then convert the list to leaf format and try
+	 * again.
  	 */
-	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)) {
+	if (xfs_attr_is_shortform(dp)) {
 
  		/*
-		 * Try to add the attr to the attribute list in the inode.
+		 * If the attr was successfully set in shortform, the
+		 * transaction is committed and set to NULL.  Otherwise, is it
+		 * converted from shortform to leaf, and the transaction is
+		 * retained.
  		 */
-		error = xfs_attr_try_sf_addname(dp, args);
-		if (error != -ENOSPC) {
-			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.
-		 * 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.
-		 * Once we're done rolling the transaction we can release
-		 * the hold and add the attr to the leaf.
-		 */
-		xfs_trans_bhold(args->trans, leaf_bp);
-		error = xfs_defer_finish(&args->trans);
-		xfs_trans_bhold_release(args->trans, leaf_bp);
-		if (error) {
-			xfs_trans_brelse(args->trans, leaf_bp);
+		error = xfs_attr_set_shortform(args, &leaf_bp);
+		if (error || !args->trans)
  			return error;
-		}
  	}
 
  	if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
Signature · 1 line
2.7.4
#36 lore raw

PATCH v9 15/24 xfs: Add helper function xfs_attr_leaf_mark_incomplete

In reply to Allison Collins

This patch helps to simplify xfs_attr_node_removename by modularizing the code around the transactions into helper functions. This will make the function easier to follow when we introduce delayed attributes.

---
 fs/xfs/libxfs/xfs_attr.c | 41 +++++++++++++++++++++++++++--------------
 1 file changed, 27 insertions(+), 14 deletions(-)
fs/xfs/libxfs/xfs_attr.c +27 -14
index d112910..df77a3c 100644
@@ -1148,6 +1148,32 @@ xfs_attr_node_shrink(
 }
 
 /*
+ * Mark an attribute entry INCOMPLETE and save pointers to the relevant buffers
+ * for later deletion of the entry.
+ */
+STATIC int
+xfs_attr_leaf_mark_incomplete(
+	struct xfs_da_args	*args,
+	struct xfs_da_state	*state)
+{
+	int			error;
+
+	/*
+	 * 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)
+		return error;
+
+	/*
+	 * Mark the attribute as INCOMPLETE
+	 */
+	return xfs_attr3_leaf_setflag(args);
+}
+
+/*
  * Remove a name from a B-tree attribute list.
  *
  * This will involve walking down the Btree, and may involve joining
@@ -1178,20 +1204,7 @@ xfs_attr_node_removename(
 	ASSERT(blk->bp != NULL);
 	ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
 	if (args->rmtblkno > 0) {
-		/*
-		 * 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);
+		error = xfs_attr_leaf_mark_incomplete(args, state);
 		if (error)
 			goto out;
 
Signature · 1 line
2.7.4
Reviewed-by on v9 15/24
#37 lore raw

Re: [PATCH v9 15/24] xfs: Add helper function xfs_attr_leaf_mark_incomplete

Quoted 8 lines · Allison Collins

This patch helps to simplify xfs_attr_node_removename by modularizing the code around the transactions into helper functions. This will make the function easier to follow when we introduce delayed attributes.

LGTM,

--D

Quoted 66 lines
---
 fs/xfs/libxfs/xfs_attr.c | 41 +++++++++++++++++++++++++++--------------
 1 file changed, 27 insertions(+), 14 deletions(-)
fs/xfs/libxfs/xfs_attr.c +27 -14
index d112910..df77a3c 100644
@@ -1148,6 +1148,32 @@ xfs_attr_node_shrink(
 }
 
 /*
+ * Mark an attribute entry INCOMPLETE and save pointers to the relevant buffers
+ * for later deletion of the entry.
+ */
+STATIC int
+xfs_attr_leaf_mark_incomplete(
+	struct xfs_da_args	*args,
+	struct xfs_da_state	*state)
+{
+	int			error;
+
+	/*
+	 * 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)
+		return error;
+
+	/*
+	 * Mark the attribute as INCOMPLETE
+	 */
+	return xfs_attr3_leaf_setflag(args);
+}
+
+/*
  * Remove a name from a B-tree attribute list.
  *
  * This will involve walking down the Btree, and may involve joining
@@ -1178,20 +1204,7 @@ xfs_attr_node_removename(
 	ASSERT(blk->bp != NULL);
 	ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
 	if (args->rmtblkno > 0) {
-		/*
-		 * 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);
+		error = xfs_attr_leaf_mark_incomplete(args, state);
 		if (error)
 			goto out;
 
Signature · 1 line
2.7.4
#38 lore raw

PATCH v9 16/24 xfs: Add remote block helper functions

In reply to Allison Collins

This patch adds two new helper functions xfs_attr_store_rmt_blk and xfs_attr_restore_rmt_blk. These two helpers assist to remove redundant code associated with storing and retrieving remote blocks during the attr set operations.

---
 fs/xfs/libxfs/xfs_attr.c | 50 +++++++++++++++++++++++++++++-------------------
 1 file changed, 30 insertions(+), 20 deletions(-)
fs/xfs/libxfs/xfs_attr.c +30 -20
index df77a3c..feae122 100644
@@ -563,6 +563,30 @@ xfs_attr_shortform_addname(xfs_da_args_t *args)
  * External routines when attribute list is one block
  *========================================================================*/
 
+/* Store info about a remote block */
+STATIC void
+xfs_attr_save_rmt_blk(
+	struct xfs_da_args	*args)
+{
+	args->blkno2 = args->blkno;
+	args->index2 = args->index;
+	args->rmtblkno2 = args->rmtblkno;
+	args->rmtblkcnt2 = args->rmtblkcnt;
+	args->rmtvaluelen2 = args->rmtvaluelen;
+}
+
+/* Set stored info about a remote block */
+STATIC void
+xfs_attr_restore_rmt_blk(
+	struct xfs_da_args	*args)
+{
+	args->blkno = args->blkno2;
+	args->index = args->index2;
+	args->rmtblkno = args->rmtblkno2;
+	args->rmtblkcnt = args->rmtblkcnt2;
+	args->rmtvaluelen = args->rmtvaluelen2;
+}
+
 /*
  * Tries to add an attribute to an inode in leaf form
  *
@@ -597,11 +621,7 @@ xfs_attr_leaf_try_add(
 
 		/* save the attribute state for later removal*/
 		args->op_flags |= XFS_DA_OP_RENAME;	/* an atomic rename */
-		args->blkno2 = args->blkno;		/* set 2nd entry info*/
-		args->index2 = args->index;
-		args->rmtblkno2 = args->rmtblkno;
-		args->rmtblkcnt2 = args->rmtblkcnt;
-		args->rmtvaluelen2 = args->rmtvaluelen;
+		xfs_attr_save_rmt_blk(args);
 
 		/*
 		 * clear the remote attr state now that it is saved so that the
@@ -700,11 +720,8 @@ xfs_attr_leaf_addname(
 		 * Dismantle the "old" attribute/value pair by removing
 		 * a "remote" value (if it exists).
 		 */
-		args->index = args->index2;
-		args->blkno = args->blkno2;
-		args->rmtblkno = args->rmtblkno2;
-		args->rmtblkcnt = args->rmtblkcnt2;
-		args->rmtvaluelen = args->rmtvaluelen2;
+		xfs_attr_restore_rmt_blk(args);
+
 		if (args->rmtblkno) {
 			error = xfs_attr_rmtval_invalidate(args);
 			if (error)
@@ -929,11 +946,7 @@ xfs_attr_node_addname(
 
 		/* 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;
+		xfs_attr_save_rmt_blk(args);
 
 		/*
 		 * clear the remote attr state now that it is saved so that the
@@ -1045,11 +1058,8 @@ xfs_attr_node_addname(
 		 * Dismantle the "old" attribute/value pair by removing
 		 * a "remote" value (if it exists).
 		 */
-		args->index = args->index2;
-		args->blkno = args->blkno2;
-		args->rmtblkno = args->rmtblkno2;
-		args->rmtblkcnt = args->rmtblkcnt2;
-		args->rmtvaluelen = args->rmtvaluelen2;
+		xfs_attr_restore_rmt_blk(args);
+
 		if (args->rmtblkno) {
 			error = xfs_attr_rmtval_invalidate(args);
 			if (error)
Signature · 1 line
2.7.4
Reviewed-by on v9 16/24
#39 lore raw

Re: [PATCH v9 16/24] xfs: Add remote block helper functions

Quoted 9 lines · Allison Collins

This patch adds two new helper functions xfs_attr_store_rmt_blk and xfs_attr_restore_rmt_blk. These two helpers assist to remove redundant code associated with storing and retrieving remote blocks during the attr set operations.

Hmm. This is an ok-enough refactoring of the same idiom repeated over and over, but ...ugh, there has got to be a less weird way of pushing and popping state like this.

Unfortunately, the only thing I can think of would be to pass a "which attr state?" argument to all the attr functions, and that might just make things worse, particularly since we already have da state that gets passed around everywhere, and afaict there's on a few users of this.

--D

Quoted 96 lines
---
 fs/xfs/libxfs/xfs_attr.c | 50 +++++++++++++++++++++++++++++-------------------
 1 file changed, 30 insertions(+), 20 deletions(-)
fs/xfs/libxfs/xfs_attr.c +30 -20
index df77a3c..feae122 100644
@@ -563,6 +563,30 @@ xfs_attr_shortform_addname(xfs_da_args_t *args)
  * External routines when attribute list is one block
  *========================================================================*/
 
+/* Store info about a remote block */
+STATIC void
+xfs_attr_save_rmt_blk(
+	struct xfs_da_args	*args)
+{
+	args->blkno2 = args->blkno;
+	args->index2 = args->index;
+	args->rmtblkno2 = args->rmtblkno;
+	args->rmtblkcnt2 = args->rmtblkcnt;
+	args->rmtvaluelen2 = args->rmtvaluelen;
+}
+
+/* Set stored info about a remote block */
+STATIC void
+xfs_attr_restore_rmt_blk(
+	struct xfs_da_args	*args)
+{
+	args->blkno = args->blkno2;
+	args->index = args->index2;
+	args->rmtblkno = args->rmtblkno2;
+	args->rmtblkcnt = args->rmtblkcnt2;
+	args->rmtvaluelen = args->rmtvaluelen2;
+}
+
 /*
  * Tries to add an attribute to an inode in leaf form
  *
@@ -597,11 +621,7 @@ xfs_attr_leaf_try_add(
 
 		/* save the attribute state for later removal*/
 		args->op_flags |= XFS_DA_OP_RENAME;	/* an atomic rename */
-		args->blkno2 = args->blkno;		/* set 2nd entry info*/
-		args->index2 = args->index;
-		args->rmtblkno2 = args->rmtblkno;
-		args->rmtblkcnt2 = args->rmtblkcnt;
-		args->rmtvaluelen2 = args->rmtvaluelen;
+		xfs_attr_save_rmt_blk(args);
 
 		/*
 		 * clear the remote attr state now that it is saved so that the
@@ -700,11 +720,8 @@ xfs_attr_leaf_addname(
 		 * Dismantle the "old" attribute/value pair by removing
 		 * a "remote" value (if it exists).
 		 */
-		args->index = args->index2;
-		args->blkno = args->blkno2;
-		args->rmtblkno = args->rmtblkno2;
-		args->rmtblkcnt = args->rmtblkcnt2;
-		args->rmtvaluelen = args->rmtvaluelen2;
+		xfs_attr_restore_rmt_blk(args);
+
 		if (args->rmtblkno) {
 			error = xfs_attr_rmtval_invalidate(args);
 			if (error)
@@ -929,11 +946,7 @@ xfs_attr_node_addname(
 
 		/* 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;
+		xfs_attr_save_rmt_blk(args);
 
 		/*
 		 * clear the remote attr state now that it is saved so that the
@@ -1045,11 +1058,8 @@ xfs_attr_node_addname(
 		 * Dismantle the "old" attribute/value pair by removing
 		 * a "remote" value (if it exists).
 		 */
-		args->index = args->index2;
-		args->blkno = args->blkno2;
-		args->rmtblkno = args->rmtblkno2;
-		args->rmtblkcnt = args->rmtblkcnt2;
-		args->rmtvaluelen = args->rmtvaluelen2;
+		xfs_attr_restore_rmt_blk(args);
+
 		if (args->rmtblkno) {
 			error = xfs_attr_rmtval_invalidate(args);
 			if (error)
Signature · 1 line
2.7.4
#40 lore raw

Re: [PATCH v9 16/24] xfs: Add remote block helper functions

Quoted 11 lines · Darrick J. Wong
Quoted 9 lines · Allison Collins

This patch adds two new helper functions xfs_attr_store_rmt_blk and xfs_attr_restore_rmt_blk. These two helpers assist to remove redundant code associated with storing and retrieving remote blocks during the attr set operations.

Quoted 9 lines

Hmm. This is an ok-enough refactoring of the same idiom repeated over and over, but ...ugh, there has got to be a less weird way of pushing and popping state like this.

Unfortunately, the only thing I can think of would be to pass a "which attr state?" argument to all the attr functions, and that might just make things worse, particularly since we already have da state that gets passed around everywhere, and afaict there's on a few users of this.

Hmm, ok, I'll give it some thought. I just spotted it as a sort of clean up while trying to organize things.

Quoted 1 line

Alrighty, thank you!

Allison

Quoted 99 lines

--D

Quoted 96 lines
---
  fs/xfs/libxfs/xfs_attr.c | 50 +++++++++++++++++++++++++++++-------------------
  1 file changed, 30 insertions(+), 20 deletions(-)
fs/xfs/libxfs/xfs_attr.c +30 -20
index df77a3c..feae122 100644
@@ -563,6 +563,30 @@ xfs_attr_shortform_addname(xfs_da_args_t *args)
   * External routines when attribute list is one block
   *========================================================================*/
 
+/* Store info about a remote block */
+STATIC void
+xfs_attr_save_rmt_blk(
+	struct xfs_da_args	*args)
+{
+	args->blkno2 = args->blkno;
+	args->index2 = args->index;
+	args->rmtblkno2 = args->rmtblkno;
+	args->rmtblkcnt2 = args->rmtblkcnt;
+	args->rmtvaluelen2 = args->rmtvaluelen;
+}
+
+/* Set stored info about a remote block */
+STATIC void
+xfs_attr_restore_rmt_blk(
+	struct xfs_da_args	*args)
+{
+	args->blkno = args->blkno2;
+	args->index = args->index2;
+	args->rmtblkno = args->rmtblkno2;
+	args->rmtblkcnt = args->rmtblkcnt2;
+	args->rmtvaluelen = args->rmtvaluelen2;
+}
+
  /*
   * Tries to add an attribute to an inode in leaf form
   *
@@ -597,11 +621,7 @@ xfs_attr_leaf_try_add(
 
  		/* save the attribute state for later removal*/
  		args->op_flags |= XFS_DA_OP_RENAME;	/* an atomic rename */
-		args->blkno2 = args->blkno;		/* set 2nd entry info*/
-		args->index2 = args->index;
-		args->rmtblkno2 = args->rmtblkno;
-		args->rmtblkcnt2 = args->rmtblkcnt;
-		args->rmtvaluelen2 = args->rmtvaluelen;
+		xfs_attr_save_rmt_blk(args);
 
  		/*
  		 * clear the remote attr state now that it is saved so that the
@@ -700,11 +720,8 @@ xfs_attr_leaf_addname(
  		 * Dismantle the "old" attribute/value pair by removing
  		 * a "remote" value (if it exists).
  		 */
-		args->index = args->index2;
-		args->blkno = args->blkno2;
-		args->rmtblkno = args->rmtblkno2;
-		args->rmtblkcnt = args->rmtblkcnt2;
-		args->rmtvaluelen = args->rmtvaluelen2;
+		xfs_attr_restore_rmt_blk(args);
+
  		if (args->rmtblkno) {
  			error = xfs_attr_rmtval_invalidate(args);
  			if (error)
@@ -929,11 +946,7 @@ xfs_attr_node_addname(
 
  		/* 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;
+		xfs_attr_save_rmt_blk(args);
 
  		/*
  		 * clear the remote attr state now that it is saved so that the
@@ -1045,11 +1058,8 @@ xfs_attr_node_addname(
  		 * Dismantle the "old" attribute/value pair by removing
  		 * a "remote" value (if it exists).
  		 */
-		args->index = args->index2;
-		args->blkno = args->blkno2;
-		args->rmtblkno = args->rmtblkno2;
-		args->rmtblkcnt = args->rmtblkcnt2;
-		args->rmtvaluelen = args->rmtvaluelen2;
+		xfs_attr_restore_rmt_blk(args);
+
  		if (args->rmtblkno) {
  			error = xfs_attr_rmtval_invalidate(args);
  			if (error)
Signature · 1 line
2.7.4
#41 lore raw

PATCH v9 17/24 xfs: Add helper function xfs_attr_node_removename_setup

In reply to Allison Collins

This patch adds a new helper function xfs_attr_node_removename_setup. This will help modularize xfs_attr_node_removename when we add delay ready attributes later.

---
 fs/xfs/libxfs/xfs_attr.c | 48 +++++++++++++++++++++++++++++++++++-------------
 1 file changed, 35 insertions(+), 13 deletions(-)
fs/xfs/libxfs/xfs_attr.c +35 -13
index feae122..c8226c6 100644
@@ -1184,6 +1184,39 @@ xfs_attr_leaf_mark_incomplete(
 }
 
 /*
+ * Initial setup for xfs_attr_node_removename.  Make sure the attr is there and
+ * the blocks are valid.  Any remote blocks will be marked incomplete.
+ */
+STATIC
+int xfs_attr_node_removename_setup(
+	struct xfs_da_args	*args,
+	struct xfs_da_state	**state)
+{
+	int			error;
+	struct xfs_da_state_blk	*blk;
+
+	error = xfs_attr_node_hasname(args, state);
+	if (error != -EEXIST)
+		return error;
+
+	blk = &(*state)->path.blk[(*state)->path.active - 1];
+	ASSERT(blk->bp != NULL);
+	ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
+
+	if (args->rmtblkno > 0) {
+		error = xfs_attr_leaf_mark_incomplete(args, *state);
+		if (error)
+			return error;
+
+		error = xfs_attr_rmtval_invalidate(args);
+		if (error)
+			return error;
+	}
+
+	return 0;
+}
+
+/*
  * Remove a name from a B-tree attribute list.
  *
  * This will involve walking down the Btree, and may involve joining
@@ -1201,8 +1234,8 @@ xfs_attr_node_removename(
 
 	trace_xfs_attr_node_removename(args);
 
-	error = xfs_attr_node_hasname(args, &state);
-	if (error != -EEXIST)
+	error = xfs_attr_node_removename_setup(args, &state);
+	if (error)
 		goto out;
 
 	/*
@@ -1210,18 +1243,7 @@ xfs_attr_node_removename(
 	 * 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.
 	 */
-	blk = &state->path.blk[ state->path.active-1 ];
-	ASSERT(blk->bp != NULL);
-	ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
 	if (args->rmtblkno > 0) {
-		error = xfs_attr_leaf_mark_incomplete(args, state);
-		if (error)
-			goto out;
-
-		error = xfs_attr_rmtval_invalidate(args);
-		if (error)
-			return error;
-
 		error = xfs_attr_rmtval_remove(args);
 		if (error)
 			goto out;
Signature · 1 line
2.7.4
Reviewed-by on v9 17/24
#42 lore raw

Re: [PATCH v9 17/24] xfs: Add helper function xfs_attr_node_removename_setup

Quoted 16 lines · Allison Collins

This patch adds a new helper function xfs_attr_node_removename_setup. This will help modularize xfs_attr_node_removename when we add delay ready attributes later.

---
 fs/xfs/libxfs/xfs_attr.c | 48 +++++++++++++++++++++++++++++++++++-------------
 1 file changed, 35 insertions(+), 13 deletions(-)
fs/xfs/libxfs/xfs_attr.c +0 -0
index feae122..c8226c6 100644

fs/xfs/libxfs/xfs_attr.c xfs_attr_leaf_mark_incomplete( · line 1188

Quoted 5 lines
fs/xfs/libxfs/xfs_attr.c +2 -0
@@ -1184,6 +1184,39 @@ xfs_attr_leaf_mark_incomplete(
 }
 
 /*
+ * Initial setup for xfs_attr_node_removename.  Make sure the attr is there and
+ * the blocks are valid.  Any remote blocks will be marked incomplete.

"Attr keys with remote blocks will be marked incomplete."

Quoted 15 lines
fs/xfs/libxfs/xfs_attr.c +15 -0
+ */
+STATIC
+int xfs_attr_node_removename_setup(
+	struct xfs_da_args	*args,
+	struct xfs_da_state	**state)
+{
+	int			error;
+	struct xfs_da_state_blk	*blk;
+
+	error = xfs_attr_node_hasname(args, state);
+	if (error != -EEXIST)
+		return error;
+
+	blk = &(*state)->path.blk[(*state)->path.active - 1];
+	ASSERT(blk->bp != NULL);

fs/xfs/libxfs/xfs_attr.c xfs_attr_leaf_mark_incomplete( · line 1213

Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10 -0
+	ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
+
+	if (args->rmtblkno > 0) {
+		error = xfs_attr_leaf_mark_incomplete(args, *state);
+		if (error)
+			return error;
+
+		error = xfs_attr_rmtval_invalidate(args);
+		if (error)
+			return error;
		return xfs_attr_rmtval_invalidate(args);

With those two things changed,

--D

Quoted 42 lines
fs/xfs/libxfs/xfs_attr.c +8 -13
+	}
+
+	return 0;
+}
+
+/*
  * Remove a name from a B-tree attribute list.
  *
  * This will involve walking down the Btree, and may involve joining
@@ -1201,8 +1234,8 @@ xfs_attr_node_removename(
 
 	trace_xfs_attr_node_removename(args);
 
-	error = xfs_attr_node_hasname(args, &state);
-	if (error != -EEXIST)
+	error = xfs_attr_node_removename_setup(args, &state);
+	if (error)
 		goto out;
 
 	/*
@@ -1210,18 +1243,7 @@ xfs_attr_node_removename(
 	 * 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.
 	 */
-	blk = &state->path.blk[ state->path.active-1 ];
-	ASSERT(blk->bp != NULL);
-	ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
 	if (args->rmtblkno > 0) {
-		error = xfs_attr_leaf_mark_incomplete(args, state);
-		if (error)
-			goto out;
-
-		error = xfs_attr_rmtval_invalidate(args);
-		if (error)
-			return error;
-
 		error = xfs_attr_rmtval_remove(args);
 		if (error)
 			goto out;
Signature · 1 line
2.7.4
#43 lore raw

Re: [PATCH v9 17/24] xfs: Add helper function xfs_attr_node_removename_setup

Quoted 19 lines · Darrick J. Wong
Quoted 18 lines · Allison Collins

This patch adds a new helper function xfs_attr_node_removename_setup. This will help modularize xfs_attr_node_removename when we add delay ready attributes later.

---
  fs/xfs/libxfs/xfs_attr.c | 48 +++++++++++++++++++++++++++++++++++-------------
  1 file changed, 35 insertions(+), 13 deletions(-)
fs/xfs/libxfs/xfs_attr.c +0 -0
index feae122..c8226c6 100644
@@ -1184,6 +1184,39 @@ xfs_attr_leaf_mark_incomplete(
  }
 
Quoted 5 lines

fs/xfs/libxfs/xfs_attr.c xfs_attr_leaf_mark_incomplete( · line 1188

Quoted 3 lines
fs/xfs/libxfs/xfs_attr.c +2 -0
  /*
+ * Initial setup for xfs_attr_node_removename.  Make sure the attr is there and
+ * the blocks are valid.  Any remote blocks will be marked incomplete.

"Attr keys with remote blocks will be marked incomplete."

Ok, will fix.

Quoted 29 lines
Quoted 16 lines
fs/xfs/libxfs/xfs_attr.c +15 -0
+ */
+STATIC
+int xfs_attr_node_removename_setup(
+	struct xfs_da_args	*args,
+	struct xfs_da_state	**state)
+{
+	int			error;
+	struct xfs_da_state_blk	*blk;
+
+	error = xfs_attr_node_hasname(args, state);
+	if (error != -EEXIST)
+		return error;
+
+	blk = &(*state)->path.blk[(*state)->path.active - 1];
+	ASSERT(blk->bp != NULL);

fs/xfs/libxfs/xfs_attr.c xfs_attr_leaf_mark_incomplete( · line 1213

Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10 -0
+	ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
+
+	if (args->rmtblkno > 0) {
+		error = xfs_attr_leaf_mark_incomplete(args, *state);
+		if (error)
+			return error;
+
+		error = xfs_attr_rmtval_invalidate(args);
+		if (error)
+			return error;
		return xfs_attr_rmtval_invalidate(args);
Quoted 2 lines

With those two things changed,

Ok, thank you!

Allison

Quoted 45 lines

--D

Quoted 42 lines
fs/xfs/libxfs/xfs_attr.c +8 -13
+	}
+
+	return 0;
+}
+
+/*
   * Remove a name from a B-tree attribute list.
   *
   * This will involve walking down the Btree, and may involve joining
@@ -1201,8 +1234,8 @@ xfs_attr_node_removename(
 
  	trace_xfs_attr_node_removename(args);
 
-	error = xfs_attr_node_hasname(args, &state);
-	if (error != -EEXIST)
+	error = xfs_attr_node_removename_setup(args, &state);
+	if (error)
  		goto out;
 
  	/*
@@ -1210,18 +1243,7 @@ xfs_attr_node_removename(
  	 * 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.
  	 */
-	blk = &state->path.blk[ state->path.active-1 ];
-	ASSERT(blk->bp != NULL);
-	ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
  	if (args->rmtblkno > 0) {
-		error = xfs_attr_leaf_mark_incomplete(args, state);
-		if (error)
-			goto out;
-
-		error = xfs_attr_rmtval_invalidate(args);
-		if (error)
-			return error;
-
  		error = xfs_attr_rmtval_remove(args);
  		if (error)
  			goto out;
Signature · 1 line
2.7.4
#44 lore raw

PATCH v9 18/24 xfs: Add helper function xfs_attr_node_removename_rmt

In reply to Allison Collins

This patch adds another new helper function xfs_attr_node_removename_rmt. This will also help modularize xfs_attr_node_removename when we add delay ready attributes later.

---
 fs/xfs/libxfs/xfs_attr.c | 28 +++++++++++++++++++---------
 1 file changed, 19 insertions(+), 9 deletions(-)
fs/xfs/libxfs/xfs_attr.c +19 -9
index c8226c6..ab1c9fa 100644
@@ -1216,6 +1216,24 @@ int xfs_attr_node_removename_setup(
 	return 0;
 }
 
+STATIC int
+xfs_attr_node_removename_rmt (
+	struct xfs_da_args	*args,
+	struct xfs_da_state	*state)
+{
+	int			error = 0;
+
+	error = xfs_attr_rmtval_remove(args);
+	if (error)
+		return error;
+
+	/*
+	 * Refill the state structure with buffers, the prior calls released our
+	 * buffers.
+	 */
+	return xfs_attr_refillstate(state);
+}
+
 /*
  * Remove a name from a B-tree attribute list.
  *
@@ -1244,15 +1262,7 @@ xfs_attr_node_removename(
 	 * overflow the maximum size of a transaction and/or hit a deadlock.
 	 */
 	if (args->rmtblkno > 0) {
-		error = xfs_attr_rmtval_remove(args);
-		if (error)
-			goto out;
-
-		/*
-		 * Refill the state structure with buffers, the prior calls
-		 * released our buffers.
-		 */
-		error = xfs_attr_refillstate(state);
+		error = xfs_attr_node_removename_rmt(args, state);
 		if (error)
 			goto out;
 	}
Signature · 1 line
2.7.4
Reviewed-by on v9 18/24
#45 lore raw

Re: [PATCH v9 18/24] xfs: Add helper function xfs_attr_node_removename_rmt

Quoted 16 lines · Allison Collins

This patch adds another new helper function xfs_attr_node_removename_rmt. This will also help modularize xfs_attr_node_removename when we add delay ready attributes later.

---
 fs/xfs/libxfs/xfs_attr.c | 28 +++++++++++++++++++---------
 1 file changed, 19 insertions(+), 9 deletions(-)
fs/xfs/libxfs/xfs_attr.c +0 -0
index c8226c6..ab1c9fa 100644

fs/xfs/libxfs/xfs_attr.c int xfs_attr_node_removename_setup( · line 1220

Quoted 5 lines
fs/xfs/libxfs/xfs_attr.c +2 -0
@@ -1216,6 +1216,24 @@ int xfs_attr_node_removename_setup(
 	return 0;
 }
 
+STATIC int
+xfs_attr_node_removename_rmt (

xfs_attr_node_remove_rmt?

Otherwise looks ok,

--D

Quoted 39 lines
fs/xfs/libxfs/xfs_attr.c +17 -9
+	struct xfs_da_args	*args,
+	struct xfs_da_state	*state)
+{
+	int			error = 0;
+
+	error = xfs_attr_rmtval_remove(args);
+	if (error)
+		return error;
+
+	/*
+	 * Refill the state structure with buffers, the prior calls released our
+	 * buffers.
+	 */
+	return xfs_attr_refillstate(state);
+}
+
 /*
  * Remove a name from a B-tree attribute list.
  *
@@ -1244,15 +1262,7 @@ xfs_attr_node_removename(
 	 * overflow the maximum size of a transaction and/or hit a deadlock.
 	 */
 	if (args->rmtblkno > 0) {
-		error = xfs_attr_rmtval_remove(args);
-		if (error)
-			goto out;
-
-		/*
-		 * Refill the state structure with buffers, the prior calls
-		 * released our buffers.
-		 */
-		error = xfs_attr_refillstate(state);
+		error = xfs_attr_node_removename_rmt(args, state);
 		if (error)
 			goto out;
 	}
Signature · 1 line
2.7.4
#46 lore raw

Re: [PATCH v9 18/24] xfs: Add helper function xfs_attr_node_removename_rmt

Quoted 20 lines · Darrick J. Wong
Quoted 19 lines · Allison Collins

This patch adds another new helper function xfs_attr_node_removename_rmt. This will also help modularize xfs_attr_node_removename when we add delay ready attributes later.

---
  fs/xfs/libxfs/xfs_attr.c | 28 +++++++++++++++++++---------
  1 file changed, 19 insertions(+), 9 deletions(-)
fs/xfs/libxfs/xfs_attr.c +0 -0
index c8226c6..ab1c9fa 100644
@@ -1216,6 +1216,24 @@ int xfs_attr_node_removename_setup(
  	return 0;
  }
 
Quoted 4 lines

fs/xfs/libxfs/xfs_attr.c int xfs_attr_node_removename_setup( · line 1220

Quoted 2 lines
fs/xfs/libxfs/xfs_attr.c +2 -0
+STATIC int
+xfs_attr_node_removename_rmt (

xfs_attr_node_remove_rmt?

I believe this is a name Brian had asked for in a prior review, though I don't know how firmly set he is on it?

Quoted 3 lines

Otherwise looks ok,

Alrighty, thank you!

Allison

Quoted 42 lines

--D

Quoted 39 lines
fs/xfs/libxfs/xfs_attr.c +17 -9
+	struct xfs_da_args	*args,
+	struct xfs_da_state	*state)
+{
+	int			error = 0;
+
+	error = xfs_attr_rmtval_remove(args);
+	if (error)
+		return error;
+
+	/*
+	 * Refill the state structure with buffers, the prior calls released our
+	 * buffers.
+	 */
+	return xfs_attr_refillstate(state);
+}
+
  /*
   * Remove a name from a B-tree attribute list.
   *
@@ -1244,15 +1262,7 @@ xfs_attr_node_removename(
  	 * overflow the maximum size of a transaction and/or hit a deadlock.
  	 */
  	if (args->rmtblkno > 0) {
-		error = xfs_attr_rmtval_remove(args);
-		if (error)
-			goto out;
-
-		/*
-		 * Refill the state structure with buffers, the prior calls
-		 * released our buffers.
-		 */
-		error = xfs_attr_refillstate(state);
+		error = xfs_attr_node_removename_rmt(args, state);
  		if (error)
  			goto out;
  	}
Signature · 1 line
2.7.4
#47 lore raw

PATCH v9 19/24 xfs: Simplify xfs_attr_leaf_addname

In reply to Allison Collins

Quick patch to unnest the rename logic in the leaf code path. This will help simplify delayed attr logic later.

---
 fs/xfs/libxfs/xfs_attr.c | 108 +++++++++++++++++++++++------------------------
 1 file changed, 53 insertions(+), 55 deletions(-)
fs/xfs/libxfs/xfs_attr.c +53 -55
index ab1c9fa..1810f90 100644
@@ -694,73 +694,71 @@ xfs_attr_leaf_addname(
 			return error;
 	}
 
-	/*
-	 * If this is an atomic rename operation, we must "flip" the
-	 * incomplete flags on the "new" and "old" attribute/value pairs
-	 * so that one disappears and one appears atomically.  Then we
-	 * must remove the "old" attribute/value pair.
-	 */
-	if (args->op_flags & XFS_DA_OP_RENAME) {
+	if ((args->op_flags & XFS_DA_OP_RENAME) == 0) {
 		/*
-		 * In a separate transaction, set the incomplete flag on the
-		 * "old" attr and clear the incomplete flag on the "new" attr.
-		 */
-		error = xfs_attr3_leaf_flipflags(args);
-		if (error)
-			return error;
-		/*
-		 * Commit the flag value change and start the next trans in
-		 * series.
+		 * Added a "remote" value, just clear the incomplete flag.
 		 */
-		error = xfs_trans_roll_inode(&args->trans, args->dp);
-		if (error)
-			return error;
+		if (args->rmtblkno > 0)
+			error = xfs_attr3_leaf_clearflag(args);
 
-		/*
-		 * Dismantle the "old" attribute/value pair by removing
-		 * a "remote" value (if it exists).
-		 */
-		xfs_attr_restore_rmt_blk(args);
+		return error;
+	}
 
-		if (args->rmtblkno) {
-			error = xfs_attr_rmtval_invalidate(args);
-			if (error)
-				return error;
+	/*
+	 * If this is an atomic rename operation, we must "flip" the incomplete
+	 * flags on the "new" and "old" attribute/value pairs so that one
+	 * disappears and one appears atomically.  Then we must remove the "old"
+	 * attribute/value pair.
+	 *
+	 * In a separate transaction, set the incomplete flag on the "old" attr
+	 * and clear the incomplete flag on the "new" attr.
+	 */
 
-			error = xfs_attr_rmtval_remove(args);
-			if (error)
-				return error;
-		}
+	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;
 
-		/*
-		 * Read in the block containing the "old" attr, then
-		 * remove the "old" attr from that block (neat, huh!)
-		 */
-		error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno,
-					   &bp);
+	/*
+	 * Dismantle the "old" attribute/value pair by removing a "remote" value
+	 * (if it exists).
+	 */
+	xfs_attr_restore_rmt_blk(args);
+
+	if (args->rmtblkno) {
+		error = xfs_attr_rmtval_invalidate(args);
 		if (error)
 			return error;
 
-		xfs_attr3_leaf_remove(bp, args);
-
-		/*
-		 * If the result is small enough, shrink it all into the inode.
-		 */
-		if ((forkoff = xfs_attr_shortform_allfit(bp, dp))) {
-			error = xfs_attr3_leaf_to_shortform(bp, args, forkoff);
-			/* bp is gone due to xfs_da_shrink_inode */
-			if (error)
-				return error;
-		}
-
-	} else if (args->rmtblkno > 0) {
-		/*
-		 * Added a "remote" value, just clear the incomplete flag.
-		 */
-		error = xfs_attr3_leaf_clearflag(args);
+		error = xfs_attr_rmtval_remove(args);
 		if (error)
 			return error;
 	}
+
+	/*
+	 * Read in the block containing the "old" attr, then remove the "old"
+	 * attr from that block (neat, huh!)
+	 */
+	error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno,
+				   &bp);
+	if (error)
+		return error;
+
+	xfs_attr3_leaf_remove(bp, args);
+
+	/*
+	 * If the result is small enough, shrink it all into the inode.
+	 */
+	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 */
+
 	return error;
 }
 
Signature · 1 line
2.7.4
#48 lore raw

Re: [PATCH v9 19/24] xfs: Simplify xfs_attr_leaf_addname

Quoted 2 lines · Allison Collins

Quick patch to unnest the rename logic in the leaf code path. This will help simplify delayed attr logic later.

This isn't really an unnesting, is it? We're inverting the if logic and flipping the subordinate blocks.

"Invert the rename logic in xfs_attr_leaf_addname to simplify the delayed attr logic later."

Quoted 11 lines
---
 fs/xfs/libxfs/xfs_attr.c | 108 +++++++++++++++++++++++------------------------
 1 file changed, 53 insertions(+), 55 deletions(-)
fs/xfs/libxfs/xfs_attr.c +0 -0
index ab1c9fa..1810f90 100644
@@ -694,73 +694,71 @@ xfs_attr_leaf_addname(
 			return error;

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

Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +1 -7
 	}
 
-	/*
-	 * If this is an atomic rename operation, we must "flip" the
-	 * incomplete flags on the "new" and "old" attribute/value pairs
-	 * so that one disappears and one appears atomically.  Then we
-	 * must remove the "old" attribute/value pair.
-	 */
-	if (args->op_flags & XFS_DA_OP_RENAME) {
+	if ((args->op_flags & XFS_DA_OP_RENAME) == 0) {
	if (!(args->op_flags & XFS_DA_OP_RENAME)) {

--D

Quoted 118 lines
fs/xfs/libxfs/xfs_attr.c +52 -48
 		/*
-		 * In a separate transaction, set the incomplete flag on the
-		 * "old" attr and clear the incomplete flag on the "new" attr.
-		 */
-		error = xfs_attr3_leaf_flipflags(args);
-		if (error)
-			return error;
-		/*
-		 * Commit the flag value change and start the next trans in
-		 * series.
+		 * Added a "remote" value, just clear the incomplete flag.
 		 */
-		error = xfs_trans_roll_inode(&args->trans, args->dp);
-		if (error)
-			return error;
+		if (args->rmtblkno > 0)
+			error = xfs_attr3_leaf_clearflag(args);
 
-		/*
-		 * Dismantle the "old" attribute/value pair by removing
-		 * a "remote" value (if it exists).
-		 */
-		xfs_attr_restore_rmt_blk(args);
+		return error;
+	}
 
-		if (args->rmtblkno) {
-			error = xfs_attr_rmtval_invalidate(args);
-			if (error)
-				return error;
+	/*
+	 * If this is an atomic rename operation, we must "flip" the incomplete
+	 * flags on the "new" and "old" attribute/value pairs so that one
+	 * disappears and one appears atomically.  Then we must remove the "old"
+	 * attribute/value pair.
+	 *
+	 * In a separate transaction, set the incomplete flag on the "old" attr
+	 * and clear the incomplete flag on the "new" attr.
+	 */
 
-			error = xfs_attr_rmtval_remove(args);
-			if (error)
-				return error;
-		}
+	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;
 
-		/*
-		 * Read in the block containing the "old" attr, then
-		 * remove the "old" attr from that block (neat, huh!)
-		 */
-		error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno,
-					   &bp);
+	/*
+	 * Dismantle the "old" attribute/value pair by removing a "remote" value
+	 * (if it exists).
+	 */
+	xfs_attr_restore_rmt_blk(args);
+
+	if (args->rmtblkno) {
+		error = xfs_attr_rmtval_invalidate(args);
 		if (error)
 			return error;
 
-		xfs_attr3_leaf_remove(bp, args);
-
-		/*
-		 * If the result is small enough, shrink it all into the inode.
-		 */
-		if ((forkoff = xfs_attr_shortform_allfit(bp, dp))) {
-			error = xfs_attr3_leaf_to_shortform(bp, args, forkoff);
-			/* bp is gone due to xfs_da_shrink_inode */
-			if (error)
-				return error;
-		}
-
-	} else if (args->rmtblkno > 0) {
-		/*
-		 * Added a "remote" value, just clear the incomplete flag.
-		 */
-		error = xfs_attr3_leaf_clearflag(args);
+		error = xfs_attr_rmtval_remove(args);
 		if (error)
 			return error;
 	}
+
+	/*
+	 * Read in the block containing the "old" attr, then remove the "old"
+	 * attr from that block (neat, huh!)
+	 */
+	error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno,
+				   &bp);
+	if (error)
+		return error;
+
+	xfs_attr3_leaf_remove(bp, args);
+
+	/*
+	 * If the result is small enough, shrink it all into the inode.
+	 */
+	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 */
+
 	return error;
 }
 
Signature · 1 line
2.7.4
#49 lore raw

Re: [PATCH v9 19/24] xfs: Simplify xfs_attr_leaf_addname

Quoted 9 lines · Darrick J. Wong
Quoted 2 lines · Allison Collins

Quick patch to unnest the rename logic in the leaf code path. This will help simplify delayed attr logic later.

This isn't really an unnesting, is it? We're inverting the if logic and flipping the subordinate blocks.

"Invert the rename logic in xfs_attr_leaf_addname to simplify the delayed attr logic later."

Alrighty, will fix

Quoted 14 lines
Quoted 14 lines
---
  fs/xfs/libxfs/xfs_attr.c | 108 +++++++++++++++++++++++------------------------
  1 file changed, 53 insertions(+), 55 deletions(-)
fs/xfs/libxfs/xfs_attr.c +0 -0
index ab1c9fa..1810f90 100644
@@ -694,73 +694,71 @@ xfs_attr_leaf_addname(
  			return error;
  	}
 
Quoted 10 lines

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

Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c +1 -7
-	/*
-	 * If this is an atomic rename operation, we must "flip" the
-	 * incomplete flags on the "new" and "old" attribute/value pairs
-	 * so that one disappears and one appears atomically.  Then we
-	 * must remove the "old" attribute/value pair.
-	 */
-	if (args->op_flags & XFS_DA_OP_RENAME) {
+	if ((args->op_flags & XFS_DA_OP_RENAME) == 0) {
	if (!(args->op_flags & XFS_DA_OP_RENAME)) {

Sure, will flip. Thanks!

Allison

Quoted 121 lines

--D

Quoted 118 lines
fs/xfs/libxfs/xfs_attr.c +52 -48
  		/*
-		 * In a separate transaction, set the incomplete flag on the
-		 * "old" attr and clear the incomplete flag on the "new" attr.
-		 */
-		error = xfs_attr3_leaf_flipflags(args);
-		if (error)
-			return error;
-		/*
-		 * Commit the flag value change and start the next trans in
-		 * series.
+		 * Added a "remote" value, just clear the incomplete flag.
  		 */
-		error = xfs_trans_roll_inode(&args->trans, args->dp);
-		if (error)
-			return error;
+		if (args->rmtblkno > 0)
+			error = xfs_attr3_leaf_clearflag(args);
 
-		/*
-		 * Dismantle the "old" attribute/value pair by removing
-		 * a "remote" value (if it exists).
-		 */
-		xfs_attr_restore_rmt_blk(args);
+		return error;
+	}
 
-		if (args->rmtblkno) {
-			error = xfs_attr_rmtval_invalidate(args);
-			if (error)
-				return error;
+	/*
+	 * If this is an atomic rename operation, we must "flip" the incomplete
+	 * flags on the "new" and "old" attribute/value pairs so that one
+	 * disappears and one appears atomically.  Then we must remove the "old"
+	 * attribute/value pair.
+	 *
+	 * In a separate transaction, set the incomplete flag on the "old" attr
+	 * and clear the incomplete flag on the "new" attr.
+	 */
 
-			error = xfs_attr_rmtval_remove(args);
-			if (error)
-				return error;
-		}
+	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;
 
-		/*
-		 * Read in the block containing the "old" attr, then
-		 * remove the "old" attr from that block (neat, huh!)
-		 */
-		error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno,
-					   &bp);
+	/*
+	 * Dismantle the "old" attribute/value pair by removing a "remote" value
+	 * (if it exists).
+	 */
+	xfs_attr_restore_rmt_blk(args);
+
+	if (args->rmtblkno) {
+		error = xfs_attr_rmtval_invalidate(args);
  		if (error)
  			return error;
 
-		xfs_attr3_leaf_remove(bp, args);
-
-		/*
-		 * If the result is small enough, shrink it all into the inode.
-		 */
-		if ((forkoff = xfs_attr_shortform_allfit(bp, dp))) {
-			error = xfs_attr3_leaf_to_shortform(bp, args, forkoff);
-			/* bp is gone due to xfs_da_shrink_inode */
-			if (error)
-				return error;
-		}
-
-	} else if (args->rmtblkno > 0) {
-		/*
-		 * Added a "remote" value, just clear the incomplete flag.
-		 */
-		error = xfs_attr3_leaf_clearflag(args);
+		error = xfs_attr_rmtval_remove(args);
  		if (error)
  			return error;
  	}
+
+	/*
+	 * Read in the block containing the "old" attr, then remove the "old"
+	 * attr from that block (neat, huh!)
+	 */
+	error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno,
+				   &bp);
+	if (error)
+		return error;
+
+	xfs_attr3_leaf_remove(bp, args);
+
+	/*
+	 * If the result is small enough, shrink it all into the inode.
+	 */
+	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 */
+
  	return error;
  }
 
Signature · 1 line
2.7.4
Reviewed-by on v9 19/24
#50 lore raw

Re: [PATCH v9 19/24] xfs: Simplify xfs_attr_leaf_addname

In reply to Allison Collins
Quoted 5 lines · Allison Collins

Quick patch to unnest the rename logic in the leaf code path. This will help simplify delayed attr logic later.

---

With Darrick's cleanups:

Quoted 137 lines
 fs/xfs/libxfs/xfs_attr.c | 108 +++++++++++++++++++++++------------------------
 1 file changed, 53 insertions(+), 55 deletions(-)
fs/xfs/libxfs/xfs_attr.c +53 -55
index ab1c9fa..1810f90 100644
@@ -694,73 +694,71 @@ xfs_attr_leaf_addname(
 			return error;
 	}
 
-	/*
-	 * If this is an atomic rename operation, we must "flip" the
-	 * incomplete flags on the "new" and "old" attribute/value pairs
-	 * so that one disappears and one appears atomically.  Then we
-	 * must remove the "old" attribute/value pair.
-	 */
-	if (args->op_flags & XFS_DA_OP_RENAME) {
+	if ((args->op_flags & XFS_DA_OP_RENAME) == 0) {
 		/*
-		 * In a separate transaction, set the incomplete flag on the
-		 * "old" attr and clear the incomplete flag on the "new" attr.
-		 */
-		error = xfs_attr3_leaf_flipflags(args);
-		if (error)
-			return error;
-		/*
-		 * Commit the flag value change and start the next trans in
-		 * series.
+		 * Added a "remote" value, just clear the incomplete flag.
 		 */
-		error = xfs_trans_roll_inode(&args->trans, args->dp);
-		if (error)
-			return error;
+		if (args->rmtblkno > 0)
+			error = xfs_attr3_leaf_clearflag(args);
 
-		/*
-		 * Dismantle the "old" attribute/value pair by removing
-		 * a "remote" value (if it exists).
-		 */
-		xfs_attr_restore_rmt_blk(args);
+		return error;
+	}
 
-		if (args->rmtblkno) {
-			error = xfs_attr_rmtval_invalidate(args);
-			if (error)
-				return error;
+	/*
+	 * If this is an atomic rename operation, we must "flip" the incomplete
+	 * flags on the "new" and "old" attribute/value pairs so that one
+	 * disappears and one appears atomically.  Then we must remove the "old"
+	 * attribute/value pair.
+	 *
+	 * In a separate transaction, set the incomplete flag on the "old" attr
+	 * and clear the incomplete flag on the "new" attr.
+	 */
 
-			error = xfs_attr_rmtval_remove(args);
-			if (error)
-				return error;
-		}
+	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;
 
-		/*
-		 * Read in the block containing the "old" attr, then
-		 * remove the "old" attr from that block (neat, huh!)
-		 */
-		error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno,
-					   &bp);
+	/*
+	 * Dismantle the "old" attribute/value pair by removing a "remote" value
+	 * (if it exists).
+	 */
+	xfs_attr_restore_rmt_blk(args);
+
+	if (args->rmtblkno) {
+		error = xfs_attr_rmtval_invalidate(args);
 		if (error)
 			return error;
 
-		xfs_attr3_leaf_remove(bp, args);
-
-		/*
-		 * If the result is small enough, shrink it all into the inode.
-		 */
-		if ((forkoff = xfs_attr_shortform_allfit(bp, dp))) {
-			error = xfs_attr3_leaf_to_shortform(bp, args, forkoff);
-			/* bp is gone due to xfs_da_shrink_inode */
-			if (error)
-				return error;
-		}
-
-	} else if (args->rmtblkno > 0) {
-		/*
-		 * Added a "remote" value, just clear the incomplete flag.
-		 */
-		error = xfs_attr3_leaf_clearflag(args);
+		error = xfs_attr_rmtval_remove(args);
 		if (error)
 			return error;
 	}
+
+	/*
+	 * Read in the block containing the "old" attr, then remove the "old"
+	 * attr from that block (neat, huh!)
+	 */
+	error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno,
+				   &bp);
+	if (error)
+		return error;
+
+	xfs_attr3_leaf_remove(bp, args);
+
+	/*
+	 * If the result is small enough, shrink it all into the inode.
+	 */
+	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 */
+
 	return error;
 }
 
Signature · 1 line
2.7.4
#51 lore raw

Re: [PATCH v9 19/24] xfs: Simplify xfs_attr_leaf_addname

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

Quick patch to unnest the rename logic in the leaf code path. This will help simplify delayed attr logic later.

---

With Darrick's cleanups:

Great, thank you!

Allison

Quoted 139 lines
Quoted 138 lines
  fs/xfs/libxfs/xfs_attr.c | 108 +++++++++++++++++++++++------------------------
  1 file changed, 53 insertions(+), 55 deletions(-)
fs/xfs/libxfs/xfs_attr.c +53 -55
index ab1c9fa..1810f90 100644
@@ -694,73 +694,71 @@ xfs_attr_leaf_addname(
  			return error;
  	}
 
-	/*
-	 * If this is an atomic rename operation, we must "flip" the
-	 * incomplete flags on the "new" and "old" attribute/value pairs
-	 * so that one disappears and one appears atomically.  Then we
-	 * must remove the "old" attribute/value pair.
-	 */
-	if (args->op_flags & XFS_DA_OP_RENAME) {
+	if ((args->op_flags & XFS_DA_OP_RENAME) == 0) {
  		/*
-		 * In a separate transaction, set the incomplete flag on the
-		 * "old" attr and clear the incomplete flag on the "new" attr.
-		 */
-		error = xfs_attr3_leaf_flipflags(args);
-		if (error)
-			return error;
-		/*
-		 * Commit the flag value change and start the next trans in
-		 * series.
+		 * Added a "remote" value, just clear the incomplete flag.
  		 */
-		error = xfs_trans_roll_inode(&args->trans, args->dp);
-		if (error)
-			return error;
+		if (args->rmtblkno > 0)
+			error = xfs_attr3_leaf_clearflag(args);
 
-		/*
-		 * Dismantle the "old" attribute/value pair by removing
-		 * a "remote" value (if it exists).
-		 */
-		xfs_attr_restore_rmt_blk(args);
+		return error;
+	}
 
-		if (args->rmtblkno) {
-			error = xfs_attr_rmtval_invalidate(args);
-			if (error)
-				return error;
+	/*
+	 * If this is an atomic rename operation, we must "flip" the incomplete
+	 * flags on the "new" and "old" attribute/value pairs so that one
+	 * disappears and one appears atomically.  Then we must remove the "old"
+	 * attribute/value pair.
+	 *
+	 * In a separate transaction, set the incomplete flag on the "old" attr
+	 * and clear the incomplete flag on the "new" attr.
+	 */
 
-			error = xfs_attr_rmtval_remove(args);
-			if (error)
-				return error;
-		}
+	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;
 
-		/*
-		 * Read in the block containing the "old" attr, then
-		 * remove the "old" attr from that block (neat, huh!)
-		 */
-		error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno,
-					   &bp);
+	/*
+	 * Dismantle the "old" attribute/value pair by removing a "remote" value
+	 * (if it exists).
+	 */
+	xfs_attr_restore_rmt_blk(args);
+
+	if (args->rmtblkno) {
+		error = xfs_attr_rmtval_invalidate(args);
  		if (error)
  			return error;
 
-		xfs_attr3_leaf_remove(bp, args);
-
-		/*
-		 * If the result is small enough, shrink it all into the inode.
-		 */
-		if ((forkoff = xfs_attr_shortform_allfit(bp, dp))) {
-			error = xfs_attr3_leaf_to_shortform(bp, args, forkoff);
-			/* bp is gone due to xfs_da_shrink_inode */
-			if (error)
-				return error;
-		}
-
-	} else if (args->rmtblkno > 0) {
-		/*
-		 * Added a "remote" value, just clear the incomplete flag.
-		 */
-		error = xfs_attr3_leaf_clearflag(args);
+		error = xfs_attr_rmtval_remove(args);
  		if (error)
  			return error;
  	}
+
+	/*
+	 * Read in the block containing the "old" attr, then remove the "old"
+	 * attr from that block (neat, huh!)
+	 */
+	error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno,
+				   &bp);
+	if (error)
+		return error;
+
+	xfs_attr3_leaf_remove(bp, args);
+
+	/*
+	 * If the result is small enough, shrink it all into the inode.
+	 */
+	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 */
+
  	return error;
  }
 
Signature · 1 line
2.7.4
#52 lore raw

PATCH v9 20/24 xfs: Simplify xfs_attr_node_addname

In reply to Allison Collins

Quick patch to unnest the rename logic in the node code path. This will help simplify delayed attr logic later.

---
 fs/xfs/libxfs/xfs_attr.c | 131 +++++++++++++++++++++++------------------------
 1 file changed, 64 insertions(+), 67 deletions(-)
fs/xfs/libxfs/xfs_attr.c +64 -67
index 1810f90..9171895 100644
@@ -1030,83 +1030,80 @@ xfs_attr_node_addname(
 			return error;
 	}
 
-	/*
-	 * If this is an atomic rename operation, we must "flip" the
-	 * incomplete flags on the "new" and "old" attribute/value pairs
-	 * so that one disappears and one appears atomically.  Then we
-	 * must remove the "old" attribute/value pair.
-	 */
-	if (args->op_flags & XFS_DA_OP_RENAME) {
-		/*
-		 * In a separate transaction, set the incomplete flag on the
-		 * "old" attr and clear the incomplete flag on the "new" attr.
-		 */
-		error = xfs_attr3_leaf_flipflags(args);
-		if (error)
-			goto out;
+	if ((args->op_flags & XFS_DA_OP_RENAME) == 0) {
 		/*
-		 * Commit the flag value change and start the next trans in
-		 * series
+		 * Added a "remote" value, just clear the incomplete flag.
 		 */
-		error = xfs_trans_roll_inode(&args->trans, args->dp);
-		if (error)
-			goto out;
+		if (args->rmtblkno > 0)
+			error = xfs_attr3_leaf_clearflag(args);
+		retval = error;
+		goto out;
+	}
 
-		/*
-		 * Dismantle the "old" attribute/value pair by removing
-		 * a "remote" value (if it exists).
-		 */
-		xfs_attr_restore_rmt_blk(args);
+	/*
+	 * If this is an atomic rename operation, we must "flip" the incomplete
+	 * flags on the "new" and "old" attribute/value pairs so that one
+	 * disappears and one appears atomically.  Then we must remove the "old"
+	 * attribute/value pair.
+	 *
+	 * In a separate transaction, set the incomplete flag on the "old" attr
+	 * and clear the incomplete flag on the "new" attr.
+	 */
+	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;
 
-		if (args->rmtblkno) {
-			error = xfs_attr_rmtval_invalidate(args);
-			if (error)
-				return error;
+	/*
+	 * Dismantle the "old" attribute/value pair by removing a "remote" value
+	 * (if it exists).
+	 */
+	xfs_attr_restore_rmt_blk(args);
 
-			error = xfs_attr_rmtval_remove(args);
-			if (error)
-				return error;
-		}
+	if (args->rmtblkno) {
+		error = xfs_attr_rmtval_invalidate(args);
+		if (error)
+			return error;
 
-		/*
-		 * Re-find the "old" attribute entry after any split ops.
-		 * The INCOMPLETE flag means that we will find the "old"
-		 * attr, not the "new" one.
-		 */
-		args->attr_filter |= XFS_ATTR_INCOMPLETE;
-		state = xfs_da_state_alloc();
-		state->args = args;
-		state->mp = mp;
-		state->inleaf = 0;
-		error = xfs_da3_node_lookup_int(state, &retval);
+		error = xfs_attr_rmtval_remove(args);
 		if (error)
-			goto out;
+			return error;
+	}
 
-		/*
-		 * Remove the name and update the hashvals in the tree.
-		 */
-		blk = &state->path.blk[ state->path.active-1 ];
-		ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
-		error = xfs_attr3_leaf_remove(blk->bp, args);
-		xfs_da3_fixhashpath(state, &state->path);
+	/*
+	 * Re-find the "old" attribute entry after any split ops. The INCOMPLETE
+	 * flag means that we will find the "old" attr, not the "new" one.
+	 */
+	args->attr_filter |= XFS_ATTR_INCOMPLETE;
+	state = xfs_da_state_alloc();
+	state->args = args;
+	state->mp = mp;
+	state->inleaf = 0;
+	error = xfs_da3_node_lookup_int(state, &retval);
+	if (error)
+		goto out;
 
-		/*
-		 * Check to see if the tree needs to be collapsed.
-		 */
-		if (retval && (state->path.active > 1)) {
-			error = xfs_da3_join(state);
-			if (error)
-				goto out;
-			error = xfs_defer_finish(&args->trans);
-			if (error)
-				goto out;
-		}
+	/*
+	 * Remove the name and update the hashvals in the tree.
+	 */
+	blk = &state->path.blk[state->path.active-1];
+	ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
+	error = xfs_attr3_leaf_remove(blk->bp, args);
+	xfs_da3_fixhashpath(state, &state->path);
 
-	} else if (args->rmtblkno > 0) {
-		/*
-		 * Added a "remote" value, just clear the incomplete flag.
-		 */
-		error = xfs_attr3_leaf_clearflag(args);
+	/*
+	 * Check to see if the tree needs to be collapsed.
+	 */
+	if (retval && (state->path.active > 1)) {
+		error = xfs_da3_join(state);
+		if (error)
+			goto out;
+		error = xfs_defer_finish(&args->trans);
 		if (error)
 			goto out;
 	}
Signature · 1 line
2.7.4
#53 lore raw

Re: [PATCH v9 20/24] xfs: Simplify xfs_attr_node_addname

Quoted 21 lines · Allison Collins

Quick patch to unnest the rename logic in the node code path. This will help simplify delayed attr logic later.

---
 fs/xfs/libxfs/xfs_attr.c | 131 +++++++++++++++++++++++------------------------
 1 file changed, 64 insertions(+), 67 deletions(-)
fs/xfs/libxfs/xfs_attr.c +0 -5
index 1810f90..9171895 100644
@@ -1030,83 +1030,80 @@ xfs_attr_node_addname(
 			return error;
 	}
 
-	/*
-	 * If this is an atomic rename operation, we must "flip" the
-	 * incomplete flags on the "new" and "old" attribute/value pairs
-	 * so that one disappears and one appears atomically.  Then we
-	 * must remove the "old" attribute/value pair.

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

Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +1 -9
-	 */
-	if (args->op_flags & XFS_DA_OP_RENAME) {
-		/*
-		 * In a separate transaction, set the incomplete flag on the
-		 * "old" attr and clear the incomplete flag on the "new" attr.
-		 */
-		error = xfs_attr3_leaf_flipflags(args);
-		if (error)
-			goto out;
+	if ((args->op_flags & XFS_DA_OP_RENAME) == 0) {

Same comments about the commit message and the if test as the previous patch.

Admittedly I'm now starting to wonder if this patch and the previous one should really just hoist the taken and not-taken branches into separate functions, but maybe you've already gone around and around on that, and everyone else already thought we have too many small functions...

--D

Quoted 132 lines
fs/xfs/libxfs/xfs_attr.c +63 -53
 		/*
-		 * Commit the flag value change and start the next trans in
-		 * series
+		 * Added a "remote" value, just clear the incomplete flag.
 		 */
-		error = xfs_trans_roll_inode(&args->trans, args->dp);
-		if (error)
-			goto out;
+		if (args->rmtblkno > 0)
+			error = xfs_attr3_leaf_clearflag(args);
+		retval = error;
+		goto out;
+	}
 
-		/*
-		 * Dismantle the "old" attribute/value pair by removing
-		 * a "remote" value (if it exists).
-		 */
-		xfs_attr_restore_rmt_blk(args);
+	/*
+	 * If this is an atomic rename operation, we must "flip" the incomplete
+	 * flags on the "new" and "old" attribute/value pairs so that one
+	 * disappears and one appears atomically.  Then we must remove the "old"
+	 * attribute/value pair.
+	 *
+	 * In a separate transaction, set the incomplete flag on the "old" attr
+	 * and clear the incomplete flag on the "new" attr.
+	 */
+	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;
 
-		if (args->rmtblkno) {
-			error = xfs_attr_rmtval_invalidate(args);
-			if (error)
-				return error;
+	/*
+	 * Dismantle the "old" attribute/value pair by removing a "remote" value
+	 * (if it exists).
+	 */
+	xfs_attr_restore_rmt_blk(args);
 
-			error = xfs_attr_rmtval_remove(args);
-			if (error)
-				return error;
-		}
+	if (args->rmtblkno) {
+		error = xfs_attr_rmtval_invalidate(args);
+		if (error)
+			return error;
 
-		/*
-		 * Re-find the "old" attribute entry after any split ops.
-		 * The INCOMPLETE flag means that we will find the "old"
-		 * attr, not the "new" one.
-		 */
-		args->attr_filter |= XFS_ATTR_INCOMPLETE;
-		state = xfs_da_state_alloc();
-		state->args = args;
-		state->mp = mp;
-		state->inleaf = 0;
-		error = xfs_da3_node_lookup_int(state, &retval);
+		error = xfs_attr_rmtval_remove(args);
 		if (error)
-			goto out;
+			return error;
+	}
 
-		/*
-		 * Remove the name and update the hashvals in the tree.
-		 */
-		blk = &state->path.blk[ state->path.active-1 ];
-		ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
-		error = xfs_attr3_leaf_remove(blk->bp, args);
-		xfs_da3_fixhashpath(state, &state->path);
+	/*
+	 * Re-find the "old" attribute entry after any split ops. The INCOMPLETE
+	 * flag means that we will find the "old" attr, not the "new" one.
+	 */
+	args->attr_filter |= XFS_ATTR_INCOMPLETE;
+	state = xfs_da_state_alloc();
+	state->args = args;
+	state->mp = mp;
+	state->inleaf = 0;
+	error = xfs_da3_node_lookup_int(state, &retval);
+	if (error)
+		goto out;
 
-		/*
-		 * Check to see if the tree needs to be collapsed.
-		 */
-		if (retval && (state->path.active > 1)) {
-			error = xfs_da3_join(state);
-			if (error)
-				goto out;
-			error = xfs_defer_finish(&args->trans);
-			if (error)
-				goto out;
-		}
+	/*
+	 * Remove the name and update the hashvals in the tree.
+	 */
+	blk = &state->path.blk[state->path.active-1];
+	ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
+	error = xfs_attr3_leaf_remove(blk->bp, args);
+	xfs_da3_fixhashpath(state, &state->path);
 
-	} else if (args->rmtblkno > 0) {
-		/*
-		 * Added a "remote" value, just clear the incomplete flag.
-		 */
-		error = xfs_attr3_leaf_clearflag(args);
+	/*
+	 * Check to see if the tree needs to be collapsed.
+	 */
+	if (retval && (state->path.active > 1)) {
+		error = xfs_da3_join(state);
+		if (error)
+			goto out;
+		error = xfs_defer_finish(&args->trans);
 		if (error)
 			goto out;
 	}
Signature · 1 line
2.7.4
#54 lore raw

Re: [PATCH v9 20/24] xfs: Simplify xfs_attr_node_addname

Quoted 36 lines · Darrick J. Wong
Quoted 21 lines · Allison Collins

Quick patch to unnest the rename logic in the node code path. This will help simplify delayed attr logic later.

---
  fs/xfs/libxfs/xfs_attr.c | 131 +++++++++++++++++++++++------------------------
  1 file changed, 64 insertions(+), 67 deletions(-)
fs/xfs/libxfs/xfs_attr.c +0 -5
index 1810f90..9171895 100644
@@ -1030,83 +1030,80 @@ xfs_attr_node_addname(
  			return error;
  	}
 
-	/*
-	 * If this is an atomic rename operation, we must "flip" the
-	 * incomplete flags on the "new" and "old" attribute/value pairs
-	 * so that one disappears and one appears atomically.  Then we
-	 * must remove the "old" attribute/value pair.

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

Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +1 -9
-	 */
-	if (args->op_flags & XFS_DA_OP_RENAME) {
-		/*
-		 * In a separate transaction, set the incomplete flag on the
-		 * "old" attr and clear the incomplete flag on the "new" attr.
-		 */
-		error = xfs_attr3_leaf_flipflags(args);
-		if (error)
-			goto out;
+	if ((args->op_flags & XFS_DA_OP_RENAME) == 0) {

Same comments about the commit message and the if test as the previous patch.

Quoted 4 lines

Admittedly I'm now starting to wonder if this patch and the previous one should really just hoist the taken and not-taken branches into separate functions, but maybe you've already gone around and around on that, and everyone else already thought we have too many small functions...

Yes, I had played with that and even suggested it myself in the last review. What I didnt like about it after prototyping it, was having to plumb around the leaf_bp that is still needed for a rename, and also the state machine logic ends up getting plumbed downward, instead of trying to keep it up in one high level function.

Really the initial motivation for this patch was to just avoid putting xfs_das_* labels in the middle of if{} statements or loops when we get further down the set. With that goal in mind, this solution seemed like the least amount of required surgery. Though the patch itself tends to suggest a helper, I figure I'd let people consider this first before jumping to the later option which will end up with more plumbing.

Allison

Quoted 135 lines

--D

Quoted 132 lines
fs/xfs/libxfs/xfs_attr.c +63 -53
  		/*
-		 * Commit the flag value change and start the next trans in
-		 * series
+		 * Added a "remote" value, just clear the incomplete flag.
  		 */
-		error = xfs_trans_roll_inode(&args->trans, args->dp);
-		if (error)
-			goto out;
+		if (args->rmtblkno > 0)
+			error = xfs_attr3_leaf_clearflag(args);
+		retval = error;
+		goto out;
+	}
 
-		/*
-		 * Dismantle the "old" attribute/value pair by removing
-		 * a "remote" value (if it exists).
-		 */
-		xfs_attr_restore_rmt_blk(args);
+	/*
+	 * If this is an atomic rename operation, we must "flip" the incomplete
+	 * flags on the "new" and "old" attribute/value pairs so that one
+	 * disappears and one appears atomically.  Then we must remove the "old"
+	 * attribute/value pair.
+	 *
+	 * In a separate transaction, set the incomplete flag on the "old" attr
+	 * and clear the incomplete flag on the "new" attr.
+	 */
+	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;
 
-		if (args->rmtblkno) {
-			error = xfs_attr_rmtval_invalidate(args);
-			if (error)
-				return error;
+	/*
+	 * Dismantle the "old" attribute/value pair by removing a "remote" value
+	 * (if it exists).
+	 */
+	xfs_attr_restore_rmt_blk(args);
 
-			error = xfs_attr_rmtval_remove(args);
-			if (error)
-				return error;
-		}
+	if (args->rmtblkno) {
+		error = xfs_attr_rmtval_invalidate(args);
+		if (error)
+			return error;
 
-		/*
-		 * Re-find the "old" attribute entry after any split ops.
-		 * The INCOMPLETE flag means that we will find the "old"
-		 * attr, not the "new" one.
-		 */
-		args->attr_filter |= XFS_ATTR_INCOMPLETE;
-		state = xfs_da_state_alloc();
-		state->args = args;
-		state->mp = mp;
-		state->inleaf = 0;
-		error = xfs_da3_node_lookup_int(state, &retval);
+		error = xfs_attr_rmtval_remove(args);
  		if (error)
-			goto out;
+			return error;
+	}
 
-		/*
-		 * Remove the name and update the hashvals in the tree.
-		 */
-		blk = &state->path.blk[ state->path.active-1 ];
-		ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
-		error = xfs_attr3_leaf_remove(blk->bp, args);
-		xfs_da3_fixhashpath(state, &state->path);
+	/*
+	 * Re-find the "old" attribute entry after any split ops. The INCOMPLETE
+	 * flag means that we will find the "old" attr, not the "new" one.
+	 */
+	args->attr_filter |= XFS_ATTR_INCOMPLETE;
+	state = xfs_da_state_alloc();
+	state->args = args;
+	state->mp = mp;
+	state->inleaf = 0;
+	error = xfs_da3_node_lookup_int(state, &retval);
+	if (error)
+		goto out;
 
-		/*
-		 * Check to see if the tree needs to be collapsed.
-		 */
-		if (retval && (state->path.active > 1)) {
-			error = xfs_da3_join(state);
-			if (error)
-				goto out;
-			error = xfs_defer_finish(&args->trans);
-			if (error)
-				goto out;
-		}
+	/*
+	 * Remove the name and update the hashvals in the tree.
+	 */
+	blk = &state->path.blk[state->path.active-1];
+	ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
+	error = xfs_attr3_leaf_remove(blk->bp, args);
+	xfs_da3_fixhashpath(state, &state->path);
 
-	} else if (args->rmtblkno > 0) {
-		/*
-		 * Added a "remote" value, just clear the incomplete flag.
-		 */
-		error = xfs_attr3_leaf_clearflag(args);
+	/*
+	 * Check to see if the tree needs to be collapsed.
+	 */
+	if (retval && (state->path.active > 1)) {
+		error = xfs_da3_join(state);
+		if (error)
+			goto out;
+		error = xfs_defer_finish(&args->trans);
  		if (error)
  			goto out;
  	}
Signature · 1 line
2.7.4
Reviewed-by on v9 20/24
#55 lore raw

Re: [PATCH v9 20/24] xfs: Simplify xfs_attr_node_addname

In reply to Allison Collins
Quoted 32 lines · Allison Collins

Quick patch to unnest the rename logic in the node code path. This will help simplify delayed attr logic later.

---
 fs/xfs/libxfs/xfs_attr.c | 131 +++++++++++++++++++++++------------------------
 1 file changed, 64 insertions(+), 67 deletions(-)
fs/xfs/libxfs/xfs_attr.c +1 -14
index 1810f90..9171895 100644
@@ -1030,83 +1030,80 @@ xfs_attr_node_addname(
 			return error;
 	}
 
-	/*
-	 * If this is an atomic rename operation, we must "flip" the
-	 * incomplete flags on the "new" and "old" attribute/value pairs
-	 * so that one disappears and one appears atomically.  Then we
-	 * must remove the "old" attribute/value pair.
-	 */
-	if (args->op_flags & XFS_DA_OP_RENAME) {
-		/*
-		 * In a separate transaction, set the incomplete flag on the
-		 * "old" attr and clear the incomplete flag on the "new" attr.
-		 */
-		error = xfs_attr3_leaf_flipflags(args);
-		if (error)
-			goto out;
+	if ((args->op_flags & XFS_DA_OP_RENAME) == 0) {
 		/*

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

Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +4 -5
-		 * Commit the flag value change and start the next trans in
-		 * series
+		 * Added a "remote" value, just clear the incomplete flag.
 		 */
-		error = xfs_trans_roll_inode(&args->trans, args->dp);
-		if (error)
-			goto out;
+		if (args->rmtblkno > 0)
+			error = xfs_attr3_leaf_clearflag(args);
+		retval = error;

Can we just init retval to 0 and avoid this assignment? With that and similar fixups to the previous patch:

Note that I'm also of the mind to break this down into smaller functions depending on what later patches look like, but if there's more to consider around that this seems like a good step in that direction.

Brian

Quoted 121 lines
fs/xfs/libxfs/xfs_attr.c +59 -48
+		goto out;
+	}
 
-		/*
-		 * Dismantle the "old" attribute/value pair by removing
-		 * a "remote" value (if it exists).
-		 */
-		xfs_attr_restore_rmt_blk(args);
+	/*
+	 * If this is an atomic rename operation, we must "flip" the incomplete
+	 * flags on the "new" and "old" attribute/value pairs so that one
+	 * disappears and one appears atomically.  Then we must remove the "old"
+	 * attribute/value pair.
+	 *
+	 * In a separate transaction, set the incomplete flag on the "old" attr
+	 * and clear the incomplete flag on the "new" attr.
+	 */
+	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;
 
-		if (args->rmtblkno) {
-			error = xfs_attr_rmtval_invalidate(args);
-			if (error)
-				return error;
+	/*
+	 * Dismantle the "old" attribute/value pair by removing a "remote" value
+	 * (if it exists).
+	 */
+	xfs_attr_restore_rmt_blk(args);
 
-			error = xfs_attr_rmtval_remove(args);
-			if (error)
-				return error;
-		}
+	if (args->rmtblkno) {
+		error = xfs_attr_rmtval_invalidate(args);
+		if (error)
+			return error;
 
-		/*
-		 * Re-find the "old" attribute entry after any split ops.
-		 * The INCOMPLETE flag means that we will find the "old"
-		 * attr, not the "new" one.
-		 */
-		args->attr_filter |= XFS_ATTR_INCOMPLETE;
-		state = xfs_da_state_alloc();
-		state->args = args;
-		state->mp = mp;
-		state->inleaf = 0;
-		error = xfs_da3_node_lookup_int(state, &retval);
+		error = xfs_attr_rmtval_remove(args);
 		if (error)
-			goto out;
+			return error;
+	}
 
-		/*
-		 * Remove the name and update the hashvals in the tree.
-		 */
-		blk = &state->path.blk[ state->path.active-1 ];
-		ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
-		error = xfs_attr3_leaf_remove(blk->bp, args);
-		xfs_da3_fixhashpath(state, &state->path);
+	/*
+	 * Re-find the "old" attribute entry after any split ops. The INCOMPLETE
+	 * flag means that we will find the "old" attr, not the "new" one.
+	 */
+	args->attr_filter |= XFS_ATTR_INCOMPLETE;
+	state = xfs_da_state_alloc();
+	state->args = args;
+	state->mp = mp;
+	state->inleaf = 0;
+	error = xfs_da3_node_lookup_int(state, &retval);
+	if (error)
+		goto out;
 
-		/*
-		 * Check to see if the tree needs to be collapsed.
-		 */
-		if (retval && (state->path.active > 1)) {
-			error = xfs_da3_join(state);
-			if (error)
-				goto out;
-			error = xfs_defer_finish(&args->trans);
-			if (error)
-				goto out;
-		}
+	/*
+	 * Remove the name and update the hashvals in the tree.
+	 */
+	blk = &state->path.blk[state->path.active-1];
+	ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
+	error = xfs_attr3_leaf_remove(blk->bp, args);
+	xfs_da3_fixhashpath(state, &state->path);
 
-	} else if (args->rmtblkno > 0) {
-		/*
-		 * Added a "remote" value, just clear the incomplete flag.
-		 */
-		error = xfs_attr3_leaf_clearflag(args);
+	/*
+	 * Check to see if the tree needs to be collapsed.
+	 */
+	if (retval && (state->path.active > 1)) {
+		error = xfs_da3_join(state);
+		if (error)
+			goto out;
+		error = xfs_defer_finish(&args->trans);
 		if (error)
 			goto out;
 	}
Signature · 1 line
2.7.4
#56 lore raw

Re: [PATCH v9 20/24] xfs: Simplify xfs_attr_node_addname

Quoted 38 lines · Brian Foster
Quoted 37 lines · Allison Collins

Quick patch to unnest the rename logic in the node code path. This will help simplify delayed attr logic later.

---
  fs/xfs/libxfs/xfs_attr.c | 131 +++++++++++++++++++++++------------------------
  1 file changed, 64 insertions(+), 67 deletions(-)
fs/xfs/libxfs/xfs_attr.c +2 -17
index 1810f90..9171895 100644
@@ -1030,83 +1030,80 @@ xfs_attr_node_addname(
  			return error;
  	}
 
-	/*
-	 * If this is an atomic rename operation, we must "flip" the
-	 * incomplete flags on the "new" and "old" attribute/value pairs
-	 * so that one disappears and one appears atomically.  Then we
-	 * must remove the "old" attribute/value pair.
-	 */
-	if (args->op_flags & XFS_DA_OP_RENAME) {
-		/*
-		 * In a separate transaction, set the incomplete flag on the
-		 * "old" attr and clear the incomplete flag on the "new" attr.
-		 */
-		error = xfs_attr3_leaf_flipflags(args);
-		if (error)
-			goto out;
+	if ((args->op_flags & XFS_DA_OP_RENAME) == 0) {
  		/*
-		 * Commit the flag value change and start the next trans in
-		 * series
+		 * Added a "remote" value, just clear the incomplete flag.
  		 */
-		error = xfs_trans_roll_inode(&args->trans, args->dp);
Quoted 9 lines

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

Quoted 5 lines
fs/xfs/libxfs/xfs_attr.c +3 -2
-		if (error)
-			goto out;
+		if (args->rmtblkno > 0)
+			error = xfs_attr3_leaf_clearflag(args);
+		retval = error;

Can we just init retval to 0 and avoid this assignment? With that and similar fixups to the previous patch:

Sure, will do.

Quoted 5 lines

Note that I'm also of the mind to break this down into smaller functions depending on what later patches look like, but if there's more to consider around that this seems like a good step in that direction.

Sure, and that's fine too if we change our minds later. I just figured I see what people thought of this first. Thanks for the reviews!

Allison

Quoted 125 lines

Brian

Quoted 121 lines
fs/xfs/libxfs/xfs_attr.c +59 -48
+		goto out;
+	}
 
-		/*
-		 * Dismantle the "old" attribute/value pair by removing
-		 * a "remote" value (if it exists).
-		 */
-		xfs_attr_restore_rmt_blk(args);
+	/*
+	 * If this is an atomic rename operation, we must "flip" the incomplete
+	 * flags on the "new" and "old" attribute/value pairs so that one
+	 * disappears and one appears atomically.  Then we must remove the "old"
+	 * attribute/value pair.
+	 *
+	 * In a separate transaction, set the incomplete flag on the "old" attr
+	 * and clear the incomplete flag on the "new" attr.
+	 */
+	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;
 
-		if (args->rmtblkno) {
-			error = xfs_attr_rmtval_invalidate(args);
-			if (error)
-				return error;
+	/*
+	 * Dismantle the "old" attribute/value pair by removing a "remote" value
+	 * (if it exists).
+	 */
+	xfs_attr_restore_rmt_blk(args);
 
-			error = xfs_attr_rmtval_remove(args);
-			if (error)
-				return error;
-		}
+	if (args->rmtblkno) {
+		error = xfs_attr_rmtval_invalidate(args);
+		if (error)
+			return error;
 
-		/*
-		 * Re-find the "old" attribute entry after any split ops.
-		 * The INCOMPLETE flag means that we will find the "old"
-		 * attr, not the "new" one.
-		 */
-		args->attr_filter |= XFS_ATTR_INCOMPLETE;
-		state = xfs_da_state_alloc();
-		state->args = args;
-		state->mp = mp;
-		state->inleaf = 0;
-		error = xfs_da3_node_lookup_int(state, &retval);
+		error = xfs_attr_rmtval_remove(args);
  		if (error)
-			goto out;
+			return error;
+	}
 
-		/*
-		 * Remove the name and update the hashvals in the tree.
-		 */
-		blk = &state->path.blk[ state->path.active-1 ];
-		ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
-		error = xfs_attr3_leaf_remove(blk->bp, args);
-		xfs_da3_fixhashpath(state, &state->path);
+	/*
+	 * Re-find the "old" attribute entry after any split ops. The INCOMPLETE
+	 * flag means that we will find the "old" attr, not the "new" one.
+	 */
+	args->attr_filter |= XFS_ATTR_INCOMPLETE;
+	state = xfs_da_state_alloc();
+	state->args = args;
+	state->mp = mp;
+	state->inleaf = 0;
+	error = xfs_da3_node_lookup_int(state, &retval);
+	if (error)
+		goto out;
 
-		/*
-		 * Check to see if the tree needs to be collapsed.
-		 */
-		if (retval && (state->path.active > 1)) {
-			error = xfs_da3_join(state);
-			if (error)
-				goto out;
-			error = xfs_defer_finish(&args->trans);
-			if (error)
-				goto out;
-		}
+	/*
+	 * Remove the name and update the hashvals in the tree.
+	 */
+	blk = &state->path.blk[state->path.active-1];
+	ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
+	error = xfs_attr3_leaf_remove(blk->bp, args);
+	xfs_da3_fixhashpath(state, &state->path);
 
-	} else if (args->rmtblkno > 0) {
-		/*
-		 * Added a "remote" value, just clear the incomplete flag.
-		 */
-		error = xfs_attr3_leaf_clearflag(args);
+	/*
+	 * Check to see if the tree needs to be collapsed.
+	 */
+	if (retval && (state->path.active > 1)) {
+		error = xfs_da3_join(state);
+		if (error)
+			goto out;
+		error = xfs_defer_finish(&args->trans);
  		if (error)
  			goto out;
  	}
Signature · 1 line
2.7.4
#57 lore raw

PATCH v9 21/24 xfs: Lift -ENOSPC handler from xfs_attr_leaf_addname

In reply to Allison Collins

Lift -ENOSPC handler from xfs_attr_leaf_addname. This will help to reorganize transitions between the attr forms later.

---
 fs/xfs/libxfs/xfs_attr.c | 25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)
fs/xfs/libxfs/xfs_attr.c +11 -14
index 9171895..c8cae68 100644
@@ -299,6 +299,13 @@ xfs_attr_set_args(
 			return error;
 
 		/*
+		 * Promote the attribute list to the Btree format.
+		 */
+		error = xfs_attr3_leaf_to_node(args);
+		if (error)
+			return error;
+
+		/*
 		 * Commit that transaction so that the node_addname()
 		 * call can manage its own transactions.
 		 */
@@ -602,7 +609,7 @@ xfs_attr_leaf_try_add(
 	struct xfs_da_args	*args,
 	struct xfs_buf		*bp)
 {
-	int			retval, error;
+	int			retval;
 
 	/*
 	 * Look up the given attribute in the leaf block.  Figure out if
@@ -634,20 +641,10 @@ xfs_attr_leaf_try_add(
 	}
 
 	/*
-	 * Add the attribute to the leaf block, transitioning to a Btree
-	 * if required.
+	 * Add the attribute to the leaf block
 	 */
-	retval = xfs_attr3_leaf_add(bp, args);
-	if (retval == -ENOSPC) {
-		/*
-		 * Promote the attribute list to the Btree format. Unless an
-		 * error occurs, retain the -ENOSPC retval
-		 */
-		error = xfs_attr3_leaf_to_node(args);
-		if (error)
-			return error;
-	}
-	return retval;
+	return xfs_attr3_leaf_add(bp, args);
+
 out_brelse:
 	xfs_trans_brelse(args->trans, bp);
 	return retval;
Signature · 1 line
2.7.4
Reviewed-by on v9 21/24
#58 lore raw

Re: [PATCH v9 21/24] xfs: Lift -ENOSPC handler from xfs_attr_leaf_addname

Quoted 4 lines · Allison Collins

Lift -ENOSPC handler from xfs_attr_leaf_addname. This will help to reorganize transitions between the attr forms later.

Looks decent,

--D

Quoted 58 lines
---
 fs/xfs/libxfs/xfs_attr.c | 25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)
fs/xfs/libxfs/xfs_attr.c +11 -14
index 9171895..c8cae68 100644
@@ -299,6 +299,13 @@ xfs_attr_set_args(
 			return error;
 
 		/*
+		 * Promote the attribute list to the Btree format.
+		 */
+		error = xfs_attr3_leaf_to_node(args);
+		if (error)
+			return error;
+
+		/*
 		 * Commit that transaction so that the node_addname()
 		 * call can manage its own transactions.
 		 */
@@ -602,7 +609,7 @@ xfs_attr_leaf_try_add(
 	struct xfs_da_args	*args,
 	struct xfs_buf		*bp)
 {
-	int			retval, error;
+	int			retval;
 
 	/*
 	 * Look up the given attribute in the leaf block.  Figure out if
@@ -634,20 +641,10 @@ xfs_attr_leaf_try_add(
 	}
 
 	/*
-	 * Add the attribute to the leaf block, transitioning to a Btree
-	 * if required.
+	 * Add the attribute to the leaf block
 	 */
-	retval = xfs_attr3_leaf_add(bp, args);
-	if (retval == -ENOSPC) {
-		/*
-		 * Promote the attribute list to the Btree format. Unless an
-		 * error occurs, retain the -ENOSPC retval
-		 */
-		error = xfs_attr3_leaf_to_node(args);
-		if (error)
-			return error;
-	}
-	return retval;
+	return xfs_attr3_leaf_add(bp, args);
+
 out_brelse:
 	xfs_trans_brelse(args->trans, bp);
 	return retval;
Signature · 1 line
2.7.4
#59 lore raw

Re: [PATCH v9 21/24] xfs: Lift -ENOSPC handler from xfs_attr_leaf_addname

Quoted 9 lines · Darrick J. Wong
Quoted 4 lines · Allison Collins

Lift -ENOSPC handler from xfs_attr_leaf_addname. This will help to reorganize transitions between the attr forms later.

Looks decent,

Ok, thank you!

Allison

Quoted 60 lines

--D

Quoted 58 lines
---
  fs/xfs/libxfs/xfs_attr.c | 25 +++++++++++--------------
  1 file changed, 11 insertions(+), 14 deletions(-)
fs/xfs/libxfs/xfs_attr.c +11 -14
index 9171895..c8cae68 100644
@@ -299,6 +299,13 @@ xfs_attr_set_args(
  			return error;
 
  		/*
+		 * Promote the attribute list to the Btree format.
+		 */
+		error = xfs_attr3_leaf_to_node(args);
+		if (error)
+			return error;
+
+		/*
  		 * Commit that transaction so that the node_addname()
  		 * call can manage its own transactions.
  		 */
@@ -602,7 +609,7 @@ xfs_attr_leaf_try_add(
  	struct xfs_da_args	*args,
  	struct xfs_buf		*bp)
  {
-	int			retval, error;
+	int			retval;
 
  	/*
  	 * Look up the given attribute in the leaf block.  Figure out if
@@ -634,20 +641,10 @@ xfs_attr_leaf_try_add(
  	}
 
  	/*
-	 * Add the attribute to the leaf block, transitioning to a Btree
-	 * if required.
+	 * Add the attribute to the leaf block
  	 */
-	retval = xfs_attr3_leaf_add(bp, args);
-	if (retval == -ENOSPC) {
-		/*
-		 * Promote the attribute list to the Btree format. Unless an
-		 * error occurs, retain the -ENOSPC retval
-		 */
-		error = xfs_attr3_leaf_to_node(args);
-		if (error)
-			return error;
-	}
-	return retval;
+	return xfs_attr3_leaf_add(bp, args);
+
  out_brelse:
  	xfs_trans_brelse(args->trans, bp);
  	return retval;
Signature · 1 line
2.7.4
Reviewed-by on v9 21/24
#60 lore raw

Re: [PATCH v9 21/24] xfs: Lift -ENOSPC handler from xfs_attr_leaf_addname

In reply to Allison Collins
Quoted 5 lines · Allison Collins

Lift -ENOSPC handler from xfs_attr_leaf_addname. This will help to reorganize transitions between the attr forms later.

---

Quoted 57 lines
 fs/xfs/libxfs/xfs_attr.c | 25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)
fs/xfs/libxfs/xfs_attr.c +11 -14
index 9171895..c8cae68 100644
@@ -299,6 +299,13 @@ xfs_attr_set_args(
 			return error;
 
 		/*
+		 * Promote the attribute list to the Btree format.
+		 */
+		error = xfs_attr3_leaf_to_node(args);
+		if (error)
+			return error;
+
+		/*
 		 * Commit that transaction so that the node_addname()
 		 * call can manage its own transactions.
 		 */
@@ -602,7 +609,7 @@ xfs_attr_leaf_try_add(
 	struct xfs_da_args	*args,
 	struct xfs_buf		*bp)
 {
-	int			retval, error;
+	int			retval;
 
 	/*
 	 * Look up the given attribute in the leaf block.  Figure out if
@@ -634,20 +641,10 @@ xfs_attr_leaf_try_add(
 	}
 
 	/*
-	 * Add the attribute to the leaf block, transitioning to a Btree
-	 * if required.
+	 * Add the attribute to the leaf block
 	 */
-	retval = xfs_attr3_leaf_add(bp, args);
-	if (retval == -ENOSPC) {
-		/*
-		 * Promote the attribute list to the Btree format. Unless an
-		 * error occurs, retain the -ENOSPC retval
-		 */
-		error = xfs_attr3_leaf_to_node(args);
-		if (error)
-			return error;
-	}
-	return retval;
+	return xfs_attr3_leaf_add(bp, args);
+
 out_brelse:
 	xfs_trans_brelse(args->trans, bp);
 	return retval;
Signature · 1 line
2.7.4
#61 lore raw

Re: [PATCH v9 21/24] xfs: Lift -ENOSPC handler from xfs_attr_leaf_addname

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

Lift -ENOSPC handler from xfs_attr_leaf_addname. This will help to reorganize transitions between the attr forms later.

---

Thank you!
Allison

Quoted 59 lines
Quoted 58 lines
  fs/xfs/libxfs/xfs_attr.c | 25 +++++++++++--------------
  1 file changed, 11 insertions(+), 14 deletions(-)
fs/xfs/libxfs/xfs_attr.c +11 -14
index 9171895..c8cae68 100644
@@ -299,6 +299,13 @@ xfs_attr_set_args(
  			return error;
 
  		/*
+		 * Promote the attribute list to the Btree format.
+		 */
+		error = xfs_attr3_leaf_to_node(args);
+		if (error)
+			return error;
+
+		/*
  		 * Commit that transaction so that the node_addname()
  		 * call can manage its own transactions.
  		 */
@@ -602,7 +609,7 @@ xfs_attr_leaf_try_add(
  	struct xfs_da_args	*args,
  	struct xfs_buf		*bp)
  {
-	int			retval, error;
+	int			retval;
 
  	/*
  	 * Look up the given attribute in the leaf block.  Figure out if
@@ -634,20 +641,10 @@ xfs_attr_leaf_try_add(
  	}
 
  	/*
-	 * Add the attribute to the leaf block, transitioning to a Btree
-	 * if required.
+	 * Add the attribute to the leaf block
  	 */
-	retval = xfs_attr3_leaf_add(bp, args);
-	if (retval == -ENOSPC) {
-		/*
-		 * Promote the attribute list to the Btree format. Unless an
-		 * error occurs, retain the -ENOSPC retval
-		 */
-		error = xfs_attr3_leaf_to_node(args);
-		if (error)
-			return error;
-	}
-	return retval;
+	return xfs_attr3_leaf_add(bp, args);
+
  out_brelse:
  	xfs_trans_brelse(args->trans, bp);
  	return retval;
Signature · 1 line
2.7.4
#62 lore raw

PATCH v9 22/24 xfs: Add delay ready attr remove routines

In reply to Allison Collins

This patch modifies the attr remove routines to be delay ready. This means they no longer roll or commit transactions, but instead return -EAGAIN to have the calling routine roll and refresh the transaction. In this series, xfs_attr_remove_args has become xfs_attr_remove_iter, which uses a sort of state machine like switch to keep track of where it was when EAGAIN was returned. xfs_attr_node_removename has also been modified to use the switch, and a new version of xfs_attr_remove_args consists of a simple loop to refresh the transaction until the operation is completed. A new XFS_DAC_DEFER_FINISH flag is used to finish the transaction where ever the existing code used to.

Calls to xfs_attr_rmtval_remove are replaced with the delay ready version __xfs_attr_rmtval_remove. We will rename __xfs_attr_rmtval_remove back to xfs_attr_rmtval_remove when we are done.

xfs_attr_rmtval_remove itself is still in use by the set routines (used during a rename). For reasons of perserving existing function, we modify xfs_attr_rmtval_remove to call xfs_defer_finish when the flag is set. Similar to how xfs_attr_remove_args does here. Once we transition the set routines to be delay ready, xfs_attr_rmtval_remove is no longer used and will be removed.

This patch also adds a new struct xfs_delattr_context, which we will use to keep track of the current state of an attribute operation. The new xfs_delattr_state enum 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.

Below is a state machine diagram for attr remove operations. The XFS_DAS_* states indicate places where the function would return -EAGAIN, and then immediately resume from after being recalled by the calling function. States marked as a "subroutine state" indicate that they belong to a subroutine, and so the calling function needs to pass them back to that subroutine to allow it to finish where it left off. But they otherwise do not have a role in the calling function other than just passing through.

xfs_attr_remove_iter()

         XFS_DAS_RM_SHRINK     ─┐
         (subroutine state)     │
                                └─>xfs_attr_node_removename()
                                                 │

v
need to
shrink tree? ─n─┐
│ │
y │
│ │
v │
XFS_DAS_RM_SHRINK │
│ │
v │
done <─────┘

---
 fs/xfs/libxfs/xfs_attr.c        | 159 ++++++++++++++++++++++++++++++----------
 fs/xfs/libxfs/xfs_attr.h        |  73 ++++++++++++++++++
 fs/xfs/libxfs/xfs_attr_leaf.c   |   2 +-
 fs/xfs/libxfs/xfs_attr_remote.c |  31 ++++----
 fs/xfs/libxfs/xfs_attr_remote.h |   2 +-
 fs/xfs/xfs_attr_inactive.c      |   2 +-
 6 files changed, 215 insertions(+), 54 deletions(-)
fs/xfs/libxfs/xfs_attr.c +121 -38
index c8cae68..7213589 100644
@@ -53,12 +53,21 @@ STATIC int xfs_attr_leaf_hasname(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_attr_node_removename(xfs_da_args_t *args);
+STATIC int xfs_attr_node_removename(struct xfs_delattr_context *dac);
 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);
 
+void
+xfs_delattr_context_init(
+	struct xfs_delattr_context	*dac,
+	struct xfs_da_args		*args)
+{
+	memset(dac, 0, sizeof(struct xfs_delattr_context));
+	dac->da_args = args;
+}
+
 int
 xfs_inode_hasattr(
 	struct xfs_inode	*ip)
@@ -263,6 +272,18 @@ xfs_attr_set_shortform(
 	return 0;
 }
 
+int xfs_attr_defer_finish(
+	struct xfs_delattr_context      *dac)
+{
+	struct xfs_da_args              *args = dac->da_args;
+
+	if (!(dac->flags & XFS_DAC_DEFER_FINISH))
+		return 0;
+
+	dac->flags &= ~XFS_DAC_DEFER_FINISH;
+	return xfs_defer_finish(&args->trans);
+}
+
 /*
  * Set the attribute specified in @args.
  */
@@ -363,23 +384,57 @@ xfs_has_attr(
  */
 int
 xfs_attr_remove_args(
-	struct xfs_da_args      *args)
+	struct xfs_da_args	*args)
+{
+	int			error = 0;
+	struct			xfs_delattr_context dac;
+
+	xfs_delattr_context_init(&dac, args);
+
+	do {
+		error = xfs_attr_remove_iter(&dac);
+		if (error != -EAGAIN)
+			break;
+
+		error = xfs_attr_defer_finish(&dac);
+		if (error)
+			break;
+
+		error = xfs_trans_roll_inode(&args->trans, args->dp);
+		if (error)
+			break;
+	} while (true);
+
+	return error;
+}
+
+/*
+ * Remove the attribute specified in @args.
+ *
+ * This function may return -EAGAIN to signal that the transaction needs to be
+ * rolled.  Callers should continue calling this function until they receive a
+ * return value other than -EAGAIN.
+ */
+int
+xfs_attr_remove_iter(
+	struct xfs_delattr_context *dac)
 {
+	struct xfs_da_args	*args = dac->da_args;
 	struct xfs_inode	*dp = args->dp;
-	int			error;
+
+	if (dac->dela_state == XFS_DAS_RM_SHRINK)
+		goto node;
 
 	if (!xfs_inode_hasattr(dp)) {
-		error = -ENOATTR;
+		return -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);
+		return xfs_attr_shortform_remove(args);
 	} else if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
-		error = xfs_attr_leaf_removename(args);
-	} else {
-		error = xfs_attr_node_removename(args);
+		return xfs_attr_leaf_removename(args);
 	}
-
-	return error;
+node:
+	return  xfs_attr_node_removename(dac);
 }
 
 /*
@@ -1177,15 +1232,17 @@ xfs_attr_leaf_mark_incomplete(
 
 /*
  * Initial setup for xfs_attr_node_removename.  Make sure the attr is there and
- * the blocks are valid.  Any remote blocks will be marked incomplete.
+ * the blocks are valid.  Any remote blocks will be marked incomplete and
+ * invalidated.
  */
 STATIC
 int xfs_attr_node_removename_setup(
-	struct xfs_da_args	*args,
-	struct xfs_da_state	**state)
+	struct xfs_delattr_context	*dac,
+	struct xfs_da_state		**state)
 {
-	int			error;
-	struct xfs_da_state_blk	*blk;
+	struct xfs_da_args		*args = dac->da_args;
+	int				error;
+	struct xfs_da_state_blk		*blk;
 
 	error = xfs_attr_node_hasname(args, state);
 	if (error != -EEXIST)
@@ -1195,6 +1252,13 @@ int xfs_attr_node_removename_setup(
 	ASSERT(blk->bp != NULL);
 	ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
 
+	/*
+	 * Store blk and state in the context incase we need to cycle out the
+	 * transaction
+	 */
+	dac->blk = blk;
+	dac->da_state = *state;
+
 	if (args->rmtblkno > 0) {
 		error = xfs_attr_leaf_mark_incomplete(args, *state);
 		if (error)
@@ -1210,12 +1274,15 @@ int xfs_attr_node_removename_setup(
 
 STATIC int
 xfs_attr_node_removename_rmt (
-	struct xfs_da_args	*args,
-	struct xfs_da_state	*state)
+	struct xfs_delattr_context	*dac,
+	struct xfs_da_state		*state)
 {
-	int			error = 0;
+	int				error = 0;
 
-	error = xfs_attr_rmtval_remove(args);
+	/*
+	 * May return -EAGAIN to request that the caller recall this function
+	 */
+	error = __xfs_attr_rmtval_remove(dac);
 	if (error)
 		return error;
 
@@ -1232,21 +1299,35 @@ xfs_attr_node_removename_rmt (
  * 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 either an inline or delayed operation,
+ * and may return -EAGAIN 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_attr_node_removename(
-	struct xfs_da_args	*args)
+	struct xfs_delattr_context	*dac)
 {
-	struct xfs_da_state	*state;
-	struct xfs_da_state_blk	*blk;
-	int			retval, error;
-	struct xfs_inode	*dp = args->dp;
+	struct xfs_da_args		*args = dac->da_args;
+	struct xfs_da_state		*state;
+	struct xfs_da_state_blk		*blk;
+	int				retval, error;
+	struct xfs_inode		*dp = args->dp;
 
 	trace_xfs_attr_node_removename(args);
+	state = dac->da_state;
+	blk = dac->blk;
 
-	error = xfs_attr_node_removename_setup(args, &state);
-	if (error)
-		goto out;
+	if (dac->dela_state == XFS_DAS_RM_SHRINK)
+		goto das_rm_shrink;
+
+	if ((dac->flags & XFS_DAC_NODE_RMVNAME_INIT) == 0) {
+		dac->flags |= XFS_DAC_NODE_RMVNAME_INIT;
+		error = xfs_attr_node_removename_setup(dac, &state);
+		if (error)
+			goto out;
+	}
 
 	/*
 	 * If there is an out-of-line value, de-allocate the blocks.
@@ -1254,8 +1335,13 @@ xfs_attr_node_removename(
 	 * overflow the maximum size of a transaction and/or hit a deadlock.
 	 */
 	if (args->rmtblkno > 0) {
-		error = xfs_attr_node_removename_rmt(args, state);
-		if (error)
+		/*
+		 * May return -EAGAIN. Remove blocks until args->rmtblkno == 0
+		 */
+		error = xfs_attr_node_removename_rmt(dac, state);
+		if (error == -EAGAIN)
+			return error;
+		else if (error)
 			goto out;
 	}
 
@@ -1274,17 +1360,14 @@ xfs_attr_node_removename(
 		error = xfs_da3_join(state);
 		if (error)
 			goto out;
-		error = xfs_defer_finish(&args->trans);
-		if (error)
-			goto out;
-		/*
-		 * Commit the Btree join operation and start a new trans.
-		 */
-		error = xfs_trans_roll_inode(&args->trans, dp);
-		if (error)
-			goto out;
+
+		dac->flags |= XFS_DAC_DEFER_FINISH;
+		dac->dela_state = XFS_DAS_RM_SHRINK;
+		return -EAGAIN;
 	}
 
+das_rm_shrink:
+
 	/*
 	 * If the result is small enough, push it all into the inode.
 	 */
fs/xfs/libxfs/xfs_attr.h +73 -0

85 lines not on this page · raw message

fs/xfs/libxfs/xfs_attr_leaf.c +1 -1
index f55402b..2e36c8b 100644
@@ -19,8 +19,8 @@
 #include "xfs_bmap_btree.h"
 #include "xfs_bmap.h"
 #include "xfs_attr_sf.h"
-#include "xfs_attr_remote.h"
 #include "xfs_attr.h"
+#include "xfs_attr_remote.h"
 #include "xfs_attr_leaf.h"
 #include "xfs_error.h"
 #include "xfs_trace.h"
fs/xfs/libxfs/xfs_attr_remote.c +18 -13
index f770159..f2d46c7 100644
@@ -676,14 +676,16 @@ xfs_attr_rmtval_invalidate(
  */
 int
 xfs_attr_rmtval_remove(
-	struct xfs_da_args      *args)
+	struct xfs_da_args		*args)
 {
-	xfs_dablk_t		lblkno;
-	int			blkcnt;
-	int			error = 0;
-	int			retval = 0;
+	struct xfs_delattr_context	dac;
+	xfs_dablk_t			lblkno;
+	int				blkcnt;
+	int				error = 0;
+	int				retval = 0;
 
 	trace_xfs_attr_rmtval_remove(args);
+	xfs_delattr_context_init(&dac, args);
 
 	/*
 	 * Keep de-allocating extents until the remote-value region is gone.
@@ -691,10 +693,14 @@ xfs_attr_rmtval_remove(
 	lblkno = args->rmtblkno;
 	blkcnt = args->rmtblkcnt;
 	do {
-		retval = __xfs_attr_rmtval_remove(args);
+		retval = __xfs_attr_rmtval_remove(&dac);
 		if (retval && retval != EAGAIN)
 			return retval;
 
+		error = xfs_attr_defer_finish(&dac);
+		if (error)
+			break;
+
 		/*
 		 * Close out trans and start the next one in the chain.
 		 */
@@ -713,9 +719,10 @@ xfs_attr_rmtval_remove(
  */
 int
 __xfs_attr_rmtval_remove(
-	struct xfs_da_args	*args)
+	struct xfs_delattr_context	*dac)
 {
-	int			error, done;
+	struct xfs_da_args		*args = dac->da_args;
+	int				error, done;
 
 	/*
 	 * Unmap value blocks for this attr.
@@ -725,12 +732,10 @@ __xfs_attr_rmtval_remove(
 	if (error)
 		return error;
 
-	error = xfs_defer_finish(&args->trans);
-	if (error)
-		return error;
-
-	if (!done)
+	if (!done) {
+		dac->flags &= ~XFS_DAC_DEFER_FINISH;
 		return -EAGAIN;
+	}
 
 	return error;
 }
fs/xfs/libxfs/xfs_attr_remote.h +1 -1
index ee3337b..351da00 100644
@@ -14,5 +14,5 @@ int xfs_attr_rmtval_remove(struct xfs_da_args *args);
 int xfs_attr_rmtval_stale(struct xfs_inode *ip, struct xfs_bmbt_irec *map,
 		xfs_buf_flags_t incore_flags);
 int xfs_attr_rmtval_invalidate(struct xfs_da_args *args);
-int __xfs_attr_rmtval_remove(struct xfs_da_args *args);
+int __xfs_attr_rmtval_remove(struct xfs_delattr_context *dac);
 #endif /* __XFS_ATTR_REMOTE_H__ */
fs/xfs/xfs_attr_inactive.c +1 -1
index c42f90e..b2150fa 100644
@@ -15,10 +15,10 @@
 #include "xfs_da_format.h"
 #include "xfs_da_btree.h"
 #include "xfs_inode.h"
+#include "xfs_attr.h"
 #include "xfs_attr_remote.h"
 #include "xfs_trans.h"
 #include "xfs_bmap.h"
-#include "xfs_attr.h"
 #include "xfs_attr_leaf.h"
 #include "xfs_quota.h"
 #include "xfs_dir2.h"
Signature · 1 line
2.7.4
#63 lore raw

Re: [PATCH v9 22/24] xfs: Add delay ready attr remove routines

Quoted 79 lines · Allison Collins

This patch modifies the attr remove routines to be delay ready. This means they no longer roll or commit transactions, but instead return -EAGAIN to have the calling routine roll and refresh the transaction. In this series, xfs_attr_remove_args has become xfs_attr_remove_iter, which uses a sort of state machine like switch to keep track of where it was when EAGAIN was returned. xfs_attr_node_removename has also been modified to use the switch, and a new version of xfs_attr_remove_args consists of a simple loop to refresh the transaction until the operation is completed. A new XFS_DAC_DEFER_FINISH flag is used to finish the transaction where ever the existing code used to.

Calls to xfs_attr_rmtval_remove are replaced with the delay ready version __xfs_attr_rmtval_remove. We will rename __xfs_attr_rmtval_remove back to xfs_attr_rmtval_remove when we are done.

xfs_attr_rmtval_remove itself is still in use by the set routines (used during a rename). For reasons of perserving existing function, we modify xfs_attr_rmtval_remove to call xfs_defer_finish when the flag is set. Similar to how xfs_attr_remove_args does here. Once we transition the set routines to be delay ready, xfs_attr_rmtval_remove is no longer used and will be removed.

This patch also adds a new struct xfs_delattr_context, which we will use to keep track of the current state of an attribute operation. The new xfs_delattr_state enum 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.

Below is a state machine diagram for attr remove operations. The XFS_DAS_* states indicate places where the function would return -EAGAIN, and then immediately resume from after being recalled by the calling function. States marked as a "subroutine state" indicate that they belong to a subroutine, and so the calling function needs to pass them back to that subroutine to allow it to finish where it left off. But they otherwise do not have a role in the calling function other than just passing through.

xfs_attr_remove_iter()

         XFS_DAS_RM_SHRINK     ─┐
         (subroutine state)     │
                                └─>xfs_attr_node_removename()
                                                 │

v
need to
shrink tree? ─n─┐
│ │
y │
│ │
v │
XFS_DAS_RM_SHRINK │
│ │
v │
done <─────┘

---
 fs/xfs/libxfs/xfs_attr.c        | 159 ++++++++++++++++++++++++++++++----------
 fs/xfs/libxfs/xfs_attr.h        |  73 ++++++++++++++++++
 fs/xfs/libxfs/xfs_attr_leaf.c   |   2 +-
 fs/xfs/libxfs/xfs_attr_remote.c |  31 ++++----
 fs/xfs/libxfs/xfs_attr_remote.h |   2 +-
 fs/xfs/xfs_attr_inactive.c      |   2 +-
 6 files changed, 215 insertions(+), 54 deletions(-)
fs/xfs/libxfs/xfs_attr.c +1 -1
index c8cae68..7213589 100644
@@ -53,12 +53,21 @@ STATIC int xfs_attr_leaf_hasname(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_attr_node_removename(xfs_da_args_t *args);
+STATIC int xfs_attr_node_removename(struct xfs_delattr_context *dac);
 STATIC int xfs_attr_node_hasname(xfs_da_args_t *args,
 				 struct xfs_da_state **state);

fs/xfs/libxfs/xfs_attr.c STATIC int xfs_attr_leaf_hasname(struct xfs_da_args *args, struct xfs_buf **bp); · line 68

Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +7 -0
 STATIC int xfs_attr_fillstate(xfs_da_state_t *state);
 STATIC int xfs_attr_refillstate(xfs_da_state_t *state);
 
+void
+xfs_delattr_context_init(
+	struct xfs_delattr_context	*dac,
+	struct xfs_da_args		*args)
+{
+	memset(dac, 0, sizeof(struct xfs_delattr_context));
+	dac->da_args = args;

Couldn't this could be open coded as:

struct xfs_delattr_context	dac = {
	.da_args		= args,
};

in the callers? One less helper function, and it means that the stack contents will always be fully initialized.

fs/xfs/libxfs/xfs_attr.c xfs_attr_set_shortform( · line 275

Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +3 -0
+}
+
 int
 xfs_inode_hasattr(
 	struct xfs_inode	*ip)
@@ -263,6 +272,18 @@ xfs_attr_set_shortform(
 	return 0;
 }
 
+int xfs_attr_defer_finish(

static inline int
xfs_attr_defer_finish(

fs/xfs/libxfs/xfs_attr.c xfs_attr_set_shortform( · line 284

Quoted 9 lines
fs/xfs/libxfs/xfs_attr.c +9 -0
+	struct xfs_delattr_context      *dac)
+{
+	struct xfs_da_args              *args = dac->da_args;
+
+	if (!(dac->flags & XFS_DAC_DEFER_FINISH))
+		return 0;
+
+	dac->flags &= ~XFS_DAC_DEFER_FINISH;
+	return xfs_defer_finish(&args->trans);

I also wonder if you want to hoist the trans_roll_inode to here too?

Actually, what if this instead became:

static inline bool
xfs_attr_roll_again(

	struct xfs_delattr_context	*dac,
	int				*error)
{
	if (*error != -EAGAIN)
		return false;

	if (dac->flags & XFS_DAC_DEFER_FINISH)) {
		dac->flags &= ~XFS_DAC_DEFER_FINISH;
		*error = xfs_defer_finish(&args->trans);
		if (*error)
			return false;
	}

	*error = xfs_trans_roll_inode(&dac->da_args->trans, dac->da_args->dp);
	return *error == 0;
}
Quoted 20 lines
fs/xfs/libxfs/xfs_attr.c +12 -1
+}
+
 /*
  * Set the attribute specified in @args.
  */
@@ -363,23 +384,57 @@ xfs_has_attr(
  */
 int
 xfs_attr_remove_args(
-	struct xfs_da_args      *args)
+	struct xfs_da_args	*args)
+{
+	int			error = 0;
+	struct			xfs_delattr_context dac;
+
+	xfs_delattr_context_init(&dac, args);
+
+	do {
+		error = xfs_attr_remove_iter(&dac);
+		if (error != -EAGAIN)

fs/xfs/libxfs/xfs_attr.c xfs_has_attr( · line 406

Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10 -0
+			break;
+
+		error = xfs_attr_defer_finish(&dac);
+		if (error)
+			break;
+
+		error = xfs_trans_roll_inode(&args->trans, args->dp);
+		if (error)
+			break;
+	} while (true);

and then this whole function becomes:

int
xfs_attr_remove_args(
struct xfs_da_args *args)

{
	struct xfs_delattr_context	dac = {
		.da_args		= args,
	};

	do {
		error = xfs_attr_remove_iter(&dac);
	} while (xfs_attr_roll_again(&dac, &error));

	return error;
}
Quoted 127 lines
fs/xfs/libxfs/xfs_attr.c +57 -22
+
+	return error;
+}
+
+/*
+ * Remove the attribute specified in @args.
+ *
+ * This function may return -EAGAIN to signal that the transaction needs to be
+ * rolled.  Callers should continue calling this function until they receive a
+ * return value other than -EAGAIN.
+ */
+int
+xfs_attr_remove_iter(
+	struct xfs_delattr_context *dac)
 {
+	struct xfs_da_args	*args = dac->da_args;
 	struct xfs_inode	*dp = args->dp;
-	int			error;
+
+	if (dac->dela_state == XFS_DAS_RM_SHRINK)
+		goto node;
 
 	if (!xfs_inode_hasattr(dp)) {
-		error = -ENOATTR;
+		return -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);
+		return xfs_attr_shortform_remove(args);
 	} else if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
-		error = xfs_attr_leaf_removename(args);
-	} else {
-		error = xfs_attr_node_removename(args);
+		return xfs_attr_leaf_removename(args);
 	}
-
-	return error;
+node:
+	return  xfs_attr_node_removename(dac);
 }
 
 /*
@@ -1177,15 +1232,17 @@ xfs_attr_leaf_mark_incomplete(
 
 /*
  * Initial setup for xfs_attr_node_removename.  Make sure the attr is there and
- * the blocks are valid.  Any remote blocks will be marked incomplete.
+ * the blocks are valid.  Any remote blocks will be marked incomplete and
+ * invalidated.
  */
 STATIC
 int xfs_attr_node_removename_setup(
-	struct xfs_da_args	*args,
-	struct xfs_da_state	**state)
+	struct xfs_delattr_context	*dac,
+	struct xfs_da_state		**state)
 {
-	int			error;
-	struct xfs_da_state_blk	*blk;
+	struct xfs_da_args		*args = dac->da_args;
+	int				error;
+	struct xfs_da_state_blk		*blk;
 
 	error = xfs_attr_node_hasname(args, state);
 	if (error != -EEXIST)
@@ -1195,6 +1252,13 @@ int xfs_attr_node_removename_setup(
 	ASSERT(blk->bp != NULL);
 	ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
 
+	/*
+	 * Store blk and state in the context incase we need to cycle out the
+	 * transaction
+	 */
+	dac->blk = blk;
+	dac->da_state = *state;
+
 	if (args->rmtblkno > 0) {
 		error = xfs_attr_leaf_mark_incomplete(args, *state);
 		if (error)
@@ -1210,12 +1274,15 @@ int xfs_attr_node_removename_setup(
 
 STATIC int
 xfs_attr_node_removename_rmt (
-	struct xfs_da_args	*args,
-	struct xfs_da_state	*state)
+	struct xfs_delattr_context	*dac,
+	struct xfs_da_state		*state)
 {
-	int			error = 0;
+	int				error = 0;
 
-	error = xfs_attr_rmtval_remove(args);
+	/*
+	 * May return -EAGAIN to request that the caller recall this function
+	 */
+	error = __xfs_attr_rmtval_remove(dac);
 	if (error)
 		return error;
 
@@ -1232,21 +1299,35 @@ xfs_attr_node_removename_rmt (
  * 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 either an inline or delayed operation,
+ * and may return -EAGAIN 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_attr_node_removename(
-	struct xfs_da_args	*args)
+	struct xfs_delattr_context	*dac)
 {
-	struct xfs_da_state	*state;
-	struct xfs_da_state_blk	*blk;
-	int			retval, error;
-	struct xfs_inode	*dp = args->dp;
+	struct xfs_da_args		*args = dac->da_args;
+	struct xfs_da_state		*state;
+	struct xfs_da_state_blk		*blk;
+	int				retval, error;
+	struct xfs_inode		*dp = args->dp;
 
 	trace_xfs_attr_node_removename(args);
+	state = dac->da_state;
+	blk = dac->blk;

fs/xfs/libxfs/xfs_attr.c xfs_attr_node_removename_rmt ( · line 1327

Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +6 -3
 
-	error = xfs_attr_node_removename_setup(args, &state);
-	if (error)
-		goto out;
+	if (dac->dela_state == XFS_DAS_RM_SHRINK)
+		goto das_rm_shrink;
+
+	if ((dac->flags & XFS_DAC_NODE_RMVNAME_INIT) == 0) {
+		dac->flags |= XFS_DAC_NODE_RMVNAME_INIT;
+		error = xfs_attr_node_removename_setup(dac, &state);

Shouldn't XFS_DAC_NODE_RMVNAME_INIT be set by
xfs_attr_node_removename_setup?

Quoted 207 lines
fs/xfs/libxfs/xfs_attr.c +16 -11
+		if (error)
+			goto out;
+	}
 
 	/*
 	 * If there is an out-of-line value, de-allocate the blocks.
@@ -1254,8 +1335,13 @@ xfs_attr_node_removename(
 	 * overflow the maximum size of a transaction and/or hit a deadlock.
 	 */
 	if (args->rmtblkno > 0) {
-		error = xfs_attr_node_removename_rmt(args, state);
-		if (error)
+		/*
+		 * May return -EAGAIN. Remove blocks until args->rmtblkno == 0
+		 */
+		error = xfs_attr_node_removename_rmt(dac, state);
+		if (error == -EAGAIN)
+			return error;
+		else if (error)
 			goto out;
 	}
 
@@ -1274,17 +1360,14 @@ xfs_attr_node_removename(
 		error = xfs_da3_join(state);
 		if (error)
 			goto out;
-		error = xfs_defer_finish(&args->trans);
-		if (error)
-			goto out;
-		/*
-		 * Commit the Btree join operation and start a new trans.
-		 */
-		error = xfs_trans_roll_inode(&args->trans, dp);
-		if (error)
-			goto out;
+
+		dac->flags |= XFS_DAC_DEFER_FINISH;
+		dac->dela_state = XFS_DAS_RM_SHRINK;
+		return -EAGAIN;
 	}
 
+das_rm_shrink:
+
 	/*
 	 * If the result is small enough, push it all into the inode.
 	 */
fs/xfs/libxfs/xfs_attr.h +73 -0
index 66575b8..0430c79 100644
@@ -74,6 +74,75 @@ struct xfs_attr_list_context {
 };
 
 
+/*
+ * ========================================================================
+ * Structure used to pass context around among the delayed routines.
+ * ========================================================================
+ */
+
+/*
+ * Below is a state machine diagram for attr remove operations. The  XFS_DAS_*
+ * states indicate places where the function would return -EAGAIN, and then
+ * immediately resume from after being recalled by the calling function. States
+ * marked as a "subroutine state" indicate that they belong to a subroutine, and
+ * so the calling function needs to pass them back to that subroutine to allow
+ * it to finish where it left off. But they otherwise do not have a role in the
+ * calling function other than just passing through.
+ *
+ * xfs_attr_remove_iter()
+ *	  XFS_DAS_RM_SHRINK ─┐
+ *	  (subroutine state) │
+ *	                     └─>xfs_attr_node_removename()
+ *	                                      │
+ *	                                      v
+ *	                                   need to
+ *	                                shrink tree? ─n─┐
+ *	                                      │         │
+ *	                                      y         │
+ *	                                      │         │
+ *	                                      v         │
+ *	                              XFS_DAS_RM_SHRINK │
+ *	                                      │         │
+ *	                                      v         │
+ *	                                     done <─────┘
+ *
+ */
+
+/*
+ * Enum values for xfs_delattr_context.da_state
+ *
+ * These values are used by delayed attribute operations to keep track  of where
+ * they were before they returned -EAGAIN.  A return code of -EAGAIN signals the
+ * calling function to roll the transaction, and then recall the subroutine to
+ * finish the operation.  The enum is then used by the subroutine to jump back
+ * to where it was and resume executing where it left off.
+ */
+enum xfs_delattr_state {
+				      /* Zero is uninitalized */
+	XFS_DAS_RM_SHRINK	= 1,  /* We are shrinking the tree */
+};
+
+/*
+ * Defines for xfs_delattr_context.flags
+ */
+#define XFS_DAC_DEFER_FINISH		0x01 /* finish the transaction */
+#define XFS_DAC_NODE_RMVNAME_INIT	0x02 /* xfs_attr_node_removename init */
+
+/*
+ * Context used for keeping track of delayed attribute operations
+ */
+struct xfs_delattr_context {
+	struct xfs_da_args      *da_args;
+
+	/* Used in xfs_attr_node_removename to roll through removing blocks */
+	struct xfs_da_state     *da_state;
+	struct xfs_da_state_blk *blk;
+
+	/* Used to keep track of current state of delayed operation */
+	unsigned int            flags;
+	enum xfs_delattr_state  dela_state;
+};
+
 /*========================================================================
  * Function prototypes for the kernel.
  *========================================================================*/
@@ -91,6 +160,10 @@ int xfs_attr_set(struct xfs_da_args *args);
 int xfs_attr_set_args(struct xfs_da_args *args);
 int xfs_has_attr(struct xfs_da_args *args);
 int xfs_attr_remove_args(struct xfs_da_args *args);
+int xfs_attr_remove_iter(struct xfs_delattr_context *dac);
+int xfs_attr_defer_finish(struct xfs_delattr_context *dac);
 bool xfs_attr_namecheck(const void *name, size_t length);
+void xfs_delattr_context_init(struct xfs_delattr_context *dac,
+			      struct xfs_da_args *args);
 
 #endif	/* __XFS_ATTR_H__ */
fs/xfs/libxfs/xfs_attr_leaf.c +1 -1
index f55402b..2e36c8b 100644
@@ -19,8 +19,8 @@
 #include "xfs_bmap_btree.h"
 #include "xfs_bmap.h"
 #include "xfs_attr_sf.h"
-#include "xfs_attr_remote.h"
 #include "xfs_attr.h"
+#include "xfs_attr_remote.h"
 #include "xfs_attr_leaf.h"
 #include "xfs_error.h"
 #include "xfs_trace.h"
fs/xfs/libxfs/xfs_attr_remote.c +15 -8
index f770159..f2d46c7 100644
@@ -676,14 +676,16 @@ xfs_attr_rmtval_invalidate(
  */
 int
 xfs_attr_rmtval_remove(
-	struct xfs_da_args      *args)
+	struct xfs_da_args		*args)
 {
-	xfs_dablk_t		lblkno;
-	int			blkcnt;
-	int			error = 0;
-	int			retval = 0;
+	struct xfs_delattr_context	dac;
+	xfs_dablk_t			lblkno;
+	int				blkcnt;
+	int				error = 0;
+	int				retval = 0;
 
 	trace_xfs_attr_rmtval_remove(args);
+	xfs_delattr_context_init(&dac, args);
 
 	/*
 	 * Keep de-allocating extents until the remote-value region is gone.
@@ -691,10 +693,14 @@ xfs_attr_rmtval_remove(
 	lblkno = args->rmtblkno;
 	blkcnt = args->rmtblkcnt;
 	do {
-		retval = __xfs_attr_rmtval_remove(args);
+		retval = __xfs_attr_rmtval_remove(&dac);
 		if (retval && retval != EAGAIN)
 			return retval;
 
+		error = xfs_attr_defer_finish(&dac);
+		if (error)
+			break;
+
 		/*
 		 * Close out trans and start the next one in the chain.
 		 */
@@ -713,9 +719,10 @@ xfs_attr_rmtval_remove(
  */
 int
 __xfs_attr_rmtval_remove(
-	struct xfs_da_args	*args)
+	struct xfs_delattr_context	*dac)
 {
-	int			error, done;
+	struct xfs_da_args		*args = dac->da_args;
+	int				error, done;
 
 	/*
 	 * Unmap value blocks for this attr.

fs/xfs/libxfs/xfs_attr_remote.c __xfs_attr_rmtval_remove( · line 736

Quoted 10 lines
fs/xfs/libxfs/xfs_attr_remote.c +2 -5
@@ -725,12 +732,10 @@ __xfs_attr_rmtval_remove(
 	if (error)
 		return error;
 
-	error = xfs_defer_finish(&args->trans);
-	if (error)
-		return error;
-
-	if (!done)
+	if (!done) {
+		dac->flags &= ~XFS_DAC_DEFER_FINISH;

Why do we strip off DEFER_FINISH here? Is it because we're making xfs_attr_rmtval_remove invoke xfs_defer_finish unconditionally to clear out any pending rmap items?

If you transformed the do-while loop in xfs_attr_rmtval_remove to use xfs_attr_roll_again, then you could make this set DEFER_FINISH, which would make me a lot less suspicious that we're dropping state here.

(It would also clean up a lot of the defer_finish -> trans_roll_inode code that's scattering everywhere...)

--D

Quoted 35 lines
fs/xfs/libxfs/xfs_attr_remote.c +1 -0
 		return -EAGAIN;
+	}
 
 	return error;
 }
fs/xfs/libxfs/xfs_attr_remote.h +1 -1
index ee3337b..351da00 100644
@@ -14,5 +14,5 @@ int xfs_attr_rmtval_remove(struct xfs_da_args *args);
 int xfs_attr_rmtval_stale(struct xfs_inode *ip, struct xfs_bmbt_irec *map,
 		xfs_buf_flags_t incore_flags);
 int xfs_attr_rmtval_invalidate(struct xfs_da_args *args);
-int __xfs_attr_rmtval_remove(struct xfs_da_args *args);
+int __xfs_attr_rmtval_remove(struct xfs_delattr_context *dac);
 #endif /* __XFS_ATTR_REMOTE_H__ */
fs/xfs/xfs_attr_inactive.c +1 -1
index c42f90e..b2150fa 100644
@@ -15,10 +15,10 @@
 #include "xfs_da_format.h"
 #include "xfs_da_btree.h"
 #include "xfs_inode.h"
+#include "xfs_attr.h"
 #include "xfs_attr_remote.h"
 #include "xfs_trans.h"
 #include "xfs_bmap.h"
-#include "xfs_attr.h"
 #include "xfs_attr_leaf.h"
 #include "xfs_quota.h"
 #include "xfs_dir2.h"
Signature · 1 line
2.7.4
#64 lore raw

Re: [PATCH v9 22/24] xfs: Add delay ready attr remove routines

Quoted 93 lines · Darrick J. Wong
Quoted 79 lines · Allison Collins

This patch modifies the attr remove routines to be delay ready. This means they no longer roll or commit transactions, but instead return -EAGAIN to have the calling routine roll and refresh the transaction. In this series, xfs_attr_remove_args has become xfs_attr_remove_iter, which uses a sort of state machine like switch to keep track of where it was when EAGAIN was returned. xfs_attr_node_removename has also been modified to use the switch, and a new version of xfs_attr_remove_args consists of a simple loop to refresh the transaction until the operation is completed. A new XFS_DAC_DEFER_FINISH flag is used to finish the transaction where ever the existing code used to.

Calls to xfs_attr_rmtval_remove are replaced with the delay ready version __xfs_attr_rmtval_remove. We will rename __xfs_attr_rmtval_remove back to xfs_attr_rmtval_remove when we are done.

xfs_attr_rmtval_remove itself is still in use by the set routines (used during a rename). For reasons of perserving existing function, we modify xfs_attr_rmtval_remove to call xfs_defer_finish when the flag is set. Similar to how xfs_attr_remove_args does here. Once we transition the set routines to be delay ready, xfs_attr_rmtval_remove is no longer used and will be removed.

This patch also adds a new struct xfs_delattr_context, which we will use to keep track of the current state of an attribute operation. The new xfs_delattr_state enum 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.

Below is a state machine diagram for attr remove operations. The XFS_DAS_* states indicate places where the function would return -EAGAIN, and then immediately resume from after being recalled by the calling function. States marked as a "subroutine state" indicate that they belong to a subroutine, and so the calling function needs to pass them back to that subroutine to allow it to finish where it left off. But they otherwise do not have a role in the calling function other than just passing through.

xfs_attr_remove_iter()

          XFS_DAS_RM_SHRINK     ─┐
          (subroutine state)     │
                                 └─>xfs_attr_node_removename()
                                                  │

v
need to
shrink tree? ─n─┐
│ │
y │
│ │
v │
XFS_DAS_RM_SHRINK │
│ │
v │
done <─────┘

---
  fs/xfs/libxfs/xfs_attr.c        | 159 ++++++++++++++++++++++++++++++----------
  fs/xfs/libxfs/xfs_attr.h        |  73 ++++++++++++++++++
  fs/xfs/libxfs/xfs_attr_leaf.c   |   2 +-
  fs/xfs/libxfs/xfs_attr_remote.c |  31 ++++----
  fs/xfs/libxfs/xfs_attr_remote.h |   2 +-
  fs/xfs/xfs_attr_inactive.c      |   2 +-
  6 files changed, 215 insertions(+), 54 deletions(-)
fs/xfs/libxfs/xfs_attr.c +1 -1
index c8cae68..7213589 100644
@@ -53,12 +53,21 @@ STATIC int xfs_attr_leaf_hasname(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_attr_node_removename(xfs_da_args_t *args);
+STATIC int xfs_attr_node_removename(struct xfs_delattr_context *dac);
  STATIC int xfs_attr_node_hasname(xfs_da_args_t *args,
  				 struct xfs_da_state **state);

fs/xfs/libxfs/xfs_attr.c STATIC int xfs_attr_leaf_hasname(struct xfs_da_args *args, struct xfs_buf **bp); · line 68

Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +7 -0
  STATIC int xfs_attr_fillstate(xfs_da_state_t *state);
  STATIC int xfs_attr_refillstate(xfs_da_state_t *state);
 
+void
+xfs_delattr_context_init(
+	struct xfs_delattr_context	*dac,
+	struct xfs_da_args		*args)
+{
+	memset(dac, 0, sizeof(struct xfs_delattr_context));
+	dac->da_args = args;

Couldn't this could be open coded as:

Quoted 6 lines
struct xfs_delattr_context	dac = {
	.da_args		= args,
};

in the callers? One less helper function, and it means that the stack contents will always be fully initialized.

I believe Dave had suggested the initializer back when I had dac a member of args instead of the other way around. I dont know that he was too particular about exactly what the initializer was though. Is this generally the standard for initializers?

Quoted 31 lines

fs/xfs/libxfs/xfs_attr.c xfs_attr_set_shortform( · line 275

Quoted 11 lines
fs/xfs/libxfs/xfs_attr.c +3 -0
+}
+
  int
  xfs_inode_hasattr(
  	struct xfs_inode	*ip)
@@ -263,6 +272,18 @@ xfs_attr_set_shortform(
  	return 0;
  }
 
+int xfs_attr_defer_finish(

static inline int
xfs_attr_defer_finish(

fs/xfs/libxfs/xfs_attr.c xfs_attr_set_shortform( · line 284

Quoted 9 lines
fs/xfs/libxfs/xfs_attr.c +9 -0
+	struct xfs_delattr_context      *dac)
+{
+	struct xfs_da_args              *args = dac->da_args;
+
+	if (!(dac->flags & XFS_DAC_DEFER_FINISH))
+		return 0;
+
+	dac->flags &= ~XFS_DAC_DEFER_FINISH;
+	return xfs_defer_finish(&args->trans);

I also wonder if you want to hoist the trans_roll_inode to here too?

Actually, what if this instead became:

static inline bool
xfs_attr_roll_again(

Quoted 17 lines
	struct xfs_delattr_context	*dac,
	int				*error)
{
	if (*error != -EAGAIN)
		return false;

	if (dac->flags & XFS_DAC_DEFER_FINISH)) {
		dac->flags &= ~XFS_DAC_DEFER_FINISH;
		*error = xfs_defer_finish(&args->trans);
		if (*error)
			return false;
	}

	*error = xfs_trans_roll_inode(&dac->da_args->trans, dac->da_args->dp);
	return *error == 0;
}

Sure, that should be fine

Quoted 36 lines
Quoted 20 lines
fs/xfs/libxfs/xfs_attr.c +12 -1
+}
+
  /*
   * Set the attribute specified in @args.
   */
@@ -363,23 +384,57 @@ xfs_has_attr(
   */
  int
  xfs_attr_remove_args(
-	struct xfs_da_args      *args)
+	struct xfs_da_args	*args)
+{
+	int			error = 0;
+	struct			xfs_delattr_context dac;
+
+	xfs_delattr_context_init(&dac, args);
+
+	do {
+		error = xfs_attr_remove_iter(&dac);
+		if (error != -EAGAIN)

fs/xfs/libxfs/xfs_attr.c xfs_has_attr( · line 406

Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10 -0
+			break;
+
+		error = xfs_attr_defer_finish(&dac);
+		if (error)
+			break;
+
+		error = xfs_trans_roll_inode(&args->trans, args->dp);
+		if (error)
+			break;
+	} while (true);

and then this whole function becomes:

int
xfs_attr_remove_args(
struct xfs_da_args *args)

Quoted 11 lines
{
	struct xfs_delattr_context	dac = {
		.da_args		= args,
	};

	do {
		error = xfs_attr_remove_iter(&dac);
	} while (xfs_attr_roll_again(&dac, &error));

	return error;
}

Alrighty then

Quoted 129 lines
Quoted 129 lines
fs/xfs/libxfs/xfs_attr.c +57 -22
+
+	return error;
+}
+
+/*
+ * Remove the attribute specified in @args.
+ *
+ * This function may return -EAGAIN to signal that the transaction needs to be
+ * rolled.  Callers should continue calling this function until they receive a
+ * return value other than -EAGAIN.
+ */
+int
+xfs_attr_remove_iter(
+	struct xfs_delattr_context *dac)
  {
+	struct xfs_da_args	*args = dac->da_args;
  	struct xfs_inode	*dp = args->dp;
-	int			error;
+
+	if (dac->dela_state == XFS_DAS_RM_SHRINK)
+		goto node;
 
  	if (!xfs_inode_hasattr(dp)) {
-		error = -ENOATTR;
+		return -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);
+		return xfs_attr_shortform_remove(args);
  	} else if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
-		error = xfs_attr_leaf_removename(args);
-	} else {
-		error = xfs_attr_node_removename(args);
+		return xfs_attr_leaf_removename(args);
  	}
-
-	return error;
+node:
+	return  xfs_attr_node_removename(dac);
  }
 
  /*
@@ -1177,15 +1232,17 @@ xfs_attr_leaf_mark_incomplete(
 
  /*
   * Initial setup for xfs_attr_node_removename.  Make sure the attr is there and
- * the blocks are valid.  Any remote blocks will be marked incomplete.
+ * the blocks are valid.  Any remote blocks will be marked incomplete and
+ * invalidated.
   */
  STATIC
  int xfs_attr_node_removename_setup(
-	struct xfs_da_args	*args,
-	struct xfs_da_state	**state)
+	struct xfs_delattr_context	*dac,
+	struct xfs_da_state		**state)
  {
-	int			error;
-	struct xfs_da_state_blk	*blk;
+	struct xfs_da_args		*args = dac->da_args;
+	int				error;
+	struct xfs_da_state_blk		*blk;
 
  	error = xfs_attr_node_hasname(args, state);
  	if (error != -EEXIST)
@@ -1195,6 +1252,13 @@ int xfs_attr_node_removename_setup(
  	ASSERT(blk->bp != NULL);
  	ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
 
+	/*
+	 * Store blk and state in the context incase we need to cycle out the
+	 * transaction
+	 */
+	dac->blk = blk;
+	dac->da_state = *state;
+
  	if (args->rmtblkno > 0) {
  		error = xfs_attr_leaf_mark_incomplete(args, *state);
  		if (error)
@@ -1210,12 +1274,15 @@ int xfs_attr_node_removename_setup(
 
  STATIC int
  xfs_attr_node_removename_rmt (
-	struct xfs_da_args	*args,
-	struct xfs_da_state	*state)
+	struct xfs_delattr_context	*dac,
+	struct xfs_da_state		*state)
  {
-	int			error = 0;
+	int				error = 0;
 
-	error = xfs_attr_rmtval_remove(args);
+	/*
+	 * May return -EAGAIN to request that the caller recall this function
+	 */
+	error = __xfs_attr_rmtval_remove(dac);
  	if (error)
  		return error;
 
@@ -1232,21 +1299,35 @@ xfs_attr_node_removename_rmt (
   * 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 either an inline or delayed operation,
+ * and may return -EAGAIN 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_attr_node_removename(
-	struct xfs_da_args	*args)
+	struct xfs_delattr_context	*dac)
  {
-	struct xfs_da_state	*state;
-	struct xfs_da_state_blk	*blk;
-	int			retval, error;
-	struct xfs_inode	*dp = args->dp;
+	struct xfs_da_args		*args = dac->da_args;
+	struct xfs_da_state		*state;
+	struct xfs_da_state_blk		*blk;
+	int				retval, error;
+	struct xfs_inode		*dp = args->dp;
 
  	trace_xfs_attr_node_removename(args);
+	state = dac->da_state;
+	blk = dac->blk;
 
Quoted 12 lines

fs/xfs/libxfs/xfs_attr.c xfs_attr_node_removename_rmt ( · line 1327

Quoted 9 lines
fs/xfs/libxfs/xfs_attr.c +6 -3
-	error = xfs_attr_node_removename_setup(args, &state);
-	if (error)
-		goto out;
+	if (dac->dela_state == XFS_DAS_RM_SHRINK)
+		goto das_rm_shrink;
+
+	if ((dac->flags & XFS_DAC_NODE_RMVNAME_INIT) == 0) {
+		dac->flags |= XFS_DAC_NODE_RMVNAME_INIT;
+		error = xfs_attr_node_removename_setup(dac, &state);

Shouldn't XFS_DAC_NODE_RMVNAME_INIT be set by
xfs_attr_node_removename_setup?

I suppose it could be. Initially this was a state not a flag, so that's why we see it here in this scope.

There may be reason to keep it there though. These -EAGAIN functions are admittadly sort of jumpy, so when trying to trace them though, haveing the flag in the top level like that makes it clear that when we come back through on another iteration, we dont init twice. Really, it's more to do with managing function re-entry than anything else going on in the init function. I think Brian and I have been trying our best to keep code flow craziness in the same scope rather than letting them get burried in subfunctions. Though I suppose it wouldnt be too hard to find if folks prefer the flag be in the subfunction?

Quoted 211 lines
Quoted 211 lines
fs/xfs/libxfs/xfs_attr.c +16 -11
+		if (error)
+			goto out;
+	}
 
  	/*
  	 * If there is an out-of-line value, de-allocate the blocks.
@@ -1254,8 +1335,13 @@ xfs_attr_node_removename(
  	 * overflow the maximum size of a transaction and/or hit a deadlock.
  	 */
  	if (args->rmtblkno > 0) {
-		error = xfs_attr_node_removename_rmt(args, state);
-		if (error)
+		/*
+		 * May return -EAGAIN. Remove blocks until args->rmtblkno == 0
+		 */
+		error = xfs_attr_node_removename_rmt(dac, state);
+		if (error == -EAGAIN)
+			return error;
+		else if (error)
  			goto out;
  	}
 
@@ -1274,17 +1360,14 @@ xfs_attr_node_removename(
  		error = xfs_da3_join(state);
  		if (error)
  			goto out;
-		error = xfs_defer_finish(&args->trans);
-		if (error)
-			goto out;
-		/*
-		 * Commit the Btree join operation and start a new trans.
-		 */
-		error = xfs_trans_roll_inode(&args->trans, dp);
-		if (error)
-			goto out;
+
+		dac->flags |= XFS_DAC_DEFER_FINISH;
+		dac->dela_state = XFS_DAS_RM_SHRINK;
+		return -EAGAIN;
  	}
 
+das_rm_shrink:
+
  	/*
  	 * If the result is small enough, push it all into the inode.
  	 */
fs/xfs/libxfs/xfs_attr.h +73 -0
index 66575b8..0430c79 100644
@@ -74,6 +74,75 @@ struct xfs_attr_list_context {
  };
 
 
+/*
+ * ========================================================================
+ * Structure used to pass context around among the delayed routines.
+ * ========================================================================
+ */
+
+/*
+ * Below is a state machine diagram for attr remove operations. The  XFS_DAS_*
+ * states indicate places where the function would return -EAGAIN, and then
+ * immediately resume from after being recalled by the calling function. States
+ * marked as a "subroutine state" indicate that they belong to a subroutine, and
+ * so the calling function needs to pass them back to that subroutine to allow
+ * it to finish where it left off. But they otherwise do not have a role in the
+ * calling function other than just passing through.
+ *
+ * xfs_attr_remove_iter()
+ *	  XFS_DAS_RM_SHRINK ─┐
+ *	  (subroutine state) │
+ *	                     └─>xfs_attr_node_removename()
+ *	                                      │
+ *	                                      v
+ *	                                   need to
+ *	                                shrink tree? ─n─┐
+ *	                                      │         │
+ *	                                      y         │
+ *	                                      │         │
+ *	                                      v         │
+ *	                              XFS_DAS_RM_SHRINK │
+ *	                                      │         │
+ *	                                      v         │
+ *	                                     done <─────┘
+ *
+ */
+
+/*
+ * Enum values for xfs_delattr_context.da_state
+ *
+ * These values are used by delayed attribute operations to keep track  of where
+ * they were before they returned -EAGAIN.  A return code of -EAGAIN signals the
+ * calling function to roll the transaction, and then recall the subroutine to
+ * finish the operation.  The enum is then used by the subroutine to jump back
+ * to where it was and resume executing where it left off.
+ */
+enum xfs_delattr_state {
+				      /* Zero is uninitalized */
+	XFS_DAS_RM_SHRINK	= 1,  /* We are shrinking the tree */
+};
+
+/*
+ * Defines for xfs_delattr_context.flags
+ */
+#define XFS_DAC_DEFER_FINISH		0x01 /* finish the transaction */
+#define XFS_DAC_NODE_RMVNAME_INIT	0x02 /* xfs_attr_node_removename init */
+
+/*
+ * Context used for keeping track of delayed attribute operations
+ */
+struct xfs_delattr_context {
+	struct xfs_da_args      *da_args;
+
+	/* Used in xfs_attr_node_removename to roll through removing blocks */
+	struct xfs_da_state     *da_state;
+	struct xfs_da_state_blk *blk;
+
+	/* Used to keep track of current state of delayed operation */
+	unsigned int            flags;
+	enum xfs_delattr_state  dela_state;
+};
+
  /*========================================================================
   * Function prototypes for the kernel.
   *========================================================================*/
@@ -91,6 +160,10 @@ int xfs_attr_set(struct xfs_da_args *args);
  int xfs_attr_set_args(struct xfs_da_args *args);
  int xfs_has_attr(struct xfs_da_args *args);
  int xfs_attr_remove_args(struct xfs_da_args *args);
+int xfs_attr_remove_iter(struct xfs_delattr_context *dac);
+int xfs_attr_defer_finish(struct xfs_delattr_context *dac);
  bool xfs_attr_namecheck(const void *name, size_t length);
+void xfs_delattr_context_init(struct xfs_delattr_context *dac,
+			      struct xfs_da_args *args);
 
  #endif	/* __XFS_ATTR_H__ */
fs/xfs/libxfs/xfs_attr_leaf.c +1 -1
index f55402b..2e36c8b 100644
@@ -19,8 +19,8 @@
  #include "xfs_bmap_btree.h"
  #include "xfs_bmap.h"
  #include "xfs_attr_sf.h"
-#include "xfs_attr_remote.h"
  #include "xfs_attr.h"
+#include "xfs_attr_remote.h"
  #include "xfs_attr_leaf.h"
  #include "xfs_error.h"
  #include "xfs_trace.h"
fs/xfs/libxfs/xfs_attr_remote.c +15 -8
index f770159..f2d46c7 100644
@@ -676,14 +676,16 @@ xfs_attr_rmtval_invalidate(
   */
  int
  xfs_attr_rmtval_remove(
-	struct xfs_da_args      *args)
+	struct xfs_da_args		*args)
  {
-	xfs_dablk_t		lblkno;
-	int			blkcnt;
-	int			error = 0;
-	int			retval = 0;
+	struct xfs_delattr_context	dac;
+	xfs_dablk_t			lblkno;
+	int				blkcnt;
+	int				error = 0;
+	int				retval = 0;
 
  	trace_xfs_attr_rmtval_remove(args);
+	xfs_delattr_context_init(&dac, args);
 
  	/*
  	 * Keep de-allocating extents until the remote-value region is gone.
@@ -691,10 +693,14 @@ xfs_attr_rmtval_remove(
  	lblkno = args->rmtblkno;
  	blkcnt = args->rmtblkcnt;
  	do {
-		retval = __xfs_attr_rmtval_remove(args);
+		retval = __xfs_attr_rmtval_remove(&dac);
  		if (retval && retval != EAGAIN)
  			return retval;
 
+		error = xfs_attr_defer_finish(&dac);
+		if (error)
+			break;
+
  		/*
  		 * Close out trans and start the next one in the chain.
  		 */
@@ -713,9 +719,10 @@ xfs_attr_rmtval_remove(
   */
  int
  __xfs_attr_rmtval_remove(
-	struct xfs_da_args	*args)
+	struct xfs_delattr_context	*dac)
  {
-	int			error, done;
+	struct xfs_da_args		*args = dac->da_args;
+	int				error, done;
 
  	/*
  	 * Unmap value blocks for this attr.
@@ -725,12 +732,10 @@ __xfs_attr_rmtval_remove(
  	if (error)
  		return error;
 
Quoted 11 lines

fs/xfs/libxfs/xfs_attr_remote.c __xfs_attr_rmtval_remove( · line 736

Quoted 7 lines
fs/xfs/libxfs/xfs_attr_remote.c +2 -5
-	error = xfs_defer_finish(&args->trans);
-	if (error)
-		return error;
-
-	if (!done)
+	if (!done) {
+		dac->flags &= ~XFS_DAC_DEFER_FINISH;

Why do we strip off DEFER_FINISH here? Is it because we're making xfs_attr_rmtval_remove invoke xfs_defer_finish unconditionally to clear out any pending rmap items?

Sorry, that should have been a flag set, not a strip. Will fix!

Quoted 7 lines

If you transformed the do-while loop in xfs_attr_rmtval_remove to use xfs_attr_roll_again, then you could make this set DEFER_FINISH, which would make me a lot less suspicious that we're dropping state here.

(It would also clean up a lot of the defer_finish -> trans_roll_inode code that's scattering everywhere...)

Yes, will do that. Thanks for the review!

Quoted 38 lines

--D

Quoted 35 lines
fs/xfs/libxfs/xfs_attr_remote.c +1 -0
  		return -EAGAIN;
+	}
 
  	return error;
  }
fs/xfs/libxfs/xfs_attr_remote.h +1 -1
index ee3337b..351da00 100644
@@ -14,5 +14,5 @@ int xfs_attr_rmtval_remove(struct xfs_da_args *args);
  int xfs_attr_rmtval_stale(struct xfs_inode *ip, struct xfs_bmbt_irec *map,
  		xfs_buf_flags_t incore_flags);
  int xfs_attr_rmtval_invalidate(struct xfs_da_args *args);
-int __xfs_attr_rmtval_remove(struct xfs_da_args *args);
+int __xfs_attr_rmtval_remove(struct xfs_delattr_context *dac);
  #endif /* __XFS_ATTR_REMOTE_H__ */
fs/xfs/xfs_attr_inactive.c +1 -1
index c42f90e..b2150fa 100644
@@ -15,10 +15,10 @@
  #include "xfs_da_format.h"
  #include "xfs_da_btree.h"
  #include "xfs_inode.h"
+#include "xfs_attr.h"
  #include "xfs_attr_remote.h"
  #include "xfs_trans.h"
  #include "xfs_bmap.h"
-#include "xfs_attr.h"
  #include "xfs_attr_leaf.h"
  #include "xfs_quota.h"
  #include "xfs_dir2.h"
Signature · 1 line
2.7.4
#65 lore raw

Re: [PATCH v9 22/24] xfs: Add delay ready attr remove routines

Quoted 99 lines · Allison Collins
Quoted 96 lines · Darrick J. Wong
Quoted 78 lines · Allison Collins

This patch modifies the attr remove routines to be delay ready. This means they no longer roll or commit transactions, but instead return -EAGAIN to have the calling routine roll and refresh the transaction. In this series, xfs_attr_remove_args has become xfs_attr_remove_iter, which uses a sort of state machine like switch to keep track of where it was when EAGAIN was returned. xfs_attr_node_removename has also been modified to use the switch, and a new version of xfs_attr_remove_args consists of a simple loop to refresh the transaction until the operation is completed. A new XFS_DAC_DEFER_FINISH flag is used to finish the transaction where ever the existing code used to.

Calls to xfs_attr_rmtval_remove are replaced with the delay ready version __xfs_attr_rmtval_remove. We will rename __xfs_attr_rmtval_remove back to xfs_attr_rmtval_remove when we are done.

xfs_attr_rmtval_remove itself is still in use by the set routines (used during a rename). For reasons of perserving existing function, we modify xfs_attr_rmtval_remove to call xfs_defer_finish when the flag is set. Similar to how xfs_attr_remove_args does here. Once we transition the set routines to be delay ready, xfs_attr_rmtval_remove is no longer used and will be removed.

This patch also adds a new struct xfs_delattr_context, which we will use to keep track of the current state of an attribute operation. The new xfs_delattr_state enum 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.

Below is a state machine diagram for attr remove operations. The XFS_DAS_* states indicate places where the function would return -EAGAIN, and then immediately resume from after being recalled by the calling function. States marked as a "subroutine state" indicate that they belong to a subroutine, and so the calling function needs to pass them back to that subroutine to allow it to finish where it left off. But they otherwise do not have a role in the calling function other than just passing through.

xfs_attr_remove_iter()

          XFS_DAS_RM_SHRINK     ─┐
          (subroutine state)     │
                                 └─>xfs_attr_node_removename()
                                                  │

v
need to
shrink tree? ─n─┐
│ │
y │
│ │
v │
XFS_DAS_RM_SHRINK │
│ │
v │
done <─────┘

---
  fs/xfs/libxfs/xfs_attr.c        | 159 ++++++++++++++++++++++++++++++----------
  fs/xfs/libxfs/xfs_attr.h        |  73 ++++++++++++++++++
  fs/xfs/libxfs/xfs_attr_leaf.c   |   2 +-
  fs/xfs/libxfs/xfs_attr_remote.c |  31 ++++----
  fs/xfs/libxfs/xfs_attr_remote.h |   2 +-
  fs/xfs/xfs_attr_inactive.c      |   2 +-
  6 files changed, 215 insertions(+), 54 deletions(-)
fs/xfs/libxfs/xfs_attr.c +1 -1
index c8cae68..7213589 100644
@@ -53,12 +53,21 @@ STATIC int xfs_attr_leaf_hasname(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_attr_node_removename(xfs_da_args_t *args);
+STATIC int xfs_attr_node_removename(struct xfs_delattr_context *dac);
  STATIC int xfs_attr_node_hasname(xfs_da_args_t *args,

fs/xfs/libxfs/xfs_attr.c STATIC int xfs_attr_leaf_hasname(struct xfs_da_args *args, struct xfs_buf **bp); · line 67

Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +7 -0
  				 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);
+void
+xfs_delattr_context_init(
+	struct xfs_delattr_context	*dac,
+	struct xfs_da_args		*args)
+{
+	memset(dac, 0, sizeof(struct xfs_delattr_context));
+	dac->da_args = args;

Couldn't this could be open coded as:

struct xfs_delattr_context	dac = {
	.da_args		= args,
};
Quoted 6 lines
Quoted 2 lines

in the callers? One less helper function, and it means that the stack contents will always be fully initialized.

I believe Dave had suggested the initializer back when I had dac a member of args instead of the other way around. I dont know that he was too particular about exactly what the initializer was though. Is this generally the standard for initializers?

One of them, yes. :)

I've started to prefer that form simply because we don't have to remember that some struct is uninitialized between its definition and some later initializer function call. There are (many) places where we have to unpack other things before we can initialize a struct, but for the simpler cases I like to reduce the brainpower needed to understand code, lest I turn into Mr. D P Gumby.

Quoted 232 lines
Quoted 30 lines

fs/xfs/libxfs/xfs_attr.c xfs_attr_set_shortform( · line 274

Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +3 -0
+}
+
  int
  xfs_inode_hasattr(
  	struct xfs_inode	*ip)
@@ -263,6 +272,18 @@ xfs_attr_set_shortform(
  	return 0;
  }
+int xfs_attr_defer_finish(

static inline int
xfs_attr_defer_finish(

fs/xfs/libxfs/xfs_attr.c xfs_attr_set_shortform( · line 284

Quoted 9 lines
fs/xfs/libxfs/xfs_attr.c +9 -0
+	struct xfs_delattr_context      *dac)
+{
+	struct xfs_da_args              *args = dac->da_args;
+
+	if (!(dac->flags & XFS_DAC_DEFER_FINISH))
+		return 0;
+
+	dac->flags &= ~XFS_DAC_DEFER_FINISH;
+	return xfs_defer_finish(&args->trans);

I also wonder if you want to hoist the trans_roll_inode to here too?

Actually, what if this instead became:

static inline bool
xfs_attr_roll_again(

Quoted 17 lines
	struct xfs_delattr_context	*dac,
	int				*error)
{
	if (*error != -EAGAIN)
		return false;

	if (dac->flags & XFS_DAC_DEFER_FINISH)) {
		dac->flags &= ~XFS_DAC_DEFER_FINISH;
		*error = xfs_defer_finish(&args->trans);
		if (*error)
			return false;
	}

	*error = xfs_trans_roll_inode(&dac->da_args->trans, dac->da_args->dp);
	return *error == 0;
}

Sure, that should be fine

Quoted 36 lines
Quoted 20 lines
fs/xfs/libxfs/xfs_attr.c +12 -1
+}
+
  /*
   * Set the attribute specified in @args.
   */
@@ -363,23 +384,57 @@ xfs_has_attr(
   */
  int
  xfs_attr_remove_args(
-	struct xfs_da_args      *args)
+	struct xfs_da_args	*args)
+{
+	int			error = 0;
+	struct			xfs_delattr_context dac;
+
+	xfs_delattr_context_init(&dac, args);
+
+	do {
+		error = xfs_attr_remove_iter(&dac);
+		if (error != -EAGAIN)

fs/xfs/libxfs/xfs_attr.c xfs_has_attr( · line 406

Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10 -0
+			break;
+
+		error = xfs_attr_defer_finish(&dac);
+		if (error)
+			break;
+
+		error = xfs_trans_roll_inode(&args->trans, args->dp);
+		if (error)
+			break;
+	} while (true);

and then this whole function becomes:

int
xfs_attr_remove_args(
struct xfs_da_args *args)

Quoted 11 lines
{
	struct xfs_delattr_context	dac = {
		.da_args		= args,
	};

	do {
		error = xfs_attr_remove_iter(&dac);
	} while (xfs_attr_roll_again(&dac, &error));

	return error;
}

Alrighty then

Quoted 123 lines
Quoted 123 lines
fs/xfs/libxfs/xfs_attr.c +58 -25
+
+	return error;
+}
+
+/*
+ * Remove the attribute specified in @args.
+ *
+ * This function may return -EAGAIN to signal that the transaction needs to be
+ * rolled.  Callers should continue calling this function until they receive a
+ * return value other than -EAGAIN.
+ */
+int
+xfs_attr_remove_iter(
+	struct xfs_delattr_context *dac)
  {
+	struct xfs_da_args	*args = dac->da_args;
  	struct xfs_inode	*dp = args->dp;
-	int			error;
+
+	if (dac->dela_state == XFS_DAS_RM_SHRINK)
+		goto node;
  	if (!xfs_inode_hasattr(dp)) {
-		error = -ENOATTR;
+		return -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);
+		return xfs_attr_shortform_remove(args);
  	} else if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
-		error = xfs_attr_leaf_removename(args);
-	} else {
-		error = xfs_attr_node_removename(args);
+		return xfs_attr_leaf_removename(args);
  	}
-
-	return error;
+node:
+	return  xfs_attr_node_removename(dac);
  }
  /*
@@ -1177,15 +1232,17 @@ xfs_attr_leaf_mark_incomplete(
  /*
   * Initial setup for xfs_attr_node_removename.  Make sure the attr is there and
- * the blocks are valid.  Any remote blocks will be marked incomplete.
+ * the blocks are valid.  Any remote blocks will be marked incomplete and
+ * invalidated.
   */
  STATIC
  int xfs_attr_node_removename_setup(
-	struct xfs_da_args	*args,
-	struct xfs_da_state	**state)
+	struct xfs_delattr_context	*dac,
+	struct xfs_da_state		**state)
  {
-	int			error;
-	struct xfs_da_state_blk	*blk;
+	struct xfs_da_args		*args = dac->da_args;
+	int				error;
+	struct xfs_da_state_blk		*blk;
  	error = xfs_attr_node_hasname(args, state);
  	if (error != -EEXIST)
@@ -1195,6 +1252,13 @@ int xfs_attr_node_removename_setup(
  	ASSERT(blk->bp != NULL);
  	ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
+	/*
+	 * Store blk and state in the context incase we need to cycle out the
+	 * transaction
+	 */
+	dac->blk = blk;
+	dac->da_state = *state;
+
  	if (args->rmtblkno > 0) {
  		error = xfs_attr_leaf_mark_incomplete(args, *state);
  		if (error)
@@ -1210,12 +1274,15 @@ int xfs_attr_node_removename_setup(
  STATIC int
  xfs_attr_node_removename_rmt (
-	struct xfs_da_args	*args,
-	struct xfs_da_state	*state)
+	struct xfs_delattr_context	*dac,
+	struct xfs_da_state		*state)
  {
-	int			error = 0;
+	int				error = 0;
-	error = xfs_attr_rmtval_remove(args);
+	/*
+	 * May return -EAGAIN to request that the caller recall this function
+	 */
+	error = __xfs_attr_rmtval_remove(dac);
  	if (error)
  		return error;
@@ -1232,21 +1299,35 @@ xfs_attr_node_removename_rmt (
   * 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 either an inline or delayed operation,
+ * and may return -EAGAIN 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_attr_node_removename(
-	struct xfs_da_args	*args)
+	struct xfs_delattr_context	*dac)
  {
-	struct xfs_da_state	*state;
-	struct xfs_da_state_blk	*blk;
-	int			retval, error;
-	struct xfs_inode	*dp = args->dp;
+	struct xfs_da_args		*args = dac->da_args;
+	struct xfs_da_state		*state;
+	struct xfs_da_state_blk		*blk;
+	int				retval, error;
+	struct xfs_inode		*dp = args->dp;
  	trace_xfs_attr_node_removename(args);
+	state = dac->da_state;
+	blk = dac->blk;
-	error = xfs_attr_node_removename_setup(args, &state);
-	if (error)
-		goto out;
+	if (dac->dela_state == XFS_DAS_RM_SHRINK)
Quoted 8 lines

fs/xfs/libxfs/xfs_attr.c xfs_attr_node_removename_rmt ( · line 1327

Quoted 5 lines
fs/xfs/libxfs/xfs_attr.c +5 -0
+		goto das_rm_shrink;
+
+	if ((dac->flags & XFS_DAC_NODE_RMVNAME_INIT) == 0) {
+		dac->flags |= XFS_DAC_NODE_RMVNAME_INIT;
+		error = xfs_attr_node_removename_setup(dac, &state);

Shouldn't XFS_DAC_NODE_RMVNAME_INIT be set by
xfs_attr_node_removename_setup?

I suppose it could be. Initially this was a state not a flag, so that's why we see it here in this scope.

Quoted 9 lines

There may be reason to keep it there though. These -EAGAIN functions are admittadly sort of jumpy, so when trying to trace them though, haveing the flag in the top level like that makes it clear that when we come back through on another iteration, we dont init twice. Really, it's more to do with managing function re-entry than anything else going on in the init function. I think Brian and I have been trying our best to keep code flow craziness in the same scope rather than letting them get burried in subfunctions. Though I suppose it wouldnt be too hard to find if folks prefer the flag be in the subfunction?

Hm, ok, leave it there then. :)

Quoted 216 lines
Quoted 205 lines
Quoted 205 lines
fs/xfs/libxfs/xfs_attr.c +16 -11
+		if (error)
+			goto out;
+	}
  	/*
  	 * If there is an out-of-line value, de-allocate the blocks.
@@ -1254,8 +1335,13 @@ xfs_attr_node_removename(
  	 * overflow the maximum size of a transaction and/or hit a deadlock.
  	 */
  	if (args->rmtblkno > 0) {
-		error = xfs_attr_node_removename_rmt(args, state);
-		if (error)
+		/*
+		 * May return -EAGAIN. Remove blocks until args->rmtblkno == 0
+		 */
+		error = xfs_attr_node_removename_rmt(dac, state);
+		if (error == -EAGAIN)
+			return error;
+		else if (error)
  			goto out;
  	}
@@ -1274,17 +1360,14 @@ xfs_attr_node_removename(
  		error = xfs_da3_join(state);
  		if (error)
  			goto out;
-		error = xfs_defer_finish(&args->trans);
-		if (error)
-			goto out;
-		/*
-		 * Commit the Btree join operation and start a new trans.
-		 */
-		error = xfs_trans_roll_inode(&args->trans, dp);
-		if (error)
-			goto out;
+
+		dac->flags |= XFS_DAC_DEFER_FINISH;
+		dac->dela_state = XFS_DAS_RM_SHRINK;
+		return -EAGAIN;
  	}
+das_rm_shrink:
+
  	/*
  	 * If the result is small enough, push it all into the inode.
  	 */
fs/xfs/libxfs/xfs_attr.h +73 -0
index 66575b8..0430c79 100644
@@ -74,6 +74,75 @@ struct xfs_attr_list_context {
  };
+/*
+ * ========================================================================
+ * Structure used to pass context around among the delayed routines.
+ * ========================================================================
+ */
+
+/*
+ * Below is a state machine diagram for attr remove operations. The  XFS_DAS_*
+ * states indicate places where the function would return -EAGAIN, and then
+ * immediately resume from after being recalled by the calling function. States
+ * marked as a "subroutine state" indicate that they belong to a subroutine, and
+ * so the calling function needs to pass them back to that subroutine to allow
+ * it to finish where it left off. But they otherwise do not have a role in the
+ * calling function other than just passing through.
+ *
+ * xfs_attr_remove_iter()
+ *	  XFS_DAS_RM_SHRINK ─┐
+ *	  (subroutine state) │
+ *	                     └─>xfs_attr_node_removename()
+ *	                                      │
+ *	                                      v
+ *	                                   need to
+ *	                                shrink tree? ─n─┐
+ *	                                      │         │
+ *	                                      y         │
+ *	                                      │         │
+ *	                                      v         │
+ *	                              XFS_DAS_RM_SHRINK │
+ *	                                      │         │
+ *	                                      v         │
+ *	                                     done <─────┘
+ *
+ */
+
+/*
+ * Enum values for xfs_delattr_context.da_state
+ *
+ * These values are used by delayed attribute operations to keep track  of where
+ * they were before they returned -EAGAIN.  A return code of -EAGAIN signals the
+ * calling function to roll the transaction, and then recall the subroutine to
+ * finish the operation.  The enum is then used by the subroutine to jump back
+ * to where it was and resume executing where it left off.
+ */
+enum xfs_delattr_state {
+				      /* Zero is uninitalized */
+	XFS_DAS_RM_SHRINK	= 1,  /* We are shrinking the tree */
+};
+
+/*
+ * Defines for xfs_delattr_context.flags
+ */
+#define XFS_DAC_DEFER_FINISH		0x01 /* finish the transaction */
+#define XFS_DAC_NODE_RMVNAME_INIT	0x02 /* xfs_attr_node_removename init */
+
+/*
+ * Context used for keeping track of delayed attribute operations
+ */
+struct xfs_delattr_context {
+	struct xfs_da_args      *da_args;
+
+	/* Used in xfs_attr_node_removename to roll through removing blocks */
+	struct xfs_da_state     *da_state;
+	struct xfs_da_state_blk *blk;
+
+	/* Used to keep track of current state of delayed operation */
+	unsigned int            flags;
+	enum xfs_delattr_state  dela_state;
+};
+
  /*========================================================================
   * Function prototypes for the kernel.
   *========================================================================*/
@@ -91,6 +160,10 @@ int xfs_attr_set(struct xfs_da_args *args);
  int xfs_attr_set_args(struct xfs_da_args *args);
  int xfs_has_attr(struct xfs_da_args *args);
  int xfs_attr_remove_args(struct xfs_da_args *args);
+int xfs_attr_remove_iter(struct xfs_delattr_context *dac);
+int xfs_attr_defer_finish(struct xfs_delattr_context *dac);
  bool xfs_attr_namecheck(const void *name, size_t length);
+void xfs_delattr_context_init(struct xfs_delattr_context *dac,
+			      struct xfs_da_args *args);
  #endif	/* __XFS_ATTR_H__ */
fs/xfs/libxfs/xfs_attr_leaf.c +1 -1
index f55402b..2e36c8b 100644
@@ -19,8 +19,8 @@
  #include "xfs_bmap_btree.h"
  #include "xfs_bmap.h"
  #include "xfs_attr_sf.h"
-#include "xfs_attr_remote.h"
  #include "xfs_attr.h"
+#include "xfs_attr_remote.h"
  #include "xfs_attr_leaf.h"
  #include "xfs_error.h"
  #include "xfs_trace.h"
fs/xfs/libxfs/xfs_attr_remote.c +15 -11
index f770159..f2d46c7 100644
@@ -676,14 +676,16 @@ xfs_attr_rmtval_invalidate(
   */
  int
  xfs_attr_rmtval_remove(
-	struct xfs_da_args      *args)
+	struct xfs_da_args		*args)
  {
-	xfs_dablk_t		lblkno;
-	int			blkcnt;
-	int			error = 0;
-	int			retval = 0;
+	struct xfs_delattr_context	dac;
+	xfs_dablk_t			lblkno;
+	int				blkcnt;
+	int				error = 0;
+	int				retval = 0;
  	trace_xfs_attr_rmtval_remove(args);
+	xfs_delattr_context_init(&dac, args);
  	/*
  	 * Keep de-allocating extents until the remote-value region is gone.
@@ -691,10 +693,14 @@ xfs_attr_rmtval_remove(
  	lblkno = args->rmtblkno;
  	blkcnt = args->rmtblkcnt;
  	do {
-		retval = __xfs_attr_rmtval_remove(args);
+		retval = __xfs_attr_rmtval_remove(&dac);
  		if (retval && retval != EAGAIN)
  			return retval;
+		error = xfs_attr_defer_finish(&dac);
+		if (error)
+			break;
+
  		/*
  		 * Close out trans and start the next one in the chain.
  		 */
@@ -713,9 +719,10 @@ xfs_attr_rmtval_remove(
   */
  int
  __xfs_attr_rmtval_remove(
-	struct xfs_da_args	*args)
+	struct xfs_delattr_context	*dac)
  {
-	int			error, done;
+	struct xfs_da_args		*args = dac->da_args;
+	int				error, done;
  	/*
  	 * Unmap value blocks for this attr.
@@ -725,12 +732,10 @@ __xfs_attr_rmtval_remove(
  	if (error)
  		return error;
-	error = xfs_defer_finish(&args->trans);
-	if (error)
-		return error;
Quoted 8 lines

fs/xfs/libxfs/xfs_attr_remote.c __xfs_attr_rmtval_remove( · line 736

Quoted 4 lines
fs/xfs/libxfs/xfs_attr_remote.c +2 -2
-
-	if (!done)
+	if (!done) {
+		dac->flags &= ~XFS_DAC_DEFER_FINISH;

Why do we strip off DEFER_FINISH here? Is it because we're making xfs_attr_rmtval_remove invoke xfs_defer_finish unconditionally to clear out any pending rmap items?

Sorry, that should have been a flag set, not a strip. Will fix!

Quoted 1 line
Quoted 7 lines
Quoted 6 lines

If you transformed the do-while loop in xfs_attr_rmtval_remove to use xfs_attr_roll_again, then you could make this set DEFER_FINISH, which would make me a lot less suspicious that we're dropping state here.

(It would also clean up a lot of the defer_finish -> trans_roll_inode code that's scattering everywhere...)

Yes, will do that. Thanks for the review!

:D

--D

Quoted 37 lines
Quoted 37 lines

--D

Quoted 34 lines
fs/xfs/libxfs/xfs_attr_remote.c +1 -0
  		return -EAGAIN;
+	}
  	return error;
  }
fs/xfs/libxfs/xfs_attr_remote.h +1 -1
index ee3337b..351da00 100644
@@ -14,5 +14,5 @@ int xfs_attr_rmtval_remove(struct xfs_da_args *args);
  int xfs_attr_rmtval_stale(struct xfs_inode *ip, struct xfs_bmbt_irec *map,
  		xfs_buf_flags_t incore_flags);
  int xfs_attr_rmtval_invalidate(struct xfs_da_args *args);
-int __xfs_attr_rmtval_remove(struct xfs_da_args *args);
+int __xfs_attr_rmtval_remove(struct xfs_delattr_context *dac);
  #endif /* __XFS_ATTR_REMOTE_H__ */
fs/xfs/xfs_attr_inactive.c +1 -1
index c42f90e..b2150fa 100644
@@ -15,10 +15,10 @@
  #include "xfs_da_format.h"
  #include "xfs_da_btree.h"
  #include "xfs_inode.h"
+#include "xfs_attr.h"
  #include "xfs_attr_remote.h"
  #include "xfs_trans.h"
  #include "xfs_bmap.h"
-#include "xfs_attr.h"
  #include "xfs_attr_leaf.h"
  #include "xfs_quota.h"
  #include "xfs_dir2.h"
Signature · 1 line
2.7.4
#66 lore raw

Re: [PATCH v9 22/24] xfs: Add delay ready attr remove routines

Quoted 107 lines · Darrick J. Wong
Quoted 99 lines · Allison Collins
Quoted 96 lines · Darrick J. Wong
Quoted 78 lines · Allison Collins

This patch modifies the attr remove routines to be delay ready. This means they no longer roll or commit transactions, but instead return -EAGAIN to have the calling routine roll and refresh the transaction. In this series, xfs_attr_remove_args has become xfs_attr_remove_iter, which uses a sort of state machine like switch to keep track of where it was when EAGAIN was returned. xfs_attr_node_removename has also been modified to use the switch, and a new version of xfs_attr_remove_args consists of a simple loop to refresh the transaction until the operation is completed. A new XFS_DAC_DEFER_FINISH flag is used to finish the transaction where ever the existing code used to.

Calls to xfs_attr_rmtval_remove are replaced with the delay ready version __xfs_attr_rmtval_remove. We will rename __xfs_attr_rmtval_remove back to xfs_attr_rmtval_remove when we are done.

xfs_attr_rmtval_remove itself is still in use by the set routines (used during a rename). For reasons of perserving existing function, we modify xfs_attr_rmtval_remove to call xfs_defer_finish when the flag is set. Similar to how xfs_attr_remove_args does here. Once we transition the set routines to be delay ready, xfs_attr_rmtval_remove is no longer used and will be removed.

This patch also adds a new struct xfs_delattr_context, which we will use to keep track of the current state of an attribute operation. The new xfs_delattr_state enum 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.

Below is a state machine diagram for attr remove operations. The XFS_DAS_* states indicate places where the function would return -EAGAIN, and then immediately resume from after being recalled by the calling function. States marked as a "subroutine state" indicate that they belong to a subroutine, and so the calling function needs to pass them back to that subroutine to allow it to finish where it left off. But they otherwise do not have a role in the calling function other than just passing through.

xfs_attr_remove_iter()

           XFS_DAS_RM_SHRINK     ─┐
           (subroutine state)     │
                                  └─>xfs_attr_node_removename()
                                                   │

v
need to
shrink tree? ─n─┐
│ │
y │
│ │
v │
XFS_DAS_RM_SHRINK │
│ │
v │
done <─────┘

---
   fs/xfs/libxfs/xfs_attr.c        | 159 ++++++++++++++++++++++++++++++----------
   fs/xfs/libxfs/xfs_attr.h        |  73 ++++++++++++++++++
   fs/xfs/libxfs/xfs_attr_leaf.c   |   2 +-
   fs/xfs/libxfs/xfs_attr_remote.c |  31 ++++----
   fs/xfs/libxfs/xfs_attr_remote.h |   2 +-
   fs/xfs/xfs_attr_inactive.c      |   2 +-
   6 files changed, 215 insertions(+), 54 deletions(-)
fs/xfs/libxfs/xfs_attr.c +1 -1
index c8cae68..7213589 100644
@@ -53,12 +53,21 @@ STATIC int xfs_attr_leaf_hasname(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_attr_node_removename(xfs_da_args_t *args);
+STATIC int xfs_attr_node_removename(struct xfs_delattr_context *dac);
   STATIC int xfs_attr_node_hasname(xfs_da_args_t *args,

fs/xfs/libxfs/xfs_attr.c STATIC int xfs_attr_leaf_hasname(struct xfs_da_args *args, struct xfs_buf **bp); · line 67

Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +7 -0
   				 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);
+void
+xfs_delattr_context_init(
+	struct xfs_delattr_context	*dac,
+	struct xfs_da_args		*args)
+{
+	memset(dac, 0, sizeof(struct xfs_delattr_context));
+	dac->da_args = args;

Couldn't this could be open coded as:

struct xfs_delattr_context	dac = {
	.da_args		= args,
};
Quoted 6 lines
Quoted 2 lines

in the callers? One less helper function, and it means that the stack contents will always be fully initialized.

I believe Dave had suggested the initializer back when I had dac a member of args instead of the other way around. I dont know that he was too particular about exactly what the initializer was though. Is this generally the standard for initializers?

Quoted 8 lines

One of them, yes. :)

I've started to prefer that form simply because we don't have to remember that some struct is uninitialized between its definition and some later initializer function call. There are (many) places where we have to unpack other things before we can initialize a struct, but for the simpler cases I like to reduce the brainpower needed to understand code, lest I turn into Mr. D P Gumby.

Alrighty, will change that out. Thanks!

Allison

Quoted 510 lines
Quoted 233 lines
Quoted 31 lines

fs/xfs/libxfs/xfs_attr.c xfs_attr_set_shortform( · line 274

Quoted 11 lines
fs/xfs/libxfs/xfs_attr.c +3 -0
+}
+
   int
   xfs_inode_hasattr(
   	struct xfs_inode	*ip)
@@ -263,6 +272,18 @@ xfs_attr_set_shortform(
   	return 0;
   }
+int xfs_attr_defer_finish(

static inline int
xfs_attr_defer_finish(

fs/xfs/libxfs/xfs_attr.c xfs_attr_set_shortform( · line 284

Quoted 9 lines
fs/xfs/libxfs/xfs_attr.c +9 -0
+	struct xfs_delattr_context      *dac)
+{
+	struct xfs_da_args              *args = dac->da_args;
+
+	if (!(dac->flags & XFS_DAC_DEFER_FINISH))
+		return 0;
+
+	dac->flags &= ~XFS_DAC_DEFER_FINISH;
+	return xfs_defer_finish(&args->trans);

I also wonder if you want to hoist the trans_roll_inode to here too?

Actually, what if this instead became:

static inline bool
xfs_attr_roll_again(

Quoted 17 lines
	struct xfs_delattr_context	*dac,
	int				*error)
{
	if (*error != -EAGAIN)
		return false;

	if (dac->flags & XFS_DAC_DEFER_FINISH)) {
		dac->flags &= ~XFS_DAC_DEFER_FINISH;
		*error = xfs_defer_finish(&args->trans);
		if (*error)
			return false;
	}

	*error = xfs_trans_roll_inode(&dac->da_args->trans, dac->da_args->dp);
	return *error == 0;
}

Sure, that should be fine

Quoted 36 lines
Quoted 20 lines
fs/xfs/libxfs/xfs_attr.c +12 -1
+}
+
   /*
    * Set the attribute specified in @args.
    */
@@ -363,23 +384,57 @@ xfs_has_attr(
    */
   int
   xfs_attr_remove_args(
-	struct xfs_da_args      *args)
+	struct xfs_da_args	*args)
+{
+	int			error = 0;
+	struct			xfs_delattr_context dac;
+
+	xfs_delattr_context_init(&dac, args);
+
+	do {
+		error = xfs_attr_remove_iter(&dac);
+		if (error != -EAGAIN)

fs/xfs/libxfs/xfs_attr.c xfs_has_attr( · line 406

Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10 -0
+			break;
+
+		error = xfs_attr_defer_finish(&dac);
+		if (error)
+			break;
+
+		error = xfs_trans_roll_inode(&args->trans, args->dp);
+		if (error)
+			break;
+	} while (true);

and then this whole function becomes:

int
xfs_attr_remove_args(
struct xfs_da_args *args)

Quoted 11 lines
{
	struct xfs_delattr_context	dac = {
		.da_args		= args,
	};

	do {
		error = xfs_attr_remove_iter(&dac);
	} while (xfs_attr_roll_again(&dac, &error));

	return error;
}

Alrighty then

Quoted 123 lines
Quoted 123 lines
fs/xfs/libxfs/xfs_attr.c +58 -25
+
+	return error;
+}
+
+/*
+ * Remove the attribute specified in @args.
+ *
+ * This function may return -EAGAIN to signal that the transaction needs to be
+ * rolled.  Callers should continue calling this function until they receive a
+ * return value other than -EAGAIN.
+ */
+int
+xfs_attr_remove_iter(
+	struct xfs_delattr_context *dac)
   {
+	struct xfs_da_args	*args = dac->da_args;
   	struct xfs_inode	*dp = args->dp;
-	int			error;
+
+	if (dac->dela_state == XFS_DAS_RM_SHRINK)
+		goto node;
   	if (!xfs_inode_hasattr(dp)) {
-		error = -ENOATTR;
+		return -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);
+		return xfs_attr_shortform_remove(args);
   	} else if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
-		error = xfs_attr_leaf_removename(args);
-	} else {
-		error = xfs_attr_node_removename(args);
+		return xfs_attr_leaf_removename(args);
   	}
-
-	return error;
+node:
+	return  xfs_attr_node_removename(dac);
   }
   /*
@@ -1177,15 +1232,17 @@ xfs_attr_leaf_mark_incomplete(
   /*
    * Initial setup for xfs_attr_node_removename.  Make sure the attr is there and
- * the blocks are valid.  Any remote blocks will be marked incomplete.
+ * the blocks are valid.  Any remote blocks will be marked incomplete and
+ * invalidated.
    */
   STATIC
   int xfs_attr_node_removename_setup(
-	struct xfs_da_args	*args,
-	struct xfs_da_state	**state)
+	struct xfs_delattr_context	*dac,
+	struct xfs_da_state		**state)
   {
-	int			error;
-	struct xfs_da_state_blk	*blk;
+	struct xfs_da_args		*args = dac->da_args;
+	int				error;
+	struct xfs_da_state_blk		*blk;
   	error = xfs_attr_node_hasname(args, state);
   	if (error != -EEXIST)
@@ -1195,6 +1252,13 @@ int xfs_attr_node_removename_setup(
   	ASSERT(blk->bp != NULL);
   	ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
+	/*
+	 * Store blk and state in the context incase we need to cycle out the
+	 * transaction
+	 */
+	dac->blk = blk;
+	dac->da_state = *state;
+
   	if (args->rmtblkno > 0) {
   		error = xfs_attr_leaf_mark_incomplete(args, *state);
   		if (error)
@@ -1210,12 +1274,15 @@ int xfs_attr_node_removename_setup(
   STATIC int
   xfs_attr_node_removename_rmt (
-	struct xfs_da_args	*args,
-	struct xfs_da_state	*state)
+	struct xfs_delattr_context	*dac,
+	struct xfs_da_state		*state)
   {
-	int			error = 0;
+	int				error = 0;
-	error = xfs_attr_rmtval_remove(args);
+	/*
+	 * May return -EAGAIN to request that the caller recall this function
+	 */
+	error = __xfs_attr_rmtval_remove(dac);
   	if (error)
   		return error;
@@ -1232,21 +1299,35 @@ xfs_attr_node_removename_rmt (
    * 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 either an inline or delayed operation,
+ * and may return -EAGAIN 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_attr_node_removename(
-	struct xfs_da_args	*args)
+	struct xfs_delattr_context	*dac)
   {
-	struct xfs_da_state	*state;
-	struct xfs_da_state_blk	*blk;
-	int			retval, error;
-	struct xfs_inode	*dp = args->dp;
+	struct xfs_da_args		*args = dac->da_args;
+	struct xfs_da_state		*state;
+	struct xfs_da_state_blk		*blk;
+	int				retval, error;
+	struct xfs_inode		*dp = args->dp;
   	trace_xfs_attr_node_removename(args);
+	state = dac->da_state;
+	blk = dac->blk;
-	error = xfs_attr_node_removename_setup(args, &state);
-	if (error)
-		goto out;
+	if (dac->dela_state == XFS_DAS_RM_SHRINK)
Quoted 8 lines

fs/xfs/libxfs/xfs_attr.c xfs_attr_node_removename_rmt ( · line 1327

Quoted 5 lines
fs/xfs/libxfs/xfs_attr.c +5 -0
+		goto das_rm_shrink;
+
+	if ((dac->flags & XFS_DAC_NODE_RMVNAME_INIT) == 0) {
+		dac->flags |= XFS_DAC_NODE_RMVNAME_INIT;
+		error = xfs_attr_node_removename_setup(dac, &state);

Shouldn't XFS_DAC_NODE_RMVNAME_INIT be set by
xfs_attr_node_removename_setup?

I suppose it could be. Initially this was a state not a flag, so that's why we see it here in this scope.

Quoted 9 lines

There may be reason to keep it there though. These -EAGAIN functions are admittadly sort of jumpy, so when trying to trace them though, haveing the flag in the top level like that makes it clear that when we come back through on another iteration, we dont init twice. Really, it's more to do with managing function re-entry than anything else going on in the init function. I think Brian and I have been trying our best to keep code flow craziness in the same scope rather than letting them get burried in subfunctions. Though I suppose it wouldnt be too hard to find if folks prefer the flag be in the subfunction?

Hm, ok, leave it there then. :)

Quoted 216 lines
Quoted 205 lines
Quoted 205 lines
fs/xfs/libxfs/xfs_attr.c +16 -11
+		if (error)
+			goto out;
+	}
   	/*
   	 * If there is an out-of-line value, de-allocate the blocks.
@@ -1254,8 +1335,13 @@ xfs_attr_node_removename(
   	 * overflow the maximum size of a transaction and/or hit a deadlock.
   	 */
   	if (args->rmtblkno > 0) {
-		error = xfs_attr_node_removename_rmt(args, state);
-		if (error)
+		/*
+		 * May return -EAGAIN. Remove blocks until args->rmtblkno == 0
+		 */
+		error = xfs_attr_node_removename_rmt(dac, state);
+		if (error == -EAGAIN)
+			return error;
+		else if (error)
   			goto out;
   	}
@@ -1274,17 +1360,14 @@ xfs_attr_node_removename(
   		error = xfs_da3_join(state);
   		if (error)
   			goto out;
-		error = xfs_defer_finish(&args->trans);
-		if (error)
-			goto out;
-		/*
-		 * Commit the Btree join operation and start a new trans.
-		 */
-		error = xfs_trans_roll_inode(&args->trans, dp);
-		if (error)
-			goto out;
+
+		dac->flags |= XFS_DAC_DEFER_FINISH;
+		dac->dela_state = XFS_DAS_RM_SHRINK;
+		return -EAGAIN;
   	}
+das_rm_shrink:
+
   	/*
   	 * If the result is small enough, push it all into the inode.
   	 */
fs/xfs/libxfs/xfs_attr.h +73 -0
index 66575b8..0430c79 100644
@@ -74,6 +74,75 @@ struct xfs_attr_list_context {
   };
+/*
+ * ========================================================================
+ * Structure used to pass context around among the delayed routines.
+ * ========================================================================
+ */
+
+/*
+ * Below is a state machine diagram for attr remove operations. The  XFS_DAS_*
+ * states indicate places where the function would return -EAGAIN, and then
+ * immediately resume from after being recalled by the calling function. States
+ * marked as a "subroutine state" indicate that they belong to a subroutine, and
+ * so the calling function needs to pass them back to that subroutine to allow
+ * it to finish where it left off. But they otherwise do not have a role in the
+ * calling function other than just passing through.
+ *
+ * xfs_attr_remove_iter()
+ *	  XFS_DAS_RM_SHRINK ─┐
+ *	  (subroutine state) │
+ *	                     └─>xfs_attr_node_removename()
+ *	                                      │
+ *	                                      v
+ *	                                   need to
+ *	                                shrink tree? ─n─┐
+ *	                                      │         │
+ *	                                      y         │
+ *	                                      │         │
+ *	                                      v         │
+ *	                              XFS_DAS_RM_SHRINK │
+ *	                                      │         │
+ *	                                      v         │
+ *	                                     done <─────┘
+ *
+ */
+
+/*
+ * Enum values for xfs_delattr_context.da_state
+ *
+ * These values are used by delayed attribute operations to keep track  of where
+ * they were before they returned -EAGAIN.  A return code of -EAGAIN signals the
+ * calling function to roll the transaction, and then recall the subroutine to
+ * finish the operation.  The enum is then used by the subroutine to jump back
+ * to where it was and resume executing where it left off.
+ */
+enum xfs_delattr_state {
+				      /* Zero is uninitalized */
+	XFS_DAS_RM_SHRINK	= 1,  /* We are shrinking the tree */
+};
+
+/*
+ * Defines for xfs_delattr_context.flags
+ */
+#define XFS_DAC_DEFER_FINISH		0x01 /* finish the transaction */
+#define XFS_DAC_NODE_RMVNAME_INIT	0x02 /* xfs_attr_node_removename init */
+
+/*
+ * Context used for keeping track of delayed attribute operations
+ */
+struct xfs_delattr_context {
+	struct xfs_da_args      *da_args;
+
+	/* Used in xfs_attr_node_removename to roll through removing blocks */
+	struct xfs_da_state     *da_state;
+	struct xfs_da_state_blk *blk;
+
+	/* Used to keep track of current state of delayed operation */
+	unsigned int            flags;
+	enum xfs_delattr_state  dela_state;
+};
+
   /*========================================================================
    * Function prototypes for the kernel.
    *========================================================================*/
@@ -91,6 +160,10 @@ int xfs_attr_set(struct xfs_da_args *args);
   int xfs_attr_set_args(struct xfs_da_args *args);
   int xfs_has_attr(struct xfs_da_args *args);
   int xfs_attr_remove_args(struct xfs_da_args *args);
+int xfs_attr_remove_iter(struct xfs_delattr_context *dac);
+int xfs_attr_defer_finish(struct xfs_delattr_context *dac);
   bool xfs_attr_namecheck(const void *name, size_t length);
+void xfs_delattr_context_init(struct xfs_delattr_context *dac,
+			      struct xfs_da_args *args);
   #endif	/* __XFS_ATTR_H__ */
fs/xfs/libxfs/xfs_attr_leaf.c +1 -1
index f55402b..2e36c8b 100644
@@ -19,8 +19,8 @@
   #include "xfs_bmap_btree.h"
   #include "xfs_bmap.h"
   #include "xfs_attr_sf.h"
-#include "xfs_attr_remote.h"
   #include "xfs_attr.h"
+#include "xfs_attr_remote.h"
   #include "xfs_attr_leaf.h"
   #include "xfs_error.h"
   #include "xfs_trace.h"
fs/xfs/libxfs/xfs_attr_remote.c +15 -11
index f770159..f2d46c7 100644
@@ -676,14 +676,16 @@ xfs_attr_rmtval_invalidate(
    */
   int
   xfs_attr_rmtval_remove(
-	struct xfs_da_args      *args)
+	struct xfs_da_args		*args)
   {
-	xfs_dablk_t		lblkno;
-	int			blkcnt;
-	int			error = 0;
-	int			retval = 0;
+	struct xfs_delattr_context	dac;
+	xfs_dablk_t			lblkno;
+	int				blkcnt;
+	int				error = 0;
+	int				retval = 0;
   	trace_xfs_attr_rmtval_remove(args);
+	xfs_delattr_context_init(&dac, args);
   	/*
   	 * Keep de-allocating extents until the remote-value region is gone.
@@ -691,10 +693,14 @@ xfs_attr_rmtval_remove(
   	lblkno = args->rmtblkno;
   	blkcnt = args->rmtblkcnt;
   	do {
-		retval = __xfs_attr_rmtval_remove(args);
+		retval = __xfs_attr_rmtval_remove(&dac);
   		if (retval && retval != EAGAIN)
   			return retval;
+		error = xfs_attr_defer_finish(&dac);
+		if (error)
+			break;
+
   		/*
   		 * Close out trans and start the next one in the chain.
   		 */
@@ -713,9 +719,10 @@ xfs_attr_rmtval_remove(
    */
   int
   __xfs_attr_rmtval_remove(
-	struct xfs_da_args	*args)
+	struct xfs_delattr_context	*dac)
   {
-	int			error, done;
+	struct xfs_da_args		*args = dac->da_args;
+	int				error, done;
   	/*
   	 * Unmap value blocks for this attr.
@@ -725,12 +732,10 @@ __xfs_attr_rmtval_remove(
   	if (error)
   		return error;
-	error = xfs_defer_finish(&args->trans);
-	if (error)
-		return error;
Quoted 8 lines

fs/xfs/libxfs/xfs_attr_remote.c __xfs_attr_rmtval_remove( · line 736

Quoted 4 lines
fs/xfs/libxfs/xfs_attr_remote.c +2 -2
-
-	if (!done)
+	if (!done) {
+		dac->flags &= ~XFS_DAC_DEFER_FINISH;

Why do we strip off DEFER_FINISH here? Is it because we're making xfs_attr_rmtval_remove invoke xfs_defer_finish unconditionally to clear out any pending rmap items?

Sorry, that should have been a flag set, not a strip. Will fix!

Quoted 1 line
Quoted 7 lines
Quoted 6 lines

If you transformed the do-while loop in xfs_attr_rmtval_remove to use xfs_attr_roll_again, then you could make this set DEFER_FINISH, which would make me a lot less suspicious that we're dropping state here.

(It would also clean up a lot of the defer_finish -> trans_roll_inode code that's scattering everywhere...)

Yes, will do that. Thanks for the review!

:D

--D

Quoted 37 lines
Quoted 37 lines

--D

Quoted 34 lines
fs/xfs/libxfs/xfs_attr_remote.c +1 -0
   		return -EAGAIN;
+	}
   	return error;
   }
fs/xfs/libxfs/xfs_attr_remote.h +1 -1
index ee3337b..351da00 100644
@@ -14,5 +14,5 @@ int xfs_attr_rmtval_remove(struct xfs_da_args *args);
   int xfs_attr_rmtval_stale(struct xfs_inode *ip, struct xfs_bmbt_irec *map,
   		xfs_buf_flags_t incore_flags);
   int xfs_attr_rmtval_invalidate(struct xfs_da_args *args);
-int __xfs_attr_rmtval_remove(struct xfs_da_args *args);
+int __xfs_attr_rmtval_remove(struct xfs_delattr_context *dac);
   #endif /* __XFS_ATTR_REMOTE_H__ */
fs/xfs/xfs_attr_inactive.c +1 -1
index c42f90e..b2150fa 100644
@@ -15,10 +15,10 @@
   #include "xfs_da_format.h"
   #include "xfs_da_btree.h"
   #include "xfs_inode.h"
+#include "xfs_attr.h"
   #include "xfs_attr_remote.h"
   #include "xfs_trans.h"
   #include "xfs_bmap.h"
-#include "xfs_attr.h"
   #include "xfs_attr_leaf.h"
   #include "xfs_quota.h"
   #include "xfs_dir2.h"
Signature · 1 line
2.7.4
#67 lore raw

Re: [PATCH v9 22/24] xfs: Add delay ready attr remove routines

In reply to Allison Collins

On Thu, Apr 30, 2020 at 03:50:14PM -0700, Allison Collins wrote:
...

Quoted 15 lines
---
 fs/xfs/libxfs/xfs_attr.c        | 159 ++++++++++++++++++++++++++++++----------
 fs/xfs/libxfs/xfs_attr.h        |  73 ++++++++++++++++++
 fs/xfs/libxfs/xfs_attr_leaf.c   |   2 +-
 fs/xfs/libxfs/xfs_attr_remote.c |  31 ++++----
 fs/xfs/libxfs/xfs_attr_remote.h |   2 +-
 fs/xfs/xfs_attr_inactive.c      |   2 +-
 6 files changed, 215 insertions(+), 54 deletions(-)
fs/xfs/libxfs/xfs_attr.c +0 -0
index c8cae68..7213589 100644

...

Quoted 1 line
fs/xfs/libxfs/xfs_attr.c +0 -0
@@ -363,23 +384,57 @@ xfs_has_attr(

...

Quoted 7 lines
fs/xfs/libxfs/xfs_attr.c +7 -0
+/*
+ * Remove the attribute specified in @args.
+ *
+ * This function may return -EAGAIN to signal that the transaction needs to be
+ * rolled.  Callers should continue calling this function until they receive a
+ * return value other than -EAGAIN.
+ */

fs/xfs/libxfs/xfs_attr.c xfs_has_attr( · line 426

Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +7 -1
+int
+xfs_attr_remove_iter(
+	struct xfs_delattr_context *dac)
 {
+	struct xfs_da_args	*args = dac->da_args;
 	struct xfs_inode	*dp = args->dp;
-	int			error;
+
+	if (dac->dela_state == XFS_DAS_RM_SHRINK)
+		goto node;

If we're in the above state, doesn't that mean we're in node format and should fall through to the node function based on the logic below anyways?

Quoted 21 lines
fs/xfs/libxfs/xfs_attr.c +5 -7
 	if (!xfs_inode_hasattr(dp)) {
-		error = -ENOATTR;
+		return -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);
+		return xfs_attr_shortform_remove(args);
 	} else if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
-		error = xfs_attr_leaf_removename(args);
-	} else {
-		error = xfs_attr_node_removename(args);
+		return xfs_attr_leaf_removename(args);
 	}
-
-	return error;
+node:
+	return  xfs_attr_node_removename(dac);
 }
 
 /*

...

Quoted 31 lines
fs/xfs/libxfs/xfs_attr.c +13 -7
@@ -1232,21 +1299,35 @@ xfs_attr_node_removename_rmt (
  * 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 either an inline or delayed operation,
+ * and may return -EAGAIN 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_attr_node_removename(
-	struct xfs_da_args	*args)
+	struct xfs_delattr_context	*dac)
 {
-	struct xfs_da_state	*state;
-	struct xfs_da_state_blk	*blk;
-	int			retval, error;
-	struct xfs_inode	*dp = args->dp;
+	struct xfs_da_args		*args = dac->da_args;
+	struct xfs_da_state		*state;
+	struct xfs_da_state_blk		*blk;
+	int				retval, error;
+	struct xfs_inode		*dp = args->dp;
 
 	trace_xfs_attr_node_removename(args);
+	state = dac->da_state;
+	blk = dac->blk;
 
-	error = xfs_attr_node_removename_setup(args, &state);
-	if (error)

fs/xfs/libxfs/xfs_attr.c xfs_attr_node_removename_rmt ( · line 1330

Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +9 -1
-		goto out;
+	if (dac->dela_state == XFS_DAS_RM_SHRINK)
+		goto das_rm_shrink;
+
+	if ((dac->flags & XFS_DAC_NODE_RMVNAME_INIT) == 0) {
+		dac->flags |= XFS_DAC_NODE_RMVNAME_INIT;
+		error = xfs_attr_node_removename_setup(dac, &state);
+		if (error)
+			goto out;
+	}

Now that we've factored out this state with the flag, I wonder if we could factor out this logic and pull it all the way up to xfs_attr_remove_args(). That would remove the init flag, we'd presumably just have to duplicate the format checks to make sure the fork is in node format.

I'd consider that a followup patch, btw. I know it's a bit circuitous to add the flag only to then remove it, but I think there's value in making simple, incremental changes. ;)

Quoted 30 lines
fs/xfs/libxfs/xfs_attr.c +7 -9
 	/*
 	 * If there is an out-of-line value, de-allocate the blocks.
@@ -1254,8 +1335,13 @@ xfs_attr_node_removename(
 	 * overflow the maximum size of a transaction and/or hit a deadlock.
 	 */
 	if (args->rmtblkno > 0) {
-		error = xfs_attr_node_removename_rmt(args, state);
-		if (error)
+		/*
+		 * May return -EAGAIN. Remove blocks until args->rmtblkno == 0
+		 */
+		error = xfs_attr_node_removename_rmt(dac, state);
+		if (error == -EAGAIN)
+			return error;
+		else if (error)
 			goto out;
 	}
 
@@ -1274,17 +1360,14 @@ xfs_attr_node_removename(
 		error = xfs_da3_join(state);
 		if (error)
 			goto out;
-		error = xfs_defer_finish(&args->trans);
-		if (error)
-			goto out;
-		/*
-		 * Commit the Btree join operation and start a new trans.
-		 */
-		error = xfs_trans_roll_inode(&args->trans, dp);

fs/xfs/libxfs/xfs_attr.c xfs_attr_node_removename( · line 1370

Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +6 -2
-		if (error)
-			goto out;
+
+		dac->flags |= XFS_DAC_DEFER_FINISH;
+		dac->dela_state = XFS_DAS_RM_SHRINK;
+		return -EAGAIN;
 	}
 
+das_rm_shrink:
+

Alternatively to the state question in xfs_attr_remove_iter(), I wonder if we could lift the bottom part of this function (that does the tree collapse and potential node shrink) into the caller. AFAICT that would isolate all of the xattr remove state tracking code to xfs_attr_remove_iter(), which would be a pretty nice result IMO.

Quoted 3 lines
fs/xfs/libxfs/xfs_attr.c +0 -0
 	/*
 	 * If the result is small enough, push it all into the inode.
 	 */

...

Quoted 4 lines
fs/xfs/libxfs/xfs_attr_remote.c +0 -0
index f770159..f2d46c7 100644

...

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

Quoted 13 lines
fs/xfs/libxfs/xfs_attr_remote.c +5 -1
@@ -691,10 +693,14 @@ xfs_attr_rmtval_remove(
 	lblkno = args->rmtblkno;
 	blkcnt = args->rmtblkcnt;
 	do {
-		retval = __xfs_attr_rmtval_remove(args);
+		retval = __xfs_attr_rmtval_remove(&dac);
 		if (retval && retval != EAGAIN)
 			return retval;
 
+		error = xfs_attr_defer_finish(&dac);
+		if (error)
+			break;
+

This seems to come out of nowhere..?

Brian

Quoted 62 lines
fs/xfs/libxfs/xfs_attr_remote.c +6 -7
 		/*
 		 * Close out trans and start the next one in the chain.
 		 */
@@ -713,9 +719,10 @@ xfs_attr_rmtval_remove(
  */
 int
 __xfs_attr_rmtval_remove(
-	struct xfs_da_args	*args)
+	struct xfs_delattr_context	*dac)
 {
-	int			error, done;
+	struct xfs_da_args		*args = dac->da_args;
+	int				error, done;
 
 	/*
 	 * Unmap value blocks for this attr.
@@ -725,12 +732,10 @@ __xfs_attr_rmtval_remove(
 	if (error)
 		return error;
 
-	error = xfs_defer_finish(&args->trans);
-	if (error)
-		return error;
-
-	if (!done)
+	if (!done) {
+		dac->flags &= ~XFS_DAC_DEFER_FINISH;
 		return -EAGAIN;
+	}
 
 	return error;
 }
fs/xfs/libxfs/xfs_attr_remote.h +1 -1
index ee3337b..351da00 100644
@@ -14,5 +14,5 @@ int xfs_attr_rmtval_remove(struct xfs_da_args *args);
 int xfs_attr_rmtval_stale(struct xfs_inode *ip, struct xfs_bmbt_irec *map,
 		xfs_buf_flags_t incore_flags);
 int xfs_attr_rmtval_invalidate(struct xfs_da_args *args);
-int __xfs_attr_rmtval_remove(struct xfs_da_args *args);
+int __xfs_attr_rmtval_remove(struct xfs_delattr_context *dac);
 #endif /* __XFS_ATTR_REMOTE_H__ */
fs/xfs/xfs_attr_inactive.c +1 -1
index c42f90e..b2150fa 100644
@@ -15,10 +15,10 @@
 #include "xfs_da_format.h"
 #include "xfs_da_btree.h"
 #include "xfs_inode.h"
+#include "xfs_attr.h"
 #include "xfs_attr_remote.h"
 #include "xfs_trans.h"
 #include "xfs_bmap.h"
-#include "xfs_attr.h"
 #include "xfs_attr_leaf.h"
 #include "xfs_quota.h"
 #include "xfs_dir2.h"
Signature · 1 line
2.7.4
#68 lore raw

PATCH v9 23/24 xfs: Add delay ready attr set routines

In reply to Allison Collins

This patch modifies the attr set routines to be delay ready. This means they no longer roll or commit transactions, but instead return -EAGAIN to have the calling routine roll and refresh the transaction. In this series, xfs_attr_set_args has become xfs_attr_set_iter, which uses a state machine like switch to keep track of where it was when EAGAIN was returned.

Two new helper functions have been added: xfs_attr_rmtval_set_init and xfs_attr_rmtval_set_blk. They provide a subset of logic similar to xfs_attr_rmtval_set, but they store the current block in the delay attr context to allow the caller to roll the transaction between allocations. This helps to simplify and consolidate code used by xfs_attr_leaf_addname and xfs_attr_node_addname. xfs_attr_set_args has now become a simple loop to refresh the transaction until the operation is completed. Lastly, xfs_attr_rmtval_remove is no longer used, and is removed.

Below is a state machine diagram for attr set operations. The XFS_DAS_* states indicate places where the function would return -EAGAIN, and then immediately resume from after being recalled by the calling function. States marked as a "subroutine state" indicate that they belong to a subroutine, and so the calling function needs to pass them back to that subroutine to allow it to finish where it left off. But they otherwise do not have a role in the calling function other than just passing through.

xfs_attr_set_iter()
│
v

  ┌──────n── fork has
  │         only 1 blk?
  │              │
  │              y
  │              │
  │              v
  │     xfs_attr_leaf_try_add()
  │              │
  │              v
  │          had enough
  ├──────n──   space?
  │              │
  │              y
  │              │
  │              v
  │      XFS_DAS_FOUND_LBLK  ──┐
  │                            │
  │      XFS_DAS_FLIP_LFLAG  ──┤
  │      (subroutine state)    │
  │                            │
  │                            └─>xfs_attr_leaf_addname()
  │                                              │
  │                                              v
  │                                            was this
  │                                           a rename? ──n─┐
  │                                              │          │
  │                                              y          │
  │                                              │          │
  │                                              v          │
  │                                        flip incomplete  │
  │                                            flag         │
  │                                              │          │
  │                                              v          │
  │                                      XFS_DAS_FLIP_LFLAG │
  │                                              │          │
  │                                              v          │
  │                                            remove       │
  │                        XFS_DAS_RM_LBLK ─> old name      │
  │                                 ^            │          │
  │                                 │            v          │
  │                                 └──────y── more to      │
  │                                            remove       │
  │                                              │          │
  │                                              n          │
  │                                              │          │
  │                                              v          │
  │                                             done <──────┘
  └────> XFS_DAS_FOUND_NBLK  ──┐
         (subroutine state)    │
                               │
         XFS_DAS_ALLOC_NODE  ──┤
         (subroutine state)    │
                               │
         XFS_DAS_FLIP_NFLAG  ──┤
         (subroutine state)    │
                               │
                               └─>xfs_attr_node_addname()
                                                 │

v
find space to store
attr. Split if needed
│ v
XFS_DAS_FOUND_NBLK
│ v
┌─────n── need to
│ alloc blks?
│ │
│ y
│ │
│ v
│ ┌─>XFS_DAS_ALLOC_NODE
│ │ │
│ │ v
│ └──y── need to alloc
│ more blocks?
│ │
│ n
│ │
│ v
│ was this
└────────> a rename? ──n─┐
│ │
y │
│ │
v │
flip incomplete │
flag │
│ │
v │
XFS_DAS_FLIP_NFLAG │
│ │
v │
remove │
XFS_DAS_RM_NBLK ─> old name │
^ │ │
│ v │
└──────y── more to │
remove │
│ │
n │
│ │
v │
done <──────┘

---
 fs/xfs/libxfs/xfs_attr.c        | 371 +++++++++++++++++++++++++++-------------
 fs/xfs/libxfs/xfs_attr.h        | 127 +++++++++++++-
 fs/xfs/libxfs/xfs_attr_remote.c | 110 +++++++-----
 fs/xfs/libxfs/xfs_attr_remote.h |   4 +
 fs/xfs/xfs_trace.h              |   1 -
 5 files changed, 445 insertions(+), 168 deletions(-)
fs/xfs/libxfs/xfs_attr.c +249 -122
index 7213589..0751231 100644
@@ -44,7 +44,7 @@ STATIC int xfs_attr_shortform_addname(xfs_da_args_t *args);
  * Internal routines when attribute list is one block.
  */
 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_addname(struct xfs_delattr_context *dac);
 STATIC int xfs_attr_leaf_removename(xfs_da_args_t *args);
 STATIC int xfs_attr_leaf_hasname(struct xfs_da_args *args, struct xfs_buf **bp);
 
@@ -52,12 +52,13 @@ STATIC int xfs_attr_leaf_hasname(struct xfs_da_args *args, struct xfs_buf **bp);
  * Internal routines when attribute list is more than one block.
  */
 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_addname(struct xfs_delattr_context *dac);
 STATIC int xfs_attr_node_removename(struct xfs_delattr_context *dac);
 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);
 
 void
 xfs_delattr_context_init(
@@ -227,8 +228,11 @@ xfs_attr_is_shortform(
 
 /*
  * Attempts to set an attr in shortform, or converts short form to leaf form if
- * there is not enough room.  If the attr is set, the transaction is committed
- * and set to NULL.
+ * there is not enough room.  This function is meant to operate as a helper
+ * routine to the delayed attribute functions.  It returns -EAGAIN to indicate
+ * that the calling function should roll the transaction, and then proceed to
+ * add the attr in leaf form.  This subroutine does not expect to be recalled
+ * again like the other delayed attr routines do.
  */
 STATIC int
 xfs_attr_set_shortform(
@@ -236,16 +240,16 @@ xfs_attr_set_shortform(
 	struct xfs_buf		**leaf_bp)
 {
 	struct xfs_inode	*dp = args->dp;
-	int			error, error2 = 0;
+	int			error = 0;
 
 	/*
 	 * Try to add the attr to the attribute list in the inode.
 	 */
 	error = xfs_attr_try_sf_addname(dp, args);
+
+	/* Should only be 0, -EEXIST or ENOSPC */
 	if (error != -ENOSPC) {
-		error2 = xfs_trans_commit(args->trans);
-		args->trans = NULL;
-		return error ? error : error2;
+		return error;
 	}
 	/*
 	 * It won't fit in the shortform, transform to a leaf block.  GROT:
@@ -258,20 +262,13 @@ xfs_attr_set_shortform(
 	/*
 	 * 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. Once we're done rolling the transaction we
-	 * can release the hold and add the attr to the leaf.
+	 * with the write verifier.
 	 */
 	xfs_trans_bhold(args->trans, *leaf_bp);
-	error = xfs_defer_finish(&args->trans);
-	xfs_trans_bhold_release(args->trans, *leaf_bp);
-	if (error) {
-		xfs_trans_brelse(args->trans, *leaf_bp);
-		return error;
-	}
-
-	return 0;
+	return -EAGAIN;
 }
 
+STATIC
 int xfs_attr_defer_finish(
 	struct xfs_delattr_context      *dac)
 {
@@ -291,60 +288,128 @@ int
 xfs_attr_set_args(
 	struct xfs_da_args	*args)
 {
-	struct xfs_inode	*dp = args->dp;
-	struct xfs_buf          *leaf_bp = NULL;
-	int			error = 0;
+	struct xfs_buf			*leaf_bp = NULL;
+	int				error = 0;
+	struct xfs_delattr_context	dac;
+
+	xfs_delattr_context_init(&dac, args);
+
+	do {
+		error = xfs_attr_set_iter(&dac, &leaf_bp);
+		if (error != -EAGAIN)
+			break;
+
+		error = xfs_attr_defer_finish(&dac);
+		if (error)
+			break;
+
+		error = xfs_trans_roll_inode(&args->trans, args->dp);
+		if (error)
+			break;
+
+		if (leaf_bp) {
+			xfs_trans_bjoin(args->trans, leaf_bp);
+			xfs_trans_bhold(args->trans, leaf_bp);
+		}
+
+	} while (true);
+
+	return error;
+}
+
+/*
+ * Set the attribute specified in @args.
+ * This routine is meant to function as a delayed operation, and may return
+ * -EAGAIN 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_iter(
+	struct xfs_delattr_context	*dac,
+	struct xfs_buf			**leaf_bp)
+{
+	struct xfs_da_args		*args = dac->da_args;
+	struct xfs_inode		*dp = args->dp;
+	int				error = 0;
+
+	/* State machine switch */
+	switch (dac->dela_state) {
+	case XFS_DAS_FLIP_LFLAG:
+	case XFS_DAS_FOUND_LBLK:
+		goto das_leaf;
+	case XFS_DAS_FOUND_NBLK:
+	case XFS_DAS_FLIP_NFLAG:
+	case XFS_DAS_ALLOC_NODE:
+		goto das_node;
+	default:
+		break;
+	}
 
 	/*
 	 * If the attribute list is already in leaf format, jump straight to
 	 * leaf handling.  Otherwise, try to add the attribute to the shortform
 	 * list; if there's no room then convert the list to leaf format and try
-	 * again.
+	 * again. No need to set state as we will be in leaf form when we come
+	 * back
 	 */
 	if (xfs_attr_is_shortform(dp)) {
 
 		/*
-		 * If the attr was successfully set in shortform, the
-		 * transaction is committed and set to NULL.  Otherwise, is it
-		 * converted from shortform to leaf, and the transaction is
-		 * retained.
+		 * If the attr was successfully set in shortform, no need to
+		 * continue.  Otherwise, is it converted from shortform to leaf
+		 * and -EAGAIN is returned.
 		 */
-		error = xfs_attr_set_shortform(args, &leaf_bp);
-		if (error || !args->trans)
-			return error;
-	}
+		error = xfs_attr_set_shortform(args, leaf_bp);
+		if (error == -EAGAIN)
+			dac->flags |= XFS_DAC_DEFER_FINISH;
 
-	if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
-		error = xfs_attr_leaf_addname(args);
-		if (error != -ENOSPC)
-			return error;
+		return error;
+	}
 
-		/*
-		 * Promote the attribute list to the Btree format.
-		 */
-		error = xfs_attr3_leaf_to_node(args);
-		if (error)
-			return error;
+	/*
+	 * 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_bhold_release(args->trans, *leaf_bp);
+		*leaf_bp = NULL;
+	}
 
-		/*
-		 * Commit that transaction so that the node_addname()
-		 * call can manage its own transactions.
-		 */
-		error = xfs_defer_finish(&args->trans);
-		if (error)
-			return error;
+	if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
+		error = xfs_attr_leaf_try_add(args, *leaf_bp);
+		switch (error) {
+		case -ENOSPC:
+			/*
+			 * Promote the attribute list to the Btree format.
+			 */
+			error = xfs_attr3_leaf_to_node(args);
+			if (error)
+				return error;
 
-		/*
-		 * Commit the current trans (including the inode) and
-		 * start a new one.
-		 */
-		error = xfs_trans_roll_inode(&args->trans, dp);
-		if (error)
+			/*
+			 * Commit that transaction so that the node_addname()
+			 * call can manage its own transactions.
+			 */
+			dac->flags |= XFS_DAC_DEFER_FINISH;
+			return -EAGAIN;
+		case 0:
+			dac->dela_state = XFS_DAS_FOUND_LBLK;
+			return -EAGAIN;
+		default:
 			return error;
+		}
+das_leaf:
+		error = xfs_attr_leaf_addname(dac);
+		if (error == -ENOSPC)
+			/* We will be in node form when we return */
+			return -EAGAIN;
 
+		return error;
 	}
-
-	error = xfs_attr_node_addname(args);
+das_node:
+	error = xfs_attr_node_addname(dac);
 	return error;
 }
 
@@ -711,28 +776,30 @@ xfs_attr_leaf_try_add(
  *
  * 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
+ * -EAGAIN 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_attr_leaf_addname(
-	struct xfs_da_args	*args)
+	struct xfs_delattr_context	*dac)
 {
-	int			error, forkoff;
-	struct xfs_buf		*bp = NULL;
-	struct xfs_inode	*dp = args->dp;
-
-	trace_xfs_attr_leaf_addname(args);
-
-	error = xfs_attr_leaf_try_add(args, bp);
-	if (error)
-		return error;
+	struct xfs_da_args		*args = dac->da_args;
+	struct xfs_buf			*bp = NULL;
+	int				error, forkoff;
+	struct xfs_inode		*dp = args->dp;
 
-	/*
-	 * Commit the transaction that added the attr name so that
-	 * later routines can manage their own transactions.
-	 */
-	error = xfs_trans_roll_inode(&args->trans, dp);
-	if (error)
-		return error;
+	/* State machine switch */
+	switch (dac->dela_state) {
+	case XFS_DAS_FLIP_LFLAG:
+		goto das_flip_flag;
+	case XFS_DAS_RM_LBLK:
+		goto das_rm_lblk;
+	default:
+		break;
+	}
 
 	/*
 	 * If there was an out-of-line value, allocate the blocks we
@@ -740,12 +807,34 @@ xfs_attr_leaf_addname(
 	 * 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) {
-		error = xfs_attr_rmtval_set(args);
+
+	/* Open coded xfs_attr_rmtval_set without trans handling */
+	if ((dac->flags & XFS_DAC_LEAF_ADDNAME_INIT) == 0) {
+		dac->flags |= XFS_DAC_LEAF_ADDNAME_INIT;
+		if (args->rmtblkno > 0) {
+			error = xfs_attr_rmtval_set_init(dac);
+			if (error)
+				return error;
+		}
+	}
+
+	/*
+	 * Roll through the "value", allocating blocks on disk as
+	 * required.
+	 */
+	while (dac->blkcnt > 0) {
+		error = xfs_attr_rmtval_set_blk(dac);
 		if (error)
 			return error;
+
+		dac->flags |= XFS_DAC_DEFER_FINISH;
+		return -EAGAIN;
 	}
 
+	error = xfs_attr_rmtval_set_value(args);
+	if (error)
+		return error;
+
 	if ((args->op_flags & XFS_DA_OP_RENAME) == 0) {
 		/*
 		 * Added a "remote" value, just clear the incomplete flag.
@@ -765,29 +854,33 @@ xfs_attr_leaf_addname(
 	 * In a separate transaction, set the incomplete flag on the "old" attr
 	 * and clear the incomplete flag on the "new" attr.
 	 */
-
 	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;
-
+	dac->dela_state = XFS_DAS_FLIP_LFLAG;
+	return -EAGAIN;
+das_flip_flag:
 	/*
 	 * Dismantle the "old" attribute/value pair by removing a "remote" value
 	 * (if it exists).
 	 */
 	xfs_attr_restore_rmt_blk(args);
 
+	error = xfs_attr_rmtval_invalidate(args);
+	if (error)
+		return error;
+das_rm_lblk:
 	if (args->rmtblkno) {
-		error = xfs_attr_rmtval_invalidate(args);
-		if (error)
-			return error;
+		error = __xfs_attr_rmtval_remove(dac);
+
+		if (error == -EAGAIN) {
+			dac->dela_state = XFS_DAS_RM_LBLK;
+			return -EAGAIN;
+		}
 
-		error = xfs_attr_rmtval_remove(args);
 		if (error)
 			return error;
 	}
@@ -957,16 +1050,23 @@ xfs_attr_node_hasname(
  *
  * "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
+ * -EAGAIN 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_attr_node_addname(
-	struct xfs_da_args	*args)
+	struct xfs_delattr_context	*dac)
 {
-	struct xfs_da_state	*state;
-	struct xfs_da_state_blk	*blk;
-	struct xfs_inode	*dp;
-	struct xfs_mount	*mp;
-	int			retval, error;
+	struct xfs_da_args		*args = dac->da_args;
+	struct xfs_da_state		*state = NULL;
+	struct xfs_da_state_blk		*blk;
+	struct xfs_inode		*dp;
+	struct xfs_mount		*mp;
+	int				retval = 0;
+	int				error = 0;
 
 	trace_xfs_attr_node_addname(args);
 
@@ -975,7 +1075,21 @@ xfs_attr_node_addname(
 	 */
 	dp = args->dp;
 	mp = dp->i_mount;
-restart:
+
+	/* State machine switch */
+	switch (dac->dela_state) {
+	case XFS_DAS_FLIP_NFLAG:
+		goto das_flip_flag;
+	case XFS_DAS_FOUND_NBLK:
+		goto das_found_nblk;
+	case XFS_DAS_ALLOC_NODE:
+		goto das_alloc_node;
+	case XFS_DAS_RM_NBLK:
+		goto das_rm_nblk;
+	default:
+		break;
+	}
+
 	/*
 	 * Search to see if name already exists, and get back a pointer
 	 * to where it should go.
@@ -1021,19 +1135,13 @@ xfs_attr_node_addname(
 			error = xfs_attr3_leaf_to_node(args);
 			if (error)
 				goto out;
-			error = xfs_defer_finish(&args->trans);
-			if (error)
-				goto out;
 
 			/*
-			 * Commit the node conversion and start the next
-			 * trans in the chain.
+			 * Restart routine from the top.  No need to set  the
+			 * state
 			 */
-			error = xfs_trans_roll_inode(&args->trans, dp);
-			if (error)
-				goto out;
-
-			goto restart;
+			dac->flags |= XFS_DAC_DEFER_FINISH;
+			return -EAGAIN;
 		}
 
 		/*
@@ -1045,9 +1153,7 @@ xfs_attr_node_addname(
 		error = xfs_da3_split(state);
 		if (error)
 			goto out;
-		error = xfs_defer_finish(&args->trans);
-		if (error)
-			goto out;
+		dac->flags |= XFS_DAC_DEFER_FINISH;
 	} else {
 		/*
 		 * Addition succeeded, update Btree hashvals.
@@ -1062,13 +1168,9 @@ xfs_attr_node_addname(
 	xfs_da_state_free(state);
 	state = NULL;
 
-	/*
-	 * Commit the leaf addition or btree split and start the next
-	 * trans in the chain.
-	 */
-	error = xfs_trans_roll_inode(&args->trans, dp);
-	if (error)
-		goto out;
+	dac->dela_state = XFS_DAS_FOUND_NBLK;
+	return -EAGAIN;
+das_found_nblk:
 
 	/*
 	 * If there was an out-of-line value, allocate the blocks we
@@ -1077,7 +1179,27 @@ xfs_attr_node_addname(
 	 * maximum size of a transaction and/or hit a deadlock.
 	 */
 	if (args->rmtblkno > 0) {
-		error = xfs_attr_rmtval_set(args);
+		/* Open coded xfs_attr_rmtval_set without trans handling */
+		error = xfs_attr_rmtval_set_init(dac);
+		if (error)
+			return error;
+
+		/*
+		 * Roll through the "value", allocating blocks on disk as
+		 * required.
+		 */
+das_alloc_node:
+		while (dac->blkcnt > 0) {
+			error = xfs_attr_rmtval_set_blk(dac);
+			if (error)
+				return error;
+
+			dac->flags |= XFS_DAC_DEFER_FINISH;
+			dac->dela_state = XFS_DAS_ALLOC_NODE;
+			return -EAGAIN;
+		}
+
+		error = xfs_attr_rmtval_set_value(args);
 		if (error)
 			return error;
 	}
@@ -1107,22 +1229,28 @@ xfs_attr_node_addname(
 	/*
 	 * 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;
-
+	dac->dela_state = XFS_DAS_FLIP_NFLAG;
+	return -EAGAIN;
+das_flip_flag:
 	/*
 	 * Dismantle the "old" attribute/value pair by removing a "remote" value
 	 * (if it exists).
 	 */
 	xfs_attr_restore_rmt_blk(args);
 
+	error = xfs_attr_rmtval_invalidate(args);
+	if (error)
+		return error;
+
+das_rm_nblk:
 	if (args->rmtblkno) {
-		error = xfs_attr_rmtval_invalidate(args);
-		if (error)
-			return error;
+		error = __xfs_attr_rmtval_remove(dac);
+
+		if (error == -EAGAIN) {
+			dac->dela_state = XFS_DAS_RM_NBLK;
+			return -EAGAIN;
+		}
 
-		error = xfs_attr_rmtval_remove(args);
 		if (error)
 			return error;
 	}
@@ -1155,9 +1283,8 @@ xfs_attr_node_addname(
 		error = xfs_da3_join(state);
 		if (error)
 			goto out;
-		error = xfs_defer_finish(&args->trans);
-		if (error)
-			goto out;
+
+		dac->flags |= XFS_DAC_DEFER_FINISH;
 	}
 	retval = error = 0;
 
fs/xfs/libxfs/xfs_attr.h +126 -1

160 lines not on this page · raw message

fs/xfs/libxfs/xfs_attr_remote.c +66 -44

134 lines not on this page · raw message

fs/xfs/libxfs/xfs_attr_remote.h +4 -0
index 351da00..51a1c91 100644
@@ -15,4 +15,8 @@ int xfs_attr_rmtval_stale(struct xfs_inode *ip, struct xfs_bmbt_irec *map,
 		xfs_buf_flags_t incore_flags);
 int xfs_attr_rmtval_invalidate(struct xfs_da_args *args);
 int __xfs_attr_rmtval_remove(struct xfs_delattr_context *dac);
+int xfs_attr_rmt_find_hole(struct xfs_da_args *args);
+int xfs_attr_rmtval_set_value(struct xfs_da_args *args);
+int xfs_attr_rmtval_set_blk(struct xfs_delattr_context *dac);
+int xfs_attr_rmtval_set_init(struct xfs_delattr_context *dac);
 #endif /* __XFS_ATTR_REMOTE_H__ */
fs/xfs/xfs_trace.h +0 -1
index a4323a6..26dc8bf 100644
@@ -1784,7 +1784,6 @@ DEFINE_ATTR_EVENT(xfs_attr_refillstate);
 
 DEFINE_ATTR_EVENT(xfs_attr_rmtval_get);
 DEFINE_ATTR_EVENT(xfs_attr_rmtval_set);
-DEFINE_ATTR_EVENT(xfs_attr_rmtval_remove);
 
 #define DEFINE_DA_EVENT(name) \
 DEFINE_EVENT(xfs_da_class, name, \
Signature · 1 line
2.7.4
#69 lore raw

Re: [PATCH v9 23/24] xfs: Add delay ready attr set routines

Quoted 26 lines · Allison Collins

This patch modifies the attr set routines to be delay ready. This means they no longer roll or commit transactions, but instead return -EAGAIN to have the calling routine roll and refresh the transaction. In this series, xfs_attr_set_args has become xfs_attr_set_iter, which uses a state machine like switch to keep track of where it was when EAGAIN was returned.

Two new helper functions have been added: xfs_attr_rmtval_set_init and xfs_attr_rmtval_set_blk. They provide a subset of logic similar to xfs_attr_rmtval_set, but they store the current block in the delay attr context to allow the caller to roll the transaction between allocations. This helps to simplify and consolidate code used by xfs_attr_leaf_addname and xfs_attr_node_addname. xfs_attr_set_args has now become a simple loop to refresh the transaction until the operation is completed. Lastly, xfs_attr_rmtval_remove is no longer used, and is removed.

Below is a state machine diagram for attr set operations. The XFS_DAS_* states indicate places where the function would return -EAGAIN, and then immediately resume from after being recalled by the calling function. States marked as a "subroutine state" indicate that they belong to a subroutine, and so the calling function needs to pass them back to that subroutine to allow it to finish where it left off. But they otherwise do not have a role in the calling function other than just passing through.

Quoted 5 lines

xfs_attr_set_iter()
│
v

  ┌──────n── fork has
  │         only 1 blk?

"Refer to the state machine diagram in xfs_attr.h for exact details of how this works."

Quoted 215 lines
  │              │
  │              y
  │              │
  │              v
  │     xfs_attr_leaf_try_add()
  │              │
  │              v
  │          had enough
  ├──────n──   space?
  │              │
  │              y
  │              │
  │              v
  │      XFS_DAS_FOUND_LBLK  ──┐
  │                            │
  │      XFS_DAS_FLIP_LFLAG  ──┤
  │      (subroutine state)    │
  │                            │
  │                            └─>xfs_attr_leaf_addname()
  │                                              │
  │                                              v
  │                                            was this
  │                                           a rename? ──n─┐
  │                                              │          │
  │                                              y          │
  │                                              │          │
  │                                              v          │
  │                                        flip incomplete  │
  │                                            flag         │
  │                                              │          │
  │                                              v          │
  │                                      XFS_DAS_FLIP_LFLAG │
  │                                              │          │
  │                                              v          │
  │                                            remove       │
  │                        XFS_DAS_RM_LBLK ─> old name      │
  │                                 ^            │          │
  │                                 │            v          │
  │                                 └──────y── more to      │
  │                                            remove       │
  │                                              │          │
  │                                              n          │
  │                                              │          │
  │                                              v          │
  │                                             done <──────┘
  └────> XFS_DAS_FOUND_NBLK  ──┐
         (subroutine state)    │
                               │
         XFS_DAS_ALLOC_NODE  ──┤
         (subroutine state)    │
                               │
         XFS_DAS_FLIP_NFLAG  ──┤
         (subroutine state)    │
                               │
                               └─>xfs_attr_node_addname()
                                                 │

v
find space to store
attr. Split if needed
│ v
XFS_DAS_FOUND_NBLK
│ v
┌─────n── need to
│ alloc blks?
│ │
│ y
│ │
│ v
│ ┌─>XFS_DAS_ALLOC_NODE
│ │ │
│ │ v
│ └──y── need to alloc
│ more blocks?
│ │
│ n
│ │
│ v
│ was this
└────────> a rename? ──n─┐
│ │
y │
│ │
v │
flip incomplete │
flag │
│ │
v │
XFS_DAS_FLIP_NFLAG │
│ │
v │
remove │
XFS_DAS_RM_NBLK ─> old name │
^ │ │
│ v │
└──────y── more to │
remove │
│ │
n │
│ │
v │
done <──────┘

---
 fs/xfs/libxfs/xfs_attr.c        | 371 +++++++++++++++++++++++++++-------------
 fs/xfs/libxfs/xfs_attr.h        | 127 +++++++++++++-
 fs/xfs/libxfs/xfs_attr_remote.c | 110 +++++++-----
 fs/xfs/libxfs/xfs_attr_remote.h |   4 +
 fs/xfs/xfs_trace.h              |   1 -
 5 files changed, 445 insertions(+), 168 deletions(-)
fs/xfs/libxfs/xfs_attr.c +23 -21
index 7213589..0751231 100644
@@ -44,7 +44,7 @@ STATIC int xfs_attr_shortform_addname(xfs_da_args_t *args);
  * Internal routines when attribute list is one block.
  */
 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_addname(struct xfs_delattr_context *dac);
 STATIC int xfs_attr_leaf_removename(xfs_da_args_t *args);
 STATIC int xfs_attr_leaf_hasname(struct xfs_da_args *args, struct xfs_buf **bp);
 
@@ -52,12 +52,13 @@ STATIC int xfs_attr_leaf_hasname(struct xfs_da_args *args, struct xfs_buf **bp);
  * Internal routines when attribute list is more than one block.
  */
 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_addname(struct xfs_delattr_context *dac);
 STATIC int xfs_attr_node_removename(struct xfs_delattr_context *dac);
 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);
 
 void
 xfs_delattr_context_init(
@@ -227,8 +228,11 @@ xfs_attr_is_shortform(
 
 /*
  * Attempts to set an attr in shortform, or converts short form to leaf form if
- * there is not enough room.  If the attr is set, the transaction is committed
- * and set to NULL.
+ * there is not enough room.  This function is meant to operate as a helper
+ * routine to the delayed attribute functions.  It returns -EAGAIN to indicate
+ * that the calling function should roll the transaction, and then proceed to
+ * add the attr in leaf form.  This subroutine does not expect to be recalled
+ * again like the other delayed attr routines do.
  */
 STATIC int
 xfs_attr_set_shortform(
@@ -236,16 +240,16 @@ xfs_attr_set_shortform(
 	struct xfs_buf		**leaf_bp)
 {
 	struct xfs_inode	*dp = args->dp;
-	int			error, error2 = 0;
+	int			error = 0;
 
 	/*
 	 * Try to add the attr to the attribute list in the inode.
 	 */
 	error = xfs_attr_try_sf_addname(dp, args);
+
+	/* Should only be 0, -EEXIST or ENOSPC */
 	if (error != -ENOSPC) {
-		error2 = xfs_trans_commit(args->trans);
-		args->trans = NULL;
-		return error ? error : error2;
+		return error;
 	}
 	/*
 	 * It won't fit in the shortform, transform to a leaf block.  GROT:
@@ -258,20 +262,13 @@ xfs_attr_set_shortform(
 	/*
 	 * 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. Once we're done rolling the transaction we
-	 * can release the hold and add the attr to the leaf.
+	 * with the write verifier.
 	 */
 	xfs_trans_bhold(args->trans, *leaf_bp);
-	error = xfs_defer_finish(&args->trans);
-	xfs_trans_bhold_release(args->trans, *leaf_bp);
-	if (error) {
-		xfs_trans_brelse(args->trans, *leaf_bp);
-		return error;
-	}
-
-	return 0;
+	return -EAGAIN;
 }
 
+STATIC
 int xfs_attr_defer_finish(
 	struct xfs_delattr_context      *dac)
 {
@@ -291,60 +288,128 @@ int
 xfs_attr_set_args(
 	struct xfs_da_args	*args)
 {
-	struct xfs_inode	*dp = args->dp;
-	struct xfs_buf          *leaf_bp = NULL;
-	int			error = 0;
+	struct xfs_buf			*leaf_bp = NULL;
+	int				error = 0;
+	struct xfs_delattr_context	dac;
+
+	xfs_delattr_context_init(&dac, args);
+
+	do {
+		error = xfs_attr_set_iter(&dac, &leaf_bp);

fs/xfs/libxfs/xfs_attr.c int · line 308

Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10 -0
+		if (error != -EAGAIN)
+			break;
+
+		error = xfs_attr_defer_finish(&dac);
+		if (error)
+			break;
+
+		error = xfs_trans_roll_inode(&args->trans, args->dp);
+		if (error)
+			break;
	if (!xfs_attr_roll_again(&dac, &error))
		break;
Quoted 201 lines
fs/xfs/libxfs/xfs_attr.c +112 -53
+
+		if (leaf_bp) {
+			xfs_trans_bjoin(args->trans, leaf_bp);
+			xfs_trans_bhold(args->trans, leaf_bp);
+		}
+
+	} while (true);
+
+	return error;
+}
+
+/*
+ * Set the attribute specified in @args.
+ * This routine is meant to function as a delayed operation, and may return
+ * -EAGAIN 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_iter(
+	struct xfs_delattr_context	*dac,
+	struct xfs_buf			**leaf_bp)
+{
+	struct xfs_da_args		*args = dac->da_args;
+	struct xfs_inode		*dp = args->dp;
+	int				error = 0;
+
+	/* State machine switch */
+	switch (dac->dela_state) {
+	case XFS_DAS_FLIP_LFLAG:
+	case XFS_DAS_FOUND_LBLK:
+		goto das_leaf;
+	case XFS_DAS_FOUND_NBLK:
+	case XFS_DAS_FLIP_NFLAG:
+	case XFS_DAS_ALLOC_NODE:
+		goto das_node;
+	default:
+		break;
+	}
 
 	/*
 	 * If the attribute list is already in leaf format, jump straight to
 	 * leaf handling.  Otherwise, try to add the attribute to the shortform
 	 * list; if there's no room then convert the list to leaf format and try
-	 * again.
+	 * again. No need to set state as we will be in leaf form when we come
+	 * back
 	 */
 	if (xfs_attr_is_shortform(dp)) {
 
 		/*
-		 * If the attr was successfully set in shortform, the
-		 * transaction is committed and set to NULL.  Otherwise, is it
-		 * converted from shortform to leaf, and the transaction is
-		 * retained.
+		 * If the attr was successfully set in shortform, no need to
+		 * continue.  Otherwise, is it converted from shortform to leaf
+		 * and -EAGAIN is returned.
 		 */
-		error = xfs_attr_set_shortform(args, &leaf_bp);
-		if (error || !args->trans)
-			return error;
-	}
+		error = xfs_attr_set_shortform(args, leaf_bp);
+		if (error == -EAGAIN)
+			dac->flags |= XFS_DAC_DEFER_FINISH;
 
-	if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
-		error = xfs_attr_leaf_addname(args);
-		if (error != -ENOSPC)
-			return error;
+		return error;
+	}
 
-		/*
-		 * Promote the attribute list to the Btree format.
-		 */
-		error = xfs_attr3_leaf_to_node(args);
-		if (error)
-			return error;
+	/*
+	 * 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_bhold_release(args->trans, *leaf_bp);
+		*leaf_bp = NULL;
+	}
 
-		/*
-		 * Commit that transaction so that the node_addname()
-		 * call can manage its own transactions.
-		 */
-		error = xfs_defer_finish(&args->trans);
-		if (error)
-			return error;
+	if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
+		error = xfs_attr_leaf_try_add(args, *leaf_bp);
+		switch (error) {
+		case -ENOSPC:
+			/*
+			 * Promote the attribute list to the Btree format.
+			 */
+			error = xfs_attr3_leaf_to_node(args);
+			if (error)
+				return error;
 
-		/*
-		 * Commit the current trans (including the inode) and
-		 * start a new one.
-		 */
-		error = xfs_trans_roll_inode(&args->trans, dp);
-		if (error)
+			/*
+			 * Commit that transaction so that the node_addname()
+			 * call can manage its own transactions.
+			 */
+			dac->flags |= XFS_DAC_DEFER_FINISH;
+			return -EAGAIN;
+		case 0:
+			dac->dela_state = XFS_DAS_FOUND_LBLK;
+			return -EAGAIN;
+		default:
 			return error;
+		}
+das_leaf:
+		error = xfs_attr_leaf_addname(dac);
+		if (error == -ENOSPC)
+			/* We will be in node form when we return */
+			return -EAGAIN;
 
+		return error;
 	}
-
-	error = xfs_attr_node_addname(args);
+das_node:
+	error = xfs_attr_node_addname(dac);
 	return error;
 }
 
@@ -711,28 +776,30 @@ xfs_attr_leaf_try_add(
  *
  * 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
+ * -EAGAIN 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_attr_leaf_addname(
-	struct xfs_da_args	*args)
+	struct xfs_delattr_context	*dac)
 {
-	int			error, forkoff;
-	struct xfs_buf		*bp = NULL;
-	struct xfs_inode	*dp = args->dp;
-
-	trace_xfs_attr_leaf_addname(args);
-
-	error = xfs_attr_leaf_try_add(args, bp);
-	if (error)
-		return error;
+	struct xfs_da_args		*args = dac->da_args;
+	struct xfs_buf			*bp = NULL;
+	int				error, forkoff;
+	struct xfs_inode		*dp = args->dp;
 
-	/*
-	 * Commit the transaction that added the attr name so that
-	 * later routines can manage their own transactions.
-	 */
-	error = xfs_trans_roll_inode(&args->trans, dp);
-	if (error)
-		return error;
+	/* State machine switch */
+	switch (dac->dela_state) {
+	case XFS_DAS_FLIP_LFLAG:
+		goto das_flip_flag;
+	case XFS_DAS_RM_LBLK:
+		goto das_rm_lblk;
+	default:
+		break;
+	}
 
 	/*
 	 * If there was an out-of-line value, allocate the blocks we
@@ -740,12 +807,34 @@ xfs_attr_leaf_addname(
 	 * 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) {
-		error = xfs_attr_rmtval_set(args);
+
+	/* Open coded xfs_attr_rmtval_set without trans handling */
+	if ((dac->flags & XFS_DAC_LEAF_ADDNAME_INIT) == 0) {
+		dac->flags |= XFS_DAC_LEAF_ADDNAME_INIT;
+		if (args->rmtblkno > 0) {
+			error = xfs_attr_rmtval_set_init(dac);

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

Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10 -0
+			if (error)
+				return error;
+		}
+	}
+
+	/*
+	 * Roll through the "value", allocating blocks on disk as
+	 * required.
+	 */
+	while (dac->blkcnt > 0) {

if() ?

Quoted 164 lines
fs/xfs/libxfs/xfs_attr.c +57 -36
+		error = xfs_attr_rmtval_set_blk(dac);
 		if (error)
 			return error;
+
+		dac->flags |= XFS_DAC_DEFER_FINISH;
+		return -EAGAIN;
 	}
 
+	error = xfs_attr_rmtval_set_value(args);
+	if (error)
+		return error;
+
 	if ((args->op_flags & XFS_DA_OP_RENAME) == 0) {
 		/*
 		 * Added a "remote" value, just clear the incomplete flag.
@@ -765,29 +854,33 @@ xfs_attr_leaf_addname(
 	 * In a separate transaction, set the incomplete flag on the "old" attr
 	 * and clear the incomplete flag on the "new" attr.
 	 */
-
 	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;
-
+	dac->dela_state = XFS_DAS_FLIP_LFLAG;
+	return -EAGAIN;
+das_flip_flag:
 	/*
 	 * Dismantle the "old" attribute/value pair by removing a "remote" value
 	 * (if it exists).
 	 */
 	xfs_attr_restore_rmt_blk(args);
 
+	error = xfs_attr_rmtval_invalidate(args);
+	if (error)
+		return error;
+das_rm_lblk:
 	if (args->rmtblkno) {
-		error = xfs_attr_rmtval_invalidate(args);
-		if (error)
-			return error;
+		error = __xfs_attr_rmtval_remove(dac);
+
+		if (error == -EAGAIN) {
+			dac->dela_state = XFS_DAS_RM_LBLK;
+			return -EAGAIN;
+		}
 
-		error = xfs_attr_rmtval_remove(args);
 		if (error)
 			return error;
 	}
@@ -957,16 +1050,23 @@ xfs_attr_node_hasname(
  *
  * "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
+ * -EAGAIN 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_attr_node_addname(
-	struct xfs_da_args	*args)
+	struct xfs_delattr_context	*dac)
 {
-	struct xfs_da_state	*state;
-	struct xfs_da_state_blk	*blk;
-	struct xfs_inode	*dp;
-	struct xfs_mount	*mp;
-	int			retval, error;
+	struct xfs_da_args		*args = dac->da_args;
+	struct xfs_da_state		*state = NULL;
+	struct xfs_da_state_blk		*blk;
+	struct xfs_inode		*dp;
+	struct xfs_mount		*mp;
+	int				retval = 0;
+	int				error = 0;
 
 	trace_xfs_attr_node_addname(args);
 
@@ -975,7 +1075,21 @@ xfs_attr_node_addname(
 	 */
 	dp = args->dp;
 	mp = dp->i_mount;
-restart:
+
+	/* State machine switch */
+	switch (dac->dela_state) {
+	case XFS_DAS_FLIP_NFLAG:
+		goto das_flip_flag;
+	case XFS_DAS_FOUND_NBLK:
+		goto das_found_nblk;
+	case XFS_DAS_ALLOC_NODE:
+		goto das_alloc_node;
+	case XFS_DAS_RM_NBLK:
+		goto das_rm_nblk;
+	default:
+		break;
+	}
+
 	/*
 	 * Search to see if name already exists, and get back a pointer
 	 * to where it should go.
@@ -1021,19 +1135,13 @@ xfs_attr_node_addname(
 			error = xfs_attr3_leaf_to_node(args);
 			if (error)
 				goto out;
-			error = xfs_defer_finish(&args->trans);
-			if (error)
-				goto out;
 
 			/*
-			 * Commit the node conversion and start the next
-			 * trans in the chain.
+			 * Restart routine from the top.  No need to set  the
+			 * state
 			 */
-			error = xfs_trans_roll_inode(&args->trans, dp);
-			if (error)
-				goto out;
-
-			goto restart;
+			dac->flags |= XFS_DAC_DEFER_FINISH;
+			return -EAGAIN;
 		}
 
 		/*
@@ -1045,9 +1153,7 @@ xfs_attr_node_addname(
 		error = xfs_da3_split(state);
 		if (error)
 			goto out;
-		error = xfs_defer_finish(&args->trans);
-		if (error)
-			goto out;
+		dac->flags |= XFS_DAC_DEFER_FINISH;
 	} else {
 		/*
 		 * Addition succeeded, update Btree hashvals.
@@ -1062,13 +1168,9 @@ xfs_attr_node_addname(
 	xfs_da_state_free(state);
 	state = NULL;
 
-	/*
-	 * Commit the leaf addition or btree split and start the next
-	 * trans in the chain.
-	 */
-	error = xfs_trans_roll_inode(&args->trans, dp);
-	if (error)
-		goto out;
+	dac->dela_state = XFS_DAS_FOUND_NBLK;
+	return -EAGAIN;
+das_found_nblk:
 
 	/*
 	 * If there was an out-of-line value, allocate the blocks we

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

Quoted 6 lines
fs/xfs/libxfs/xfs_attr.c +2 -1
@@ -1077,7 +1179,27 @@ xfs_attr_node_addname(
 	 * maximum size of a transaction and/or hit a deadlock.
 	 */
 	if (args->rmtblkno > 0) {
-		error = xfs_attr_rmtval_set(args);
+		/* Open coded xfs_attr_rmtval_set without trans handling */
+		error = xfs_attr_rmtval_set_init(dac);

Do we need to test/set LEAF_ADDNAME_INIT here too?

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

Quoted 9 lines
fs/xfs/libxfs/xfs_attr.c +9 -0
+		if (error)
+			return error;
+
+		/*
+		 * Roll through the "value", allocating blocks on disk as
+		 * required.
+		 */
+das_alloc_node:
+		while (dac->blkcnt > 0) {

if() ?

Quoted 254 lines
fs/xfs/libxfs/xfs_attr.c +26 -11
+			error = xfs_attr_rmtval_set_blk(dac);
+			if (error)
+				return error;
+
+			dac->flags |= XFS_DAC_DEFER_FINISH;
+			dac->dela_state = XFS_DAS_ALLOC_NODE;
+			return -EAGAIN;
+		}
+
+		error = xfs_attr_rmtval_set_value(args);
 		if (error)
 			return error;
 	}
@@ -1107,22 +1229,28 @@ xfs_attr_node_addname(
 	/*
 	 * 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;
-
+	dac->dela_state = XFS_DAS_FLIP_NFLAG;
+	return -EAGAIN;
+das_flip_flag:
 	/*
 	 * Dismantle the "old" attribute/value pair by removing a "remote" value
 	 * (if it exists).
 	 */
 	xfs_attr_restore_rmt_blk(args);
 
+	error = xfs_attr_rmtval_invalidate(args);
+	if (error)
+		return error;
+
+das_rm_nblk:
 	if (args->rmtblkno) {
-		error = xfs_attr_rmtval_invalidate(args);
-		if (error)
-			return error;
+		error = __xfs_attr_rmtval_remove(dac);
+
+		if (error == -EAGAIN) {
+			dac->dela_state = XFS_DAS_RM_NBLK;
+			return -EAGAIN;
+		}
 
-		error = xfs_attr_rmtval_remove(args);
 		if (error)
 			return error;
 	}
@@ -1155,9 +1283,8 @@ xfs_attr_node_addname(
 		error = xfs_da3_join(state);
 		if (error)
 			goto out;
-		error = xfs_defer_finish(&args->trans);
-		if (error)
-			goto out;
+
+		dac->flags |= XFS_DAC_DEFER_FINISH;
 	}
 	retval = error = 0;
 
fs/xfs/libxfs/xfs_attr.h +126 -1
index 0430c79..5cbefa90 100644
@@ -106,6 +106,118 @@ struct xfs_attr_list_context {
  *	                                      v         │
  *	                                     done <─────┘
  *
+ *
+ * Below is a state machine diagram for attr set operations.
+ *
+ *  xfs_attr_set_iter()
+ *             │
+ *             v
+ *   ┌───n── fork has
+ *   │	    only 1 blk?
+ *   │		│
+ *   │		y
+ *   │		│
+ *   │		v
+ *   │	xfs_attr_leaf_try_add()
+ *   │		│
+ *   │		v
+ *   │	     had enough
+ *   ├───n────space?
+ *   │		│
+ *   │		y
+ *   │		│
+ *   │		v
+ *   │	XFS_DAS_FOUND_LBLK ──┐
+ *   │	                     │
+ *   │	XFS_DAS_FLIP_LFLAG ──┤
+ *   │	(subroutine state)   │
+ *   │		             │
+ *   │		             └─>xfs_attr_leaf_addname()
+ *   │		                      │
+ *   │		                      v
+ *   │		                   was this
+ *   │		                   a rename? ──n─┐
+ *   │		                      │          │
+ *   │		                      y          │
+ *   │		                      │          │
+ *   │		                      v          │
+ *   │		                flip incomplete  │
+ *   │		                    flag         │
+ *   │		                      │          │
+ *   │		                      v          │
+ *   │		              XFS_DAS_FLIP_LFLAG │
+ *   │		                      │          │
+ *   │		                      v          │
+ *   │		                    remove       │
+ *   │		XFS_DAS_RM_LBLK ─> old name      │
+ *   │		         ^            │          │
+ *   │		         │            v          │
+ *   │		         └──────y── more to      │
+ *   │		                    remove       │
+ *   │		                      │          │
+ *   │		                      n          │
+ *   │		                      │          │
+ *   │		                      v          │
+ *   │		                     done <──────┘
+ *   └──> XFS_DAS_FOUND_NBLK ──┐
+ *	  (subroutine state)   │
+ *	                       │
+ *	  XFS_DAS_ALLOC_NODE ──┤
+ *	  (subroutine state)   │
+ *	                       │
+ *	  XFS_DAS_FLIP_NFLAG ──┤
+ *	  (subroutine state)   │
+ *	                       │
+ *	                       └─>xfs_attr_node_addname()
+ *	                               │
+ *	                               v
+ *	                       find space to store
+ *	                      attr. Split if needed
+ *	                               │
+ *	                               v
+ *	                       XFS_DAS_FOUND_NBLK
+ *	                               │
+ *	                               v
+ *	                 ┌─────n──  need to
+ *	                 │        alloc blks?
+ *	                 │             │
+ *	                 │             y
+ *	                 │             │
+ *	                 │             v
+ *	                 │  ┌─>XFS_DAS_ALLOC_NODE
+ *	                 │  │          │
+ *	                 │  │          v
+ *	                 │  └──y── need to alloc
+ *	                 │         more blocks?
+ *	                 │             │
+ *	                 │             n
+ *	                 │             │
+ *	                 │             v
+ *	                 │          was this
+ *	                 └────────> a rename? ──n─┐
+ *	                               │          │
+ *	                               y          │
+ *	                               │          │
+ *	                               v          │
+ *	                         flip incomplete  │
+ *	                             flag         │
+ *	                               │          │
+ *	                               v          │
+ *	                       XFS_DAS_FLIP_NFLAG │
+ *	                               │          │
+ *	                               v          │
+ *	                             remove       │
+ *	         XFS_DAS_RM_NBLK ─> old name      │
+ *	                  ^            │          │
+ *	                  │            v          │
+ *	                  └──────y── more to      │
+ *	                             remove       │
+ *	                               │          │
+ *	                               n          │
+ *	                               │          │
+ *	                               v          │
+ *	                              done <──────┘
+ *
  */
 
 /*
@@ -120,6 +232,13 @@ struct xfs_attr_list_context {
 enum xfs_delattr_state {
 				      /* Zero is uninitalized */
 	XFS_DAS_RM_SHRINK	= 1,  /* We are shrinking the tree */
+	XFS_DAS_FOUND_LBLK,	      /* We found leaf blk for attr */
+	XFS_DAS_FOUND_NBLK,	      /* We found node blk for attr */
+	XFS_DAS_FLIP_LFLAG,	      /* Flipped leaf INCOMPLETE attr flag */
+	XFS_DAS_RM_LBLK,	      /* A rename is removing leaf blocks */
+	XFS_DAS_ALLOC_NODE,	      /* We are allocating node blocks */
+	XFS_DAS_FLIP_NFLAG,	      /* Flipped node INCOMPLETE attr flag */
+	XFS_DAS_RM_NBLK,	      /* A rename is removing node blocks */
 };
 
 /*
@@ -127,6 +246,7 @@ enum xfs_delattr_state {
  */
 #define XFS_DAC_DEFER_FINISH		0x01 /* finish the transaction */
 #define XFS_DAC_NODE_RMVNAME_INIT	0x02 /* xfs_attr_node_removename init */
+#define XFS_DAC_LEAF_ADDNAME_INIT	0x04 /* xfs_attr_leaf_addname init*/
 
 /*
  * Context used for keeping track of delayed attribute operations
@@ -134,6 +254,11 @@ enum xfs_delattr_state {
 struct xfs_delattr_context {
 	struct xfs_da_args      *da_args;
 
+	/* Used in xfs_attr_rmtval_set_blk to roll through allocating blocks */
+	struct xfs_bmbt_irec	map;
+	xfs_dablk_t		lblkno;
+	int			blkcnt;
+
 	/* Used in xfs_attr_node_removename to roll through removing blocks */
 	struct xfs_da_state     *da_state;
 	struct xfs_da_state_blk *blk;
@@ -158,10 +283,10 @@ int xfs_attr_get_ilocked(struct xfs_da_args *args);
 int xfs_attr_get(struct xfs_da_args *args);
 int xfs_attr_set(struct xfs_da_args *args);
 int xfs_attr_set_args(struct xfs_da_args *args);
+int xfs_attr_set_iter(struct xfs_delattr_context *dac, struct xfs_buf **leaf_bp);
 int xfs_has_attr(struct xfs_da_args *args);
 int xfs_attr_remove_args(struct xfs_da_args *args);
 int xfs_attr_remove_iter(struct xfs_delattr_context *dac);
-int xfs_attr_defer_finish(struct xfs_delattr_context *dac);
 bool xfs_attr_namecheck(const void *name, size_t length);
 void xfs_delattr_context_init(struct xfs_delattr_context *dac,
 			      struct xfs_da_args *args);
fs/xfs/libxfs/xfs_attr_remote.c +2 -2
index f2d46c7..7a342f1 100644
@@ -443,7 +443,7 @@ xfs_attr_rmtval_get(
  * Find a "hole" in the attribute address space large enough for us to drop the
  * new attribute's value into
  */
-STATIC int
+int
 xfs_attr_rmt_find_hole(
 	struct xfs_da_args	*args)
 {
@@ -470,7 +470,7 @@ xfs_attr_rmt_find_hole(
 	return 0;
 }
 
-STATIC int
+int
 xfs_attr_rmtval_set_value(
 	struct xfs_da_args	*args)
 {

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

Quoted 9 lines
fs/xfs/libxfs/xfs_attr_remote.c +6 -0
@@ -630,6 +630,70 @@ xfs_attr_rmtval_set(
 }
 
 /*
+ * Find a hole for the attr and store it in the delayed attr context.  This
+ * initializes the context to roll through allocating an attr extent for a
+ * delayed attr operation
+ */
+int
+xfs_attr_rmtval_set_init(

/me wonders if this ought to be named xfs_attr_rmtval_find_space() ?

That's more or less what it's getting ready to do, right?

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

Quoted 5 lines
fs/xfs/libxfs/xfs_attr_remote.c +5 -0
+	struct xfs_delattr_context	*dac)
+{
+	struct xfs_da_args		*args = dac->da_args;
+	struct xfs_bmbt_irec		*map = &dac->map;
+	int error;
	int				error;
Quoted 5 lines
fs/xfs/libxfs/xfs_attr_remote.c +5 -0
+
+	dac->lblkno = 0;
+	dac->blkcnt = 0;
+	args->rmtblkcnt = 0;
+	args->rmtblkno = 0;

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

Quoted 10 lines
fs/xfs/libxfs/xfs_attr_remote.c +10 -0
+	memset(map, 0, sizeof(struct xfs_bmbt_irec));
+
+	error = xfs_attr_rmt_find_hole(args);
+	if (error)
+		return error;
+
+	dac->blkcnt = args->rmtblkcnt;
+	dac->lblkno = args->rmtblkno;
+
+	return error;

This could be return 0;.

Quoted 13 lines
fs/xfs/libxfs/xfs_attr_remote.c +13 -0
+}
+
+/*
+ * Write one block of the value associated with an attribute into the
+ * out-of-line buffer that we have defined for it. This is similar to a subset
+ * of xfs_attr_rmtval_set, but records the current block to the delayed attr
+ * context, and leaves transaction handling to the caller.
+ */
+int
+xfs_attr_rmtval_set_blk(
+	struct xfs_delattr_context	*dac)
+{
+	struct xfs_da_args		*args = dac->da_args;

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

Quoted 10 lines
fs/xfs/libxfs/xfs_attr_remote.c +10 -0
+	struct xfs_inode		*dp = args->dp;
+	struct xfs_bmbt_irec		*map = &dac->map;
+	int nmap;
+	int error;
+
+	nmap = 1;
+	error = xfs_bmapi_write(args->trans, dp,
+		  (xfs_fileoff_t)dac->lblkno,
+		  dac->blkcnt, XFS_BMAPI_ATTRFORK,
+		  args->total, map, &nmap);

The indenting here could be improved.

Whee, ok, it's lunchtime. I'll look at the state machine after eating.

--D

Quoted 95 lines
fs/xfs/libxfs/xfs_attr_remote.c +15 -42
+	if (error)
+		return error;
+
+	ASSERT(nmap == 1);
+	ASSERT((map->br_startblock != DELAYSTARTBLOCK) &&
+	       (map->br_startblock != HOLESTARTBLOCK));
+
+	/* roll attribute extent map forwards */
+	dac->lblkno += map->br_blockcount;
+	dac->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.
  */
@@ -671,48 +735,6 @@ xfs_attr_rmtval_invalidate(
 }
 
 /*
- * 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)
-{
-	struct xfs_delattr_context	dac;
-	xfs_dablk_t			lblkno;
-	int				blkcnt;
-	int				error = 0;
-	int				retval = 0;
-
-	trace_xfs_attr_rmtval_remove(args);
-	xfs_delattr_context_init(&dac, args);
-
-	/*
-	 * Keep de-allocating extents until the remote-value region is gone.
-	 */
-	lblkno = args->rmtblkno;
-	blkcnt = args->rmtblkcnt;
-	do {
-		retval = __xfs_attr_rmtval_remove(&dac);
-		if (retval && retval != EAGAIN)
-			return retval;
-
-		error = xfs_attr_defer_finish(&dac);
-		if (error)
-			break;
-
-		/*
-		 * Close out trans and start the next one in the chain.
-		 */
-		error = xfs_trans_roll_inode(&args->trans, args->dp);
-		if (error)
-			return error;
-	} while (retval == -EAGAIN);
-
-	return 0;
-}
-
-/*
  * Remove the value associated with an attribute by deleting the out-of-line
  * buffer that it is stored on. Returns EAGAIN for the caller to refresh the
  * transaction and recall the function
fs/xfs/libxfs/xfs_attr_remote.h +4 -0
index 351da00..51a1c91 100644
@@ -15,4 +15,8 @@ int xfs_attr_rmtval_stale(struct xfs_inode *ip, struct xfs_bmbt_irec *map,
 		xfs_buf_flags_t incore_flags);
 int xfs_attr_rmtval_invalidate(struct xfs_da_args *args);
 int __xfs_attr_rmtval_remove(struct xfs_delattr_context *dac);
+int xfs_attr_rmt_find_hole(struct xfs_da_args *args);
+int xfs_attr_rmtval_set_value(struct xfs_da_args *args);
+int xfs_attr_rmtval_set_blk(struct xfs_delattr_context *dac);
+int xfs_attr_rmtval_set_init(struct xfs_delattr_context *dac);
 #endif /* __XFS_ATTR_REMOTE_H__ */
fs/xfs/xfs_trace.h +0 -1
index a4323a6..26dc8bf 100644
@@ -1784,7 +1784,6 @@ DEFINE_ATTR_EVENT(xfs_attr_refillstate);
 
 DEFINE_ATTR_EVENT(xfs_attr_rmtval_get);
 DEFINE_ATTR_EVENT(xfs_attr_rmtval_set);
-DEFINE_ATTR_EVENT(xfs_attr_rmtval_remove);
 
 #define DEFINE_DA_EVENT(name) \
 DEFINE_EVENT(xfs_da_class, name, \
Signature · 1 line
2.7.4
#70 lore raw

Re: [PATCH v9 23/24] xfs: Add delay ready attr set routines

Quoted 27 lines · Darrick J. Wong
Quoted 26 lines · Allison Collins

This patch modifies the attr set routines to be delay ready. This means they no longer roll or commit transactions, but instead return -EAGAIN to have the calling routine roll and refresh the transaction. In this series, xfs_attr_set_args has become xfs_attr_set_iter, which uses a state machine like switch to keep track of where it was when EAGAIN was returned.

Two new helper functions have been added: xfs_attr_rmtval_set_init and xfs_attr_rmtval_set_blk. They provide a subset of logic similar to xfs_attr_rmtval_set, but they store the current block in the delay attr context to allow the caller to roll the transaction between allocations. This helps to simplify and consolidate code used by xfs_attr_leaf_addname and xfs_attr_node_addname. xfs_attr_set_args has now become a simple loop to refresh the transaction until the operation is completed. Lastly, xfs_attr_rmtval_remove is no longer used, and is removed.

Below is a state machine diagram for attr set operations. The XFS_DAS_* states indicate places where the function would return -EAGAIN, and then immediately resume from after being recalled by the calling function. States marked as a "subroutine state" indicate that they belong to a subroutine, and so the calling function needs to pass them back to that subroutine to allow it to finish where it left off. But they otherwise do not have a role in the calling function other than just passing through.

Quoted 8 lines
Quoted 5 lines

xfs_attr_set_iter()
│
v

   ┌──────n── fork has
   │         only 1 blk?

"Refer to the state machine diagram in xfs_attr.h for exact details of how this works."

Sure, that fine

Quoted 221 lines
Quoted 221 lines
   │              │
   │              y
   │              │
   │              v
   │     xfs_attr_leaf_try_add()
   │              │
   │              v
   │          had enough
   ├──────n──   space?
   │              │
   │              y
   │              │
   │              v
   │      XFS_DAS_FOUND_LBLK  ──┐
   │                            │
   │      XFS_DAS_FLIP_LFLAG  ──┤
   │      (subroutine state)    │
   │                            │
   │                            └─>xfs_attr_leaf_addname()
   │                                              │
   │                                              v
   │                                            was this
   │                                           a rename? ──n─┐
   │                                              │          │
   │                                              y          │
   │                                              │          │
   │                                              v          │
   │                                        flip incomplete  │
   │                                            flag         │
   │                                              │          │
   │                                              v          │
   │                                      XFS_DAS_FLIP_LFLAG │
   │                                              │          │
   │                                              v          │
   │                                            remove       │
   │                        XFS_DAS_RM_LBLK ─> old name      │
   │                                 ^            │          │
   │                                 │            v          │
   │                                 └──────y── more to      │
   │                                            remove       │
   │                                              │          │
   │                                              n          │
   │                                              │          │
   │                                              v          │
   │                                             done <──────┘
   └────> XFS_DAS_FOUND_NBLK  ──┐
          (subroutine state)    │
                                │
          XFS_DAS_ALLOC_NODE  ──┤
          (subroutine state)    │
                                │
          XFS_DAS_FLIP_NFLAG  ──┤
          (subroutine state)    │
                                │
                                └─>xfs_attr_node_addname()
                                                  │

v
find space to store
attr. Split if needed
│ v
XFS_DAS_FOUND_NBLK
│ v
┌─────n── need to
│ alloc blks?
│ │
│ y
│ │
│ v
│ ┌─>XFS_DAS_ALLOC_NODE
│ │ │
│ │ v
│ └──y── need to alloc
│ more blocks?
│ │
│ n
│ │
│ v
│ was this
└────────> a rename? ──n─┐
│ │
y │
│ │
v │
flip incomplete │
flag │
│ │
v │
XFS_DAS_FLIP_NFLAG │
│ │
v │
remove │
XFS_DAS_RM_NBLK ─> old name │
^ │ │
│ v │
└──────y── more to │
remove │
│ │
n │
│ │
v │
done <──────┘

---
  fs/xfs/libxfs/xfs_attr.c        | 371 +++++++++++++++++++++++++++-------------
  fs/xfs/libxfs/xfs_attr.h        | 127 +++++++++++++-
  fs/xfs/libxfs/xfs_attr_remote.c | 110 +++++++-----
  fs/xfs/libxfs/xfs_attr_remote.h |   4 +
  fs/xfs/xfs_trace.h              |   1 -
  5 files changed, 445 insertions(+), 168 deletions(-)
fs/xfs/libxfs/xfs_attr.c +28 -21
index 7213589..0751231 100644
@@ -44,7 +44,7 @@ STATIC int xfs_attr_shortform_addname(xfs_da_args_t *args);
   * Internal routines when attribute list is one block.
   */
  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_addname(struct xfs_delattr_context *dac);
  STATIC int xfs_attr_leaf_removename(xfs_da_args_t *args);
  STATIC int xfs_attr_leaf_hasname(struct xfs_da_args *args, struct xfs_buf **bp);
 
@@ -52,12 +52,13 @@ STATIC int xfs_attr_leaf_hasname(struct xfs_da_args *args, struct xfs_buf **bp);
   * Internal routines when attribute list is more than one block.
   */
  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_addname(struct xfs_delattr_context *dac);
  STATIC int xfs_attr_node_removename(struct xfs_delattr_context *dac);
  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);
 
  void
  xfs_delattr_context_init(
@@ -227,8 +228,11 @@ xfs_attr_is_shortform(
 
  /*
   * Attempts to set an attr in shortform, or converts short form to leaf form if
- * there is not enough room.  If the attr is set, the transaction is committed
- * and set to NULL.
+ * there is not enough room.  This function is meant to operate as a helper
+ * routine to the delayed attribute functions.  It returns -EAGAIN to indicate
+ * that the calling function should roll the transaction, and then proceed to
+ * add the attr in leaf form.  This subroutine does not expect to be recalled
+ * again like the other delayed attr routines do.
   */
  STATIC int
  xfs_attr_set_shortform(
@@ -236,16 +240,16 @@ xfs_attr_set_shortform(
  	struct xfs_buf		**leaf_bp)
  {
  	struct xfs_inode	*dp = args->dp;
-	int			error, error2 = 0;
+	int			error = 0;
 
  	/*
  	 * Try to add the attr to the attribute list in the inode.
  	 */
  	error = xfs_attr_try_sf_addname(dp, args);
+
+	/* Should only be 0, -EEXIST or ENOSPC */
  	if (error != -ENOSPC) {
-		error2 = xfs_trans_commit(args->trans);
-		args->trans = NULL;
-		return error ? error : error2;
+		return error;
  	}
  	/*
  	 * It won't fit in the shortform, transform to a leaf block.  GROT:
@@ -258,20 +262,13 @@ xfs_attr_set_shortform(
  	/*
  	 * 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. Once we're done rolling the transaction we
-	 * can release the hold and add the attr to the leaf.
+	 * with the write verifier.
  	 */
  	xfs_trans_bhold(args->trans, *leaf_bp);
-	error = xfs_defer_finish(&args->trans);
-	xfs_trans_bhold_release(args->trans, *leaf_bp);
-	if (error) {
-		xfs_trans_brelse(args->trans, *leaf_bp);
-		return error;
-	}
-
-	return 0;
+	return -EAGAIN;
  }
 
+STATIC
  int xfs_attr_defer_finish(
  	struct xfs_delattr_context      *dac)
  {
@@ -291,60 +288,128 @@ int
  xfs_attr_set_args(
  	struct xfs_da_args	*args)
  {
-	struct xfs_inode	*dp = args->dp;
-	struct xfs_buf          *leaf_bp = NULL;
-	int			error = 0;
+	struct xfs_buf			*leaf_bp = NULL;
+	int				error = 0;
+	struct xfs_delattr_context	dac;
+
+	xfs_delattr_context_init(&dac, args);
+
+	do {
+		error = xfs_attr_set_iter(&dac, &leaf_bp);
+		if (error != -EAGAIN)
+			break;
+
+		error = xfs_attr_defer_finish(&dac);
+		if (error)
Quoted 8 lines

fs/xfs/libxfs/xfs_attr.c int · line 308

Quoted 5 lines
fs/xfs/libxfs/xfs_attr.c +5 -0
+			break;
+
+		error = xfs_trans_roll_inode(&args->trans, args->dp);
+		if (error)
+			break;
	if (!xfs_attr_roll_again(&dac, &error))
		break;

Yep, ok

Quoted 666 lines
Quoted 202 lines
fs/xfs/libxfs/xfs_attr.c +112 -53
+
+		if (leaf_bp) {
+			xfs_trans_bjoin(args->trans, leaf_bp);
+			xfs_trans_bhold(args->trans, leaf_bp);
+		}
+
+	} while (true);
+
+	return error;
+}
+
+/*
+ * Set the attribute specified in @args.
+ * This routine is meant to function as a delayed operation, and may return
+ * -EAGAIN 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_iter(
+	struct xfs_delattr_context	*dac,
+	struct xfs_buf			**leaf_bp)
+{
+	struct xfs_da_args		*args = dac->da_args;
+	struct xfs_inode		*dp = args->dp;
+	int				error = 0;
+
+	/* State machine switch */
+	switch (dac->dela_state) {
+	case XFS_DAS_FLIP_LFLAG:
+	case XFS_DAS_FOUND_LBLK:
+		goto das_leaf;
+	case XFS_DAS_FOUND_NBLK:
+	case XFS_DAS_FLIP_NFLAG:
+	case XFS_DAS_ALLOC_NODE:
+		goto das_node;
+	default:
+		break;
+	}
 
  	/*
  	 * If the attribute list is already in leaf format, jump straight to
  	 * leaf handling.  Otherwise, try to add the attribute to the shortform
  	 * list; if there's no room then convert the list to leaf format and try
-	 * again.
+	 * again. No need to set state as we will be in leaf form when we come
+	 * back
  	 */
  	if (xfs_attr_is_shortform(dp)) {
 
  		/*
-		 * If the attr was successfully set in shortform, the
-		 * transaction is committed and set to NULL.  Otherwise, is it
-		 * converted from shortform to leaf, and the transaction is
-		 * retained.
+		 * If the attr was successfully set in shortform, no need to
+		 * continue.  Otherwise, is it converted from shortform to leaf
+		 * and -EAGAIN is returned.
  		 */
-		error = xfs_attr_set_shortform(args, &leaf_bp);
-		if (error || !args->trans)
-			return error;
-	}
+		error = xfs_attr_set_shortform(args, leaf_bp);
+		if (error == -EAGAIN)
+			dac->flags |= XFS_DAC_DEFER_FINISH;
 
-	if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
-		error = xfs_attr_leaf_addname(args);
-		if (error != -ENOSPC)
-			return error;
+		return error;
+	}
 
-		/*
-		 * Promote the attribute list to the Btree format.
-		 */
-		error = xfs_attr3_leaf_to_node(args);
-		if (error)
-			return error;
+	/*
+	 * 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_bhold_release(args->trans, *leaf_bp);
+		*leaf_bp = NULL;
+	}
 
-		/*
-		 * Commit that transaction so that the node_addname()
-		 * call can manage its own transactions.
-		 */
-		error = xfs_defer_finish(&args->trans);
-		if (error)
-			return error;
+	if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
+		error = xfs_attr_leaf_try_add(args, *leaf_bp);
+		switch (error) {
+		case -ENOSPC:
+			/*
+			 * Promote the attribute list to the Btree format.
+			 */
+			error = xfs_attr3_leaf_to_node(args);
+			if (error)
+				return error;
 
-		/*
-		 * Commit the current trans (including the inode) and
-		 * start a new one.
-		 */
-		error = xfs_trans_roll_inode(&args->trans, dp);
-		if (error)
+			/*
+			 * Commit that transaction so that the node_addname()
+			 * call can manage its own transactions.
+			 */
+			dac->flags |= XFS_DAC_DEFER_FINISH;
+			return -EAGAIN;
+		case 0:
+			dac->dela_state = XFS_DAS_FOUND_LBLK;
+			return -EAGAIN;
+		default:
  			return error;
+		}
+das_leaf:
+		error = xfs_attr_leaf_addname(dac);
+		if (error == -ENOSPC)
+			/* We will be in node form when we return */
+			return -EAGAIN;
 
+		return error;
  	}
-
-	error = xfs_attr_node_addname(args);
+das_node:
+	error = xfs_attr_node_addname(dac);
  	return error;
  }
 
@@ -711,28 +776,30 @@ xfs_attr_leaf_try_add(
   *
   * 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
+ * -EAGAIN 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_attr_leaf_addname(
-	struct xfs_da_args	*args)
+	struct xfs_delattr_context	*dac)
  {
-	int			error, forkoff;
-	struct xfs_buf		*bp = NULL;
-	struct xfs_inode	*dp = args->dp;
-
-	trace_xfs_attr_leaf_addname(args);
-
-	error = xfs_attr_leaf_try_add(args, bp);
-	if (error)
-		return error;
+	struct xfs_da_args		*args = dac->da_args;
+	struct xfs_buf			*bp = NULL;
+	int				error, forkoff;
+	struct xfs_inode		*dp = args->dp;
 
-	/*
-	 * Commit the transaction that added the attr name so that
-	 * later routines can manage their own transactions.
-	 */
-	error = xfs_trans_roll_inode(&args->trans, dp);
-	if (error)
-		return error;
+	/* State machine switch */
+	switch (dac->dela_state) {
+	case XFS_DAS_FLIP_LFLAG:
+		goto das_flip_flag;
+	case XFS_DAS_RM_LBLK:
+		goto das_rm_lblk;
+	default:
+		break;
+	}
 
  	/*
  	 * If there was an out-of-line value, allocate the blocks we
@@ -740,12 +807,34 @@ xfs_attr_leaf_addname(
  	 * 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) {
-		error = xfs_attr_rmtval_set(args);
+
+	/* Open coded xfs_attr_rmtval_set without trans handling */
+	if ((dac->flags & XFS_DAC_LEAF_ADDNAME_INIT) == 0) {
+		dac->flags |= XFS_DAC_LEAF_ADDNAME_INIT;
+		if (args->rmtblkno > 0) {
+			error = xfs_attr_rmtval_set_init(dac);

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

Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10 -0
+			if (error)
+				return error;
+		}
+	}
+
+	/*
+	 * Roll through the "value", allocating blocks on disk as
+	 * required.
+	 */
+	while (dac->blkcnt > 0) {

if() ?

Quoted 164 lines
fs/xfs/libxfs/xfs_attr.c +57 -36
+		error = xfs_attr_rmtval_set_blk(dac);
  		if (error)
  			return error;
+
+		dac->flags |= XFS_DAC_DEFER_FINISH;
+		return -EAGAIN;
  	}
 
+	error = xfs_attr_rmtval_set_value(args);
+	if (error)
+		return error;
+
  	if ((args->op_flags & XFS_DA_OP_RENAME) == 0) {
  		/*
  		 * Added a "remote" value, just clear the incomplete flag.
@@ -765,29 +854,33 @@ xfs_attr_leaf_addname(
  	 * In a separate transaction, set the incomplete flag on the "old" attr
  	 * and clear the incomplete flag on the "new" attr.
  	 */
-
  	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;
-
+	dac->dela_state = XFS_DAS_FLIP_LFLAG;
+	return -EAGAIN;
+das_flip_flag:
  	/*
  	 * Dismantle the "old" attribute/value pair by removing a "remote" value
  	 * (if it exists).
  	 */
  	xfs_attr_restore_rmt_blk(args);
 
+	error = xfs_attr_rmtval_invalidate(args);
+	if (error)
+		return error;
+das_rm_lblk:
  	if (args->rmtblkno) {
-		error = xfs_attr_rmtval_invalidate(args);
-		if (error)
-			return error;
+		error = __xfs_attr_rmtval_remove(dac);
+
+		if (error == -EAGAIN) {
+			dac->dela_state = XFS_DAS_RM_LBLK;
+			return -EAGAIN;
+		}
 
-		error = xfs_attr_rmtval_remove(args);
  		if (error)
  			return error;
  	}
@@ -957,16 +1050,23 @@ xfs_attr_node_hasname(
   *
   * "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
+ * -EAGAIN 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_attr_node_addname(
-	struct xfs_da_args	*args)
+	struct xfs_delattr_context	*dac)
  {
-	struct xfs_da_state	*state;
-	struct xfs_da_state_blk	*blk;
-	struct xfs_inode	*dp;
-	struct xfs_mount	*mp;
-	int			retval, error;
+	struct xfs_da_args		*args = dac->da_args;
+	struct xfs_da_state		*state = NULL;
+	struct xfs_da_state_blk		*blk;
+	struct xfs_inode		*dp;
+	struct xfs_mount		*mp;
+	int				retval = 0;
+	int				error = 0;
 
  	trace_xfs_attr_node_addname(args);
 
@@ -975,7 +1075,21 @@ xfs_attr_node_addname(
  	 */
  	dp = args->dp;
  	mp = dp->i_mount;
-restart:
+
+	/* State machine switch */
+	switch (dac->dela_state) {
+	case XFS_DAS_FLIP_NFLAG:
+		goto das_flip_flag;
+	case XFS_DAS_FOUND_NBLK:
+		goto das_found_nblk;
+	case XFS_DAS_ALLOC_NODE:
+		goto das_alloc_node;
+	case XFS_DAS_RM_NBLK:
+		goto das_rm_nblk;
+	default:
+		break;
+	}
+
  	/*
  	 * Search to see if name already exists, and get back a pointer
  	 * to where it should go.
@@ -1021,19 +1135,13 @@ xfs_attr_node_addname(
  			error = xfs_attr3_leaf_to_node(args);
  			if (error)
  				goto out;
-			error = xfs_defer_finish(&args->trans);
-			if (error)
-				goto out;
 
  			/*
-			 * Commit the node conversion and start the next
-			 * trans in the chain.
+			 * Restart routine from the top.  No need to set  the
+			 * state
  			 */
-			error = xfs_trans_roll_inode(&args->trans, dp);
-			if (error)
-				goto out;
-
-			goto restart;
+			dac->flags |= XFS_DAC_DEFER_FINISH;
+			return -EAGAIN;
  		}
 
  		/*
@@ -1045,9 +1153,7 @@ xfs_attr_node_addname(
  		error = xfs_da3_split(state);
  		if (error)
  			goto out;
-		error = xfs_defer_finish(&args->trans);
-		if (error)
-			goto out;
+		dac->flags |= XFS_DAC_DEFER_FINISH;
  	} else {
  		/*
  		 * Addition succeeded, update Btree hashvals.
@@ -1062,13 +1168,9 @@ xfs_attr_node_addname(
  	xfs_da_state_free(state);
  	state = NULL;
 
-	/*
-	 * Commit the leaf addition or btree split and start the next
-	 * trans in the chain.
-	 */
-	error = xfs_trans_roll_inode(&args->trans, dp);
-	if (error)
-		goto out;
+	dac->dela_state = XFS_DAS_FOUND_NBLK;
+	return -EAGAIN;
+das_found_nblk:
 
  	/*
  	 * If there was an out-of-line value, allocate the blocks we

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

Quoted 6 lines
fs/xfs/libxfs/xfs_attr.c +2 -1
@@ -1077,7 +1179,27 @@ xfs_attr_node_addname(
  	 * maximum size of a transaction and/or hit a deadlock.
  	 */
  	if (args->rmtblkno > 0) {
-		error = xfs_attr_rmtval_set(args);
+		/* Open coded xfs_attr_rmtval_set without trans handling */
+		error = xfs_attr_rmtval_set_init(dac);

Do we need to test/set LEAF_ADDNAME_INIT here too?

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

Quoted 9 lines
fs/xfs/libxfs/xfs_attr.c +9 -0
+		if (error)
+			return error;
+
+		/*
+		 * Roll through the "value", allocating blocks on disk as
+		 * required.
+		 */
+das_alloc_node:
+		while (dac->blkcnt > 0) {

if() ?

Quoted 254 lines
fs/xfs/libxfs/xfs_attr.c +26 -11
+			error = xfs_attr_rmtval_set_blk(dac);
+			if (error)
+				return error;
+
+			dac->flags |= XFS_DAC_DEFER_FINISH;
+			dac->dela_state = XFS_DAS_ALLOC_NODE;
+			return -EAGAIN;
+		}
+
+		error = xfs_attr_rmtval_set_value(args);
  		if (error)
  			return error;
  	}
@@ -1107,22 +1229,28 @@ xfs_attr_node_addname(
  	/*
  	 * 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;
-
+	dac->dela_state = XFS_DAS_FLIP_NFLAG;
+	return -EAGAIN;
+das_flip_flag:
  	/*
  	 * Dismantle the "old" attribute/value pair by removing a "remote" value
  	 * (if it exists).
  	 */
  	xfs_attr_restore_rmt_blk(args);
 
+	error = xfs_attr_rmtval_invalidate(args);
+	if (error)
+		return error;
+
+das_rm_nblk:
  	if (args->rmtblkno) {
-		error = xfs_attr_rmtval_invalidate(args);
-		if (error)
-			return error;
+		error = __xfs_attr_rmtval_remove(dac);
+
+		if (error == -EAGAIN) {
+			dac->dela_state = XFS_DAS_RM_NBLK;
+			return -EAGAIN;
+		}
 
-		error = xfs_attr_rmtval_remove(args);
  		if (error)
  			return error;
  	}
@@ -1155,9 +1283,8 @@ xfs_attr_node_addname(
  		error = xfs_da3_join(state);
  		if (error)
  			goto out;
-		error = xfs_defer_finish(&args->trans);
-		if (error)
-			goto out;
+
+		dac->flags |= XFS_DAC_DEFER_FINISH;
  	}
  	retval = error = 0;
 
fs/xfs/libxfs/xfs_attr.h +126 -1
index 0430c79..5cbefa90 100644
@@ -106,6 +106,118 @@ struct xfs_attr_list_context {
   *	                                      v         │
   *	                                     done <─────┘
   *
+ *
+ * Below is a state machine diagram for attr set operations.
+ *
+ *  xfs_attr_set_iter()
+ *             │
+ *             v
+ *   ┌───n── fork has
+ *   │	    only 1 blk?
+ *   │		│
+ *   │		y
+ *   │		│
+ *   │		v
+ *   │	xfs_attr_leaf_try_add()
+ *   │		│
+ *   │		v
+ *   │	     had enough
+ *   ├───n────space?
+ *   │		│
+ *   │		y
+ *   │		│
+ *   │		v
+ *   │	XFS_DAS_FOUND_LBLK ──┐
+ *   │	                     │
+ *   │	XFS_DAS_FLIP_LFLAG ──┤
+ *   │	(subroutine state)   │
+ *   │		             │
+ *   │		             └─>xfs_attr_leaf_addname()
+ *   │		                      │
+ *   │		                      v
+ *   │		                   was this
+ *   │		                   a rename? ──n─┐
+ *   │		                      │          │
+ *   │		                      y          │
+ *   │		                      │          │
+ *   │		                      v          │
+ *   │		                flip incomplete  │
+ *   │		                    flag         │
+ *   │		                      │          │
+ *   │		                      v          │
+ *   │		              XFS_DAS_FLIP_LFLAG │
+ *   │		                      │          │
+ *   │		                      v          │
+ *   │		                    remove       │
+ *   │		XFS_DAS_RM_LBLK ─> old name      │
+ *   │		         ^            │          │
+ *   │		         │            v          │
+ *   │		         └──────y── more to      │
+ *   │		                    remove       │
+ *   │		                      │          │
+ *   │		                      n          │
+ *   │		                      │          │
+ *   │		                      v          │
+ *   │		                     done <──────┘
+ *   └──> XFS_DAS_FOUND_NBLK ──┐
+ *	  (subroutine state)   │
+ *	                       │
+ *	  XFS_DAS_ALLOC_NODE ──┤
+ *	  (subroutine state)   │
+ *	                       │
+ *	  XFS_DAS_FLIP_NFLAG ──┤
+ *	  (subroutine state)   │
+ *	                       │
+ *	                       └─>xfs_attr_node_addname()
+ *	                               │
+ *	                               v
+ *	                       find space to store
+ *	                      attr. Split if needed
+ *	                               │
+ *	                               v
+ *	                       XFS_DAS_FOUND_NBLK
+ *	                               │
+ *	                               v
+ *	                 ┌─────n──  need to
+ *	                 │        alloc blks?
+ *	                 │             │
+ *	                 │             y
+ *	                 │             │
+ *	                 │             v
+ *	                 │  ┌─>XFS_DAS_ALLOC_NODE
+ *	                 │  │          │
+ *	                 │  │          v
+ *	                 │  └──y── need to alloc
+ *	                 │         more blocks?
+ *	                 │             │
+ *	                 │             n
+ *	                 │             │
+ *	                 │             v
+ *	                 │          was this
+ *	                 └────────> a rename? ──n─┐
+ *	                               │          │
+ *	                               y          │
+ *	                               │          │
+ *	                               v          │
+ *	                         flip incomplete  │
+ *	                             flag         │
+ *	                               │          │
+ *	                               v          │
+ *	                       XFS_DAS_FLIP_NFLAG │
+ *	                               │          │
+ *	                               v          │
+ *	                             remove       │
+ *	         XFS_DAS_RM_NBLK ─> old name      │
+ *	                  ^            │          │
+ *	                  │            v          │
+ *	                  └──────y── more to      │
+ *	                             remove       │
+ *	                               │          │
+ *	                               n          │
+ *	                               │          │
+ *	                               v          │
+ *	                              done <──────┘
+ *
   */
 
  /*
@@ -120,6 +232,13 @@ struct xfs_attr_list_context {
  enum xfs_delattr_state {
  				      /* Zero is uninitalized */
  	XFS_DAS_RM_SHRINK	= 1,  /* We are shrinking the tree */
+	XFS_DAS_FOUND_LBLK,	      /* We found leaf blk for attr */
+	XFS_DAS_FOUND_NBLK,	      /* We found node blk for attr */
+	XFS_DAS_FLIP_LFLAG,	      /* Flipped leaf INCOMPLETE attr flag */
+	XFS_DAS_RM_LBLK,	      /* A rename is removing leaf blocks */
+	XFS_DAS_ALLOC_NODE,	      /* We are allocating node blocks */
+	XFS_DAS_FLIP_NFLAG,	      /* Flipped node INCOMPLETE attr flag */
+	XFS_DAS_RM_NBLK,	      /* A rename is removing node blocks */
  };
 
  /*
@@ -127,6 +246,7 @@ enum xfs_delattr_state {
   */
  #define XFS_DAC_DEFER_FINISH		0x01 /* finish the transaction */
  #define XFS_DAC_NODE_RMVNAME_INIT	0x02 /* xfs_attr_node_removename init */
+#define XFS_DAC_LEAF_ADDNAME_INIT	0x04 /* xfs_attr_leaf_addname init*/
 
  /*
   * Context used for keeping track of delayed attribute operations
@@ -134,6 +254,11 @@ enum xfs_delattr_state {
  struct xfs_delattr_context {
  	struct xfs_da_args      *da_args;
 
+	/* Used in xfs_attr_rmtval_set_blk to roll through allocating blocks */
+	struct xfs_bmbt_irec	map;
+	xfs_dablk_t		lblkno;
+	int			blkcnt;
+
  	/* Used in xfs_attr_node_removename to roll through removing blocks */
  	struct xfs_da_state     *da_state;
  	struct xfs_da_state_blk *blk;
@@ -158,10 +283,10 @@ int xfs_attr_get_ilocked(struct xfs_da_args *args);
  int xfs_attr_get(struct xfs_da_args *args);
  int xfs_attr_set(struct xfs_da_args *args);
  int xfs_attr_set_args(struct xfs_da_args *args);
+int xfs_attr_set_iter(struct xfs_delattr_context *dac, struct xfs_buf **leaf_bp);
  int xfs_has_attr(struct xfs_da_args *args);
  int xfs_attr_remove_args(struct xfs_da_args *args);
  int xfs_attr_remove_iter(struct xfs_delattr_context *dac);
-int xfs_attr_defer_finish(struct xfs_delattr_context *dac);
  bool xfs_attr_namecheck(const void *name, size_t length);
  void xfs_delattr_context_init(struct xfs_delattr_context *dac,
  			      struct xfs_da_args *args);
fs/xfs/libxfs/xfs_attr_remote.c +2 -2
index f2d46c7..7a342f1 100644
@@ -443,7 +443,7 @@ xfs_attr_rmtval_get(
   * Find a "hole" in the attribute address space large enough for us to drop the
   * new attribute's value into
   */
-STATIC int
+int
  xfs_attr_rmt_find_hole(
  	struct xfs_da_args	*args)
  {
@@ -470,7 +470,7 @@ xfs_attr_rmt_find_hole(
  	return 0;
  }
 
-STATIC int
+int
  xfs_attr_rmtval_set_value(
  	struct xfs_da_args	*args)
  {

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

Quoted 9 lines
fs/xfs/libxfs/xfs_attr_remote.c +6 -0
@@ -630,6 +630,70 @@ xfs_attr_rmtval_set(
  }
 
  /*
+ * Find a hole for the attr and store it in the delayed attr context.  This
+ * initializes the context to roll through allocating an attr extent for a
+ * delayed attr operation
+ */
+int
+xfs_attr_rmtval_set_init(

/me wonders if this ought to be named xfs_attr_rmtval_find_space() ?

Quoted 1 line

That's more or less what it's getting ready to do, right?

This is one Brian had asked for, though I'm not sure how set he is about names?

Quoted 18 lines

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

Quoted 6 lines
fs/xfs/libxfs/xfs_attr_remote.c +5 -0
+	struct xfs_delattr_context	*dac)
+{
+	struct xfs_da_args		*args = dac->da_args;
+	struct xfs_bmbt_irec		*map = &dac->map;
+	int error;
	int				error;
Quoted 9 lines
fs/xfs/libxfs/xfs_attr_remote.c +9 -0
+
+	dac->lblkno = 0;
+	dac->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)
Quoted 8 lines

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

Quoted 6 lines
fs/xfs/libxfs/xfs_attr_remote.c +6 -0
+		return error;
+
+	dac->blkcnt = args->rmtblkcnt;
+	dac->lblkno = args->rmtblkno;
+
+	return error;

This could be return 0;.

Sure

Quoted 18 lines
Quoted 18 lines
fs/xfs/libxfs/xfs_attr_remote.c +17 -0
+}
+
+/*
+ * Write one block of the value associated with an attribute into the
+ * out-of-line buffer that we have defined for it. This is similar to a subset
+ * of xfs_attr_rmtval_set, but records the current block to the delayed attr
+ * context, and leaves transaction handling to the caller.
+ */
+int
+xfs_attr_rmtval_set_blk(
+	struct xfs_delattr_context	*dac)
+{
+	struct xfs_da_args		*args = dac->da_args;
+	struct xfs_inode		*dp = args->dp;
+	struct xfs_bmbt_irec		*map = &dac->map;
+	int nmap;
+	int error;
Quoted 8 lines

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

Quoted 6 lines
fs/xfs/libxfs/xfs_attr_remote.c +6 -0
+
+	nmap = 1;
+	error = xfs_bmapi_write(args->trans, dp,
+		  (xfs_fileoff_t)dac->lblkno,
+		  dac->blkcnt, XFS_BMAPI_ATTRFORK,
+		  args->total, map, &nmap);

The indenting here could be improved.

ok, will fix. Will jump into cont' email now :-)

Quoted 100 lines

Whee, ok, it's lunchtime. I'll look at the state machine after eating.

--D

Quoted 95 lines
fs/xfs/libxfs/xfs_attr_remote.c +15 -42
+	if (error)
+		return error;
+
+	ASSERT(nmap == 1);
+	ASSERT((map->br_startblock != DELAYSTARTBLOCK) &&
+	       (map->br_startblock != HOLESTARTBLOCK));
+
+	/* roll attribute extent map forwards */
+	dac->lblkno += map->br_blockcount;
+	dac->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.
   */
@@ -671,48 +735,6 @@ xfs_attr_rmtval_invalidate(
  }
 
  /*
- * 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)
-{
-	struct xfs_delattr_context	dac;
-	xfs_dablk_t			lblkno;
-	int				blkcnt;
-	int				error = 0;
-	int				retval = 0;
-
-	trace_xfs_attr_rmtval_remove(args);
-	xfs_delattr_context_init(&dac, args);
-
-	/*
-	 * Keep de-allocating extents until the remote-value region is gone.
-	 */
-	lblkno = args->rmtblkno;
-	blkcnt = args->rmtblkcnt;
-	do {
-		retval = __xfs_attr_rmtval_remove(&dac);
-		if (retval && retval != EAGAIN)
-			return retval;
-
-		error = xfs_attr_defer_finish(&dac);
-		if (error)
-			break;
-
-		/*
-		 * Close out trans and start the next one in the chain.
-		 */
-		error = xfs_trans_roll_inode(&args->trans, args->dp);
-		if (error)
-			return error;
-	} while (retval == -EAGAIN);
-
-	return 0;
-}
-
-/*
   * Remove the value associated with an attribute by deleting the out-of-line
   * buffer that it is stored on. Returns EAGAIN for the caller to refresh the
   * transaction and recall the function
fs/xfs/libxfs/xfs_attr_remote.h +4 -0
index 351da00..51a1c91 100644
@@ -15,4 +15,8 @@ int xfs_attr_rmtval_stale(struct xfs_inode *ip, struct xfs_bmbt_irec *map,
  		xfs_buf_flags_t incore_flags);
  int xfs_attr_rmtval_invalidate(struct xfs_da_args *args);
  int __xfs_attr_rmtval_remove(struct xfs_delattr_context *dac);
+int xfs_attr_rmt_find_hole(struct xfs_da_args *args);
+int xfs_attr_rmtval_set_value(struct xfs_da_args *args);
+int xfs_attr_rmtval_set_blk(struct xfs_delattr_context *dac);
+int xfs_attr_rmtval_set_init(struct xfs_delattr_context *dac);
  #endif /* __XFS_ATTR_REMOTE_H__ */
fs/xfs/xfs_trace.h +0 -1
index a4323a6..26dc8bf 100644
@@ -1784,7 +1784,6 @@ DEFINE_ATTR_EVENT(xfs_attr_refillstate);
 
  DEFINE_ATTR_EVENT(xfs_attr_rmtval_get);
  DEFINE_ATTR_EVENT(xfs_attr_rmtval_set);
-DEFINE_ATTR_EVENT(xfs_attr_rmtval_remove);
 
  #define DEFINE_DA_EVENT(name) \
  DEFINE_EVENT(xfs_da_class, name, \
Signature · 1 line
2.7.4
#71 lore raw

Re: [PATCH v9 23/24] xfs: Add delay ready attr set routines

In reply to Allison Collins
Quoted 266 lines · Allison Collins

This patch modifies the attr set routines to be delay ready. This means they no longer roll or commit transactions, but instead return -EAGAIN to have the calling routine roll and refresh the transaction. In this series, xfs_attr_set_args has become xfs_attr_set_iter, which uses a state machine like switch to keep track of where it was when EAGAIN was returned.

Two new helper functions have been added: xfs_attr_rmtval_set_init and xfs_attr_rmtval_set_blk. They provide a subset of logic similar to xfs_attr_rmtval_set, but they store the current block in the delay attr context to allow the caller to roll the transaction between allocations. This helps to simplify and consolidate code used by xfs_attr_leaf_addname and xfs_attr_node_addname. xfs_attr_set_args has now become a simple loop to refresh the transaction until the operation is completed. Lastly, xfs_attr_rmtval_remove is no longer used, and is removed.

Below is a state machine diagram for attr set operations. The XFS_DAS_* states indicate places where the function would return -EAGAIN, and then immediately resume from after being recalled by the calling function. States marked as a "subroutine state" indicate that they belong to a subroutine, and so the calling function needs to pass them back to that subroutine to allow it to finish where it left off. But they otherwise do not have a role in the calling function other than just passing through.

xfs_attr_set_iter()
│
v

  ┌──────n── fork has
  │         only 1 blk?
  │              │
  │              y
  │              │
  │              v
  │     xfs_attr_leaf_try_add()
  │              │
  │              v
  │          had enough
  ├──────n──   space?
  │              │
  │              y
  │              │
  │              v
  │      XFS_DAS_FOUND_LBLK  ──┐
  │                            │
  │      XFS_DAS_FLIP_LFLAG  ──┤
  │      (subroutine state)    │
  │                            │
  │                            └─>xfs_attr_leaf_addname()
  │                                              │
  │                                              v
  │                                            was this
  │                                           a rename? ──n─┐
  │                                              │          │
  │                                              y          │
  │                                              │          │
  │                                              v          │
  │                                        flip incomplete  │
  │                                            flag         │
  │                                              │          │
  │                                              v          │
  │                                      XFS_DAS_FLIP_LFLAG │
  │                                              │          │
  │                                              v          │
  │                                            remove       │
  │                        XFS_DAS_RM_LBLK ─> old name      │
  │                                 ^            │          │
  │                                 │            v          │
  │                                 └──────y── more to      │
  │                                            remove       │
  │                                              │          │
  │                                              n          │
  │                                              │          │
  │                                              v          │
  │                                             done <──────┘
  └────> XFS_DAS_FOUND_NBLK  ──┐
         (subroutine state)    │
                               │
         XFS_DAS_ALLOC_NODE  ──┤
         (subroutine state)    │
                               │
         XFS_DAS_FLIP_NFLAG  ──┤
         (subroutine state)    │
                               │
                               └─>xfs_attr_node_addname()
                                                 │

v
find space to store
attr. Split if needed
│ v
XFS_DAS_FOUND_NBLK
│ v
┌─────n── need to
│ alloc blks?
│ │
│ y
│ │
│ v
│ ┌─>XFS_DAS_ALLOC_NODE
│ │ │
│ │ v
│ └──y── need to alloc
│ more blocks?
│ │
│ n
│ │
│ v
│ was this
└────────> a rename? ──n─┐
│ │
y │
│ │
v │
flip incomplete │
flag │
│ │
v │
XFS_DAS_FLIP_NFLAG │
│ │
v │
remove │
XFS_DAS_RM_NBLK ─> old name │
^ │ │
│ v │
└──────y── more to │
remove │
│ │
n │
│ │
v │
done <──────┘

---
 fs/xfs/libxfs/xfs_attr.c        | 371 +++++++++++++++++++++++++++-------------
 fs/xfs/libxfs/xfs_attr.h        | 127 +++++++++++++-
 fs/xfs/libxfs/xfs_attr_remote.c | 110 +++++++-----
 fs/xfs/libxfs/xfs_attr_remote.h |   4 +
 fs/xfs/xfs_trace.h              |   1 -
 5 files changed, 445 insertions(+), 168 deletions(-)
fs/xfs/libxfs/xfs_attr.c +43 -21
index 7213589..0751231 100644
@@ -44,7 +44,7 @@ STATIC int xfs_attr_shortform_addname(xfs_da_args_t *args);
  * Internal routines when attribute list is one block.
  */
 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_addname(struct xfs_delattr_context *dac);
 STATIC int xfs_attr_leaf_removename(xfs_da_args_t *args);
 STATIC int xfs_attr_leaf_hasname(struct xfs_da_args *args, struct xfs_buf **bp);
 
@@ -52,12 +52,13 @@ STATIC int xfs_attr_leaf_hasname(struct xfs_da_args *args, struct xfs_buf **bp);
  * Internal routines when attribute list is more than one block.
  */
 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_addname(struct xfs_delattr_context *dac);
 STATIC int xfs_attr_node_removename(struct xfs_delattr_context *dac);
 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);
 
 void
 xfs_delattr_context_init(
@@ -227,8 +228,11 @@ xfs_attr_is_shortform(
 
 /*
  * Attempts to set an attr in shortform, or converts short form to leaf form if
- * there is not enough room.  If the attr is set, the transaction is committed
- * and set to NULL.
+ * there is not enough room.  This function is meant to operate as a helper
+ * routine to the delayed attribute functions.  It returns -EAGAIN to indicate
+ * that the calling function should roll the transaction, and then proceed to
+ * add the attr in leaf form.  This subroutine does not expect to be recalled
+ * again like the other delayed attr routines do.
  */
 STATIC int
 xfs_attr_set_shortform(
@@ -236,16 +240,16 @@ xfs_attr_set_shortform(
 	struct xfs_buf		**leaf_bp)
 {
 	struct xfs_inode	*dp = args->dp;
-	int			error, error2 = 0;
+	int			error = 0;
 
 	/*
 	 * Try to add the attr to the attribute list in the inode.
 	 */
 	error = xfs_attr_try_sf_addname(dp, args);
+
+	/* Should only be 0, -EEXIST or ENOSPC */
 	if (error != -ENOSPC) {
-		error2 = xfs_trans_commit(args->trans);
-		args->trans = NULL;
-		return error ? error : error2;
+		return error;
 	}
 	/*
 	 * It won't fit in the shortform, transform to a leaf block.  GROT:
@@ -258,20 +262,13 @@ xfs_attr_set_shortform(
 	/*
 	 * 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. Once we're done rolling the transaction we
-	 * can release the hold and add the attr to the leaf.
+	 * with the write verifier.
 	 */
 	xfs_trans_bhold(args->trans, *leaf_bp);
-	error = xfs_defer_finish(&args->trans);
-	xfs_trans_bhold_release(args->trans, *leaf_bp);
-	if (error) {
-		xfs_trans_brelse(args->trans, *leaf_bp);
-		return error;
-	}
-
-	return 0;
+	return -EAGAIN;
 }
 
+STATIC
 int xfs_attr_defer_finish(
 	struct xfs_delattr_context      *dac)
 {
@@ -291,60 +288,128 @@ int
 xfs_attr_set_args(
 	struct xfs_da_args	*args)
 {
-	struct xfs_inode	*dp = args->dp;
-	struct xfs_buf          *leaf_bp = NULL;
-	int			error = 0;
+	struct xfs_buf			*leaf_bp = NULL;
+	int				error = 0;
+	struct xfs_delattr_context	dac;
+
+	xfs_delattr_context_init(&dac, args);
+
+	do {
+		error = xfs_attr_set_iter(&dac, &leaf_bp);
+		if (error != -EAGAIN)
+			break;
+
+		error = xfs_attr_defer_finish(&dac);
+		if (error)
+			break;
+
+		error = xfs_trans_roll_inode(&args->trans, args->dp);
+		if (error)
+			break;
+
+		if (leaf_bp) {
+			xfs_trans_bjoin(args->trans, leaf_bp);
+			xfs_trans_bhold(args->trans, leaf_bp);
+		}
+
+	} while (true);
+
+	return error;
+}

fs/xfs/libxfs/xfs_attr.c int · line 328

Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10 -0
+
+/*
+ * Set the attribute specified in @args.
+ * This routine is meant to function as a delayed operation, and may return
+ * -EAGAIN 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_iter(

Could this be a static function above xfs_attr_set()? Or is this something that will need to be exported in a later series?

Quoted 53 lines
fs/xfs/libxfs/xfs_attr.c +29 -13
+	struct xfs_delattr_context	*dac,
+	struct xfs_buf			**leaf_bp)
+{
+	struct xfs_da_args		*args = dac->da_args;
+	struct xfs_inode		*dp = args->dp;
+	int				error = 0;
+
+	/* State machine switch */
+	switch (dac->dela_state) {
+	case XFS_DAS_FLIP_LFLAG:
+	case XFS_DAS_FOUND_LBLK:
+		goto das_leaf;
+	case XFS_DAS_FOUND_NBLK:
+	case XFS_DAS_FLIP_NFLAG:
+	case XFS_DAS_ALLOC_NODE:
+		goto das_node;
+	default:
+		break;
+	}
 
 	/*
 	 * If the attribute list is already in leaf format, jump straight to
 	 * leaf handling.  Otherwise, try to add the attribute to the shortform
 	 * list; if there's no room then convert the list to leaf format and try
-	 * again.
+	 * again. No need to set state as we will be in leaf form when we come
+	 * back
 	 */
 	if (xfs_attr_is_shortform(dp)) {
 
 		/*
-		 * If the attr was successfully set in shortform, the
-		 * transaction is committed and set to NULL.  Otherwise, is it
-		 * converted from shortform to leaf, and the transaction is
-		 * retained.
+		 * If the attr was successfully set in shortform, no need to
+		 * continue.  Otherwise, is it converted from shortform to leaf
+		 * and -EAGAIN is returned.
 		 */
-		error = xfs_attr_set_shortform(args, &leaf_bp);
-		if (error || !args->trans)
-			return error;
-	}
+		error = xfs_attr_set_shortform(args, leaf_bp);
+		if (error == -EAGAIN)
+			dac->flags |= XFS_DAC_DEFER_FINISH;
 
-	if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
-		error = xfs_attr_leaf_addname(args);
-		if (error != -ENOSPC)
-			return error;
+		return error;
+	}

fs/xfs/libxfs/xfs_attr.c int · line 372

Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +3 -6
 
-		/*
-		 * Promote the attribute list to the Btree format.
-		 */
-		error = xfs_attr3_leaf_to_node(args);
-		if (error)
-			return error;
+	/*
+	 * 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

"cycle"

Quoted 37 lines
fs/xfs/libxfs/xfs_attr.c +22 -13
+	 * the leaf.
+	 */
+	if (*leaf_bp != NULL) {
+		xfs_trans_bhold_release(args->trans, *leaf_bp);
+		*leaf_bp = NULL;
+	}
 
-		/*
-		 * Commit that transaction so that the node_addname()
-		 * call can manage its own transactions.
-		 */
-		error = xfs_defer_finish(&args->trans);
-		if (error)
-			return error;
+	if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
+		error = xfs_attr_leaf_try_add(args, *leaf_bp);
+		switch (error) {
+		case -ENOSPC:
+			/*
+			 * Promote the attribute list to the Btree format.
+			 */
+			error = xfs_attr3_leaf_to_node(args);
+			if (error)
+				return error;
 
-		/*
-		 * Commit the current trans (including the inode) and
-		 * start a new one.
-		 */
-		error = xfs_trans_roll_inode(&args->trans, dp);
-		if (error)
+			/*
+			 * Commit that transaction so that the node_addname()
+			 * call can manage its own transactions.
+			 */
+			dac->flags |= XFS_DAC_DEFER_FINISH;
+			return -EAGAIN;

fs/xfs/libxfs/xfs_attr.c int · line 406

Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +9 -0
+		case 0:
+			dac->dela_state = XFS_DAS_FOUND_LBLK;
+			return -EAGAIN;
+		default:
 			return error;
+		}
+das_leaf:
+		error = xfs_attr_leaf_addname(dac);
+		if (error == -ENOSPC)
+			/* We will be in node form when we return */

Er, how does this happen? Is this comment merely referencing the node conversion that just happened 20 lines above? Or does something else do the conversion too?

Quoted 128 lines
fs/xfs/libxfs/xfs_attr.c +54 -29
+			return -EAGAIN;
 
+		return error;
 	}
-
-	error = xfs_attr_node_addname(args);
+das_node:
+	error = xfs_attr_node_addname(dac);
 	return error;
 }
 
@@ -711,28 +776,30 @@ xfs_attr_leaf_try_add(
  *
  * 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
+ * -EAGAIN 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_attr_leaf_addname(
-	struct xfs_da_args	*args)
+	struct xfs_delattr_context	*dac)
 {
-	int			error, forkoff;
-	struct xfs_buf		*bp = NULL;
-	struct xfs_inode	*dp = args->dp;
-
-	trace_xfs_attr_leaf_addname(args);
-
-	error = xfs_attr_leaf_try_add(args, bp);
-	if (error)
-		return error;
+	struct xfs_da_args		*args = dac->da_args;
+	struct xfs_buf			*bp = NULL;
+	int				error, forkoff;
+	struct xfs_inode		*dp = args->dp;
 
-	/*
-	 * Commit the transaction that added the attr name so that
-	 * later routines can manage their own transactions.
-	 */
-	error = xfs_trans_roll_inode(&args->trans, dp);
-	if (error)
-		return error;
+	/* State machine switch */
+	switch (dac->dela_state) {
+	case XFS_DAS_FLIP_LFLAG:
+		goto das_flip_flag;
+	case XFS_DAS_RM_LBLK:
+		goto das_rm_lblk;
+	default:
+		break;
+	}
 
 	/*
 	 * If there was an out-of-line value, allocate the blocks we
@@ -740,12 +807,34 @@ xfs_attr_leaf_addname(
 	 * 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) {
-		error = xfs_attr_rmtval_set(args);
+
+	/* Open coded xfs_attr_rmtval_set without trans handling */
+	if ((dac->flags & XFS_DAC_LEAF_ADDNAME_INIT) == 0) {
+		dac->flags |= XFS_DAC_LEAF_ADDNAME_INIT;
+		if (args->rmtblkno > 0) {
+			error = xfs_attr_rmtval_set_init(dac);
+			if (error)
+				return error;
+		}
+	}
+
+	/*
+	 * Roll through the "value", allocating blocks on disk as
+	 * required.
+	 */
+	while (dac->blkcnt > 0) {
+		error = xfs_attr_rmtval_set_blk(dac);
 		if (error)
 			return error;
+
+		dac->flags |= XFS_DAC_DEFER_FINISH;
+		return -EAGAIN;
 	}
 
+	error = xfs_attr_rmtval_set_value(args);
+	if (error)
+		return error;
+
 	if ((args->op_flags & XFS_DA_OP_RENAME) == 0) {
 		/*
 		 * Added a "remote" value, just clear the incomplete flag.
@@ -765,29 +854,33 @@ xfs_attr_leaf_addname(
 	 * In a separate transaction, set the incomplete flag on the "old" attr
 	 * and clear the incomplete flag on the "new" attr.
 	 */
-
 	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;
-
+	dac->dela_state = XFS_DAS_FLIP_LFLAG;
+	return -EAGAIN;
+das_flip_flag:
 	/*
 	 * Dismantle the "old" attribute/value pair by removing a "remote" value
 	 * (if it exists).
 	 */
 	xfs_attr_restore_rmt_blk(args);
 
+	error = xfs_attr_rmtval_invalidate(args);
+	if (error)
+		return error;
+das_rm_lblk:
 	if (args->rmtblkno) {
-		error = xfs_attr_rmtval_invalidate(args);
-		if (error)
-			return error;

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

Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +6 -1
+		error = __xfs_attr_rmtval_remove(dac);
+
+		if (error == -EAGAIN) {
+			dac->dela_state = XFS_DAS_RM_LBLK;
+			return -EAGAIN;
+		}
 
-		error = xfs_attr_rmtval_remove(args);
 		if (error)
 			return error;

This whole bit could condense to:

		error = __xfs_attr_rmtval_remove(dac);
		if (error == -EAGAIN)
			dac->dela_state = XFS_DAS_RM_LBLK;
		if (error)
			return error;
Quoted 293 lines
fs/xfs/libxfs/xfs_attr.c +73 -39
 	}
@@ -957,16 +1050,23 @@ xfs_attr_node_hasname(
  *
  * "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
+ * -EAGAIN 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_attr_node_addname(
-	struct xfs_da_args	*args)
+	struct xfs_delattr_context	*dac)
 {
-	struct xfs_da_state	*state;
-	struct xfs_da_state_blk	*blk;
-	struct xfs_inode	*dp;
-	struct xfs_mount	*mp;
-	int			retval, error;
+	struct xfs_da_args		*args = dac->da_args;
+	struct xfs_da_state		*state = NULL;
+	struct xfs_da_state_blk		*blk;
+	struct xfs_inode		*dp;
+	struct xfs_mount		*mp;
+	int				retval = 0;
+	int				error = 0;
 
 	trace_xfs_attr_node_addname(args);
 
@@ -975,7 +1075,21 @@ xfs_attr_node_addname(
 	 */
 	dp = args->dp;
 	mp = dp->i_mount;
-restart:
+
+	/* State machine switch */
+	switch (dac->dela_state) {
+	case XFS_DAS_FLIP_NFLAG:
+		goto das_flip_flag;
+	case XFS_DAS_FOUND_NBLK:
+		goto das_found_nblk;
+	case XFS_DAS_ALLOC_NODE:
+		goto das_alloc_node;
+	case XFS_DAS_RM_NBLK:
+		goto das_rm_nblk;
+	default:
+		break;
+	}
+
 	/*
 	 * Search to see if name already exists, and get back a pointer
 	 * to where it should go.
@@ -1021,19 +1135,13 @@ xfs_attr_node_addname(
 			error = xfs_attr3_leaf_to_node(args);
 			if (error)
 				goto out;
-			error = xfs_defer_finish(&args->trans);
-			if (error)
-				goto out;
 
 			/*
-			 * Commit the node conversion and start the next
-			 * trans in the chain.
+			 * Restart routine from the top.  No need to set  the
+			 * state
 			 */
-			error = xfs_trans_roll_inode(&args->trans, dp);
-			if (error)
-				goto out;
-
-			goto restart;
+			dac->flags |= XFS_DAC_DEFER_FINISH;
+			return -EAGAIN;
 		}
 
 		/*
@@ -1045,9 +1153,7 @@ xfs_attr_node_addname(
 		error = xfs_da3_split(state);
 		if (error)
 			goto out;
-		error = xfs_defer_finish(&args->trans);
-		if (error)
-			goto out;
+		dac->flags |= XFS_DAC_DEFER_FINISH;
 	} else {
 		/*
 		 * Addition succeeded, update Btree hashvals.
@@ -1062,13 +1168,9 @@ xfs_attr_node_addname(
 	xfs_da_state_free(state);
 	state = NULL;
 
-	/*
-	 * Commit the leaf addition or btree split and start the next
-	 * trans in the chain.
-	 */
-	error = xfs_trans_roll_inode(&args->trans, dp);
-	if (error)
-		goto out;
+	dac->dela_state = XFS_DAS_FOUND_NBLK;
+	return -EAGAIN;
+das_found_nblk:
 
 	/*
 	 * If there was an out-of-line value, allocate the blocks we
@@ -1077,7 +1179,27 @@ xfs_attr_node_addname(
 	 * maximum size of a transaction and/or hit a deadlock.
 	 */
 	if (args->rmtblkno > 0) {
-		error = xfs_attr_rmtval_set(args);
+		/* Open coded xfs_attr_rmtval_set without trans handling */
+		error = xfs_attr_rmtval_set_init(dac);
+		if (error)
+			return error;
+
+		/*
+		 * Roll through the "value", allocating blocks on disk as
+		 * required.
+		 */
+das_alloc_node:
+		while (dac->blkcnt > 0) {
+			error = xfs_attr_rmtval_set_blk(dac);
+			if (error)
+				return error;
+
+			dac->flags |= XFS_DAC_DEFER_FINISH;
+			dac->dela_state = XFS_DAS_ALLOC_NODE;
+			return -EAGAIN;
+		}
+
+		error = xfs_attr_rmtval_set_value(args);
 		if (error)
 			return error;
 	}
@@ -1107,22 +1229,28 @@ xfs_attr_node_addname(
 	/*
 	 * 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;
-
+	dac->dela_state = XFS_DAS_FLIP_NFLAG;
+	return -EAGAIN;
+das_flip_flag:
 	/*
 	 * Dismantle the "old" attribute/value pair by removing a "remote" value
 	 * (if it exists).
 	 */
 	xfs_attr_restore_rmt_blk(args);
 
+	error = xfs_attr_rmtval_invalidate(args);
+	if (error)
+		return error;
+
+das_rm_nblk:
 	if (args->rmtblkno) {
-		error = xfs_attr_rmtval_invalidate(args);
-		if (error)
-			return error;
+		error = __xfs_attr_rmtval_remove(dac);
+
+		if (error == -EAGAIN) {
+			dac->dela_state = XFS_DAS_RM_NBLK;
+			return -EAGAIN;
+		}
 
-		error = xfs_attr_rmtval_remove(args);
 		if (error)
 			return error;
 	}
@@ -1155,9 +1283,8 @@ xfs_attr_node_addname(
 		error = xfs_da3_join(state);
 		if (error)
 			goto out;
-		error = xfs_defer_finish(&args->trans);
-		if (error)
-			goto out;
+
+		dac->flags |= XFS_DAC_DEFER_FINISH;
 	}
 	retval = error = 0;
 
fs/xfs/libxfs/xfs_attr.h +101 -0
index 0430c79..5cbefa90 100644
@@ -106,6 +106,118 @@ struct xfs_attr_list_context {
  *	                                      v         │
  *	                                     done <─────┘
  *
+ *
+ * Below is a state machine diagram for attr set operations.
+ *
+ *  xfs_attr_set_iter()
+ *             │
+ *             v
+ *   ┌───n── fork has
+ *   │	    only 1 blk?
+ *   │		│
+ *   │		y
+ *   │		│
+ *   │		v
+ *   │	xfs_attr_leaf_try_add()
+ *   │		│
+ *   │		v
+ *   │	     had enough
+ *   ├───n────space?
+ *   │		│
+ *   │		y
+ *   │		│
+ *   │		v
+ *   │	XFS_DAS_FOUND_LBLK ──┐
+ *   │	                     │
+ *   │	XFS_DAS_FLIP_LFLAG ──┤
+ *   │	(subroutine state)   │
+ *   │		             │
+ *   │		             └─>xfs_attr_leaf_addname()
+ *   │		                      │
+ *   │		                      v
+ *   │		                   was this
+ *   │		                   a rename? ──n─┐
+ *   │		                      │          │
+ *   │		                      y          │
+ *   │		                      │          │
+ *   │		                      v          │
+ *   │		                flip incomplete  │
+ *   │		                    flag         │
+ *   │		                      │          │
+ *   │		                      v          │
+ *   │		              XFS_DAS_FLIP_LFLAG │
+ *   │		                      │          │
+ *   │		                      v          │
+ *   │		                    remove       │
+ *   │		XFS_DAS_RM_LBLK ─> old name      │
+ *   │		         ^            │          │
+ *   │		         │            v          │
+ *   │		         └──────y── more to      │
+ *   │		                    remove       │
+ *   │		                      │          │
+ *   │		                      n          │
+ *   │		                      │          │
+ *   │		                      v          │
+ *   │		                     done <──────┘
+ *   └──> XFS_DAS_FOUND_NBLK ──┐
+ *	  (subroutine state)   │
+ *	                       │
+ *	  XFS_DAS_ALLOC_NODE ──┤
+ *	  (subroutine state)   │
+ *	                       │
+ *	  XFS_DAS_FLIP_NFLAG ──┤
+ *	  (subroutine state)   │
+ *	                       │
+ *	                       └─>xfs_attr_node_addname()
+ *	                               │
+ *	                               v
+ *	                       find space to store
+ *	                      attr. Split if needed
+ *	                               │
+ *	                               v
+ *	                       XFS_DAS_FOUND_NBLK
+ *	                               │
+ *	                               v
+ *	                 ┌─────n──  need to
+ *	                 │        alloc blks?
+ *	                 │             │
+ *	                 │             y
+ *	                 │             │
+ *	                 │             v
+ *	                 │  ┌─>XFS_DAS_ALLOC_NODE
+ *	                 │  │          │
+ *	                 │  │          v
+ *	                 │  └──y── need to alloc
+ *	                 │         more blocks?
+ *	                 │             │
+ *	                 │             n
+ *	                 │             │
+ *	                 │             v
+ *	                 │          was this
+ *	                 └────────> a rename? ──n─┐
+ *	                               │          │
+ *	                               y          │
+ *	                               │          │
+ *	                               v          │
+ *	                         flip incomplete  │
+ *	                             flag         │
+ *	                               │          │
+ *	                               v          │
+ *	                       XFS_DAS_FLIP_NFLAG │
+ *	                               │          │
+ *	                               v          │
+ *	                             remove       │

fs/xfs/libxfs/xfs_attr.h struct xfs_attr_list_context { · line 219

Quoted 10 lines
fs/xfs/libxfs/xfs_attr.h +10 -0
+ *	         XFS_DAS_RM_NBLK ─> old name      │
+ *	                  ^            │          │
+ *	                  │            v          │
+ *	                  └──────y── more to      │
+ *	                             remove       │
+ *	                               │          │
+ *	                               n          │
+ *	                               │          │
+ *	                               v          │
+ *	                              done <──────┘

Ok, I traced through all this and I /think/ the state machine accurately reflects the code paths before all the surgery started. Whoever knew that implementing a key-value store was so complex?

--D

Quoted 220 lines
fs/xfs/libxfs/xfs_attr.h +15 -1
+ *
  */
 
 /*
@@ -120,6 +232,13 @@ struct xfs_attr_list_context {
 enum xfs_delattr_state {
 				      /* Zero is uninitalized */
 	XFS_DAS_RM_SHRINK	= 1,  /* We are shrinking the tree */
+	XFS_DAS_FOUND_LBLK,	      /* We found leaf blk for attr */
+	XFS_DAS_FOUND_NBLK,	      /* We found node blk for attr */
+	XFS_DAS_FLIP_LFLAG,	      /* Flipped leaf INCOMPLETE attr flag */
+	XFS_DAS_RM_LBLK,	      /* A rename is removing leaf blocks */
+	XFS_DAS_ALLOC_NODE,	      /* We are allocating node blocks */
+	XFS_DAS_FLIP_NFLAG,	      /* Flipped node INCOMPLETE attr flag */
+	XFS_DAS_RM_NBLK,	      /* A rename is removing node blocks */
 };
 
 /*
@@ -127,6 +246,7 @@ enum xfs_delattr_state {
  */
 #define XFS_DAC_DEFER_FINISH		0x01 /* finish the transaction */
 #define XFS_DAC_NODE_RMVNAME_INIT	0x02 /* xfs_attr_node_removename init */
+#define XFS_DAC_LEAF_ADDNAME_INIT	0x04 /* xfs_attr_leaf_addname init*/
 
 /*
  * Context used for keeping track of delayed attribute operations
@@ -134,6 +254,11 @@ enum xfs_delattr_state {
 struct xfs_delattr_context {
 	struct xfs_da_args      *da_args;
 
+	/* Used in xfs_attr_rmtval_set_blk to roll through allocating blocks */
+	struct xfs_bmbt_irec	map;
+	xfs_dablk_t		lblkno;
+	int			blkcnt;
+
 	/* Used in xfs_attr_node_removename to roll through removing blocks */
 	struct xfs_da_state     *da_state;
 	struct xfs_da_state_blk *blk;
@@ -158,10 +283,10 @@ int xfs_attr_get_ilocked(struct xfs_da_args *args);
 int xfs_attr_get(struct xfs_da_args *args);
 int xfs_attr_set(struct xfs_da_args *args);
 int xfs_attr_set_args(struct xfs_da_args *args);
+int xfs_attr_set_iter(struct xfs_delattr_context *dac, struct xfs_buf **leaf_bp);
 int xfs_has_attr(struct xfs_da_args *args);
 int xfs_attr_remove_args(struct xfs_da_args *args);
 int xfs_attr_remove_iter(struct xfs_delattr_context *dac);
-int xfs_attr_defer_finish(struct xfs_delattr_context *dac);
 bool xfs_attr_namecheck(const void *name, size_t length);
 void xfs_delattr_context_init(struct xfs_delattr_context *dac,
 			      struct xfs_da_args *args);
fs/xfs/libxfs/xfs_attr_remote.c +66 -44
index f2d46c7..7a342f1 100644
@@ -443,7 +443,7 @@ xfs_attr_rmtval_get(
  * Find a "hole" in the attribute address space large enough for us to drop the
  * new attribute's value into
  */
-STATIC int
+int
 xfs_attr_rmt_find_hole(
 	struct xfs_da_args	*args)
 {
@@ -470,7 +470,7 @@ xfs_attr_rmt_find_hole(
 	return 0;
 }
 
-STATIC int
+int
 xfs_attr_rmtval_set_value(
 	struct xfs_da_args	*args)
 {
@@ -630,6 +630,70 @@ xfs_attr_rmtval_set(
 }
 
 /*
+ * Find a hole for the attr and store it in the delayed attr context.  This
+ * initializes the context to roll through allocating an attr extent for a
+ * delayed attr operation
+ */
+int
+xfs_attr_rmtval_set_init(
+	struct xfs_delattr_context	*dac)
+{
+	struct xfs_da_args		*args = dac->da_args;
+	struct xfs_bmbt_irec		*map = &dac->map;
+	int error;
+
+	dac->lblkno = 0;
+	dac->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;
+
+	dac->blkcnt = args->rmtblkcnt;
+	dac->lblkno = args->rmtblkno;
+
+	return error;
+}
+
+/*
+ * Write one block of the value associated with an attribute into the
+ * out-of-line buffer that we have defined for it. This is similar to a subset
+ * of xfs_attr_rmtval_set, but records the current block to the delayed attr
+ * context, and leaves transaction handling to the caller.
+ */
+int
+xfs_attr_rmtval_set_blk(
+	struct xfs_delattr_context	*dac)
+{
+	struct xfs_da_args		*args = dac->da_args;
+	struct xfs_inode		*dp = args->dp;
+	struct xfs_bmbt_irec		*map = &dac->map;
+	int nmap;
+	int error;
+
+	nmap = 1;
+	error = xfs_bmapi_write(args->trans, dp,
+		  (xfs_fileoff_t)dac->lblkno,
+		  dac->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 */
+	dac->lblkno += map->br_blockcount;
+	dac->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.
  */
@@ -671,48 +735,6 @@ xfs_attr_rmtval_invalidate(
 }
 
 /*
- * 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)
-{
-	struct xfs_delattr_context	dac;
-	xfs_dablk_t			lblkno;
-	int				blkcnt;
-	int				error = 0;
-	int				retval = 0;
-
-	trace_xfs_attr_rmtval_remove(args);
-	xfs_delattr_context_init(&dac, args);
-
-	/*
-	 * Keep de-allocating extents until the remote-value region is gone.
-	 */
-	lblkno = args->rmtblkno;
-	blkcnt = args->rmtblkcnt;
-	do {
-		retval = __xfs_attr_rmtval_remove(&dac);
-		if (retval && retval != EAGAIN)
-			return retval;
-
-		error = xfs_attr_defer_finish(&dac);
-		if (error)
-			break;
-
-		/*
-		 * Close out trans and start the next one in the chain.
-		 */
-		error = xfs_trans_roll_inode(&args->trans, args->dp);
-		if (error)
-			return error;
-	} while (retval == -EAGAIN);
-
-	return 0;
-}
-
-/*
  * Remove the value associated with an attribute by deleting the out-of-line
  * buffer that it is stored on. Returns EAGAIN for the caller to refresh the
  * transaction and recall the function
fs/xfs/libxfs/xfs_attr_remote.h +4 -0
index 351da00..51a1c91 100644
@@ -15,4 +15,8 @@ int xfs_attr_rmtval_stale(struct xfs_inode *ip, struct xfs_bmbt_irec *map,
 		xfs_buf_flags_t incore_flags);
 int xfs_attr_rmtval_invalidate(struct xfs_da_args *args);
 int __xfs_attr_rmtval_remove(struct xfs_delattr_context *dac);
+int xfs_attr_rmt_find_hole(struct xfs_da_args *args);
+int xfs_attr_rmtval_set_value(struct xfs_da_args *args);
+int xfs_attr_rmtval_set_blk(struct xfs_delattr_context *dac);
+int xfs_attr_rmtval_set_init(struct xfs_delattr_context *dac);
 #endif /* __XFS_ATTR_REMOTE_H__ */
fs/xfs/xfs_trace.h +0 -1
index a4323a6..26dc8bf 100644
@@ -1784,7 +1784,6 @@ DEFINE_ATTR_EVENT(xfs_attr_refillstate);
 
 DEFINE_ATTR_EVENT(xfs_attr_rmtval_get);
 DEFINE_ATTR_EVENT(xfs_attr_rmtval_set);
-DEFINE_ATTR_EVENT(xfs_attr_rmtval_remove);
 
 #define DEFINE_DA_EVENT(name) \
 DEFINE_EVENT(xfs_da_class, name, \
Signature · 1 line
2.7.4