xfs: Delay Ready Attributes
v17 cover xfs: Delay Ready Attributes
Hi all,
This set is a subset of a larger series for Dealyed Attributes. Which is a subset of a yet larger series for parent pointers. Delayed attributes allow attribute operations (set and remove) to be logged and committed in the same way that other delayed operations do. This 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 a delayed operation. 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 delayed attribute portion. We will introduce parent pointers in a later set.
The set as a whole is a bit much to digest at once, so I usually send out the smaller sub series to reduce reviewer burn out. But the entire extended series is visible through the included github links.
Updates since v16: Mostly just review feed back from the previous revision. I've tracked changes below to help reviews recall the changes discussed
xfs: Reverse apply 72b97ea40d
No change
xfs: Add xfs_attr_node_remove_cleanup
No change
xfs: Hoist xfs_attr_set_shortform
No change
xfs: Add helper xfs_attr_set_fmt
No change
xfs: Separate xfs_attr_node_addname and xfs_attr_node_addname_work
No change
xfs: Add helper xfs_attr_node_addname_find_attr
No change
xfs: Hoist xfs_attr_node_addname
Moved the xfs_da_state_free in xfs_attr_set_args into xfs_attr_node_addname to fix memleak
xfs: Hoist xfs_attr_leaf_addname
Removed trace_xfs_attr_leaf_addname from trace.h
xfs: Hoist node transaction handling
No change
xfs: Add delay ready attr remove routines
Comment for xfs_attr_trans_roll updated
Return error from xfs_attr_node_removename_setup call Changed breaks to gotos in xfs_attr_remove_iter Moved xfs_attr_node_removename_setup into the uninit state Added extra state XFS_DAS_CLNUP
Diagram updated
xfs: Add delay ready attr set routines
Added a xfs_trans_brelse in xfs_attr_set_args when xfs_attr_trans_roll fails Fixed misc nits with if/else bracket consistency
Move XFS_DAS_FOUND_LBLK state assignment in to leaf scope
Add extra -EAGAIN after calls to __xfs_at__xfs_attr_rmtval_remove Added extra state XFS_DAS_RD_LEAF and XFS_DAS_CLR_FLAG
Diagram updated
This series can be viewed on github here:
https://github.com/allisonhenderson/xfs_work/tree/delay_ready_attrs_v17
As well as the extended delayed attribute and parent pointer series:
https://github.com/allisonhenderson/xfs_work/tree/delay_ready_attrs_v17_extended
And the test cases:
https://github.com/allisonhenderson/xfs_work/tree/pptr_xfstestsv2
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_v17
https://github.com/allisonhenderson/xfs_work/tree/delay_ready_attrs_xfsprogs_v17_extended
To run the xfs attributes tests run:
check -g attr
To run as delayed attributes run:
export MOUNT_OPTIONS="-o 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 Henderson (11):
xfs: Reverse apply 72b97ea40d
xfs: Add xfs_attr_node_remove_cleanup
xfs: Hoist xfs_attr_set_shortform
xfs: Add helper xfs_attr_set_fmt
xfs: Separate xfs_attr_node_addname and
xfs_attr_node_addname_clear_incomplete
xfs: Add helper xfs_attr_node_addname_find_attr
xfs: Hoist xfs_attr_node_addname
xfs: Hoist xfs_attr_leaf_addname
xfs: Hoist node transaction handling
xfs: Add delay ready attr remove routines
xfs: Add delay ready attr set routines
fs/xfs/libxfs/xfs_attr.c | 908 ++++++++++++++++++++++++---------------- fs/xfs/libxfs/xfs_attr.h | 401 ++++++++++++++++++ fs/xfs/libxfs/xfs_attr_leaf.c | 2 +- fs/xfs/libxfs/xfs_attr_remote.c | 126 ++++-- fs/xfs/libxfs/xfs_attr_remote.h | 7 +- fs/xfs/xfs_attr_inactive.c | 2 +- fs/xfs/xfs_trace.h | 2 - 7 files changed, 1038 insertions(+), 410 deletions(-)
Signature · 1 line
2.7.4
PATCH v17 1/11 xfs: Reverse apply 72b97ea40d
Originally we added this patch to help modularize the attr code in preparation for delayed attributes and the state machine it requires. However, later reviews found that this slightly alters the transaction handling as the helper function is ambiguous as to whether the transaction is diry or clean. This may cause a dirty transaction to be included in the next roll, where previously it had not. To preserve the existing code flow, we reverse apply this commit.
--- fs/xfs/libxfs/xfs_attr.c | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-)
fs/xfs/libxfs/xfs_attr.c +9 -19
@@ -1203,24 +1203,6 @@ int xfs_attr_node_removename_setup(return 0 ; } -STATIC int -xfs_attr_node_remove_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. *
@@ -1249,7 +1231,15 @@ xfs_attr_node_removename(* overflow the maximum size of a transaction and/or hit a deadlock. */ if (args->rmtblkno >0 ) { - error =xfs_attr_node_remove_rmt (args, state); + 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);if (error) goto out; }
Signature · 1 line
2.7.4
PATCH v17 2/11 xfs: Add xfs_attr_node_remove_cleanup
In reply to Allison HendersonThis patch pulls a new helper function xfs_attr_node_remove_cleanup out of xfs_attr_node_remove_step. This helps to modularize xfs_attr_node_remove_step which will help make the delayed attribute code easier to follow
--- fs/xfs/libxfs/xfs_attr.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-)
fs/xfs/libxfs/xfs_attr.c +20 -9
@@ -1203,6 +1203,25 @@ int xfs_attr_node_removename_setup(return 0 ; } +STATIC int +xfs_attr_node_remove_cleanup ( +struct xfs_da_args *args, +struct xfs_da_state *state) +{ +struct xfs_da_state_blk *blk; +int retval; + +/* +* 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 ); + retval =xfs_attr3_leaf_remove (blk->bp, args); +xfs_da3_fixhashpath (state, &state->path); + +return retval; +} +/* * Remove a name from a B-tree attribute list. *
@@ -1215,7 +1234,6 @@ xfs_attr_node_removename( struct xfs_da_args *args) {struct xfs_da_state *state; -struct xfs_da_state_blk *blk;int retval, error;struct xfs_inode *dp = args->dp;
@@ -1243,14 +1261,7 @@ xfs_attr_node_removename(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 ); - retval =xfs_attr3_leaf_remove (blk->bp, args); -xfs_da3_fixhashpath (state, &state->path); + retval =xfs_attr_node_remove_cleanup (args, state);/* * Check to see if the tree needs to be collapsed.
Signature · 1 line
2.7.4
PATCH v17 3/11 xfs: Hoist xfs_attr_set_shortform
In reply to Allison HendersonThis patch hoists xfs_attr_set_shortform into the calling function. This will help keep all state management code in the same scope.
--- fs/xfs/libxfs/xfs_attr.c | 81 ++++++++++++++++-------------------------------- 1 file changed, 27 insertions(+), 54 deletions(-)
fs/xfs/libxfs/xfs_attr.c +27 -54
@@ -217,53 +217,6 @@ 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. -*/ -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
@@ -272,7 +225,7 @@ xfs_attr_set_args( {struct xfs_inode *dp = args->dp;struct xfs_buf *leaf_bp =NULL ; -int error =0 ; +int error2, error =0 ;/* * If the attribute list is already in leaf format, jump straight to
@@ -281,16 +234,36 @@ xfs_attr_set_args(* again. */ if (xfs_attr_is_shortform (dp)) { +/* +* 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;/* -* 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. +* 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. */ - error =xfs_attr_set_shortform (args, &leaf_bp); -if (error || !args->trans) +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; + } }if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) {
Signature · 1 line
2.7.4
PATCH v17 4/11 xfs: Add helper xfs_attr_set_fmt
In reply to Allison HendersonThis patch adds a helper function xfs_attr_set_fmt. This will help isolate the code that will require state management from the portions that do not. xfs_attr_set_fmt returns 0 when the attr has been set and no further action is needed. It returns -EAGAIN when shortform has been transformed to leaf, and the calling function should proceed the set the attr in leaf form.
--- fs/xfs/libxfs/xfs_attr.c | 79 ++++++++++++++++++++++++++++-------------------- 1 file changed, 46 insertions(+), 33 deletions(-)
fs/xfs/libxfs/xfs_attr.c +46 -33
@@ -216,6 +216,48 @@ xfs_attr_is_shortform( ip->i_afp->if_nextents == 0); } +STATIC int +xfs_attr_set_fmt ( +struct xfs_da_args *args) +{ +struct xfs_buf *leaf_bp =NULL ; +struct xfs_inode *dp = args->dp; +int error2, error =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. +*/ +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 -EAGAIN ; +} +/* * Set the attribute specified in @args. */
@@ -224,8 +266,7 @@ xfs_attr_set_args( struct xfs_da_args *args) {struct xfs_inode *dp = args->dp; -struct xfs_buf *leaf_bp =NULL ; -int error2, error =0 ; +int error;/* * If the attribute list is already in leaf format, jump straight to
@@ -234,36 +275,9 @@ xfs_attr_set_args(* again. */ if (xfs_attr_is_shortform (dp)) { -/* -* 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. -*/ -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_fmt (args); +if (error != -EAGAIN )return error; - } }if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) {
@@ -297,8 +311,7 @@ xfs_attr_set_args(return error; } - error =xfs_attr_node_addname (args); -return error; +return xfs_attr_node_addname (args); }/*
Signature · 1 line
2.7.4
PATCH v17 5/11 xfs: Separate xfs_attr_node_addname and xfs_attr_node_addname_clear_incomplete
In reply to Allison HendersonThis patch separate xfs_attr_node_addname into two functions. This will help to make it easier to hoist parts of xfs_attr_node_addname that need state management
--- fs/xfs/libxfs/xfs_attr.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
fs/xfs/libxfs/xfs_attr.c +20 -0
@@ -54,6 +54,7 @@ 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_addname_clear_incomplete(struct xfs_da_args *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);
@@ -1062,6 +1063,25 @@ xfs_attr_node_addname(return error; } + error =xfs_attr_node_addname_clear_incomplete (args); +out: +if (state) +xfs_da_state_free (state); +if (error) +return error; +return retval; +} + + +STATIC +int xfs_attr_node_addname_clear_incomplete( +struct xfs_da_args *args) +{ +struct xfs_da_state *state =NULL ; +struct xfs_da_state_blk *blk; +int retval =0 ; +int error =0 ; +/* * 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.
Signature · 1 line
2.7.4
Re: [PATCH v17 05/11] xfs: Separate xfs_attr_node_addname and xfs_attr_node_addname_clear_incomplete
Quoted 23 lines · Allison Henderson
This patch separate
xfs_attr_node_addnameinto two functions. This will help to make it easier to hoist parts ofxfs_attr_node_addnamethat need state managementSigned-off-by Allison Henderson <[email protected]>Reviewed-by Brian Foster <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)fs/xfs/libxfs/xfs_attr.c +1
-0@@ -54,6 +54,7 @@ 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_addname_clear_incomplete(struct xfs_da_args *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);
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_addname( · line 1072
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +7
-0@@ -1062,6 +1063,25 @@ xfs_attr_node_addname(return error; } + error =xfs_attr_node_addname_clear_incomplete (args); +out: +if (state) +xfs_da_state_free (state); +if (error) +return error; +return retval;
I think the above code incorrectly returns -ENOSPC when the user is performing an xattr rename operation and the call to xfs_attr3_leaf_add() resulted in returning -ENOSPC,
1. xfs_attr3_leaf_add() returns -ENOSPC.
2. xfs_da3_split() allocates a new leaf and inserts the new xattr into it.
3. If the user was performing a rename operation (i.e. XFS_DA_OP_RENAME is set), we flip the "incomplete" flag.
4. Remove the old xattr's remote blocks (if any).
5. Remove old xattr's name.
6. If "error" has zero as its value, we return the value of "retval". At this point in execution, "retval" would have -ENOSPC as its value.
--
chandan
Re: [PATCH v17 05/11] xfs: Separate xfs_attr_node_addname and xfs_attr_node_addname_clear_incomplete
Quoted 27 lines · Chandan Babu R
Quoted 26 lines · Allison Henderson
This patch separate
xfs_attr_node_addnameinto two functions. This will help to make it easier to hoist parts ofxfs_attr_node_addnamethat need state managementSigned-off-by Allison Henderson <[email protected]>Reviewed-by Brian Foster <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)fs/xfs/libxfs/xfs_attr.c +1
-0@@ -54,6 +54,7 @@ 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_addname_clear_incomplete(struct xfs_da_args *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);@@ -1062,6 +1063,25 @@ xfs_attr_node_addname(return error; }
Quoted 1 line
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_addname( · line 1066
Quoted 1 line
fs/xfs/libxfs/xfs_attr.c +1
-0+ error =xfs_attr_node_addname_clear_incomplete (args);
Ok, so i think what we need here is an extra few lines below. That's similar to the original exit handling
if (error) goto out; retval = error = 0;
Looks good?
Quoted 19 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_addname( · line 1072
Quoted 6 lines
fs/xfs/libxfs/xfs_attr.c +6
-0+out: +if (state) +xfs_da_state_free (state); +if (error) +return error; +return retval;I think the above code incorrectly returns
-ENOSPCwhen the user is performing an xattr rename operation and the call toxfs_attr3_leaf_add()resulted in returning-ENOSPC,
1.xfs_attr3_leaf_add()returns-ENOSPC.
2.xfs_da3_split()allocates a new leaf and inserts the new xattr into it.
3. If the user was performing a rename operation (i.e.XFS_DA_OP_RENAMEis set), we flip the "incomplete" flag.
4. Remove the old xattr's remote blocks (if any).
5. Remove old xattr's name.
6. If "error" has zero as its value, we return the value of "retval". At this point in execution, "retval" would have-ENOSPCas its value.
Quoted 2 lines
--
chandan
Thanks for the catch!
Allison
Quoted 1 line
Re: [PATCH v17 05/11] xfs: Separate xfs_attr_node_addname and xfs_attr_node_addname_clear_incomplete
Quoted 28 lines · Allison Henderson
Quoted 27 lines · Chandan Babu R
Quoted 26 lines · Allison Henderson
This patch separate
xfs_attr_node_addnameinto two functions. This will help to make it easier to hoist parts ofxfs_attr_node_addnamethat need state managementSigned-off-by Allison Henderson <[email protected]>Reviewed-by Brian Foster <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)fs/xfs/libxfs/xfs_attr.c +1
-0@@ -54,6 +54,7 @@ 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_addname_clear_incomplete(struct xfs_da_args *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);@@ -1062,6 +1063,25 @@ xfs_attr_node_addname(return error; }
Quoted 7 lines
Quoted 1 line
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_addname( · line 1066
Quoted 1 line
fs/xfs/libxfs/xfs_attr.c +1
-0+ error =xfs_attr_node_addname_clear_incomplete (args);Ok, so i think what we need here is an extra few lines below. That's similar to the original exit handling
if (error) goto out; retval = error = 0;
"retval = 0;" should suffice.
Quoted 24 lines
Looks good?
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_addname( · line 1072
Quoted 6 lines
fs/xfs/libxfs/xfs_attr.c +6
-0+out: +if (state) +xfs_da_state_free (state); +if (error) +return error; +return retval;I think the above code incorrectly returns
-ENOSPCwhen the user is performing an xattr rename operation and the call toxfs_attr3_leaf_add()resulted in returning-ENOSPC,Quoted 9 lines
1.
xfs_attr3_leaf_add()returns-ENOSPC.
2.xfs_da3_split()allocates a new leaf and inserts the new xattr into it.
3. If the user was performing a rename operation (i.e.XFS_DA_OP_RENAMEis set), we flip the "incomplete" flag.
4. Remove the old xattr's remote blocks (if any).
5. Remove old xattr's name.
6. If "error" has zero as its value, we return the value of "retval". At this point in execution, "retval" would have-ENOSPCas its value.Thanks for the catch!
Allison
Signature · 1 line
chandan
Re: [PATCH v17 05/11] xfs: Separate xfs_attr_node_addname and xfs_attr_node_addname_clear_incomplete
Quoted 33 lines · Chandan Babu R
Quoted 32 lines · Allison Henderson
Quoted 27 lines · Chandan Babu R
Quoted 26 lines · Allison Henderson
This patch separate
xfs_attr_node_addnameinto two functions. This will help to make it easier to hoist parts ofxfs_attr_node_addnamethat need state managementSigned-off-by Allison Henderson <[email protected]>Reviewed-by Brian Foster <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)fs/xfs/libxfs/xfs_attr.c +1
-0@@ -54,6 +54,7 @@ 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_addname_clear_incomplete(struct xfs_da_args *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);@@ -1062,6 +1063,25 @@ xfs_attr_node_addname(return error; }Quoted 1 line
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_addname( · line 1066
Quoted 1 line
fs/xfs/libxfs/xfs_attr.c +1
-0+ error =xfs_attr_node_addname_clear_incomplete (args);Ok, so i think what we need here is an extra few lines below. That's similar to the original exit handling
Quoted 5 lines
Quoted 3 lines
if (error) goto out; retval = error = 0;"retval = 0;" should suffice.
Ok, will that add in. Thanks!
Allison
Quoted 26 lines
Quoted 25 lines
Looks good?
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_addname( · line 1072
Quoted 6 lines
fs/xfs/libxfs/xfs_attr.c +6
-0+out: +if (state) +xfs_da_state_free (state); +if (error) +return error; +return retval;I think the above code incorrectly returns
-ENOSPCwhen the user is performing an xattr rename operation and the call toxfs_attr3_leaf_add()resulted in returning-ENOSPC,Quoted 9 lines
1.
xfs_attr3_leaf_add()returns-ENOSPC.
2.xfs_da3_split()allocates a new leaf and inserts the new xattr into it.
3. If the user was performing a rename operation (i.e.XFS_DA_OP_RENAMEis set), we flip the "incomplete" flag.
4. Remove the old xattr's remote blocks (if any).
5. Remove old xattr's name.
6. If "error" has zero as its value, we return the value of "retval". At this point in execution, "retval" would have-ENOSPCas its value.Thanks for the catch!
Allison
PATCH v17 6/11 xfs: Add helper xfs_attr_node_addname_find_attr
In reply to Allison HendersonThis patch separates the first half of xfs_attr_node_addname into a helper function xfs_attr_node_addname_find_attr. It also replaces the restart goto with an EAGAIN return code driven by a loop in the calling function. This looks odd now, but will clean up nicly once we introduce the state machine. It will also enable hoisting the last state out of xfs_attr_node_addname with out having to plumb in a "done" parameter to know if we need to move to the next state or not.
--- fs/xfs/libxfs/xfs_attr.c | 87 ++++++++++++++++++++++++++++++------------------ 1 file changed, 54 insertions(+), 33 deletions(-)
fs/xfs/libxfs/xfs_attr.c +54 -33
@@ -52,7 +52,10 @@ 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_da_args *args, +struct xfs_da_state *state); +STATIC int xfs_attr_node_addname_find_attr(struct xfs_da_args *args, +struct xfs_da_state **state); STATIC int xfs_attr_node_removename(xfs_da_args_t *args); STATIC int xfs_attr_node_addname_clear_incomplete(struct xfs_da_args *args); STATIC int xfs_attr_node_hasname(xfs_da_args_t *args,
@@ -267,6 +270,7 @@ xfs_attr_set_args( struct xfs_da_args *args) {struct xfs_inode *dp = args->dp; +struct xfs_da_state *state;int error;/*
@@ -312,7 +316,14 @@ xfs_attr_set_args(return error; } -return xfs_attr_node_addname (args); +do { + error =xfs_attr_node_addname_find_attr (args, &state); +if (error) +return error; + error =xfs_attr_node_addname (args, state); + }while (error == -EAGAIN ); + +return error; }/*
@@ -885,48 +896,26 @@ xfs_attr_node_hasname(* External routines when attribute list size > geo->blksize *========================================================================*/ -/* -* Add a name to a Btree-format attribute list. -* -* This will involve walking down the Btree, and may involve splitting -* leaf nodes and even splitting intermediate nodes up to and including -* the root node (a special case of an intermediate node). -* -* "Remote" attribute values confuse the issue and atomic rename operations -* add a whole extra layer of confusion on top of that. -*/ STATIC int -xfs_attr_node_addname ( -struct xfs_da_args *args) +xfs_attr_node_addname_find_attr ( +struct xfs_da_args *args, +struct xfs_da_state **state) { -struct xfs_da_state *state; -struct xfs_da_state_blk *blk; -struct xfs_inode *dp; -int retval, error; - -trace_xfs_attr_node_addname (args); +int retval;/* -* Fill in bucket of arguments/results/context to carry around. -*/ - dp = args->dp; -restart: -/* * Search to see if name already exists, and get back a pointer * to where it should go. */ - error =0 ; - retval =xfs_attr_node_hasname (args, &state); + retval =xfs_attr_node_hasname (args, state);if (retval != -ENOATTR && retval != -EEXIST ) - goto out; + goto error; - blk = &state->path.blk[ state->path.active-1 ]; -ASSERT (blk->magic ==XFS_ATTR_LEAF_MAGIC );if (retval == -ENOATTR && (args->attr_flags &XATTR_REPLACE )) - goto out; + goto error;if (retval == -EEXIST ) {if (args->attr_flags &XATTR_CREATE ) - goto out; + goto error;trace_xfs_attr_node_replace (args);
@@ -944,6 +933,38 @@ xfs_attr_node_addname( args->rmtvaluelen =0 ; } +return 0 ; +error: +if (*state) +xfs_da_state_free (*state); +return retval; +} + +/* +* Add a name to a Btree-format attribute list. +* +* This will involve walking down the Btree, and may involve splitting +* leaf nodes and even splitting intermediate nodes up to and including +* the root node (a special case of an intermediate node). +* +* "Remote" attribute values confuse the issue and atomic rename operations +* add a whole extra layer of confusion on top of that. +*/ +STATIC int +xfs_attr_node_addname ( +struct xfs_da_args *args, +struct xfs_da_state *state) +{ +struct xfs_da_state_blk *blk; +struct xfs_inode *dp; +int retval, error; + +trace_xfs_attr_node_addname (args); + + dp = args->dp; + blk = &state->path.blk[state->path.active-1 ]; +ASSERT (blk->magic ==XFS_ATTR_LEAF_MAGIC ); + retval =xfs_attr3_leaf_add (blk->bp, state->args);if (retval == -ENOSPC ) {if (state->path.active ==1 ) {
@@ -969,7 +990,7 @@ xfs_attr_node_addname(if (error) goto out; - goto restart; +return -EAGAIN ; }/*
Signature · 1 line
2.7.4
PATCH v17 7/11 xfs: Hoist xfs_attr_node_addname
In reply to Allison HendersonThis patch hoists the later half of xfs_attr_node_addname into the calling function. We do this because it is this area that will need the most state management, and we want to keep such code in the same scope as much as possible
--- fs/xfs/libxfs/xfs_attr.c | 157 +++++++++++++++++++++++------------------------ 1 file changed, 76 insertions(+), 81 deletions(-)
fs/xfs/libxfs/xfs_attr.c +76 -81
@@ -52,6 +52,7 @@ 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 void xfs_attr_restore_rmt_blk(struct xfs_da_args *args); STATIC int xfs_attr_node_addname(struct xfs_da_args *args,struct xfs_da_state *state); STATIC int xfs_attr_node_addname_find_attr(struct xfs_da_args *args,
@@ -270,8 +271,8 @@ xfs_attr_set_args( struct xfs_da_args *args) {struct xfs_inode *dp = args->dp; -struct xfs_da_state *state; -int error; +struct xfs_da_state *state =NULL ; +int error =0 ;/* * If the attribute list is already in leaf format, jump straight to
@@ -322,8 +323,77 @@ xfs_attr_set_args(return error; error =xfs_attr_node_addname (args, state); }while (error == -EAGAIN ); +if (error) +return error; + +/* +* 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; + +/* +* If there was an out-of-line value, allocate the blocks we +* identified for its storage and copy the value. This is done +* after we create the attribute so that we don't overflow the +* maximum size of a transaction and/or hit a deadlock. +*/ +if (args->rmtblkno >0 ) { + error =xfs_attr_rmtval_set (args); +if (error) +return error; + } + +if (!(args->op_flags &XFS_DA_OP_RENAME )) { +/* +* Added a "remote" value, just clear the incomplete flag. +*/ +if (args->rmtblkno >0 ) + error =xfs_attr3_leaf_clearflag (args); + goto out; + } + +/* +* 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; + +/* +* 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; + + error =xfs_attr_rmtval_remove (args); +if (error) +return error; + } + error =xfs_attr_node_addname_clear_incomplete (args); +out:return error; + }/*
@@ -957,7 +1027,7 @@ xfs_attr_node_addname( {struct xfs_da_state_blk *blk;struct xfs_inode *dp; -int retval, error; +int error;trace_xfs_attr_node_addname (args);
@@ -965,8 +1035,8 @@ xfs_attr_node_addname( blk = &state->path.blk[state->path.active-1 ];ASSERT (blk->magic ==XFS_ATTR_LEAF_MAGIC ); - retval =xfs_attr3_leaf_add (blk->bp, state->args); -if (retval == -ENOSPC ) { + error =xfs_attr3_leaf_add (blk->bp, state->args); +if (error == -ENOSPC ) {if (state->path.active ==1 ) {/* * Its really a single leaf node, but it had
@@ -1012,85 +1082,10 @@ xfs_attr_node_addname(xfs_da3_fixhashpath (state, &state->path); } -/* -* Kill the state structure, we're done with it and need to -* allow the buffers to come back later. -*/ -xfs_da_state_free (state); - state =NULL ; - -/* -* 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; - -/* -* If there was an out-of-line value, allocate the blocks we -* identified for its storage and copy the value. This is done -* after we create the attribute so that we don't overflow the -* maximum size of a transaction and/or hit a deadlock. -*/ -if (args->rmtblkno >0 ) { - error =xfs_attr_rmtval_set (args); -if (error) -return error; - } - -if (!(args->op_flags &XFS_DA_OP_RENAME )) { -/* -* Added a "remote" value, just clear the incomplete flag. -*/ -if (args->rmtblkno >0 ) - error =xfs_attr3_leaf_clearflag (args); - retval = error; - goto out; - } - -/* -* 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; - -/* -* 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; - - error =xfs_attr_rmtval_remove (args); -if (error) -return error; - } - - error =xfs_attr_node_addname_clear_incomplete (args); out:if (state)xfs_da_state_free (state); -if (error) -return error; -return retval; +return error; }
Signature · 1 line
2.7.4
Re: [PATCH v17 07/11] xfs: Hoist xfs_attr_node_addname
Quoted 5 lines · Allison Henderson
This patch hoists the later half of
xfs_attr_node_addnameinto the calling function. We do this because it is this area that will need the most state management, and we want to keep such code in the same scope as much as possible
The changes look good to me.
Quoted 213 lines
Signed-off-by Allison Henderson <[email protected]>Reviewed-by Brian Foster <[email protected]>Reviewed-by Darrick J. Wong <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 157 +++++++++++++++++++++++------------------------ 1 file changed, 76 insertions(+), 81 deletions(-)fs/xfs/libxfs/xfs_attr.c +76
-81@@ -52,6 +52,7 @@ 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 void xfs_attr_restore_rmt_blk(struct xfs_da_args *args); STATIC int xfs_attr_node_addname(struct xfs_da_args *args,struct xfs_da_state *state); STATIC int xfs_attr_node_addname_find_attr(struct xfs_da_args *args,@@ -270,8 +271,8 @@ xfs_attr_set_args( struct xfs_da_args *args) {struct xfs_inode *dp = args->dp; -struct xfs_da_state *state; -int error; +struct xfs_da_state *state =NULL ; +int error =0 ;/* * If the attribute list is already in leaf format, jump straight to @@ -322,8 +323,77 @@ xfs_attr_set_args(return error; error =xfs_attr_node_addname (args, state); }while (error == -EAGAIN ); +if (error) +return error; + +/* +* 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; + +/* +* If there was an out-of-line value, allocate the blocks we +* identified for its storage and copy the value. This is done +* after we create the attribute so that we don't overflow the +* maximum size of a transaction and/or hit a deadlock. +*/ +if (args->rmtblkno >0 ) { + error =xfs_attr_rmtval_set (args); +if (error) +return error; + } + +if (!(args->op_flags &XFS_DA_OP_RENAME )) { +/* +* Added a "remote" value, just clear the incomplete flag. +*/ +if (args->rmtblkno >0 ) + error =xfs_attr3_leaf_clearflag (args); + goto out; + } + +/* +* 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; + +/* +* 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; + + error =xfs_attr_rmtval_remove (args); +if (error) +return error; + } + error =xfs_attr_node_addname_clear_incomplete (args); +out:return error; + }/* @@ -957,7 +1027,7 @@ xfs_attr_node_addname( {struct xfs_da_state_blk *blk;struct xfs_inode *dp; -int retval, error; +int error;trace_xfs_attr_node_addname (args);@@ -965,8 +1035,8 @@ xfs_attr_node_addname( blk = &state->path.blk[state->path.active-1 ];ASSERT (blk->magic ==XFS_ATTR_LEAF_MAGIC ); - retval =xfs_attr3_leaf_add (blk->bp, state->args); -if (retval == -ENOSPC ) { + error =xfs_attr3_leaf_add (blk->bp, state->args); +if (error == -ENOSPC ) {if (state->path.active ==1 ) {/* * Its really a single leaf node, but it had @@ -1012,85 +1082,10 @@ xfs_attr_node_addname(xfs_da3_fixhashpath (state, &state->path); } -/* -* Kill the state structure, we're done with it and need to -* allow the buffers to come back later. -*/ -xfs_da_state_free (state); - state =NULL ; - -/* -* 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; - -/* -* If there was an out-of-line value, allocate the blocks we -* identified for its storage and copy the value. This is done -* after we create the attribute so that we don't overflow the -* maximum size of a transaction and/or hit a deadlock. -*/ -if (args->rmtblkno >0 ) { - error =xfs_attr_rmtval_set (args); -if (error) -return error; - } - -if (!(args->op_flags &XFS_DA_OP_RENAME )) { -/* -* Added a "remote" value, just clear the incomplete flag. -*/ -if (args->rmtblkno >0 ) - error =xfs_attr3_leaf_clearflag (args); - retval = error; - goto out; - } - -/* -* 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; - -/* -* 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; - - error =xfs_attr_rmtval_remove (args); -if (error) -return error; - } - - error =xfs_attr_node_addname_clear_incomplete (args); out:if (state)xfs_da_state_free (state); -if (error) -return error; -return retval; +return error; }
Signature · 1 line
chandan
Re: [PATCH v17 07/11] xfs: Hoist xfs_attr_node_addname
Quoted 10 lines · Chandan Babu R
Quoted 5 lines · Allison Henderson
This patch hoists the later half of
xfs_attr_node_addnameinto the calling function. We do this because it is this area that will need the most state management, and we want to keep such code in the same scope as much as possibleThe changes look good to me.
Reviewed-by Chandan Babu R <[email protected]>
Thank you!!
Allison
Quoted 216 lines
Quoted 214 lines
Signed-off-by Allison Henderson <[email protected]>Reviewed-by Brian Foster <[email protected]>Reviewed-by Darrick J. Wong <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 157 +++++++++++++++++++++++------------------------ 1 file changed, 76 insertions(+), 81 deletions(-)fs/xfs/libxfs/xfs_attr.c +76
-81@@ -52,6 +52,7 @@ 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 void xfs_attr_restore_rmt_blk(struct xfs_da_args *args); STATIC int xfs_attr_node_addname(struct xfs_da_args *args,struct xfs_da_state *state); STATIC int xfs_attr_node_addname_find_attr(struct xfs_da_args *args,@@ -270,8 +271,8 @@ xfs_attr_set_args( struct xfs_da_args *args) {struct xfs_inode *dp = args->dp; -struct xfs_da_state *state; -int error; +struct xfs_da_state *state =NULL ; +int error =0 ;/* * If the attribute list is already in leaf format, jump straight to @@ -322,8 +323,77 @@ xfs_attr_set_args(return error; error =xfs_attr_node_addname (args, state); }while (error == -EAGAIN ); +if (error) +return error; + +/* +* 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; + +/* +* If there was an out-of-line value, allocate the blocks we +* identified for its storage and copy the value. This is done +* after we create the attribute so that we don't overflow the +* maximum size of a transaction and/or hit a deadlock. +*/ +if (args->rmtblkno >0 ) { + error =xfs_attr_rmtval_set (args); +if (error) +return error; + } + +if (!(args->op_flags &XFS_DA_OP_RENAME )) { +/* +* Added a "remote" value, just clear the incomplete flag. +*/ +if (args->rmtblkno >0 ) + error =xfs_attr3_leaf_clearflag (args); + goto out; + } + +/* +* 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; + +/* +* 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; + + error =xfs_attr_rmtval_remove (args); +if (error) +return error; + } + error =xfs_attr_node_addname_clear_incomplete (args); +out:return error; + }/* @@ -957,7 +1027,7 @@ xfs_attr_node_addname( {struct xfs_da_state_blk *blk;struct xfs_inode *dp; -int retval, error; +int error;trace_xfs_attr_node_addname (args);@@ -965,8 +1035,8 @@ xfs_attr_node_addname( blk = &state->path.blk[state->path.active-1 ];ASSERT (blk->magic ==XFS_ATTR_LEAF_MAGIC ); - retval =xfs_attr3_leaf_add (blk->bp, state->args); -if (retval == -ENOSPC ) { + error =xfs_attr3_leaf_add (blk->bp, state->args); +if (error == -ENOSPC ) {if (state->path.active ==1 ) {/* * Its really a single leaf node, but it had @@ -1012,85 +1082,10 @@ xfs_attr_node_addname(xfs_da3_fixhashpath (state, &state->path); } -/* -* Kill the state structure, we're done with it and need to -* allow the buffers to come back later. -*/ -xfs_da_state_free (state); - state =NULL ; - -/* -* 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; - -/* -* If there was an out-of-line value, allocate the blocks we -* identified for its storage and copy the value. This is done -* after we create the attribute so that we don't overflow the -* maximum size of a transaction and/or hit a deadlock. -*/ -if (args->rmtblkno >0 ) { - error =xfs_attr_rmtval_set (args); -if (error) -return error; - } - -if (!(args->op_flags &XFS_DA_OP_RENAME )) { -/* -* Added a "remote" value, just clear the incomplete flag. -*/ -if (args->rmtblkno >0 ) - error =xfs_attr3_leaf_clearflag (args); - retval = error; - goto out; - } - -/* -* 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; - -/* -* 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; - - error =xfs_attr_rmtval_remove (args); -if (error) -return error; - } - - error =xfs_attr_node_addname_clear_incomplete (args); out:if (state)xfs_da_state_free (state); -if (error) -return error; -return retval; +return error; }
PATCH v17 8/11 xfs: Hoist xfs_attr_leaf_addname
In reply to Allison HendersonThis patch hoists xfs_attr_leaf_addname into the calling function. The goal being to get all the code that will require state management into the same scope. This isn't particularly aesthetic right away, but it is a preliminary step to merging in the state machine code.
--- fs/xfs/libxfs/xfs_attr.c | 209 ++++++++++++++++++++++------------------------- fs/xfs/xfs_trace.h | 1 - 2 files changed, 96 insertions(+), 114 deletions(-)
fs/xfs/libxfs/xfs_attr.c +96 -113
@@ -44,9 +44,9 @@ 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_removename(xfs_da_args_t *args); STATIC int xfs_attr_leaf_hasname(struct xfs_da_args *args, struct xfs_buf **bp); +STATIC int xfs_attr_leaf_try_add(struct xfs_da_args *args, struct xfs_buf *bp);/* * Internal routines when attribute list is more than one block.
@@ -271,8 +271,9 @@ xfs_attr_set_args( struct xfs_da_args *args) {struct xfs_inode *dp = args->dp; +struct xfs_buf *bp =NULL ;struct xfs_da_state *state =NULL ; -int error =0 ; +int forkoff, error =0 ;/* * If the attribute list is already in leaf format, jump straight to
@@ -287,10 +288,101 @@ xfs_attr_set_args( }if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) { - error =xfs_attr_leaf_addname (args); -if (error != -ENOSPC ) + error =xfs_attr_leaf_try_add (args, bp); +if (error == -ENOSPC ) + goto node; +else if (error) +return error; + +/* +* 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; + +/* +* If there was an out-of-line value, allocate the blocks we +* identified for its storage and copy the value. This is done +* after we create the attribute so that we don't overflow the +* maximum size of a transaction and/or hit a deadlock. +*/ +if (args->rmtblkno >0 ) { + error =xfs_attr_rmtval_set (args); +if (error) +return error; + } + +if (!(args->op_flags &XFS_DA_OP_RENAME )) { +/* +* Added a "remote" value, just clear the incomplete +*flag. +*/ +if (args->rmtblkno >0 ) + error =xfs_attr3_leaf_clearflag (args); + +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_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 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; + + 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; +node:/* * Promote the attribute list to the Btree format. */
@@ -727,115 +819,6 @@ xfs_attr_leaf_try_add(return retval; } - -/* -* Add a name to the leaf attribute list structure -* -* This leaf block cannot have a "remote" value, we only call this routine -* if bmap_one_block() says there is only one block (ie: no remote blks). -*/ -STATIC int -xfs_attr_leaf_addname ( -struct xfs_da_args *args) -{ -int 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 -* later routines can manage their own transactions. -*/ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) -return error; - -/* -* If there was an out-of-line value, allocate the blocks we -* identified for its storage and copy the value. This is done -* after we create the attribute so that we don't overflow the -* maximum size of a transaction and/or hit a deadlock. -*/ -if (args->rmtblkno >0 ) { - error =xfs_attr_rmtval_set (args); -if (error) -return error; - } - -if (!(args->op_flags &XFS_DA_OP_RENAME )) { -/* -* Added a "remote" value, just clear the incomplete flag. -*/ -if (args->rmtblkno >0 ) - error =xfs_attr3_leaf_clearflag (args); - -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_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 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; - - 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; -} -/* * Return EEXIST if attr is found, or ENOATTR if not */
fs/xfs/xfs_trace.h +0 -1
@@ -1914,7 +1914,6 @@ DEFINE_ATTR_EVENT(xfs_attr_leaf_add);DEFINE_ATTR_EVENT (xfs_attr_leaf_add_old);DEFINE_ATTR_EVENT (xfs_attr_leaf_add_new);DEFINE_ATTR_EVENT (xfs_attr_leaf_add_work); -DEFINE_ATTR_EVENT (xfs_attr_leaf_addname);DEFINE_ATTR_EVENT (xfs_attr_leaf_create);DEFINE_ATTR_EVENT (xfs_attr_leaf_compact);DEFINE_ATTR_EVENT (xfs_attr_leaf_get);
Signature · 1 line
2.7.4
Re: [PATCH v17 08/11] xfs: Hoist xfs_attr_leaf_addname
Quoted 17 lines · Allison Henderson
This patch hoists
xfs_attr_leaf_addnameinto the calling function. The goal being to get all the code that will require state management into the same scope. This isn't particularly aesthetic right away, but it is a preliminary step to merging in the state machine code.Signed-off-by Allison Henderson <[email protected]>Reviewed-by Darrick J. Wong <[email protected]>Reviewed-by Chandan Babu R <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 209 ++++++++++++++++++++++------------------------- fs/xfs/xfs_trace.h | 1 - 2 files changed, 96 insertions(+), 114 deletions(-)fs/xfs/libxfs/xfs_attr.c +0
-0
...
Quoted 4 lines
fs/xfs/libxfs/xfs_attr.c +0
-0@@ -287,10 +288,101 @@ xfs_attr_set_args( }if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) {
...
Quoted 4 lines
fs/xfs/libxfs/xfs_attr.c +2
-0return error; +xfs_attr3_leaf_remove (bp, args); +
fs/xfs/libxfs/xfs_attr.c xfs_attr_set_args( · line 385
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10
-0+/* +* 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; +node:
With the understanding that this mid function return thing goes away before the end of the series:
Quoted 134 lines
fs/xfs/libxfs/xfs_attr.c +0
-109/* * Promote the attribute list to the Btree format. */ @@ -727,115 +819,6 @@ xfs_attr_leaf_try_add(return retval; } - -/* -* Add a name to the leaf attribute list structure -* -* This leaf block cannot have a "remote" value, we only call this routine -* if bmap_one_block() says there is only one block (ie: no remote blks). -*/ -STATIC int -xfs_attr_leaf_addname ( -struct xfs_da_args *args) -{ -int 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 -* later routines can manage their own transactions. -*/ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) -return error; - -/* -* If there was an out-of-line value, allocate the blocks we -* identified for its storage and copy the value. This is done -* after we create the attribute so that we don't overflow the -* maximum size of a transaction and/or hit a deadlock. -*/ -if (args->rmtblkno >0 ) { - error =xfs_attr_rmtval_set (args); -if (error) -return error; - } - -if (!(args->op_flags &XFS_DA_OP_RENAME )) { -/* -* Added a "remote" value, just clear the incomplete flag. -*/ -if (args->rmtblkno >0 ) - error =xfs_attr3_leaf_clearflag (args); - -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_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 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; - - 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; -} -/* * Return EEXIST if attr is found, or ENOATTR if not */ fs/xfs/xfs_trace.h +0
-1@@ -1914,7 +1914,6 @@ DEFINE_ATTR_EVENT(xfs_attr_leaf_add);DEFINE_ATTR_EVENT (xfs_attr_leaf_add_old);DEFINE_ATTR_EVENT (xfs_attr_leaf_add_new);DEFINE_ATTR_EVENT (xfs_attr_leaf_add_work); -DEFINE_ATTR_EVENT (xfs_attr_leaf_addname);DEFINE_ATTR_EVENT (xfs_attr_leaf_create);DEFINE_ATTR_EVENT (xfs_attr_leaf_compact);DEFINE_ATTR_EVENT (xfs_attr_leaf_get);Signature · 1 line
2.7.4
Re: [PATCH v17 08/11] xfs: Hoist xfs_attr_leaf_addname
Quoted 42 lines · Brian Foster
Quoted 17 lines · Allison Henderson
This patch hoists
xfs_attr_leaf_addnameinto the calling function. The goal being to get all the code that will require state management into the same scope. This isn't particularly aesthetic right away, but it is a preliminary step to merging in the state machine code.Signed-off-by Allison Henderson <[email protected]>Reviewed-by Darrick J. Wong <[email protected]>Reviewed-by Chandan Babu R <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 209 ++++++++++++++++++++++------------------------- fs/xfs/xfs_trace.h | 1 - 2 files changed, 96 insertions(+), 114 deletions(-)fs/xfs/libxfs/xfs_attr.c +0
-0...
Quoted 4 lines
fs/xfs/libxfs/xfs_attr.c +0
-0@@ -287,10 +288,101 @@ xfs_attr_set_args( }if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) {...
Quoted 4 lines
return error;
fs/xfs/libxfs/xfs_attr.c +2
-0+xfs_attr3_leaf_remove (bp, args); +fs/xfs/libxfs/xfs_attr.c xfs_attr_set_args( · line 385
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10
-0+/* +* 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; +node:With the understanding that this mid function return thing goes away before the end of the series:
Quoted 1 line
Reviewed-by Brian Foster <[email protected]>
Great, thank you!
Allison
Quoted 136 lines
Quoted 135 lines
/*
* Promote the attribute list to the Btree format. */fs/xfs/libxfs/xfs_attr.c +0
-109@@ -727,115 +819,6 @@ xfs_attr_leaf_try_add(return retval; } - -/* -* Add a name to the leaf attribute list structure -* -* This leaf block cannot have a "remote" value, we only call this routine -* if bmap_one_block() says there is only one block (ie: no remote blks). -*/ -STATIC int -xfs_attr_leaf_addname ( -struct xfs_da_args *args) -{ -int 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 -* later routines can manage their own transactions. -*/ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) -return error; - -/* -* If there was an out-of-line value, allocate the blocks we -* identified for its storage and copy the value. This is done -* after we create the attribute so that we don't overflow the -* maximum size of a transaction and/or hit a deadlock. -*/ -if (args->rmtblkno >0 ) { - error =xfs_attr_rmtval_set (args); -if (error) -return error; - } - -if (!(args->op_flags &XFS_DA_OP_RENAME )) { -/* -* Added a "remote" value, just clear the incomplete flag. -*/ -if (args->rmtblkno >0 ) - error =xfs_attr3_leaf_clearflag (args); - -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_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 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; - - 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; -} -/* * Return EEXIST if attr is found, or ENOATTR if not */ fs/xfs/xfs_trace.h +0
-1@@ -1914,7 +1914,6 @@ DEFINE_ATTR_EVENT(xfs_attr_leaf_add);DEFINE_ATTR_EVENT (xfs_attr_leaf_add_old);DEFINE_ATTR_EVENT (xfs_attr_leaf_add_new);DEFINE_ATTR_EVENT (xfs_attr_leaf_add_work); -DEFINE_ATTR_EVENT (xfs_attr_leaf_addname);DEFINE_ATTR_EVENT (xfs_attr_leaf_create);DEFINE_ATTR_EVENT (xfs_attr_leaf_compact);DEFINE_ATTR_EVENT (xfs_attr_leaf_get);Signature · 1 line
2.7.4
PATCH v17 9/11 xfs: Hoist node transaction handling
In reply to Allison HendersonThis patch basically hoists the node transaction handling around the leaf code we just hoisted. This will helps setup this area for the state machine since the goto is easily replaced with a state since it ends with a transaction roll.
--- fs/xfs/libxfs/xfs_attr.c | 55 +++++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 26 deletions(-)
fs/xfs/libxfs/xfs_attr.c +29 -26
@@ -289,10 +289,36 @@ xfs_attr_set_args(if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) { error =xfs_attr_leaf_try_add (args, bp); -if (error == -ENOSPC ) +if (error == -ENOSPC ) { +/* +* Promote the attribute list to the Btree format. +*/ + error =xfs_attr3_leaf_to_node (args); +if (error) +return error; + +/* +* Finish any deferred work items and roll the transaction once +* more. The goal here is to call node_addname with the inode +* and transaction in the same state (inode locked and joined, +* transaction clean) no matter how we got to this step. +*/ + 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; + goto node; -else if (error) + }else if (error) {return error; + }/* * Commit the transaction that added the attr name so that
@@ -382,32 +408,9 @@ xfs_attr_set_args(/* bp is gone due to xfs_da_shrink_inode */ return error; + } node: -/* -* Promote the attribute list to the Btree format. -*/ - error =xfs_attr3_leaf_to_node (args); -if (error) -return error; - -/* -* Finish any deferred work items and roll the transaction once -* more. The goal here is to call node_addname with the inode -* and transaction in the same state (inode locked and joined, -* transaction clean) no matter how we got to this step. -*/ - 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; - } do { error = xfs_attr_node_addname_find_attr(args, &state);
Signature · 1 line
2.7.4
PATCH v17 10/11 xfs: Add delay ready attr remove routines
In reply to Allison HendersonThis 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 is merged with xfs_attr_node_removename become a new function, xfs_attr_remove_iter. This new version uses a sort of state machine like switch to keep track of where it was when EAGAIN was returned. 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 preserving 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. See xfs_attr.h for a more detailed diagram of the states.
--- fs/xfs/libxfs/xfs_attr.c | 208 +++++++++++++++++++++++++++------------- fs/xfs/libxfs/xfs_attr.h | 131 +++++++++++++++++++++++++ fs/xfs/libxfs/xfs_attr_leaf.c | 2 +- fs/xfs/libxfs/xfs_attr_remote.c | 48 ++++++---- fs/xfs/libxfs/xfs_attr_remote.h | 2 +- fs/xfs/xfs_attr_inactive.c | 2 +- 6 files changed, 305 insertions(+), 88 deletions(-)
fs/xfs/libxfs/xfs_attr.c +143 -65
@@ -57,7 +57,6 @@ STATIC int xfs_attr_node_addname(struct xfs_da_args *args, struct xfs_da_state *state); STATIC int xfs_attr_node_addname_find_attr(struct xfs_da_args *args,struct xfs_da_state **state); -STATIC int xfs_attr_node_removename(xfs_da_args_t *args); STATIC int xfs_attr_node_addname_clear_incomplete(struct xfs_da_args *args); STATIC int xfs_attr_node_hasname(xfs_da_args_t *args,struct xfs_da_state **state);
@@ -221,6 +220,31 @@ xfs_attr_is_shortform( ip->i_afp->if_nextents == 0); } +/* +* Checks to see if a delayed attribute transaction should be rolled. If so, +* transaction is finished or rolled as needed. +*/ +int +xfs_attr_trans_roll ( +struct xfs_delattr_context *dac) +{ +struct xfs_da_args *args = dac->da_args; +int error; + +if (dac->flags &XFS_DAC_DEFER_FINISH ) { +/* +* The caller wants us to finish all the deferred ops so that we +* avoid pinning the log tail with a large number of deferred +* ops. +*/ + dac->flags &= ~XFS_DAC_DEFER_FINISH ; + error =xfs_defer_finish (&args->trans); + }else + error =xfs_trans_roll_inode (&args->trans, args->dp); + +return error; +} + STATIC intxfs_attr_set_fmt (struct xfs_da_args *args)
@@ -527,21 +551,23 @@ xfs_has_attr(*/ int xfs_attr_remove_args ( -struct xfs_da_args *args) +struct xfs_da_args *args) { -struct xfs_inode *dp = args->dp; -int error; +int error; +struct xfs_delattr_context dac = { + .da_args = args, + }; -if (!xfs_inode_hasattr (dp)) { - error = -ENOATTR ; - }else if (dp->i_afp->if_format ==XFS_DINODE_FMT_LOCAL ) { -ASSERT (dp->i_afp->if_flags &XFS_IFINLINE ); - error =xfs_attr_shortform_remove (args); - }else if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) { - error =xfs_attr_leaf_removename (args); - }else { - error =xfs_attr_node_removename (args); - } +do { + error =xfs_attr_remove_iter (&dac); +if (error != -EAGAIN ) +break ; + + error =xfs_attr_trans_roll (&dac); +if (error) +return error; + + }while (true);return error; }
@@ -1187,14 +1213,16 @@ xfs_attr_leaf_mark_incomplete(*/ STATIC int xfs_attr_node_removename_setup( -struct xfs_da_args *args, -struct xfs_da_state **state) +struct xfs_delattr_context *dac) { -int error; +struct xfs_da_args *args = dac->da_args; +struct xfs_da_state **state = &dac->da_state; +int error; error =xfs_attr_node_hasname (args, state);if (error != -EEXIST )return error; + error =0 ;ASSERT ((*state)->path.blk[(*state)->path.active -1 ].bp !=NULL ); ASSERT((*state)->path.blk[(*state)->path.active - 1].magic ==
@@ -1203,10 +1231,13 @@ int xfs_attr_node_removename_setup(if (args->rmtblkno >0 ) { error =xfs_attr_leaf_mark_incomplete (args, *state);if (error) -return error; + goto out; -return xfs_attr_rmtval_invalidate (args); + error =xfs_attr_rmtval_invalidate (args); } +out: +if (error) +xfs_da_state_free (*state);return 0 ; }
@@ -1231,70 +1262,117 @@ xfs_attr_node_remove_cleanup( }/* -* Remove a name from a B-tree attribute list. +* Remove the attribute specified in @args. * * 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 in-line 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) +int +xfs_attr_remove_iter ( +struct xfs_delattr_context *dac) { -struct xfs_da_state *state; -int retval, error; -struct xfs_inode *dp = args->dp; +struct xfs_da_args *args = dac->da_args; +struct xfs_da_state *state = dac->da_state; +int retval, error; +struct xfs_inode *dp = args->dp;trace_xfs_attr_node_removename (args); - error =xfs_attr_node_removename_setup (args, &state); -if (error) - goto out; +switch (dac->dela_state) { +case XFS_DAS_UNINIT : +if (!xfs_inode_hasattr (dp)) +return -ENOATTR ; -/* -* If there is an out-of-line value, de-allocate the blocks. -* This is done before we remove the attribute so that we don't -* overflow the maximum size of a transaction and/or hit a deadlock. -*/ -if (args->rmtblkno >0 ) { - error =xfs_attr_rmtval_remove (args); -if (error) - goto out; +if (dp->i_afp->if_format ==XFS_DINODE_FMT_LOCAL ) { +ASSERT (dp->i_afp->if_flags &XFS_IFINLINE ); +return xfs_attr_shortform_remove (args); + } + +if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) +return xfs_attr_leaf_removename (args); + +if (!dac->da_state) { + error =xfs_attr_node_removename_setup (dac); +if (error) +return error; + state = dac->da_state; + } + +/* fallthrough */ +case XFS_DAS_RMTBLK : + dac->dela_state =XFS_DAS_RMTBLK ;/* -* Refill the state structure with buffers, the prior calls -* released our buffers. +* If there is an out-of-line value, de-allocate the blocks. +* This is done before we remove the attribute so that we don't +* overflow the maximum size of a transaction and/or hit a +* deadlock. */ - error =xfs_attr_refillstate (state); -if (error) - goto out; - } - retval =xfs_attr_node_remove_cleanup (args, state); +if (args->rmtblkno >0 ) { +/* +* May return -EAGAIN. Remove blocks until 0 is returned +*/ + error =__xfs_attr_rmtval_remove (dac); +if (error == -EAGAIN ) +return error; +else if (error) + goto out; + +/* +* Refill the state structure with buffers, the prior +* calls released our buffers. +*/ +ASSERT (args->rmtblkno ==0 ); + error =xfs_attr_refillstate (state); +if (error) + goto out; + + dac->dela_state =XFS_DAS_CLNUP ; + dac->flags |=XFS_DAC_DEFER_FINISH ; +return -EAGAIN ; + } + +case XFS_DAS_CLNUP : + retval =xfs_attr_node_remove_cleanup (args, state); -/* -* 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;/* -* Commit the Btree join operation and start a new trans. +* Check to see if the tree needs to be collapsed. Set the flag +* to indicate that the calling function needs to move the +* shrink operation */ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) - goto out; - } +if (retval && (state->path.active >1 )) { + error =xfs_da3_join (state); +if (error) + goto out; -/* -* If the result is small enough, push it all into the inode. -*/ -if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) - error =xfs_attr_node_shrink (args, state); + dac->flags |=XFS_DAC_DEFER_FINISH ; + dac->dela_state =XFS_DAS_RM_SHRINK ; +return -EAGAIN ; + } + +/* fallthrough */ +case XFS_DAS_RM_SHRINK : +/* +* If the result is small enough, push it all into the inode. +*/ +if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) + error =xfs_attr_node_shrink (args, state); + +break ; +default : +ASSERT (0 ); + error = -EINVAL ; + goto out; + } +if (error == -EAGAIN ) +return error; out:if (state)xfs_da_state_free (state);
fs/xfs/libxfs/xfs_attr.h +131 -0
143 lines not on this page · raw message
fs/xfs/libxfs/xfs_attr_leaf.c +1 -1
@@ -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 +28 -20
81 lines not on this page · raw message
fs/xfs/libxfs/xfs_attr_remote.h +1 -1
@@ -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
@@ -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
Re: [PATCH v17 10/11] xfs: Add delay ready attr remove routines
Quoted 149 lines · Allison Henderson
This patch modifies the attr remove routines to be delay ready. This means they no longer roll or commit transactions, but instead return
-EAGAINto have the calling routine roll and refresh the transaction. In this series,xfs_attr_remove_argsis merged withxfs_attr_node_removenamebecome a new function,xfs_attr_remove_iter. This new version uses a sort of state machine like switch to keep track of where it was when EAGAIN was returned. A new version ofxfs_attr_remove_argsconsists of a simple loop to refresh the transaction until the operation is completed. A newXFS_DAC_DEFER_FINISHflag is used to finish the transaction where ever the existing code used to.Calls to
xfs_attr_rmtval_removeare replaced with the delay ready version__xfs_attr_rmtval_remove. We will rename__xfs_attr_rmtval_removeback toxfs_attr_rmtval_removewhen we are done.
xfs_attr_rmtval_removeitself is still in use by the set routines (used during a rename). For reasons of preserving existing function, we modifyxfs_attr_rmtval_removeto callxfs_defer_finishwhen the flag is set. Similar to howxfs_attr_remove_argsdoes here. Once we transition the set routines to be delay ready,xfs_attr_rmtval_removeis 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 newxfs_delattr_stateenum 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. Seexfs_attr.hfor a more detailed diagram of the states.Signed-off-by Allison Henderson <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 208 +++++++++++++++++++++++++++------------- fs/xfs/libxfs/xfs_attr.h | 131 +++++++++++++++++++++++++ fs/xfs/libxfs/xfs_attr_leaf.c | 2 +- fs/xfs/libxfs/xfs_attr_remote.c | 48 ++++++---- fs/xfs/libxfs/xfs_attr_remote.h | 2 +- fs/xfs/xfs_attr_inactive.c | 2 +- 6 files changed, 305 insertions(+), 88 deletions(-)fs/xfs/libxfs/xfs_attr.c +45
-18@@ -57,7 +57,6 @@ STATIC int xfs_attr_node_addname(struct xfs_da_args *args, struct xfs_da_state *state); STATIC int xfs_attr_node_addname_find_attr(struct xfs_da_args *args,struct xfs_da_state **state); -STATIC int xfs_attr_node_removename(xfs_da_args_t *args); STATIC int xfs_attr_node_addname_clear_incomplete(struct xfs_da_args *args); STATIC int xfs_attr_node_hasname(xfs_da_args_t *args,struct xfs_da_state **state);@@ -221,6 +220,31 @@ xfs_attr_is_shortform( ip->i_afp->if_nextents == 0); } +/* +* Checks to see if a delayed attribute transaction should be rolled. If so, +* transaction is finished or rolled as needed. +*/ +int +xfs_attr_trans_roll ( +struct xfs_delattr_context *dac) +{ +struct xfs_da_args *args = dac->da_args; +int error; + +if (dac->flags &XFS_DAC_DEFER_FINISH ) { +/* +* The caller wants us to finish all the deferred ops so that we +* avoid pinning the log tail with a large number of deferred +* ops. +*/ + dac->flags &= ~XFS_DAC_DEFER_FINISH ; + error =xfs_defer_finish (&args->trans); + }else + error =xfs_trans_roll_inode (&args->trans, args->dp); + +return error; +} + STATIC intxfs_attr_set_fmt (struct xfs_da_args *args)@@ -527,21 +551,23 @@ xfs_has_attr(*/ int xfs_attr_remove_args ( -struct xfs_da_args *args) +struct xfs_da_args *args) { -struct xfs_inode *dp = args->dp; -int error; +int error; +struct xfs_delattr_context dac = { + .da_args = args, + }; -if (!xfs_inode_hasattr (dp)) { - error = -ENOATTR ; - }else if (dp->i_afp->if_format ==XFS_DINODE_FMT_LOCAL ) { -ASSERT (dp->i_afp->if_flags &XFS_IFINLINE ); - error =xfs_attr_shortform_remove (args); - }else if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) { - error =xfs_attr_leaf_removename (args); - }else { - error =xfs_attr_node_removename (args); - } +do { + error =xfs_attr_remove_iter (&dac); +if (error != -EAGAIN ) +break ; + + error =xfs_attr_trans_roll (&dac); +if (error) +return error; + + }while (true);return error; }@@ -1187,14 +1213,16 @@ xfs_attr_leaf_mark_incomplete(*/ STATIC int xfs_attr_node_removename_setup( -struct xfs_da_args *args, -struct xfs_da_state **state) +struct xfs_delattr_context *dac) { -int error; +struct xfs_da_args *args = dac->da_args; +struct xfs_da_state **state = &dac->da_state; +int error; error =xfs_attr_node_hasname (args, state);if (error != -EEXIST )return error; + error =0 ;ASSERT ((*state)->path.blk[(*state)->path.active -1 ].bp !=NULL ); ASSERT((*state)->path.blk[(*state)->path.active - 1].magic ==@@ -1203,10 +1231,13 @@ int xfs_attr_node_removename_setup(if (args->rmtblkno >0 ) { error =xfs_attr_leaf_mark_incomplete (args, *state);if (error) -return error;
fs/xfs/libxfs/xfs_attr.c int xfs_attr_node_removename_setup( · line 1242
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +5
-1+ goto out; -return xfs_attr_rmtval_invalidate (args); + error =xfs_attr_rmtval_invalidate (args); } +out: +if (error) +xfs_da_state_free (*state);return 0 ;
The above should be "return error". Otherwise, we might be missing out on reporting failures from xfs_attr_leaf_mark_incomplete() or xfs_attr_rmtval_invalidate().
Quoted 152 lines
fs/xfs/libxfs/xfs_attr.c +84
-46}@@ -1231,70 +1262,117 @@ xfs_attr_node_remove_cleanup( }/* -* Remove a name from a B-tree attribute list. +* Remove the attribute specified in @args. * * 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 in-line 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) +int +xfs_attr_remove_iter ( +struct xfs_delattr_context *dac) { -struct xfs_da_state *state; -int retval, error; -struct xfs_inode *dp = args->dp; +struct xfs_da_args *args = dac->da_args; +struct xfs_da_state *state = dac->da_state; +int retval, error; +struct xfs_inode *dp = args->dp;trace_xfs_attr_node_removename (args); - error =xfs_attr_node_removename_setup (args, &state); -if (error) - goto out; +switch (dac->dela_state) { +case XFS_DAS_UNINIT : +if (!xfs_inode_hasattr (dp)) +return -ENOATTR ; -/* -* If there is an out-of-line value, de-allocate the blocks. -* This is done before we remove the attribute so that we don't -* overflow the maximum size of a transaction and/or hit a deadlock. -*/ -if (args->rmtblkno >0 ) { - error =xfs_attr_rmtval_remove (args); -if (error) - goto out; +if (dp->i_afp->if_format ==XFS_DINODE_FMT_LOCAL ) { +ASSERT (dp->i_afp->if_flags &XFS_IFINLINE ); +return xfs_attr_shortform_remove (args); + } + +if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) +return xfs_attr_leaf_removename (args); + +if (!dac->da_state) { + error =xfs_attr_node_removename_setup (dac); +if (error) +return error; + state = dac->da_state; + } + +/* fallthrough */ +case XFS_DAS_RMTBLK : + dac->dela_state =XFS_DAS_RMTBLK ;/* -* Refill the state structure with buffers, the prior calls -* released our buffers. +* If there is an out-of-line value, de-allocate the blocks. +* This is done before we remove the attribute so that we don't +* overflow the maximum size of a transaction and/or hit a +* deadlock. */ - error =xfs_attr_refillstate (state); -if (error) - goto out; - } - retval =xfs_attr_node_remove_cleanup (args, state); +if (args->rmtblkno >0 ) { +/* +* May return -EAGAIN. Remove blocks until 0 is returned +*/ + error =__xfs_attr_rmtval_remove (dac); +if (error == -EAGAIN ) +return error; +else if (error) + goto out; + +/* +* Refill the state structure with buffers, the prior +* calls released our buffers. +*/ +ASSERT (args->rmtblkno ==0 ); + error =xfs_attr_refillstate (state); +if (error) + goto out; + + dac->dela_state =XFS_DAS_CLNUP ; + dac->flags |=XFS_DAC_DEFER_FINISH ; +return -EAGAIN ; + } + +case XFS_DAS_CLNUP : + retval =xfs_attr_node_remove_cleanup (args, state); -/* -* 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;/* -* Commit the Btree join operation and start a new trans. +* Check to see if the tree needs to be collapsed. Set the flag +* to indicate that the calling function needs to move the +* shrink operation */ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) - goto out; - } +if (retval && (state->path.active >1 )) { + error =xfs_da3_join (state); +if (error) + goto out; -/* -* If the result is small enough, push it all into the inode. -*/ -if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) - error =xfs_attr_node_shrink (args, state); + dac->flags |=XFS_DAC_DEFER_FINISH ; + dac->dela_state =XFS_DAS_RM_SHRINK ; +return -EAGAIN ; + } + +/* fallthrough */ +case XFS_DAS_RM_SHRINK : +/* +* If the result is small enough, push it all into the inode. +*/ +if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) + error =xfs_attr_node_shrink (args, state);
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_remove_cleanup( · line 1375
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +9
-0+ +break ; +default : +ASSERT (0 ); + error = -EINVAL ; + goto out; + } +if (error == -EAGAIN ) +return error;
The above two statements probably not required. AFAICT, the call to xfs_attr_node_shrink() is the only instance which can cause "error" to have a non-zero return value if control reaches this point in the function. All other locations in the function seem to either return from the function or jump to "out" label on detecting an error.
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_remove_cleanup( · line 1378
Quoted 3 lines
fs/xfs/libxfs/xfs_attr.c +0
-0out:if (state)xfs_da_state_free (state);
--
chandan
Re: [PATCH v17 10/11] xfs: Add delay ready attr remove routines
Quoted 159 lines · Chandan Babu R
Quoted 158 lines · Allison Henderson
This patch modifies the attr remove routines to be delay ready. This means they no longer roll or commit transactions, but instead return
-EAGAINto have the calling routine roll and refresh the transaction. In this series,xfs_attr_remove_argsis merged withxfs_attr_node_removenamebecome a new function,xfs_attr_remove_iter. This new version uses a sort of state machine like switch to keep track of where it was when EAGAIN was returned. A new version ofxfs_attr_remove_argsconsists of a simple loop to refresh the transaction until the operation is completed. A newXFS_DAC_DEFER_FINISHflag is used to finish the transaction where ever the existing code used to.Calls to
xfs_attr_rmtval_removeare replaced with the delay ready version__xfs_attr_rmtval_remove. We will rename__xfs_attr_rmtval_removeback toxfs_attr_rmtval_removewhen we are done.
xfs_attr_rmtval_removeitself is still in use by the set routines (used during a rename). For reasons of preserving existing function, we modifyxfs_attr_rmtval_removeto callxfs_defer_finishwhen the flag is set. Similar to howxfs_attr_remove_argsdoes here. Once we transition the set routines to be delay ready,xfs_attr_rmtval_removeis 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 newxfs_delattr_stateenum 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. Seexfs_attr.hfor a more detailed diagram of the states.Signed-off-by Allison Henderson <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 208 +++++++++++++++++++++++++++------------- fs/xfs/libxfs/xfs_attr.h | 131 +++++++++++++++++++++++++ fs/xfs/libxfs/xfs_attr_leaf.c | 2 +- fs/xfs/libxfs/xfs_attr_remote.c | 48 ++++++---- fs/xfs/libxfs/xfs_attr_remote.h | 2 +- fs/xfs/xfs_attr_inactive.c | 2 +- 6 files changed, 305 insertions(+), 88 deletions(-)fs/xfs/libxfs/xfs_attr.c +50
-19@@ -57,7 +57,6 @@ STATIC int xfs_attr_node_addname(struct xfs_da_args *args, struct xfs_da_state *state); STATIC int xfs_attr_node_addname_find_attr(struct xfs_da_args *args,struct xfs_da_state **state); -STATIC int xfs_attr_node_removename(xfs_da_args_t *args); STATIC int xfs_attr_node_addname_clear_incomplete(struct xfs_da_args *args); STATIC int xfs_attr_node_hasname(xfs_da_args_t *args,struct xfs_da_state **state);@@ -221,6 +220,31 @@ xfs_attr_is_shortform( ip->i_afp->if_nextents == 0); } +/* +* Checks to see if a delayed attribute transaction should be rolled. If so, +* transaction is finished or rolled as needed. +*/ +int +xfs_attr_trans_roll ( +struct xfs_delattr_context *dac) +{ +struct xfs_da_args *args = dac->da_args; +int error; + +if (dac->flags &XFS_DAC_DEFER_FINISH ) { +/* +* The caller wants us to finish all the deferred ops so that we +* avoid pinning the log tail with a large number of deferred +* ops. +*/ + dac->flags &= ~XFS_DAC_DEFER_FINISH ; + error =xfs_defer_finish (&args->trans); + }else + error =xfs_trans_roll_inode (&args->trans, args->dp); + +return error; +} + STATIC intxfs_attr_set_fmt (struct xfs_da_args *args)@@ -527,21 +551,23 @@ xfs_has_attr(*/ int xfs_attr_remove_args ( -struct xfs_da_args *args) +struct xfs_da_args *args) { -struct xfs_inode *dp = args->dp; -int error; +int error; +struct xfs_delattr_context dac = { + .da_args = args, + }; -if (!xfs_inode_hasattr (dp)) { - error = -ENOATTR ; - }else if (dp->i_afp->if_format ==XFS_DINODE_FMT_LOCAL ) { -ASSERT (dp->i_afp->if_flags &XFS_IFINLINE ); - error =xfs_attr_shortform_remove (args); - }else if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) { - error =xfs_attr_leaf_removename (args); - }else { - error =xfs_attr_node_removename (args); - } +do { + error =xfs_attr_remove_iter (&dac); +if (error != -EAGAIN ) +break ; + + error =xfs_attr_trans_roll (&dac); +if (error) +return error; + + }while (true);return error; }@@ -1187,14 +1213,16 @@ xfs_attr_leaf_mark_incomplete(*/ STATIC int xfs_attr_node_removename_setup( -struct xfs_da_args *args, -struct xfs_da_state **state) +struct xfs_delattr_context *dac) { -int error; +struct xfs_da_args *args = dac->da_args; +struct xfs_da_state **state = &dac->da_state; +int error; error =xfs_attr_node_hasname (args, state);if (error != -EEXIST )return error; + error =0 ;ASSERT ((*state)->path.blk[(*state)->path.active -1 ].bp !=NULL ); ASSERT((*state)->path.blk[(*state)->path.active - 1].magic ==@@ -1203,10 +1231,13 @@ int xfs_attr_node_removename_setup(if (args->rmtblkno >0 ) { error =xfs_attr_leaf_mark_incomplete (args, *state);if (error) -return error; + goto out; -return xfs_attr_rmtval_invalidate (args); + error =xfs_attr_rmtval_invalidate (args); } +out: +if (error) +xfs_da_state_free (*state);
Quoted 5 lines
fs/xfs/libxfs/xfs_attr.c int xfs_attr_node_removename_setup( · line 1242
Quoted 1 line
fs/xfs/libxfs/xfs_attr.c +0
-0return 0 ;The above should be "return error". Otherwise, we might be missing out on reporting failures from
xfs_attr_leaf_mark_incomplete()orxfs_attr_rmtval_invalidate().
Ok, will update the return
Quoted 161 lines
Quoted 161 lines
fs/xfs/libxfs/xfs_attr.c +91
-46}@@ -1231,70 +1262,117 @@ xfs_attr_node_remove_cleanup( }/* -* Remove a name from a B-tree attribute list. +* Remove the attribute specified in @args. * * 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 in-line 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) +int +xfs_attr_remove_iter ( +struct xfs_delattr_context *dac) { -struct xfs_da_state *state; -int retval, error; -struct xfs_inode *dp = args->dp; +struct xfs_da_args *args = dac->da_args; +struct xfs_da_state *state = dac->da_state; +int retval, error; +struct xfs_inode *dp = args->dp;trace_xfs_attr_node_removename (args); - error =xfs_attr_node_removename_setup (args, &state); -if (error) - goto out; +switch (dac->dela_state) { +case XFS_DAS_UNINIT : +if (!xfs_inode_hasattr (dp)) +return -ENOATTR ; -/* -* If there is an out-of-line value, de-allocate the blocks. -* This is done before we remove the attribute so that we don't -* overflow the maximum size of a transaction and/or hit a deadlock. -*/ -if (args->rmtblkno >0 ) { - error =xfs_attr_rmtval_remove (args); -if (error) - goto out; +if (dp->i_afp->if_format ==XFS_DINODE_FMT_LOCAL ) { +ASSERT (dp->i_afp->if_flags &XFS_IFINLINE ); +return xfs_attr_shortform_remove (args); + } + +if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) +return xfs_attr_leaf_removename (args); + +if (!dac->da_state) { + error =xfs_attr_node_removename_setup (dac); +if (error) +return error; + state = dac->da_state; + } + +/* fallthrough */ +case XFS_DAS_RMTBLK : + dac->dela_state =XFS_DAS_RMTBLK ;/* -* Refill the state structure with buffers, the prior calls -* released our buffers. +* If there is an out-of-line value, de-allocate the blocks. +* This is done before we remove the attribute so that we don't +* overflow the maximum size of a transaction and/or hit a +* deadlock. */ - error =xfs_attr_refillstate (state); -if (error) - goto out; - } - retval =xfs_attr_node_remove_cleanup (args, state); +if (args->rmtblkno >0 ) { +/* +* May return -EAGAIN. Remove blocks until 0 is returned +*/ + error =__xfs_attr_rmtval_remove (dac); +if (error == -EAGAIN ) +return error; +else if (error) + goto out; + +/* +* Refill the state structure with buffers, the prior +* calls released our buffers. +*/ +ASSERT (args->rmtblkno ==0 ); + error =xfs_attr_refillstate (state); +if (error) + goto out; + + dac->dela_state =XFS_DAS_CLNUP ; + dac->flags |=XFS_DAC_DEFER_FINISH ; +return -EAGAIN ; + } + +case XFS_DAS_CLNUP : + retval =xfs_attr_node_remove_cleanup (args, state); -/* -* 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;/* -* Commit the Btree join operation and start a new trans. +* Check to see if the tree needs to be collapsed. Set the flag +* to indicate that the calling function needs to move the +* shrink operation */ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) - goto out; - } +if (retval && (state->path.active >1 )) { + error =xfs_da3_join (state); +if (error) + goto out; -/* -* If the result is small enough, push it all into the inode. -*/ -if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) - error =xfs_attr_node_shrink (args, state); + dac->flags |=XFS_DAC_DEFER_FINISH ; + dac->dela_state =XFS_DAS_RM_SHRINK ; +return -EAGAIN ; + } + +/* fallthrough */ +case XFS_DAS_RM_SHRINK : +/* +* If the result is small enough, push it all into the inode. +*/ +if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) + error =xfs_attr_node_shrink (args, state); + +break ; +default : +ASSERT (0 ); + error = -EINVAL ; + goto out; + }
Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_remove_cleanup( · line 1375
Quoted 2 lines
fs/xfs/libxfs/xfs_attr.c +2
-0+if (error == -EAGAIN ) +return error;The above two statements probably not required. AFAICT, the call to
xfs_attr_node_shrink()is the only instance which can cause "error" to have a non-zero return value if control reaches this point in the function. All other locations in the function seem to either return from the function or jump to "out" label on detecting an error.
Ok, i suppose it doesnt hurt anything, but i'll go ahead and bump it since I need to pick up the change above.
Quoted 7 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_remove_cleanup( · line 1378
Quoted 4 lines
fs/xfs/libxfs/xfs_attr.c +0
-0out:if (state)xfs_da_state_free (state);--
chandan
Thanks for the reviews!
Allison
Quoted 1 line
Re: [PATCH v17 10/11] xfs: Add delay ready attr remove routines
In reply to Allison HendersonQuoted 47 lines · Allison Henderson
This patch modifies the attr remove routines to be delay ready. This means they no longer roll or commit transactions, but instead return
-EAGAINto have the calling routine roll and refresh the transaction. In this series,xfs_attr_remove_argsis merged withxfs_attr_node_removenamebecome a new function,xfs_attr_remove_iter. This new version uses a sort of state machine like switch to keep track of where it was when EAGAIN was returned. A new version ofxfs_attr_remove_argsconsists of a simple loop to refresh the transaction until the operation is completed. A newXFS_DAC_DEFER_FINISHflag is used to finish the transaction where ever the existing code used to.Calls to
xfs_attr_rmtval_removeare replaced with the delay ready version__xfs_attr_rmtval_remove. We will rename__xfs_attr_rmtval_removeback toxfs_attr_rmtval_removewhen we are done.
xfs_attr_rmtval_removeitself is still in use by the set routines (used during a rename). For reasons of preserving existing function, we modifyxfs_attr_rmtval_removeto callxfs_defer_finishwhen the flag is set. Similar to howxfs_attr_remove_argsdoes here. Once we transition the set routines to be delay ready,xfs_attr_rmtval_removeis 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 newxfs_delattr_stateenum 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. Seexfs_attr.hfor a more detailed diagram of the states.Signed-off-by Allison Henderson <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 208 +++++++++++++++++++++++++++------------- fs/xfs/libxfs/xfs_attr.h | 131 +++++++++++++++++++++++++ fs/xfs/libxfs/xfs_attr_leaf.c | 2 +- fs/xfs/libxfs/xfs_attr_remote.c | 48 ++++++---- fs/xfs/libxfs/xfs_attr_remote.h | 2 +- fs/xfs/xfs_attr_inactive.c | 2 +- 6 files changed, 305 insertions(+), 88 deletions(-)fs/xfs/libxfs/xfs_attr.c +0
-0
...
Quoted 33 lines
fs/xfs/libxfs/xfs_attr.c +13
-7@@ -1231,70 +1262,117 @@ xfs_attr_node_remove_cleanup( }/* -* Remove a name from a B-tree attribute list. +* Remove the attribute specified in @args. * * 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 in-line 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) +int +xfs_attr_remove_iter ( +struct xfs_delattr_context *dac) { -struct xfs_da_state *state; -int retval, error; -struct xfs_inode *dp = args->dp; +struct xfs_da_args *args = dac->da_args; +struct xfs_da_state *state = dac->da_state; +int retval, error; +struct xfs_inode *dp = args->dp;trace_xfs_attr_node_removename (args);
...
fs/xfs/libxfs/xfs_attr.c
Quoted 2 lines
fs/xfs/libxfs/xfs_attr.c +2
-0+case XFS_DAS_CLNUP : + retval =xfs_attr_node_remove_cleanup (args, state);
This is a nit, but when reading the code the "cleanup" name gives the impression that this is a resource cleanup or something along those lines, when this is actually a primary component of the operation where we remove the attr name. That took me a second to find. Could we tweak the state and rename the helper to something like DAS_RMNAME / _node_remove_name() so the naming is a bit more explicit?
Quoted 56 lines
fs/xfs/libxfs/xfs_attr.c +28
-20-/* -* 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;/* -* Commit the Btree join operation and start a new trans. +* Check to see if the tree needs to be collapsed. Set the flag +* to indicate that the calling function needs to move the +* shrink operation */ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) - goto out; - } +if (retval && (state->path.active >1 )) { + error =xfs_da3_join (state); +if (error) + goto out; -/* -* If the result is small enough, push it all into the inode. -*/ -if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) - error =xfs_attr_node_shrink (args, state); + dac->flags |=XFS_DAC_DEFER_FINISH ; + dac->dela_state =XFS_DAS_RM_SHRINK ; +return -EAGAIN ; + } + +/* fallthrough */ +case XFS_DAS_RM_SHRINK : +/* +* If the result is small enough, push it all into the inode. +*/ +if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) + error =xfs_attr_node_shrink (args, state); + +break ; +default : +ASSERT (0 ); + error = -EINVAL ; + goto out; + } +if (error == -EAGAIN ) +return error; out:if (state)xfs_da_state_free (state);
...
Quoted 4 lines
fs/xfs/libxfs/xfs_attr_remote.c +0
-0
...
fs/xfs/libxfs/xfs_attr_remote.c xfs_attr_rmtval_remove( · line 692
Quoted 10 lines
fs/xfs/libxfs/xfs_attr_remote.c +3
-3@@ -685,31 +687,29 @@ xfs_attr_rmtval_remove(* Keep de-allocating extents until the remote-value region is gone. */ do { - retval = __xfs_attr_rmtval_remove(args); - if (retval && retval != -EAGAIN) - return retval; + error = __xfs_attr_rmtval_remove(&dac); + if (error != -EAGAIN) + break;
Shouldn't this retain the (error && error != -EAGAIN) logic to roll the transaction after the final unmap? Even if this is transient, it's probably best to preserve behavior if this is unintentional.
Otherwise my only remaining feedback was to add/tweak some comments that I think make the iteration function easier to follow. I've appended a diff for that. If you agree with the changes feel free to just fold them in and/or tweak as necessary. With those various nits and Chandan's feedback addressed, I think this patch looks pretty good.
Brian
--- 8< ---
fs/xfs/libxfs/xfs_attr.c +20 -10
@@ -1289,14 +1289,21 @@ xfs_attr_remove_iter(if (!xfs_inode_hasattr (dp))return -ENOATTR ; +/* +* Shortform or leaf formats don't require transaction rolls and +* thus state transitions. Call the right helper and return. +*/ if (dp->i_afp->if_format ==XFS_DINODE_FMT_LOCAL ) {ASSERT (dp->i_afp->if_flags &XFS_IFINLINE );return xfs_attr_shortform_remove (args); } -if (xfs_bmap_one_block (dp,XFS_ATTR_FORK ))return xfs_attr_leaf_removename (args); +/* +* Node format may require transaction rolls. Set up the +* state context and fall into the state machine. +*/ if (!dac->da_state) { error =xfs_attr_node_removename_setup (dac);if (error)
@@ -1304,7 +1311,7 @@ xfs_attr_remove_iter( state = dac->da_state; } -/* fallthrough */ +/* fallthrough */ case XFS_DAS_RMTBLK : dac->dela_state =XFS_DAS_RMTBLK ;
@@ -1316,7 +1323,8 @@ xfs_attr_remove_iter(*/ if (args->rmtblkno >0 ) {/* -* May return -EAGAIN. Remove blocks until 0 is returned +* May return -EAGAIN. Roll and repeat until all remote +* blocks are removed. */ error =__xfs_attr_rmtval_remove (dac);if (error == -EAGAIN )
@@ -1325,26 +1333,26 @@ xfs_attr_remove_iter( goto out;/* -* Refill the state structure with buffers, the prior -* calls released our buffers. +* Refill the state structure with buffers (the prior +* calls released our buffers) and close out this +* transaction before proceeding. */ ASSERT (args->rmtblkno ==0 ); error =xfs_attr_refillstate (state);if (error) goto out; - dac->dela_state =XFS_DAS_CLNUP ; dac->flags |=XFS_DAC_DEFER_FINISH ;return -EAGAIN ; } +/* fallthrough */ case XFS_DAS_CLNUP : retval =xfs_attr_node_remove_cleanup (args, state);/* -* Check to see if the tree needs to be collapsed. Set the flag -* to indicate that the calling function needs to move the -* shrink operation +* Check to see if the tree needs to be collapsed. If so, roll +* the transacton and fall into the shrink state. */ if (retval && (state->path.active >1 )) { error =xfs_da3_join (state);
@@ -1360,10 +1368,12 @@ xfs_attr_remove_iter(case XFS_DAS_RM_SHRINK :/* * If the result is small enough, push it all into the inode. +* This is our final state so it's safe to return a dirty +* transaction. */ if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) error =xfs_attr_node_shrink (args, state); - +ASSERT (error != -EAGAIN );break ;default :ASSERT (0 );
Re: [PATCH v17 10/11] xfs: Add delay ready attr remove routines
Quoted 83 lines · Brian Foster
Quoted 47 lines · Allison Henderson
This patch modifies the attr remove routines to be delay ready. This means they no longer roll or commit transactions, but instead return
-EAGAINto have the calling routine roll and refresh the transaction. In this series,xfs_attr_remove_argsis merged withxfs_attr_node_removenamebecome a new function,xfs_attr_remove_iter. This new version uses a sort of state machine like switch to keep track of where it was when EAGAIN was returned. A new version ofxfs_attr_remove_argsconsists of a simple loop to refresh the transaction until the operation is completed. A newXFS_DAC_DEFER_FINISHflag is used to finish the transaction where ever the existing code used to.Calls to
xfs_attr_rmtval_removeare replaced with the delay ready version__xfs_attr_rmtval_remove. We will rename__xfs_attr_rmtval_removeback toxfs_attr_rmtval_removewhen we are done.
xfs_attr_rmtval_removeitself is still in use by the set routines (used during a rename). For reasons of preserving existing function, we modifyxfs_attr_rmtval_removeto callxfs_defer_finishwhen the flag is set. Similar to howxfs_attr_remove_argsdoes here. Once we transition the set routines to be delay ready,xfs_attr_rmtval_removeis 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 newxfs_delattr_stateenum 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. Seexfs_attr.hfor a more detailed diagram of the states.Signed-off-by Allison Henderson <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 208 +++++++++++++++++++++++++++------------- fs/xfs/libxfs/xfs_attr.h | 131 +++++++++++++++++++++++++ fs/xfs/libxfs/xfs_attr_leaf.c | 2 +- fs/xfs/libxfs/xfs_attr_remote.c | 48 ++++++---- fs/xfs/libxfs/xfs_attr_remote.h | 2 +- fs/xfs/xfs_attr_inactive.c | 2 +- 6 files changed, 305 insertions(+), 88 deletions(-)fs/xfs/libxfs/xfs_attr.c +0
-0...
Quoted 33 lines
fs/xfs/libxfs/xfs_attr.c +13
-7@@ -1231,70 +1262,117 @@ xfs_attr_node_remove_cleanup( }/* -* Remove a name from a B-tree attribute list. +* Remove the attribute specified in @args. * * 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 in-line 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) +int +xfs_attr_remove_iter ( +struct xfs_delattr_context *dac) { -struct xfs_da_state *state; -int retval, error; -struct xfs_inode *dp = args->dp; +struct xfs_da_args *args = dac->da_args; +struct xfs_da_state *state = dac->da_state; +int retval, error; +struct xfs_inode *dp = args->dp;trace_xfs_attr_node_removename (args);...
Quoted 9 lines
fs/xfs/libxfs/xfs_attr.c
Quoted 2 lines
fs/xfs/libxfs/xfs_attr.c +2
-0+case XFS_DAS_CLNUP : + retval =xfs_attr_node_remove_cleanup (args, state);This is a nit, but when reading the code the "cleanup" name gives the impression that this is a resource cleanup or something along those lines, when this is actually a primary component of the operation where we remove the attr name. That took me a second to find. Could we tweak the state and rename the helper to something like
DAS_RMNAME/_node_remove_name()so the naming is a bit more explicit?
Sure, this helper is actually added in patch 2 of this set. I can rename it there? People have already added their rvb's, but I'm assuming people are not bothered by small tweeks like that? That way this patch just sort of moves it and XFS_DAS_CLNUP can turn into XFS_DAS_RMNAME here.
Quoted 63 lines
Quoted 57 lines
fs/xfs/libxfs/xfs_attr.c +28
-20-/* -* 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;/* -* Commit the Btree join operation and start a new trans. +* Check to see if the tree needs to be collapsed. Set the flag +* to indicate that the calling function needs to move the +* shrink operation */ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) - goto out; - } +if (retval && (state->path.active >1 )) { + error =xfs_da3_join (state); +if (error) + goto out; -/* -* If the result is small enough, push it all into the inode. -*/ -if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) - error =xfs_attr_node_shrink (args, state); + dac->flags |=XFS_DAC_DEFER_FINISH ; + dac->dela_state =XFS_DAS_RM_SHRINK ; +return -EAGAIN ; + } + +/* fallthrough */ +case XFS_DAS_RM_SHRINK : +/* +* If the result is small enough, push it all into the inode. +*/ +if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) + error =xfs_attr_node_shrink (args, state); + +break ; +default : +ASSERT (0 ); + error = -EINVAL ; + goto out; + } +if (error == -EAGAIN ) +return error; out:if (state)xfs_da_state_free (state);...
Quoted 4 lines
fs/xfs/libxfs/xfs_attr_remote.c +0
-0...
Quoted 14 lines
fs/xfs/libxfs/xfs_attr_remote.c xfs_attr_rmtval_remove( · line 692
Quoted 10 lines
fs/xfs/libxfs/xfs_attr_remote.c +3
-3@@ -685,31 +687,29 @@ xfs_attr_rmtval_remove(* Keep de-allocating extents until the remote-value region is gone. */ do { - retval = __xfs_attr_rmtval_remove(args); - if (retval && retval != -EAGAIN) - return retval; + error = __xfs_attr_rmtval_remove(&dac); + if (error != -EAGAIN) + break;Shouldn't this retain the (error && error !=
-EAGAIN) logic to roll the transaction after the final unmap? Even if this is transient, it's probably best to preserve behavior if this is unintentional.
Sure, I dont think it's intentional, I think back in v10 we had a different arangement here with a helper inside the while() expression that had equivelent error handling logic. But that got nak'd in the next review and I think I likley forgot to put back this handling. Will fix.
Quoted 6 lines
Otherwise my only remaining feedback was to add/tweak some comments that I think make the iteration function easier to follow. I've appended a diff for that. If you agree with the changes feel free to just fold them in and/or tweak as necessary. With those various nits and Chandan's feedback addressed, I think this patch looks pretty good.
Sure, those all look reasonable. Will add. Thanks for the reviews! Allison
Quoted 99 lines
Brian
--- 8< ---
fs/xfs/libxfs/xfs_attr.c +20
-10@@ -1289,14 +1289,21 @@ xfs_attr_remove_iter(if (!xfs_inode_hasattr (dp))return -ENOATTR ; +/* +* Shortform or leaf formats don't require transaction rolls and +* thus state transitions. Call the right helper and return. +*/ if (dp->i_afp->if_format ==XFS_DINODE_FMT_LOCAL ) {ASSERT (dp->i_afp->if_flags &XFS_IFINLINE );return xfs_attr_shortform_remove (args); } -if (xfs_bmap_one_block (dp,XFS_ATTR_FORK ))return xfs_attr_leaf_removename (args); +/* +* Node format may require transaction rolls. Set up the +* state context and fall into the state machine. +*/ if (!dac->da_state) { error =xfs_attr_node_removename_setup (dac);if (error)@@ -1304,7 +1311,7 @@ xfs_attr_remove_iter( state = dac->da_state; } -/* fallthrough */ +/* fallthrough */ case XFS_DAS_RMTBLK : dac->dela_state =XFS_DAS_RMTBLK ;@@ -1316,7 +1323,8 @@ xfs_attr_remove_iter(*/ if (args->rmtblkno >0 ) {/* -* May return -EAGAIN. Remove blocks until 0 is returned +* May return -EAGAIN. Roll and repeat until all remote +* blocks are removed. */ error =__xfs_attr_rmtval_remove (dac);if (error == -EAGAIN )@@ -1325,26 +1333,26 @@ xfs_attr_remove_iter( goto out;/* -* Refill the state structure with buffers, the prior -* calls released our buffers. +* Refill the state structure with buffers (the prior +* calls released our buffers) and close out this +* transaction before proceeding. */ ASSERT (args->rmtblkno ==0 ); error =xfs_attr_refillstate (state);if (error) goto out; - dac->dela_state =XFS_DAS_CLNUP ; dac->flags |=XFS_DAC_DEFER_FINISH ;return -EAGAIN ; } +/* fallthrough */ case XFS_DAS_CLNUP : retval =xfs_attr_node_remove_cleanup (args, state);/* -* Check to see if the tree needs to be collapsed. Set the flag -* to indicate that the calling function needs to move the -* shrink operation +* Check to see if the tree needs to be collapsed. If so, roll +* the transacton and fall into the shrink state. */ if (retval && (state->path.active >1 )) { error =xfs_da3_join (state);@@ -1360,10 +1368,12 @@ xfs_attr_remove_iter(case XFS_DAS_RM_SHRINK :/* * If the result is small enough, push it all into the inode. +* This is our final state so it's safe to return a dirty +* transaction. */ if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) error =xfs_attr_node_shrink (args, state); - +ASSERT (error != -EAGAIN );break ;default :ASSERT (0 );
Re: [PATCH v17 10/11] xfs: Add delay ready attr remove routines
Quoted 92 lines · Allison Henderson
Quoted 80 lines · Brian Foster
Quoted 47 lines · Allison Henderson
This patch modifies the attr remove routines to be delay ready. This means they no longer roll or commit transactions, but instead return
-EAGAINto have the calling routine roll and refresh the transaction. In this series,xfs_attr_remove_argsis merged withxfs_attr_node_removenamebecome a new function,xfs_attr_remove_iter. This new version uses a sort of state machine like switch to keep track of where it was when EAGAIN was returned. A new version ofxfs_attr_remove_argsconsists of a simple loop to refresh the transaction until the operation is completed. A newXFS_DAC_DEFER_FINISHflag is used to finish the transaction where ever the existing code used to.Calls to
xfs_attr_rmtval_removeare replaced with the delay ready version__xfs_attr_rmtval_remove. We will rename__xfs_attr_rmtval_removeback toxfs_attr_rmtval_removewhen we are done.
xfs_attr_rmtval_removeitself is still in use by the set routines (used during a rename). For reasons of preserving existing function, we modifyxfs_attr_rmtval_removeto callxfs_defer_finishwhen the flag is set. Similar to howxfs_attr_remove_argsdoes here. Once we transition the set routines to be delay ready,xfs_attr_rmtval_removeis 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 newxfs_delattr_stateenum 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. Seexfs_attr.hfor a more detailed diagram of the states.Signed-off-by Allison Henderson <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 208 +++++++++++++++++++++++++++------------- fs/xfs/libxfs/xfs_attr.h | 131 +++++++++++++++++++++++++ fs/xfs/libxfs/xfs_attr_leaf.c | 2 +- fs/xfs/libxfs/xfs_attr_remote.c | 48 ++++++---- fs/xfs/libxfs/xfs_attr_remote.h | 2 +- fs/xfs/xfs_attr_inactive.c | 2 +- 6 files changed, 305 insertions(+), 88 deletions(-)fs/xfs/libxfs/xfs_attr.c +0
-0...
Quoted 30 lines
fs/xfs/libxfs/xfs_attr.c +13
-7@@ -1231,70 +1262,117 @@ xfs_attr_node_remove_cleanup( }/* -* Remove a name from a B-tree attribute list. +* Remove the attribute specified in @args. * * 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 in-line 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) +int +xfs_attr_remove_iter ( +struct xfs_delattr_context *dac) { -struct xfs_da_state *state; -int retval, error; -struct xfs_inode *dp = args->dp; +struct xfs_da_args *args = dac->da_args; +struct xfs_da_state *state = dac->da_state; +int retval, error; +struct xfs_inode *dp = args->dp;trace_xfs_attr_node_removename (args);...
Quoted 9 lines
fs/xfs/libxfs/xfs_attr.c
Quoted 2 lines
fs/xfs/libxfs/xfs_attr.c +2
-0+case XFS_DAS_CLNUP : + retval =xfs_attr_node_remove_cleanup (args, state);This is a nit, but when reading the code the "cleanup" name gives the impression that this is a resource cleanup or something along those lines, when this is actually a primary component of the operation where we remove the attr name. That took me a second to find. Could we tweak the state and rename the helper to something like
DAS_RMNAME/_node_remove_name()so the naming is a bit more explicit?
Quoted 4 lines
Sure, this helper is actually added in patch 2 of this set. I can rename it there? People have already added their rvb's, but I'm assuming people are not bothered by small tweeks like that? That way this patch just sort of moves it and
XFS_DAS_CLNUPcan turn intoXFS_DAS_RMNAMEhere.
<bikeshed> "RMNAME" looks too similar to "RENAME" for my old eyes, can we please pick something else? Like "RM_NAME", or "REMOVE_NAME" ?
--D
Quoted 181 lines
Quoted 61 lines
Quoted 55 lines
fs/xfs/libxfs/xfs_attr.c +28
-20-/* -* 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;/* -* Commit the Btree join operation and start a new trans. +* Check to see if the tree needs to be collapsed. Set the flag +* to indicate that the calling function needs to move the +* shrink operation */ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) - goto out; - } +if (retval && (state->path.active >1 )) { + error =xfs_da3_join (state); +if (error) + goto out; -/* -* If the result is small enough, push it all into the inode. -*/ -if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) - error =xfs_attr_node_shrink (args, state); + dac->flags |=XFS_DAC_DEFER_FINISH ; + dac->dela_state =XFS_DAS_RM_SHRINK ; +return -EAGAIN ; + } + +/* fallthrough */ +case XFS_DAS_RM_SHRINK : +/* +* If the result is small enough, push it all into the inode. +*/ +if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) + error =xfs_attr_node_shrink (args, state); + +break ; +default : +ASSERT (0 ); + error = -EINVAL ; + goto out; + } +if (error == -EAGAIN ) +return error; out:if (state)xfs_da_state_free (state);...
Quoted 4 lines
fs/xfs/libxfs/xfs_attr_remote.c +0
-0...
Quoted 14 lines
fs/xfs/libxfs/xfs_attr_remote.c xfs_attr_rmtval_remove( · line 692
Quoted 10 lines
fs/xfs/libxfs/xfs_attr_remote.c +3
-3@@ -685,31 +687,29 @@ xfs_attr_rmtval_remove(* Keep de-allocating extents until the remote-value region is gone. */ do { - retval = __xfs_attr_rmtval_remove(args); - if (retval && retval != -EAGAIN) - return retval; + error = __xfs_attr_rmtval_remove(&dac); + if (error != -EAGAIN) + break;Shouldn't this retain the (error && error !=
-EAGAIN) logic to roll the transaction after the final unmap? Even if this is transient, it's probably best to preserve behavior if this is unintentional.Sure, I dont think it's intentional, I think back in v10 we had a different arangement here with a helper inside the
while()expression that had equivelent error handling logic. But that got nak'd in the next review and I think I likley forgot to put back this handling. Will fix.Quoted 6 lines
Otherwise my only remaining feedback was to add/tweak some comments that I think make the iteration function easier to follow. I've appended a diff for that. If you agree with the changes feel free to just fold them in and/or tweak as necessary. With those various nits and Chandan's feedback addressed, I think this patch looks pretty good.
Sure, those all look reasonable. Will add. Thanks for the reviews! Allison
Quoted 92 lines
Brian
--- 8< ---
fs/xfs/libxfs/xfs_attr.c +20
-10@@ -1289,14 +1289,21 @@ xfs_attr_remove_iter(if (!xfs_inode_hasattr (dp))return -ENOATTR ; +/* +* Shortform or leaf formats don't require transaction rolls and +* thus state transitions. Call the right helper and return. +*/ if (dp->i_afp->if_format ==XFS_DINODE_FMT_LOCAL ) {ASSERT (dp->i_afp->if_flags &XFS_IFINLINE );return xfs_attr_shortform_remove (args); } -if (xfs_bmap_one_block (dp,XFS_ATTR_FORK ))return xfs_attr_leaf_removename (args); +/* +* Node format may require transaction rolls. Set up the +* state context and fall into the state machine. +*/ if (!dac->da_state) { error =xfs_attr_node_removename_setup (dac);if (error)@@ -1304,7 +1311,7 @@ xfs_attr_remove_iter( state = dac->da_state; } -/* fallthrough */ +/* fallthrough */ case XFS_DAS_RMTBLK : dac->dela_state =XFS_DAS_RMTBLK ;@@ -1316,7 +1323,8 @@ xfs_attr_remove_iter(*/ if (args->rmtblkno >0 ) {/* -* May return -EAGAIN. Remove blocks until 0 is returned +* May return -EAGAIN. Roll and repeat until all remote +* blocks are removed. */ error =__xfs_attr_rmtval_remove (dac);if (error == -EAGAIN )@@ -1325,26 +1333,26 @@ xfs_attr_remove_iter( goto out;/* -* Refill the state structure with buffers, the prior -* calls released our buffers. +* Refill the state structure with buffers (the prior +* calls released our buffers) and close out this +* transaction before proceeding. */ ASSERT (args->rmtblkno ==0 ); error =xfs_attr_refillstate (state);if (error) goto out; - dac->dela_state =XFS_DAS_CLNUP ; dac->flags |=XFS_DAC_DEFER_FINISH ;return -EAGAIN ; } +/* fallthrough */ case XFS_DAS_CLNUP : retval =xfs_attr_node_remove_cleanup (args, state);/* -* Check to see if the tree needs to be collapsed. Set the flag -* to indicate that the calling function needs to move the -* shrink operation +* Check to see if the tree needs to be collapsed. If so, roll +* the transacton and fall into the shrink state. */ if (retval && (state->path.active >1 )) { error =xfs_da3_join (state);@@ -1360,10 +1368,12 @@ xfs_attr_remove_iter(case XFS_DAS_RM_SHRINK :/* * If the result is small enough, push it all into the inode. +* This is our final state so it's safe to return a dirty +* transaction. */ if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) error =xfs_attr_node_shrink (args, state); - +ASSERT (error != -EAGAIN );break ;default :ASSERT (0 );
Re: [PATCH v17 10/11] xfs: Add delay ready attr remove routines
Quoted 93 lines · Darrick J. Wong
Quoted 92 lines · Allison Henderson
Quoted 89 lines · Brian Foster
Quoted 47 lines · Allison Henderson
This patch modifies the attr remove routines to be delay ready. This means they no longer roll or commit transactions, but instead return
-EAGAINto have the calling routine roll and refresh the transaction. In this series,xfs_attr_remove_argsis merged withxfs_attr_node_removenamebecome a new function,xfs_attr_remove_iter. This new version uses a sort of state machine like switch to keep track of where it was when EAGAIN was returned. A new version ofxfs_attr_remove_argsconsists of a simple loop to refresh the transaction until the operation is completed. A newXFS_DAC_DEFER_FINISHflag is used to finish the transaction where ever the existing code used to.Calls to
xfs_attr_rmtval_removeare replaced with the delay ready version__xfs_attr_rmtval_remove. We will rename__xfs_attr_rmtval_removeback toxfs_attr_rmtval_removewhen we are done.
xfs_attr_rmtval_removeitself is still in use by the set routines (used during a rename). For reasons of preserving existing function, we modifyxfs_attr_rmtval_removeto callxfs_defer_finishwhen the flag is set. Similar to howxfs_attr_remove_argsdoes here. Once we transition the set routines to be delay ready,xfs_attr_rmtval_removeis 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 newxfs_delattr_stateenum 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. Seexfs_attr.hfor a more detailed diagram of the states.Signed-off-by Allison Henderson <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 208 +++++++++++++++++++++++++++------------- fs/xfs/libxfs/xfs_attr.h | 131 +++++++++++++++++++++++++ fs/xfs/libxfs/xfs_attr_leaf.c | 2 +- fs/xfs/libxfs/xfs_attr_remote.c | 48 ++++++---- fs/xfs/libxfs/xfs_attr_remote.h | 2 +- fs/xfs/xfs_attr_inactive.c | 2 +- 6 files changed, 305 insertions(+), 88 deletions(-)fs/xfs/libxfs/xfs_attr.c +0
-0...
Quoted 30 lines
fs/xfs/libxfs/xfs_attr.c +13
-7@@ -1231,70 +1262,117 @@ xfs_attr_node_remove_cleanup( }/* -* Remove a name from a B-tree attribute list. +* Remove the attribute specified in @args. * * 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 in-line 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) +int +xfs_attr_remove_iter ( +struct xfs_delattr_context *dac) { -struct xfs_da_state *state; -int retval, error; -struct xfs_inode *dp = args->dp; +struct xfs_da_args *args = dac->da_args; +struct xfs_da_state *state = dac->da_state; +int retval, error; +struct xfs_inode *dp = args->dp;trace_xfs_attr_node_removename (args);...
fs/xfs/libxfs/xfs_attr.c
Quoted 2 lines
fs/xfs/libxfs/xfs_attr.c +2
-0+case XFS_DAS_CLNUP : + retval =xfs_attr_node_remove_cleanup (args, state);This is a nit, but when reading the code the "cleanup" name gives the impression that this is a resource cleanup or something along those lines, when this is actually a primary component of the operation where we remove the attr name. That took me a second to find. Could we tweak the state and rename the helper to something like
DAS_RMNAME/_node_remove_name()so the naming is a bit more explicit?
Quoted 8 lines
Quoted 4 lines
Sure, this helper is actually added in patch 2 of this set. I can rename it there? People have already added their rvb's, but I'm assuming people are not bothered by small tweeks like that? That way this patch just sort of moves it and
XFS_DAS_CLNUPcan turn intoXFS_DAS_RMNAMEhere.<bikeshed> "RMNAME" looks too similar to "RENAME" for my old eyes, can we please pick something else? Like "
RM_NAME", or "REMOVE_NAME" ?
Either of those seem fine to me, FWIW. I think anything that expresses removal of the name/entry over the more generic "cleanup" name is an improvement..
Brian
Quoted 184 lines
--D
Quoted 181 lines
Quoted 61 lines
Quoted 55 lines
fs/xfs/libxfs/xfs_attr.c +28
-20-/* -* 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;/* -* Commit the Btree join operation and start a new trans. +* Check to see if the tree needs to be collapsed. Set the flag +* to indicate that the calling function needs to move the +* shrink operation */ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) - goto out; - } +if (retval && (state->path.active >1 )) { + error =xfs_da3_join (state); +if (error) + goto out; -/* -* If the result is small enough, push it all into the inode. -*/ -if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) - error =xfs_attr_node_shrink (args, state); + dac->flags |=XFS_DAC_DEFER_FINISH ; + dac->dela_state =XFS_DAS_RM_SHRINK ; +return -EAGAIN ; + } + +/* fallthrough */ +case XFS_DAS_RM_SHRINK : +/* +* If the result is small enough, push it all into the inode. +*/ +if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) + error =xfs_attr_node_shrink (args, state); + +break ; +default : +ASSERT (0 ); + error = -EINVAL ; + goto out; + } +if (error == -EAGAIN ) +return error; out:if (state)xfs_da_state_free (state);...
Quoted 4 lines
fs/xfs/libxfs/xfs_attr_remote.c +0
-0...
Quoted 14 lines
fs/xfs/libxfs/xfs_attr_remote.c xfs_attr_rmtval_remove( · line 692
Quoted 10 lines
fs/xfs/libxfs/xfs_attr_remote.c +3
-3@@ -685,31 +687,29 @@ xfs_attr_rmtval_remove(* Keep de-allocating extents until the remote-value region is gone. */ do { - retval = __xfs_attr_rmtval_remove(args); - if (retval && retval != -EAGAIN) - return retval; + error = __xfs_attr_rmtval_remove(&dac); + if (error != -EAGAIN) + break;Shouldn't this retain the (error && error !=
-EAGAIN) logic to roll the transaction after the final unmap? Even if this is transient, it's probably best to preserve behavior if this is unintentional.Sure, I dont think it's intentional, I think back in v10 we had a different arangement here with a helper inside the
while()expression that had equivelent error handling logic. But that got nak'd in the next review and I think I likley forgot to put back this handling. Will fix.Quoted 6 lines
Otherwise my only remaining feedback was to add/tweak some comments that I think make the iteration function easier to follow. I've appended a diff for that. If you agree with the changes feel free to just fold them in and/or tweak as necessary. With those various nits and Chandan's feedback addressed, I think this patch looks pretty good.
Sure, those all look reasonable. Will add. Thanks for the reviews! Allison
Quoted 92 lines
Brian
--- 8< ---
fs/xfs/libxfs/xfs_attr.c +20
-10@@ -1289,14 +1289,21 @@ xfs_attr_remove_iter(if (!xfs_inode_hasattr (dp))return -ENOATTR ; +/* +* Shortform or leaf formats don't require transaction rolls and +* thus state transitions. Call the right helper and return. +*/ if (dp->i_afp->if_format ==XFS_DINODE_FMT_LOCAL ) {ASSERT (dp->i_afp->if_flags &XFS_IFINLINE );return xfs_attr_shortform_remove (args); } -if (xfs_bmap_one_block (dp,XFS_ATTR_FORK ))return xfs_attr_leaf_removename (args); +/* +* Node format may require transaction rolls. Set up the +* state context and fall into the state machine. +*/ if (!dac->da_state) { error =xfs_attr_node_removename_setup (dac);if (error)@@ -1304,7 +1311,7 @@ xfs_attr_remove_iter( state = dac->da_state; } -/* fallthrough */ +/* fallthrough */ case XFS_DAS_RMTBLK : dac->dela_state =XFS_DAS_RMTBLK ;@@ -1316,7 +1323,8 @@ xfs_attr_remove_iter(*/ if (args->rmtblkno >0 ) {/* -* May return -EAGAIN. Remove blocks until 0 is returned +* May return -EAGAIN. Roll and repeat until all remote +* blocks are removed. */ error =__xfs_attr_rmtval_remove (dac);if (error == -EAGAIN )@@ -1325,26 +1333,26 @@ xfs_attr_remove_iter( goto out;/* -* Refill the state structure with buffers, the prior -* calls released our buffers. +* Refill the state structure with buffers (the prior +* calls released our buffers) and close out this +* transaction before proceeding. */ ASSERT (args->rmtblkno ==0 ); error =xfs_attr_refillstate (state);if (error) goto out; - dac->dela_state =XFS_DAS_CLNUP ; dac->flags |=XFS_DAC_DEFER_FINISH ;return -EAGAIN ; } +/* fallthrough */ case XFS_DAS_CLNUP : retval =xfs_attr_node_remove_cleanup (args, state);/* -* Check to see if the tree needs to be collapsed. Set the flag -* to indicate that the calling function needs to move the -* shrink operation +* Check to see if the tree needs to be collapsed. If so, roll +* the transacton and fall into the shrink state. */ if (retval && (state->path.active >1 )) { error =xfs_da3_join (state);@@ -1360,10 +1368,12 @@ xfs_attr_remove_iter(case XFS_DAS_RM_SHRINK :/* * If the result is small enough, push it all into the inode. +* This is our final state so it's safe to return a dirty +* transaction. */ if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) error =xfs_attr_node_shrink (args, state); - +ASSERT (error != -EAGAIN );break ;default :ASSERT (0 );
Re: [PATCH v17 10/11] xfs: Add delay ready attr remove routines
Quoted 103 lines · Brian Foster
Quoted 93 lines · Darrick J. Wong
Quoted 92 lines · Allison Henderson
Quoted 89 lines · Brian Foster
Quoted 47 lines · Allison Henderson
This patch modifies the attr remove routines to be delay ready. This means they no longer roll or commit transactions, but instead return
-EAGAINto have the calling routine roll and refresh the transaction. In this series,xfs_attr_remove_argsis merged withxfs_attr_node_removenamebecome a new function,xfs_attr_remove_iter. This new version uses a sort of state machine like switch to keep track of where it was when EAGAIN was returned. A new version ofxfs_attr_remove_argsconsists of a simple loop to refresh the transaction until the operation is completed. A newXFS_DAC_DEFER_FINISHflag is used to finish the transaction where ever the existing code used to.Calls to
xfs_attr_rmtval_removeare replaced with the delay ready version__xfs_attr_rmtval_remove. We will rename__xfs_attr_rmtval_removeback toxfs_attr_rmtval_removewhen we are done.
xfs_attr_rmtval_removeitself is still in use by the set routines (used during a rename). For reasons of preserving existing function, we modifyxfs_attr_rmtval_removeto callxfs_defer_finishwhen the flag is set. Similar to howxfs_attr_remove_argsdoes here. Once we transition the set routines to be delay ready,xfs_attr_rmtval_removeis 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 newxfs_delattr_stateenum 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. Seexfs_attr.hfor a more detailed diagram of the states.Signed-off-by Allison Henderson <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 208 +++++++++++++++++++++++++++------------- fs/xfs/libxfs/xfs_attr.h | 131 +++++++++++++++++++++++++ fs/xfs/libxfs/xfs_attr_leaf.c | 2 +- fs/xfs/libxfs/xfs_attr_remote.c | 48 ++++++---- fs/xfs/libxfs/xfs_attr_remote.h | 2 +- fs/xfs/xfs_attr_inactive.c | 2 +- 6 files changed, 305 insertions(+), 88 deletions(-)fs/xfs/libxfs/xfs_attr.c +0
-0...
Quoted 30 lines
fs/xfs/libxfs/xfs_attr.c +13
-7@@ -1231,70 +1262,117 @@ xfs_attr_node_remove_cleanup( }/* -* Remove a name from a B-tree attribute list. +* Remove the attribute specified in @args. * * 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 in-line 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) +int +xfs_attr_remove_iter ( +struct xfs_delattr_context *dac) { -struct xfs_da_state *state; -int retval, error; -struct xfs_inode *dp = args->dp; +struct xfs_da_args *args = dac->da_args; +struct xfs_da_state *state = dac->da_state; +int retval, error; +struct xfs_inode *dp = args->dp;trace_xfs_attr_node_removename (args);...
fs/xfs/libxfs/xfs_attr.c
Quoted 2 lines
fs/xfs/libxfs/xfs_attr.c +2
-0+case XFS_DAS_CLNUP : + retval =xfs_attr_node_remove_cleanup (args, state);This is a nit, but when reading the code the "cleanup" name gives the impression that this is a resource cleanup or something along those lines, when this is actually a primary component of the operation where we remove the attr name. That took me a second to find. Could we tweak the state and rename the helper to something like
DAS_RMNAME/_node_remove_name()so the naming is a bit more explicit?Quoted 8 lines
Quoted 4 lines
Sure, this helper is actually added in patch 2 of this set. I can rename it there? People have already added their rvb's, but I'm assuming people are not bothered by small tweeks like that? That way this patch just sort of moves it and
XFS_DAS_CLNUPcan turn intoXFS_DAS_RMNAMEhere.<bikeshed> "RMNAME" looks too similar to "RENAME" for my old eyes, can we please pick something else? Like "
RM_NAME", or "REMOVE_NAME" ?
Quoted 5 lines
Either of those seem fine to me, FWIW. I think anything that expresses removal of the name/entry over the more generic "cleanup" name is an improvement..
Brian
Alrighty, lets go with RM_NAME then. Will update. Thanks for the feedback.
Allison
Quoted 186 lines
Quoted 185 lines
--D
Quoted 181 lines
Quoted 61 lines
Quoted 55 lines
fs/xfs/libxfs/xfs_attr.c +28
-20-/* -* 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;/* -* Commit the Btree join operation and start a new trans. +* Check to see if the tree needs to be collapsed. Set the flag +* to indicate that the calling function needs to move the +* shrink operation */ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) - goto out; - } +if (retval && (state->path.active >1 )) { + error =xfs_da3_join (state); +if (error) + goto out; -/* -* If the result is small enough, push it all into the inode. -*/ -if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) - error =xfs_attr_node_shrink (args, state); + dac->flags |=XFS_DAC_DEFER_FINISH ; + dac->dela_state =XFS_DAS_RM_SHRINK ; +return -EAGAIN ; + } + +/* fallthrough */ +case XFS_DAS_RM_SHRINK : +/* +* If the result is small enough, push it all into the inode. +*/ +if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) + error =xfs_attr_node_shrink (args, state); + +break ; +default : +ASSERT (0 ); + error = -EINVAL ; + goto out; + } +if (error == -EAGAIN ) +return error; out:if (state)xfs_da_state_free (state);...
Quoted 4 lines
fs/xfs/libxfs/xfs_attr_remote.c +0
-0...
Quoted 14 lines
fs/xfs/libxfs/xfs_attr_remote.c xfs_attr_rmtval_remove( · line 692
Quoted 10 lines
fs/xfs/libxfs/xfs_attr_remote.c +3
-3@@ -685,31 +687,29 @@ xfs_attr_rmtval_remove(* Keep de-allocating extents until the remote-value region is gone. */ do { - retval = __xfs_attr_rmtval_remove(args); - if (retval && retval != -EAGAIN) - return retval; + error = __xfs_attr_rmtval_remove(&dac); + if (error != -EAGAIN) + break;Shouldn't this retain the (error && error !=
-EAGAIN) logic to roll the transaction after the final unmap? Even if this is transient, it's probably best to preserve behavior if this is unintentional.Sure, I dont think it's intentional, I think back in v10 we had a different arangement here with a helper inside the
while()expression that had equivelent error handling logic. But that got nak'd in the next review and I think I likley forgot to put back this handling. Will fix.Quoted 6 lines
Otherwise my only remaining feedback was to add/tweak some comments that I think make the iteration function easier to follow. I've appended a diff for that. If you agree with the changes feel free to just fold them in and/or tweak as necessary. With those various nits and Chandan's feedback addressed, I think this patch looks pretty good.
Sure, those all look reasonable. Will add. Thanks for the reviews! Allison
Quoted 92 lines
Brian
--- 8< ---
fs/xfs/libxfs/xfs_attr.c +20
-10@@ -1289,14 +1289,21 @@ xfs_attr_remove_iter(if (!xfs_inode_hasattr (dp))return -ENOATTR ; +/* +* Shortform or leaf formats don't require transaction rolls and +* thus state transitions. Call the right helper and return. +*/ if (dp->i_afp->if_format ==XFS_DINODE_FMT_LOCAL ) {ASSERT (dp->i_afp->if_flags &XFS_IFINLINE );return xfs_attr_shortform_remove (args); } -if (xfs_bmap_one_block (dp,XFS_ATTR_FORK ))return xfs_attr_leaf_removename (args); +/* +* Node format may require transaction rolls. Set up the +* state context and fall into the state machine. +*/ if (!dac->da_state) { error =xfs_attr_node_removename_setup (dac);if (error)@@ -1304,7 +1311,7 @@ xfs_attr_remove_iter( state = dac->da_state; } -/* fallthrough */ +/* fallthrough */ case XFS_DAS_RMTBLK : dac->dela_state =XFS_DAS_RMTBLK ;@@ -1316,7 +1323,8 @@ xfs_attr_remove_iter(*/ if (args->rmtblkno >0 ) {/* -* May return -EAGAIN. Remove blocks until 0 is returned +* May return -EAGAIN. Roll and repeat until all remote +* blocks are removed. */ error =__xfs_attr_rmtval_remove (dac);if (error == -EAGAIN )@@ -1325,26 +1333,26 @@ xfs_attr_remove_iter( goto out;/* -* Refill the state structure with buffers, the prior -* calls released our buffers. +* Refill the state structure with buffers (the prior +* calls released our buffers) and close out this +* transaction before proceeding. */ ASSERT (args->rmtblkno ==0 ); error =xfs_attr_refillstate (state);if (error) goto out; - dac->dela_state =XFS_DAS_CLNUP ; dac->flags |=XFS_DAC_DEFER_FINISH ;return -EAGAIN ; } +/* fallthrough */ case XFS_DAS_CLNUP : retval =xfs_attr_node_remove_cleanup (args, state);/* -* Check to see if the tree needs to be collapsed. Set the flag -* to indicate that the calling function needs to move the -* shrink operation +* Check to see if the tree needs to be collapsed. If so, roll +* the transacton and fall into the shrink state. */ if (retval && (state->path.active >1 )) { error =xfs_da3_join (state);@@ -1360,10 +1368,12 @@ xfs_attr_remove_iter(case XFS_DAS_RM_SHRINK :/* * If the result is small enough, push it all into the inode. +* This is our final state so it's safe to return a dirty +* transaction. */ if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) error =xfs_attr_node_shrink (args, state); - +ASSERT (error != -EAGAIN );break ;default :ASSERT (0 );
PATCH v17 11/11 xfs: Add delay ready attr set routines
In reply to Allison HendersonThis 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. See xfs_attr.h for a more detailed diagram of the states.
Two new helper functions have been added: xfs_attr_rmtval_find_space 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.
--- fs/xfs/libxfs/xfs_attr.c | 445 ++++++++++++++++++++++++---------------- fs/xfs/libxfs/xfs_attr.h | 272 +++++++++++++++++++++++- fs/xfs/libxfs/xfs_attr_remote.c | 100 ++++++--- fs/xfs/libxfs/xfs_attr_remote.h | 5 +- fs/xfs/xfs_trace.h | 1 - 5 files changed, 613 insertions(+), 210 deletions(-)
fs/xfs/libxfs/xfs_attr.c +272 -173
@@ -53,15 +53,16 @@ STATIC int xfs_attr_leaf_try_add(struct xfs_da_args *args, struct xfs_buf *bp);*/ STATIC int xfs_attr_node_get(xfs_da_args_t *args); STATIC void xfs_attr_restore_rmt_blk(struct xfs_da_args *args); -STATIC int xfs_attr_node_addname(struct xfs_da_args *args, -struct xfs_da_state *state); -STATIC int xfs_attr_node_addname_find_attr(struct xfs_da_args *args, -struct xfs_da_state **state); -STATIC int xfs_attr_node_addname_clear_incomplete(struct xfs_da_args *args); +STATIC int xfs_attr_node_addname(struct xfs_delattr_context *dac); +STATIC int xfs_attr_node_addname_find_attr(struct xfs_delattr_context *dac); +STATIC int xfs_attr_node_addname_clear_incomplete( +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_set_iter(struct xfs_delattr_context *dac, +struct xfs_buf **leaf_bp);int xfs_inode_hasattr(
@@ -224,7 +225,7 @@ xfs_attr_is_shortform(* Checks to see if a delayed attribute transaction should be rolled. If so, * transaction is finished or rolled as needed. */ -int +STATIC intxfs_attr_trans_roll (struct xfs_delattr_context *dac) {
@@ -245,29 +246,58 @@ xfs_attr_trans_roll(return error; } +/* +* Set the attribute specified in @args. +*/ +int +xfs_attr_set_args ( +struct xfs_da_args *args) +{ +struct xfs_buf *leaf_bp =NULL ; +int error =0 ; +struct xfs_delattr_context dac = { + .da_args = args, + }; + +do { + error =xfs_attr_set_iter (&dac, &leaf_bp); +if (error != -EAGAIN ) +break ; + + error =xfs_attr_trans_roll (&dac); +if (error) { +if (leaf_bp) +xfs_trans_brelse (args->trans, leaf_bp); +return error; + } + }while (true); + +return error; +} + STATIC intxfs_attr_set_fmt ( -struct xfs_da_args *args) +struct xfs_delattr_context *dac, +struct xfs_buf **leaf_bp) { -struct xfs_buf *leaf_bp =NULL ; -struct xfs_inode *dp = args->dp; -int error2, error =0 ; +struct xfs_da_args *args = dac->da_args; +struct xfs_inode *dp = args->dp; +int error =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; - } + +/* Should only be 0, -EEXIST or -ENOSPC */ +if (error != -ENOSPC ) +return error;/* * It won't fit in the shortform, transform to a leaf block. * GROT: another possible req'mt for a double-split btree op. */ - error =xfs_attr_shortform_to_leaf (args, &leaf_bp); + error =xfs_attr_shortform_to_leaf (args, leaf_bp);if (error)return error;
@@ -276,94 +306,130 @@ xfs_attr_set_fmt(* concurrent AIL push cannot grab the half-baked leaf buffer * and run into problems with the write verifier. */ -xfs_trans_bhold (args->trans, leaf_bp); - 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; - } +xfs_trans_bhold (args->trans, *leaf_bp); +/* +* We're still in XFS_DAS_UNINIT state here. We've converted +* the attr fork to leaf format and will restart with the leaf +* add. +*/ + dac->flags |=XFS_DAC_DEFER_FINISH ;return -EAGAIN ; }/* * 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_args ( -struct xfs_da_args *args) +xfs_attr_set_iter ( +struct xfs_delattr_context *dac, +struct xfs_buf **leaf_bp) { -struct xfs_inode *dp = args->dp; -struct xfs_buf *bp =NULL ; -struct xfs_da_state *state =NULL ; -int forkoff, error =0 ; +struct xfs_da_args *args = dac->da_args; +struct xfs_inode *dp = args->dp; +struct xfs_buf *bp =NULL ; +int forkoff, error =0 ; -/* -* 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 (xfs_attr_is_shortform (dp)) { - error =xfs_attr_set_fmt (args); -if (error != -EAGAIN ) -return error; - } +/* State machine switch */ +switch (dac->dela_state) { +case XFS_DAS_UNINIT : +if (xfs_attr_is_shortform (dp)) +return xfs_attr_set_fmt (dac, leaf_bp); -if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) { - error =xfs_attr_leaf_try_add (args, bp); -if (error == -ENOSPC ) { -/* -* Promote the attribute list to the Btree format. -*/ - error =xfs_attr3_leaf_to_node (args); -if (error) +/* +* After a shortform to leaf conversion, we need to hold the +* leaf and cycle out the transaction. When we get back, +* we need to release the leaf to release the hold on the leaf +* buffer. +*/ +if (*leaf_bp !=NULL ) { +xfs_trans_bhold_release (args->trans, *leaf_bp); + *leaf_bp =NULL ; + } + +if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) { + error =xfs_attr_leaf_try_add (args, *leaf_bp); +if (error == -ENOSPC ) { +/* +* Promote the attribute list to the Btree +* format. +*/ + error =xfs_attr3_leaf_to_node (args); +if (error) +return error; + +/* +* Finish any deferred work items and roll the +* transaction once more. The goal here is to +* call node_addname with the inode and +* transaction in the same state (inode locked +* and joined, transaction clean) no matter how +* we got to this step. +* +* At this point, we are still in +* XFS_DAS_UNINIT, but when we come back, we'll +* be a node, so we'll fall down into the node +* handling code below +*/ + dac->flags |=XFS_DAC_DEFER_FINISH ; +return -EAGAIN ; + }else if (error) {return error; + } -/* -* Finish any deferred work items and roll the transaction once -* more. The goal here is to call node_addname with the inode -* and transaction in the same state (inode locked and joined, -* transaction clean) no matter how we got to this step. -*/ - error =xfs_defer_finish (&args->trans); + dac->dela_state =XFS_DAS_FOUND_LBLK ; +return -EAGAIN ; + + }else { + error =xfs_attr_node_addname_find_attr (dac);if (error)return error; -/* -* Commit the current trans (including the inode) and -* start a new one. -*/ - error =xfs_trans_roll_inode (&args->trans, dp); + error =xfs_attr_node_addname (dac);if (error)return error; - goto node; - }else if (error) { -return error; + dac->dela_state =XFS_DAS_FOUND_NBLK ; +return -EAGAIN ; } - -/* -* 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; - +case XFS_DAS_FOUND_LBLK :/* * If there was an out-of-line value, allocate the blocks we * identified for its storage and copy the value. This is done * after we create the attribute so that we don't overflow the * maximum size of a transaction and/or hit a deadlock. */ -if (args->rmtblkno >0 ) { - 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_find_space (dac); +if (error) +return error; + } + } + +/* +* Roll through the "value", allocating blocks on disk as +* required. +*/ +if (dac->blkcnt >0 ) { + error =xfs_attr_rmtval_set_blk (dac);if (error)return error; + +return -EAGAIN ; } + error =xfs_attr_rmtval_set_value (args); +if (error) +return error; +if (!(args->op_flags &XFS_DA_OP_RENAME )) {/* * Added a "remote" value, just clear the incomplete
@@ -392,26 +458,35 @@ xfs_attr_set_args(* 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 ; +case XFS_DAS_FLIP_LFLAG :/* * 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; + +/* Set state in case xfs_attr_rmtval_remove returns -EAGAIN */ + dac->dela_state =XFS_DAS_RM_LBLK ; + +/* fallthrough */ +case XFS_DAS_RM_LBLK :if (args->rmtblkno) { - error =xfs_attr_rmtval_invalidate (args); + error =__xfs_attr_rmtval_remove (dac);if (error)return error; - error =xfs_attr_rmtval_remove (args); -if (error) -return error; + dac->dela_state =XFS_DAS_RD_LEAF ; +return -EAGAIN ; } +/* fallthrough */ +case XFS_DAS_RD_LEAF :/* * Read in the block containing the "old" attr, then remove the * "old" attr from that block (neat, huh!)
@@ -432,89 +507,113 @@ xfs_attr_set_args(/* bp is gone due to xfs_da_shrink_inode */ return error; - } -node: +case XFS_DAS_FOUND_NBLK : +/* +* If there was an out-of-line value, allocate the blocks we +* identified for its storage and copy the value. This is done +* after we create the attribute so that we don't overflow the +* maximum size of a transaction and/or hit a deadlock. +*/ +if (args->rmtblkno >0 ) { +/* +* Open coded xfs_attr_rmtval_set without trans +* handling +*/ + error =xfs_attr_rmtval_find_space (dac); +if (error) +return error; -do { - error =xfs_attr_node_addname_find_attr (args, &state); -if (error) -return error; - error =xfs_attr_node_addname (args, state); - }while (error == -EAGAIN ); -if (error) -return error; +/* +* Roll through the "value", allocating blocks on disk +* as required. Set the state in case of -EAGAIN return +* code +*/ + dac->dela_state =XFS_DAS_ALLOC_NODE ; + } -/* -* 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; +/* fallthrough */ +case XFS_DAS_ALLOC_NODE : +if (args->rmtblkno >0 ) { +if (dac->blkcnt >0 ) { + error =xfs_attr_rmtval_set_blk (dac); +if (error) +return error; -/* -* If there was an out-of-line value, allocate the blocks we -* identified for its storage and copy the value. This is done -* after we create the attribute so that we don't overflow the -* maximum size of a transaction and/or hit a deadlock. -*/ -if (args->rmtblkno >0 ) { - error =xfs_attr_rmtval_set (args); -if (error) -return error; - } +return -EAGAIN ; + } + + error =xfs_attr_rmtval_set_value (args); +if (error) +return error; + } + +if (!(args->op_flags &XFS_DA_OP_RENAME )) { +/* +* Added a "remote" value, just clear the incomplete +* flag. +*/ +if (args->rmtblkno >0 ) + error =xfs_attr3_leaf_clearflag (args); + goto out; + } -if (!(args->op_flags &XFS_DA_OP_RENAME )) {/* -* Added a "remote" value, just clear the incomplete flag. +* 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. */ -if (args->rmtblkno >0 ) - error =xfs_attr3_leaf_clearflag (args); - goto out; - } - -/* -* 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; + error =xfs_attr3_leaf_flipflags (args); +if (error) + goto out; +/* +* Commit the flag value change and start the next trans in +* series +*/ + dac->dela_state =XFS_DAS_FLIP_NFLAG ; +return -EAGAIN ; -/* -* Dismantle the "old" attribute/value pair by removing a "remote" value -* (if it exists). -*/ -xfs_attr_restore_rmt_blk (args); +case XFS_DAS_FLIP_NFLAG : +/* +* 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; - error =xfs_attr_rmtval_remove (args); -if (error) -return error; - } +/* Set state in case xfs_attr_rmtval_remove returns -EAGAIN */ + dac->dela_state =XFS_DAS_RM_NBLK ; + +/* fallthrough */ +case XFS_DAS_RM_NBLK : +if (args->rmtblkno) { + error =__xfs_attr_rmtval_remove (dac); +if (error) +return error; - error =xfs_attr_node_addname_clear_incomplete (args); + dac->dela_state =XFS_DAS_CLR_FLAG ; +return -EAGAIN ; + } + +/* fallthrough */ +case XFS_DAS_CLR_FLAG : + error =xfs_attr_node_addname_clear_incomplete (dac); +default : +ASSERT (dac->dela_state !=XFS_DAS_RM_SHRINK ); +break ; + } out:return error; - } +/* * Return EEXIST if attr is found, or ENOATTR if not */
@@ -980,18 +1079,18 @@ xfs_attr_node_hasname( STATIC intxfs_attr_node_addname_find_attr ( -struct xfs_da_args *args, -struct xfs_da_state **state) +struct xfs_delattr_context *dac) { -int retval; +struct xfs_da_args *args = dac->da_args; +int retval;/* * Search to see if name already exists, and get back a pointer * to where it should go. */ - retval =xfs_attr_node_hasname (args, state); + retval =xfs_attr_node_hasname (args, &dac->da_state);if (retval != -ENOATTR && retval != -EEXIST ) - goto error; +return retval;if (retval == -ENOATTR && (args->attr_flags &XATTR_REPLACE )) goto error;
@@ -1017,8 +1116,8 @@ xfs_attr_node_addname_find_attr(return 0 ; error: -if (*state) -xfs_da_state_free (*state); +if (dac->da_state) +xfs_da_state_free (dac->da_state);return retval; }
@@ -1031,19 +1130,23 @@ xfs_attr_node_addname_find_attr(* * "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 intxfs_attr_node_addname ( -struct xfs_da_args *args, -struct xfs_da_state *state) +struct xfs_delattr_context *dac) { -struct xfs_da_state_blk *blk; -struct xfs_inode *dp; -int error; +struct xfs_da_args *args = dac->da_args; +struct xfs_da_state *state = dac->da_state; +struct xfs_da_state_blk *blk; +int error;trace_xfs_attr_node_addname (args); - dp = args->dp; blk = &state->path.blk[state->path.active-1 ];ASSERT (blk->magic ==XFS_ATTR_LEAF_MAGIC );
@@ -1060,18 +1163,15 @@ 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. +* Now that we have converted the leaf to a node, we can +* roll the transaction, and try xfs_attr3_leaf_add +* again on re-entry. No need to set dela_state to do +* this. dela_state is still unset by this function at +* this point. */ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) - goto out; - + dac->flags |=XFS_DAC_DEFER_FINISH ;return -EAGAIN ; }
@@ -1084,9 +1184,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.
@@ -1103,8 +1201,9 @@ xfs_attr_node_addname(STATIC int xfs_attr_node_addname_clear_incomplete( -struct xfs_da_args *args) +struct xfs_delattr_context *dac) { +struct xfs_da_args *args = dac->da_args;struct xfs_da_state *state =NULL ;struct xfs_da_state_blk *blk;int retval =0 ;
fs/xfs/libxfs/xfs_attr.h +271 -1
302 lines not on this page · raw message
fs/xfs/libxfs/xfs_attr_remote.c +66 -34
125 lines not on this page · raw message
fs/xfs/libxfs/xfs_attr_remote.h +4 -1
@@ -10,9 +10,12 @@ int xfs_attr3_rmt_blocks(struct xfs_mount *mp, int attrlen);int xfs_attr_rmtval_get (struct xfs_da_args *args);int xfs_attr_rmtval_set (struct xfs_da_args *args); -int xfs_attr_rmtval_remove (struct xfs_da_args *args);int xfs_attr_rmtval_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_find_space (struct xfs_delattr_context *dac);#endif /* __XFS_ATTR_REMOTE_H__ */
fs/xfs/xfs_trace.h +0 -1
@@ -1943,7 +1943,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
Re: [PATCH v17 11/11] xfs: Add delay ready attr set routines
Quoted 17 lines · Allison Henderson
This patch modifies the attr set routines to be delay ready. This means they no longer roll or commit transactions, but instead return
-EAGAINto have the calling routine roll and refresh the transaction. In this series,xfs_attr_set_argshas becomexfs_attr_set_iter, which uses a state machine like switch to keep track of where it was when EAGAIN was returned. Seexfs_attr.hfor a more detailed diagram of the states.Two new helper functions have been added:
xfs_attr_rmtval_find_spaceandxfs_attr_rmtval_set_blk. They provide a subset of logic similar toxfs_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 byxfs_attr_leaf_addnameandxfs_attr_node_addname.xfs_attr_set_argshas now become a simple loop to refresh the transaction until the operation is completed. Lastly,xfs_attr_rmtval_removeis no longer used, and is removed.
Quoted 4 lines
Signed-off-by Allison Henderson <[email protected]>Reviewed-by Chandan Babu R <[email protected]>Reviewed-by Darrick J. Wong <[email protected]>---
This one looks good to me. My feedback is mostly around some code formatting and comments, so again I've just appended a diff for your review. With the various nits addressed:
--- 8< ---
fs/xfs/libxfs/xfs_attr.c +39 -55
@@ -337,15 +337,15 @@ xfs_attr_set_iter(/* State machine switch */ switch (dac->dela_state) {case XFS_DAS_UNINIT : -if (xfs_attr_is_shortform (dp)) -return xfs_attr_set_fmt (dac, leaf_bp); -/* -* After a shortform to leaf conversion, we need to hold the -* leaf and cycle out the transaction. When we get back, -* we need to release the leaf to release the hold on the leaf -* buffer. +* If the fork is shortform, attempt to add the attr. If there +* is no space, this converts to leaf format and returns +* -EAGAIN with the leaf buffer held across the roll. The caller +* will deal with a transaction roll error, but otherwise +* release the hold once we return with a clean transaction. */ +if (xfs_attr_is_shortform (dp)) +return xfs_attr_set_fmt (dac, leaf_bp);if (*leaf_bp !=NULL ) {xfs_trans_bhold_release (args->trans, *leaf_bp); *leaf_bp =NULL ;
@@ -354,10 +354,6 @@ xfs_attr_set_iter(if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) { error =xfs_attr_leaf_try_add (args, *leaf_bp);if (error == -ENOSPC ) { -/* -* Promote the attribute list to the Btree -* format. -*/ error =xfs_attr3_leaf_to_node (args);if (error)return error;
@@ -382,8 +378,6 @@ xfs_attr_set_iter( } dac->dela_state =XFS_DAS_FOUND_LBLK ; -return -EAGAIN ; - }else { error =xfs_attr_node_addname_find_attr (dac);if (error)
@@ -394,8 +388,8 @@ xfs_attr_set_iter(return error; dac->dela_state =XFS_DAS_FOUND_NBLK ; -return -EAGAIN ; } +return -EAGAIN ;case XFS_DAS_FOUND_LBLK :/* * If there was an out-of-line value, allocate the blocks we
@@ -415,14 +409,13 @@ xfs_attr_set_iter( }/* -* Roll through the "value", allocating blocks on disk as -* required. +* Repeat allocating remote blocks for the attr value until +* blkcnt drops to zero. */ if (dac->blkcnt >0 ) { error =xfs_attr_rmtval_set_blk (dac);if (error)return error; -return -EAGAIN ; }
@@ -430,14 +423,13 @@ xfs_attr_set_iter(if (error)return error; +/* +* If this is not a rename, clear the incomplete flag and we're +* done. +*/ if (!(args->op_flags &XFS_DA_OP_RENAME )) { -/* -* Added a "remote" value, just clear the incomplete -*flag. -*/ if (args->rmtblkno >0 ) error =xfs_attr3_leaf_clearflag (args); -return error; }
@@ -450,7 +442,6 @@ xfs_attr_set_iter(* 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;
@@ -466,16 +457,14 @@ xfs_attr_set_iter(* "remote" value (if it exists). */ xfs_attr_restore_rmt_blk (args); - error =xfs_attr_rmtval_invalidate (args);if (error)return error; -/* Set state in case xfs_attr_rmtval_remove returns -EAGAIN */ - dac->dela_state =XFS_DAS_RM_LBLK ; -/* fallthrough */ case XFS_DAS_RM_LBLK : +/* Set state in case xfs_attr_rmtval_remove returns -EAGAIN */ + dac->dela_state =XFS_DAS_RM_LBLK ;if (args->rmtblkno) { error =__xfs_attr_rmtval_remove (dac);if (error)
@@ -488,8 +477,9 @@ xfs_attr_set_iter(/* fallthrough */ case XFS_DAS_RD_LEAF :/* -* Read in the block containing the "old" attr, then remove the -* "old" attr from that block (neat, huh!) +* This is the last step for leaf format. Read the block with +* the old attr, remove the old attr, check for shortform +* conversion and return. */ error =xfs_attr3_leaf_read (args->trans, args->dp, args->blkno, &bp);
@@ -498,9 +488,6 @@ xfs_attr_set_iter(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);
@@ -510,36 +497,29 @@ xfs_attr_set_iter(case XFS_DAS_FOUND_NBLK :/* -* If there was an out-of-line value, allocate the blocks we -* identified for its storage and copy the value. This is done -* after we create the attribute so that we don't overflow the -* maximum size of a transaction and/or hit a deadlock. +* Find space for remote blocks and fall into the allocation +* state. */ if (args->rmtblkno >0 ) { -/* -* Open coded xfs_attr_rmtval_set without trans -* handling -*/ error =xfs_attr_rmtval_find_space (dac);if (error)return error; - -/* -* Roll through the "value", allocating blocks on disk -* as required. Set the state in case of -EAGAIN return -* code -*/ - dac->dela_state =XFS_DAS_ALLOC_NODE ; }/* fallthrough */ case XFS_DAS_ALLOC_NODE : +/* +* If there was an out-of-line value, allocate the blocks we +* identified for its storage and copy the value. This is done +* after we create the attribute so that we don't overflow the +* maximum size of a transaction and/or hit a deadlock. +*/ + dac->dela_state =XFS_DAS_ALLOC_NODE ;if (args->rmtblkno >0 ) {if (dac->blkcnt >0 ) { error =xfs_attr_rmtval_set_blk (dac);if (error)return error; -return -EAGAIN ; }
@@ -548,11 +528,11 @@ xfs_attr_set_iter(return error; } +/* +* If this was not a rename, clear the incomplete flag and we're +* done. +*/ if (!(args->op_flags &XFS_DA_OP_RENAME )) { -/* -* Added a "remote" value, just clear the incomplete -* flag. -*/ if (args->rmtblkno >0 ) error =xfs_attr3_leaf_clearflag (args); goto out;
@@ -588,11 +568,10 @@ xfs_attr_set_iter(if (error)return error; -/* Set state in case xfs_attr_rmtval_remove returns -EAGAIN */ - dac->dela_state =XFS_DAS_RM_NBLK ; -/* fallthrough */ case XFS_DAS_RM_NBLK : +/* Set state in case xfs_attr_rmtval_remove returns -EAGAIN */ + dac->dela_state =XFS_DAS_RM_NBLK ;if (args->rmtblkno) { error =__xfs_attr_rmtval_remove (dac);if (error)
@@ -604,7 +583,12 @@ xfs_attr_set_iter(/* fallthrough */ case XFS_DAS_CLR_FLAG : +/* +* The last state for node format. Look up the old attr and +* remove it. +*/ error =xfs_attr_node_addname_clear_incomplete (dac); +break ;default :ASSERT (dac->dela_state !=XFS_DAS_RM_SHRINK );break ;
Re: [PATCH v17 11/11] xfs: Add delay ready attr set routines
Quoted 23 lines · Brian Foster
Quoted 17 lines · Allison Henderson
This patch modifies the attr set routines to be delay ready. This means they no longer roll or commit transactions, but instead return
-EAGAINto have the calling routine roll and refresh the transaction. In this series,xfs_attr_set_argshas becomexfs_attr_set_iter, which uses a state machine like switch to keep track of where it was when EAGAIN was returned. Seexfs_attr.hfor a more detailed diagram of the states.Two new helper functions have been added:
xfs_attr_rmtval_find_spaceandxfs_attr_rmtval_set_blk. They provide a subset of logic similar toxfs_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 byxfs_attr_leaf_addnameandxfs_attr_node_addname.xfs_attr_set_argshas now become a simple loop to refresh the transaction until the operation is completed. Lastly,xfs_attr_rmtval_removeis no longer used, and is removed.Quoted 4 lines
Signed-off-by Allison Henderson <[email protected]>Reviewed-by Chandan Babu R <[email protected]>Reviewed-by Darrick J. Wong <[email protected]>---
Quoted 5 lines
This one looks good to me. My feedback is mostly around some code formatting and comments, so again I've just appended a diff for your review. With the various nits addressed:
Reviewed-by Brian Foster <[email protected]>
Alrighty, I gave it a look through, and it looks fine to me. I'll test it and fold it into the next version. Thanks again for all the reviews!
Allison
Quoted 235 lines
--- 8< ---
fs/xfs/libxfs/xfs_attr.c +39
-55@@ -337,15 +337,15 @@ xfs_attr_set_iter(/* State machine switch */ switch (dac->dela_state) {case XFS_DAS_UNINIT : -if (xfs_attr_is_shortform (dp)) -return xfs_attr_set_fmt (dac, leaf_bp); -/* -* After a shortform to leaf conversion, we need to hold the -* leaf and cycle out the transaction. When we get back, -* we need to release the leaf to release the hold on the leaf -* buffer. +* If the fork is shortform, attempt to add the attr. If there +* is no space, this converts to leaf format and returns +* -EAGAIN with the leaf buffer held across the roll. The caller +* will deal with a transaction roll error, but otherwise +* release the hold once we return with a clean transaction. */ +if (xfs_attr_is_shortform (dp)) +return xfs_attr_set_fmt (dac, leaf_bp);if (*leaf_bp !=NULL ) {xfs_trans_bhold_release (args->trans, *leaf_bp); *leaf_bp =NULL ;@@ -354,10 +354,6 @@ xfs_attr_set_iter(if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) { error =xfs_attr_leaf_try_add (args, *leaf_bp);if (error == -ENOSPC ) { -/* -* Promote the attribute list to the Btree -* format. -*/ error =xfs_attr3_leaf_to_node (args);if (error)return error;@@ -382,8 +378,6 @@ xfs_attr_set_iter( } dac->dela_state =XFS_DAS_FOUND_LBLK ; -return -EAGAIN ; - }else { error =xfs_attr_node_addname_find_attr (dac);if (error)@@ -394,8 +388,8 @@ xfs_attr_set_iter(return error; dac->dela_state =XFS_DAS_FOUND_NBLK ; -return -EAGAIN ; } +return -EAGAIN ;case XFS_DAS_FOUND_LBLK :/* * If there was an out-of-line value, allocate the blocks we @@ -415,14 +409,13 @@ xfs_attr_set_iter( }/* -* Roll through the "value", allocating blocks on disk as -* required. +* Repeat allocating remote blocks for the attr value until +* blkcnt drops to zero. */ if (dac->blkcnt >0 ) { error =xfs_attr_rmtval_set_blk (dac);if (error)return error; -return -EAGAIN ; }@@ -430,14 +423,13 @@ xfs_attr_set_iter(if (error)return error; +/* +* If this is not a rename, clear the incomplete flag and we're +* done. +*/ if (!(args->op_flags &XFS_DA_OP_RENAME )) { -/* -* Added a "remote" value, just clear the incomplete -*flag. -*/ if (args->rmtblkno >0 ) error =xfs_attr3_leaf_clearflag (args); -return error; }@@ -450,7 +442,6 @@ xfs_attr_set_iter(* 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;@@ -466,16 +457,14 @@ xfs_attr_set_iter(* "remote" value (if it exists). */ xfs_attr_restore_rmt_blk (args); - error =xfs_attr_rmtval_invalidate (args);if (error)return error; -/* Set state in case xfs_attr_rmtval_remove returns -EAGAIN */ - dac->dela_state =XFS_DAS_RM_LBLK ; -/* fallthrough */ case XFS_DAS_RM_LBLK : +/* Set state in case xfs_attr_rmtval_remove returns -EAGAIN */ + dac->dela_state =XFS_DAS_RM_LBLK ;if (args->rmtblkno) { error =__xfs_attr_rmtval_remove (dac);if (error)@@ -488,8 +477,9 @@ xfs_attr_set_iter(/* fallthrough */ case XFS_DAS_RD_LEAF :/* -* Read in the block containing the "old" attr, then remove the -* "old" attr from that block (neat, huh!) +* This is the last step for leaf format. Read the block with +* the old attr, remove the old attr, check for shortform +* conversion and return. */ error =xfs_attr3_leaf_read (args->trans, args->dp, args->blkno, &bp);@@ -498,9 +488,6 @@ xfs_attr_set_iter(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);@@ -510,36 +497,29 @@ xfs_attr_set_iter(case XFS_DAS_FOUND_NBLK :/* -* If there was an out-of-line value, allocate the blocks we -* identified for its storage and copy the value. This is done -* after we create the attribute so that we don't overflow the -* maximum size of a transaction and/or hit a deadlock. +* Find space for remote blocks and fall into the allocation +* state. */ if (args->rmtblkno >0 ) { -/* -* Open coded xfs_attr_rmtval_set without trans -* handling -*/ error =xfs_attr_rmtval_find_space (dac);if (error)return error; - -/* -* Roll through the "value", allocating blocks on disk -* as required. Set the state in case of -EAGAIN return -* code -*/ - dac->dela_state =XFS_DAS_ALLOC_NODE ; }/* fallthrough */ case XFS_DAS_ALLOC_NODE : +/* +* If there was an out-of-line value, allocate the blocks we +* identified for its storage and copy the value. This is done +* after we create the attribute so that we don't overflow the +* maximum size of a transaction and/or hit a deadlock. +*/ + dac->dela_state =XFS_DAS_ALLOC_NODE ;if (args->rmtblkno >0 ) {if (dac->blkcnt >0 ) { error =xfs_attr_rmtval_set_blk (dac);if (error)return error; -return -EAGAIN ; }@@ -548,11 +528,11 @@ xfs_attr_set_iter(return error; } +/* +* If this was not a rename, clear the incomplete flag and we're +* done. +*/ if (!(args->op_flags &XFS_DA_OP_RENAME )) { -/* -* Added a "remote" value, just clear the incomplete -* flag. -*/ if (args->rmtblkno >0 ) error =xfs_attr3_leaf_clearflag (args); goto out;@@ -588,11 +568,10 @@ xfs_attr_set_iter(if (error)return error; -/* Set state in case xfs_attr_rmtval_remove returns -EAGAIN */ - dac->dela_state =XFS_DAS_RM_NBLK ; -/* fallthrough */ case XFS_DAS_RM_NBLK : +/* Set state in case xfs_attr_rmtval_remove returns -EAGAIN */ + dac->dela_state =XFS_DAS_RM_NBLK ;if (args->rmtblkno) { error =__xfs_attr_rmtval_remove (dac);if (error)@@ -604,7 +583,12 @@ xfs_attr_set_iter(/* fallthrough */ case XFS_DAS_CLR_FLAG : +/* +* The last state for node format. Look up the old attr and +* remove it. +*/ error =xfs_attr_node_addname_clear_incomplete (dac); +break ;default :ASSERT (dac->dela_state !=XFS_DAS_RM_SHRINK );break ;