xfs: Delayed Attributes
v15 cover xfs: Delayed Attributes
Hi all,
This set is a subset of a larger series for parent pointers. Delayed attributes allow attribute operations (set and remove) to be logged and committed in the same way that other delayed operations do. This 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.
At the moment, I would like people to focus their review efforts on just this "delayed attribute" sub series, as I think that is a more conservative use of peoples review time. I also think the set is a bit much to manage all at once, and we need to get the infrastructure ironed out before we focus too much anything that depends on it. But I do have the extended series for folks that want to see the bigger picture of where this is going.
To help organize the set, I've arranged the patches to make sort of mini sets. I thought it would help reviewers break down the reviewing some. For reviewing purposes, the set could be broken up into 2 phases:
Delay Ready Attributes: (patches 1-15)
Some of these are the remaining patches belonging to the "Delay Ready" series that we've been working with. In these patches, transaction handling is removed from the attr routines, and replaced with a state machine that allows a high level function to roll the transaction and repeatedly recall the attr routines until they are finished. Patches 4-12 correspond to a refactoring RFC effort that Brian and I had worked on earlier. The lower level versions of the RFC patch deviates slightly to correct some minor logic bugs not seen in the RFC. I further continued the refactoring to hoist the last state up into the xfs_attr_set_iter routine. The final product does create a bit of a monster function, but the state management code is much more linear than in previous versions. It should be noted that while some of these new patches look a little odd, their purpose is neither to optimize aesthetics, or even the hoist. The goal is to prepare an arrangement of the code such that the code changes in patch 12 are minimal and limited to state machine mechanics. As in previous revisions, the final product of this sub series is that the attr routines are now compatible as a .finish_item call back.
xfs: Add helper xfs_attr_node_remove_step
xfs: Add xfs_attr_node_remove_cleanup
xfs: Hoist transaction handling in xfs_attr_node_remove_step
xfs: Hoist xfs_attr_set_shortform
xfs: Add helper xfs_attr_set_fmt
xfs: Separate xfs_attr_node_addname and xfs_attr_node_addname_work
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
xfs: Add state machine tracepoints
xfs: Rename __xfs_attr_rmtval_remove
xfs: Handle krealloc errors in xlog_recover_add_to_cont_trans
Delayed Attributes: (patches 15 - 22)
These patches go on to fully implement delayed attributes. New attr intent and done items are introduced for use in the existing logging infrastructure. A mount option is added to toggle the feature on and off, and an error tag is added to test the log replay
xfs: Set up infastructure for deferred attribute operations
xfs: Skip flip flags for delayed attrs
xfs: Add xfs_attr_set_deferred and xfs_attr_remove_deferred
xfs: Remove unused xfs_attr_*_args
xfs: Add delayed attributes error tag
xfs: Add delattr mount option
xfs: Merge xfs_delattr_context into xfs_attr_item
Updates since v14: Mostly re-layering the changes discussed in the rfc along with other minor nits from the last revision
xfs: Add helper xfs_attr_node_remove_step
Typo nits in commit message
xfs: Hoist transaction handling in xfs_attr_node_remove_step
Fixed typo in commit message
removed unused dp variable from xfs_attr_node_remove_step Changed "return error" to "goto out" in xfs_attr_node_removename
xfs: Add delay ready attr remove routines
Added extra xfs_freestate in xfs_attr_node_removename_setup rebase adjustments
xfs: Hoist xfs_attr_set_shortform
NEW
xfs: Add helper xfs_attr_set_fmt
NEW
xfs: Separate xfs_attr_node_addname and xfs_attr_node_addname_work
NEW
xfs: Add helper xfs_attr_node_addname_find_attr
NEW
xfs: Hoist xfs_attr_node_addname
NEW
xfs: Hoist xfs_attr_leaf_addname
NEW
xfs: Hoist node transaction handling
NEW
xfs: Add delay ready attr set routines
Fixed typos in comments and commit message Rebased onto refactoring additions
All state management appears in xfs_attr_set_iter State machine gotos replaced with switch Flow chart updated
xfs: Add state machine tracepoints
Rebase adjustments
Added inode to trace data
Added separate traces types for each function
xfs: Rename __xfs_attr_rmtval_remove
Rebase adjustments
xfs: Handle krealloc errors in xlog_recover_add_to_cont_trans
Expanded commit message about alloc warnings
xfs: Skip flip flags for delayed attrs
Rebase adjustments
xfs: Remove unused xfs_attr_*_args
Rebase adjustments
xfs: Merge xfs_delattr_context into xfs_attr_item
Rebase adjustments
xfsprogs: Introduce error injection to allocate only minlen size extents for files
Ported as a rebase dependancy
Amended io/inject.c with error tag name to avoid compiler errors
xfsprogs: Introduce error injection to reduce maximum inode fork extent count
Ported as a rebase dependancy
Amended io/inject.c with error tag name to avoid compiler errors
This series can be viewed on github here:
https://github.com/allisonhenderson/xfs_work/tree/delay_ready_attrs_v15
As well as the extended delayed attribute and parent pointer series:
https://github.com/allisonhenderson/xfs_work/tree/delay_ready_attrs_v15_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_v15
https://github.com/allisonhenderson/xfs_work/tree/delay_ready_attrs_xfsprogs_v15_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 Collins (1):
xfs: Add helper xfs_attr_node_remove_step
xfs: Add xfs_attr_set_deferred and xfs_attr_remove_deferred
Allison Henderson (20):
xfs: Add xfs_attr_node_remove_cleanup
xfs: Hoist transaction handling in xfs_attr_node_remove_step
xfs: Hoist xfs_attr_set_shortform
xfs: Add helper xfs_attr_set_fmt
xfs: Separate xfs_attr_node_addname and xfs_attr_node_addname_work
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
xfs: Add state machine tracepoints
xfs: Rename __xfs_attr_rmtval_remove
xfs: Handle krealloc errors in xlog_recover_add_to_cont_trans
xfs: Set up infastructure for deferred attribute operations
xfs: Skip flip flags for delayed attrs
xfs: Remove unused xfs_attr_*_args
xfs: Add delayed attributes error tag
xfs: Add delattr mount option
xfs: Merge xfs_delattr_context into xfs_attr_item
fs/xfs/Makefile | 1 + fs/xfs/libxfs/xfs_attr.c | 955 +++++++++++++++++++++++++--------------- fs/xfs/libxfs/xfs_attr.h | 366 ++++++++++++++- fs/xfs/libxfs/xfs_attr_leaf.c | 5 +- fs/xfs/libxfs/xfs_attr_remote.c | 127 ++++-- fs/xfs/libxfs/xfs_attr_remote.h | 7 +- fs/xfs/libxfs/xfs_defer.c | 1 + fs/xfs/libxfs/xfs_defer.h | 3 + fs/xfs/libxfs/xfs_errortag.h | 4 +- fs/xfs/libxfs/xfs_log_format.h | 44 +- fs/xfs/libxfs/xfs_log_recover.h | 2 + fs/xfs/scrub/common.c | 2 + fs/xfs/xfs_acl.c | 2 + fs/xfs/xfs_attr_inactive.c | 2 +- fs/xfs/xfs_attr_item.c | 830 ++++++++++++++++++++++++++++++++++ fs/xfs/xfs_attr_item.h | 52 +++ fs/xfs/xfs_attr_list.c | 1 + fs/xfs/xfs_error.c | 3 + fs/xfs/xfs_ioctl.c | 2 + fs/xfs/xfs_ioctl32.c | 2 + fs/xfs/xfs_iops.c | 2 + fs/xfs/xfs_log.c | 4 + fs/xfs/xfs_log_recover.c | 7 +- fs/xfs/xfs_mount.h | 1 + fs/xfs/xfs_ondisk.h | 2 + fs/xfs/xfs_super.c | 6 +- fs/xfs/xfs_trace.h | 26 +- fs/xfs/xfs_xattr.c | 3 + 28 files changed, 2056 insertions(+), 406 deletions(-) create mode 100644 fs/xfs/xfs_attr_item.c create mode 100644 fs/xfs/xfs_attr_item.h
Signature · 1 line
2.7.4
PATCH v15 1/22 xfs: Add helper xfs_attr_node_remove_step
From: Allison Collins <[email protected]>
This patch adds a new helper function xfs_attr_node_remove_step. This will help simplify and modularize the calling function xfs_attr_node_removename.
--- fs/xfs/libxfs/xfs_attr.c | 46 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 12 deletions(-)
fs/xfs/libxfs/xfs_attr.c +34 -12
@@ -1228,19 +1228,14 @@ xfs_attr_node_remove_rmt(* the root node (a special case of an intermediate node). */ STATIC int -xfs_attr_node_removename ( -struct xfs_da_args *args) +xfs_attr_node_remove_step ( +struct xfs_da_args *args, +struct xfs_da_state *state) { -struct xfs_da_state *state;struct xfs_da_state_blk *blk;int retval, error;struct xfs_inode *dp = args->dp; -trace_xfs_attr_node_removename (args); - - error =xfs_attr_node_removename_setup (args, &state); -if (error) - goto out;/* * If there is an out-of-line value, de-allocate the blocks.
@@ -1250,7 +1245,7 @@ xfs_attr_node_removename(if (args->rmtblkno >0 ) { error =xfs_attr_node_remove_rmt (args, state);if (error) - goto out; +return error; }/*
@@ -1267,18 +1262,45 @@ xfs_attr_node_removename(if (retval && (state->path.active >1 )) { error =xfs_da3_join (state);if (error) - goto out; +return error; error =xfs_defer_finish (&args->trans);if (error) - goto out; +return error;/* * Commit the Btree join operation and start a new trans. */ error =xfs_trans_roll_inode (&args->trans, dp);if (error) - goto out; +return error; } +return error; +} + +/* +* Remove a name from a B-tree attribute list. +* +* This routine will find the blocks of the name to remove, remove them and +* shrink the tree if needed. +*/ +STATIC int +xfs_attr_node_removename ( +struct xfs_da_args *args) +{ +struct xfs_da_state *state =NULL ; +int 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; + + error =xfs_attr_node_remove_step (args, state); +if (error) + goto out; +/* * If the result is small enough, push it all into the inode. */
Signature · 1 line
2.7.4
Re: [PATCH v15 01/22] xfs: Add helper xfs_attr_node_remove_step
Quoted 17 lines · Allison Henderson
From: Allison Collins <[email protected]>
This patch adds a new helper function
xfs_attr_node_remove_step. This will help simplify and modularize the calling functionxfs_attr_node_removename.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 | 46 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 12 deletions(-)fs/xfs/libxfs/xfs_attr.c +0
-0
...
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +2
-2@@ -1267,18 +1262,45 @@ xfs_attr_node_removename(if (retval && (state->path.active >1 )) { error =xfs_da3_join (state);if (error) - goto out; +return error; error =xfs_defer_finish (&args->trans);if (error) - goto out; +return error;
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_removename( · line 1277
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +2
-1/* * Commit the Btree join operation and start a new trans. */ error =xfs_trans_roll_inode (&args->trans, dp);if (error) - goto out; +return error; } +return error;
Maybe just return 0 here since it looks like error might not have been assigned..? With that fixed:
Quoted 32 lines
fs/xfs/libxfs/xfs_attr.c +26
-0+} + +/* +* Remove a name from a B-tree attribute list. +* +* This routine will find the blocks of the name to remove, remove them and +* shrink the tree if needed. +*/ +STATIC int +xfs_attr_node_removename ( +struct xfs_da_args *args) +{ +struct xfs_da_state *state =NULL ; +int 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; + + error =xfs_attr_node_remove_step (args, state); +if (error) + goto out; +/* * If the result is small enough, push it all into the inode. */ Signature · 1 line
2.7.4
Re: [PATCH v15 01/22] xfs: Add helper xfs_attr_node_remove_step
Quoted 38 lines · Brian Foster
Quoted 17 lines · Allison Henderson
From: Allison Collins <[email protected]>
This patch adds a new helper function
xfs_attr_node_remove_step. This will help simplify and modularize the calling functionxfs_attr_node_removename.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 | 46 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 12 deletions(-)fs/xfs/libxfs/xfs_attr.c +0
-0...
Quoted 19 lines
fs/xfs/libxfs/xfs_attr.c +3
-3@@ -1267,18 +1262,45 @@ xfs_attr_node_removename(if (retval && (state->path.active >1 )) { error =xfs_da3_join (state);if (error) - goto out; +return error; error =xfs_defer_finish (&args->trans);if (error) - goto out; +return error;/* * Commit the Btree join operation and start a new trans. */ error =xfs_trans_roll_inode (&args->trans, dp);if (error) - goto out; +return error; }
Quoted 6 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_removename( · line 1277
Quoted 1 line
fs/xfs/libxfs/xfs_attr.c +1
-0+return error;Maybe just return 0 here since it looks like error might not have been assigned..? With that fixed:
Reviewed-by Brian Foster <[email protected]>
Sure, will do. Thanks!
Allison
Quoted 34 lines
Quoted 33 lines
fs/xfs/libxfs/xfs_attr.c +26
-0+} + +/* +* Remove a name from a B-tree attribute list. +* +* This routine will find the blocks of the name to remove, remove them and +* shrink the tree if needed. +*/ +STATIC int +xfs_attr_node_removename ( +struct xfs_da_args *args) +{ +struct xfs_da_state *state =NULL ; +int 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; + + error =xfs_attr_node_remove_step (args, state); +if (error) + goto out; +/* * If the result is small enough, push it all into the inode. */ Signature · 1 line
2.7.4
PATCH v15 2/22 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
@@ -1220,6 +1220,25 @@ xfs_attr_node_remove_rmt(return xfs_attr_refillstate (state); } +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. *
@@ -1232,7 +1251,6 @@ xfs_attr_node_remove_step(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;
@@ -1247,14 +1265,7 @@ xfs_attr_node_remove_step(if (error)return error; } - -/* -* Remove the name and update the hashvals in the tree. -*/ - blk = &state->path.blk[ state->path.active-1 ]; -ASSERT (blk->magic ==XFS_ATTR_LEAF_MAGIC ); - 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
Re: [PATCH v15 02/22] xfs: Add xfs_attr_node_remove_cleanup
Quoted 8 lines · Allison Henderson
This patch pulls a new helper function
xfs_attr_node_remove_cleanupout ofxfs_attr_node_remove_step. This helps to modularizexfs_attr_node_remove_stepwhich will help make the delayed attribute code easier to followSigned-off-by Allison Henderson <[email protected]>Reviewed-by Chandan Babu R <[email protected]>---
Looks like I sent a review for this on v14...
Quoted 60 lines
fs/xfs/libxfs/xfs_attr.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-)fs/xfs/libxfs/xfs_attr.c +20
-9@@ -1220,6 +1220,25 @@ xfs_attr_node_remove_rmt(return xfs_attr_refillstate (state); } +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. * @@ -1232,7 +1251,6 @@ xfs_attr_node_remove_step(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;@@ -1247,14 +1265,7 @@ xfs_attr_node_remove_step(if (error)return error; } - -/* -* Remove the name and update the hashvals in the tree. -*/ - blk = &state->path.blk[ state->path.active-1 ]; -ASSERT (blk->magic ==XFS_ATTR_LEAF_MAGIC ); - 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
Re: [PATCH v15 02/22] xfs: Add xfs_attr_node_remove_cleanup
Quoted 6 lines · Brian Foster
Quoted 5 lines · Allison Henderson
This patch pulls a new helper function
xfs_attr_node_remove_cleanupout ofxfs_attr_node_remove_step. This helps to modularizexfs_attr_node_remove_stepwhich will help make the delayed attribute code easier to follow
Quoted 7 lines
Quoted 3 lines
Signed-off-by Allison Henderson <[email protected]>Reviewed-by Chandan Babu R <[email protected]>---
Looks like I sent a review for this on v14...
Reviewed-by Brian Foster <[email protected]>
Sorry about that, I got tied up in the extra refactoring. Will add. Thanks again!
Allison
Quoted 62 lines
Quoted 61 lines
fs/xfs/libxfs/xfs_attr.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-)fs/xfs/libxfs/xfs_attr.c +20
-9@@ -1220,6 +1220,25 @@ xfs_attr_node_remove_rmt(return xfs_attr_refillstate (state); } +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. * @@ -1232,7 +1251,6 @@ xfs_attr_node_remove_step(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;@@ -1247,14 +1265,7 @@ xfs_attr_node_remove_step(if (error)return error; } - -/* -* Remove the name and update the hashvals in the tree. -*/ - blk = &state->path.blk[ state->path.active-1 ]; -ASSERT (blk->magic ==XFS_ATTR_LEAF_MAGIC ); - 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
Re: [PATCH v15 02/22] xfs: Add xfs_attr_node_remove_cleanup
In reply to Allison HendersonQuoted 7 lines · Allison Henderson
This patch pulls a new helper function
xfs_attr_node_remove_cleanupout ofxfs_attr_node_remove_step. This helps to modularizexfs_attr_node_remove_stepwhich will help make the delayed attribute code easier to followSigned-off-by Allison Henderson <[email protected]>Reviewed-by Chandan Babu R <[email protected]>
Looks ok,
--D
Quoted 61 lines
--- fs/xfs/libxfs/xfs_attr.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-)fs/xfs/libxfs/xfs_attr.c +20
-9@@ -1220,6 +1220,25 @@ xfs_attr_node_remove_rmt(return xfs_attr_refillstate (state); } +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. * @@ -1232,7 +1251,6 @@ xfs_attr_node_remove_step(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;@@ -1247,14 +1265,7 @@ xfs_attr_node_remove_step(if (error)return error; } - -/* -* Remove the name and update the hashvals in the tree. -*/ - blk = &state->path.blk[ state->path.active-1 ]; -ASSERT (blk->magic ==XFS_ATTR_LEAF_MAGIC ); - 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
Re: [PATCH v15 02/22] xfs: Add xfs_attr_node_remove_cleanup
Quoted 11 lines · Darrick J. Wong
Quoted 7 lines · Allison Henderson
This patch pulls a new helper function
xfs_attr_node_remove_cleanupout ofxfs_attr_node_remove_step. This helps to modularizexfs_attr_node_remove_stepwhich will help make the delayed attribute code easier to followSigned-off-by Allison Henderson <[email protected]>Reviewed-by Chandan Babu R <[email protected]>Looks ok,
Reviewed-by Darrick J. Wong <[email protected]>
Ok, thanks!
Allison
Quoted 64 lines
--D
Quoted 61 lines
--- fs/xfs/libxfs/xfs_attr.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-)fs/xfs/libxfs/xfs_attr.c +20
-9@@ -1220,6 +1220,25 @@ xfs_attr_node_remove_rmt(return xfs_attr_refillstate (state); } +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. * @@ -1232,7 +1251,6 @@ xfs_attr_node_remove_step(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;@@ -1247,14 +1265,7 @@ xfs_attr_node_remove_step(if (error)return error; } - -/* -* Remove the name and update the hashvals in the tree. -*/ - blk = &state->path.blk[ state->path.active-1 ]; -ASSERT (blk->magic ==XFS_ATTR_LEAF_MAGIC ); - 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 v15 3/22 xfs: Hoist transaction handling in xfs_attr_node_remove_step
In reply to Allison HendersonThis patch hoists transaction handling in xfs_attr_node_removename to xfs_attr_node_remove_step. This will help keep transaction handling in higher level functions instead of buried in subfunctions when we introduce delay attributes
--- fs/xfs/libxfs/xfs_attr.c | 45 ++++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 23 deletions(-)
fs/xfs/libxfs/xfs_attr.c +22 -23
@@ -1251,9 +1251,7 @@ xfs_attr_node_remove_step(struct xfs_da_args *args, struct xfs_da_state *state) { - int retval, error; -struct xfs_inode *dp = args->dp; - + int error = 0;/* * If there is an out-of-line value, de-allocate the blocks.
@@ -1265,25 +1263,6 @@ xfs_attr_node_remove_step(if (error)return error; } - 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) -return error; - error =xfs_defer_finish (&args->trans); -if (error) -return error; -/* -* Commit the Btree join operation and start a new trans. -*/ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) -return error; - }return error; }
@@ -1299,7 +1278,7 @@ xfs_attr_node_removename( struct xfs_da_args *args) {struct xfs_da_state *state =NULL ; -int error; +int retval, error;struct xfs_inode *dp = args->dp;trace_xfs_attr_node_removename (args);
@@ -1312,6 +1291,26 @@ xfs_attr_node_removename(if (error) goto out; + 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. +*/ + error =xfs_trans_roll_inode (&args->trans, dp); +if (error) + goto out; + } +/* * If the result is small enough, push it all into the inode. */
Signature · 1 line
2.7.4
Re: [PATCH v15 03/22] xfs: Hoist transaction handling in xfs_attr_node_remove_step
Quoted 7 lines · Allison Henderson
This patch hoists transaction handling in
xfs_attr_node_removenametoxfs_attr_node_remove_step. This will help keep transaction handling in higher level functions instead of buried in subfunctions when we introduce delay attributesSigned-off-by Allison Henderson <[email protected]>---
Quoted 83 lines
fs/xfs/libxfs/xfs_attr.c | 45 ++++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 23 deletions(-)fs/xfs/libxfs/xfs_attr.c +22
-23@@ -1251,9 +1251,7 @@ xfs_attr_node_remove_step(struct xfs_da_args *args, struct xfs_da_state *state) { - int retval, error; -struct xfs_inode *dp = args->dp; - + int error = 0;/* * If there is an out-of-line value, de-allocate the blocks. @@ -1265,25 +1263,6 @@ xfs_attr_node_remove_step(if (error)return error; } - 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) -return error; - error =xfs_defer_finish (&args->trans); -if (error) -return error; -/* -* Commit the Btree join operation and start a new trans. -*/ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) -return error; - }return error; }@@ -1299,7 +1278,7 @@ xfs_attr_node_removename( struct xfs_da_args *args) {struct xfs_da_state *state =NULL ; -int error; +int retval, error;struct xfs_inode *dp = args->dp;trace_xfs_attr_node_removename (args);@@ -1312,6 +1291,26 @@ xfs_attr_node_removename(if (error) goto out; + 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. +*/ + error =xfs_trans_roll_inode (&args->trans, dp); +if (error) + goto out; + } +/* * If the result is small enough, push it all into the inode. */ Signature · 1 line
2.7.4
Re: [PATCH v15 03/22] xfs: Hoist transaction handling in xfs_attr_node_remove_step
Quoted 10 lines · Brian Foster
Quoted 7 lines · Allison Henderson
This patch hoists transaction handling in
xfs_attr_node_removenametoxfs_attr_node_remove_step. This will help keep transaction handling in higher level functions instead of buried in subfunctions when we introduce delay attributesSigned-off-by Allison Henderson <[email protected]>---
Reviewed-by Brian Foster <[email protected]>
Great, thank you!
Allison
Quoted 85 lines
Quoted 84 lines
fs/xfs/libxfs/xfs_attr.c | 45 ++++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 23 deletions(-)fs/xfs/libxfs/xfs_attr.c +22
-23@@ -1251,9 +1251,7 @@ xfs_attr_node_remove_step(struct xfs_da_args *args, struct xfs_da_state *state) { - int retval, error; -struct xfs_inode *dp = args->dp; - + int error = 0;/* * If there is an out-of-line value, de-allocate the blocks. @@ -1265,25 +1263,6 @@ xfs_attr_node_remove_step(if (error)return error; } - 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) -return error; - error =xfs_defer_finish (&args->trans); -if (error) -return error; -/* -* Commit the Btree join operation and start a new trans. -*/ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) -return error; - }return error; }@@ -1299,7 +1278,7 @@ xfs_attr_node_removename( struct xfs_da_args *args) {struct xfs_da_state *state =NULL ; -int error; +int retval, error;struct xfs_inode *dp = args->dp;trace_xfs_attr_node_removename (args);@@ -1312,6 +1291,26 @@ xfs_attr_node_removename(if (error) goto out; + 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. +*/ + error =xfs_trans_roll_inode (&args->trans, dp); +if (error) + goto out; + } +/* * If the result is small enough, push it all into the inode. */ Signature · 1 line
2.7.4
Re: [PATCH v15 03/22] xfs: Hoist transaction handling in xfs_attr_node_remove_step
In reply to Allison HendersonQuoted 6 lines · Allison Henderson
This patch hoists transaction handling in
xfs_attr_node_removenametoxfs_attr_node_remove_step. This will help keep transaction handling in higher level functions instead of buried in subfunctions when we introduce delay attributesSigned-off-by Allison Henderson <[email protected]>
Looks ok,
--D
Quoted 84 lines
--- fs/xfs/libxfs/xfs_attr.c | 45 ++++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 23 deletions(-)fs/xfs/libxfs/xfs_attr.c +22
-23@@ -1251,9 +1251,7 @@ xfs_attr_node_remove_step(struct xfs_da_args *args, struct xfs_da_state *state) { - int retval, error; -struct xfs_inode *dp = args->dp; - + int error = 0;/* * If there is an out-of-line value, de-allocate the blocks. @@ -1265,25 +1263,6 @@ xfs_attr_node_remove_step(if (error)return error; } - 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) -return error; - error =xfs_defer_finish (&args->trans); -if (error) -return error; -/* -* Commit the Btree join operation and start a new trans. -*/ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) -return error; - }return error; }@@ -1299,7 +1278,7 @@ xfs_attr_node_removename( struct xfs_da_args *args) {struct xfs_da_state *state =NULL ; -int error; +int retval, error;struct xfs_inode *dp = args->dp;trace_xfs_attr_node_removename (args);@@ -1312,6 +1291,26 @@ xfs_attr_node_removename(if (error) goto out; + 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. +*/ + error =xfs_trans_roll_inode (&args->trans, dp); +if (error) + goto out; + } +/* * If the result is small enough, push it all into the inode. */ Signature · 1 line
2.7.4
Re: [PATCH v15 03/22] xfs: Hoist transaction handling in xfs_attr_node_remove_step
Quoted 10 lines · Darrick J. Wong
Quoted 6 lines · Allison Henderson
This patch hoists transaction handling in
xfs_attr_node_removenametoxfs_attr_node_remove_step. This will help keep transaction handling in higher level functions instead of buried in subfunctions when we introduce delay attributesSigned-off-by Allison Henderson <[email protected]>Looks ok,
Reviewed-by Darrick J. Wong <[email protected]>
Great, thank you!
Allison
Quoted 87 lines
--D
Quoted 84 lines
--- fs/xfs/libxfs/xfs_attr.c | 45 ++++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 23 deletions(-)fs/xfs/libxfs/xfs_attr.c +22
-23@@ -1251,9 +1251,7 @@ xfs_attr_node_remove_step(struct xfs_da_args *args, struct xfs_da_state *state) { - int retval, error; -struct xfs_inode *dp = args->dp; - + int error = 0;/* * If there is an out-of-line value, de-allocate the blocks. @@ -1265,25 +1263,6 @@ xfs_attr_node_remove_step(if (error)return error; } - 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) -return error; - error =xfs_defer_finish (&args->trans); -if (error) -return error; -/* -* Commit the Btree join operation and start a new trans. -*/ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) -return error; - }return error; }@@ -1299,7 +1278,7 @@ xfs_attr_node_removename( struct xfs_da_args *args) {struct xfs_da_state *state =NULL ; -int error; +int retval, error;struct xfs_inode *dp = args->dp;trace_xfs_attr_node_removename (args);@@ -1312,6 +1291,26 @@ xfs_attr_node_removename(if (error) goto out; + 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. +*/ + error =xfs_trans_roll_inode (&args->trans, dp); +if (error) + goto out; + } +/* * If the result is small enough, push it all into the inode. */ Signature · 1 line
2.7.4
PATCH v15 4/22 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
Re: [PATCH v15 04/22] xfs: Hoist xfs_attr_set_shortform
Quoted 5 lines · Allison Henderson
This patch hoists
xfs_attr_set_shortforminto the calling function. This will help keep all state management code in the same scope.Signed-off-by Allison Henderson <[email protected]>---
LGTM:
Quoted 116 lines
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
Re: [PATCH v15 04/22] xfs: Hoist xfs_attr_set_shortform
Quoted 10 lines · Brian Foster
Quoted 5 lines · Allison Henderson
This patch hoists
xfs_attr_set_shortforminto the calling function. This will help keep all state management code in the same scope.Signed-off-by Allison Henderson <[email protected]>---
LGTM:
Reviewed-by Brian Foster <[email protected]>
Thanks!
Allison
Quoted 118 lines
Quoted 117 lines
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
Re: [PATCH v15 04/22] xfs: Hoist xfs_attr_set_shortform
In reply to Allison HendersonQuoted 4 lines · Allison Henderson
This patch hoists
xfs_attr_set_shortforminto the calling function. This will help keep all state management code in the same scope.Signed-off-by Allison Henderson <[email protected]>
Whoah, /removing/ a function! :)
--D
Quoted 117 lines
--- 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
Re: [PATCH v15 04/22] xfs: Hoist xfs_attr_set_shortform
Quoted 9 lines · Darrick J. Wong
Quoted 4 lines · Allison Henderson
This patch hoists
xfs_attr_set_shortforminto the calling function. This will help keep all state management code in the same scope.Signed-off-by Allison Henderson <[email protected]>Whoah, /removing/ a function! :)
Reviewed-by Darrick J. Wong <[email protected]>
Thanks! Yeah, in this series we do flatten up a lot of helper functions with the goal of getting all the states into a single function.
Allison
Quoted 120 lines
--D
Quoted 117 lines
--- 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 v15 5/22 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 | 77 +++++++++++++++++++++++++++--------------------- 1 file changed, 44 insertions(+), 33 deletions(-)
fs/xfs/libxfs/xfs_attr.c +44 -33
@@ -216,6 +216,46 @@ 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 -EAGAIN ; +} +/* * Set the attribute specified in @args. */
@@ -224,8 +264,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 +273,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) + error =xfs_attr_set_fmt (args); +if (error != -EAGAIN )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; - } }if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) {
@@ -297,8 +309,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
Re: [PATCH v15 05/22] xfs: Add helper xfs_attr_set_fmt
Quoted 9 lines · Allison Henderson
This 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_fmtreturns 0 when the attr has been set and no further action is needed. It returns-EAGAINwhen shortform has been transformed to leaf, and the calling function should proceed the set the attr in leaf form.Signed-off-by Allison Henderson <[email protected]>---
Quoted 116 lines
fs/xfs/libxfs/xfs_attr.c | 77 +++++++++++++++++++++++++++--------------------- 1 file changed, 44 insertions(+), 33 deletions(-)fs/xfs/libxfs/xfs_attr.c +44
-33@@ -216,6 +216,46 @@ 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 -EAGAIN ; +} +/* * Set the attribute specified in @args. */ @@ -224,8 +264,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 +273,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) + error =xfs_attr_set_fmt (args); +if (error != -EAGAIN )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; - } }if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) {@@ -297,8 +309,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
Re: [PATCH v15 05/22] xfs: Add helper xfs_attr_set_fmt
Quoted 8 lines · Brian Foster
Quoted 7 lines · Allison Henderson
This 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_fmtreturns 0 when the attr has been set and no further action is needed. It returns-EAGAINwhen shortform has been transformed to leaf, and the calling function should proceed the set the attr in leaf form.
Quoted 4 lines
Quoted 2 lines
Signed-off-by Allison Henderson <[email protected]>---
Reviewed-by Brian Foster <[email protected]>
Will add. Thank you!!
Allison
Quoted 118 lines
Quoted 117 lines
fs/xfs/libxfs/xfs_attr.c | 77 +++++++++++++++++++++++++++--------------------- 1 file changed, 44 insertions(+), 33 deletions(-)fs/xfs/libxfs/xfs_attr.c +44
-33@@ -216,6 +216,46 @@ 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 -EAGAIN ; +} +/* * Set the attribute specified in @args. */ @@ -224,8 +264,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 +273,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) + error =xfs_attr_set_fmt (args); +if (error != -EAGAIN )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; - } }if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) {@@ -297,8 +309,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
Re: [PATCH v15 05/22] xfs: Add helper xfs_attr_set_fmt
In reply to Allison HendersonQuoted 46 lines · Allison Henderson
This 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_fmtreturns 0 when the attr has been set and no further action is needed. It returns-EAGAINwhen shortform has been transformed to leaf, and the calling function should proceed the set the attr in leaf form.Signed-off-by Allison Henderson <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 77 +++++++++++++++++++++++++++--------------------- 1 file changed, 44 insertions(+), 33 deletions(-)fs/xfs/libxfs/xfs_attr.c +26
-0@@ -216,6 +216,46 @@ 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; +
fs/xfs/libxfs/xfs_attr.c xfs_attr_is_shortform( · line 254
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10
-0+/* +* Prevent the leaf buffer from being unlocked so that a +* concurrent AIL push cannot grab the half-baked leaf buffer +* and run into problems with the write verifier. +*/ +xfs_trans_bhold (args->trans, leaf_bp); + error =xfs_defer_finish (&args->trans); +xfs_trans_bhold_release (args->trans, leaf_bp); +if (error) +xfs_trans_brelse (args->trans, leaf_bp);
Shouldn't this pass the error back to the caller?
--D
Quoted 69 lines
fs/xfs/libxfs/xfs_attr.c +8
-33+ +return -EAGAIN ; +} +/* * Set the attribute specified in @args. */ @@ -224,8 +264,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 +273,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) + error =xfs_attr_set_fmt (args); +if (error != -EAGAIN )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; - } }if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) {@@ -297,8 +309,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
Re: [PATCH v15 05/22] xfs: Add helper xfs_attr_set_fmt
Quoted 60 lines · Darrick J. Wong
Quoted 46 lines · Allison Henderson
This 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_fmtreturns 0 when the attr has been set and no further action is needed. It returns-EAGAINwhen shortform has been transformed to leaf, and the calling function should proceed the set the attr in leaf form.Signed-off-by Allison Henderson <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 77 +++++++++++++++++++++++++++--------------------- 1 file changed, 44 insertions(+), 33 deletions(-)fs/xfs/libxfs/xfs_attr.c +26
-0@@ -216,6 +216,46 @@ 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; +fs/xfs/libxfs/xfs_attr.c xfs_attr_is_shortform( · line 254
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10
-0+/* +* Prevent the leaf buffer from being unlocked so that a +* concurrent AIL push cannot grab the half-baked leaf buffer +* and run into problems with the write verifier. +*/ +xfs_trans_bhold (args->trans, leaf_bp); + error =xfs_defer_finish (&args->trans); +xfs_trans_bhold_release (args->trans, leaf_bp); +if (error) +xfs_trans_brelse (args->trans, leaf_bp);Shouldn't this pass the error back to the caller?
Quoted 1 line
--D
Yes, I must of have missed it in this temporary phase of this function.
It quickly gets pulled back out when the defer_finishes go away, but
will fix for this phase in the series. Thanks for the catch!
Allison
Quoted 70 lines
Quoted 70 lines
fs/xfs/libxfs/xfs_attr.c +8
-33+ +return -EAGAIN ; +} +/* * Set the attribute specified in @args. */ @@ -224,8 +264,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 +273,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) + error =xfs_attr_set_fmt (args); +if (error != -EAGAIN )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; - } }if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) {@@ -297,8 +309,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 v15 6/22 xfs: Separate xfs_attr_node_addname and xfs_attr_node_addname_work
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_work(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);
@@ -1059,6 +1060,25 @@ xfs_attr_node_addname(return error; } + error =xfs_attr_node_addname_work (args); +out: +if (state) +xfs_da_state_free (state); +if (error) +return error; +return retval; +} + + +STATIC +int xfs_attr_node_addname_work( +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 v15 06/22] xfs: Separate xfs_attr_node_addname and xfs_attr_node_addname_work
Quoted 6 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]>---
Quoted 44 lines
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_work(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);@@ -1059,6 +1060,25 @@ xfs_attr_node_addname(return error; } + error =xfs_attr_node_addname_work (args); +out: +if (state) +xfs_da_state_free (state); +if (error) +return error; +return retval; +} + + +STATIC +int xfs_attr_node_addname_work( +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 v15 06/22] xfs: Separate xfs_attr_node_addname and xfs_attr_node_addname_work
Quoted 9 lines · Brian Foster
Quoted 6 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]>
Alrighty, thanks!
Allison
Quoted 46 lines
Quoted 45 lines
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_work(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);@@ -1059,6 +1060,25 @@ xfs_attr_node_addname(return error; } + error =xfs_attr_node_addname_work (args); +out: +if (state) +xfs_da_state_free (state); +if (error) +return error; +return retval; +} + + +STATIC +int xfs_attr_node_addname_work( +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 v15 06/22] xfs: Separate xfs_attr_node_addname and xfs_attr_node_addname_work
In reply to Allison HendersonQuoted 27 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]>--- fs/xfs/libxfs/xfs_attr.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)fs/xfs/libxfs/xfs_attr.c +3
-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_work(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);@@ -1059,6 +1060,25 @@ xfs_attr_node_addname(return error; } + error =xfs_attr_node_addname_work (args); +out:
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_addname( · line 1074
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10
-0+if (state) +xfs_da_state_free (state); +if (error) +return error; +return retval; +} + + +STATIC +int xfs_attr_node_addname_work(
What, erm, work does this function do? Since it survives to the end of the patchset, I think this needs a better name (or at least needs a comment about what it's actually supposed to do).
AFAICT you're splitting node_addname() into two functions because we're at a transaction roll point, and this "_work" function exists to remove the copy of the xattr key that has the "INCOMPLETE" bit set (aka the old one), right?
--D
Quoted 13 lines
fs/xfs/libxfs/xfs_attr.c +7
-0+ 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 v15 06/22] xfs: Separate xfs_attr_node_addname and xfs_attr_node_addname_work
Quoted 26 lines · Darrick J. Wong
Quoted 25 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]>--- 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_work(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);@@ -1059,6 +1060,25 @@ xfs_attr_node_addname(return error; }
Quoted 16 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_addname( · line 1074
Quoted 12 lines
fs/xfs/libxfs/xfs_attr.c +12
-0+ error =xfs_attr_node_addname_work (args); +out: +if (state) +xfs_da_state_free (state); +if (error) +return error; +return retval; +} + + +STATIC +int xfs_attr_node_addname_work(What, erm, work does this function do? Since it survives to the end of the patchset, I think this needs a better name (or at least needs a comment about what it's actually supposed to do).
To directly answer the question: it's here to help xfs_attr_set_iter not be any bigger than it has to. I think we likely struggled with the name because it's almost like it's just the "remainder" of the operation that doesnt need state management
Quoted 5 lines
AFAICT you're splitting
node_addname()into two functions because we're at a transaction roll point, and this "_work" function exists to remove the copy of the xattr key that has the "INCOMPLETE" bit set (aka the old one), right?
Thats about right. Maybe just a quick comment?
/*
* Removes the old xattr key marked with the INCOMPLETE bit */
I suppose we could consider something like "xfs_attr_node_addname_remv_incomplete"? Or xfs_attr_node_addname_cleanup? Trying to cram it into the name maybe getting a bit wordy too.
Allison
Quoted 16 lines
--D
Quoted 13 lines
fs/xfs/libxfs/xfs_attr.c +7
-0+ 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 v15 06/22] xfs: Separate xfs_attr_node_addname and xfs_attr_node_addname_work
Quoted 54 lines · Allison Henderson
Quoted 33 lines · Darrick J. Wong
Quoted 32 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]>--- fs/xfs/libxfs/xfs_attr.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)fs/xfs/libxfs/xfs_attr.c +9
-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_work(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);@@ -1059,6 +1060,25 @@ xfs_attr_node_addname(return error; } + error =xfs_attr_node_addname_work (args); +out: +if (state) +xfs_da_state_free (state); +if (error) +return error; +return retval; +}Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_addname( · line 1074
Quoted 4 lines
fs/xfs/libxfs/xfs_attr.c +4
-0+ + +STATIC +int xfs_attr_node_addname_work(What, erm, work does this function do? Since it survives to the end of the patchset, I think this needs a better name (or at least needs a comment about what it's actually supposed to do).
To directly answer the question: it's here to help
xfs_attr_set_iternot be any bigger than it has to. I think we likely struggled with the name because it's almost like it's just the "remainder" of the operation that doesnt need state managementQuoted 5 lines
AFAICT you're splitting
node_addname()into two functions because we're at a transaction roll point, and this "_work" function exists to remove the copy of the xattr key that has the "INCOMPLETE" bit set (aka the old one), right?
Quoted 8 lines
Thats about right. Maybe just a quick comment?
/*
* Removes the old xattr key marked with the INCOMPLETE bit */I suppose we could consider something like "
xfs_attr_node_addname_remv_incomplete"? Orxfs_attr_node_addname_cleanup? Trying to cram it into the name maybe getting a bit wordy too.
xfs_attr_node_addname_clear_incomplete?
--D
Quoted 18 lines
Allison
Quoted 16 lines
--D
Quoted 13 lines
fs/xfs/libxfs/xfs_attr.c +7
-0+ 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 v15 06/22] xfs: Separate xfs_attr_node_addname and xfs_attr_node_addname_work
Quoted 60 lines · Darrick J. Wong
Quoted 59 lines · Allison Henderson
Quoted 33 lines · Darrick J. Wong
Quoted 32 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]>--- fs/xfs/libxfs/xfs_attr.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)fs/xfs/libxfs/xfs_attr.c +9
-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_work(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);@@ -1059,6 +1060,25 @@ xfs_attr_node_addname(return error; } + error =xfs_attr_node_addname_work (args); +out: +if (state) +xfs_da_state_free (state); +if (error) +return error; +return retval; +}Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_addname( · line 1074
Quoted 4 lines
fs/xfs/libxfs/xfs_attr.c +4
-0+ + +STATIC +int xfs_attr_node_addname_work(What, erm, work does this function do? Since it survives to the end of the patchset, I think this needs a better name (or at least needs a comment about what it's actually supposed to do).
To directly answer the question: it's here to help
xfs_attr_set_iternot be any bigger than it has to. I think we likely struggled with the name because it's almost like it's just the "remainder" of the operation that doesnt need state managementQuoted 5 lines
AFAICT you're splitting
node_addname()into two functions because we're at a transaction roll point, and this "_work" function exists to remove the copy of the xattr key that has the "INCOMPLETE" bit set (aka the old one), right?Thats about right. Maybe just a quick comment?
/*
* Removes the old xattr key marked with the INCOMPLETE bit */
Quoted 5 lines
Quoted 3 lines
I suppose we could consider something like "
xfs_attr_node_addname_remv_incomplete"? Orxfs_attr_node_addname_cleanup? Trying to cram it into the name maybe getting a bit wordy too.
xfs_attr_node_addname_clear_incomplete?
I'm fine with that as long as everyone else is :-)
Allison
Quoted 21 lines
--D
Quoted 18 lines
Allison
Quoted 16 lines
--D
Quoted 13 lines
fs/xfs/libxfs/xfs_attr.c +7
-0+ 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
PATCH v15 7/22 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 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 | 80 ++++++++++++++++++++++++++++++------------------ 1 file changed, 51 insertions(+), 29 deletions(-)
fs/xfs/libxfs/xfs_attr.c +51 -29
@@ -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_work(struct xfs_da_args *args); STATIC int xfs_attr_node_hasname(xfs_da_args_t *args,
@@ -265,6 +268,7 @@ xfs_attr_set_args( struct xfs_da_args *args) {struct xfs_inode *dp = args->dp; +struct xfs_da_state *state;int error;/*
@@ -310,7 +314,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; }/*
@@ -883,42 +894,21 @@ 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. */ - retval =xfs_attr_node_hasname (args, &state); + retval =xfs_attr_node_hasname (args, state);if (retval != -ENOATTR && retval != -EEXIST ) goto out; - blk = &state->path.blk[ state->path.active-1 ]; -ASSERT (blk->magic ==XFS_ATTR_LEAF_MAGIC );if (retval == -ENOATTR && (args->attr_flags &XATTR_REPLACE )) goto out;if (retval == -EEXIST ) {
@@ -941,6 +931,38 @@ xfs_attr_node_addname( args->rmtvaluelen =0 ; } +return 0 ; +out: +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 ) {
@@ -966,7 +988,7 @@ xfs_attr_node_addname(if (error) goto out; - goto restart; +return -EAGAIN ; }/*
Signature · 1 line
2.7.4
Re: [PATCH v15 07/22] xfs: Add helper xfs_attr_node_addname_find_attr
Quoted 17 lines · Allison Henderson
This patch separates the first half of
xfs_attr_node_addnameinto a helper functionxfs_attr_node_addname_find_attr. It also replaces the restart goto with 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 ofxfs_attr_node_addnamewith out having to plumb in a "done" parameter to know if we need to move to the next state or not.Signed-off-by Allison Henderson <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 80 ++++++++++++++++++++++++++++++------------------ 1 file changed, 51 insertions(+), 29 deletions(-)fs/xfs/libxfs/xfs_attr.c +0
-0
...
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_addname( · line 935
Quoted 6 lines
fs/xfs/libxfs/xfs_attr.c +2
-0@@ -941,6 +931,38 @@ xfs_attr_node_addname( args->rmtvaluelen =0 ; } +return 0 ; +out:
Nit: can we call this label 'error' since it appears to be used when we want to return the current retval as an operational error?
Quoted 15 lines
fs/xfs/libxfs/xfs_attr.c +15
-0+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. +*/
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_addname( · line 960
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10
-0+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);
This moves the tracepoint into the looping sequence whereas previously it would only execute once. I don't see a clean way to fix that with the breakdown as of this patch, and it's not a huge deal, but it would be nice to fix that before the end of the series if we haven't already. Otherwise LGTM:
Quoted 20 lines
fs/xfs/libxfs/xfs_attr.c +6
-1+ + 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 ) {@@ -966,7 +988,7 @@ xfs_attr_node_addname(if (error) goto out; - goto restart; +return -EAGAIN ; }/* Signature · 1 line
2.7.4
Re: [PATCH v15 07/22] xfs: Add helper xfs_attr_node_addname_find_attr
Quoted 23 lines · Brian Foster
Quoted 17 lines · Allison Henderson
This patch separates the first half of
xfs_attr_node_addnameinto a helper functionxfs_attr_node_addname_find_attr. It also replaces the restart goto with 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 ofxfs_attr_node_addnamewith out having to plumb in a "done" parameter to know if we need to move to the next state or not.Signed-off-by Allison Henderson <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 80 ++++++++++++++++++++++++++++++------------------ 1 file changed, 51 insertions(+), 29 deletions(-)fs/xfs/libxfs/xfs_attr.c +0
-0...
Quoted 4 lines
fs/xfs/libxfs/xfs_attr.c +0
-0@@ -941,6 +931,38 @@ xfs_attr_node_addname( args->rmtvaluelen =0 ; }
Quoted 5 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_addname( · line 935
Quoted 2 lines
fs/xfs/libxfs/xfs_attr.c +2
-0+return 0 ; +out:Nit: can we call this label 'error' since it appears to be used when we want to return the current retval as an operational error?
Sure, will change out
Quoted 24 lines
Quoted 24 lines
fs/xfs/libxfs/xfs_attr.c +23
-0+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;
Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_addname( · line 960
Quoted 2 lines
fs/xfs/libxfs/xfs_attr.c +2
-0+ +trace_xfs_attr_node_addname (args);This moves the tracepoint into the looping sequence whereas previously it would only execute once. I don't see a clean way to fix that with the breakdown as of this patch, and it's not a huge deal, but it would be nice to fix that before the end of the series if we haven't already. Otherwise LGTM:
I see, I could hoist it out, but it is short lived really. Once we get into the state machine it wont much matter if it's hoisted or not. In the greater scheme of things, I think it makes more sense for it to stay where it is. A lot of these patches are not particularly elegant during this refactoring phase, and then things sort of come together once the state machine gets here.
Quoted 2 lines
Reviewed-by Brian Foster <[email protected]>
Thank you!
Allison
Quoted 22 lines
Quoted 21 lines
fs/xfs/libxfs/xfs_attr.c +6
-1+ + 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 ) {@@ -966,7 +988,7 @@ xfs_attr_node_addname(if (error) goto out; - goto restart; +return -EAGAIN ; }/* Signature · 1 line
2.7.4
Re: [PATCH v15 07/22] xfs: Add helper xfs_attr_node_addname_find_attr
In reply to Allison HendersonQuoted 9 lines · Allison Henderson
This patch separates the first half of
xfs_attr_node_addnameinto a helper functionxfs_attr_node_addname_find_attr. It also replaces the restart goto with 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 ofxfs_attr_node_addnamewith out having to plumb in a "done" parameter to know if we need to move to the next state or not.Signed-off-by Allison Henderson <[email protected]>
Looks ok to me,
--D
Quoted 143 lines
--- fs/xfs/libxfs/xfs_attr.c | 80 ++++++++++++++++++++++++++++++------------------ 1 file changed, 51 insertions(+), 29 deletions(-)fs/xfs/libxfs/xfs_attr.c +51
-29@@ -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_work(struct xfs_da_args *args); STATIC int xfs_attr_node_hasname(xfs_da_args_t *args,@@ -265,6 +268,7 @@ xfs_attr_set_args( struct xfs_da_args *args) {struct xfs_inode *dp = args->dp; +struct xfs_da_state *state;int error;/* @@ -310,7 +314,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; }/* @@ -883,42 +894,21 @@ 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. */ - retval =xfs_attr_node_hasname (args, &state); + retval =xfs_attr_node_hasname (args, state);if (retval != -ENOATTR && retval != -EEXIST ) goto out; - blk = &state->path.blk[ state->path.active-1 ]; -ASSERT (blk->magic ==XFS_ATTR_LEAF_MAGIC );if (retval == -ENOATTR && (args->attr_flags &XATTR_REPLACE )) goto out;if (retval == -EEXIST ) {@@ -941,6 +931,38 @@ xfs_attr_node_addname( args->rmtvaluelen =0 ; } +return 0 ; +out: +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 ) {@@ -966,7 +988,7 @@ xfs_attr_node_addname(if (error) goto out; - goto restart; +return -EAGAIN ; }/* Signature · 1 line
2.7.4
Re: [PATCH v15 07/22] xfs: Add helper xfs_attr_node_addname_find_attr
Quoted 9 lines · Darrick J. Wong
Quoted 8 lines · Allison Henderson
This patch separates the first half of
xfs_attr_node_addnameinto a helper functionxfs_attr_node_addname_find_attr. It also replaces the restart goto with 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 ofxfs_attr_node_addnamewith out having to plumb in a "done" parameter to know if we need to move to the next state or not.
Quoted 4 lines
Quoted 1 line
Signed-off-by Allison Henderson <[email protected]>Looks ok to me,
Reviewed-by Darrick J. Wong <[email protected]>
Thanks!
Allison
Quoted 146 lines
--D
Quoted 143 lines
--- fs/xfs/libxfs/xfs_attr.c | 80 ++++++++++++++++++++++++++++++------------------ 1 file changed, 51 insertions(+), 29 deletions(-)fs/xfs/libxfs/xfs_attr.c +51
-29@@ -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_work(struct xfs_da_args *args); STATIC int xfs_attr_node_hasname(xfs_da_args_t *args,@@ -265,6 +268,7 @@ xfs_attr_set_args( struct xfs_da_args *args) {struct xfs_inode *dp = args->dp; +struct xfs_da_state *state;int error;/* @@ -310,7 +314,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; }/* @@ -883,42 +894,21 @@ 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. */ - retval =xfs_attr_node_hasname (args, &state); + retval =xfs_attr_node_hasname (args, state);if (retval != -ENOATTR && retval != -EEXIST ) goto out; - blk = &state->path.blk[ state->path.active-1 ]; -ASSERT (blk->magic ==XFS_ATTR_LEAF_MAGIC );if (retval == -ENOATTR && (args->attr_flags &XATTR_REPLACE )) goto out;if (retval == -EEXIST ) {@@ -941,6 +931,38 @@ xfs_attr_node_addname( args->rmtvaluelen =0 ; } +return 0 ; +out: +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 ) {@@ -966,7 +988,7 @@ xfs_attr_node_addname(if (error) goto out; - goto restart; +return -EAGAIN ; }/* Signature · 1 line
2.7.4
PATCH v15 8/22 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 | 165 ++++++++++++++++++++++++----------------------- 1 file changed, 83 insertions(+), 82 deletions(-)
fs/xfs/libxfs/xfs_attr.c +83 -82
@@ -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,
@@ -268,8 +269,9 @@ 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 ; +int retval =0 ;/* * If the attribute list is already in leaf format, jump straight to
@@ -320,8 +322,82 @@ 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); + 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_work (args); +out: +if (state) +xfs_da_state_free (state); +if (error) +return error; +return retval; -return error; }/*
@@ -955,7 +1031,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);
@@ -963,8 +1039,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
@@ -1010,85 +1086,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_work (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 v15 08/22] xfs: Hoist xfs_attr_node_addname
Quoted 14 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 possibleSigned-off-by Allison Henderson <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 165 ++++++++++++++++++++++++----------------------- 1 file changed, 83 insertions(+), 82 deletions(-)fs/xfs/libxfs/xfs_attr.c +0
-0
...
Quoted 24 lines
fs/xfs/libxfs/xfs_attr.c +20
-0@@ -320,8 +322,82 @@ 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)
fs/xfs/libxfs/xfs_attr.c xfs_attr_set_args( · line 354
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10
-0+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;
It looks like this is the only use of retval. Otherwise this function is getting a bit big, but the factoring LGTM:
Quoted 160 lines
fs/xfs/libxfs/xfs_attr.c +49
-80+ 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_work (args); +out: +if (state) +xfs_da_state_free (state); +if (error) +return error; +return retval; -return error; }/* @@ -955,7 +1031,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);@@ -963,8 +1039,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 @@ -1010,85 +1086,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_work (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 v15 08/22] xfs: Hoist xfs_attr_node_addname
Quoted 45 lines · Brian Foster
Quoted 14 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 possibleSigned-off-by Allison Henderson <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 165 ++++++++++++++++++++++++----------------------- 1 file changed, 83 insertions(+), 82 deletions(-)fs/xfs/libxfs/xfs_attr.c +0
-0...
Quoted 29 lines
fs/xfs/libxfs/xfs_attr.c +25
-0@@ -320,8 +322,82 @@ 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 )) { +/*
Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_set_args( · line 354
Quoted 5 lines
fs/xfs/libxfs/xfs_attr.c +5
-0+* Added a "remote" value, just clear the incomplete flag. +*/ +if (args->rmtblkno >0 ) + error =xfs_attr3_leaf_clearflag (args); + retval = error;It looks like this is the only use of retval. Otherwise this function is getting a bit big, but the factoring LGTM:
Ok, will clean out.
Quoted 2 lines
Reviewed-by Brian Foster <[email protected]>
Thank you!
Allison
Quoted 162 lines
Quoted 161 lines
fs/xfs/libxfs/xfs_attr.c +49
-80+ 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_work (args); +out: +if (state) +xfs_da_state_free (state); +if (error) +return error; +return retval; -return error; }/* @@ -955,7 +1031,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);@@ -963,8 +1039,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 @@ -1010,85 +1086,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_work (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 v15 08/22] xfs: Hoist xfs_attr_node_addname
In reply to Allison HendersonQuoted 6 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 possibleSigned-off-by Allison Henderson <[email protected]>
Simple enough transplant,
--D
Quoted 222 lines
--- fs/xfs/libxfs/xfs_attr.c | 165 ++++++++++++++++++++++++----------------------- 1 file changed, 83 insertions(+), 82 deletions(-)fs/xfs/libxfs/xfs_attr.c +83
-82@@ -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,@@ -268,8 +269,9 @@ 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 ; +int retval =0 ;/* * If the attribute list is already in leaf format, jump straight to @@ -320,8 +322,82 @@ 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); + 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_work (args); +out: +if (state) +xfs_da_state_free (state); +if (error) +return error; +return retval; -return error; }/* @@ -955,7 +1031,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);@@ -963,8 +1039,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 @@ -1010,85 +1086,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_work (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 v15 08/22] xfs: Hoist xfs_attr_node_addname
Quoted 10 lines · Darrick J. Wong
Quoted 6 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 possibleSigned-off-by Allison Henderson <[email protected]>Simple enough transplant,
Reviewed-by Darrick J. Wong <[email protected]>
Great, thank you!
Allison
Quoted 225 lines
--D
Quoted 222 lines
--- fs/xfs/libxfs/xfs_attr.c | 165 ++++++++++++++++++++++++----------------------- 1 file changed, 83 insertions(+), 82 deletions(-)fs/xfs/libxfs/xfs_attr.c +83
-82@@ -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,@@ -268,8 +269,9 @@ 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 ; +int retval =0 ;/* * If the attribute list is already in leaf format, jump straight to @@ -320,8 +322,82 @@ 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); + 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_work (args); +out: +if (state) +xfs_da_state_free (state); +if (error) +return error; +return retval; -return error; }/* @@ -955,7 +1031,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);@@ -963,8 +1039,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 @@ -1010,85 +1086,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_work (args); out:if (state)xfs_da_state_free (state); -if (error) -return error; -return retval; +return error; }Signature · 1 line
2.7.4
PATCH v15 9/22 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 particuarly asetheic right away, but it is a preliminary step to to manageing the state machine code.
--- fs/xfs/libxfs/xfs_attr.c | 209 ++++++++++++++++++++++------------------------- 1 file changed, 96 insertions(+), 113 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.
@@ -269,8 +269,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 ;int retval =0 ;/*
@@ -286,10 +287,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. */
@@ -731,115 +823,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 */
Signature · 1 line
2.7.4
Re: [PATCH v15 09/22] xfs: Hoist xfs_attr_leaf_addname
Quoted 14 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 particuarly asetheic right away, but it is a preliminary step to to manageing the state machine code.Signed-off-by Allison Henderson <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 209 ++++++++++++++++++++++------------------------- 1 file changed, 96 insertions(+), 113 deletions(-)fs/xfs/libxfs/xfs_attr.c +0
-0
...
Quoted 1 line
fs/xfs/libxfs/xfs_attr.c +0
-0@@ -286,10 +287,101 @@ xfs_attr_set_args(
...
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 384
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:
Hmm, I'm not a fan of this unconditional return followed by a jump label in the middle of the function. It's a pretty clear indication that this is just two functions smashed together, so I'm not sure what the advantage of this is. I'll continue on to see what falls out of the next patches..
Brian
Quoted 122 lines
fs/xfs/libxfs/xfs_attr.c +0
-109/* * Promote the attribute list to the Btree format. */ @@ -731,115 +823,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 */ Signature · 1 line
2.7.4
Re: [PATCH v15 09/22] xfs: Hoist xfs_attr_leaf_addname
Quoted 39 lines · Brian Foster
Quoted 14 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 particuarly asetheic right away, but it is a preliminary step to to manageing the state machine code.Signed-off-by Allison Henderson <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 209 ++++++++++++++++++++++------------------------- 1 file changed, 96 insertions(+), 113 deletions(-)fs/xfs/libxfs/xfs_attr.c +0
-0...
Quoted 1 line
fs/xfs/libxfs/xfs_attr.c +0
-0@@ -286,10 +287,101 @@ xfs_attr_set_args(...
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 384
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:Hmm, I'm not a fan of this unconditional return followed by a jump label in the middle of the function. It's a pretty clear indication that this is just two functions smashed together, so I'm not sure what the advantage of this is. I'll continue on to see what falls out of the next patches..
Quoted 1 line
Brian
Yes, it does kinda look a little displaced, but the point of it is to bring code that will require state management into the same scope so that the state switch can span all the operations it affects. Which seemed to be what the RFC was striving for? Looking ahead at the other reviews, I think it came together for you?
Allison
Quoted 124 lines
Quoted 123 lines
/*
* Promote the attribute list to the Btree format. */fs/xfs/libxfs/xfs_attr.c +0
-109@@ -731,115 +823,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 */ Signature · 1 line
2.7.4
Re: [PATCH v15 09/22] xfs: Hoist xfs_attr_leaf_addname
Quoted 41 lines · Allison Henderson
Quoted 38 lines · Brian Foster
Quoted 14 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 particuarly asetheic right away, but it is a preliminary step to to manageing the state machine code.Signed-off-by Allison Henderson <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 209 ++++++++++++++++++++++------------------------- 1 file changed, 96 insertions(+), 113 deletions(-)fs/xfs/libxfs/xfs_attr.c +0
-0...
Quoted 1 line
fs/xfs/libxfs/xfs_attr.c +0
-0@@ -286,10 +287,101 @@ xfs_attr_set_args(...
fs/xfs/libxfs/xfs_attr.c xfs_attr_set_args( · line 384
Quoted 13 lines
return error;
fs/xfs/libxfs/xfs_attr.c +12
-0+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:Hmm, I'm not a fan of this unconditional return followed by a jump label in the middle of the function. It's a pretty clear indication that this is just two functions smashed together, so I'm not sure what the advantage of this is. I'll continue on to see what falls out of the next patches..
Quoted 8 lines
Quoted 1 line
Brian
Yes, it does kinda look a little displaced, but the point of it is to bring code that will require state management into the same scope so that the state switch can span all the operations it affects. Which seemed to be what the RFC was striving for? Looking ahead at the other reviews, I think it came together for you?
Yes, I think so. If the subsequent patches line everything up nicely in that single switch statement in one place (which it looks like we're pretty close to), then I can probably live with this transient quirk. That said, I might wait until at least the attr set path looks pretty much finalized and come back and take a last look at this one, if nothing else just to think about if there's any simple/unintrusive way to avoid it..
Brian
Quoted 126 lines
Allison
Quoted 123 lines
Quoted 122 lines
/*
* Promote the attribute list to the Btree format. */fs/xfs/libxfs/xfs_attr.c +0
-109@@ -731,115 +823,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 */ Signature · 1 line
2.7.4
Re: [PATCH v15 09/22] xfs: Hoist xfs_attr_leaf_addname
In reply to Allison HendersonQuoted 3 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 particuarly asetheic right away, but it is a
"aesthetic"
Quoted 1 line
preliminary step to to manageing the state machine code.
"to merging in" ?
The goto label is ugly, but afaict this patch moves code and the next one rearranges it the way you ultimately want it, right?
With spelling fixed,
--D
Quoted 254 lines
Signed-off-by Allison Henderson <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 209 ++++++++++++++++++++++------------------------- 1 file changed, 96 insertions(+), 113 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. @@ -269,8 +269,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 ;int retval =0 ;/* @@ -286,10 +287,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. */ @@ -731,115 +823,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 */ Signature · 1 line
2.7.4
Re: [PATCH v15 09/22] xfs: Hoist xfs_attr_leaf_addname
Quoted 9 lines · Darrick J. Wong
Quoted 3 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 particuarly asetheic right away, but it is a"aesthetic"
Quoted 1 line
preliminary step to to manageing the state machine code.
Quoted 8 lines
"to merging in" ?
The goto label is ugly, but afaict this patch moves code and the next one rearranges it the way you ultimately want it, right?
With spelling fixed,
Reviewed-by Darrick J. Wong <[email protected]>
Ok, will fix spelling nits. Thank you!
Allison
Quoted 257 lines
--D
Quoted 254 lines
Signed-off-by Allison Henderson <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 209 ++++++++++++++++++++++------------------------- 1 file changed, 96 insertions(+), 113 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. @@ -269,8 +269,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 ;int retval =0 ;/* @@ -286,10 +287,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. */ @@ -731,115 +823,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 */ Signature · 1 line
2.7.4
PATCH v15 10/22 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 | 53 +++++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 25 deletions(-)
fs/xfs/libxfs/xfs_attr.c +28 -25
@@ -288,8 +288,34 @@ 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)return error;
@@ -381,32 +407,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
Re: [PATCH v15 10/22] xfs: Hoist node transaction handling
Quoted 38 lines · Allison Henderson
This 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.
Signed-off-by Allison Henderson <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 53 +++++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 25 deletions(-)fs/xfs/libxfs/xfs_attr.c +19
-1@@ -288,8 +288,34 @@ 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; + +/*
fs/xfs/libxfs/xfs_attr.c xfs_attr_set_args( · line 319
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +8
-0+* 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;
}(I think we usually try to add braces around all branches of an if/else if at least one branch requires them.)
Otherwise, the factoring looks Ok to me and this does improve on the wart from the previous patch:
Quoted 39 lines
fs/xfs/libxfs/xfs_attr.c +1
-24return error;@@ -381,32 +407,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
Re: [PATCH v15 10/22] xfs: Hoist node transaction handling
Quoted 54 lines · Brian Foster
Quoted 38 lines · Allison Henderson
This 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.
Signed-off-by Allison Henderson <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 53 +++++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 25 deletions(-)fs/xfs/libxfs/xfs_attr.c +19
-1@@ -288,8 +288,34 @@ 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; + +/* fs/xfs/libxfs/xfs_attr.c xfs_attr_set_args( · line 319
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +8
-0+* 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; }
Quoted 2 lines
(I think we usually try to add braces around all branches of an if/else if at least one branch requires them.)
Ok, will fix
Quoted 5 lines
Otherwise, the factoring looks Ok to me and this does improve on the wart from the previous patch:
Reviewed-by Brian Foster <[email protected]>
Great, thanks!
Allison
Quoted 41 lines
Quoted 40 lines
fs/xfs/libxfs/xfs_attr.c +1
-24return error;@@ -381,32 +407,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
Re: [PATCH v15 10/22] xfs: Hoist node transaction handling
In reply to Allison HendersonQuoted 39 lines · Allison Henderson
This 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.
Signed-off-by Allison Henderson <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 53 +++++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 25 deletions(-)fs/xfs/libxfs/xfs_attr.c +20
-1@@ -288,8 +288,34 @@ 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
fs/xfs/libxfs/xfs_attr.c xfs_attr_set_args( · line 320
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +7
-0+* start a new one. +*/ + error =xfs_trans_roll_inode (&args->trans, dp); +if (error) +return error; + goto node; + }else if (error)return error;
With the braces and indenting fixed the way Brian said,
--D
Quoted 38 lines
fs/xfs/libxfs/xfs_attr.c +1
-24@@ -381,32 +407,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
Re: [PATCH v15 10/22] xfs: Hoist node transaction handling
Quoted 52 lines · Darrick J. Wong
Quoted 39 lines · Allison Henderson
This 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.
Signed-off-by Allison Henderson <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 53 +++++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 25 deletions(-)fs/xfs/libxfs/xfs_attr.c +20
-1@@ -288,8 +288,34 @@ 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 fs/xfs/libxfs/xfs_attr.c xfs_attr_set_args( · line 320
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +7
-0+* start a new one. +*/ + error =xfs_trans_roll_inode (&args->trans, dp); +if (error) +return error; + goto node; + }else if (error)return error;With the braces and indenting fixed the way Brian said,
Quoted 1 line
Reviewed-by Darrick J. Wong <[email protected]>
Sure, will do. Thank you!
Allison
Quoted 41 lines
--D
Quoted 38 lines
fs/xfs/libxfs/xfs_attr.c +1
-24@@ -381,32 +407,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 v15 11/22 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 has become xfs_attr_remove_iter, which uses a sort of state machine like switch to keep track of where it was when EAGAIN was returned. xfs_attr_node_removename has also been modified to use the switch, and a new version of xfs_attr_remove_args consists of a simple loop to refresh the transaction until the operation is completed. A new XFS_DAC_DEFER_FINISH flag is used to finish the transaction where ever the existing code used to.
Calls to xfs_attr_rmtval_remove are replaced with the delay ready version __xfs_attr_rmtval_remove. We will rename __xfs_attr_rmtval_remove back to xfs_attr_rmtval_remove when we are done.
xfs_attr_rmtval_remove itself is still in use by the set routines (used during a rename). For reasons of 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 | 223 +++++++++++++++++++++++++++++----------- fs/xfs/libxfs/xfs_attr.h | 100 ++++++++++++++++++ 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, 294 insertions(+), 83 deletions(-)
fs/xfs/libxfs/xfs_attr.c +163 -60
@@ -57,8 +57,8 @@ 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_work(struct xfs_da_args *args); +STATIC int xfs_attr_node_removename_iter(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);
@@ -221,6 +221,34 @@ xfs_attr_is_shortform( ip->i_afp->if_nextents == 0); } +/* +* Checks to see if a delayed attribute transaction should be rolled. If so, +* also checks for a defer finish. Transaction is finished and rolled as +* needed, and returns true of false if the delayed operation should continue. +*/ +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); +if (error) +return error; + }else + error =xfs_trans_roll_inode (&args->trans, args->dp); + +return error; +} + STATIC intxfs_attr_set_fmt (struct xfs_da_args *args)
@@ -531,23 +559,58 @@ 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, + }; + +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; +} + +/* +* Remove the attribute specified in @args. +* +* This function may return -EAGAIN to signal that the transaction needs to be +* rolled. Callers should continue calling this function until they receive a +* return value other than -EAGAIN. +*/ +int +xfs_attr_remove_iter ( +struct xfs_delattr_context *dac) +{ +struct xfs_da_args *args = dac->da_args; +struct xfs_inode *dp = args->dp; -if (!xfs_inode_hasattr (dp)) { - error = -ENOATTR ; - }else if (dp->i_afp->if_format ==XFS_DINODE_FMT_LOCAL ) { +/* If we are shrinking a node, resume shrink */ +if (dac->dela_state ==XFS_DAS_RM_SHRINK ) + goto node; + +if (!xfs_inode_hasattr (dp)) +return -ENOATTR ; + +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); +return xfs_attr_shortform_remove (args); } -return error; +if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) +return xfs_attr_leaf_removename (args); +node: +/* If we are not short form or leaf, then proceed to remove node */ +return xfs_attr_node_removename_iter (dac); }/*
@@ -1191,14 +1254,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 ==
@@ -1207,22 +1272,28 @@ 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 ; } STATIC int -xfs_attr_node_remove_rmt ( -struct xfs_da_args *args, -struct xfs_da_state *state) +xfs_attr_node_remove_rmt ( +struct xfs_delattr_context *dac, +struct xfs_da_state *state) { -int error =0 ; +int error =0 ; - error =xfs_attr_rmtval_remove (args); +/* +* May return -EAGAIN to request that the caller recall this function +*/ + error =__xfs_attr_rmtval_remove (dac);if (error)return error;
@@ -1253,18 +1324,24 @@ xfs_attr_node_remove_cleanup( }/* -* Remove a name from a B-tree attribute list. +* Step through removeing a name from a B-tree attribute list. * * This will involve walking down the Btree, and may involve joining * leaf nodes and even joining intermediate nodes up to and including * the root node (a special case of an intermediate node). +* +* This routine is meant to function as either an inline or delayed operation, +* and may return -EAGAIN when the transaction needs to be rolled. Calling +* functions will need to handle this, and recall the function until a +* successful error code is returned. */ STATIC intxfs_attr_node_remove_step ( -struct xfs_da_args *args, -struct xfs_da_state *state) +struct xfs_delattr_context *dac) { -int error =0 ; +struct xfs_da_args *args = dac->da_args; +struct xfs_da_state *state = dac->da_state; +int error =0 ;/* * If there is an out-of-line value, de-allocate the blocks.
@@ -1272,7 +1349,10 @@ xfs_attr_node_remove_step(* overflow the maximum size of a transaction and/or hit a deadlock. */ if (args->rmtblkno >0 ) { - error =xfs_attr_node_remove_rmt (args, state); +/* +* May return -EAGAIN. Remove blocks until args->rmtblkno == 0 +*/ + error =xfs_attr_node_remove_rmt (dac, state);if (error)return error; }
@@ -1285,51 +1365,74 @@ xfs_attr_node_remove_step(* * This routine will find the blocks of the name to remove, remove them and * shrink the tree if needed. +* +* This routine is meant to function as either an inline or delayed operation, +* and may return -EAGAIN when the transaction needs to be rolled. Calling +* functions will need to handle this, and recall the function until a +* successful error code is returned. */ STATIC int -xfs_attr_node_removename ( -struct xfs_da_args *args) +xfs_attr_node_removename_iter ( +struct xfs_delattr_context *dac) { -struct xfs_da_state *state =NULL ; -int retval, error; -struct xfs_inode *dp = args->dp; +struct xfs_da_args *args = dac->da_args; +struct xfs_da_state *state =NULL ; +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; - - error =xfs_attr_node_remove_step (args, state); -if (error) - goto out; - - 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 (!dac->da_state) { + error =xfs_attr_node_removename_setup (dac);if (error) goto out; + } + state = dac->da_state; + +switch (dac->dela_state) { +case XFS_DAS_UNINIT :/* -* Commit the Btree join operation and start a new trans. +* repeatedly remove remote blocks, remove the entry and join. +* returns -EAGAIN or 0 for completion of the step. */ - error =xfs_trans_roll_inode (&args->trans, dp); + error =xfs_attr_node_remove_step (dac);if (error) - goto out; - } +break ; -/* -* 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); + 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 +*/ +if (retval && (state->path.active >1 )) { + error =xfs_da3_join (state); +if (error) + goto out; + + 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 +100 -0
112 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 v15 11/22] xfs: Add delay ready attr remove routines
Quoted 46 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_argshas becomexfs_attr_remove_iter, which uses a sort of state machine like switch to keep track of where it was when EAGAIN was returned.xfs_attr_node_removenamehas also been modified to use the switch, and 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 | 223 +++++++++++++++++++++++++++++----------- fs/xfs/libxfs/xfs_attr.h | 100 ++++++++++++++++++ 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, 294 insertions(+), 83 deletions(-)fs/xfs/libxfs/xfs_attr.c +0
-0
...
Quoted 16 lines
fs/xfs/libxfs/xfs_attr.c +12
-0@@ -221,6 +221,34 @@ xfs_attr_is_shortform( ip->i_afp->if_nextents == 0); } +/* +* Checks to see if a delayed attribute transaction should be rolled. If so, +* also checks for a defer finish. Transaction is finished and rolled as +* needed, and returns true of false if the delayed operation should continue. +*/ +int +xfs_attr_trans_roll ( +struct xfs_delattr_context *dac) +{ +struct xfs_da_args *args = dac->da_args; +int error; +
fs/xfs/libxfs/xfs_attr.c xfs_attr_is_shortform( · line 245
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10
-0+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); +if (error) +return error;
No need for the error check here.
Quoted 67 lines
fs/xfs/libxfs/xfs_attr.c +47
-10+ }else + error =xfs_trans_roll_inode (&args->trans, args->dp); + +return error; +} + STATIC intxfs_attr_set_fmt (struct xfs_da_args *args)@@ -531,23 +559,58 @@ 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, + }; + +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; +} + +/* +* Remove the attribute specified in @args. +* +* This function may return -EAGAIN to signal that the transaction needs to be +* rolled. Callers should continue calling this function until they receive a +* return value other than -EAGAIN. +*/ +int +xfs_attr_remove_iter ( +struct xfs_delattr_context *dac) +{ +struct xfs_da_args *args = dac->da_args; +struct xfs_inode *dp = args->dp; -if (!xfs_inode_hasattr (dp)) { - error = -ENOATTR ; - }else if (dp->i_afp->if_format ==XFS_DINODE_FMT_LOCAL ) { +/* If we are shrinking a node, resume shrink */ +if (dac->dela_state ==XFS_DAS_RM_SHRINK ) + goto node; + +if (!xfs_inode_hasattr (dp)) +return -ENOATTR ; + +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 {
fs/xfs/libxfs/xfs_attr.c xfs_has_attr( · line 613
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +6
-2- error =xfs_attr_node_removename (args); +return xfs_attr_shortform_remove (args); } -return error; +if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) +return xfs_attr_leaf_removename (args); +node: +/* If we are not short form or leaf, then proceed to remove node */ +return xfs_attr_node_removename_iter (dac);
Extra whitespace before the function name;
Also, can we lift xfs_attr_node_removename_iter() into this function, form the current implementation of xfs_attr_remove_iter() into the UNINIT state, and move the current UNINIT state into a new RMT_BLK state to support reentry? ISTM that would condense everything to a single switch statement that can live inside xfs_attr_remove_iter(). IOW, we can kill off the 'node:' level and multi-layer state management here. Hm?
Quoted 3 lines
fs/xfs/libxfs/xfs_attr.c +0
-0}/*
...
Quoted 12 lines
fs/xfs/libxfs/xfs_attr.c +4
-2@@ -1207,22 +1272,28 @@ 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)
fs/xfs/libxfs/xfs_attr.c int xfs_attr_node_removename_setup( · line 1287
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +2
-3+xfs_da_state_free (*state);return 0 ; } STATIC int -xfs_attr_node_remove_rmt ( -struct xfs_da_args *args, -struct xfs_da_state *state) +xfs_attr_node_remove_rmt (
Extra whitespace before the opening brace.
Quoted 14 lines
fs/xfs/libxfs/xfs_attr.c +7
-2+struct xfs_delattr_context *dac, + struct xfs_da_state *state) { -int error =0 ; + int error = 0; - error =xfs_attr_rmtval_remove (args); +/* +* May return -EAGAIN to request that the caller recall this function +*/ + error =__xfs_attr_rmtval_remove (dac);if (error)return error;
...
Quoted 54 lines
fs/xfs/libxfs/xfs_attr.c +18
-23@@ -1285,51 +1365,74 @@ xfs_attr_node_remove_step(* * This routine will find the blocks of the name to remove, remove them and * shrink the tree if needed. +* +* This routine is meant to function as either an inline or delayed operation, +* and may return -EAGAIN when the transaction needs to be rolled. Calling +* functions will need to handle this, and recall the function until a +* successful error code is returned. */ STATIC int -xfs_attr_node_removename ( -struct xfs_da_args *args) +xfs_attr_node_removename_iter ( +struct xfs_delattr_context *dac) { -struct xfs_da_state *state =NULL ; -int retval, error; -struct xfs_inode *dp = args->dp; +struct xfs_da_args *args = dac->da_args; +struct xfs_da_state *state =NULL ; +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; - - error =xfs_attr_node_remove_step (args, state); -if (error) - goto out; - - 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 (!dac->da_state) { + error =xfs_attr_node_removename_setup (dac);if (error) goto out; + } + state = dac->da_state; + +switch (dac->dela_state) { +case XFS_DAS_UNINIT :/*
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_remove_step( · line 1400
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +4
-4-* Commit the Btree join operation and start a new trans. +* repeatedly remove remote blocks, remove the entry and join. +* returns -EAGAIN or 0 for completion of the step. */ - error =xfs_trans_roll_inode (&args->trans, dp); + error =xfs_attr_node_remove_step (dac);if (error) - goto out; - } +break ;
Hmm.. so re: my comment further down on xfs_attr_rmtval_remove(), wouldn't that change semantics here? I.e., once remote blocks are removed this would previously carry on with a clean transaction. Now it looks like we'd carry on with the dirty transaction that removed the last remote extent. This suggests that perhaps we should return once more and fall into a new state to remove the name..? Also, it would be nice to remove the several seemingly unnecessary layers of indirection here. For example, something like the following (also considering my comment above wrt to xfs_attr_remove_iter() and UNINIT):
case UNINIT:
...
/* fallthrough */
case RMTBLK:
if (args->rmtblkno > 0) {
dac->dela_state = RMTBLK;
error = __xfs_attr_rmtval_remove(dac);
if (error)
break;
ASSERT(args->rmtblkno == 0);
xfs_attr_refillstate(state);
dac->flags |= XFS_DAC_DEFER_FINISH;
dac->dela_state = RMNAME;
return -EAGAIN;
}
/* fallthrough */
case RMNAME:
...
...Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c +1
-5-/* -* 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); + retval =xfs_attr_node_remove_cleanup (args, 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;
Previously this would roll once and exit the loop on retval == 0. Now it looks like we break out of the loop immediately. Why the change?
Brian
Quoted 88 lines
fs/xfs/libxfs/xfs_attr_remote.c +20
-14-/* -* Close out trans and start the next one in the chain. -*/ - error =xfs_trans_roll_inode (&args->trans, args->dp); + error =xfs_attr_trans_roll (&dac);if (error)return error; - }while (retval == -EAGAIN ); + }while (true); -return 0 ; +return error; }/* * Remove the value associated with an attribute by deleting the out-of-line -* buffer that it is stored on. Returns EAGAIN for the caller to refresh the +* buffer that it is stored on. Returns -EAGAIN for the caller to refresh the * transaction and re-call the function */ int __xfs_attr_rmtval_remove ( -struct xfs_da_args *args) +struct xfs_delattr_context *dac) { -int error, done; +struct xfs_da_args *args = dac->da_args; +int error, done;/* * Unmap value blocks for this attr. @@ -719,12 +719,20 @@ __xfs_attr_rmtval_remove(if (error)return error; - error =xfs_defer_finish (&args->trans); -if (error) -return error; - -if (!done) +/* +* We dont need an explicit state here to pick up where we left off. We +* can figure it out using the !done return code. Calling function only +* needs to keep recalling this routine until we indicate to stop by +* returning anything other than -EAGAIN. The actual value of +* attr->xattri_dela_state may be some value reminicent of the calling +* function, but it's value is irrelevant with in the context of this +* function. Once we are done here, the next state is set as needed +* by the parent +*/ +if (!done) { + dac->flags |=XFS_DAC_DEFER_FINISH ;return -EAGAIN ; + }return error; }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 v15 11/22] xfs: Add delay ready attr remove routines
Quoted 68 lines · Brian Foster
Quoted 46 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_argshas becomexfs_attr_remove_iter, which uses a sort of state machine like switch to keep track of where it was when EAGAIN was returned.xfs_attr_node_removenamehas also been modified to use the switch, and 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 | 223 +++++++++++++++++++++++++++++----------- fs/xfs/libxfs/xfs_attr.h | 100 ++++++++++++++++++ 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, 294 insertions(+), 83 deletions(-)fs/xfs/libxfs/xfs_attr.c +0
-0...
Quoted 20 lines
fs/xfs/libxfs/xfs_attr.c +16
-0@@ -221,6 +221,34 @@ xfs_attr_is_shortform( ip->i_afp->if_nextents == 0); } +/* +* Checks to see if a delayed attribute transaction should be rolled. If so, +* also checks for a defer finish. Transaction is finished and rolled as +* needed, and returns true of false if the delayed operation should continue. +*/ +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
Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_is_shortform( · line 245
Quoted 6 lines
fs/xfs/libxfs/xfs_attr.c +6
-0+* ops. +*/ + dac->flags &= ~XFS_DAC_DEFER_FINISH ; + error =xfs_defer_finish (&args->trans); +if (error) +return error;No need for the error check here.
Sure, will clean up
Quoted 72 lines
Quoted 72 lines
fs/xfs/libxfs/xfs_attr.c +48
-11+ }else + error =xfs_trans_roll_inode (&args->trans, args->dp); + +return error; +} + STATIC intxfs_attr_set_fmt (struct xfs_da_args *args)@@ -531,23 +559,58 @@ 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, + }; + +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; +} + +/* +* Remove the attribute specified in @args. +* +* This function may return -EAGAIN to signal that the transaction needs to be +* rolled. Callers should continue calling this function until they receive a +* return value other than -EAGAIN. +*/ +int +xfs_attr_remove_iter ( +struct xfs_delattr_context *dac) +{ +struct xfs_da_args *args = dac->da_args; +struct xfs_inode *dp = args->dp; -if (!xfs_inode_hasattr (dp)) { - error = -ENOATTR ; - }else if (dp->i_afp->if_format ==XFS_DINODE_FMT_LOCAL ) { +/* If we are shrinking a node, resume shrink */ +if (dac->dela_state ==XFS_DAS_RM_SHRINK ) + goto node; + +if (!xfs_inode_hasattr (dp)) +return -ENOATTR ; + +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); +return xfs_attr_shortform_remove (args); }
Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c xfs_has_attr( · line 613
Quoted 6 lines
fs/xfs/libxfs/xfs_attr.c +5
-1-return error; +if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) +return xfs_attr_leaf_removename (args); +node: +/* If we are not short form or leaf, then proceed to remove node */ +return xfs_attr_node_removename_iter (dac);Extra whitespace before the function name;
Ok, will fix
Quoted 8 lines
Also, can we lift
xfs_attr_node_removename_iter()into this function, form the current implementation ofxfs_attr_remove_iter()into the UNINIT state, and move the current UNINIT state into a newRMT_BLKstate to support reentry? ISTM that would condense everything to a single switch statement that can live insidexfs_attr_remove_iter(). IOW, we can kill off the 'node:' level and multi-layer state management here. Hm?
Sure, I think the lift should be fine, though I dont think we'll need the extra state. See below....
Quoted 22 lines
Quoted 4 lines
fs/xfs/libxfs/xfs_attr.c +0
-0}/* ...
Quoted 17 lines
fs/xfs/libxfs/xfs_attr.c +5
-2@@ -1207,22 +1272,28 @@ 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 ; }
Quoted 7 lines
fs/xfs/libxfs/xfs_attr.c int xfs_attr_node_removename_setup( · line 1287
Quoted 5 lines
fs/xfs/libxfs/xfs_attr.c +1
-3STATIC int -xfs_attr_node_remove_rmt ( -struct xfs_da_args *args, -struct xfs_da_state *state) +xfs_attr_node_remove_rmt (Extra whitespace before the opening brace.
ok, will fix
Quoted 79 lines
Quoted 15 lines
fs/xfs/libxfs/xfs_attr.c +7
-2+struct xfs_delattr_context *dac, + struct xfs_da_state *state) { -int error =0 ; + int error = 0; - error =xfs_attr_rmtval_remove (args); +/* +* May return -EAGAIN to request that the caller recall this function +*/ + error =__xfs_attr_rmtval_remove (dac);if (error)return error;...
Quoted 63 lines
fs/xfs/libxfs/xfs_attr.c +21
-27@@ -1285,51 +1365,74 @@ xfs_attr_node_remove_step(* * This routine will find the blocks of the name to remove, remove them and * shrink the tree if needed. +* +* This routine is meant to function as either an inline or delayed operation, +* and may return -EAGAIN when the transaction needs to be rolled. Calling +* functions will need to handle this, and recall the function until a +* successful error code is returned. */ STATIC int -xfs_attr_node_removename ( -struct xfs_da_args *args) +xfs_attr_node_removename_iter ( +struct xfs_delattr_context *dac) { -struct xfs_da_state *state =NULL ; -int retval, error; -struct xfs_inode *dp = args->dp; +struct xfs_da_args *args = dac->da_args; +struct xfs_da_state *state =NULL ; +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; - - error =xfs_attr_node_remove_step (args, state); -if (error) - goto out; - - 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 (!dac->da_state) { + error =xfs_attr_node_removename_setup (dac);if (error) goto out; + } + state = dac->da_state; + +switch (dac->dela_state) { +case XFS_DAS_UNINIT :/* -* Commit the Btree join operation and start a new trans. +* repeatedly remove remote blocks, remove the entry and join. +* returns -EAGAIN or 0 for completion of the step. */ - error =xfs_trans_roll_inode (&args->trans, dp); + error =xfs_attr_node_remove_step (dac);if (error) - goto out; - }
Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_remove_step( · line 1400
Quoted 1 line
fs/xfs/libxfs/xfs_attr.c +1
-0+break ;Hmm.. so re: my comment further down on
xfs_attr_rmtval_remove(), wouldn't that change semantics here? I.e., once remote blocks are removed this would previously carry on with a clean transaction. Now it looks like we'd carry on with the dirty transaction that removed the last remote extent. This suggests that perhaps we should return once more and fall into a new state to remove the name..?
I suspect the diff might be making this a bit difficult to see. The roll that you see being removed here belongs to the transaction we hoisted up in patch 3 which happens after the clean up below, and we have the corresponding EAGAIN fot that one. I think the diff gets things a little interlaced here because the switch adds another level of indentation.
some times i do like to I use a graphical diffviewer like diffuse when patches get weird like this. Something like this:
git config --global diff.tool diffuse
git difftool 3c53e49 e201c09
You'd need to download the branch and also the diffuse tool, but sometimes i think it makes some of these diffs a bit easier to see
Also, it would be
Quoted 4 lines
nice to remove the several seemingly unnecessary layers of indirection here. For example, something like the following (also considering my comment above wrt to
xfs_attr_remove_iter()and UNINIT):
Quoted 16 lines
case UNINIT:
...
/* fallthrough */
case RMTBLK:
if (args->rmtblkno > 0) {
dac->dela_state = RMTBLK;
error = __xfs_attr_rmtval_remove(dac);
if (error)
break;
ASSERT(args->rmtblkno == 0);
xfs_attr_refillstate(state);
dac->flags |= XFS_DAC_DEFER_FINISH;
dac->dela_state = RMNAME;
return -EAGAIN;
}Ok, this looks to me like we've hoisted both xfs_attr_node_remove_rmt and xfs_attr_node_remove_step into this scope, but I still think this adds an extra roll where non previously was. With out that extra EAGAIN, I think we are fine to have all that just under the UNINIT case.
I also think it's also worth noteing here that this is kind of a
reverse of patch 1, which I think we put in for reasons of trying to modularize the higher level functions as much as possible.
I suspect some of where you were going with this may have been influenced by the earlier diff confusion too. Maybe take a second look there before we go too much down this change....
Quoted 6 lines
/* fallthrough */ case RMNAME: ... ...Quoted 1 line
Quoted 8 lines
Quoted 7 lines
fs/xfs/libxfs/xfs_attr.c +1
-5-/* -* 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); + retval =xfs_attr_node_remove_cleanup (args, state);...
I think the overlooked EAGAIN was in this area that got clipped out.....
Quoted 5 lines
Quoted 4 lines
fs/xfs/libxfs/xfs_attr_remote.c +0
-0...
Quoted 13 lines
fs/xfs/libxfs/xfs_attr_remote.c c( · line 692
Quoted 10 lines
fs/xfs/libxfs/xfs_attr_remote.c +3
-3@@ -685,31 +687,29 @@ c(* 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;Previously this would roll once and exit the loop on retval == 0. Now it looks like we break out of the loop immediately. Why the change?
Gosh, I think sometime in reviewing v9, we had come up with a "xfs_attr_roll_again" helper that took the error code as a paramater and decided whether or not to roll. And then in v10 i think people thought that was weird and we turned it into xfs_attr_trans_roll. I think I likley forgot to restore the orginal retval handling here. This whole function disappears in the next patch, but the original error handling should be restored to keep things consistent. Thx for the catch!
Thx for the reviews!! I know it's complicated! I've chased my tail many times with it myself :-)
Allison
Quoted 92 lines
Brian
Quoted 88 lines
fs/xfs/libxfs/xfs_attr_remote.c +20
-14-/* -* Close out trans and start the next one in the chain. -*/ - error =xfs_trans_roll_inode (&args->trans, args->dp); + error =xfs_attr_trans_roll (&dac);if (error)return error; - }while (retval == -EAGAIN ); + }while (true); -return 0 ; +return error; }/* * Remove the value associated with an attribute by deleting the out-of-line -* buffer that it is stored on. Returns EAGAIN for the caller to refresh the +* buffer that it is stored on. Returns -EAGAIN for the caller to refresh the * transaction and re-call the function */ int __xfs_attr_rmtval_remove ( -struct xfs_da_args *args) +struct xfs_delattr_context *dac) { -int error, done; +struct xfs_da_args *args = dac->da_args; +int error, done;/* * Unmap value blocks for this attr. @@ -719,12 +719,20 @@ __xfs_attr_rmtval_remove(if (error)return error; - error =xfs_defer_finish (&args->trans); -if (error) -return error; - -if (!done) +/* +* We dont need an explicit state here to pick up where we left off. We +* can figure it out using the !done return code. Calling function only +* needs to keep recalling this routine until we indicate to stop by +* returning anything other than -EAGAIN. The actual value of +* attr->xattri_dela_state may be some value reminicent of the calling +* function, but it's value is irrelevant with in the context of this +* function. Once we are done here, the next state is set as needed +* by the parent +*/ +if (!done) { + dac->flags |=XFS_DAC_DEFER_FINISH ;return -EAGAIN ; + }return error; }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 v15 11/22] xfs: Add delay ready attr remove routines
Quoted 50 lines · Allison Henderson
Quoted 47 lines · Brian Foster
Quoted 46 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_argshas becomexfs_attr_remove_iter, which uses a sort of state machine like switch to keep track of where it was when EAGAIN was returned.xfs_attr_node_removenamehas also been modified to use the switch, and 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 | 223 +++++++++++++++++++++++++++++----------- fs/xfs/libxfs/xfs_attr.h | 100 ++++++++++++++++++ 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, 294 insertions(+), 83 deletions(-)fs/xfs/libxfs/xfs_attr.c +0
-0
...
Quoted 69 lines
Quoted 61 lines
Quoted 61 lines
fs/xfs/libxfs/xfs_attr.c +21
-27@@ -1285,51 +1365,74 @@ xfs_attr_node_remove_step(* * This routine will find the blocks of the name to remove, remove them and * shrink the tree if needed. +* +* This routine is meant to function as either an inline or delayed operation, +* and may return -EAGAIN when the transaction needs to be rolled. Calling +* functions will need to handle this, and recall the function until a +* successful error code is returned. */ STATIC int -xfs_attr_node_removename ( -struct xfs_da_args *args) +xfs_attr_node_removename_iter ( +struct xfs_delattr_context *dac) { -struct xfs_da_state *state =NULL ; -int retval, error; -struct xfs_inode *dp = args->dp; +struct xfs_da_args *args = dac->da_args; +struct xfs_da_state *state =NULL ; +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; - - error =xfs_attr_node_remove_step (args, state); -if (error) - goto out; - - 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 (!dac->da_state) { + error =xfs_attr_node_removename_setup (dac);if (error) goto out; + } + state = dac->da_state; + +switch (dac->dela_state) { +case XFS_DAS_UNINIT :/* -* Commit the Btree join operation and start a new trans. +* repeatedly remove remote blocks, remove the entry and join. +* returns -EAGAIN or 0 for completion of the step. */ - error =xfs_trans_roll_inode (&args->trans, dp); + error =xfs_attr_node_remove_step (dac);if (error) - goto out; - }Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_remove_step( · line 1398
Quoted 1 line
fs/xfs/libxfs/xfs_attr.c +1
-0+break ;Hmm.. so re: my comment further down on
xfs_attr_rmtval_remove(), wouldn't that change semantics here? I.e., once remote blocks are removed this would previously carry on with a clean transaction. Now it looks like we'd carry on with the dirty transaction that removed the last remote extent. This suggests that perhaps we should return once more and fall into a new state to remove the name..?
Quoted 6 lines
I suspect the diff might be making this a bit difficult to see. The roll that you see being removed here belongs to the transaction we hoisted up in patch 3 which happens after the clean up below, and we have the corresponding EAGAIN fot that one. I think the diff gets things a little interlaced here because the switch adds another level of indentation.
Hmm.. the roll in patch 3 appears to be related to the _cleanup() helper. What I'm referring to here is the state of the transaction after the final remote block is removed from the attr. I'm not sure we're talking about the same thing here..
Quoted 9 lines
some times i do like to I use a graphical diffviewer like diffuse when patches get weird like this. Something like this:
git config --global diff.tool diffuse
git difftool 3c53e49 e201c09You'd need to download the branch and also the diffuse tool, but sometimes i think it makes some of these diffs a bit easier to see
I think it's easier just to refer to the code directly. The current upstream code flows down into:
...xfs_attr_node_removename()
xfs_attr_node_remove_rmt()
xfs_attr_rmtval_remove()
... which then implements the following loop:
do {
retval = __xfs_attr_rmtval_remove(args);
if (retval && retval != -EAGAIN)
return retval;
/*
* Close out trans and start the next one in the chain.
*/
error = xfs_trans_roll_inode(&args->trans, args->dp);
if (error)
return error;
} while (retval == -EAGAIN);This rolls the transaction when retval == -EAGAIN or retval == 0, thus always returns with a clean transaction after the remote block removal completes.
The code as of this patch does:
...xfs_attr_node_removename_iter()
xfs_attr_node_remove_step()
xfs_attr_node_remove_rmt()
__xfs_attr_rmtval_remove()
... which either returns -EAGAIN (since the roll is now implemented at the very top) or 0 when done == true. The transaction might be dirty in the latter case, but xfs_attr_node_removename_iter() moves right on to xfs_attr_node_remove_cleanup() which can now do more work in that same transaction. Am I following that correctly?
Quoted 29 lines
Also, it would be
Quoted 4 lines
nice to remove the several seemingly unnecessary layers of indirection here. For example, something like the following (also considering my comment above wrt to
xfs_attr_remove_iter()and UNINIT):Quoted 16 lines
case UNINIT: ... /* fallthrough */ case RMTBLK: if (args->rmtblkno > 0) { dac->dela_state = RMTBLK; error = __xfs_attr_rmtval_remove(dac); if (error) break; ASSERT(args->rmtblkno == 0); xfs_attr_refillstate(state); dac->flags |= XFS_DAC_DEFER_FINISH; dac->dela_state = RMNAME; return -EAGAIN; }Ok, this looks to me like we've hoisted both
xfs_attr_node_remove_rmtandxfs_attr_node_remove_stepinto this scope, but I still think this adds an extra roll where non previously was. With out that extra EAGAIN, I think we are fine to have all that just under the UNINIT case. I also think it's also worth noteing here that this is kind of a reverse of patch 1, which I think we put in for reasons of trying to modularize the higher level functions as much as possible.
Quoted 4 lines
I suspect some of where you were going with this may have been influenced by the earlier diff confusion too. Maybe take a second look there before we go too much down this change....
I can certainly be getting lost somewhere in all the refactoring. If so, can you point out where in the flow described above?
Brian
Quoted 138 lines
Quoted 6 lines
/* fallthrough */ case RMNAME: ... ...Quoted 7 lines
Quoted 6 lines
fs/xfs/libxfs/xfs_attr.c +1
-5-/* -* 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); + retval =xfs_attr_node_remove_cleanup (args, state);...
I think the overlooked EAGAIN was in this area that got clipped out.....
Quoted 5 lines
Quoted 4 lines
fs/xfs/libxfs/xfs_attr_remote.c +0
-0...
Quoted 13 lines
fs/xfs/libxfs/xfs_attr_remote.c c( · line 692
Quoted 10 lines
fs/xfs/libxfs/xfs_attr_remote.c +3
-3@@ -685,31 +687,29 @@ c(* 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;Previously this would roll once and exit the loop on retval == 0. Now it looks like we break out of the loop immediately. Why the change?
Gosh, I think sometime in reviewing v9, we had come up with a "
xfs_attr_roll_again" helper that took the error code as a paramater and decided whether or not to roll. And then in v10 i think people thought that was weird and we turned it intoxfs_attr_trans_roll. I think I likley forgot to restore the orginal retval handling here. This whole function disappears in the next patch, but the original error handling should be restored to keep things consistent. Thx for the catch!Thx for the reviews!! I know it's complicated! I've chased my tail many times with it myself :-)
Allison
Quoted 86 lines
Brian
Quoted 82 lines
fs/xfs/libxfs/xfs_attr_remote.c +20
-14-/* -* Close out trans and start the next one in the chain. -*/ - error =xfs_trans_roll_inode (&args->trans, args->dp); + error =xfs_attr_trans_roll (&dac);if (error)return error; - }while (retval == -EAGAIN ); + }while (true); -return 0 ; +return error; }/* * Remove the value associated with an attribute by deleting the out-of-line -* buffer that it is stored on. Returns EAGAIN for the caller to refresh the +* buffer that it is stored on. Returns -EAGAIN for the caller to refresh the * transaction and re-call the function */ int __xfs_attr_rmtval_remove ( -struct xfs_da_args *args) +struct xfs_delattr_context *dac) { -int error, done; +struct xfs_da_args *args = dac->da_args; +int error, done;/* * Unmap value blocks for this attr. @@ -719,12 +719,20 @@ __xfs_attr_rmtval_remove(if (error)return error; - error =xfs_defer_finish (&args->trans); -if (error) -return error; - -if (!done) +/* +* We dont need an explicit state here to pick up where we left off. We +* can figure it out using the !done return code. Calling function only +* needs to keep recalling this routine until we indicate to stop by +* returning anything other than -EAGAIN. The actual value of +* attr->xattri_dela_state may be some value reminicent of the calling +* function, but it's value is irrelevant with in the context of this +* function. Once we are done here, the next state is set as needed +* by the parent +*/ +if (!done) { + dac->flags |=XFS_DAC_DEFER_FINISH ;return -EAGAIN ; + }return error; }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 v15 11/22] xfs: Add delay ready attr remove routines
Quoted 213 lines · Brian Foster
Quoted 50 lines · Allison Henderson
Quoted 47 lines · Brian Foster
Quoted 46 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_argshas becomexfs_attr_remove_iter, which uses a sort of state machine like switch to keep track of where it was when EAGAIN was returned.xfs_attr_node_removenamehas also been modified to use the switch, and 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 | 223 +++++++++++++++++++++++++++++----------- fs/xfs/libxfs/xfs_attr.h | 100 ++++++++++++++++++ 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, 294 insertions(+), 83 deletions(-)fs/xfs/libxfs/xfs_attr.c +0
-0...
Quoted 69 lines
Quoted 61 lines
Quoted 61 lines
fs/xfs/libxfs/xfs_attr.c +21
-27@@ -1285,51 +1365,74 @@ xfs_attr_node_remove_step(* * This routine will find the blocks of the name to remove, remove them and * shrink the tree if needed. +* +* This routine is meant to function as either an inline or delayed operation, +* and may return -EAGAIN when the transaction needs to be rolled. Calling +* functions will need to handle this, and recall the function until a +* successful error code is returned. */ STATIC int -xfs_attr_node_removename ( -struct xfs_da_args *args) +xfs_attr_node_removename_iter ( +struct xfs_delattr_context *dac) { -struct xfs_da_state *state =NULL ; -int retval, error; -struct xfs_inode *dp = args->dp; +struct xfs_da_args *args = dac->da_args; +struct xfs_da_state *state =NULL ; +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; - - error =xfs_attr_node_remove_step (args, state); -if (error) - goto out; - - 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 (!dac->da_state) { + error =xfs_attr_node_removename_setup (dac);if (error) goto out; + } + state = dac->da_state; + +switch (dac->dela_state) { +case XFS_DAS_UNINIT :/* -* Commit the Btree join operation and start a new trans. +* repeatedly remove remote blocks, remove the entry and join. +* returns -EAGAIN or 0 for completion of the step. */ - error =xfs_trans_roll_inode (&args->trans, dp); + error =xfs_attr_node_remove_step (dac);if (error) - goto out; - }Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_remove_step( · line 1398
Quoted 1 line
fs/xfs/libxfs/xfs_attr.c +1
-0+break ;Hmm.. so re: my comment further down on
xfs_attr_rmtval_remove(), wouldn't that change semantics here? I.e., once remote blocks are removed this would previously carry on with a clean transaction. Now it looks like we'd carry on with the dirty transaction that removed the last remote extent. This suggests that perhaps we should return once more and fall into a new state to remove the name..?Quoted 6 lines
I suspect the diff might be making this a bit difficult to see. The roll that you see being removed here belongs to the transaction we hoisted up in patch 3 which happens after the clean up below, and we have the corresponding EAGAIN fot that one. I think the diff gets things a little interlaced here because the switch adds another level of indentation.
Hmm.. the roll in patch 3 appears to be related to the
_cleanup()helper. What I'm referring to here is the state of the transaction after the final remote block is removed from the attr. I'm not sure we're talking about the same thing here..Quoted 9 lines
some times i do like to I use a graphical diffviewer like diffuse when patches get weird like this. Something like this:
git config --global diff.tool diffuse
git difftool 3c53e49 e201c09You'd need to download the branch and also the diffuse tool, but sometimes i think it makes some of these diffs a bit easier to see
I think it's easier just to refer to the code directly. The current upstream code flows down into:
...
xfs_attr_node_removename()
xfs_attr_node_remove_rmt()
xfs_attr_rmtval_remove()... which then implements the following loop:
do { retval = __xfs_attr_rmtval_remove(args); if (retval && retval != -EAGAIN) return retval; /* * Close out trans and start the next one in the chain. */ error = xfs_trans_roll_inode(&args->trans, args->dp); if (error) return error; } while (retval == -EAGAIN);This rolls the transaction when retval ==
-EAGAINor retval == 0, thus always returns with a clean transaction after the remote block removal completes.The code as of this patch does:
...
xfs_attr_node_removename_iter()
xfs_attr_node_remove_step()
xfs_attr_node_remove_rmt()__xfs_attr_rmtval_remove()... which either returns
-EAGAIN(since the roll is now implemented at the very top) or 0 when done == true. The transaction might be dirty in the latter case, butxfs_attr_node_removename_iter()moves right on toxfs_attr_node_remove_cleanup()which can now do more work in that same transaction. Am I following that correctly?Quoted 29 lines
Also, it would be
Quoted 4 lines
nice to remove the several seemingly unnecessary layers of indirection here. For example, something like the following (also considering my comment above wrt to
xfs_attr_remove_iter()and UNINIT):Quoted 16 lines
case UNINIT: ... /* fallthrough */ case RMTBLK: if (args->rmtblkno > 0) { dac->dela_state = RMTBLK; error = __xfs_attr_rmtval_remove(dac); if (error) break; ASSERT(args->rmtblkno == 0); xfs_attr_refillstate(state); dac->flags |= XFS_DAC_DEFER_FINISH; dac->dela_state = RMNAME; return -EAGAIN; }Ok, this looks to me like we've hoisted both
xfs_attr_node_remove_rmtandxfs_attr_node_remove_stepinto this scope, but I still think this adds an extra roll where non previously was. With out that extra EAGAIN, I think we are fine to have all that just under the UNINIT case. I also think it's also worth noteing here that this is kind of a reverse of patch 1, which I think we put in for reasons of trying to modularize the higher level functions as much as possible.
Quoted 7 lines
Quoted 4 lines
I suspect some of where you were going with this may have been influenced by the earlier diff confusion too. Maybe take a second look there before we go too much down this change....
I can certainly be getting lost somewhere in all the refactoring. If so, can you point out where in the flow described above?
Ok, I think see it. So basically I think this means we cant have the helpers because it's ambiguos as to if the transaction is dirty or not.
I dont see that there's anything in the review history where we
rationalized that away, so I think we just overlooked it. So I think what this means is that we need to reverse apply commit 72b97ea40d (which is where we added xfs_attr_node_remove_rmt), then drop patch 1 which leaves no need for patch 3, since the transaction will have not moved. Then add state RMTBLK? I think that arrives at what you have here.
Allison
Quoted 142 lines
Brian
Quoted 138 lines
Quoted 6 lines
/* fallthrough */ case RMNAME: ... ...Quoted 7 lines
Quoted 6 lines
fs/xfs/libxfs/xfs_attr.c +1
-5-/* -* 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); + retval =xfs_attr_node_remove_cleanup (args, state);...
I think the overlooked EAGAIN was in this area that got clipped out.....
Quoted 5 lines
Quoted 4 lines
fs/xfs/libxfs/xfs_attr_remote.c +0
-0...
Quoted 13 lines
fs/xfs/libxfs/xfs_attr_remote.c c( · line 692
Quoted 10 lines
fs/xfs/libxfs/xfs_attr_remote.c +3
-3@@ -685,31 +687,29 @@ c(* 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;Previously this would roll once and exit the loop on retval == 0. Now it looks like we break out of the loop immediately. Why the change?
Gosh, I think sometime in reviewing v9, we had come up with a "
xfs_attr_roll_again" helper that took the error code as a paramater and decided whether or not to roll. And then in v10 i think people thought that was weird and we turned it intoxfs_attr_trans_roll. I think I likley forgot to restore the orginal retval handling here. This whole function disappears in the next patch, but the original error handling should be restored to keep things consistent. Thx for the catch!Thx for the reviews!! I know it's complicated! I've chased my tail many times with it myself :-)
Allison
Quoted 86 lines
Brian
Quoted 82 lines
fs/xfs/libxfs/xfs_attr_remote.c +20
-14-/* -* Close out trans and start the next one in the chain. -*/ - error =xfs_trans_roll_inode (&args->trans, args->dp); + error =xfs_attr_trans_roll (&dac);if (error)return error; - }while (retval == -EAGAIN ); + }while (true); -return 0 ; +return error; }/* * Remove the value associated with an attribute by deleting the out-of-line -* buffer that it is stored on. Returns EAGAIN for the caller to refresh the +* buffer that it is stored on. Returns -EAGAIN for the caller to refresh the * transaction and re-call the function */ int __xfs_attr_rmtval_remove ( -struct xfs_da_args *args) +struct xfs_delattr_context *dac) { -int error, done; +struct xfs_da_args *args = dac->da_args; +int error, done;/* * Unmap value blocks for this attr. @@ -719,12 +719,20 @@ __xfs_attr_rmtval_remove(if (error)return error; - error =xfs_defer_finish (&args->trans); -if (error) -return error; - -if (!done) +/* +* We dont need an explicit state here to pick up where we left off. We +* can figure it out using the !done return code. Calling function only +* needs to keep recalling this routine until we indicate to stop by +* returning anything other than -EAGAIN. The actual value of +* attr->xattri_dela_state may be some value reminicent of the calling +* function, but it's value is irrelevant with in the context of this +* function. Once we are done here, the next state is set as needed +* by the parent +*/ +if (!done) { + dac->flags |=XFS_DAC_DEFER_FINISH ;return -EAGAIN ; + }return error; }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 v15 11/22] xfs: Add delay ready attr remove routines
Quoted 223 lines · Allison Henderson
Quoted 213 lines · Brian Foster
Quoted 50 lines · Allison Henderson
Quoted 47 lines · Brian Foster
Quoted 46 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_argshas becomexfs_attr_remove_iter, which uses a sort of state machine like switch to keep track of where it was when EAGAIN was returned.xfs_attr_node_removenamehas also been modified to use the switch, and 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 | 223 +++++++++++++++++++++++++++++----------- fs/xfs/libxfs/xfs_attr.h | 100 ++++++++++++++++++ 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, 294 insertions(+), 83 deletions(-)fs/xfs/libxfs/xfs_attr.c +0
-0...
Quoted 69 lines
Quoted 61 lines
Quoted 61 lines
fs/xfs/libxfs/xfs_attr.c +21
-27@@ -1285,51 +1365,74 @@ xfs_attr_node_remove_step(* * This routine will find the blocks of the name to remove, remove them and * shrink the tree if needed. +* +* This routine is meant to function as either an inline or delayed operation, +* and may return -EAGAIN when the transaction needs to be rolled. Calling +* functions will need to handle this, and recall the function until a +* successful error code is returned. */ STATIC int -xfs_attr_node_removename ( -struct xfs_da_args *args) +xfs_attr_node_removename_iter ( +struct xfs_delattr_context *dac) { -struct xfs_da_state *state =NULL ; -int retval, error; -struct xfs_inode *dp = args->dp; +struct xfs_da_args *args = dac->da_args; +struct xfs_da_state *state =NULL ; +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; - - error =xfs_attr_node_remove_step (args, state); -if (error) - goto out; - - 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 (!dac->da_state) { + error =xfs_attr_node_removename_setup (dac);if (error) goto out; + } + state = dac->da_state; + +switch (dac->dela_state) { +case XFS_DAS_UNINIT :/* -* Commit the Btree join operation and start a new trans. +* repeatedly remove remote blocks, remove the entry and join. +* returns -EAGAIN or 0 for completion of the step. */ - error =xfs_trans_roll_inode (&args->trans, dp); + error =xfs_attr_node_remove_step (dac);if (error) - goto out; - }Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_remove_step( · line 1398
Quoted 1 line
fs/xfs/libxfs/xfs_attr.c +1
-0+break ;Hmm.. so re: my comment further down on
xfs_attr_rmtval_remove(), wouldn't that change semantics here? I.e., once remote blocks are removed this would previously carry on with a clean transaction. Now it looks like we'd carry on with the dirty transaction that removed the last remote extent. This suggests that perhaps we should return once more and fall into a new state to remove the name..?Quoted 6 lines
I suspect the diff might be making this a bit difficult to see. The roll that you see being removed here belongs to the transaction we hoisted up in patch 3 which happens after the clean up below, and we have the corresponding EAGAIN fot that one. I think the diff gets things a little interlaced here because the switch adds another level of indentation.
Hmm.. the roll in patch 3 appears to be related to the
_cleanup()helper. What I'm referring to here is the state of the transaction after the final remote block is removed from the attr. I'm not sure we're talking about the same thing here..Quoted 9 lines
some times i do like to I use a graphical diffviewer like diffuse when patches get weird like this. Something like this:
git config --global diff.tool diffuse
git difftool 3c53e49 e201c09You'd need to download the branch and also the diffuse tool, but sometimes i think it makes some of these diffs a bit easier to see
I think it's easier just to refer to the code directly. The current upstream code flows down into:
...
xfs_attr_node_removename()
xfs_attr_node_remove_rmt()
xfs_attr_rmtval_remove()... which then implements the following loop:
do { retval = __xfs_attr_rmtval_remove(args); if (retval && retval != -EAGAIN) return retval; /* * Close out trans and start the next one in the chain. */ error = xfs_trans_roll_inode(&args->trans, args->dp); if (error) return error; } while (retval == -EAGAIN);This rolls the transaction when retval ==
-EAGAINor retval == 0, thus always returns with a clean transaction after the remote block removal completes.The code as of this patch does:
...
xfs_attr_node_removename_iter()
xfs_attr_node_remove_step()
xfs_attr_node_remove_rmt()__xfs_attr_rmtval_remove()... which either returns
-EAGAIN(since the roll is now implemented at the very top) or 0 when done == true. The transaction might be dirty in the latter case, butxfs_attr_node_removename_iter()moves right on toxfs_attr_node_remove_cleanup()which can now do more work in that same transaction. Am I following that correctly?Quoted 29 lines
Also, it would be
Quoted 4 lines
nice to remove the several seemingly unnecessary layers of indirection here. For example, something like the following (also considering my comment above wrt to
xfs_attr_remove_iter()and UNINIT):Quoted 16 lines
case UNINIT: ... /* fallthrough */ case RMTBLK: if (args->rmtblkno > 0) { dac->dela_state = RMTBLK; error = __xfs_attr_rmtval_remove(dac); if (error) break; ASSERT(args->rmtblkno == 0); xfs_attr_refillstate(state); dac->flags |= XFS_DAC_DEFER_FINISH; dac->dela_state = RMNAME; return -EAGAIN; }Ok, this looks to me like we've hoisted both
xfs_attr_node_remove_rmtandxfs_attr_node_remove_stepinto this scope, but I still think this adds an extra roll where non previously was. With out that extra EAGAIN, I think we are fine to have all that just under the UNINIT case. I also think it's also worth noteing here that this is kind of a reverse of patch 1, which I think we put in for reasons of trying to modularize the higher level functions as much as possible.Quoted 7 lines
Quoted 4 lines
I suspect some of where you were going with this may have been influenced by the earlier diff confusion too. Maybe take a second look there before we go too much down this change....
I can certainly be getting lost somewhere in all the refactoring. If so, can you point out where in the flow described above?
Quoted 9 lines
Ok, I think see it. So basically I think this means we cant have the helpers because it's ambiguos as to if the transaction is dirty or not. I dont see that there's anything in the review history where we rationalized that away, so I think we just overlooked it. So I think what this means is that we need to reverse apply commit
72b97ea40d(which is where we addedxfs_attr_node_remove_rmt), then drop patch 1 which leaves no need for patch 3, since the transaction will have not moved. Then add state RMTBLK? I think that arrives at what you have here.
It's not clear to me if anything needs to change before this patch or the changes can just fold into this patch itself. You probably have a better sense of that than I do atm. From my perspective, I think we want that transaction to roll after the final remote extent removal unless we had some reason to explicitly change existing behavior. This used to be handled by the old loop that rolled the transaction down in the remote block removal code. ISTM that the proper way to maintain the same behavior in the new state machine code is to unconditionally fall out of a RMTBLKREMOVE state with an -EAGAIN from _iter().
IOW, __xfs_attr_rmtval_remove() returns -EAGAIN when it has more work to do. _iter() returns -EAGAIN when __xfs_attr_rmtval_remove() was called, finished its work, but we need to roll the transaction before the next step of the operation..
Brian
Quoted 145 lines
Allison
Quoted 142 lines
Brian
Quoted 138 lines
Quoted 6 lines
/* fallthrough */ case RMNAME: ... ...Quoted 7 lines
Quoted 6 lines
fs/xfs/libxfs/xfs_attr.c +1
-5-/* -* 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); + retval =xfs_attr_node_remove_cleanup (args, state);...
I think the overlooked EAGAIN was in this area that got clipped out.....
Quoted 5 lines
Quoted 4 lines
fs/xfs/libxfs/xfs_attr_remote.c +0
-0...
Quoted 13 lines
fs/xfs/libxfs/xfs_attr_remote.c c( · line 692
Quoted 10 lines
fs/xfs/libxfs/xfs_attr_remote.c +3
-3@@ -685,31 +687,29 @@ c(* 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;Previously this would roll once and exit the loop on retval == 0. Now it looks like we break out of the loop immediately. Why the change?
Gosh, I think sometime in reviewing v9, we had come up with a "
xfs_attr_roll_again" helper that took the error code as a paramater and decided whether or not to roll. And then in v10 i think people thought that was weird and we turned it intoxfs_attr_trans_roll. I think I likley forgot to restore the orginal retval handling here. This whole function disappears in the next patch, but the original error handling should be restored to keep things consistent. Thx for the catch!Thx for the reviews!! I know it's complicated! I've chased my tail many times with it myself :-)
Allison
Quoted 86 lines
Brian
Quoted 82 lines
fs/xfs/libxfs/xfs_attr_remote.c +20
-14-/* -* Close out trans and start the next one in the chain. -*/ - error =xfs_trans_roll_inode (&args->trans, args->dp); + error =xfs_attr_trans_roll (&dac);if (error)return error; - }while (retval == -EAGAIN ); + }while (true); -return 0 ; +return error; }/* * Remove the value associated with an attribute by deleting the out-of-line -* buffer that it is stored on. Returns EAGAIN for the caller to refresh the +* buffer that it is stored on. Returns -EAGAIN for the caller to refresh the * transaction and re-call the function */ int __xfs_attr_rmtval_remove ( -struct xfs_da_args *args) +struct xfs_delattr_context *dac) { -int error, done; +struct xfs_da_args *args = dac->da_args; +int error, done;/* * Unmap value blocks for this attr. @@ -719,12 +719,20 @@ __xfs_attr_rmtval_remove(if (error)return error; - error =xfs_defer_finish (&args->trans); -if (error) -return error; - -if (!done) +/* +* We dont need an explicit state here to pick up where we left off. We +* can figure it out using the !done return code. Calling function only +* needs to keep recalling this routine until we indicate to stop by +* returning anything other than -EAGAIN. The actual value of +* attr->xattri_dela_state may be some value reminicent of the calling +* function, but it's value is irrelevant with in the context of this +* function. Once we are done here, the next state is set as needed +* by the parent +*/ +if (!done) { + dac->flags |=XFS_DAC_DEFER_FINISH ;return -EAGAIN ; + }return error; }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 v15 11/22] xfs: Add delay ready attr remove routines
Quoted 234 lines · Brian Foster
Quoted 223 lines · Allison Henderson
Quoted 213 lines · Brian Foster
Quoted 50 lines · Allison Henderson
Quoted 47 lines · Brian Foster
Quoted 46 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_argshas becomexfs_attr_remove_iter, which uses a sort of state machine like switch to keep track of where it was when EAGAIN was returned.xfs_attr_node_removenamehas also been modified to use the switch, and 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 | 223 +++++++++++++++++++++++++++++----------- fs/xfs/libxfs/xfs_attr.h | 100 ++++++++++++++++++ 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, 294 insertions(+), 83 deletions(-)fs/xfs/libxfs/xfs_attr.c +0
-0...
Quoted 69 lines
Quoted 61 lines
Quoted 61 lines
fs/xfs/libxfs/xfs_attr.c +21
-27@@ -1285,51 +1365,74 @@ xfs_attr_node_remove_step(* * This routine will find the blocks of the name to remove, remove them and * shrink the tree if needed. +* +* This routine is meant to function as either an inline or delayed operation, +* and may return -EAGAIN when the transaction needs to be rolled. Calling +* functions will need to handle this, and recall the function until a +* successful error code is returned. */ STATIC int -xfs_attr_node_removename ( -struct xfs_da_args *args) +xfs_attr_node_removename_iter ( +struct xfs_delattr_context *dac) { -struct xfs_da_state *state =NULL ; -int retval, error; -struct xfs_inode *dp = args->dp; +struct xfs_da_args *args = dac->da_args; +struct xfs_da_state *state =NULL ; +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; - - error =xfs_attr_node_remove_step (args, state); -if (error) - goto out; - - 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 (!dac->da_state) { + error =xfs_attr_node_removename_setup (dac);if (error) goto out; + } + state = dac->da_state; + +switch (dac->dela_state) { +case XFS_DAS_UNINIT :/* -* Commit the Btree join operation and start a new trans. +* repeatedly remove remote blocks, remove the entry and join. +* returns -EAGAIN or 0 for completion of the step. */ - error =xfs_trans_roll_inode (&args->trans, dp); + error =xfs_attr_node_remove_step (dac);if (error) - goto out; - }Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_remove_step( · line 1398
Quoted 1 line
fs/xfs/libxfs/xfs_attr.c +1
-0+break ;Hmm.. so re: my comment further down on
xfs_attr_rmtval_remove(), wouldn't that change semantics here? I.e., once remote blocks are removed this would previously carry on with a clean transaction. Now it looks like we'd carry on with the dirty transaction that removed the last remote extent. This suggests that perhaps we should return once more and fall into a new state to remove the name..?Quoted 6 lines
I suspect the diff might be making this a bit difficult to see. The roll that you see being removed here belongs to the transaction we hoisted up in patch 3 which happens after the clean up below, and we have the corresponding EAGAIN fot that one. I think the diff gets things a little interlaced here because the switch adds another level of indentation.
Hmm.. the roll in patch 3 appears to be related to the
_cleanup()helper. What I'm referring to here is the state of the transaction after the final remote block is removed from the attr. I'm not sure we're talking about the same thing here..Quoted 9 lines
some times i do like to I use a graphical diffviewer like diffuse when patches get weird like this. Something like this:
git config --global diff.tool diffuse
git difftool 3c53e49 e201c09You'd need to download the branch and also the diffuse tool, but sometimes i think it makes some of these diffs a bit easier to see
I think it's easier just to refer to the code directly. The current upstream code flows down into:
...
xfs_attr_node_removename()
xfs_attr_node_remove_rmt()
xfs_attr_rmtval_remove()... which then implements the following loop:
do { retval = __xfs_attr_rmtval_remove(args); if (retval && retval != -EAGAIN) return retval; /* * Close out trans and start the next one in the chain. */ error = xfs_trans_roll_inode(&args->trans, args->dp); if (error) return error; } while (retval == -EAGAIN);This rolls the transaction when retval ==
-EAGAINor retval == 0, thus always returns with a clean transaction after the remote block removal completes.The code as of this patch does:
...
xfs_attr_node_removename_iter()
xfs_attr_node_remove_step()xfs_attr_node_remove_rmt() __xfs_attr_rmtval_remove()... which either returns
-EAGAIN(since the roll is now implemented at the very top) or 0 when done == true. The transaction might be dirty in the latter case, butxfs_attr_node_removename_iter()moves right on toxfs_attr_node_remove_cleanup()which can now do more work in that same transaction. Am I following that correctly?Quoted 29 lines
Also, it would be
Quoted 4 lines
nice to remove the several seemingly unnecessary layers of indirection here. For example, something like the following (also considering my comment above wrt to
xfs_attr_remove_iter()and UNINIT):Quoted 16 lines
case UNINIT: ... /* fallthrough */ case RMTBLK: if (args->rmtblkno > 0) { dac->dela_state = RMTBLK; error = __xfs_attr_rmtval_remove(dac); if (error) break; ASSERT(args->rmtblkno == 0); xfs_attr_refillstate(state); dac->flags |= XFS_DAC_DEFER_FINISH; dac->dela_state = RMNAME; return -EAGAIN; }Ok, this looks to me like we've hoisted both
xfs_attr_node_remove_rmtandxfs_attr_node_remove_stepinto this scope, but I still think this adds an extra roll where non previously was. With out that extra EAGAIN, I think we are fine to have all that just under the UNINIT case. I also think it's also worth noteing here that this is kind of a reverse of patch 1, which I think we put in for reasons of trying to modularize the higher level functions as much as possible.Quoted 7 lines
Quoted 4 lines
I suspect some of where you were going with this may have been influenced by the earlier diff confusion too. Maybe take a second look there before we go too much down this change....
I can certainly be getting lost somewhere in all the refactoring. If so, can you point out where in the flow described above?
Quoted 9 lines
Ok, I think see it. So basically I think this means we cant have the helpers because it's ambiguos as to if the transaction is dirty or not. I dont see that there's anything in the review history where we rationalized that away, so I think we just overlooked it. So I think what this means is that we need to reverse apply commit
72b97ea40d(which is where we addedxfs_attr_node_remove_rmt), then drop patch 1 which leaves no need for patch 3, since the transaction will have not moved. Then add state RMTBLK? I think that arrives at what you have here.
Quoted 3 lines
It's not clear to me if anything needs to change before this patch or the changes can just fold into this patch itself. You probably have a better sense of that than I do atm.
I can unfold it here in this patch too if people prefer. I'm getting the impression that others are having a hard time keeping up with the refactoring, so maybe that might be better.
From my perspective, I think we want
Quoted 6 lines
that transaction to roll after the final remote extent removal unless we had some reason to explicitly change existing behavior. This used to be handled by the old loop that rolled the transaction down in the remote block removal code. ISTM that the proper way to maintain the same behavior in the new state machine code is to unconditionally fall out of a RMTBLKREMOVE state with an
-EAGAINfrom_iter().
Sure, I think that describes what you have up there
Quoted 5 lines
IOW,
__xfs_attr_rmtval_remove()returns-EAGAINwhen it has more work to do._iter()returns-EAGAINwhen__xfs_attr_rmtval_remove()was called, finished its work, but we need to roll the transaction before the next step of the operation..
Right, ok, will make those modifcations here then. Thanks for the reviews! I know it's a lot.
Allison
Quoted 149 lines
Brian
Quoted 145 lines
Allison
Quoted 142 lines
Brian
Quoted 138 lines
Quoted 6 lines
/* fallthrough */ case RMNAME: ... ...Quoted 7 lines
Quoted 6 lines
fs/xfs/libxfs/xfs_attr.c +1
-5-/* -* 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); + retval =xfs_attr_node_remove_cleanup (args, state);...
I think the overlooked EAGAIN was in this area that got clipped out.....
Quoted 5 lines
Quoted 4 lines
fs/xfs/libxfs/xfs_attr_remote.c +0
-0...
Quoted 13 lines
fs/xfs/libxfs/xfs_attr_remote.c c( · line 692
Quoted 10 lines
fs/xfs/libxfs/xfs_attr_remote.c +3
-3@@ -685,31 +687,29 @@ c(* 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;Previously this would roll once and exit the loop on retval == 0. Now it looks like we break out of the loop immediately. Why the change?
Gosh, I think sometime in reviewing v9, we had come up with a "
xfs_attr_roll_again" helper that took the error code as a paramater and decided whether or not to roll. And then in v10 i think people thought that was weird and we turned it intoxfs_attr_trans_roll. I think I likley forgot to restore the orginal retval handling here. This whole function disappears in the next patch, but the original error handling should be restored to keep things consistent. Thx for the catch!Thx for the reviews!! I know it's complicated! I've chased my tail many times with it myself :-)
Allison
Quoted 86 lines
Brian
Quoted 82 lines
fs/xfs/libxfs/xfs_attr_remote.c +20
-14-/* -* Close out trans and start the next one in the chain. -*/ - error =xfs_trans_roll_inode (&args->trans, args->dp); + error =xfs_attr_trans_roll (&dac);if (error)return error; - }while (retval == -EAGAIN ); + }while (true); -return 0 ; +return error; }/* * Remove the value associated with an attribute by deleting the out-of-line -* buffer that it is stored on. Returns EAGAIN for the caller to refresh the +* buffer that it is stored on. Returns -EAGAIN for the caller to refresh the * transaction and re-call the function */ int __xfs_attr_rmtval_remove ( -struct xfs_da_args *args) +struct xfs_delattr_context *dac) { -int error, done; +struct xfs_da_args *args = dac->da_args; +int error, done;/* * Unmap value blocks for this attr. @@ -719,12 +719,20 @@ __xfs_attr_rmtval_remove(if (error)return error; - error =xfs_defer_finish (&args->trans); -if (error) -return error; - -if (!done) +/* +* We dont need an explicit state here to pick up where we left off. We +* can figure it out using the !done return code. Calling function only +* needs to keep recalling this routine until we indicate to stop by +* returning anything other than -EAGAIN. The actual value of +* attr->xattri_dela_state may be some value reminicent of the calling +* function, but it's value is irrelevant with in the context of this +* function. Once we are done here, the next state is set as needed +* by the parent +*/ +if (!done) { + dac->flags |=XFS_DAC_DEFER_FINISH ;return -EAGAIN ; + }return error; }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
PATCH v15 12/22 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 | 448 ++++++++++++++++++++++++---------------- fs/xfs/libxfs/xfs_attr.h | 241 ++++++++++++++++++++- fs/xfs/libxfs/xfs_attr_remote.c | 98 ++++++--- fs/xfs/libxfs/xfs_attr_remote.h | 5 +- fs/xfs/xfs_trace.h | 1 - 5 files changed, 583 insertions(+), 210 deletions(-)
fs/xfs/libxfs/xfs_attr.c +274 -174
@@ -53,16 +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_work(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_work(struct xfs_delattr_context *dac); STATIC int xfs_attr_node_removename_iter(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(
@@ -226,7 +226,7 @@ xfs_attr_is_shortform(* also checks for a defer finish. Transaction is finished and rolled as * needed, and returns true of false if the delayed operation should continue. */ -int +STATIC intxfs_attr_trans_roll (struct xfs_delattr_context *dac) {
@@ -249,29 +249,55 @@ 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) +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;
@@ -280,93 +306,140 @@ 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); +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 ; -int retval =0 ; +struct xfs_da_args *args = dac->da_args; +struct xfs_inode *dp = args->dp; +struct xfs_buf *bp =NULL ; +struct xfs_da_state *state =NULL ; +int forkoff, error =0 ; +int retval =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); +/* +* 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; + } +else { + error =xfs_attr_node_addname_find_attr (dac);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); + error =xfs_attr_node_addname (dac);if (error)return error;/* -* Commit the current trans (including the inode) and -* start a new one. +* If addname was sucesfull, and we dont need to alloc +* anymore blks, we're done. */ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) +if (!args->rmtblkno && !args->rmtblkno2)return error; - goto node; + dac->dela_state =XFS_DAS_FOUND_NBLK ; +return -EAGAIN ; } -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; + dac->dela_state =XFS_DAS_FOUND_LBLK ; +return -EAGAIN ; +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
@@ -395,22 +468,26 @@ 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); -if (args->rmtblkno) { - error =xfs_attr_rmtval_invalidate (args); -if (error) -return error; + error =xfs_attr_rmtval_invalidate (args); +if (error) +return error; - error =xfs_attr_rmtval_remove (args); +/* 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_remove (dac);if (error)return error; }
@@ -435,94 +512,117 @@ 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); + retval = error; + 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); - 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; + 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); +/* 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_work (dac); + +out: +if (state) +xfs_da_state_free (state);if (error)return error; - } +return retval; - error =xfs_attr_node_addname_work (args); -out: -if (state) -xfs_da_state_free (state); -if (error) -return error; -return retval; +default : +ASSERT (dac->dela_state !=XFS_DAS_RM_SHRINK ); +break ; + } +return error; } +/* * Return EEXIST if attr is found, or ENOATTR if not */
@@ -1021,18 +1121,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 out; +return retval;if (retval == -ENOATTR && (args->attr_flags &XATTR_REPLACE )) goto out;
@@ -1058,8 +1158,8 @@ xfs_attr_node_addname_find_attr(return 0 ; out: -if (*state) -xfs_da_state_free (*state); +if (dac->da_state) +xfs_da_state_free (dac->da_state);return retval; }
@@ -1072,20 +1172,24 @@ 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 ]; + blk = &state->path.blk[ state->path.active-1 ];ASSERT (blk->magic ==XFS_ATTR_LEAF_MAGIC ); error =xfs_attr3_leaf_add (blk->bp, state->args);
@@ -1101,18 +1205,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 ; }
@@ -1125,9 +1226,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.
@@ -1144,8 +1243,9 @@ xfs_attr_node_addname(STATIC int xfs_attr_node_addname_work( -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 +240 -1
271 lines not on this page · raw message
fs/xfs/libxfs/xfs_attr_remote.c +65 -33
122 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
@@ -1942,7 +1942,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 v15 12/22] 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 2 lines
Signed-off-by Allison Henderson <[email protected]>Reviewed-by Chandan Babu R <[email protected]>
I /think/ this looks reasonable.
By the way, would you mind going through the comments in these patches looking for typos? I noticed a few ("sucesfull") lurking here and there.
--D
Quoted 1,082 lines
--- fs/xfs/libxfs/xfs_attr.c | 448 ++++++++++++++++++++++++---------------- fs/xfs/libxfs/xfs_attr.h | 241 ++++++++++++++++++++- fs/xfs/libxfs/xfs_attr_remote.c | 98 ++++++--- fs/xfs/libxfs/xfs_attr_remote.h | 5 +- fs/xfs/xfs_trace.h | 1 - 5 files changed, 583 insertions(+), 210 deletions(-)fs/xfs/libxfs/xfs_attr.c +274
-174@@ -53,16 +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_work(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_work(struct xfs_delattr_context *dac); STATIC int xfs_attr_node_removename_iter(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(@@ -226,7 +226,7 @@ xfs_attr_is_shortform(* also checks for a defer finish. Transaction is finished and rolled as * needed, and returns true of false if the delayed operation should continue. */ -int +STATIC intxfs_attr_trans_roll (struct xfs_delattr_context *dac) {@@ -249,29 +249,55 @@ 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) +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;@@ -280,93 +306,140 @@ 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); +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 ; -int retval =0 ; +struct xfs_da_args *args = dac->da_args; +struct xfs_inode *dp = args->dp; +struct xfs_buf *bp =NULL ; +struct xfs_da_state *state =NULL ; +int forkoff, error =0 ; +int retval =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); +/* +* 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; + } +else { + error =xfs_attr_node_addname_find_attr (dac);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); + error =xfs_attr_node_addname (dac);if (error)return error;/* -* Commit the current trans (including the inode) and -* start a new one. +* If addname was sucesfull, and we dont need to alloc +* anymore blks, we're done. */ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) +if (!args->rmtblkno && !args->rmtblkno2)return error; - goto node; + dac->dela_state =XFS_DAS_FOUND_NBLK ; +return -EAGAIN ; } -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; + dac->dela_state =XFS_DAS_FOUND_LBLK ; +return -EAGAIN ; +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 @@ -395,22 +468,26 @@ 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); -if (args->rmtblkno) { - error =xfs_attr_rmtval_invalidate (args); -if (error) -return error; + error =xfs_attr_rmtval_invalidate (args); +if (error) +return error; - error =xfs_attr_rmtval_remove (args); +/* 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_remove (dac);if (error)return error; }@@ -435,94 +512,117 @@ 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); + retval = error; + 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); - 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; + 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); +/* 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_work (dac); + +out: +if (state) +xfs_da_state_free (state);if (error)return error; - } +return retval; - error =xfs_attr_node_addname_work (args); -out: -if (state) -xfs_da_state_free (state); -if (error) -return error; -return retval; +default : +ASSERT (dac->dela_state !=XFS_DAS_RM_SHRINK ); +break ; + } +return error; } +/* * Return EEXIST if attr is found, or ENOATTR if not */ @@ -1021,18 +1121,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 out; +return retval;if (retval == -ENOATTR && (args->attr_flags &XATTR_REPLACE )) goto out;@@ -1058,8 +1158,8 @@ xfs_attr_node_addname_find_attr(return 0 ; out: -if (*state) -xfs_da_state_free (*state); +if (dac->da_state) +xfs_da_state_free (dac->da_state);return retval; }@@ -1072,20 +1172,24 @@ 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 ]; + blk = &state->path.blk[ state->path.active-1 ];ASSERT (blk->magic ==XFS_ATTR_LEAF_MAGIC ); error =xfs_attr3_leaf_add (blk->bp, state->args);@@ -1101,18 +1205,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 ; }@@ -1125,9 +1226,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. @@ -1144,8 +1243,9 @@ xfs_attr_node_addname(STATIC int xfs_attr_node_addname_work( -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 +240
-1@@ -135,6 +135,233 @@ struct xfs_attr_list_context {* v * done * +* +* Below is a state machine diagram for attr set operations. +* +* It seems the challenge with undertanding this system comes from trying to +* absorb the state machine all at once, when really one should only be looking +* at it with in the context of a single function. Once a state sensitive +* function is called, the idea is that it "takes ownership" of the +* statemachine. It isn't concerned with the states that may have belonged to +* it's calling parent. Only the states relevant to itself or any other +* subroutines there in. Once a calling function hands off the statemachine to +* a subroutine, it needs to respect the simple rule that it doesn't "own" the +* statemachine anymore, and it's the responsibility of that calling function to +* propagate the -EAGAIN back up the call stack. Upon reentry, it is committed +* to re-calling that subroutine until it returns something other than -EAGAIN. +* Once that subroutine signals completion (by returning anything other than +* -EAGAIN), the calling function can resume using the statemachine. +* +* xfs_attr_set_iter() +* │ +* v +* ┌─y─ has an attr fork? +* │ | +* │ n +* │ | +* │ V +* │ add a fork +* │ │ +* └──────────┤ +* │ +* V +* ┌─y─ is shortform? +* │ │ +* │ V +* │ xfs_attr_set_fmt +* │ | +* │ V +* │ xfs_attr_try_sf_addname +* │ │ +* │ V +* │ had enough ──y──> done +* │ space? +* n │ +* │ n +* │ │ +* │ V +* │ transform to leaf +* │ │ +* │ V +* │ hold the leaf buffer +* │ │ +* │ V +* │ return -EAGAIN +* │ Re-enter in +* │ leaf form +* │ +* └─> release leaf buffer +* if needed +* │ +* V +* ┌───n── fork has +* │ only 1 blk? +* │ │ +* │ y +* │ │ +* │ v +* │ xfs_attr_leaf_try_add() +* │ │ +* │ v +* │ had enough ──────────────y───────────────┐ +* │ space? │ +* │ │ │ +* │ n │ +* │ │ │ +* │ v │ +* │ return -EAGAIN │ +* │ re-enter in │ +* │ node form │ +* │ │ │ +* └──────────┤ │ +* │ │ +* V │ +* xfs_attr_node_addname_find_attr │ +* determines if this │ +* is create or rename │ +* find space to store attr │ +* │ │ +* v │ +* xfs_attr_node_addname │ +* │ │ +* v │ +* fits in a node leaf? ────n─────┐ │ +* │ ^ v │ +* │ │ single leaf node? │ +* │ │ │ │ │ +* y │ y n │ +* │ │ │ │ │ +* v │ v v │ +* update │ grow the leaf split if │ +* hashvals └─── return -EAGAIN needed │ +* │ retry leaf add │ │ +* │ on reentry │ │ +* ├─────────────────────────────┘ │ +* │ │ +* v │ +* need to alloc │ +* ┌─y── or flip flag? │ +* │ │ │ +* │ n │ +* │ │ │ +* │ v │ +* │ done │ +* │ │ +* │ │ +* │ XFS_DAS_FOUND_LBLK <──────────────────┘ +* │ │ +* │ V +* │ xfs_attr_leaf_addname() +* │ │ +* │ v +* │ ┌──first time through? +* │ │ │ +* │ │ y +* │ │ │ +* │ n v +* │ │ if we have rmt blks +* │ │ find space for them +* │ │ │ +* │ └──────────┤ +* │ │ +* │ v +* │ still have +* │ ┌─n─ blks to alloc? <──┐ +* │ │ │ │ +* │ │ y │ +* │ │ │ │ +* │ │ v │ +* │ │ alloc one blk │ +* │ │ return -EAGAIN ──┘ +* │ │ re-enter with one +* │ │ less blk to alloc +* │ │ +* │ │ +* │ └───> set the rmt +* │ value +* │ │ +* │ v +* │ was this +* │ a rename? ──n─┐ +* │ │ │ +* │ y │ +* │ │ │ +* │ v │ +* │ flip incomplete │ +* │ flag │ +* │ │ │ +* │ v │ +* │ XFS_DAS_FLIP_LFLAG │ +* │ │ │ +* │ v │ +* │ remove │ +* │ ┌───> old name │ +* │ │ │ │ +* │ XFS_DAS_RM_LBLK │ │ +* │ ^ │ │ +* │ │ v │ +* │ └──y── more to │ +* │ remove │ +* │ │ │ +* │ n │ +* │ │ │ +* │ v │ +* │ done <──────┘ +* │ +* └──────> XFS_DAS_FOUND_NBLK +* │ +* v +* ┌─────n── need to +* │ alloc blks? +* │ │ +* │ y +* │ │ +* │ v +* │ find space +* │ │ +* │ v +* │ ┌─>XFS_DAS_ALLOC_NODE +* │ │ │ +* │ │ v +* │ │ alloc blk +* │ │ │ +* │ │ v +* │ └──y── need to alloc +* │ more blocks? +* │ │ +* │ n +* │ │ +* │ v +* │ set the rmt value +* │ │ +* │ v +* │ was this +* └────────> a rename? ──n─┐ +* │ │ +* y │ +* │ │ +* v │ +* flip incomplete │ +* flag │ +* │ │ +* v │ +* XFS_DAS_FLIP_NFLAG │ +* │ │ +* v │ +* remove │ +* ┌────────> old name │ +* │ │ │ +* XFS_DAS_RM_NBLK │ │ +* ^ │ │ +* │ v │ +* └──────y── more to │ +* remove │ +* │ │ +* n │ +* │ │ +* v │ +* done <──────┘ +* */ /* @@ -149,12 +376,20 @@ struct xfs_attr_list_context {enum xfs_delattr_state {XFS_DAS_UNINIT =0 ,/* No state has been set yet */ XFS_DAS_RM_SHRINK ,/* We are shrinking the tree */ +XFS_DAS_FOUND_LBLK ,/* We found leaf blk for attr */ +XFS_DAS_FOUND_NBLK ,/* We found node blk for attr */ +XFS_DAS_FLIP_LFLAG ,/* Flipped leaf INCOMPLETE attr flag */ +XFS_DAS_RM_LBLK ,/* A rename is removing leaf blocks */ +XFS_DAS_ALLOC_NODE ,/* We are allocating node blocks */ +XFS_DAS_FLIP_NFLAG ,/* Flipped node INCOMPLETE attr flag */ +XFS_DAS_RM_NBLK ,/* A rename is removing node blocks */ };/* * Defines for xfs_delattr_context.flags */ #define XFS_DAC_DEFER_FINISH 0x01/* finish the transaction */ +#define XFS_DAC_LEAF_ADDNAME_INIT 0x02/* xfs_attr_leaf_addname init*/ /* * Context used for keeping track of delayed attribute operations @@ -162,6 +397,11 @@ enum xfs_delattr_state {struct xfs_delattr_context {struct xfs_da_args *da_args; +/* Used in xfs_attr_rmtval_set_blk to roll through allocating blocks */ +struct xfs_bmbt_irec map; +xfs_dablk_t lblkno; +int blkcnt; +/* Used in xfs_attr_node_removename to roll through removing blocks */ struct xfs_da_state *da_state;@@ -188,7 +428,6 @@ int xfs_attr_set_args(struct xfs_da_args *args);int xfs_has_attr (struct xfs_da_args *args);int xfs_attr_remove_args (struct xfs_da_args *args);int xfs_attr_remove_iter (struct xfs_delattr_context *dac); -int xfs_attr_trans_roll (struct xfs_delattr_context *dac);bool xfs_attr_namecheck (const void *name,size_t length);void xfs_delattr_context_init (struct xfs_delattr_context *dac,struct xfs_da_args *args);fs/xfs/libxfs/xfs_attr_remote.c +65
-33@@ -441,7 +441,7 @@ xfs_attr_rmtval_get(* Find a "hole" in the attribute address space large enough for us to drop the * new attribute's value into */ -STATIC int +int xfs_attr_rmt_find_hole (struct xfs_da_args *args) {@@ -468,7 +468,7 @@ xfs_attr_rmt_find_hole(return 0 ; } -STATIC int +int xfs_attr_rmtval_set_value (struct xfs_da_args *args) {@@ -628,6 +628,69 @@ xfs_attr_rmtval_set( }/* +* Find a hole for the attr and store it in the delayed attr context. This +* initializes the context to roll through allocating an attr extent for a +* delayed attr operation +*/ +int +xfs_attr_rmtval_find_space ( +struct xfs_delattr_context *dac) +{ +struct xfs_da_args *args = dac->da_args; +struct xfs_bmbt_irec *map = &dac->map; +int error; + + dac->lblkno =0 ; + dac->blkcnt =0 ; + args->rmtblkcnt =0 ; + args->rmtblkno =0 ; +memset (map,0 ,sizeof (struct xfs_bmbt_irec )); + + error =xfs_attr_rmt_find_hole (args); +if (error) +return error; + + dac->blkcnt = args->rmtblkcnt; + dac->lblkno = args->rmtblkno; + +return 0 ; +} + +/* +* Write one block of the value associated with an attribute into the +* out-of-line buffer that we have defined for it. This is similar to a subset +* of xfs_attr_rmtval_set, but records the current block to the delayed attr +* context, and leaves transaction handling to the caller. +*/ +int +xfs_attr_rmtval_set_blk ( +struct xfs_delattr_context *dac) +{ +struct xfs_da_args *args = dac->da_args; +struct xfs_inode *dp = args->dp; +struct xfs_bmbt_irec *map = &dac->map; +int nmap; +int error; + + nmap =1 ; + error =xfs_bmapi_write (args->trans, dp, (xfs_fileoff_t )dac->lblkno, + dac->blkcnt,XFS_BMAPI_ATTRFORK , args->total, + map, &nmap); +if (error) +return error; + +ASSERT (nmap ==1 ); +ASSERT ((map->br_startblock !=DELAYSTARTBLOCK ) && + (map->br_startblock !=HOLESTARTBLOCK )); + +/* roll attribute extent map forwards */ + dac->lblkno += map->br_blockcount; + dac->blkcnt -= map->br_blockcount; + +return 0 ; +} + +/* * Remove the value associated with an attribute by deleting the * out-of-line buffer that it is stored on. */ @@ -669,37 +732,6 @@ xfs_attr_rmtval_invalidate( }/* -* Remove the value associated with an attribute by deleting the -* out-of-line buffer that it is stored on. -*/ -int -xfs_attr_rmtval_remove ( -struct xfs_da_args *args) -{ -int error; -struct xfs_delattr_context dac = { - .da_args = args, - }; - -trace_xfs_attr_rmtval_remove (args); - -/* -* Keep de-allocating extents until the remote-value region is gone. -*/ -do { - error =__xfs_attr_rmtval_remove (&dac); -if (error != -EAGAIN ) -break ; - - error =xfs_attr_trans_roll (&dac); -if (error) -return error; - }while (true); - -return error; -} - -/* * Remove the value associated with an attribute by deleting the out-of-line * buffer that it is stored on. Returns -EAGAIN for the caller to refresh the * transaction and re-call the function 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@@ -1942,7 +1942,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
PATCH v15 13/22 xfs: Add state machine tracepoints
In reply to Allison HendersonThis is a quick patch to add a new tracepoint: xfs_das_state_return. We use this to track when ever a new state is set or -EAGAIN is returned
--- fs/xfs/libxfs/xfs_attr.c | 31 ++++++++++++++++++++++++++++++- fs/xfs/libxfs/xfs_attr_remote.c | 1 + fs/xfs/xfs_trace.h | 25 +++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 1 deletion(-)
fs/xfs/libxfs/xfs_attr.c +30 -1
@@ -313,6 +313,7 @@ xfs_attr_set_fmt(* the attr fork to leaf format and will restart with the leaf * add. */ +trace_xfs_attr_set_fmt_return (XFS_DAS_UNINIT , args->dp); dac->flags |=XFS_DAC_DEFER_FINISH ;return -EAGAIN ; }
@@ -378,6 +379,8 @@ xfs_attr_set_iter(* handling code below */ dac->flags |=XFS_DAC_DEFER_FINISH ; +trace_xfs_attr_set_iter_return ( + dac->dela_state, args->dp);return -EAGAIN ; }else if (error)
@@ -400,10 +403,13 @@ xfs_attr_set_iter(return error; dac->dela_state =XFS_DAS_FOUND_NBLK ; +trace_xfs_attr_set_iter_return (dac->dela_state, + args->dp);return -EAGAIN ; } dac->dela_state =XFS_DAS_FOUND_LBLK ; +trace_xfs_attr_set_iter_return (dac->dela_state, args->dp);return -EAGAIN ;case XFS_DAS_FOUND_LBLK :
@@ -433,6 +439,8 @@ xfs_attr_set_iter(if (error)return error; +trace_xfs_attr_set_iter_return (dac->dela_state, + args->dp);return -EAGAIN ; }
@@ -469,6 +477,7 @@ xfs_attr_set_iter(* series. */ dac->dela_state =XFS_DAS_FLIP_LFLAG ; +trace_xfs_attr_set_iter_return (dac->dela_state, args->dp);return -EAGAIN ;case XFS_DAS_FLIP_LFLAG :/*
@@ -488,6 +497,9 @@ xfs_attr_set_iter(case XFS_DAS_RM_LBLK :if (args->rmtblkno) { error =__xfs_attr_rmtval_remove (dac); +if (error == -EAGAIN ) +trace_xfs_attr_set_iter_return ( + dac->dela_state, args->dp);if (error)return error; }
@@ -545,6 +557,8 @@ xfs_attr_set_iter(if (error)return error; +trace_xfs_attr_set_iter_return ( + dac->dela_state, args->dp);return -EAGAIN ; }
@@ -581,6 +595,7 @@ xfs_attr_set_iter(* series */ dac->dela_state =XFS_DAS_FLIP_NFLAG ; +trace_xfs_attr_set_iter_return (dac->dela_state, args->dp);return -EAGAIN ;case XFS_DAS_FLIP_NFLAG :
@@ -601,6 +616,10 @@ xfs_attr_set_iter(case XFS_DAS_RM_NBLK :if (args->rmtblkno) { error =__xfs_attr_rmtval_remove (dac); +if (error == -EAGAIN ) +trace_xfs_attr_set_iter_return ( + dac->dela_state, args->dp); +if (error)return error; }
@@ -1214,6 +1233,8 @@ xfs_attr_node_addname(* this point. */ dac->flags |=XFS_DAC_DEFER_FINISH ; +trace_xfs_attr_node_addname_return ( + dac->dela_state, args->dp);return -EAGAIN ; }
@@ -1394,6 +1415,9 @@ xfs_attr_node_remove_rmt (* May return -EAGAIN to request that the caller recall this function */ error =__xfs_attr_rmtval_remove (dac); +if (error == -EAGAIN ) +trace_xfs_attr_node_remove_rmt_return (dac->dela_state, + dac->da_args->dp);if (error)return error;
@@ -1513,6 +1537,8 @@ xfs_attr_node_removename_iter( dac->flags |=XFS_DAC_DEFER_FINISH ; dac->dela_state =XFS_DAS_RM_SHRINK ; +trace_xfs_attr_node_removename_iter_return ( + dac->dela_state, args->dp);return -EAGAIN ; }
@@ -1531,8 +1557,11 @@ xfs_attr_node_removename_iter( goto out; } -if (error == -EAGAIN ) +if (error == -EAGAIN ) { +trace_xfs_attr_node_removename_iter_return ( + dac->dela_state, args->dp);return error; + } out:if (state)xfs_da_state_free (state);
fs/xfs/libxfs/xfs_attr_remote.c +1 -0
@@ -763,6 +763,7 @@ __xfs_attr_rmtval_remove(*/ if (!done) { dac->flags |=XFS_DAC_DEFER_FINISH ; +trace_xfs_attr_rmtval_remove_return (dac->dela_state, args->dp);return -EAGAIN ; }
fs/xfs/xfs_trace.h +25 -0
@@ -3927,6 +3927,31 @@ DEFINE_EVENT(xfs_eofblocks_class, name, \DEFINE_EOFBLOCKS_EVENT (xfs_ioc_free_eofblocks);DEFINE_EOFBLOCKS_EVENT (xfs_blockgc_free_space); +DECLARE_EVENT_CLASS (xfs_das_state_class, + TP_PROTO(int das, struct xfs_inode *ip), +TP_ARGS (das, ip), +TP_STRUCT__entry ( + __field(int, das) +__field (xfs_ino_t, ino) + ), +TP_fast_assign ( + __entry->das = das; + __entry->ino = ip->i_ino; + ), +TP_printk ("state change %d ino 0x%llx" , + __entry->das, __entry->ino) +) + +#define DEFINE_DAS_STATE_EVENT (name) \ +DEFINE_EVENT(xfs_das_state_class, name, \ + TP_PROTO(int das, struct xfs_inode *ip), \ + TP_ARGS(das, ip)) +DEFINE_DAS_STATE_EVENT (xfs_attr_set_fmt_return); +DEFINE_DAS_STATE_EVENT (xfs_attr_set_iter_return); +DEFINE_DAS_STATE_EVENT (xfs_attr_node_addname_return); +DEFINE_DAS_STATE_EVENT (xfs_attr_node_removename_iter_return); +DEFINE_DAS_STATE_EVENT (xfs_attr_node_remove_rmt_return); +DEFINE_DAS_STATE_EVENT (xfs_attr_rmtval_remove_return);#endif /* _TRACE_XFS_H */ #undef TRACE_INCLUDE_PATH
Signature · 1 line
2.7.4
Re: [PATCH v15 13/22] xfs: Add state machine tracepoints
Quoted 4 lines · Allison Henderson
This is a quick patch to add a new tracepoint:
xfs_das_state_return. We use this to track when ever a new state is set or-EAGAINis returnedSigned-off-by Allison Henderson <[email protected]>
Looks good!
--D
Quoted 188 lines
--- fs/xfs/libxfs/xfs_attr.c | 31 ++++++++++++++++++++++++++++++- fs/xfs/libxfs/xfs_attr_remote.c | 1 + fs/xfs/xfs_trace.h | 25 +++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 1 deletion(-)fs/xfs/libxfs/xfs_attr.c +30
-1@@ -313,6 +313,7 @@ xfs_attr_set_fmt(* the attr fork to leaf format and will restart with the leaf * add. */ +trace_xfs_attr_set_fmt_return (XFS_DAS_UNINIT , args->dp); dac->flags |=XFS_DAC_DEFER_FINISH ;return -EAGAIN ; }@@ -378,6 +379,8 @@ xfs_attr_set_iter(* handling code below */ dac->flags |=XFS_DAC_DEFER_FINISH ; +trace_xfs_attr_set_iter_return ( + dac->dela_state, args->dp);return -EAGAIN ; }else if (error)@@ -400,10 +403,13 @@ xfs_attr_set_iter(return error; dac->dela_state =XFS_DAS_FOUND_NBLK ; +trace_xfs_attr_set_iter_return (dac->dela_state, + args->dp);return -EAGAIN ; } dac->dela_state =XFS_DAS_FOUND_LBLK ; +trace_xfs_attr_set_iter_return (dac->dela_state, args->dp);return -EAGAIN ;case XFS_DAS_FOUND_LBLK :@@ -433,6 +439,8 @@ xfs_attr_set_iter(if (error)return error; +trace_xfs_attr_set_iter_return (dac->dela_state, + args->dp);return -EAGAIN ; }@@ -469,6 +477,7 @@ xfs_attr_set_iter(* series. */ dac->dela_state =XFS_DAS_FLIP_LFLAG ; +trace_xfs_attr_set_iter_return (dac->dela_state, args->dp);return -EAGAIN ;case XFS_DAS_FLIP_LFLAG :/* @@ -488,6 +497,9 @@ xfs_attr_set_iter(case XFS_DAS_RM_LBLK :if (args->rmtblkno) { error =__xfs_attr_rmtval_remove (dac); +if (error == -EAGAIN ) +trace_xfs_attr_set_iter_return ( + dac->dela_state, args->dp);if (error)return error; }@@ -545,6 +557,8 @@ xfs_attr_set_iter(if (error)return error; +trace_xfs_attr_set_iter_return ( + dac->dela_state, args->dp);return -EAGAIN ; }@@ -581,6 +595,7 @@ xfs_attr_set_iter(* series */ dac->dela_state =XFS_DAS_FLIP_NFLAG ; +trace_xfs_attr_set_iter_return (dac->dela_state, args->dp);return -EAGAIN ;case XFS_DAS_FLIP_NFLAG :@@ -601,6 +616,10 @@ xfs_attr_set_iter(case XFS_DAS_RM_NBLK :if (args->rmtblkno) { error =__xfs_attr_rmtval_remove (dac); +if (error == -EAGAIN ) +trace_xfs_attr_set_iter_return ( + dac->dela_state, args->dp); +if (error)return error; }@@ -1214,6 +1233,8 @@ xfs_attr_node_addname(* this point. */ dac->flags |=XFS_DAC_DEFER_FINISH ; +trace_xfs_attr_node_addname_return ( + dac->dela_state, args->dp);return -EAGAIN ; }@@ -1394,6 +1415,9 @@ xfs_attr_node_remove_rmt (* May return -EAGAIN to request that the caller recall this function */ error =__xfs_attr_rmtval_remove (dac); +if (error == -EAGAIN ) +trace_xfs_attr_node_remove_rmt_return (dac->dela_state, + dac->da_args->dp);if (error)return error;@@ -1513,6 +1537,8 @@ xfs_attr_node_removename_iter( dac->flags |=XFS_DAC_DEFER_FINISH ; dac->dela_state =XFS_DAS_RM_SHRINK ; +trace_xfs_attr_node_removename_iter_return ( + dac->dela_state, args->dp);return -EAGAIN ; }@@ -1531,8 +1557,11 @@ xfs_attr_node_removename_iter( goto out; } -if (error == -EAGAIN ) +if (error == -EAGAIN ) { +trace_xfs_attr_node_removename_iter_return ( + dac->dela_state, args->dp);return error; + } out:if (state)xfs_da_state_free (state);fs/xfs/libxfs/xfs_attr_remote.c +1
-0@@ -763,6 +763,7 @@ __xfs_attr_rmtval_remove(*/ if (!done) { dac->flags |=XFS_DAC_DEFER_FINISH ; +trace_xfs_attr_rmtval_remove_return (dac->dela_state, args->dp);return -EAGAIN ; }fs/xfs/xfs_trace.h +25
-0@@ -3927,6 +3927,31 @@ DEFINE_EVENT(xfs_eofblocks_class, name, \DEFINE_EOFBLOCKS_EVENT (xfs_ioc_free_eofblocks);DEFINE_EOFBLOCKS_EVENT (xfs_blockgc_free_space); +DECLARE_EVENT_CLASS (xfs_das_state_class, + TP_PROTO(int das, struct xfs_inode *ip), +TP_ARGS (das, ip), +TP_STRUCT__entry ( + __field(int, das) +__field (xfs_ino_t, ino) + ), +TP_fast_assign ( + __entry->das = das; + __entry->ino = ip->i_ino; + ), +TP_printk ("state change %d ino 0x%llx" , + __entry->das, __entry->ino) +) + +#define DEFINE_DAS_STATE_EVENT (name) \ +DEFINE_EVENT(xfs_das_state_class, name, \ + TP_PROTO(int das, struct xfs_inode *ip), \ + TP_ARGS(das, ip)) +DEFINE_DAS_STATE_EVENT (xfs_attr_set_fmt_return); +DEFINE_DAS_STATE_EVENT (xfs_attr_set_iter_return); +DEFINE_DAS_STATE_EVENT (xfs_attr_node_addname_return); +DEFINE_DAS_STATE_EVENT (xfs_attr_node_removename_iter_return); +DEFINE_DAS_STATE_EVENT (xfs_attr_node_remove_rmt_return); +DEFINE_DAS_STATE_EVENT (xfs_attr_rmtval_remove_return);#endif /* _TRACE_XFS_H */ #undef TRACE_INCLUDE_PATHSignature · 1 line
2.7.4
Re: [PATCH v15 13/22] xfs: Add state machine tracepoints
Quoted 8 lines · Darrick J. Wong
Quoted 4 lines · Allison Henderson
This is a quick patch to add a new tracepoint:
xfs_das_state_return. We use this to track when ever a new state is set or-EAGAINis returnedSigned-off-by Allison Henderson <[email protected]>Looks good!
Reviewed-by Darrick J. Wong <[email protected]>
Cool, thank you!
Allison
Quoted 191 lines
--D
Quoted 188 lines
--- fs/xfs/libxfs/xfs_attr.c | 31 ++++++++++++++++++++++++++++++- fs/xfs/libxfs/xfs_attr_remote.c | 1 + fs/xfs/xfs_trace.h | 25 +++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 1 deletion(-)fs/xfs/libxfs/xfs_attr.c +30
-1@@ -313,6 +313,7 @@ xfs_attr_set_fmt(* the attr fork to leaf format and will restart with the leaf * add. */ +trace_xfs_attr_set_fmt_return (XFS_DAS_UNINIT , args->dp); dac->flags |=XFS_DAC_DEFER_FINISH ;return -EAGAIN ; }@@ -378,6 +379,8 @@ xfs_attr_set_iter(* handling code below */ dac->flags |=XFS_DAC_DEFER_FINISH ; +trace_xfs_attr_set_iter_return ( + dac->dela_state, args->dp);return -EAGAIN ; }else if (error)@@ -400,10 +403,13 @@ xfs_attr_set_iter(return error; dac->dela_state =XFS_DAS_FOUND_NBLK ; +trace_xfs_attr_set_iter_return (dac->dela_state, + args->dp);return -EAGAIN ; } dac->dela_state =XFS_DAS_FOUND_LBLK ; +trace_xfs_attr_set_iter_return (dac->dela_state, args->dp);return -EAGAIN ;case XFS_DAS_FOUND_LBLK :@@ -433,6 +439,8 @@ xfs_attr_set_iter(if (error)return error; +trace_xfs_attr_set_iter_return (dac->dela_state, + args->dp);return -EAGAIN ; }@@ -469,6 +477,7 @@ xfs_attr_set_iter(* series. */ dac->dela_state =XFS_DAS_FLIP_LFLAG ; +trace_xfs_attr_set_iter_return (dac->dela_state, args->dp);return -EAGAIN ;case XFS_DAS_FLIP_LFLAG :/* @@ -488,6 +497,9 @@ xfs_attr_set_iter(case XFS_DAS_RM_LBLK :if (args->rmtblkno) { error =__xfs_attr_rmtval_remove (dac); +if (error == -EAGAIN ) +trace_xfs_attr_set_iter_return ( + dac->dela_state, args->dp);if (error)return error; }@@ -545,6 +557,8 @@ xfs_attr_set_iter(if (error)return error; +trace_xfs_attr_set_iter_return ( + dac->dela_state, args->dp);return -EAGAIN ; }@@ -581,6 +595,7 @@ xfs_attr_set_iter(* series */ dac->dela_state =XFS_DAS_FLIP_NFLAG ; +trace_xfs_attr_set_iter_return (dac->dela_state, args->dp);return -EAGAIN ;case XFS_DAS_FLIP_NFLAG :@@ -601,6 +616,10 @@ xfs_attr_set_iter(case XFS_DAS_RM_NBLK :if (args->rmtblkno) { error =__xfs_attr_rmtval_remove (dac); +if (error == -EAGAIN ) +trace_xfs_attr_set_iter_return ( + dac->dela_state, args->dp); +if (error)return error; }@@ -1214,6 +1233,8 @@ xfs_attr_node_addname(* this point. */ dac->flags |=XFS_DAC_DEFER_FINISH ; +trace_xfs_attr_node_addname_return ( + dac->dela_state, args->dp);return -EAGAIN ; }@@ -1394,6 +1415,9 @@ xfs_attr_node_remove_rmt (* May return -EAGAIN to request that the caller recall this function */ error =__xfs_attr_rmtval_remove (dac); +if (error == -EAGAIN ) +trace_xfs_attr_node_remove_rmt_return (dac->dela_state, + dac->da_args->dp);if (error)return error;@@ -1513,6 +1537,8 @@ xfs_attr_node_removename_iter( dac->flags |=XFS_DAC_DEFER_FINISH ; dac->dela_state =XFS_DAS_RM_SHRINK ; +trace_xfs_attr_node_removename_iter_return ( + dac->dela_state, args->dp);return -EAGAIN ; }@@ -1531,8 +1557,11 @@ xfs_attr_node_removename_iter( goto out; } -if (error == -EAGAIN ) +if (error == -EAGAIN ) { +trace_xfs_attr_node_removename_iter_return ( + dac->dela_state, args->dp);return error; + } out:if (state)xfs_da_state_free (state);fs/xfs/libxfs/xfs_attr_remote.c +1
-0@@ -763,6 +763,7 @@ __xfs_attr_rmtval_remove(*/ if (!done) { dac->flags |=XFS_DAC_DEFER_FINISH ; +trace_xfs_attr_rmtval_remove_return (dac->dela_state, args->dp);return -EAGAIN ; }fs/xfs/xfs_trace.h +25
-0@@ -3927,6 +3927,31 @@ DEFINE_EVENT(xfs_eofblocks_class, name, \DEFINE_EOFBLOCKS_EVENT (xfs_ioc_free_eofblocks);DEFINE_EOFBLOCKS_EVENT (xfs_blockgc_free_space); +DECLARE_EVENT_CLASS (xfs_das_state_class, + TP_PROTO(int das, struct xfs_inode *ip), +TP_ARGS (das, ip), +TP_STRUCT__entry ( + __field(int, das) +__field (xfs_ino_t, ino) + ), +TP_fast_assign ( + __entry->das = das; + __entry->ino = ip->i_ino; + ), +TP_printk ("state change %d ino 0x%llx" , + __entry->das, __entry->ino) +) + +#define DEFINE_DAS_STATE_EVENT (name) \ +DEFINE_EVENT(xfs_das_state_class, name, \ + TP_PROTO(int das, struct xfs_inode *ip), \ + TP_ARGS(das, ip)) +DEFINE_DAS_STATE_EVENT (xfs_attr_set_fmt_return); +DEFINE_DAS_STATE_EVENT (xfs_attr_set_iter_return); +DEFINE_DAS_STATE_EVENT (xfs_attr_node_addname_return); +DEFINE_DAS_STATE_EVENT (xfs_attr_node_removename_iter_return); +DEFINE_DAS_STATE_EVENT (xfs_attr_node_remove_rmt_return); +DEFINE_DAS_STATE_EVENT (xfs_attr_rmtval_remove_return);#endif /* _TRACE_XFS_H */ #undef TRACE_INCLUDE_PATHSignature · 1 line
2.7.4
PATCH v15 14/22 xfs: Rename __xfs_attr_rmtval_remove
In reply to Allison HendersonNow that xfs_attr_rmtval_remove is gone, rename __xfs_attr_rmtval_remove to xfs_attr_rmtval_remove
--- fs/xfs/libxfs/xfs_attr.c | 6 +++--- fs/xfs/libxfs/xfs_attr_remote.c | 2 +- fs/xfs/libxfs/xfs_attr_remote.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-)
fs/xfs/libxfs/xfs_attr.c +3 -3
@@ -496,7 +496,7 @@ xfs_attr_set_iter(/* fallthrough */ case XFS_DAS_RM_LBLK :if (args->rmtblkno) { - error =__xfs_attr_rmtval_remove (dac); + error =xfs_attr_rmtval_remove (dac);if (error == -EAGAIN )trace_xfs_attr_set_iter_return ( dac->dela_state, args->dp);
@@ -615,7 +615,7 @@ xfs_attr_set_iter(/* fallthrough */ case XFS_DAS_RM_NBLK :if (args->rmtblkno) { - error =__xfs_attr_rmtval_remove (dac); + error =xfs_attr_rmtval_remove (dac);if (error == -EAGAIN )trace_xfs_attr_set_iter_return ( dac->dela_state, args->dp);
@@ -1414,7 +1414,7 @@ xfs_attr_node_remove_rmt (/* * May return -EAGAIN to request that the caller recall this function */ - error =__xfs_attr_rmtval_remove (dac); + error =xfs_attr_rmtval_remove (dac);if (error == -EAGAIN )trace_xfs_attr_node_remove_rmt_return (dac->dela_state, dac->da_args->dp);
fs/xfs/libxfs/xfs_attr_remote.c +1 -1
@@ -737,7 +737,7 @@ xfs_attr_rmtval_invalidate(* transaction and re-call the function */ int -__xfs_attr_rmtval_remove ( +xfs_attr_rmtval_remove (struct xfs_delattr_context *dac) {struct xfs_da_args *args = dac->da_args;
fs/xfs/libxfs/xfs_attr_remote.h +1 -1
@@ -13,7 +13,7 @@ int xfs_attr_rmtval_set(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_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);
Signature · 1 line
2.7.4
PATCH v15 15/22 xfs: Handle krealloc errors in xlog_recover_add_to_cont_trans
In reply to Allison HendersonBecause xattrs can be over a page in size, we need to handle possible krealloc errors to avoid warnings
The warning:
WARNING: CPU: 1 PID: 20255 at mm/page_alloc.c:3446
get_page_from_freelist+0x100b/0x1690is caused when sizes larger that a page are allocated with the __GFP_NOFAIL flag option. We encounter this error now because attr values can be up to 64k in size. So we cannot use __GFP_NOFAIL, and we need to handle the error code if the allocation fails.
--- fs/xfs/xfs_log_recover.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
fs/xfs/xfs_log_recover.c +4 -1
@@ -2061,7 +2061,10 @@ xlog_recover_add_to_cont_trans( old_ptr = item->ri_buf[item->ri_cnt-1 ].i_addr; old_len = item->ri_buf[item->ri_cnt-1 ].i_len; - ptr =krealloc (old_ptr, len + old_len,GFP_KERNEL | __GFP_NOFAIL); + ptr =krealloc (old_ptr, len + old_len,GFP_KERNEL ); +if (ptr ==NULL ) +return -ENOMEM ; +memcpy (&ptr[old_len], dp, len); item->ri_buf[item->ri_cnt-1 ].i_len += len; item->ri_buf[item->ri_cnt-1 ].i_addr = ptr;
Signature · 1 line
2.7.4
Re: [PATCH v15 15/22] xfs: Handle krealloc errors in xlog_recover_add_to_cont_trans
Quoted 22 lines · Allison Henderson
Because xattrs can be over a page in size, we need to handle possible krealloc errors to avoid warnings
The warning:
WARNING: CPU: 1 PID: 20255 at mm/page_alloc.c:3446 get_page_from_freelist+0x100b/0x1690is caused when sizes larger that a page are allocated with the
__GFP_NOFAILflag option. We encounter this error now because attr values can be up to 64k in size. So we cannot use__GFP_NOFAIL, and we need to handle the error code if the allocation fails.Signed-off-by Allison Henderson <[email protected]>--- fs/xfs/xfs_log_recover.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)fs/xfs/xfs_log_recover.c +0
-0
fs/xfs/xfs_log_recover.c xlog_recover_add_to_cont_trans( · line 2066
Quoted 7 lines
fs/xfs/xfs_log_recover.c +3
-1@@ -2061,7 +2061,10 @@ xlog_recover_add_to_cont_trans( old_ptr = item->ri_buf[item->ri_cnt-1 ].i_addr; old_len = item->ri_buf[item->ri_cnt-1 ].i_len; - ptr =krealloc (old_ptr, len + old_len,GFP_KERNEL | __GFP_NOFAIL); + ptr =krealloc (old_ptr, len + old_len,GFP_KERNEL ); +if (ptr ==NULL ) +return -ENOMEM ;
Given that we update i_addr anyway, perhaps this should fall back to kmem_alloc_large+memcpy to avoid introducing another failure point?
--D
Quoted 7 lines
fs/xfs/xfs_log_recover.c +1
-0+memcpy (&ptr[old_len], dp, len); item->ri_buf[item->ri_cnt-1 ].i_len += len; item->ri_buf[item->ri_cnt-1 ].i_addr = ptr;Signature · 1 line
2.7.4
Re: [PATCH v15 15/22] xfs: Handle krealloc errors in xlog_recover_add_to_cont_trans
Quoted 26 lines · Darrick J. Wong
Quoted 25 lines · Allison Henderson
Because xattrs can be over a page in size, we need to handle possible krealloc errors to avoid warnings
The warning:
WARNING: CPU: 1 PID: 20255 at mm/page_alloc.c:3446 get_page_from_freelist+0x100b/0x1690is caused when sizes larger that a page are allocated with the
__GFP_NOFAILflag option. We encounter this error now because attr values can be up to 64k in size. So we cannot use__GFP_NOFAIL, and we need to handle the error code if the allocation fails.Signed-off-by Allison Henderson <[email protected]>--- fs/xfs/xfs_log_recover.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)fs/xfs/xfs_log_recover.c +0
-0@@ -2061,7 +2061,10 @@ xlog_recover_add_to_cont_trans( old_ptr = item->ri_buf[item->ri_cnt-1 ].i_addr; old_len = item->ri_buf[item->ri_cnt-1 ].i_len;
Quoted 7 lines
fs/xfs/xfs_log_recover.c xlog_recover_add_to_cont_trans( · line 2066
Quoted 4 lines
fs/xfs/xfs_log_recover.c +3
-1- ptr =krealloc (old_ptr, len + old_len,GFP_KERNEL | __GFP_NOFAIL); + ptr =krealloc (old_ptr, len + old_len,GFP_KERNEL ); +if (ptr ==NULL ) +return -ENOMEM ;Given that we update
i_addranyway, perhaps this should fall back to kmem_alloc_large+memcpy to avoid introducing another failure point?
Sure, I can add that in. Thx!
Allison
Quoted 10 lines
--D
Quoted 7 lines
fs/xfs/xfs_log_recover.c +1
-0+memcpy (&ptr[old_len], dp, len); item->ri_buf[item->ri_cnt-1 ].i_len += len; item->ri_buf[item->ri_cnt-1 ].i_addr = ptr;Signature · 1 line
2.7.4
PATCH v15 16/22 xfs: Set up infastructure for deferred attribute operations
In reply to Allison HendersonCurrently attributes are modified directly across one or more transactions. But they are not logged or replayed in the event of an error. The goal of delayed attributes is to enable logging and replaying of attribute operations using the existing delayed operations infrastructure. This will later enable the attributes to become part of larger multi part operations that also must first be recorded to the log. This is mostly of interest in the scheme of parent pointers which would need to maintain an attribute containing parent inode information any time an inode is moved, created, or removed. Parent pointers would then be of interest to any feature that would need to quickly derive an inode path from the mount point. Online scrub, nfs lookups and fs grow or shrink operations are all features that could take advantage of this.
This patch adds two new log item types for setting or removing attributes as deferred operations. The xfs_attri_log_item logs an intent to set or remove an attribute. The corresponding xfs_attrd_log_item holds a reference to the xfs_attri_log_item and is freed once the transaction is done. Both log items use a generic xfs_attr_log_format structure that contains the attribute name, value, flags, inode, and an op_flag that indicates if the operations is a set or remove.
--- fs/xfs/Makefile | 1 + fs/xfs/libxfs/xfs_attr.c | 7 +- fs/xfs/libxfs/xfs_attr.h | 31 ++ fs/xfs/libxfs/xfs_defer.c | 1 + fs/xfs/libxfs/xfs_defer.h | 3 + fs/xfs/libxfs/xfs_log_format.h | 44 ++- fs/xfs/libxfs/xfs_log_recover.h | 2 + fs/xfs/scrub/common.c | 2 + fs/xfs/xfs_acl.c | 2 + fs/xfs/xfs_attr_item.c | 828 ++++++++++++++++++++++++++++++++++++++++ fs/xfs/xfs_attr_item.h | 52 +++ fs/xfs/xfs_attr_list.c | 1 + fs/xfs/xfs_ioctl.c | 2 + fs/xfs/xfs_ioctl32.c | 2 + fs/xfs/xfs_iops.c | 2 + fs/xfs/xfs_log.c | 4 + fs/xfs/xfs_log_recover.c | 2 + fs/xfs/xfs_ondisk.h | 2 + fs/xfs/xfs_xattr.c | 1 + 19 files changed, 984 insertions(+), 5 deletions(-)
fs/xfs/Makefile +1 -0
@@ -102,6 +102,7 @@ xfs-y += xfs_log.o \ xfs_buf_item_recover.o \ xfs_dquot_item_recover.o \ xfs_extfree_item.o \ + xfs_attr_item.o \ xfs_icreate_item.o \ xfs_inode_item.o \ xfs_inode_item_recover.o \
fs/xfs/libxfs/xfs_attr.c +4 -3
@@ -24,6 +24,7 @@#include "xfs_quota.h" #include "xfs_trans_space.h" #include "xfs_trace.h" +#include "xfs_attr_item.h" /* * xfs_attr.c
@@ -61,8 +62,8 @@ 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_attr_set_iter (struct xfs_delattr_context *dac, +struct xfs_buf **leaf_bp);int xfs_inode_hasattr(
@@ -144,7 +145,7 @@ xfs_attr_get(/* * Calculate how many blocks we need for the new attribute, */ -STATIC int +int xfs_attr_calc_size (struct xfs_da_args *args,int *local)
fs/xfs/libxfs/xfs_attr.h +31 -0
@@ -28,6 +28,11 @@ struct xfs_attr_list_context;*/ #define ATTR_MAX_VALUELEN (64*1024)/* max length of a value */ +static inline bool xfs_hasdelattr (struct xfs_mount *mp) +{ +return false; +} +/* * Kernel-internal version of the attrlist cursor. */
@@ -390,6 +395,7 @@ enum xfs_delattr_state {*/ #define XFS_DAC_DEFER_FINISH 0x01/* finish the transaction */ #define XFS_DAC_LEAF_ADDNAME_INIT 0x02/* xfs_attr_leaf_addname init*/ +#define XFS_DAC_DELAYED_OP_INIT 0x04/* delayed operations init*/ /* * Context used for keeping track of delayed attribute operations
@@ -397,6 +403,11 @@ enum xfs_delattr_state {struct xfs_delattr_context {struct xfs_da_args *da_args; +/* +* Used by xfs_attr_set to hold a leaf buffer across a transaction roll +*/ +struct xfs_buf *leaf_bp; +/* Used in xfs_attr_rmtval_set_blk to roll through allocating blocks */ struct xfs_bmbt_irec map;xfs_dablk_t lblkno;
@@ -410,6 +421,23 @@ struct xfs_delattr_context {enum xfs_delattr_state dela_state; }; +/* +* List of attrs to commit later. +*/ +struct xfs_attr_item { +struct xfs_delattr_context xattri_dac; + +/* +* Indicates if the attr operation is a set or a remove +* XFS_ATTR_OP_FLAGS_{SET,REMOVE} +*/ +uint32_t xattri_op_flags; + +/* used to log this item to an intent */ +struct list_head xattri_list; +}; + +/*======================================================================== * Function prototypes for the kernel. *========================================================================*/
@@ -425,11 +453,14 @@ int xfs_attr_get_ilocked(struct xfs_da_args *args);int xfs_attr_get (struct xfs_da_args *args);int xfs_attr_set (struct xfs_da_args *args);int xfs_attr_set_args (struct xfs_da_args *args); +int xfs_attr_set_iter (struct xfs_delattr_context *dac, +struct xfs_buf **leaf_bp);int xfs_has_attr (struct xfs_da_args *args);int xfs_attr_remove_args (struct xfs_da_args *args);int xfs_attr_remove_iter (struct xfs_delattr_context *dac);bool xfs_attr_namecheck (const void *name,size_t length);void xfs_delattr_context_init (struct xfs_delattr_context *dac,struct xfs_da_args *args); +int xfs_attr_calc_size (struct xfs_da_args *args,int *local);#endif /* __XFS_ATTR_H__ */
fs/xfs/libxfs/xfs_defer.c +1 -0
@@ -178,6 +178,7 @@ static const struct xfs_defer_op_type *defer_op_types[] = { [XFS_DEFER_OPS_TYPE_RMAP] = &xfs_rmap_update_defer_type, [XFS_DEFER_OPS_TYPE_FREE] = &xfs_extent_free_defer_type, [XFS_DEFER_OPS_TYPE_AGFL_FREE] = &xfs_agfl_free_defer_type, + [XFS_DEFER_OPS_TYPE_ATTR] = &xfs_attr_defer_type, }; static void
fs/xfs/libxfs/xfs_defer.h +3 -0
@@ -19,6 +19,7 @@ enum xfs_defer_ops_type {XFS_DEFER_OPS_TYPE_RMAP ,XFS_DEFER_OPS_TYPE_FREE ,XFS_DEFER_OPS_TYPE_AGFL_FREE , +XFS_DEFER_OPS_TYPE_ATTR , XFS_DEFER_OPS_TYPE_MAX, };
@@ -63,6 +64,8 @@ extern const struct xfs_defer_op_type xfs_refcount_update_defer_type;extern const struct xfs_defer_op_type xfs_rmap_update_defer_type;extern const struct xfs_defer_op_type xfs_extent_free_defer_type;extern const struct xfs_defer_op_type xfs_agfl_free_defer_type; +extern const struct xfs_defer_op_type xfs_attr_defer_type; +/* * This structure enables a dfops user to detach the chain of deferred
fs/xfs/libxfs/xfs_log_format.h +42 -2
66 lines not on this page · raw message
fs/xfs/libxfs/xfs_log_recover.h +2 -0
@@ -72,6 +72,8 @@ extern const struct xlog_recover_item_ops xlog_rui_item_ops;extern const struct xlog_recover_item_ops xlog_rud_item_ops;extern const struct xlog_recover_item_ops xlog_cui_item_ops;extern const struct xlog_recover_item_ops xlog_cud_item_ops; +extern const struct xlog_recover_item_ops xlog_attri_item_ops; +extern const struct xlog_recover_item_ops xlog_attrd_item_ops;/* * Macros, structures, prototypes for internal log manager use.
fs/xfs/scrub/common.c +2 -0
@@ -24,6 +24,8 @@#include "xfs_rmap_btree.h" #include "xfs_log.h" #include "xfs_trans_priv.h" +#include "xfs_da_format.h" +#include "xfs_da_btree.h" #include "xfs_attr.h" #include "xfs_reflink.h" #include "scrub/scrub.h"
fs/xfs/xfs_acl.c +2 -0
@@ -10,6 +10,8 @@#include "xfs_trans_resv.h" #include "xfs_mount.h" #include "xfs_inode.h" +#include "xfs_da_format.h" +#include "xfs_da_btree.h" #include "xfs_attr.h" #include "xfs_trace.h" #include "xfs_error.h"
fs/xfs/xfs_attr_item.c new file +828 -0
828 lines not on this page · raw message
fs/xfs/xfs_attr_item.h new file +52 -0
52 lines not on this page · raw message
fs/xfs/xfs_attr_list.c +1 -0
@@ -15,6 +15,7 @@#include "xfs_inode.h" #include "xfs_trans.h" #include "xfs_bmap.h" +#include "xfs_da_btree.h" #include "xfs_attr.h" #include "xfs_attr_sf.h" #include "xfs_attr_leaf.h"
fs/xfs/xfs_ioctl.c +2 -0
@@ -15,6 +15,8 @@#include "xfs_iwalk.h" #include "xfs_itable.h" #include "xfs_error.h" +#include "xfs_da_format.h" +#include "xfs_da_btree.h" #include "xfs_attr.h" #include "xfs_bmap.h" #include "xfs_bmap_util.h"
fs/xfs/xfs_ioctl32.c +2 -0
@@ -17,6 +17,8 @@#include "xfs_itable.h" #include "xfs_fsops.h" #include "xfs_rtalloc.h" +#include "xfs_da_format.h" +#include "xfs_da_btree.h" #include "xfs_attr.h" #include "xfs_ioctl.h" #include "xfs_ioctl32.h"
fs/xfs/xfs_iops.c +2 -0
@@ -13,6 +13,8 @@#include "xfs_inode.h" #include "xfs_acl.h" #include "xfs_quota.h" +#include "xfs_da_format.h" +#include "xfs_da_btree.h" #include "xfs_attr.h" #include "xfs_trans.h" #include "xfs_trace.h"
fs/xfs/xfs_log.c +4 -0
@@ -2070,6 +2070,10 @@ xlog_print_tic_res(REG_TYPE_STR (CUD_FORMAT ,"cud_format" ),REG_TYPE_STR (BUI_FORMAT ,"bui_format" ),REG_TYPE_STR (BUD_FORMAT ,"bud_format" ), +REG_TYPE_STR (ATTRI_FORMAT ,"attri_format" ), +REG_TYPE_STR (ATTRD_FORMAT ,"attrd_format" ), +REG_TYPE_STR (ATTR_NAME ,"attr_name" ), +REG_TYPE_STR (ATTR_VALUE ,"attr_value" ), };BUILD_BUG_ON (ARRAY_SIZE (res_type_str) !=XLOG_REG_TYPE_MAX +1 );#undef REG_TYPE_STR
fs/xfs/xfs_log_recover.c +2 -0
@@ -1775,6 +1775,8 @@ static const struct xlog_recover_item_ops *xlog_recover_item_ops[] = { &xlog_cud_item_ops, &xlog_bui_item_ops, &xlog_bud_item_ops, + &xlog_attri_item_ops, + &xlog_attrd_item_ops, }; static const struct xlog_recover_item_ops *
fs/xfs/xfs_ondisk.h +2 -0
@@ -132,6 +132,8 @@ xfs_check_ondisk_structs(void) XFS_CHECK_STRUCT_SIZE(struct xfs_inode_log_format, 56); XFS_CHECK_STRUCT_SIZE(struct xfs_qoff_logformat, 20); XFS_CHECK_STRUCT_SIZE(struct xfs_trans_header, 16); + XFS_CHECK_STRUCT_SIZE(struct xfs_attri_log_format, 40); + XFS_CHECK_STRUCT_SIZE(struct xfs_attrd_log_format, 16);/* * The v5 superblock format extended several v4 header structures with
fs/xfs/xfs_xattr.c +1 -0
@@ -10,6 +10,7 @@#include "xfs_log_format.h" #include "xfs_da_format.h" #include "xfs_inode.h" +#include "xfs_da_btree.h" #include "xfs_attr.h" #include "xfs_acl.h" #include "xfs_da_btree.h"
Signature · 1 line
2.7.4
Re: [PATCH v15 16/22] xfs: Set up infastructure for deferred attribute operations
Quoted 22 lines · Allison Henderson
Currently attributes are modified directly across one or more transactions. But they are not logged or replayed in the event of an error. The goal of delayed attributes is to enable logging and replaying of attribute operations using the existing delayed operations infrastructure. This will later enable the attributes to become part of larger multi part operations that also must first be recorded to the log. This is mostly of interest in the scheme of parent pointers which would need to maintain an attribute containing parent inode information any time an inode is moved, created, or removed. Parent pointers would then be of interest to any feature that would need to quickly derive an inode path from the mount point. Online scrub, nfs lookups and fs grow or shrink operations are all features that could take advantage of this.
This patch adds two new log item types for setting or removing attributes as deferred operations. The
xfs_attri_log_itemlogs an intent to set or remove an attribute. The correspondingxfs_attrd_log_itemholds a reference to thexfs_attri_log_itemand is freed once the transaction is done. Both log items use a genericxfs_attr_log_formatstructure that contains the attribute name, value, flags, inode, and anop_flagthat indicates if the operations is a set or remove.
Quoted 1 line
Signed-off-by Allison Henderson <[email protected]>
I saw a 36K patch and thought "Jeez! This should be broken up!"
Then I looked at atomic extent swap (which does add its log item code gradually) and decided that maybe you just don't want to explode the patchset from 22 to 30. That sounds (kind of) reasonable.
(...and by 'kind of', I probably mean that if I end up taking everything up to this patch for 5.13 then this part really ought to get broken up a bit for a future submission. But let's wait until the end of this review to decide that...)
Quoted 574 lines
--- fs/xfs/Makefile | 1 + fs/xfs/libxfs/xfs_attr.c | 7 +- fs/xfs/libxfs/xfs_attr.h | 31 ++ fs/xfs/libxfs/xfs_defer.c | 1 + fs/xfs/libxfs/xfs_defer.h | 3 + fs/xfs/libxfs/xfs_log_format.h | 44 ++- fs/xfs/libxfs/xfs_log_recover.h | 2 + fs/xfs/scrub/common.c | 2 + fs/xfs/xfs_acl.c | 2 + fs/xfs/xfs_attr_item.c | 828 ++++++++++++++++++++++++++++++++++++++++ fs/xfs/xfs_attr_item.h | 52 +++ fs/xfs/xfs_attr_list.c | 1 + fs/xfs/xfs_ioctl.c | 2 + fs/xfs/xfs_ioctl32.c | 2 + fs/xfs/xfs_iops.c | 2 + fs/xfs/xfs_log.c | 4 + fs/xfs/xfs_log_recover.c | 2 + fs/xfs/xfs_ondisk.h | 2 + fs/xfs/xfs_xattr.c | 1 + 19 files changed, 984 insertions(+), 5 deletions(-)fs/xfs/Makefile +1
-0@@ -102,6 +102,7 @@ xfs-y += xfs_log.o \ xfs_buf_item_recover.o \ xfs_dquot_item_recover.o \ xfs_extfree_item.o \ + xfs_attr_item.o \ xfs_icreate_item.o \ xfs_inode_item.o \ xfs_inode_item_recover.o \fs/xfs/libxfs/xfs_attr.c +4
-3@@ -24,6 +24,7 @@#include "xfs_quota.h" #include "xfs_trans_space.h" #include "xfs_trace.h" +#include "xfs_attr_item.h" /* * xfs_attr.c @@ -61,8 +62,8 @@ 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_attr_set_iter (struct xfs_delattr_context *dac, +struct xfs_buf **leaf_bp);int xfs_inode_hasattr(@@ -144,7 +145,7 @@ xfs_attr_get(/* * Calculate how many blocks we need for the new attribute, */ -STATIC int +int xfs_attr_calc_size (struct xfs_da_args *args,int *local)fs/xfs/libxfs/xfs_attr.h +31
-0@@ -28,6 +28,11 @@ struct xfs_attr_list_context;*/ #define ATTR_MAX_VALUELEN (64*1024)/* max length of a value */ +static inline bool xfs_hasdelattr (struct xfs_mount *mp) +{ +return false; +} +/* * Kernel-internal version of the attrlist cursor. */ @@ -390,6 +395,7 @@ enum xfs_delattr_state {*/ #define XFS_DAC_DEFER_FINISH 0x01/* finish the transaction */ #define XFS_DAC_LEAF_ADDNAME_INIT 0x02/* xfs_attr_leaf_addname init*/ +#define XFS_DAC_DELAYED_OP_INIT 0x04/* delayed operations init*/ /* * Context used for keeping track of delayed attribute operations @@ -397,6 +403,11 @@ enum xfs_delattr_state {struct xfs_delattr_context {struct xfs_da_args *da_args; +/* +* Used by xfs_attr_set to hold a leaf buffer across a transaction roll +*/ +struct xfs_buf *leaf_bp; +/* Used in xfs_attr_rmtval_set_blk to roll through allocating blocks */ struct xfs_bmbt_irec map;xfs_dablk_t lblkno;@@ -410,6 +421,23 @@ struct xfs_delattr_context {enum xfs_delattr_state dela_state; }; +/* +* List of attrs to commit later. +*/ +struct xfs_attr_item { +struct xfs_delattr_context xattri_dac; + +/* +* Indicates if the attr operation is a set or a remove +* XFS_ATTR_OP_FLAGS_{SET,REMOVE} +*/ +uint32_t xattri_op_flags; + +/* used to log this item to an intent */ +struct list_head xattri_list; +}; + +/*======================================================================== * Function prototypes for the kernel. *========================================================================*/ @@ -425,11 +453,14 @@ int xfs_attr_get_ilocked(struct xfs_da_args *args);int xfs_attr_get (struct xfs_da_args *args);int xfs_attr_set (struct xfs_da_args *args);int xfs_attr_set_args (struct xfs_da_args *args); +int xfs_attr_set_iter (struct xfs_delattr_context *dac, +struct xfs_buf **leaf_bp);int xfs_has_attr (struct xfs_da_args *args);int xfs_attr_remove_args (struct xfs_da_args *args);int xfs_attr_remove_iter (struct xfs_delattr_context *dac);bool xfs_attr_namecheck (const void *name,size_t length);void xfs_delattr_context_init (struct xfs_delattr_context *dac,struct xfs_da_args *args); +int xfs_attr_calc_size (struct xfs_da_args *args,int *local);#endif /* __XFS_ATTR_H__ */ fs/xfs/libxfs/xfs_defer.c +1
-0@@ -178,6 +178,7 @@ static const struct xfs_defer_op_type *defer_op_types[] = { [XFS_DEFER_OPS_TYPE_RMAP] = &xfs_rmap_update_defer_type, [XFS_DEFER_OPS_TYPE_FREE] = &xfs_extent_free_defer_type, [XFS_DEFER_OPS_TYPE_AGFL_FREE] = &xfs_agfl_free_defer_type, + [XFS_DEFER_OPS_TYPE_ATTR] = &xfs_attr_defer_type, }; static voidfs/xfs/libxfs/xfs_defer.h +3
-0@@ -19,6 +19,7 @@ enum xfs_defer_ops_type {XFS_DEFER_OPS_TYPE_RMAP ,XFS_DEFER_OPS_TYPE_FREE ,XFS_DEFER_OPS_TYPE_AGFL_FREE , +XFS_DEFER_OPS_TYPE_ATTR , XFS_DEFER_OPS_TYPE_MAX, };@@ -63,6 +64,8 @@ extern const struct xfs_defer_op_type xfs_refcount_update_defer_type;extern const struct xfs_defer_op_type xfs_rmap_update_defer_type;extern const struct xfs_defer_op_type xfs_extent_free_defer_type;extern const struct xfs_defer_op_type xfs_agfl_free_defer_type; +extern const struct xfs_defer_op_type xfs_attr_defer_type; +/* * This structure enables a dfops user to detach the chain of deferred fs/xfs/libxfs/xfs_log_format.h +42
-2@@ -117,7 +117,12 @@ struct xfs_unmount_log_format {#define XLOG_REG_TYPE_CUD_FORMAT 24#define XLOG_REG_TYPE_BUI_FORMAT 25#define XLOG_REG_TYPE_BUD_FORMAT 26 -#define XLOG_REG_TYPE_MAX 26 +#define XLOG_REG_TYPE_ATTRI_FORMAT 27 +#define XLOG_REG_TYPE_ATTRD_FORMAT 28 +#define XLOG_REG_TYPE_ATTR_NAME 29 +#define XLOG_REG_TYPE_ATTR_VALUE 30 +#define XLOG_REG_TYPE_MAX 30 +/* * Flags to log operation header @@ -240,6 +245,8 @@ typedef struct xfs_trans_header {#define XFS_LI_CUD 0x1243#define XFS_LI_BUI 0x1244/* bmbt update intent */ #define XFS_LI_BUD 0x1245 +#define XFS_LI_ATTRI 0x1246/* attr set/remove intent*/ +#define XFS_LI_ATTRD 0x1247/* attr set/remove done */ #define XFS_LI_TYPE_DESC \ { XFS_LI_EFI, "XFS_LI_EFI" }, \@@ -255,7 +262,9 @@ typedef struct xfs_trans_header { { XFS_LI_CUI, "XFS_LI_CUI" }, \ { XFS_LI_CUD, "XFS_LI_CUD" }, \ { XFS_LI_BUI, "XFS_LI_BUI" }, \ - { XFS_LI_BUD, "XFS_LI_BUD" } + { XFS_LI_BUD, "XFS_LI_BUD" }, \ + { XFS_LI_ATTRI, "XFS_LI_ATTRI" }, \ + { XFS_LI_ATTRD, "XFS_LI_ATTRD" }/* * Inode Log Item Format definitions. @@ -863,4 +872,35 @@ struct xfs_icreate_log { __be32 icl_gen; /* inode generation number to use */ }; +/* +* Flags for deferred attribute operations. +* Upper bits are flags, lower byte is type code +*/ +#define XFS_ATTR_OP_FLAGS_SET 1/* Set the attribute */ +#define XFS_ATTR_OP_FLAGS_REMOVE 2/* Remove the attribute */ +#define XFS_ATTR_OP_FLAGS_TYPE_MASK 0x0FF/* Flags type mask */ + +/* +* This is the structure used to lay out an attr log item in the +* log. +*/ +struct xfs_attri_log_format { +uint16_t alfi_type;/* attri log item type */ +uint16_t alfi_size;/* size of this item */ +uint32_t __pad;/* pad to 64 bit aligned */ +uint64_t alfi_id;/* attri identifier */ +uint64_t alfi_ino;/* the inode for this attr operation */ +uint32_t alfi_op_flags;/* marks the op as a set or remove */ +uint32_t alfi_name_len;/* attr name length */ +uint32_t alfi_value_len;/* attr value length */ +uint32_t alfi_attr_flags;/* attr flags */ +}; + +struct xfs_attrd_log_format { +uint16_t alfd_type;/* attrd log item type */ +uint16_t alfd_size;/* size of this item */ +uint32_t __pad;/* pad to 64 bit aligned */ +uint64_t alfd_alf_id;/* id of corresponding attri */ +}; +#endif /* __XFS_LOG_FORMAT_H__ */ fs/xfs/libxfs/xfs_log_recover.h +2
-0@@ -72,6 +72,8 @@ extern const struct xlog_recover_item_ops xlog_rui_item_ops;extern const struct xlog_recover_item_ops xlog_rud_item_ops;extern const struct xlog_recover_item_ops xlog_cui_item_ops;extern const struct xlog_recover_item_ops xlog_cud_item_ops; +extern const struct xlog_recover_item_ops xlog_attri_item_ops; +extern const struct xlog_recover_item_ops xlog_attrd_item_ops;/* * Macros, structures, prototypes for internal log manager use. fs/xfs/scrub/common.c +2
-0@@ -24,6 +24,8 @@#include "xfs_rmap_btree.h" #include "xfs_log.h" #include "xfs_trans_priv.h" +#include "xfs_da_format.h" +#include "xfs_da_btree.h" #include "xfs_attr.h" #include "xfs_reflink.h" #include "scrub/scrub.h" fs/xfs/xfs_acl.c +2
-0@@ -10,6 +10,8 @@#include "xfs_trans_resv.h" #include "xfs_mount.h" #include "xfs_inode.h" +#include "xfs_da_format.h" +#include "xfs_da_btree.h" #include "xfs_attr.h" #include "xfs_trace.h" #include "xfs_error.h" fs/xfs/xfs_attr_item.c new file +281
-0@@ -0,0 +1,828 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (C) 2021 Oracle. All Rights Reserved. +* Author: Allison Collins <[email protected]> +*/ + +#include "xfs.h" +#include "xfs_fs.h" +#include "xfs_format.h" +#include "xfs_log_format.h" +#include "xfs_trans_resv.h" +#include "xfs_bit.h" +#include "xfs_shared.h" +#include "xfs_mount.h" +#include "xfs_defer.h" +#include "xfs_da_format.h" +#include "xfs_log_format.h" +#include "xfs_trans.h" +#include "xfs_bmap.h" +#include "xfs_bmap_btree.h" +#include "xfs_trans_priv.h" +#include "xfs_buf_item.h" +#include "xfs_attr_item.h" +#include "xfs_log.h" +#include "xfs_btree.h" +#include "xfs_rmap.h" +#include "xfs_inode.h" +#include "xfs_icache.h" +#include "xfs_da_format.h" +#include "xfs_da_btree.h" +#include "xfs_attr.h" +#include "xfs_shared.h" +#include "xfs_attr_item.h" +#include "xfs_alloc.h" +#include "xfs_bmap.h" +#include "xfs_trace.h" +#include "libxfs/xfs_da_format.h" +#include "xfs_inode.h" +#include "xfs_quota.h" +#include "xfs_trans_space.h" +#include "xfs_log_priv.h" +#include "xfs_log_recover.h" + +static const struct xfs_item_ops xfs_attri_item_ops; +static const struct xfs_item_ops xfs_attrd_item_ops; + +/* iovec length must be 32-bit aligned */ +static inline size_t ATTR_NVEC_SIZE (size_t size) +{ +return size ==sizeof (int32_t ) ? size : +sizeof (int32_t ) +round_up (size,sizeof (int32_t )); +} + +static inline struct xfs_attri_log_item *ATTRI_ITEM (struct xfs_log_item *lip) +{ + return container_of(lip, struct xfs_attri_log_item, attri_item); +} + +STATIC void +xfs_attri_item_free ( +struct xfs_attri_log_item *attrip) +{ +kmem_free (attrip->attri_item.li_lv_shadow); +kmem_free (attrip); +} + +/* +* Freeing the attrip requires that we remove it from the AIL if it has already +* been placed there. However, the ATTRI may not yet have been placed in the +* AIL when called by xfs_attri_release() from ATTRD processing due to the +* ordering of committed vs unpin operations in bulk insert operations. Hence +* the reference count to ensure only the last caller frees the ATTRI. +*/ +STATIC void +xfs_attri_release ( +struct xfs_attri_log_item *attrip) +{ +ASSERT (atomic_read (&attrip->attri_refcount) >0 ); +if (atomic_dec_and_test (&attrip->attri_refcount)) { +xfs_trans_ail_delete (&attrip->attri_item, +SHUTDOWN_LOG_IO_ERROR ); +xfs_attri_item_free (attrip); + } +} + +STATIC void +xfs_attri_item_size ( +struct xfs_log_item *lip, +int *nvecs, +int *nbytes) +{ +struct xfs_attri_log_item *attrip =ATTRI_ITEM (lip); + + *nvecs +=1 ; + *nbytes +=sizeof (struct xfs_attri_log_format ); + +/* Attr set and remove operations require a name */ +ASSERT (attrip->attri_name_len >0 ); + + *nvecs +=1 ; + *nbytes +=ATTR_NVEC_SIZE (attrip->attri_name_len); + +/* +* Set ops can accept a value of 0 len to clear an attr value. Remove +* ops do not need a value at all. So only account for the value +* when it is needed. +*/ +if (attrip->attri_value_len >0 ) { + *nvecs +=1 ; + *nbytes +=ATTR_NVEC_SIZE (attrip->attri_value_len); + } +} + +/* +* This is called to fill in the log iovecs for the given attri log +* item. We use 1 iovec for the attri_format_item, 1 for the name, and +* another for the value if it is present +*/ +STATIC void +xfs_attri_item_format ( +struct xfs_log_item *lip, +struct xfs_log_vec *lv) +{ +struct xfs_attri_log_item *attrip =ATTRI_ITEM (lip); +struct xfs_log_iovec *vecp =NULL ; + + attrip->attri_format.alfi_type =XFS_LI_ATTRI ; + attrip->attri_format.alfi_size =1 ; + +/* +* This size accounting must be done before copying the attrip into the +* iovec. If we do it after, the wrong size will be recorded to the log +* and we trip across assertion checks for bad region sizes later during +* the log recovery. +*/ + +ASSERT (attrip->attri_name_len >0 ); + attrip->attri_format.alfi_size++; + +if (attrip->attri_value_len >0 ) + attrip->attri_format.alfi_size++; + +xlog_copy_iovec (lv, &vecp,XLOG_REG_TYPE_ATTRI_FORMAT , + &attrip->attri_format, +sizeof (struct xfs_attri_log_format )); +xlog_copy_iovec (lv, &vecp,XLOG_REG_TYPE_ATTR_NAME , + attrip->attri_name, +ATTR_NVEC_SIZE (attrip->attri_name_len)); +if (attrip->attri_value_len >0 ) +xlog_copy_iovec (lv, &vecp,XLOG_REG_TYPE_ATTR_VALUE , + attrip->attri_value, +ATTR_NVEC_SIZE (attrip->attri_value_len)); +} + +/* +* The unpin operation is the last place an ATTRI is manipulated in the log. It +* is either inserted in the AIL or aborted in the event of a log I/O error. In +* either case, the ATTRI transaction has been successfully committed to make +* it this far. Therefore, we expect whoever committed the ATTRI to either +* construct and commit the ATTRD or drop the ATTRD's reference in the event of +* error. Simply drop the log's ATTRI reference now that the log is done with +* it. +*/ +STATIC void +xfs_attri_item_unpin ( +struct xfs_log_item *lip, +int remove) +{ +xfs_attri_release (ATTRI_ITEM (lip)); +} + + +STATIC void +xfs_attri_item_release ( +struct xfs_log_item *lip) +{ +xfs_attri_release (ATTRI_ITEM (lip)); +} + +/* +* Allocate and initialize an attri item. Caller may allocate an additional +* trailing buffer of the specified size +*/ +STATIC struct xfs_attri_log_item * +xfs_attri_init ( +struct xfs_mount *mp, +int buffer_size) + +{ +struct xfs_attri_log_item *attrip; +uint size; + + size =sizeof (struct xfs_attri_log_item ) + buffer_size; + attrip =kmem_alloc_large (size,KM_ZERO ); +if (attrip ==NULL ) +return NULL ; + +xfs_log_item_init (mp, &attrip->attri_item,XFS_LI_ATTRI , + &xfs_attri_item_ops); + attrip->attri_format.alfi_id = (uintptr_t )(void *)attrip; +atomic_set (&attrip->attri_refcount,2 ); + +return attrip; +} + +/* +* Copy an attr format buffer from the given buf, and into the destination attr +* format structure. +*/ +STATIC int +xfs_attri_copy_format ( +struct xfs_log_iovec *buf, +struct xfs_attri_log_format *dst_attr_fmt) +{ +struct xfs_attri_log_format *src_attr_fmt = buf->i_addr; +uint len; + + len =sizeof (struct xfs_attri_log_format ); +if (buf->i_len != len) +return -EFSCORRUPTED ; + +memcpy ((char *)dst_attr_fmt, (char *)src_attr_fmt, len); +return 0 ; +} + +static inline struct xfs_attrd_log_item *ATTRD_ITEM (struct xfs_log_item *lip) +{ + return container_of(lip, struct xfs_attrd_log_item, attrd_item); +} + +STATIC void +xfs_attrd_item_free (struct xfs_attrd_log_item *attrdp) +{ +kmem_free (attrdp->attrd_item.li_lv_shadow); +kmem_free (attrdp); +} + +STATIC void +xfs_attrd_item_size ( +struct xfs_log_item *lip, +int *nvecs, +int *nbytes) +{ + *nvecs +=1 ; + *nbytes +=sizeof (struct xfs_attrd_log_format ); +} + +/* +* This is called to fill in the log iovecs for the given attrd log item. We use +* only 1 iovec for the attrd_format, and we point that at the attr_log_format +* structure embedded in the attrd item. +*/ +STATIC void +xfs_attrd_item_format ( +struct xfs_log_item *lip, +struct xfs_log_vec *lv) +{ +struct xfs_attrd_log_item *attrdp =ATTRD_ITEM (lip); +struct xfs_log_iovec *vecp =NULL ; + + attrdp->attrd_format.alfd_type =XFS_LI_ATTRD ; + attrdp->attrd_format.alfd_size =1 ; + +xlog_copy_iovec (lv, &vecp,XLOG_REG_TYPE_ATTRD_FORMAT , + &attrdp->attrd_format, +sizeof (struct xfs_attrd_log_format )); +} + +/* +* The ATTRD is either committed or aborted if the transaction is cancelled. If +* the transaction is cancelled, drop our reference to the ATTRI and free the +* ATTRD. +*/ +STATIC void +xfs_attrd_item_release ( +struct xfs_log_item *lip) +{ +struct xfs_attrd_log_item *attrdp =ATTRD_ITEM (lip); + +xfs_attri_release (attrdp->attrd_attrip); +xfs_attrd_item_free (attrdp);
fs/xfs/xfs_attr_item.c line 291
Quoted 10 lines
fs/xfs/xfs_attr_item.c new file +10
-0+} + +/* +* Performs one step of an attribute update intent and marks the attrd item +* dirty.. An attr operation may be a set or a remove. Note that the +* transaction is marked dirty regardless of whether the operation succeeds or +* fails to support the ATTRI/ATTRD lifecycle rules. +*/ +int +xfs_trans_attr(
xfs_attri_finish_update() ?
Quoted 166 lines
fs/xfs/xfs_attr_item.c new file +166
-0+struct xfs_delattr_context *dac, + struct xfs_attrd_log_item *attrdp, + struct xfs_buf **leaf_bp, + uint32_t op_flags) +{ + struct xfs_da_args *args = dac->da_args; +int error; + + error =xfs_qm_dqattach_locked (args->dp,0 ); +if (error) +return error; + +switch (op_flags) { +case XFS_ATTR_OP_FLAGS_SET : + args->op_flags |=XFS_DA_OP_ADDNAME ; + error =xfs_attr_set_iter (dac, leaf_bp); +break ; +case XFS_ATTR_OP_FLAGS_REMOVE : +ASSERT (XFS_IFORK_Q (args->dp)); + error =xfs_attr_remove_iter (dac); +break ; +default : + error = -EFSCORRUPTED ; +break ; + } + +/* +* Mark the transaction dirty, even on error. This ensures the +* transaction is aborted, which: +* +* 1.) releases the ATTRI and frees the ATTRD +* 2.) shuts down the filesystem +*/ + args->trans->t_flags |=XFS_TRANS_DIRTY ; + +/* +* attr intent/done items are null when delayed attributes are disabled +*/ +if (attrdp) +set_bit (XFS_LI_DIRTY , &attrdp->attrd_item.li_flags); + +return error; +} + +/* Log an attr to the intent item. */ +STATIC void +xfs_attr_log_item ( +struct xfs_trans *tp, +struct xfs_attri_log_item *attrip, +struct xfs_attr_item *attr) +{ +struct xfs_attri_log_format *attrp; + + tp->t_flags |=XFS_TRANS_DIRTY ; +set_bit (XFS_LI_DIRTY , &attrip->attri_item.li_flags); + +/* +* At this point the xfs_attr_item has been constructed, and we've +* created the log intent. Fill in the attri log item and log format +* structure with fields from this xfs_attr_item +*/ + attrp = &attrip->attri_format; + attrp->alfi_ino = attr->xattri_dac.da_args->dp->i_ino; + attrp->alfi_op_flags = attr->xattri_op_flags; + attrp->alfi_value_len = attr->xattri_dac.da_args->valuelen; + attrp->alfi_name_len = attr->xattri_dac.da_args->namelen; + attrp->alfi_attr_flags = attr->xattri_dac.da_args->attr_filter; + + attrip->attri_name = (void *)attr->xattri_dac.da_args->name; + attrip->attri_value = attr->xattri_dac.da_args->value; + attrip->attri_name_len = attr->xattri_dac.da_args->namelen; + attrip->attri_value_len = attr->xattri_dac.da_args->valuelen; +} + +/* Get an ATTRI. */ +static struct xfs_log_item * +xfs_attr_create_intent ( +struct xfs_trans *tp, +struct list_head *items, +unsigned int count, +bool sort) +{ +struct xfs_mount *mp = tp->t_mountp; +struct xfs_attri_log_item *attrip; +struct xfs_attr_item *attr; + +ASSERT (count ==1 ); + +if (!xfs_hasdelattr (mp)) +return NULL ; + + attrip =xfs_attri_init (mp,0 ); +if (attrip ==NULL ) +return NULL ; + +xfs_trans_add_item (tp, &attrip->attri_item); +list_for_each_entry (attr, items, xattri_list) +xfs_attr_log_item (tp, attrip, attr); +return &attrip->attri_item; +} + +/* Process an attr. */ +STATIC int +xfs_attr_finish_item ( +struct xfs_trans *tp, +struct xfs_log_item *done, +struct list_head *item, +struct xfs_btree_cur **state) +{ +struct xfs_attr_item *attr; +struct xfs_attrd_log_item *done_item =NULL ; +int error; +struct xfs_delattr_context *dac; + + attr = container_of(item, struct xfs_attr_item, xattri_list); + dac = &attr->xattri_dac; +if (done) + done_item =ATTRD_ITEM (done); + +/* +* Corner case that can happen during a recovery. Because the first +* iteration of a multi part delay op happens in xfs_attri_item_recover +* to maintain the order of the log replay items. But the new +* transactions do not automatically rejoin during a recovery as they do +* in a standard delay op, so we need to catch this here and rejoin the +* leaf to the new transaction +*/ +if (attr->xattri_dac.leaf_bp && + attr->xattri_dac.leaf_bp->b_transp != tp) { +xfs_trans_bjoin (tp, attr->xattri_dac.leaf_bp); +xfs_trans_bhold (tp, attr->xattri_dac.leaf_bp); + } + +/* +* Always reset trans after EAGAIN cycle +* since the transaction is new +*/ + dac->da_args->trans = tp; + + error =xfs_trans_attr (dac, done_item, &dac->leaf_bp, + attr->xattri_op_flags); +if (error != -EAGAIN ) +kmem_free (attr); + +return error; +} + +/* Abort all pending ATTRs. */ +STATIC void +xfs_attr_abort_intent ( +struct xfs_log_item *intent) +{ +xfs_attri_release (ATTRI_ITEM (intent)); +} + +/* Cancel an attr */ +STATIC void +xfs_attr_cancel_item ( +struct list_head *item) +{ +struct xfs_attr_item *attr; + + attr = container_of(item, struct xfs_attr_item, xattri_list); +kmem_free (attr); +} +
fs/xfs/xfs_attr_item.c line 467
Quoted 10 lines
fs/xfs/xfs_attr_item.c new file +10
-0+STATIC xfs_lsn_t +xfs_attri_item_committed ( +struct xfs_log_item *lip, +xfs_lsn_t lsn) +{ +struct xfs_attri_log_item *attrip; +/* +* The attrip refers to xfs_attr_item memory to log the name and value +* with the intent item. This already occurred when the intent was +* committed so these fields are no longer accessed. Clear them out of
+ * caution since we're about to free the xfs_attr_item.
Quoted 102 lines
fs/xfs/xfs_attr_item.c new file +102
-0+*/ + attrip =ATTRI_ITEM (lip); + attrip->attri_name =NULL ; + attrip->attri_value =NULL ; + +/* +* The ATTRI is logged only once and cannot be moved in the log, so +* simply return the lsn at which it's been logged. +*/ +return lsn; +} + +STATIC bool +xfs_attri_item_match ( +struct xfs_log_item *lip, +uint64_t intent_id) +{ +return ATTRI_ITEM (lip)->attri_format.alfi_id == intent_id; +} + +/* +* This routine is called to allocate an "attr free done" log item. +*/ +struct xfs_attrd_log_item * +xfs_trans_get_attrd (struct xfs_trans *tp, +struct xfs_attri_log_item *attrip) +{ +struct xfs_attrd_log_item *attrdp; +uint size; + +ASSERT (tp !=NULL ); + + size =sizeof (struct xfs_attrd_log_item ); + attrdp =kmem_zalloc (size,0 ); + +xfs_log_item_init (tp->t_mountp, &attrdp->attrd_item,XFS_LI_ATTRD , + &xfs_attrd_item_ops); + attrdp->attrd_attrip = attrip; + attrdp->attrd_format.alfd_alf_id = attrip->attri_format.alfi_id; + +xfs_trans_add_item (tp, &attrdp->attrd_item); +return attrdp; +} + +static const struct xfs_item_ops xfs_attrd_item_ops = { + .flags =XFS_ITEM_RELEASE_WHEN_COMMITTED , + .iop_size = xfs_attrd_item_size, + .iop_format = xfs_attrd_item_format, + .iop_release = xfs_attrd_item_release, +}; + + +/* Get an ATTRD so we can process all the attrs. */ +static struct xfs_log_item * +xfs_attr_create_done ( +struct xfs_trans *tp, +struct xfs_log_item *intent, +unsigned int count) +{ +if (!intent) +return NULL ; + +return &xfs_trans_get_attrd (tp,ATTRI_ITEM (intent))->attrd_item; +} + +const struct xfs_defer_op_type xfs_attr_defer_type = { + .max_items =1 , + .create_intent = xfs_attr_create_intent, + .abort_intent = xfs_attr_abort_intent, + .create_done = xfs_attr_create_done, + .finish_item = xfs_attr_finish_item, + .cancel_item = xfs_attr_cancel_item, +}; + +/* +* Process an attr intent item that was recovered from the log. We need to +* delete the attr that it describes. +*/ +STATIC int +xfs_attri_item_recover ( +struct xfs_log_item *lip, +struct list_head *capture_list) +{ +struct xfs_attri_log_item *attrip =ATTRI_ITEM (lip); +struct xfs_attr_item *new_attr; +struct xfs_mount *mp = lip->li_mountp; +struct xfs_inode *ip; +struct xfs_da_args args; +struct xfs_da_args *new_args; +struct xfs_trans_res tres; +bool rsvd; +struct xfs_attri_log_format *attrp; +int error; +int total; +int local; +struct xfs_attrd_log_item *done_item =NULL ; +struct xfs_attr_item attr = { + .xattri_op_flags = attrip->attri_format.alfi_op_flags, + .xattri_dac.da_args = &args, + }; + +/*
fs/xfs/xfs_attr_item.c line 580
Quoted 10 lines
fs/xfs/xfs_attr_item.c new file +10
-0+* First check the validity of the attr described by the ATTRI. If any +* are bad, then assume that all are bad and just toss the ATTRI. +*/ + attrp = &attrip->attri_format; + if (!(attrp->alfi_op_flags == XFS_ATTR_OP_FLAGS_SET || + attrp->alfi_op_flags == XFS_ATTR_OP_FLAGS_REMOVE) || + (attrp->alfi_value_len > XATTR_SIZE_MAX) || + (attrp->alfi_name_len > XATTR_NAME_MAX) || + (attrp->alfi_name_len == 0) || + xfs_verify_ino(mp, attrp->alfi_ino) == false ||
Please put this validation logic in a separate predicate.
It probably ought to ensure that there aren't illegal characters in the attr name too.
fs/xfs/xfs_attr_item.c line 581
Quoted 1 line
fs/xfs/xfs_attr_item.c new file +1
-0+ !xfs_hasdelattr(mp)) {
Weird nit: If you mount with -o delattr, crash, and remount without that mount option, we'll report that as a corruption error.
Not sure what we want to do about that, it's a rough edge but it's also an experimental feature.
Quoted 26 lines
fs/xfs/xfs_attr_item.c new file +25
-0+return -EFSCORRUPTED ; + } + + error =xfs_iget (mp,0 , attrp->alfi_ino,0 ,0 , &ip); +if (error) +return error; + +if (VFS_I (ip)->i_nlink ==0 ) +xfs_iflags_set (ip,XFS_IRECOVERY ); + +memset (&args,0 ,sizeof (struct xfs_da_args )); + args.dp = ip; + args.geo = mp->m_attr_geo; + args.op_flags = attrp->alfi_op_flags; + args.whichfork =XFS_ATTR_FORK ; + args.name = attrip->attri_name; + args.namelen = attrp->alfi_name_len; + args.hashval =xfs_da_hashname (args.name, args.namelen); + args.attr_filter = attrp->alfi_attr_flags; + +if (attrp->alfi_op_flags ==XFS_ATTR_OP_FLAGS_SET ) { + args.value = attrip->attri_value; + args.valuelen = attrp->alfi_value_len; + args.total =xfs_attr_calc_size (&args, &local); +
fs/xfs/xfs_attr_item.c line 616
Quoted 10 lines
fs/xfs/xfs_attr_item.c new file +10
-0+ tres.tr_logres =M_RES (mp)->tr_attrsetm.tr_logres + +M_RES (mp)->tr_attrsetrt.tr_logres * + args.total; + tres.tr_logcount =XFS_ATTRSET_LOG_COUNT ; + tres.tr_logflags =XFS_TRANS_PERM_LOG_RES ; + total = args.total; + }else { + tres =M_RES (mp)->tr_attrrm; + total =XFS_ATTRRM_SPACE_RES (mp); + }
Isn't there already code in xfs_attr.c that does this?
Quoted 126 lines
fs/xfs/xfs_attr_item.c new file +126
-0+ error =xfs_trans_alloc (mp, &tres, total,0 , + rsvd ?XFS_TRANS_RESERVE :0 , &args.trans); +if (error) +return error; + + done_item =xfs_trans_get_attrd (args.trans, attrip); + +xfs_ilock (ip,XFS_ILOCK_EXCL ); +xfs_trans_ijoin (args.trans, ip,0 ); + + error =xfs_trans_attr (&attr.xattri_dac, done_item, + &attr.xattri_dac.leaf_bp, attrp->alfi_op_flags); +if (error == -EAGAIN ) { +/* +* There's more work to do, so make a new xfs_attr_item and add +* it to this transaction. We dont use xfs_attr_item_init here +* because we need the info stored in the current attr to +* continue with this multi-part operation. So, alloc space +* for it and the args and copy everything there. +*/ + new_attr =kmem_zalloc (sizeof (struct xfs_attr_item ) + +sizeof (struct xfs_da_args ),KM_NOFS ); + new_args = (struct xfs_da_args *)((char *)new_attr + +sizeof (struct xfs_attr_item )); + +memcpy (new_args, &args,sizeof (struct xfs_da_args )); +memcpy (new_attr, &attr,sizeof (struct xfs_attr_item )); + + new_attr->xattri_dac.da_args = new_args; +memset (&new_attr->xattri_list,0 ,sizeof (struct list_head )); + +xfs_defer_add (args.trans,XFS_DEFER_OPS_TYPE_ATTR , + &new_attr->xattri_list); + +/* Do not send -EAGAIN back to caller */ + error =0 ; + }else if (error) { +xfs_trans_cancel (args.trans); + goto out; + } + +xfs_defer_ops_capture_and_commit (args.trans, ip, capture_list); + +out: +xfs_iunlock (ip,XFS_ILOCK_EXCL ); +xfs_irele (ip); +return error; +} + +/* Relog an intent item to push the log tail forward. */ +static struct xfs_log_item * +xfs_attri_item_relog ( +struct xfs_log_item *intent, +struct xfs_trans *tp) +{ +struct xfs_attrd_log_item *attrdp; +struct xfs_attri_log_item *old_attrip; +struct xfs_attri_log_item *new_attrip; +struct xfs_attri_log_format *new_attrp; +struct xfs_attri_log_format *old_attrp; +int buffer_size; + + old_attrip =ATTRI_ITEM (intent); + old_attrp = &old_attrip->attri_format; + buffer_size = old_attrp->alfi_value_len + old_attrp->alfi_name_len; + + tp->t_flags |=XFS_TRANS_DIRTY ; + attrdp =xfs_trans_get_attrd (tp, old_attrip); +set_bit (XFS_LI_DIRTY , &attrdp->attrd_item.li_flags); + + new_attrip =xfs_attri_init (tp->t_mountp, buffer_size); + new_attrp = &new_attrip->attri_format; + + new_attrp->alfi_ino = old_attrp->alfi_ino; + new_attrp->alfi_op_flags = old_attrp->alfi_op_flags; + new_attrp->alfi_value_len = old_attrp->alfi_value_len; + new_attrp->alfi_name_len = old_attrp->alfi_name_len; + new_attrp->alfi_attr_flags = old_attrp->alfi_attr_flags; + + new_attrip->attri_name_len = old_attrip->attri_name_len; + new_attrip->attri_name = ((char *)new_attrip) + +sizeof (struct xfs_attri_log_item ); +memcpy (new_attrip->attri_name, old_attrip->attri_name, + new_attrip->attri_name_len); + + new_attrip->attri_value_len = old_attrip->attri_value_len; +if (new_attrip->attri_value_len >0 ) { + new_attrip->attri_value = new_attrip->attri_name + + new_attrip->attri_name_len; + +memcpy (new_attrip->attri_value, old_attrip->attri_value, + new_attrip->attri_value_len); + } + +xfs_trans_add_item (tp, &new_attrip->attri_item); +set_bit (XFS_LI_DIRTY , &new_attrip->attri_item.li_flags); + +return &new_attrip->attri_item; +} + +static const struct xfs_item_ops xfs_attri_item_ops = { + .iop_size = xfs_attri_item_size, + .iop_format = xfs_attri_item_format, + .iop_unpin = xfs_attri_item_unpin, + .iop_committed = xfs_attri_item_committed, + .iop_release = xfs_attri_item_release, + .iop_recover = xfs_attri_item_recover, + .iop_match = xfs_attri_item_match, + .iop_relog = xfs_attri_item_relog, +}; + + + +STATIC int +xlog_recover_attri_commit_pass2 ( +struct xlog *log, +struct list_head *buffer_list, +struct xlog_recover_item *item, +xfs_lsn_t lsn) +{ +int error; +struct xfs_mount *mp = log->l_mp; +struct xfs_attri_log_item *attrip; +struct xfs_attri_log_format *attri_formatp; +char *name =NULL ; +char *value =NULL ;
fs/xfs/xfs_attr_item.c line 752
Quoted 10 lines
fs/xfs/xfs_attr_item.c new file +10
-0+int region =0 ; +int buffer_size; + + attri_formatp = item->ri_buf[region].i_addr; + +/* Validate xfs_attri_log_format */ +if (attri_formatp->__pad !=0 || attri_formatp->alfi_name_len ==0 || + (attri_formatp->alfi_op_flags ==XFS_ATTR_OP_FLAGS_REMOVE && + attri_formatp->alfi_value_len !=0 )) +return -EFSCORRUPTED ;
Might be worth an XFS_ERROR_REPORT here since this is evidence of incore memory corruption, right?
Quoted 93 lines
fs/xfs/xfs_attr_item.c new file +76
-0+ + buffer_size = attri_formatp->alfi_name_len + + attri_formatp->alfi_value_len; + + attrip =xfs_attri_init (mp, buffer_size); +if (attrip ==NULL ) +return -ENOMEM ; + + error =xfs_attri_copy_format (&item->ri_buf[region], + &attrip->attri_format); +if (error) { +xfs_attri_item_free (attrip); +return error; + } + + attrip->attri_name_len = attri_formatp->alfi_name_len; + attrip->attri_value_len = attri_formatp->alfi_value_len; + region++; + name = ((char *)attrip) +sizeof (struct xfs_attri_log_item ); +memcpy (name, item->ri_buf[region].i_addr, attrip->attri_name_len); + attrip->attri_name = name; + +if (attrip->attri_value_len >0 ) { + region++; + value = ((char *)attrip) +sizeof (struct xfs_attri_log_item ) + + attrip->attri_name_len; +memcpy (value, item->ri_buf[region].i_addr, + attrip->attri_value_len); + attrip->attri_value = value; + } + +/* +* The ATTRI has two references. One for the ATTRD and one for ATTRI to +* ensure it makes it into the AIL. Insert the ATTRI into the AIL +* directly and drop the ATTRI reference. Note that +* xfs_trans_ail_update() drops the AIL lock. +*/ +xfs_trans_ail_insert (log->l_ailp, &attrip->attri_item, lsn); +xfs_attri_release (attrip); +return 0 ; +} + +const struct xlog_recover_item_ops xlog_attri_item_ops = { + .item_type =XFS_LI_ATTRI , + .commit_pass2 = xlog_recover_attri_commit_pass2, +}; + +/* +* This routine is called when an ATTRD format structure is found in a committed +* transaction in the log. Its purpose is to cancel the corresponding ATTRI if +* it was still in the log. To do this it searches the AIL for the ATTRI with +* an id equal to that in the ATTRD format structure. If we find it we drop +* the ATTRD reference, which removes the ATTRI from the AIL and frees it. +*/ +STATIC int +xlog_recover_attrd_commit_pass2 ( +struct xlog *log, +struct list_head *buffer_list, +struct xlog_recover_item *item, +xfs_lsn_t lsn) +{ +struct xfs_attrd_log_format *attrd_formatp; + + attrd_formatp = item->ri_buf[0 ].i_addr; +ASSERT ((item->ri_buf[0 ].i_len == + (sizeof (struct xfs_attrd_log_format )))); + +xlog_recover_release_intent (log,XFS_LI_ATTRI , + attrd_formatp->alfd_alf_id); +return 0 ; +} + +const struct xlog_recover_item_ops xlog_attrd_item_ops = { + .item_type =XFS_LI_ATTRD , + .commit_pass2 = xlog_recover_attrd_commit_pass2, +};fs/xfs/xfs_attr_item.h new file +11
-0@@ -0,0 +1,52 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later +* +* Copyright (C) 2019 Oracle. All Rights Reserved. +* Author: Allison Collins <[email protected]> +*/ +#ifndef __XFS_ATTR_ITEM_H__ +#define __XFS_ATTR_ITEM_H__ + +/* kernel only ATTRI/ATTRD definitions */ + +struct xfs_mount ;
fs/xfs/xfs_attr_item.h line 21
Quoted 10 lines
fs/xfs/xfs_attr_item.h new file +10
-0+struct kmem_zone ; + +/* +* Define ATTR flag bits. Manipulated by set/clear/test_bit operators. +*/ +#define XFS_ATTRI_RECOVERED 1 + + +/* +* This is the "attr intention" log item. It is used to log the fact that some
Well, it's the incore state tracking for attr intent log items... :)
Aside from the nits I 've pointed out so far, this looks more or less ok to me.
--------------
Ok, so here we are at the end. Looking at my own atomic extent swap series, I broke this up into two pieces -- one to create the barebones log item (with dummy implementations); and a second one to create the defer ops code and connect it to the log item.
Oh, heh. The first patch is 16K and the second one is 47K.
That might be a good way to break *this* patch into smaller parts, if nothing else -- concentrate on getting the log parts working, then connect the new state machine to defer ops and log items.
That said, as this series gets longer and longer I find it really more difficult to go through the whole series one by one vs. just diffing the whole branch and reviewing that.
<shrug> I don't really have a definitive answer for which is better. The xattr code is very complex, and I struggle even combining both of my usual strategies and attacking review from both ends.
By the way, have you been stress testing the xattr code with all this stuff applied? At some point it becomes easier to pull this in and fix up the breakage than it is to review 22 slice-n-dice patches every cycle.
--D
Quoted 138 lines
fs/xfs/xfs_attr_item.h new file +31
-0+* attribute operations need to be processed. An operation is currently either +* a set or remove. Set or remove operations are described by the xfs_attr_item +* which may be logged to this intent. +* +* During a normal attr operation, name and value point to the name and value +* feilds of the calling functions xfs_da_args. During a recovery, the name +* and value buffers are copied from the log, and stored in a trailing buffer +* attached to the xfs_attr_item until they are committed. They are freed when +* the xfs_attr_item itself is freed when the work is done. +*/ +struct xfs_attri_log_item { +struct xfs_log_item attri_item; +atomic_t attri_refcount; +int attri_name_len; +int attri_value_len; +void *attri_name; +void *attri_value; +struct xfs_attri_log_format attri_format; +}; + +/* +* This is the "attr done" log item. It is used to log the fact that some attrs +* earlier mentioned in an attri item have been freed. +*/ +struct xfs_attrd_log_item { +struct xfs_attri_log_item *attrd_attrip; +struct xfs_log_item attrd_item; +struct xfs_attrd_log_format attrd_format; +}; + +#endif /* __XFS_ATTR_ITEM_H__ */ fs/xfs/xfs_attr_list.c +1
-0@@ -15,6 +15,7 @@#include "xfs_inode.h" #include "xfs_trans.h" #include "xfs_bmap.h" +#include "xfs_da_btree.h" #include "xfs_attr.h" #include "xfs_attr_sf.h" #include "xfs_attr_leaf.h" fs/xfs/xfs_ioctl.c +2
-0@@ -15,6 +15,8 @@#include "xfs_iwalk.h" #include "xfs_itable.h" #include "xfs_error.h" +#include "xfs_da_format.h" +#include "xfs_da_btree.h" #include "xfs_attr.h" #include "xfs_bmap.h" #include "xfs_bmap_util.h" fs/xfs/xfs_ioctl32.c +2
-0@@ -17,6 +17,8 @@#include "xfs_itable.h" #include "xfs_fsops.h" #include "xfs_rtalloc.h" +#include "xfs_da_format.h" +#include "xfs_da_btree.h" #include "xfs_attr.h" #include "xfs_ioctl.h" #include "xfs_ioctl32.h" fs/xfs/xfs_iops.c +2
-0@@ -13,6 +13,8 @@#include "xfs_inode.h" #include "xfs_acl.h" #include "xfs_quota.h" +#include "xfs_da_format.h" +#include "xfs_da_btree.h" #include "xfs_attr.h" #include "xfs_trans.h" #include "xfs_trace.h" fs/xfs/xfs_log.c +4
-0@@ -2070,6 +2070,10 @@ xlog_print_tic_res(REG_TYPE_STR (CUD_FORMAT ,"cud_format" ),REG_TYPE_STR (BUI_FORMAT ,"bui_format" ),REG_TYPE_STR (BUD_FORMAT ,"bud_format" ), +REG_TYPE_STR (ATTRI_FORMAT ,"attri_format" ), +REG_TYPE_STR (ATTRD_FORMAT ,"attrd_format" ), +REG_TYPE_STR (ATTR_NAME ,"attr_name" ), +REG_TYPE_STR (ATTR_VALUE ,"attr_value" ), };BUILD_BUG_ON (ARRAY_SIZE (res_type_str) !=XLOG_REG_TYPE_MAX +1 );#undef REG_TYPE_STRfs/xfs/xfs_log_recover.c +2
-0@@ -1775,6 +1775,8 @@ static const struct xlog_recover_item_ops *xlog_recover_item_ops[] = { &xlog_cud_item_ops, &xlog_bui_item_ops, &xlog_bud_item_ops, + &xlog_attri_item_ops, + &xlog_attrd_item_ops, }; static const struct xlog_recover_item_ops *fs/xfs/xfs_ondisk.h +2
-0@@ -132,6 +132,8 @@ xfs_check_ondisk_structs(void) XFS_CHECK_STRUCT_SIZE(struct xfs_inode_log_format, 56); XFS_CHECK_STRUCT_SIZE(struct xfs_qoff_logformat, 20); XFS_CHECK_STRUCT_SIZE(struct xfs_trans_header, 16); + XFS_CHECK_STRUCT_SIZE(struct xfs_attri_log_format, 40); + XFS_CHECK_STRUCT_SIZE(struct xfs_attrd_log_format, 16);/* * The v5 superblock format extended several v4 header structures with fs/xfs/xfs_xattr.c +1
-0@@ -10,6 +10,7 @@#include "xfs_log_format.h" #include "xfs_da_format.h" #include "xfs_inode.h" +#include "xfs_da_btree.h" #include "xfs_attr.h" #include "xfs_acl.h" #include "xfs_da_btree.h" Signature · 1 line
2.7.4