xfs: Delayed Attributes
v13 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 either a delayed operation or a inline operation since older filesystems will not be able to use the new log entries. This means that they cannot roll, commit, or finish transactions. Instead, they return -EAGAIN to allow the calling function to handle the transaction. In this series, we focus on only the clean up and refactoring needed to accomplish this. We will introduce delayed attrs and parent pointers in a later set.
At the moment, I would like people to focus their review efforts on just this "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-4)
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. The behavior of the attr set/remove routines are now also compatible as a .finish_item callback
xfs: Add helper xfs_attr_node_remove_step
xfs: Add delay ready attr remove routines
xfs: Add delay ready attr set routines
xfs: Rename __xfs_attr_rmtval_remove
Delayed Attributes: (patches 5 - 10)
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 feature bit 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: Add xfs_attr_set_deferred and xfs_attr_remove_deferred
xfs: Add feature bit XFS_SB_FEAT_INCOMPAT_LOG_DELATTR
xfs: Enable delayed attributes
xfs Remove unused xfs_attr_-_args.patch
xfs: Add delayed attributes error tag
Updates since v12: Mostly integrating review feed back. I've refactored xfs_attr_node_removename as discussed in the 2nd patch, and consolidated the xfs_attr_item members into a single args pointer. I've gotten the dfops mechanics to drive both delayed and non-delayed operations. Lastly the xfs_attr_*_args functions are removed at the end of the set since the dfops machinery replaces it. I did explore reorganizing xfs_da_args, though I think thats big enough to be a separate project and I wanted to get a v13 out before too much time gets away. Also updated the extended parent pointer series to keep it functional for now.
xfs: Add helper xfs_attr_node_remove_step
New
xfs: Add delay ready attr remove routines
Fixed typo in commit message
Rebase adjustments
Refactored xfs_attr_node_removename to xfs_attr_node_removename_iter Added state XFS_DAC_UNINIT to avoid warnings
Found I could remove blk from dac. Removed to simplify
xfs: Add delay ready attr set routines
Rebase adjustments
xfs: Set up infastructure for deferred attribute operations
Collapsed xfs_attr_item members into a single args pointer
Modified xfs_attr_create_intent routines to return null when delayed attrs not enabled Modified xfs_trans_attr and xfs_attr_finish_item to avoid handling intent and
done items when delayed attrs not enabled Moved xfs_sb_version_hasdelattr stub from "xfs: Add feature bit XFS_SB_FEAT_INCOMPAT_LOG_DELATTR" patch to this patch. Used in managing when intents are recorded
Removed initialization logic from args xfs_attr_finish_item (no longer needed) Simplified xfs_attr_recover to eliminate looping logic
xfs: Add xfs_attr_set_deferred and xfs_attr_remove_deferred
collapsed parameters into a single args pointer
xfs: Add feature bit XFS_SB_FEAT_INCOMPAT_LOG_DELATTR
Rebase adjustments: Fill in xfs_sb_version_hasdelattr stub from earlier patch
xfs: Enable delayed attributes
Removed logic to test for feature bit which is now handled by delayed attr mechanics
xfs: Remove unused xfs_attr_*_args
New
This series can be viewed on github here:
https://github.com/allisonhenderson/xfs_work/tree/delay_ready_attrs_v13
As well as the extended delayed attribute and parent pointer series:
https://github.com/allisonhenderson/xfs_work/tree/delay_ready_attrs_v13_extended
And the test cases:
https://github.com/allisonhenderson/xfs_work/tree/pptr_xfstests
In order to run the test cases, you will need have the corresponding xfsprogs changes as well. Which can be found here:
https://github.com/allisonhenderson/xfs_work/tree/delay_ready_attrs_xfsprogs_v13
https://github.com/allisonhenderson/xfs_work/tree/delay_ready_attrs_xfsprogs_v13_extended
To run the xfs attributes tests run:
check -g attr
To run as delayed attributes run:
export MKFS_OPTIONS="-n delattr"
check -g attr
To run parent pointer tests:
check -g parent
I've also made the corresponding updates to the user space side as well, and ported anything they need to seat correctly.
Questions, comment and feedback appreciated!
Thanks all!
Allison
Allison Collins (5):
xfs: Add helper xfs_attr_node_remove_step
xfs: Rename __xfs_attr_rmtval_remove
xfs: Add xfs_attr_set_deferred and xfs_attr_remove_deferred
xfs: Enable delayed attributes
xfs: Add delayed attributes error tag
Allison Henderson (5):
xfs: Add delay ready attr remove routines
xfs: Add delay ready attr set routines
xfs: Set up infastructure for deferred attribute operations
xfs: Add feature bit XFS_SB_FEAT_INCOMPAT_LOG_DELATTR
xfs: Remove unused xfs_attr_*_args
fs/xfs/Makefile | 1 + fs/xfs/libxfs/xfs_attr.c | 550 +++++++++++++++++++---------- fs/xfs/libxfs/xfs_attr.h | 218 +++++++++++- fs/xfs/libxfs/xfs_attr_leaf.c | 2 +- fs/xfs/libxfs/xfs_attr_remote.c | 110 +++--- 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_format.h | 11 +- fs/xfs/libxfs/xfs_fs.h | 1 + fs/xfs/libxfs/xfs_log_format.h | 44 ++- fs/xfs/libxfs/xfs_log_recover.h | 2 + fs/xfs/libxfs/xfs_sb.c | 2 + fs/xfs/libxfs/xfs_types.h | 1 + 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 | 758 ++++++++++++++++++++++++++++++++++++++++ fs/xfs/xfs_attr_item.h | 76 ++++ 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 | 2 + fs/xfs/xfs_ondisk.h | 2 + fs/xfs/xfs_super.c | 3 + fs/xfs/xfs_trace.h | 1 - fs/xfs/xfs_xattr.c | 1 + 31 files changed, 1591 insertions(+), 229 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 v13 1/10 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_remove.
--- 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 +* shirnk the tree if needed. +*/ +STATIC int +xfs_attr_node_removename ( +struct xfs_da_args *args) +{ +struct xfs_da_state *state; +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 v13 01/10] xfs: Add helper xfs_attr_node_remove_step
Quoted 5 lines · IST 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_remove.
The above should have been "xfs_attr_node_removename".
The code changes themselves are logically correct.
Quoted 92 lines
Signed-off-by Allison Henderson <[email protected]>--- 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 +* shirnk the tree if needed. +*/ +STATIC int +xfs_attr_node_removename ( +struct xfs_da_args *args) +{ +struct xfs_da_state *state; +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
chandan
Re: [PATCH v13 01/10] xfs: Add helper xfs_attr_node_remove_step
Quoted 8 lines · Chandan Babu R
Quoted 5 lines · IST 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_remove.The above should have been "
xfs_attr_node_removename".
Sure, will fix. Thanks!
Allison
Quoted 98 lines
The code changes themselves are logically correct.
Reviewed-by Chandan Babu R <[email protected]>Quoted 92 lines
Signed-off-by Allison Henderson <[email protected]>--- 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 +* shirnk the tree if needed. +*/ +STATIC int +xfs_attr_node_removename ( +struct xfs_da_args *args) +{ +struct xfs_da_state *state; +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. */
Re: [PATCH v13 01/10] xfs: Add helper xfs_attr_node_remove_step
In reply to Allison HendersonQuoted 15 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_remove.Signed-off-by Allison Henderson <[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 23 lines
fs/xfs/libxfs/xfs_attr.c +7
-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; } +return error; +} + +/*
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_removename( · line 1290
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10
-0+* Remove a name from a B-tree attribute list. +* +* This routine will find the blocks of the name to remove, remove them and +* shirnk the tree if needed. +*/ +STATIC int +xfs_attr_node_removename ( +struct xfs_da_args *args) +{ +struct xfs_da_state *state;
It urks me a little bit that we have to dig down into a couple functions to grok that state allocation is the first step or otherwise occurs before we potentially use the error path. Since we already check for state in the out path, can we just initialize this as *state = NULL here so the logic is clear? Otherwise the patch LGTM:
Quoted 19 lines
fs/xfs/libxfs/xfs_attr.c +13
-0+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 v13 01/10] xfs: Add helper xfs_attr_node_remove_step
Quoted 48 lines · Brian Foster
Quoted 15 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_remove.Signed-off-by Allison Henderson <[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 31 lines
fs/xfs/libxfs/xfs_attr.c +15
-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; } +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 +* shirnk the tree if needed. +*/ +STATIC int +xfs_attr_node_removename ( +struct xfs_da_args *args)
Quoted 9 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_removename( · line 1290
Quoted 2 lines
fs/xfs/libxfs/xfs_attr.c +2
-0+{ +struct xfs_da_state *state;It urks me a little bit that we have to dig down into a couple functions to grok that state allocation is the first step or otherwise occurs before we potentially use the error path. Since we already check for state in the out path, can we just initialize this as *state = NULL here so the logic is clear? Otherwise the patch LGTM:
Sure, will add. Thanks!
Allison
Quoted 22 lines
Reviewed-by Brian Foster <[email protected]>Quoted 19 lines
fs/xfs/libxfs/xfs_attr.c +13
-0+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 v13 01/10] xfs: Add helper xfs_attr_node_remove_step
In reply to Allison HendersonQuoted 7 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_remove.Signed-off-by Allison Henderson <[email protected]>
Looks fine to me, modulo Brian and Chandan's suggestions;
--D
Quoted 92 lines
--- 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 +* shirnk the tree if needed. +*/ +STATIC int +xfs_attr_node_removename ( +struct xfs_da_args *args) +{ +struct xfs_da_state *state; +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 v13 01/10] xfs: Add helper xfs_attr_node_remove_step
Quoted 11 lines · Darrick J. Wong
Quoted 7 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_remove.Signed-off-by Allison Henderson <[email protected]>Looks fine to me, modulo Brian and Chandan's suggestions;
Reviewed-by Darrick J. Wong <[email protected]>
Ok, thank you!
Allison
Quoted 95 lines
--D
Quoted 92 lines
--- 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 +* shirnk the tree if needed. +*/ +STATIC int +xfs_attr_node_removename ( +struct xfs_da_args *args) +{ +struct xfs_da_state *state; +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 v13 2/10 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 | 200 +++++++++++++++++++++++++++++----------- fs/xfs/libxfs/xfs_attr.h | 72 +++++++++++++++ fs/xfs/libxfs/xfs_attr_leaf.c | 2 +- fs/xfs/libxfs/xfs_attr_remote.c | 37 ++++---- fs/xfs/libxfs/xfs_attr_remote.h | 2 +- fs/xfs/xfs_attr_inactive.c | 2 +- 6 files changed, 241 insertions(+), 74 deletions(-)
fs/xfs/libxfs/xfs_attr.c +148 -52
@@ -53,7 +53,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_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);
@@ -264,6 +264,33 @@ xfs_attr_set_shortform( }/* +* 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 =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; + } + +return xfs_trans_roll_inode (&args->trans, args->dp); +} + +/* * Set the attribute specified in @args. */ int
@@ -364,23 +391,54 @@ 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 =0 ; +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 (dac->dela_state ==XFS_DAS_RM_SHRINK ) + goto node;if (!xfs_inode_hasattr (dp)) { - error = -ENOATTR ; +return -ENOATTR ; }else if (dp->i_afp->if_format ==XFS_DINODE_FMT_LOCAL ) {ASSERT (dp->i_afp->if_flags &XFS_IFINLINE ); - error =xfs_attr_shortform_remove (args); +return xfs_attr_shortform_remove (args); }else if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) { - error =xfs_attr_leaf_removename (args); - }else { - error =xfs_attr_node_removename (args); +return xfs_attr_leaf_removename (args); } - -return error; +node: +return xfs_attr_node_removename_iter (dac); }/*
@@ -1178,10 +1236,11 @@ 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, +struct xfs_da_state **state) { -int error; +struct xfs_da_args *args = dac->da_args; +int error; error =xfs_attr_node_hasname (args, state);if (error != -EEXIST )
@@ -1191,6 +1250,12 @@ int xfs_attr_node_removename_setup(ASSERT ((*state)->path.blk[(*state)->path.active -1 ].magic ==XFS_ATTR_LEAF_MAGIC ); +/* +* Store state in the context incase we need to cycle out the +* transaction +*/ + dac->da_state = *state; +if (args->rmtblkno >0 ) { error =xfs_attr_leaf_mark_incomplete (args, *state);if (error)
@@ -1203,13 +1268,16 @@ int xfs_attr_node_removename_setup( } 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;
@@ -1221,21 +1289,27 @@ xfs_attr_node_remove_rmt( }/* -* 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) { -struct xfs_da_state_blk *blk; -int retval, error; -struct xfs_inode *dp = args->dp; +struct xfs_da_args *args = dac->da_args; +struct xfs_da_state *state; +struct xfs_da_state_blk *blk; +int retval, error =0 ; + state = dac->da_state;/* * If there is an out-of-line value, de-allocate the blocks.
@@ -1243,7 +1317,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; }
@@ -1257,21 +1334,18 @@ xfs_attr_node_remove_step(xfs_da3_fixhashpath (state, &state->path);/* -* Check to see if the tree needs to be collapsed. +* Check to see if the tree needs to be collapsed. Set the flag to +* indicate that the calling function needs to move the to shrink +* operation */ 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; + + dac->flags |=XFS_DAC_DEFER_FINISH ; + dac->dela_state =XFS_DAS_RM_SHRINK ; +return -EAGAIN ; }return error;
@@ -1282,31 +1356,53 @@ xfs_attr_node_remove_step(* * This routine will find the blocks of the name to remove, remove them and * shirnk 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; -int error; -struct xfs_inode *dp = args->dp; +struct xfs_da_args *args = dac->da_args; +struct xfs_da_state *state; +int error; +struct xfs_inode *dp = args->dp;trace_xfs_attr_node_removename (args); + state = dac->da_state; - error =xfs_attr_node_removename_setup (args, &state); -if (error) - goto out; +if ((dac->flags &XFS_DAC_NODE_RMVNAME_INIT ) ==0 ) { + dac->flags |=XFS_DAC_NODE_RMVNAME_INIT ; + error =xfs_attr_node_removename_setup (dac, &state); +if (error) + goto out; + } - error =xfs_attr_node_remove_step (args, state); -if (error) - goto out; +switch (dac->dela_state) { +case XFS_DAS_UNINIT : + error =xfs_attr_node_remove_step (dac); +if (error) +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); +/* do not break, proceed to shrink if needed */ +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 ); +return -EINVAL ; + } + +if (error == -EAGAIN ) +return error; out:if (state)xfs_da_state_free (state);
fs/xfs/libxfs/xfs_attr.h +72 -0
84 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 +18 -19
@@ -674,10 +674,12 @@ xfs_attr_rmtval_invalidate(*/ int xfs_attr_rmtval_remove ( -struct xfs_da_args *args) +struct xfs_da_args *args) { -int error; -int retval; +int error; +struct xfs_delattr_context dac = { + .da_args = args, + };trace_xfs_attr_rmtval_remove (args);
@@ -685,19 +687,17 @@ 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 ; -/* -* 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 ); -return 0 ; + }while (true); + +return error; }/*
@@ -707,9 +707,10 @@ xfs_attr_rmtval_remove(*/ int __xfs_attr_rmtval_remove ( -struct xfs_da_args *args) +struct xfs_delattr_context *dac) { -int error, done; +struct xfs_da_args *args = dac->da_args; +int error, done;/* * Unmap value blocks for this attr.
@@ -719,12 +720,10 @@ __xfs_attr_rmtval_remove(if (error)return error; - error =xfs_defer_finish (&args->trans); -if (error) -return error; - -if (!done) +if (!done) { + dac->flags |=XFS_DAC_DEFER_FINISH ;return -EAGAIN ; + }return error; }
fs/xfs/libxfs/xfs_attr_remote.h +1 -1
@@ -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 v13 02/10] xfs: Add delay ready attr remove routines
Quoted 90 lines · IST 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 | 200 +++++++++++++++++++++++++++++----------- fs/xfs/libxfs/xfs_attr.h | 72 +++++++++++++++ fs/xfs/libxfs/xfs_attr_leaf.c | 2 +- fs/xfs/libxfs/xfs_attr_remote.c | 37 ++++---- fs/xfs/libxfs/xfs_attr_remote.h | 2 +- fs/xfs/xfs_attr_inactive.c | 2 +- 6 files changed, 241 insertions(+), 74 deletions(-)fs/xfs/libxfs/xfs_attr.c +28
-1@@ -53,7 +53,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_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);@@ -264,6 +264,33 @@ xfs_attr_set_shortform( }/* +* 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 =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; + } + +return xfs_trans_roll_inode (&args->trans, args->dp); +} + +/* * Set the attribute specified in @args. */ int
fs/xfs/libxfs/xfs_attr.c xfs_has_attr( · line 396
Quoted 9 lines
fs/xfs/libxfs/xfs_attr.c +2
-3@@ -364,23 +391,54 @@ 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 =0 ;
I guess the explicit initialization of "error" can be removed since the value returned by the call to xfs_attr_remove_iter() will overwrite it.
Quoted 233 lines
fs/xfs/libxfs/xfs_attr.c +105
-48+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 (dac->dela_state ==XFS_DAS_RM_SHRINK ) + goto node;if (!xfs_inode_hasattr (dp)) { - error = -ENOATTR ; +return -ENOATTR ; }else if (dp->i_afp->if_format ==XFS_DINODE_FMT_LOCAL ) {ASSERT (dp->i_afp->if_flags &XFS_IFINLINE ); - error =xfs_attr_shortform_remove (args); +return xfs_attr_shortform_remove (args); }else if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) { - error =xfs_attr_leaf_removename (args); - }else { - error =xfs_attr_node_removename (args); +return xfs_attr_leaf_removename (args); } - -return error; +node: +return xfs_attr_node_removename_iter (dac); }/* @@ -1178,10 +1236,11 @@ 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, +struct xfs_da_state **state) { -int error; +struct xfs_da_args *args = dac->da_args; +int error; error =xfs_attr_node_hasname (args, state);if (error != -EEXIST )@@ -1191,6 +1250,12 @@ int xfs_attr_node_removename_setup(ASSERT ((*state)->path.blk[(*state)->path.active -1 ].magic ==XFS_ATTR_LEAF_MAGIC ); +/* +* Store state in the context incase we need to cycle out the +* transaction +*/ + dac->da_state = *state; +if (args->rmtblkno >0 ) { error =xfs_attr_leaf_mark_incomplete (args, *state);if (error)@@ -1203,13 +1268,16 @@ int xfs_attr_node_removename_setup( } 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;@@ -1221,21 +1289,27 @@ xfs_attr_node_remove_rmt( }/* -* 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) { -struct xfs_da_state_blk *blk; -int retval, error; -struct xfs_inode *dp = args->dp; +struct xfs_da_args *args = dac->da_args; +struct xfs_da_state *state; +struct xfs_da_state_blk *blk; +int retval, error =0 ; + state = dac->da_state;/* * If there is an out-of-line value, de-allocate the blocks. @@ -1243,7 +1317,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; }@@ -1257,21 +1334,18 @@ xfs_attr_node_remove_step(xfs_da3_fixhashpath (state, &state->path);/* -* Check to see if the tree needs to be collapsed. +* Check to see if the tree needs to be collapsed. Set the flag to +* indicate that the calling function needs to move the to shrink +* operation */ 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; + + dac->flags |=XFS_DAC_DEFER_FINISH ; + dac->dela_state =XFS_DAS_RM_SHRINK ; +return -EAGAIN ; }return error;@@ -1282,31 +1356,53 @@ xfs_attr_node_remove_step(* * This routine will find the blocks of the name to remove, remove them and * shirnk 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; -int error; -struct xfs_inode *dp = args->dp; +struct xfs_da_args *args = dac->da_args; +struct xfs_da_state *state; +int error; +struct xfs_inode *dp = args->dp;trace_xfs_attr_node_removename (args); + state = dac->da_state; - error =xfs_attr_node_removename_setup (args, &state); -if (error) - goto out; +if ((dac->flags &XFS_DAC_NODE_RMVNAME_INIT ) ==0 ) { + dac->flags |=XFS_DAC_NODE_RMVNAME_INIT ; + error =xfs_attr_node_removename_setup (dac, &state); +if (error) + goto out; + } - error =xfs_attr_node_remove_step (args, state); -if (error) - goto out; +switch (dac->dela_state) { +case XFS_DAS_UNINIT : + error =xfs_attr_node_remove_step (dac); +if (error) +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); +/* do not break, proceed to shrink if needed */ +case XFS_DAS_RM_SHRINK :
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_remove_step( · line 1401
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +9
-0+/* +* 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 ); +return -EINVAL ;
I don't think it is possible in a real world scenario, but if "state" were pointing to allocated memory then the above return value might leak the corresponding memory.
Apart from the above nit, the remaining changes look good to me.
Quoted 215 lines
fs/xfs/libxfs/xfs_attr.c +4
-0+ } + +if (error == -EAGAIN ) +return error; out:if (state)xfs_da_state_free (state);fs/xfs/libxfs/xfs_attr.h +72
-0@@ -74,6 +74,74 @@ struct xfs_attr_list_context { }; +/* +* ======================================================================== +* Structure used to pass context around among the delayed routines. +* ======================================================================== +*/ + +/* +* Below is a state machine diagram for attr remove operations. The XFS_DAS_* +* states indicate places where the function would return -EAGAIN, and then +* immediately resume from after being recalled by the calling function. States +* marked as a "subroutine state" indicate that they belong to a subroutine, and +* so the calling function needs to pass them back to that subroutine to allow +* it to finish where it left off. But they otherwise do not have a role in the +* calling function other than just passing through. +* +* xfs_attr_remove_iter() +* XFS_DAS_RM_SHRINK ─┐ +* (subroutine state) │ +* └─>xfs_attr_node_removename() +* │ +* v +* need to +* shrink tree? ─n─┐ +* │ │ +* y │ +* │ │ +* v │ +* XFS_DAS_RM_SHRINK │ +* │ │ +* v │ +* done <─────┘ +* +*/ + +/* +* Enum values for xfs_delattr_context.da_state +* +* These values are used by delayed attribute operations to keep track of where +* they were before they returned -EAGAIN. A return code of -EAGAIN signals the +* calling function to roll the transaction, and then recall the subroutine to +* finish the operation. The enum is then used by the subroutine to jump back +* to where it was and resume executing where it left off. +*/ +enum xfs_delattr_state { +XFS_DAS_UNINIT =0 ,/* No state has been set yet */ +XFS_DAS_RM_SHRINK ,/* We are shrinking the tree */ +}; + +/* +* Defines for xfs_delattr_context.flags +*/ +#define XFS_DAC_DEFER_FINISH 0x01/* finish the transaction */ +#define XFS_DAC_NODE_RMVNAME_INIT 0x02/* xfs_attr_node_removename init */ + +/* +* Context used for keeping track of delayed attribute operations +*/ +struct xfs_delattr_context { +struct xfs_da_args *da_args; + +/* Used in xfs_attr_node_removename to roll through removing blocks */ +struct xfs_da_state *da_state; + +/* Used to keep track of current state of delayed operation */ +unsigned int flags; +enum xfs_delattr_state dela_state; +}; +/*======================================================================== * Function prototypes for the kernel. *========================================================================*/ @@ -91,6 +159,10 @@ int xfs_attr_set(struct xfs_da_args *args);int xfs_attr_set_args (struct xfs_da_args *args);int xfs_has_attr (struct xfs_da_args *args);int xfs_attr_remove_args (struct xfs_da_args *args); +int xfs_attr_remove_iter (struct xfs_delattr_context *dac); +int xfs_attr_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);#endif /* __XFS_ATTR_H__ */ 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 +18
-19@@ -674,10 +674,12 @@ xfs_attr_rmtval_invalidate(*/ int xfs_attr_rmtval_remove ( -struct xfs_da_args *args) +struct xfs_da_args *args) { -int error; -int retval; +int error; +struct xfs_delattr_context dac = { + .da_args = args, + };trace_xfs_attr_rmtval_remove (args);@@ -685,19 +687,17 @@ 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 ; -/* -* 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 ); -return 0 ; + }while (true); + +return error; }/* @@ -707,9 +707,10 @@ xfs_attr_rmtval_remove(*/ int __xfs_attr_rmtval_remove ( -struct xfs_da_args *args) +struct xfs_delattr_context *dac) { -int error, done; +struct xfs_da_args *args = dac->da_args; +int error, done;/* * Unmap value blocks for this attr. @@ -719,12 +720,10 @@ __xfs_attr_rmtval_remove(if (error)return error; - error =xfs_defer_finish (&args->trans); -if (error) -return error; - -if (!done) +if (!done) { + dac->flags |=XFS_DAC_DEFER_FINISH ;return -EAGAIN ; + }return error; }fs/xfs/libxfs/xfs_attr_remote.h +1
-1@@ -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
chandan
Re: [PATCH v13 02/10] xfs: Add delay ready attr remove routines
Quoted 95 lines · Chandan Babu R
Quoted 94 lines · IST 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 | 200 +++++++++++++++++++++++++++++----------- fs/xfs/libxfs/xfs_attr.h | 72 +++++++++++++++ fs/xfs/libxfs/xfs_attr_leaf.c | 2 +- fs/xfs/libxfs/xfs_attr_remote.c | 37 ++++---- fs/xfs/libxfs/xfs_attr_remote.h | 2 +- fs/xfs/xfs_attr_inactive.c | 2 +- 6 files changed, 241 insertions(+), 74 deletions(-)fs/xfs/libxfs/xfs_attr.c +28
-2@@ -53,7 +53,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_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);@@ -264,6 +264,33 @@ xfs_attr_set_shortform( }/* +* 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 =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; + } + +return xfs_trans_roll_inode (&args->trans, args->dp); +} + +/* * Set the attribute specified in @args. */ int @@ -364,23 +391,54 @@ xfs_has_attr(*/ int xfs_attr_remove_args( -struct xfs_da_args *args)
Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c xfs_has_attr( · line 396
Quoted 5 lines
fs/xfs/libxfs/xfs_attr.c +2
-2+ struct xfs_da_args *args) { -struct xfs_inode *dp = args->dp; -int error; +int error =0 ;I guess the explicit initialization of "error" can be removed since the value returned by the call to
xfs_attr_remove_iter()will overwrite it.
Sure, will fix
Quoted 240 lines
Quoted 240 lines
fs/xfs/libxfs/xfs_attr.c +110
-48+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 (dac->dela_state ==XFS_DAS_RM_SHRINK ) + goto node;if (!xfs_inode_hasattr (dp)) { - error = -ENOATTR ; +return -ENOATTR ; }else if (dp->i_afp->if_format ==XFS_DINODE_FMT_LOCAL ) {ASSERT (dp->i_afp->if_flags &XFS_IFINLINE ); - error =xfs_attr_shortform_remove (args); +return xfs_attr_shortform_remove (args); }else if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) { - error =xfs_attr_leaf_removename (args); - }else { - error =xfs_attr_node_removename (args); +return xfs_attr_leaf_removename (args); } - -return error; +node: +return xfs_attr_node_removename_iter (dac); }/* @@ -1178,10 +1236,11 @@ 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, +struct xfs_da_state **state) { -int error; +struct xfs_da_args *args = dac->da_args; +int error; error =xfs_attr_node_hasname (args, state);if (error != -EEXIST )@@ -1191,6 +1250,12 @@ int xfs_attr_node_removename_setup(ASSERT ((*state)->path.blk[(*state)->path.active -1 ].magic ==XFS_ATTR_LEAF_MAGIC ); +/* +* Store state in the context incase we need to cycle out the +* transaction +*/ + dac->da_state = *state; +if (args->rmtblkno >0 ) { error =xfs_attr_leaf_mark_incomplete (args, *state);if (error)@@ -1203,13 +1268,16 @@ int xfs_attr_node_removename_setup( } 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;@@ -1221,21 +1289,27 @@ xfs_attr_node_remove_rmt( }/* -* 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) { -struct xfs_da_state_blk *blk; -int retval, error; -struct xfs_inode *dp = args->dp; +struct xfs_da_args *args = dac->da_args; +struct xfs_da_state *state; +struct xfs_da_state_blk *blk; +int retval, error =0 ; + state = dac->da_state;/* * If there is an out-of-line value, de-allocate the blocks. @@ -1243,7 +1317,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; }@@ -1257,21 +1334,18 @@ xfs_attr_node_remove_step(xfs_da3_fixhashpath (state, &state->path);/* -* Check to see if the tree needs to be collapsed. +* Check to see if the tree needs to be collapsed. Set the flag to +* indicate that the calling function needs to move the to shrink +* operation */ 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; + + dac->flags |=XFS_DAC_DEFER_FINISH ; + dac->dela_state =XFS_DAS_RM_SHRINK ; +return -EAGAIN ; }return error;@@ -1282,31 +1356,53 @@ xfs_attr_node_remove_step(* * This routine will find the blocks of the name to remove, remove them and * shirnk 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; -int error; -struct xfs_inode *dp = args->dp; +struct xfs_da_args *args = dac->da_args; +struct xfs_da_state *state; +int error; +struct xfs_inode *dp = args->dp;trace_xfs_attr_node_removename (args); + state = dac->da_state; - error =xfs_attr_node_removename_setup (args, &state); -if (error) - goto out; +if ((dac->flags &XFS_DAC_NODE_RMVNAME_INIT ) ==0 ) { + dac->flags |=XFS_DAC_NODE_RMVNAME_INIT ; + error =xfs_attr_node_removename_setup (dac, &state); +if (error) + goto out; + } - error =xfs_attr_node_remove_step (args, state); -if (error) - goto out; +switch (dac->dela_state) { +case XFS_DAS_UNINIT : + error =xfs_attr_node_remove_step (dac); +if (error) +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); +/* do not break, proceed to shrink if needed */ +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);
Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_remove_step( · line 1401
Quoted 4 lines
fs/xfs/libxfs/xfs_attr.c +4
-0+break ; +default : +ASSERT (0 ); +return -EINVAL ;I don't think it is possible in a real world scenario, but if "state" were pointing to allocated memory then the above return value might leak the corresponding memory.
Hmm, trying to follow you here.... I'm assuming you meant dela_state instead of state since that's what controls the switch. The dac structure is zeroed when allocated to avoid this. Most of the time when this switch executes, dela_state is zero. I did have to add the XFS_DAS_UNINIT from the previous suggestion in the last revision though or it generates warnings.
Quoted 2 lines
Apart from the above nit, the remaining changes look good to me.
Ok, thanks for the review!
Allison
Quoted 220 lines
Reviewed-by Chandan Babu R <[email protected]>Quoted 215 lines
fs/xfs/libxfs/xfs_attr.c +4
-0+ } + +if (error == -EAGAIN ) +return error; out:if (state)xfs_da_state_free (state);fs/xfs/libxfs/xfs_attr.h +72
-0@@ -74,6 +74,74 @@ struct xfs_attr_list_context { }; +/* +* ======================================================================== +* Structure used to pass context around among the delayed routines. +* ======================================================================== +*/ + +/* +* Below is a state machine diagram for attr remove operations. The XFS_DAS_* +* states indicate places where the function would return -EAGAIN, and then +* immediately resume from after being recalled by the calling function. States +* marked as a "subroutine state" indicate that they belong to a subroutine, and +* so the calling function needs to pass them back to that subroutine to allow +* it to finish where it left off. But they otherwise do not have a role in the +* calling function other than just passing through. +* +* xfs_attr_remove_iter() +* XFS_DAS_RM_SHRINK ─┐ +* (subroutine state) │ +* └─>xfs_attr_node_removename() +* │ +* v +* need to +* shrink tree? ─n─┐ +* │ │ +* y │ +* │ │ +* v │ +* XFS_DAS_RM_SHRINK │ +* │ │ +* v │ +* done <─────┘ +* +*/ + +/* +* Enum values for xfs_delattr_context.da_state +* +* These values are used by delayed attribute operations to keep track of where +* they were before they returned -EAGAIN. A return code of -EAGAIN signals the +* calling function to roll the transaction, and then recall the subroutine to +* finish the operation. The enum is then used by the subroutine to jump back +* to where it was and resume executing where it left off. +*/ +enum xfs_delattr_state { +XFS_DAS_UNINIT =0 ,/* No state has been set yet */ +XFS_DAS_RM_SHRINK ,/* We are shrinking the tree */ +}; + +/* +* Defines for xfs_delattr_context.flags +*/ +#define XFS_DAC_DEFER_FINISH 0x01/* finish the transaction */ +#define XFS_DAC_NODE_RMVNAME_INIT 0x02/* xfs_attr_node_removename init */ + +/* +* Context used for keeping track of delayed attribute operations +*/ +struct xfs_delattr_context { +struct xfs_da_args *da_args; + +/* Used in xfs_attr_node_removename to roll through removing blocks */ +struct xfs_da_state *da_state; + +/* Used to keep track of current state of delayed operation */ +unsigned int flags; +enum xfs_delattr_state dela_state; +}; +/*======================================================================== * Function prototypes for the kernel. *========================================================================*/ @@ -91,6 +159,10 @@ int xfs_attr_set(struct xfs_da_args *args);int xfs_attr_set_args (struct xfs_da_args *args);int xfs_has_attr (struct xfs_da_args *args);int xfs_attr_remove_args (struct xfs_da_args *args); +int xfs_attr_remove_iter (struct xfs_delattr_context *dac); +int xfs_attr_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);#endif /* __XFS_ATTR_H__ */ 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 +18
-19@@ -674,10 +674,12 @@ xfs_attr_rmtval_invalidate(*/ int xfs_attr_rmtval_remove ( -struct xfs_da_args *args) +struct xfs_da_args *args) { -int error; -int retval; +int error; +struct xfs_delattr_context dac = { + .da_args = args, + };trace_xfs_attr_rmtval_remove (args);@@ -685,19 +687,17 @@ 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 ; -/* -* 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 ); -return 0 ; + }while (true); + +return error; }/* @@ -707,9 +707,10 @@ xfs_attr_rmtval_remove(*/ int __xfs_attr_rmtval_remove ( -struct xfs_da_args *args) +struct xfs_delattr_context *dac) { -int error, done; +struct xfs_da_args *args = dac->da_args; +int error, done;/* * Unmap value blocks for this attr. @@ -719,12 +720,10 @@ __xfs_attr_rmtval_remove(if (error)return error; - error =xfs_defer_finish (&args->trans); -if (error) -return error; - -if (!done) +if (!done) { + dac->flags |=XFS_DAC_DEFER_FINISH ;return -EAGAIN ; + }return error; }fs/xfs/libxfs/xfs_attr_remote.h +1
-1@@ -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"
Re: [PATCH v13 02/10] xfs: Add delay ready attr remove routines
Quoted 354 lines · IST Allison Henderson
Quoted 95 lines · Chandan Babu R
Quoted 94 lines · IST 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 | 200 +++++++++++++++++++++++++++++----------- fs/xfs/libxfs/xfs_attr.h | 72 +++++++++++++++ fs/xfs/libxfs/xfs_attr_leaf.c | 2 +- fs/xfs/libxfs/xfs_attr_remote.c | 37 ++++---- fs/xfs/libxfs/xfs_attr_remote.h | 2 +- fs/xfs/xfs_attr_inactive.c | 2 +- 6 files changed, 241 insertions(+), 74 deletions(-)fs/xfs/libxfs/xfs_attr.c +28
-2@@ -53,7 +53,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_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);@@ -264,6 +264,33 @@ xfs_attr_set_shortform( }/* +* 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 =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; + } + +return xfs_trans_roll_inode (&args->trans, args->dp); +} + +/* * Set the attribute specified in @args. */ int @@ -364,23 +391,54 @@ xfs_has_attr(*/ int xfs_attr_remove_args( -struct xfs_da_args *args)Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c xfs_has_attr( · line 396
Quoted 5 lines
fs/xfs/libxfs/xfs_attr.c +2
-2+ struct xfs_da_args *args) { -struct xfs_inode *dp = args->dp; -int error; +int error =0 ;I guess the explicit initialization of "error" can be removed since the value returned by the call to
xfs_attr_remove_iter()will overwrite it.Sure, will fix
Quoted 240 lines
Quoted 240 lines
fs/xfs/libxfs/xfs_attr.c +110
-48+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 (dac->dela_state ==XFS_DAS_RM_SHRINK ) + goto node;if (!xfs_inode_hasattr (dp)) { - error = -ENOATTR ; +return -ENOATTR ; }else if (dp->i_afp->if_format ==XFS_DINODE_FMT_LOCAL ) {ASSERT (dp->i_afp->if_flags &XFS_IFINLINE ); - error =xfs_attr_shortform_remove (args); +return xfs_attr_shortform_remove (args); }else if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) { - error =xfs_attr_leaf_removename (args); - }else { - error =xfs_attr_node_removename (args); +return xfs_attr_leaf_removename (args); } - -return error; +node: +return xfs_attr_node_removename_iter (dac); }/* @@ -1178,10 +1236,11 @@ 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, +struct xfs_da_state **state) { -int error; +struct xfs_da_args *args = dac->da_args; +int error; error =xfs_attr_node_hasname (args, state);if (error != -EEXIST )@@ -1191,6 +1250,12 @@ int xfs_attr_node_removename_setup(ASSERT ((*state)->path.blk[(*state)->path.active -1 ].magic ==XFS_ATTR_LEAF_MAGIC ); +/* +* Store state in the context incase we need to cycle out the +* transaction +*/ + dac->da_state = *state; +if (args->rmtblkno >0 ) { error =xfs_attr_leaf_mark_incomplete (args, *state);if (error)@@ -1203,13 +1268,16 @@ int xfs_attr_node_removename_setup( } 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;@@ -1221,21 +1289,27 @@ xfs_attr_node_remove_rmt( }/* -* 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) { -struct xfs_da_state_blk *blk; -int retval, error; -struct xfs_inode *dp = args->dp; +struct xfs_da_args *args = dac->da_args; +struct xfs_da_state *state; +struct xfs_da_state_blk *blk; +int retval, error =0 ; + state = dac->da_state;/* * If there is an out-of-line value, de-allocate the blocks. @@ -1243,7 +1317,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; }@@ -1257,21 +1334,18 @@ xfs_attr_node_remove_step(xfs_da3_fixhashpath (state, &state->path);/* -* Check to see if the tree needs to be collapsed. +* Check to see if the tree needs to be collapsed. Set the flag to +* indicate that the calling function needs to move the to shrink +* operation */ 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; + + dac->flags |=XFS_DAC_DEFER_FINISH ; + dac->dela_state =XFS_DAS_RM_SHRINK ; +return -EAGAIN ; }return error;@@ -1282,31 +1356,53 @@ xfs_attr_node_remove_step(* * This routine will find the blocks of the name to remove, remove them and * shirnk 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; -int error; -struct xfs_inode *dp = args->dp; +struct xfs_da_args *args = dac->da_args; +struct xfs_da_state *state; +int error; +struct xfs_inode *dp = args->dp;trace_xfs_attr_node_removename (args); + state = dac->da_state; - error =xfs_attr_node_removename_setup (args, &state); -if (error) - goto out; +if ((dac->flags &XFS_DAC_NODE_RMVNAME_INIT ) ==0 ) { + dac->flags |=XFS_DAC_NODE_RMVNAME_INIT ; + error =xfs_attr_node_removename_setup (dac, &state); +if (error) + goto out; + } - error =xfs_attr_node_remove_step (args, state); -if (error) - goto out; +switch (dac->dela_state) { +case XFS_DAS_UNINIT : + error =xfs_attr_node_remove_step (dac); +if (error) +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); +/* do not break, proceed to shrink if needed */ +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);Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_remove_step( · line 1401
Quoted 4 lines
fs/xfs/libxfs/xfs_attr.c +4
-0+break ; +default : +ASSERT (0 ); +return -EINVAL ;I don't think it is possible in a real world scenario, but if "state" were pointing to allocated memory then the above return value might leak the corresponding memory.
Quoted 7 lines
Hmm, trying to follow you here.... I'm assuming you meant
dela_stateinstead of state since that's what controls the switch. The dac structure is zeroed when allocated to avoid this. Most of the time when this switch executes,dela_stateis zero. I did have to add theXFS_DAS_UNINITfrom the previous suggestion in the last revision though or it generates warnings.Quoted 1 line
Sorry, I should have clarified that I was referring to the allocated memory pointed to by dac->da_state. If dac->da_state was pointing to a valid memory location and dac->dela_state's value is not equal to either XFS_DAS_UNINIT nor XFS_DAS_RM_SHRINK then the code under the "default" clause will execute causing -EINVAL to be returned. This could leak the memory pointed to by dac->da_state.
Quoted 225 lines
Quoted 1 line
Apart from the above nit, the remaining changes look good to me.
Ok, thanks for the review!
AllisonQuoted 220 lines
Reviewed-by Chandan Babu R <[email protected]>Quoted 215 lines
fs/xfs/libxfs/xfs_attr.c +4
-0+ } + +if (error == -EAGAIN ) +return error; out:if (state)xfs_da_state_free (state);fs/xfs/libxfs/xfs_attr.h +72
-0@@ -74,6 +74,74 @@ struct xfs_attr_list_context { }; +/* +* ======================================================================== +* Structure used to pass context around among the delayed routines. +* ======================================================================== +*/ + +/* +* Below is a state machine diagram for attr remove operations. The XFS_DAS_* +* states indicate places where the function would return -EAGAIN, and then +* immediately resume from after being recalled by the calling function. States +* marked as a "subroutine state" indicate that they belong to a subroutine, and +* so the calling function needs to pass them back to that subroutine to allow +* it to finish where it left off. But they otherwise do not have a role in the +* calling function other than just passing through. +* +* xfs_attr_remove_iter() +* XFS_DAS_RM_SHRINK ─┐ +* (subroutine state) │ +* └─>xfs_attr_node_removename() +* │ +* v +* need to +* shrink tree? ─n─┐ +* │ │ +* y │ +* │ │ +* v │ +* XFS_DAS_RM_SHRINK │ +* │ │ +* v │ +* done <─────┘ +* +*/ + +/* +* Enum values for xfs_delattr_context.da_state +* +* These values are used by delayed attribute operations to keep track of where +* they were before they returned -EAGAIN. A return code of -EAGAIN signals the +* calling function to roll the transaction, and then recall the subroutine to +* finish the operation. The enum is then used by the subroutine to jump back +* to where it was and resume executing where it left off. +*/ +enum xfs_delattr_state { +XFS_DAS_UNINIT =0 ,/* No state has been set yet */ +XFS_DAS_RM_SHRINK ,/* We are shrinking the tree */ +}; + +/* +* Defines for xfs_delattr_context.flags +*/ +#define XFS_DAC_DEFER_FINISH 0x01/* finish the transaction */ +#define XFS_DAC_NODE_RMVNAME_INIT 0x02/* xfs_attr_node_removename init */ + +/* +* Context used for keeping track of delayed attribute operations +*/ +struct xfs_delattr_context { +struct xfs_da_args *da_args; + +/* Used in xfs_attr_node_removename to roll through removing blocks */ +struct xfs_da_state *da_state; + +/* Used to keep track of current state of delayed operation */ +unsigned int flags; +enum xfs_delattr_state dela_state; +}; +/*======================================================================== * Function prototypes for the kernel. *========================================================================*/ @@ -91,6 +159,10 @@ int xfs_attr_set(struct xfs_da_args *args);int xfs_attr_set_args (struct xfs_da_args *args);int xfs_has_attr (struct xfs_da_args *args);int xfs_attr_remove_args (struct xfs_da_args *args); +int xfs_attr_remove_iter (struct xfs_delattr_context *dac); +int xfs_attr_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);#endif /* __XFS_ATTR_H__ */ 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 +18
-19@@ -674,10 +674,12 @@ xfs_attr_rmtval_invalidate(*/ int xfs_attr_rmtval_remove ( -struct xfs_da_args *args) +struct xfs_da_args *args) { -int error; -int retval; +int error; +struct xfs_delattr_context dac = { + .da_args = args, + };trace_xfs_attr_rmtval_remove (args);@@ -685,19 +687,17 @@ 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 ; -/* -* 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 ); -return 0 ; + }while (true); + +return error; }/* @@ -707,9 +707,10 @@ xfs_attr_rmtval_remove(*/ int __xfs_attr_rmtval_remove ( -struct xfs_da_args *args) +struct xfs_delattr_context *dac) { -int error, done; +struct xfs_da_args *args = dac->da_args; +int error, done;/* * Unmap value blocks for this attr. @@ -719,12 +720,10 @@ __xfs_attr_rmtval_remove(if (error)return error; - error =xfs_defer_finish (&args->trans); -if (error) -return error; - -if (!done) +if (!done) { + dac->flags |=XFS_DAC_DEFER_FINISH ;return -EAGAIN ; + }return error; }fs/xfs/libxfs/xfs_attr_remote.h +1
-1@@ -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
chandan
Re: [PATCH v13 02/10] xfs: Add delay ready attr remove routines
Quoted 363 lines · Chandan Babu R
Quoted 354 lines · IST Allison Henderson
Quoted 95 lines · Chandan Babu R
Quoted 94 lines · IST 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 | 200 +++++++++++++++++++++++++++++----------- fs/xfs/libxfs/xfs_attr.h | 72 +++++++++++++++ fs/xfs/libxfs/xfs_attr_leaf.c | 2 +- fs/xfs/libxfs/xfs_attr_remote.c | 37 ++++---- fs/xfs/libxfs/xfs_attr_remote.h | 2 +- fs/xfs/xfs_attr_inactive.c | 2 +- 6 files changed, 241 insertions(+), 74 deletions(-)fs/xfs/libxfs/xfs_attr.c +28
-2@@ -53,7 +53,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_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);@@ -264,6 +264,33 @@ xfs_attr_set_shortform( }/* +* 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 =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; + } + +return xfs_trans_roll_inode (&args->trans, args->dp); +} + +/* * Set the attribute specified in @args. */ int @@ -364,23 +391,54 @@ xfs_has_attr(*/ int xfs_attr_remove_args( -struct xfs_da_args *args)Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c xfs_has_attr( · line 396
Quoted 5 lines
fs/xfs/libxfs/xfs_attr.c +2
-2+ struct xfs_da_args *args) { -struct xfs_inode *dp = args->dp; -int error; +int error =0 ;I guess the explicit initialization of "error" can be removed since the value returned by the call to
xfs_attr_remove_iter()will overwrite it.Sure, will fix
Quoted 240 lines
Quoted 240 lines
fs/xfs/libxfs/xfs_attr.c +110
-48+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 (dac->dela_state ==XFS_DAS_RM_SHRINK ) + goto node;if (!xfs_inode_hasattr (dp)) { - error = -ENOATTR ; +return -ENOATTR ; }else if (dp->i_afp->if_format ==XFS_DINODE_FMT_LOCAL ) {ASSERT (dp->i_afp->if_flags &XFS_IFINLINE ); - error =xfs_attr_shortform_remove (args); +return xfs_attr_shortform_remove (args); }else if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) { - error =xfs_attr_leaf_removename (args); - }else { - error =xfs_attr_node_removename (args); +return xfs_attr_leaf_removename (args); } - -return error; +node: +return xfs_attr_node_removename_iter (dac); }/* @@ -1178,10 +1236,11 @@ 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, +struct xfs_da_state **state) { -int error; +struct xfs_da_args *args = dac->da_args; +int error; error =xfs_attr_node_hasname (args, state);if (error != -EEXIST )@@ -1191,6 +1250,12 @@ int xfs_attr_node_removename_setup(ASSERT ((*state)->path.blk[(*state)->path.active -1 ].magic ==XFS_ATTR_LEAF_MAGIC ); +/* +* Store state in the context incase we need to cycle out the +* transaction +*/ + dac->da_state = *state; +if (args->rmtblkno >0 ) { error =xfs_attr_leaf_mark_incomplete (args, *state);if (error)@@ -1203,13 +1268,16 @@ int xfs_attr_node_removename_setup( } 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;@@ -1221,21 +1289,27 @@ xfs_attr_node_remove_rmt( }/* -* 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) { -struct xfs_da_state_blk *blk; -int retval, error; -struct xfs_inode *dp = args->dp; +struct xfs_da_args *args = dac->da_args; +struct xfs_da_state *state; +struct xfs_da_state_blk *blk; +int retval, error =0 ; + state = dac->da_state;/* * If there is an out-of-line value, de-allocate the blocks. @@ -1243,7 +1317,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; }@@ -1257,21 +1334,18 @@ xfs_attr_node_remove_step(xfs_da3_fixhashpath (state, &state->path);/* -* Check to see if the tree needs to be collapsed. +* Check to see if the tree needs to be collapsed. Set the flag to +* indicate that the calling function needs to move the to shrink +* operation */ 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; + + dac->flags |=XFS_DAC_DEFER_FINISH ; + dac->dela_state =XFS_DAS_RM_SHRINK ; +return -EAGAIN ; }return error;@@ -1282,31 +1356,53 @@ xfs_attr_node_remove_step(* * This routine will find the blocks of the name to remove, remove them and * shirnk 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; -int error; -struct xfs_inode *dp = args->dp; +struct xfs_da_args *args = dac->da_args; +struct xfs_da_state *state; +int error; +struct xfs_inode *dp = args->dp;trace_xfs_attr_node_removename (args); + state = dac->da_state; - error =xfs_attr_node_removename_setup (args, &state); -if (error) - goto out; +if ((dac->flags &XFS_DAC_NODE_RMVNAME_INIT ) ==0 ) { + dac->flags |=XFS_DAC_NODE_RMVNAME_INIT ; + error =xfs_attr_node_removename_setup (dac, &state); +if (error) + goto out; + } - error =xfs_attr_node_remove_step (args, state); -if (error) - goto out; +switch (dac->dela_state) { +case XFS_DAS_UNINIT : + error =xfs_attr_node_remove_step (dac); +if (error) +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); +/* do not break, proceed to shrink if needed */ +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);Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_remove_step( · line 1401
Quoted 4 lines
fs/xfs/libxfs/xfs_attr.c +4
-0+break ; +default : +ASSERT (0 ); +return -EINVAL ;I don't think it is possible in a real world scenario, but if "state" were pointing to allocated memory then the above return value might leak the corresponding memory.
Quoted 7 lines
Hmm, trying to follow you here.... I'm assuming you meant
dela_stateinstead of state since that's what controls the switch. The dac structure is zeroed when allocated to avoid this. Most of the time when this switch executes,dela_stateis zero. I did have to add theXFS_DAS_UNINITfrom the previous suggestion in the last revision though or it generates warnings.Quoted 1 line
Quoted 6 lines
Sorry, I should have clarified that I was referring to the allocated memory pointed to by
dac->da_state. Ifdac->da_statewas pointing to a valid memory location and dac->dela_state's value is not equal to eitherXFS_DAS_UNINITnorXFS_DAS_RM_SHRINKthen the code under the "default" clause will execute causing-EINVALto be returned. This could leak the memory pointed to bydac->da_state.
Oooh, ok I see it. We should set error to -EINVAL and goto out. Ideally it should never happen, but that should be the proper error handling if it did. Thanks for the catch :-)
Allison
Quoted 229 lines
Quoted 227 lines
Quoted 3 lines
Apart from the above nit, the remaining changes look good to me.
Ok, thanks for the review!
AllisonQuoted 220 lines
Reviewed-by Chandan Babu R <[email protected]>Quoted 215 lines
fs/xfs/libxfs/xfs_attr.c +4
-0+ } + +if (error == -EAGAIN ) +return error; out:if (state)xfs_da_state_free (state);fs/xfs/libxfs/xfs_attr.h +72
-0@@ -74,6 +74,74 @@ struct xfs_attr_list_context { }; +/* +* ======================================================================== +* Structure used to pass context around among the delayed routines. +* ======================================================================== +*/ + +/* +* Below is a state machine diagram for attr remove operations. The XFS_DAS_* +* states indicate places where the function would return -EAGAIN, and then +* immediately resume from after being recalled by the calling function. States +* marked as a "subroutine state" indicate that they belong to a subroutine, and +* so the calling function needs to pass them back to that subroutine to allow +* it to finish where it left off. But they otherwise do not have a role in the +* calling function other than just passing through. +* +* xfs_attr_remove_iter() +* XFS_DAS_RM_SHRINK ─┐ +* (subroutine state) │ +* └─>xfs_attr_node_removename() +* │ +* v +* need to +* shrink tree? ─n─┐ +* │ │ +* y │ +* │ │ +* v │ +* XFS_DAS_RM_SHRINK │ +* │ │ +* v │ +* done <─────┘ +* +*/ + +/* +* Enum values for xfs_delattr_context.da_state +* +* These values are used by delayed attribute operations to keep track of where +* they were before they returned -EAGAIN. A return code of -EAGAIN signals the +* calling function to roll the transaction, and then recall the subroutine to +* finish the operation. The enum is then used by the subroutine to jump back +* to where it was and resume executing where it left off. +*/ +enum xfs_delattr_state { +XFS_DAS_UNINIT =0 ,/* No state has been set yet */ +XFS_DAS_RM_SHRINK ,/* We are shrinking the tree */ +}; + +/* +* Defines for xfs_delattr_context.flags +*/ +#define XFS_DAC_DEFER_FINISH 0x01/* finish the transaction */ +#define XFS_DAC_NODE_RMVNAME_INIT 0x02/* xfs_attr_node_removename init */ + +/* +* Context used for keeping track of delayed attribute operations +*/ +struct xfs_delattr_context { +struct xfs_da_args *da_args; + +/* Used in xfs_attr_node_removename to roll through removing blocks */ +struct xfs_da_state *da_state; + +/* Used to keep track of current state of delayed operation */ +unsigned int flags; +enum xfs_delattr_state dela_state; +}; +/*======================================================================== * Function prototypes for the kernel. *========================================================================*/ @@ -91,6 +159,10 @@ int xfs_attr_set(struct xfs_da_args *args);int xfs_attr_set_args (struct xfs_da_args *args);int xfs_has_attr (struct xfs_da_args *args);int xfs_attr_remove_args (struct xfs_da_args *args); +int xfs_attr_remove_iter (struct xfs_delattr_context *dac); +int xfs_attr_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);#endif /* __XFS_ATTR_H__ */ 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 +18
-19@@ -674,10 +674,12 @@ xfs_attr_rmtval_invalidate(*/ int xfs_attr_rmtval_remove ( -struct xfs_da_args *args) +struct xfs_da_args *args) { -int error; -int retval; +int error; +struct xfs_delattr_context dac = { + .da_args = args, + };trace_xfs_attr_rmtval_remove (args);@@ -685,19 +687,17 @@ 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 ; -/* -* 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 ); -return 0 ; + }while (true); + +return error; }/* @@ -707,9 +707,10 @@ xfs_attr_rmtval_remove(*/ int __xfs_attr_rmtval_remove ( -struct xfs_da_args *args) +struct xfs_delattr_context *dac) { -int error, done; +struct xfs_da_args *args = dac->da_args; +int error, done;/* * Unmap value blocks for this attr. @@ -719,12 +720,10 @@ __xfs_attr_rmtval_remove(if (error)return error; - error =xfs_defer_finish (&args->trans); -if (error) -return error; - -if (!done) +if (!done) { + dac->flags |=XFS_DAC_DEFER_FINISH ;return -EAGAIN ; + }return error; }fs/xfs/libxfs/xfs_attr_remote.h +1
-1@@ -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"
Re: [PATCH v13 02/10] xfs: Add delay ready attr remove routines
Quoted 355 lines · Allison Henderson
Quoted 345 lines · Chandan Babu R
Quoted 336 lines · IST Allison Henderson
Quoted 94 lines · Chandan Babu R
Quoted 93 lines · IST 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 | 200 +++++++++++++++++++++++++++++----------- fs/xfs/libxfs/xfs_attr.h | 72 +++++++++++++++ fs/xfs/libxfs/xfs_attr_leaf.c | 2 +- fs/xfs/libxfs/xfs_attr_remote.c | 37 ++++---- fs/xfs/libxfs/xfs_attr_remote.h | 2 +- fs/xfs/xfs_attr_inactive.c | 2 +- 6 files changed, 241 insertions(+), 74 deletions(-)fs/xfs/libxfs/xfs_attr.c +28
-2@@ -53,7 +53,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_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);@@ -264,6 +264,33 @@ xfs_attr_set_shortform( }/* +* 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 =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; + } + +return xfs_trans_roll_inode (&args->trans, args->dp); +} + +/* * Set the attribute specified in @args. */ int @@ -364,23 +391,54 @@ xfs_has_attr(*/ int xfs_attr_remove_args( -struct xfs_da_args *args)Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c xfs_has_attr( · line 396
Quoted 5 lines
fs/xfs/libxfs/xfs_attr.c +2
-2+ struct xfs_da_args *args) { -struct xfs_inode *dp = args->dp; -int error; +int error =0 ;I guess the explicit initialization of "error" can be removed since the value returned by the call to
xfs_attr_remove_iter()will overwrite it.Sure, will fix
Quoted 223 lines
Quoted 223 lines
fs/xfs/libxfs/xfs_attr.c +110
-48+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 (dac->dela_state ==XFS_DAS_RM_SHRINK ) + goto node;if (!xfs_inode_hasattr (dp)) { - error = -ENOATTR ; +return -ENOATTR ; }else if (dp->i_afp->if_format ==XFS_DINODE_FMT_LOCAL ) {ASSERT (dp->i_afp->if_flags &XFS_IFINLINE ); - error =xfs_attr_shortform_remove (args); +return xfs_attr_shortform_remove (args); }else if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) { - error =xfs_attr_leaf_removename (args); - }else { - error =xfs_attr_node_removename (args); +return xfs_attr_leaf_removename (args); } - -return error; +node: +return xfs_attr_node_removename_iter (dac); }/* @@ -1178,10 +1236,11 @@ 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, +struct xfs_da_state **state) { -int error; +struct xfs_da_args *args = dac->da_args; +int error; error =xfs_attr_node_hasname (args, state);if (error != -EEXIST )@@ -1191,6 +1250,12 @@ int xfs_attr_node_removename_setup(ASSERT ((*state)->path.blk[(*state)->path.active -1 ].magic ==XFS_ATTR_LEAF_MAGIC ); +/* +* Store state in the context incase we need to cycle out the +* transaction +*/ + dac->da_state = *state; +if (args->rmtblkno >0 ) { error =xfs_attr_leaf_mark_incomplete (args, *state);if (error)@@ -1203,13 +1268,16 @@ int xfs_attr_node_removename_setup( } 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;@@ -1221,21 +1289,27 @@ xfs_attr_node_remove_rmt( }/* -* 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) { -struct xfs_da_state_blk *blk; -int retval, error; -struct xfs_inode *dp = args->dp; +struct xfs_da_args *args = dac->da_args; +struct xfs_da_state *state; +struct xfs_da_state_blk *blk; +int retval, error =0 ; + state = dac->da_state;/* * If there is an out-of-line value, de-allocate the blocks. @@ -1243,7 +1317,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; }@@ -1257,21 +1334,18 @@ xfs_attr_node_remove_step(xfs_da3_fixhashpath (state, &state->path);/* -* Check to see if the tree needs to be collapsed. +* Check to see if the tree needs to be collapsed. Set the flag to +* indicate that the calling function needs to move the to shrink +* operation */ 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; + + dac->flags |=XFS_DAC_DEFER_FINISH ; + dac->dela_state =XFS_DAS_RM_SHRINK ; +return -EAGAIN ; }return error;@@ -1282,31 +1356,53 @@ xfs_attr_node_remove_step(* * This routine will find the blocks of the name to remove, remove them and * shirnk 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; -int error; -struct xfs_inode *dp = args->dp; +struct xfs_da_args *args = dac->da_args; +struct xfs_da_state *state; +int error; +struct xfs_inode *dp = args->dp;trace_xfs_attr_node_removename (args); + state = dac->da_state; - error =xfs_attr_node_removename_setup (args, &state); -if (error) - goto out; +if ((dac->flags &XFS_DAC_NODE_RMVNAME_INIT ) ==0 ) { + dac->flags |=XFS_DAC_NODE_RMVNAME_INIT ; + error =xfs_attr_node_removename_setup (dac, &state); +if (error) + goto out; + } - error =xfs_attr_node_remove_step (args, state); -if (error) - goto out; +switch (dac->dela_state) { +case XFS_DAS_UNINIT : + error =xfs_attr_node_remove_step (dac); +if (error) +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); +/* do not break, proceed to shrink if needed */ +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);Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_remove_step( · line 1401
Quoted 4 lines
fs/xfs/libxfs/xfs_attr.c +4
-0+break ; +default : +ASSERT (0 ); +return -EINVAL ;I don't think it is possible in a real world scenario, but if "state" were pointing to allocated memory then the above return value might leak the corresponding memory.
Quoted 7 lines
Hmm, trying to follow you here.... I'm assuming you meant
dela_stateinstead of state since that's what controls the switch. The dac structure is zeroed when allocated to avoid this. Most of the time when this switch executes,dela_stateis zero. I did have to add theXFS_DAS_UNINITfrom the previous suggestion in the last revision though or it generates warnings.Quoted 1 line
Quoted 6 lines
Sorry, I should have clarified that I was referring to the allocated memory pointed to by
dac->da_state. Ifdac->da_statewas pointing to a valid memory location and dac->dela_state's value is not equal to eitherXFS_DAS_UNINITnorXFS_DAS_RM_SHRINKthen the code under the "default" clause will execute causing-EINVALto be returned. This could leak the memory pointed to bydac->da_state.
Quoted 3 lines
Oooh, ok I see it. We should set error to
-EINVALand goto out. Ideally it should never happen, but that should be the proper error handling if it did. Thanks for the catch :-)
kmemleak and kasan are your friend! :)
Also, if you combine dela_context and xfs_attr_item then it'll be nice to combine all that into the attr item destructor.
--D
Quoted 219 lines
Allison
Quoted 218 lines
Quoted 216 lines
Quoted 3 lines
Apart from the above nit, the remaining changes look good to me.
Ok, thanks for the review!
AllisonQuoted 209 lines
Reviewed-by Chandan Babu R <[email protected]>Quoted 204 lines
fs/xfs/libxfs/xfs_attr.c +4
-0+ } + +if (error == -EAGAIN ) +return error; out:if (state)xfs_da_state_free (state);fs/xfs/libxfs/xfs_attr.h +72
-0@@ -74,6 +74,74 @@ struct xfs_attr_list_context { }; +/* +* ======================================================================== +* Structure used to pass context around among the delayed routines. +* ======================================================================== +*/ + +/* +* Below is a state machine diagram for attr remove operations. The XFS_DAS_* +* states indicate places where the function would return -EAGAIN, and then +* immediately resume from after being recalled by the calling function. States +* marked as a "subroutine state" indicate that they belong to a subroutine, and +* so the calling function needs to pass them back to that subroutine to allow +* it to finish where it left off. But they otherwise do not have a role in the +* calling function other than just passing through. +* +* xfs_attr_remove_iter() +* XFS_DAS_RM_SHRINK ─┐ +* (subroutine state) │ +* └─>xfs_attr_node_removename() +* │ +* v +* need to +* shrink tree? ─n─┐ +* │ │ +* y │ +* │ │ +* v │ +* XFS_DAS_RM_SHRINK │ +* │ │ +* v │ +* done <─────┘ +* +*/ + +/* +* Enum values for xfs_delattr_context.da_state +* +* These values are used by delayed attribute operations to keep track of where +* they were before they returned -EAGAIN. A return code of -EAGAIN signals the +* calling function to roll the transaction, and then recall the subroutine to +* finish the operation. The enum is then used by the subroutine to jump back +* to where it was and resume executing where it left off. +*/ +enum xfs_delattr_state { +XFS_DAS_UNINIT =0 ,/* No state has been set yet */ +XFS_DAS_RM_SHRINK ,/* We are shrinking the tree */ +}; + +/* +* Defines for xfs_delattr_context.flags +*/ +#define XFS_DAC_DEFER_FINISH 0x01/* finish the transaction */ +#define XFS_DAC_NODE_RMVNAME_INIT 0x02/* xfs_attr_node_removename init */ + +/* +* Context used for keeping track of delayed attribute operations +*/ +struct xfs_delattr_context { +struct xfs_da_args *da_args; + +/* Used in xfs_attr_node_removename to roll through removing blocks */ +struct xfs_da_state *da_state; + +/* Used to keep track of current state of delayed operation */ +unsigned int flags; +enum xfs_delattr_state dela_state; +}; +/*======================================================================== * Function prototypes for the kernel. *========================================================================*/ @@ -91,6 +159,10 @@ int xfs_attr_set(struct xfs_da_args *args);int xfs_attr_set_args (struct xfs_da_args *args);int xfs_has_attr (struct xfs_da_args *args);int xfs_attr_remove_args (struct xfs_da_args *args); +int xfs_attr_remove_iter (struct xfs_delattr_context *dac); +int xfs_attr_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);#endif /* __XFS_ATTR_H__ */ 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 +18
-19@@ -674,10 +674,12 @@ xfs_attr_rmtval_invalidate(*/ int xfs_attr_rmtval_remove ( -struct xfs_da_args *args) +struct xfs_da_args *args) { -int error; -int retval; +int error; +struct xfs_delattr_context dac = { + .da_args = args, + };trace_xfs_attr_rmtval_remove (args);@@ -685,19 +687,17 @@ 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 ; -/* -* 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 ); -return 0 ; + }while (true); + +return error; }/* @@ -707,9 +707,10 @@ xfs_attr_rmtval_remove(*/ int __xfs_attr_rmtval_remove ( -struct xfs_da_args *args) +struct xfs_delattr_context *dac) { -int error, done; +struct xfs_da_args *args = dac->da_args; +int error, done;/* * Unmap value blocks for this attr. @@ -719,12 +720,10 @@ __xfs_attr_rmtval_remove(if (error)return error; - error =xfs_defer_finish (&args->trans); -if (error) -return error; - -if (!done) +if (!done) { + dac->flags |=XFS_DAC_DEFER_FINISH ;return -EAGAIN ; + }return error; }fs/xfs/libxfs/xfs_attr_remote.h +1
-1@@ -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"
Re: [PATCH v13 02/10] xfs: Add delay ready attr remove routines
In reply to Allison HendersonQuoted 72 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 | 200 +++++++++++++++++++++++++++++----------- fs/xfs/libxfs/xfs_attr.h | 72 +++++++++++++++ fs/xfs/libxfs/xfs_attr_leaf.c | 2 +- fs/xfs/libxfs/xfs_attr_remote.c | 37 ++++---- fs/xfs/libxfs/xfs_attr_remote.h | 2 +- fs/xfs/xfs_attr_inactive.c | 2 +- 6 files changed, 241 insertions(+), 74 deletions(-)fs/xfs/libxfs/xfs_attr.c +14
-1@@ -53,7 +53,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_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);@@ -264,6 +264,33 @@ xfs_attr_set_shortform( }/* +* 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 =0 ; + +if (dac->flags &XFS_DAC_DEFER_FINISH ) { +/*
fs/xfs/libxfs/xfs_attr.c xfs_attr_set_shortform( · line 289
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10
-0+* 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; + } +
It seems like some comments on the previous version weren't addressed. I.e., the spurious transaction roll here when a dfops finish occurs..?
Quoted 101 lines
fs/xfs/libxfs/xfs_attr.c +55
-13+return xfs_trans_roll_inode (&args->trans, args->dp); +} + +/* * Set the attribute specified in @args. */ int @@ -364,23 +391,54 @@ 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 =0 ; +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 (dac->dela_state ==XFS_DAS_RM_SHRINK ) + goto node;if (!xfs_inode_hasattr (dp)) { - error = -ENOATTR ; +return -ENOATTR ; }else if (dp->i_afp->if_format ==XFS_DINODE_FMT_LOCAL ) {ASSERT (dp->i_afp->if_flags &XFS_IFINLINE ); - error =xfs_attr_shortform_remove (args); +return xfs_attr_shortform_remove (args); }else if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) { - error =xfs_attr_leaf_removename (args); - }else { - error =xfs_attr_node_removename (args); +return xfs_attr_leaf_removename (args); } - -return error; +node: +return xfs_attr_node_removename_iter (dac); }/* @@ -1178,10 +1236,11 @@ 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, +struct xfs_da_state **state) { -int error; +struct xfs_da_args *args = dac->da_args; +int error; error =xfs_attr_node_hasname (args, state);if (error != -EEXIST )@@ -1191,6 +1250,12 @@ int xfs_attr_node_removename_setup(ASSERT ((*state)->path.blk[(*state)->path.active -1 ].magic ==XFS_ATTR_LEAF_MAGIC ); +/* +* Store state in the context incase we need to cycle out the +* transaction +*/ + dac->da_state = *state; +if (args->rmtblkno >0 ) { error =xfs_attr_leaf_mark_incomplete (args, *state);if (error)
fs/xfs/libxfs/xfs_attr.c int xfs_attr_node_removename_setup( · line 1271
Quoted 7 lines
fs/xfs/libxfs/xfs_attr.c +1
-3@@ -1203,13 +1268,16 @@ int xfs_attr_node_removename_setup( } STATIC int -xfs_attr_node_remove_rmt ( -struct xfs_da_args *args, -struct xfs_da_state *state) +xfs_attr_node_remove_rmt (
Extra space ^
Quoted 125 lines
fs/xfs/libxfs/xfs_attr.c +48
-27+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;@@ -1221,21 +1289,27 @@ xfs_attr_node_remove_rmt( }/* -* 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) { -struct xfs_da_state_blk *blk; -int retval, error; -struct xfs_inode *dp = args->dp; +struct xfs_da_args *args = dac->da_args; +struct xfs_da_state *state; +struct xfs_da_state_blk *blk; +int retval, error =0 ; + state = dac->da_state;/* * If there is an out-of-line value, de-allocate the blocks. @@ -1243,7 +1317,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; }@@ -1257,21 +1334,18 @@ xfs_attr_node_remove_step(xfs_da3_fixhashpath (state, &state->path);/* -* Check to see if the tree needs to be collapsed. +* Check to see if the tree needs to be collapsed. Set the flag to +* indicate that the calling function needs to move the to shrink +* operation */ 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; + + dac->flags |=XFS_DAC_DEFER_FINISH ; + dac->dela_state =XFS_DAS_RM_SHRINK ; +return -EAGAIN ; }return error;@@ -1282,31 +1356,53 @@ xfs_attr_node_remove_step(* * This routine will find the blocks of the name to remove, remove them and * shirnk 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; -int error; -struct xfs_inode *dp = args->dp; +struct xfs_da_args *args = dac->da_args; +struct xfs_da_state *state; +int error; +struct xfs_inode *dp = args->dp;trace_xfs_attr_node_removename (args); + state = dac->da_state; - error =xfs_attr_node_removename_setup (args, &state); -if (error) - goto out; +if ((dac->flags &XFS_DAC_NODE_RMVNAME_INIT ) ==0 ) { + dac->flags |=XFS_DAC_NODE_RMVNAME_INIT ; + error =xfs_attr_node_removename_setup (dac, &state); +if (error) + goto out; + }
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_remove_step( · line 1389
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +5
-3- error =xfs_attr_node_remove_step (args, state); -if (error) - goto out; +switch (dac->dela_state) { +case XFS_DAS_UNINIT : + error =xfs_attr_node_remove_step (dac); +if (error) +break ;
I think there's a bit more preliminary refactoring to do here to isolate the state management to this one function. I.e., from the discussion on the previous version, we'd ideally pull the logic that checks for the subsequent shrink state out of xfs_attr_node_remove_step() and lift it into this branch. See the pseudocode in the previous discussion for an example of what I mean:
https://lore.kernel.org/linux-xfs/20200901170020.GC174813@bfoster/
The general goal of that is to refactor the existing code such that all of the state transitions and whatnot are shown in one place and the rest is broken down into smaller functional helpers.
Brian
Quoted 234 lines
fs/xfs/libxfs/xfs_attr.c +15
-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); +/* do not break, proceed to shrink if needed */ +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 ); +return -EINVAL ; + } + +if (error == -EAGAIN ) +return error; out:if (state)xfs_da_state_free (state);fs/xfs/libxfs/xfs_attr.h +72
-0@@ -74,6 +74,74 @@ struct xfs_attr_list_context { }; +/* +* ======================================================================== +* Structure used to pass context around among the delayed routines. +* ======================================================================== +*/ + +/* +* Below is a state machine diagram for attr remove operations. The XFS_DAS_* +* states indicate places where the function would return -EAGAIN, and then +* immediately resume from after being recalled by the calling function. States +* marked as a "subroutine state" indicate that they belong to a subroutine, and +* so the calling function needs to pass them back to that subroutine to allow +* it to finish where it left off. But they otherwise do not have a role in the +* calling function other than just passing through. +* +* xfs_attr_remove_iter() +* XFS_DAS_RM_SHRINK ─┐ +* (subroutine state) │ +* └─>xfs_attr_node_removename() +* │ +* v +* need to +* shrink tree? ─n─┐ +* │ │ +* y │ +* │ │ +* v │ +* XFS_DAS_RM_SHRINK │ +* │ │ +* v │ +* done <─────┘ +* +*/ + +/* +* Enum values for xfs_delattr_context.da_state +* +* These values are used by delayed attribute operations to keep track of where +* they were before they returned -EAGAIN. A return code of -EAGAIN signals the +* calling function to roll the transaction, and then recall the subroutine to +* finish the operation. The enum is then used by the subroutine to jump back +* to where it was and resume executing where it left off. +*/ +enum xfs_delattr_state { +XFS_DAS_UNINIT =0 ,/* No state has been set yet */ +XFS_DAS_RM_SHRINK ,/* We are shrinking the tree */ +}; + +/* +* Defines for xfs_delattr_context.flags +*/ +#define XFS_DAC_DEFER_FINISH 0x01/* finish the transaction */ +#define XFS_DAC_NODE_RMVNAME_INIT 0x02/* xfs_attr_node_removename init */ + +/* +* Context used for keeping track of delayed attribute operations +*/ +struct xfs_delattr_context { +struct xfs_da_args *da_args; + +/* Used in xfs_attr_node_removename to roll through removing blocks */ +struct xfs_da_state *da_state; + +/* Used to keep track of current state of delayed operation */ +unsigned int flags; +enum xfs_delattr_state dela_state; +}; +/*======================================================================== * Function prototypes for the kernel. *========================================================================*/ @@ -91,6 +159,10 @@ int xfs_attr_set(struct xfs_da_args *args);int xfs_attr_set_args (struct xfs_da_args *args);int xfs_has_attr (struct xfs_da_args *args);int xfs_attr_remove_args (struct xfs_da_args *args); +int xfs_attr_remove_iter (struct xfs_delattr_context *dac); +int xfs_attr_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);#endif /* __XFS_ATTR_H__ */ 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 +18
-19@@ -674,10 +674,12 @@ xfs_attr_rmtval_invalidate(*/ int xfs_attr_rmtval_remove ( -struct xfs_da_args *args) +struct xfs_da_args *args) { -int error; -int retval; +int error; +struct xfs_delattr_context dac = { + .da_args = args, + };trace_xfs_attr_rmtval_remove (args);@@ -685,19 +687,17 @@ 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 ; -/* -* 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 ); -return 0 ; + }while (true); + +return error; }/* @@ -707,9 +707,10 @@ xfs_attr_rmtval_remove(*/ int __xfs_attr_rmtval_remove ( -struct xfs_da_args *args) +struct xfs_delattr_context *dac) { -int error, done; +struct xfs_da_args *args = dac->da_args; +int error, done;/* * Unmap value blocks for this attr. @@ -719,12 +720,10 @@ __xfs_attr_rmtval_remove(if (error)return error; - error =xfs_defer_finish (&args->trans); -if (error) -return error; - -if (!done) +if (!done) { + dac->flags |=XFS_DAC_DEFER_FINISH ;return -EAGAIN ; + }return error; }fs/xfs/libxfs/xfs_attr_remote.h +1
-1@@ -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 v13 02/10] xfs: Add delay ready attr remove routines
Quoted 78 lines · Brian Foster
Quoted 77 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 | 200 +++++++++++++++++++++++++++++----------- fs/xfs/libxfs/xfs_attr.h | 72 +++++++++++++++ fs/xfs/libxfs/xfs_attr_leaf.c | 2 +- fs/xfs/libxfs/xfs_attr_remote.c | 37 ++++---- fs/xfs/libxfs/xfs_attr_remote.h | 2 +- fs/xfs/xfs_attr_inactive.c | 2 +- 6 files changed, 241 insertions(+), 74 deletions(-)fs/xfs/libxfs/xfs_attr.c +19
-1@@ -53,7 +53,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_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);@@ -264,6 +264,33 @@ xfs_attr_set_shortform( }/* +* 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 =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 ;
Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_set_shortform( · line 289
Quoted 5 lines
fs/xfs/libxfs/xfs_attr.c +5
-0+ error =xfs_defer_finish (&args->trans); +if (error) +return error; + } +It seems like some comments on the previous version weren't addressed. I.e., the spurious transaction roll here when a dfops finish occurs..?
Ok, I got the impression from the last review that we wanted most of this looping mechanism to go away, so most of the changes in this set are focused there, and forgot to come back and touch this up. Most of this code disappears in patch 9 now though. I wasnt really sure what people would think of it just yet, so I left that as a patch and the end of the series in case people had different thoughts after seeing the implementation.
Quoted 104 lines
Quoted 104 lines
fs/xfs/libxfs/xfs_attr.c +55
-13+return xfs_trans_roll_inode (&args->trans, args->dp); +} + +/* * Set the attribute specified in @args. */ int @@ -364,23 +391,54 @@ 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 =0 ; +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 (dac->dela_state ==XFS_DAS_RM_SHRINK ) + goto node;if (!xfs_inode_hasattr (dp)) { - error = -ENOATTR ; +return -ENOATTR ; }else if (dp->i_afp->if_format ==XFS_DINODE_FMT_LOCAL ) {ASSERT (dp->i_afp->if_flags &XFS_IFINLINE ); - error =xfs_attr_shortform_remove (args); +return xfs_attr_shortform_remove (args); }else if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) { - error =xfs_attr_leaf_removename (args); - }else { - error =xfs_attr_node_removename (args); +return xfs_attr_leaf_removename (args); } - -return error; +node: +return xfs_attr_node_removename_iter (dac); }/* @@ -1178,10 +1236,11 @@ 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, +struct xfs_da_state **state) { -int error; +struct xfs_da_args *args = dac->da_args; +int error; error =xfs_attr_node_hasname (args, state);if (error != -EEXIST )@@ -1191,6 +1250,12 @@ int xfs_attr_node_removename_setup(ASSERT ((*state)->path.blk[(*state)->path.active -1 ].magic ==XFS_ATTR_LEAF_MAGIC ); +/* +* Store state in the context incase we need to cycle out the +* transaction +*/ + dac->da_state = *state; +if (args->rmtblkno >0 ) { error =xfs_attr_leaf_mark_incomplete (args, *state);if (error)@@ -1203,13 +1268,16 @@ int xfs_attr_node_removename_setup( }
Quoted 7 lines
fs/xfs/libxfs/xfs_attr.c int xfs_attr_node_removename_setup( · line 1271
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 space ^
Ok will fix
Quoted 144 lines
Quoted 126 lines
fs/xfs/libxfs/xfs_attr.c +48
-27+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;@@ -1221,21 +1289,27 @@ xfs_attr_node_remove_rmt( }/* -* 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) { -struct xfs_da_state_blk *blk; -int retval, error; -struct xfs_inode *dp = args->dp; +struct xfs_da_args *args = dac->da_args; +struct xfs_da_state *state; +struct xfs_da_state_blk *blk; +int retval, error =0 ; + state = dac->da_state;/* * If there is an out-of-line value, de-allocate the blocks. @@ -1243,7 +1317,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; }@@ -1257,21 +1334,18 @@ xfs_attr_node_remove_step(xfs_da3_fixhashpath (state, &state->path);/* -* Check to see if the tree needs to be collapsed. +* Check to see if the tree needs to be collapsed. Set the flag to +* indicate that the calling function needs to move the to shrink +* operation */ 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; + + dac->flags |=XFS_DAC_DEFER_FINISH ; + dac->dela_state =XFS_DAS_RM_SHRINK ; +return -EAGAIN ; }return error;@@ -1282,31 +1356,53 @@ xfs_attr_node_remove_step(* * This routine will find the blocks of the name to remove, remove them and * shirnk 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; -int error; -struct xfs_inode *dp = args->dp; +struct xfs_da_args *args = dac->da_args; +struct xfs_da_state *state; +int error; +struct xfs_inode *dp = args->dp;trace_xfs_attr_node_removename (args); + state = dac->da_state; - error =xfs_attr_node_removename_setup (args, &state); -if (error) - goto out; +if ((dac->flags &XFS_DAC_NODE_RMVNAME_INIT ) ==0 ) { + dac->flags |=XFS_DAC_NODE_RMVNAME_INIT ; + error =xfs_attr_node_removename_setup (dac, &state); +if (error) + goto out; + }fs/xfs/libxfs/xfs_attr.c xfs_attr_node_remove_step( · line 1389
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +5
-3- error =xfs_attr_node_remove_step (args, state); -if (error) - goto out; +switch (dac->dela_state) { +case XFS_DAS_UNINIT : + error =xfs_attr_node_remove_step (dac); +if (error) +break ;I think there's a bit more preliminary refactoring to do here to isolate the state management to this one function. I.e., from the discussion on the previous version, we'd ideally pull the logic that checks for the subsequent shrink state out of
xfs_attr_node_remove_step()and lift it into this branch. See the pseudocode in the previous discussion for an example of what I mean:
Quoted 7 lines
https://urldefense.com/v3/__https://lore.kernel.org/linux-xfs/20200901170020.GC174813@bfoster/__;!!GqivPVa7Brio!JKxU3Z07HVj0V1YFesXrveRWnoGuWqiTZuaIDiG9UFmSxz-aFGsZPpLtjIOjSht7WL_h$The general goal of that is to refactor the existing code such that all of the state transitions and whatnot are shown in one place and the rest is broken down into smaller functional helpers.
Brian
Yes, I did see the pseudo code, though I wasnt able to get it through the test cases quite the way it appears. Because whether or not we proceed to shrink is determined by the leaf remove that's burried in the step function. Otherwise we run into some failed asserts in the shrink routines for "state->path.active == 1". Alternatly we can add another helper to pull it up to this scope. Then the switch ends up looking like this:
switch (dac->dela_state) {
case XFS_DAS_UNINIT:
/*
* repeatedly remove remote blocks, remove the entry
and
* join. returns -EAGAIN or 0 for completion of the
step.
*/
error = xfs_attr_node_remove_step(dac);
if (error)
break;
retval = xfs_attr_node_remove_cleanup(dac);
/*
* Check to see if the tree needs to be collapsed. Set
the flag to
* indicate that the calling function needs to move the
to shrink
* operation
*/
if (retval && (state->path.active > 1)) {
error = xfs_da3_join(state);
if (error)
return error;
dac->dela_state = XFS_DAS_RM_SHRINK;
return -EAGAIN;
}
/* check whether to shrink or return success */
if (!error && xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
dac->dela_state = XFS_DAS_RM_SHRINK;
error = -EAGAIN;
}
break;
case XFS_DAS_RM_SHRINK:
/*
* If the result is small enough, push it all into the
inode.
*/
error = xfs_attr_node_shrink(args, state);
break;
default:
ASSERT(0);
return -EINVAL;
}
if (error == -EAGAIN)
return error;And then we have this little clean up helper that we pull out of remove_step:
STATIC int
xfs_attr_node_remove_cleanup(
struct xfs_delattr_context *dac)
{
struct xfs_da_args *args = dac->da_args;
struct xfs_da_state_blk *blk;
int retval;
/*
* Remove the name and update the hashvals in the tree.
*/
blk = &dac->da_state->path.blk[ dac->da_state->path.active-1 ];
ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
retval = xfs_attr3_leaf_remove(blk->bp, args);
xfs_da3_fixhashpath(dac->da_state, &dac->da_state->path);
return retval; }
This configuration seems to get through the test cases. It's not quite as tidy, but it does get all the state handling into this scope. If people prefer it this way I can add in the extra helper and make these adjustments?
Allison
Quoted 236 lines
Quoted 235 lines
fs/xfs/libxfs/xfs_attr.c +15
-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); +/* do not break, proceed to shrink if needed */ +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 ); +return -EINVAL ; + } + +if (error == -EAGAIN ) +return error; out:if (state)xfs_da_state_free (state);fs/xfs/libxfs/xfs_attr.h +72
-0@@ -74,6 +74,74 @@ struct xfs_attr_list_context { }; +/* +* ======================================================================== +* Structure used to pass context around among the delayed routines. +* ======================================================================== +*/ + +/* +* Below is a state machine diagram for attr remove operations. The XFS_DAS_* +* states indicate places where the function would return -EAGAIN, and then +* immediately resume from after being recalled by the calling function. States +* marked as a "subroutine state" indicate that they belong to a subroutine, and +* so the calling function needs to pass them back to that subroutine to allow +* it to finish where it left off. But they otherwise do not have a role in the +* calling function other than just passing through. +* +* xfs_attr_remove_iter() +* XFS_DAS_RM_SHRINK ─┐ +* (subroutine state) │ +* └─>xfs_attr_node_removename() +* │ +* v +* need to +* shrink tree? ─n─┐ +* │ │ +* y │ +* │ │ +* v │ +* XFS_DAS_RM_SHRINK │ +* │ │ +* v │ +* done <─────┘ +* +*/ + +/* +* Enum values for xfs_delattr_context.da_state +* +* These values are used by delayed attribute operations to keep track of where +* they were before they returned -EAGAIN. A return code of -EAGAIN signals the +* calling function to roll the transaction, and then recall the subroutine to +* finish the operation. The enum is then used by the subroutine to jump back +* to where it was and resume executing where it left off. +*/ +enum xfs_delattr_state { +XFS_DAS_UNINIT =0 ,/* No state has been set yet */ +XFS_DAS_RM_SHRINK ,/* We are shrinking the tree */ +}; + +/* +* Defines for xfs_delattr_context.flags +*/ +#define XFS_DAC_DEFER_FINISH 0x01/* finish the transaction */ +#define XFS_DAC_NODE_RMVNAME_INIT 0x02/* xfs_attr_node_removename init */ + +/* +* Context used for keeping track of delayed attribute operations +*/ +struct xfs_delattr_context { +struct xfs_da_args *da_args; + +/* Used in xfs_attr_node_removename to roll through removing blocks */ +struct xfs_da_state *da_state; + +/* Used to keep track of current state of delayed operation */ +unsigned int flags; +enum xfs_delattr_state dela_state; +}; +/*======================================================================== * Function prototypes for the kernel. *========================================================================*/ @@ -91,6 +159,10 @@ int xfs_attr_set(struct xfs_da_args *args);int xfs_attr_set_args (struct xfs_da_args *args);int xfs_has_attr (struct xfs_da_args *args);int xfs_attr_remove_args (struct xfs_da_args *args); +int xfs_attr_remove_iter (struct xfs_delattr_context *dac); +int xfs_attr_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);#endif /* __XFS_ATTR_H__ */ 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 +18
-19@@ -674,10 +674,12 @@ xfs_attr_rmtval_invalidate(*/ int xfs_attr_rmtval_remove ( -struct xfs_da_args *args) +struct xfs_da_args *args) { -int error; -int retval; +int error; +struct xfs_delattr_context dac = { + .da_args = args, + };trace_xfs_attr_rmtval_remove (args);@@ -685,19 +687,17 @@ 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 ; -/* -* 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 ); -return 0 ; + }while (true); + +return error; }/* @@ -707,9 +707,10 @@ xfs_attr_rmtval_remove(*/ int __xfs_attr_rmtval_remove ( -struct xfs_da_args *args) +struct xfs_delattr_context *dac) { -int error, done; +struct xfs_da_args *args = dac->da_args; +int error, done;/* * Unmap value blocks for this attr. @@ -719,12 +720,10 @@ __xfs_attr_rmtval_remove(if (error)return error; - error =xfs_defer_finish (&args->trans); -if (error) -return error; - -if (!done) +if (!done) { + dac->flags |=XFS_DAC_DEFER_FINISH ;return -EAGAIN ; + }return error; }fs/xfs/libxfs/xfs_attr_remote.h +1
-1@@ -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 v13 02/10] 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 | 200 +++++++++++++++++++++++++++++----------- fs/xfs/libxfs/xfs_attr.h | 72 +++++++++++++++ fs/xfs/libxfs/xfs_attr_leaf.c | 2 +- fs/xfs/libxfs/xfs_attr_remote.c | 37 ++++---- fs/xfs/libxfs/xfs_attr_remote.h | 2 +- fs/xfs/xfs_attr_inactive.c | 2 +- 6 files changed, 241 insertions(+), 74 deletions(-)fs/xfs/libxfs/xfs_attr.c +0
-0
...
Quoted 56 lines
Quoted 56 lines
Quoted 32 lines
fs/xfs/libxfs/xfs_attr.c +16
-8@@ -1282,31 +1356,53 @@ xfs_attr_node_remove_step(* * This routine will find the blocks of the name to remove, remove them and * shirnk 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; -int error; -struct xfs_inode *dp = args->dp; +struct xfs_da_args *args = dac->da_args; +struct xfs_da_state *state; +int error; +struct xfs_inode *dp = args->dp;trace_xfs_attr_node_removename (args); + state = dac->da_state; - error =xfs_attr_node_removename_setup (args, &state); -if (error) - goto out; +if ((dac->flags &XFS_DAC_NODE_RMVNAME_INIT ) ==0 ) { + dac->flags |=XFS_DAC_NODE_RMVNAME_INIT ; + error =xfs_attr_node_removename_setup (dac, &state); +if (error)fs/xfs/libxfs/xfs_attr.c xfs_attr_node_remove_step( · line 1385
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +7
-3+ goto out; + } - error =xfs_attr_node_remove_step (args, state); -if (error) - goto out; +switch (dac->dela_state) { +case XFS_DAS_UNINIT : + error =xfs_attr_node_remove_step (dac); +if (error) +break ;I think there's a bit more preliminary refactoring to do here to isolate the state management to this one function. I.e., from the discussion on the previous version, we'd ideally pull the logic that checks for the subsequent shrink state out of
xfs_attr_node_remove_step()and lift it into this branch. See the pseudocode in the previous discussion for an example of what I mean:https://urldefense.com/v3/__https://lore.kernel.org/linux-xfs/20200901170020.GC174813@bfoster/__;!!GqivPVa7Brio!JKxU3Z07HVj0V1YFesXrveRWnoGuWqiTZuaIDiG9UFmSxz-aFGsZPpLtjIOjSht7WL_h$The general goal of that is to refactor the existing code such that all of the state transitions and whatnot are shown in one place and the rest is broken down into smaller functional helpers.
Quoted 9 lines
Quoted 1 line
Brian
Yes, I did see the pseudo code, though I wasnt able to get it through the test cases quite the way it appears. Because whether or not we proceed to shrink is determined by the leaf remove that's burried in the step function. Otherwise we run into some failed asserts in the shrink routines for "
state->path.active== 1". Alternatly we can add another helper to pull it up to this scope. Then the switch ends up looking like this:
Ok. That was more focused on just showing an approach that collects all of the state transition logic in one place. The factoring below seems generally reasonable to me..
Quoted 52 lines
switch (dac->dela_state) {
case XFS_DAS_UNINIT:
/*
* repeatedly remove remote blocks, remove the entry and
* join. returns -EAGAIN or 0 for completion of the step.
*/
error = xfs_attr_node_remove_step(dac);
if (error)
break;
retval = xfs_attr_node_remove_cleanup(dac);
/*
* Check to see if the tree needs to be collapsed. Set the
flag to
* indicate that the calling function needs to move the to
shrink
* operation
*/
if (retval && (state->path.active > 1)) {
error = xfs_da3_join(state);
if (error)
return error;
dac->dela_state = XFS_DAS_RM_SHRINK;
return -EAGAIN;
}
/* check whether to shrink or return success */Quoted 7 lines
if (!error && xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
dac->dela_state = XFS_DAS_RM_SHRINK;
error = -EAGAIN;
}... though what is the purpose of this hunk? This seems to diverge from the current logic, but maybe I'm missing something.
Quoted 74 lines
break; case XFS_DAS_RM_SHRINK: /* * If the result is small enough, push it all into the inode. */ error = xfs_attr_node_shrink(args, state); break; default: ASSERT(0); return -EINVAL; } if (error == -EAGAIN) return error;And then we have this little clean up helper that we pull out of
remove_step:STATIC int
xfs_attr_node_remove_cleanup(
struct
xfs_delattr_context*dac){
struct xfs_da_args *args = dac->da_args; struct xfs_da_state_blk *blk; int retval; /* * Remove the name and update the hashvals in the tree. */ blk = &dac->da_state->path.blk[ dac->da_state->path.active-1 ]; ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC); retval = xfs_attr3_leaf_remove(blk->bp, args); xfs_da3_fixhashpath(dac->da_state, &dac->da_state->path); return retval;
Quoted 7 lines
}
This configuration seems to get through the test cases. It's not quite as tidy, but it does get all the state handling into this scope. If people prefer it this way I can add in the extra helper and make these adjustments?
Makes sense. I think the goal should be to pull the state management into one (or as few) place(s) as technically possible and we should refactor however necessary to accomplish that (please just pull the refactoring out into preliminary patches to facilitate review). Thanks.
Brian
Quoted 227 lines
Allison
Quoted 224 lines
Quoted 223 lines
fs/xfs/libxfs/xfs_attr.c +15
-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); +/* do not break, proceed to shrink if needed */ +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 ); +return -EINVAL ; + } + +if (error == -EAGAIN ) +return error; out:if (state)xfs_da_state_free (state);fs/xfs/libxfs/xfs_attr.h +72
-0@@ -74,6 +74,74 @@ struct xfs_attr_list_context { }; +/* +* ======================================================================== +* Structure used to pass context around among the delayed routines. +* ======================================================================== +*/ + +/* +* Below is a state machine diagram for attr remove operations. The XFS_DAS_* +* states indicate places where the function would return -EAGAIN, and then +* immediately resume from after being recalled by the calling function. States +* marked as a "subroutine state" indicate that they belong to a subroutine, and +* so the calling function needs to pass them back to that subroutine to allow +* it to finish where it left off. But they otherwise do not have a role in the +* calling function other than just passing through. +* +* xfs_attr_remove_iter() +* XFS_DAS_RM_SHRINK ─┐ +* (subroutine state) │ +* └─>xfs_attr_node_removename() +* │ +* v +* need to +* shrink tree? ─n─┐ +* │ │ +* y │ +* │ │ +* v │ +* XFS_DAS_RM_SHRINK │ +* │ │ +* v │ +* done <─────┘ +* +*/ + +/* +* Enum values for xfs_delattr_context.da_state +* +* These values are used by delayed attribute operations to keep track of where +* they were before they returned -EAGAIN. A return code of -EAGAIN signals the +* calling function to roll the transaction, and then recall the subroutine to +* finish the operation. The enum is then used by the subroutine to jump back +* to where it was and resume executing where it left off. +*/ +enum xfs_delattr_state { +XFS_DAS_UNINIT =0 ,/* No state has been set yet */ +XFS_DAS_RM_SHRINK ,/* We are shrinking the tree */ +}; + +/* +* Defines for xfs_delattr_context.flags +*/ +#define XFS_DAC_DEFER_FINISH 0x01/* finish the transaction */ +#define XFS_DAC_NODE_RMVNAME_INIT 0x02/* xfs_attr_node_removename init */ + +/* +* Context used for keeping track of delayed attribute operations +*/ +struct xfs_delattr_context { +struct xfs_da_args *da_args; + +/* Used in xfs_attr_node_removename to roll through removing blocks */ +struct xfs_da_state *da_state; + +/* Used to keep track of current state of delayed operation */ +unsigned int flags; +enum xfs_delattr_state dela_state; +}; +/*======================================================================== * Function prototypes for the kernel. *========================================================================*/ @@ -91,6 +159,10 @@ int xfs_attr_set(struct xfs_da_args *args);int xfs_attr_set_args (struct xfs_da_args *args);int xfs_has_attr (struct xfs_da_args *args);int xfs_attr_remove_args (struct xfs_da_args *args); +int xfs_attr_remove_iter (struct xfs_delattr_context *dac); +int xfs_attr_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);#endif /* __XFS_ATTR_H__ */ 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 +18
-19@@ -674,10 +674,12 @@ xfs_attr_rmtval_invalidate(*/ int xfs_attr_rmtval_remove ( -struct xfs_da_args *args) +struct xfs_da_args *args) { -int error; -int retval; +int error; +struct xfs_delattr_context dac = { + .da_args = args, + };trace_xfs_attr_rmtval_remove (args);@@ -685,19 +687,17 @@ 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 ; -/* -* 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 ); -return 0 ; + }while (true); + +return error; }/* @@ -707,9 +707,10 @@ xfs_attr_rmtval_remove(*/ int __xfs_attr_rmtval_remove ( -struct xfs_da_args *args) +struct xfs_delattr_context *dac) { -int error, done; +struct xfs_da_args *args = dac->da_args; +int error, done;/* * Unmap value blocks for this attr. @@ -719,12 +720,10 @@ __xfs_attr_rmtval_remove(if (error)return error; - error =xfs_defer_finish (&args->trans); -if (error) -return error; - -if (!done) +if (!done) { + dac->flags |=XFS_DAC_DEFER_FINISH ;return -EAGAIN ; + }return error; }fs/xfs/libxfs/xfs_attr_remote.h +1
-1@@ -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 v13 02/10] xfs: Add delay ready attr remove routines
Quoted 176 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 | 200 +++++++++++++++++++++++++++++----------- fs/xfs/libxfs/xfs_attr.h | 72 +++++++++++++++ fs/xfs/libxfs/xfs_attr_leaf.c | 2 +- fs/xfs/libxfs/xfs_attr_remote.c | 37 ++++---- fs/xfs/libxfs/xfs_attr_remote.h | 2 +- fs/xfs/xfs_attr_inactive.c | 2 +- 6 files changed, 241 insertions(+), 74 deletions(-)fs/xfs/libxfs/xfs_attr.c +0
-0...
Quoted 56 lines
Quoted 56 lines
Quoted 32 lines
fs/xfs/libxfs/xfs_attr.c +16
-8@@ -1282,31 +1356,53 @@ xfs_attr_node_remove_step(* * This routine will find the blocks of the name to remove, remove them and * shirnk 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; -int error; -struct xfs_inode *dp = args->dp; +struct xfs_da_args *args = dac->da_args; +struct xfs_da_state *state; +int error; +struct xfs_inode *dp = args->dp;trace_xfs_attr_node_removename (args); + state = dac->da_state; - error =xfs_attr_node_removename_setup (args, &state); -if (error) - goto out; +if ((dac->flags &XFS_DAC_NODE_RMVNAME_INIT ) ==0 ) { + dac->flags |=XFS_DAC_NODE_RMVNAME_INIT ; + error =xfs_attr_node_removename_setup (dac, &state); +if (error)fs/xfs/libxfs/xfs_attr.c xfs_attr_node_remove_step( · line 1385
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +7
-3+ goto out; + } - error =xfs_attr_node_remove_step (args, state); -if (error) - goto out; +switch (dac->dela_state) { +case XFS_DAS_UNINIT : + error =xfs_attr_node_remove_step (dac); +if (error) +break ;I think there's a bit more preliminary refactoring to do here to isolate the state management to this one function. I.e., from the discussion on the previous version, we'd ideally pull the logic that checks for the subsequent shrink state out of
xfs_attr_node_remove_step()and lift it into this branch. See the pseudocode in the previous discussion for an example of what I mean:https://urldefense.com/v3/__https://lore.kernel.org/linux-xfs/20200901170020.GC174813@bfoster/__;!!GqivPVa7Brio!JKxU3Z07HVj0V1YFesXrveRWnoGuWqiTZuaIDiG9UFmSxz-aFGsZPpLtjIOjSht7WL_h$The general goal of that is to refactor the existing code such that all of the state transitions and whatnot are shown in one place and the rest is broken down into smaller functional helpers.
Quoted 9 lines
Quoted 1 line
Brian
Yes, I did see the pseudo code, though I wasnt able to get it through the test cases quite the way it appears. Because whether or not we proceed to shrink is determined by the leaf remove that's burried in the step function. Otherwise we run into some failed asserts in the shrink routines for "
state->path.active== 1". Alternatly we can add another helper to pull it up to this scope. Then the switch ends up looking like this:Ok. That was more focused on just showing an approach that collects all of the state transition logic in one place. The factoring below seems generally reasonable to me..
Quoted 54 lines
switch (dac->dela_state) { case XFS_DAS_UNINIT: /* * repeatedly remove remote blocks, remove the entry and * join. returns -EAGAIN or 0 for completion of the step. */ error = xfs_attr_node_remove_step(dac); if (error) break; retval = xfs_attr_node_remove_cleanup(dac); /* * Check to see if the tree needs to be collapsed. Set the flag to * indicate that the calling function needs to move the to shrink * operation */ if (retval && (state->path.active > 1)) { error = xfs_da3_join(state); if (error) return error; dac->dela_state = XFS_DAS_RM_SHRINK; return -EAGAIN; } /* check whether to shrink or return success */ if (!error && xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
Quoted 9 lines
Quoted 5 lines
dac->dela_state = XFS_DAS_RM_SHRINK; error = -EAGAIN; }... though what is the purpose of this hunk? This seems to diverge from the current logic, but maybe I'm missing something.
That's just me trying to get as close to the psuedo code as possible, but if the concern is just to keep the state management in this scope, I may move it back down into the the XFS_DAS_RM_SHRINK case where it was, I think it looks a little cleaner there.
Quoted 11 lines
Quoted 11 lines
break; case XFS_DAS_RM_SHRINK: /* * If the result is small enough, push it all into the inode. */
So it would go back down here like this, which is more akin to the original code flow:
if (xfs_bmap_one_block(dp, XFS_ATTR_FORK))
Quoted 71 lines
Quoted 63 lines
error = xfs_attr_node_shrink(args, state); break; default: ASSERT(0); return -EINVAL; } if (error == -EAGAIN) return error;And then we have this little clean up helper that we pull out of
remove_step:STATIC int
xfs_attr_node_remove_cleanup(
struct
xfs_delattr_context*dac){
struct xfs_da_args *args = dac->da_args; struct xfs_da_state_blk *blk; int retval; /* * Remove the name and update the hashvals in the tree. */ blk = &dac->da_state->path.blk[ dac->da_state->path.active-1 ]; ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC); retval = xfs_attr3_leaf_remove(blk->bp, args); xfs_da3_fixhashpath(dac->da_state, &dac->da_state->path); return retval;Quoted 7 lines
}
This configuration seems to get through the test cases. It's not quite as tidy, but it does get all the state handling into this scope. If people prefer it this way I can add in the extra helper and make these adjustments?
Quoted 6 lines
Makes sense. I think the goal should be to pull the state management into one (or as few) place(s) as technically possible and we should refactor however necessary to accomplish that (please just pull the refactoring out into preliminary patches to facilitate review). Thanks.
Brian
Sure, I'll add in another patch for that extra helper in the next set. Thanks for the review!
Allison
Quoted 229 lines
Quoted 228 lines
Allison
Quoted 224 lines
Quoted 223 lines
fs/xfs/libxfs/xfs_attr.c +15
-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); +/* do not break, proceed to shrink if needed */ +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 ); +return -EINVAL ; + } + +if (error == -EAGAIN ) +return error; out:if (state)xfs_da_state_free (state);fs/xfs/libxfs/xfs_attr.h +72
-0@@ -74,6 +74,74 @@ struct xfs_attr_list_context { }; +/* +* ======================================================================== +* Structure used to pass context around among the delayed routines. +* ======================================================================== +*/ + +/* +* Below is a state machine diagram for attr remove operations. The XFS_DAS_* +* states indicate places where the function would return -EAGAIN, and then +* immediately resume from after being recalled by the calling function. States +* marked as a "subroutine state" indicate that they belong to a subroutine, and +* so the calling function needs to pass them back to that subroutine to allow +* it to finish where it left off. But they otherwise do not have a role in the +* calling function other than just passing through. +* +* xfs_attr_remove_iter() +* XFS_DAS_RM_SHRINK ─┐ +* (subroutine state) │ +* └─>xfs_attr_node_removename() +* │ +* v +* need to +* shrink tree? ─n─┐ +* │ │ +* y │ +* │ │ +* v │ +* XFS_DAS_RM_SHRINK │ +* │ │ +* v │ +* done <─────┘ +* +*/ + +/* +* Enum values for xfs_delattr_context.da_state +* +* These values are used by delayed attribute operations to keep track of where +* they were before they returned -EAGAIN. A return code of -EAGAIN signals the +* calling function to roll the transaction, and then recall the subroutine to +* finish the operation. The enum is then used by the subroutine to jump back +* to where it was and resume executing where it left off. +*/ +enum xfs_delattr_state { +XFS_DAS_UNINIT =0 ,/* No state has been set yet */ +XFS_DAS_RM_SHRINK ,/* We are shrinking the tree */ +}; + +/* +* Defines for xfs_delattr_context.flags +*/ +#define XFS_DAC_DEFER_FINISH 0x01/* finish the transaction */ +#define XFS_DAC_NODE_RMVNAME_INIT 0x02/* xfs_attr_node_removename init */ + +/* +* Context used for keeping track of delayed attribute operations +*/ +struct xfs_delattr_context { +struct xfs_da_args *da_args; + +/* Used in xfs_attr_node_removename to roll through removing blocks */ +struct xfs_da_state *da_state; + +/* Used to keep track of current state of delayed operation */ +unsigned int flags; +enum xfs_delattr_state dela_state; +}; +/*======================================================================== * Function prototypes for the kernel. *========================================================================*/ @@ -91,6 +159,10 @@ int xfs_attr_set(struct xfs_da_args *args);int xfs_attr_set_args (struct xfs_da_args *args);int xfs_has_attr (struct xfs_da_args *args);int xfs_attr_remove_args (struct xfs_da_args *args); +int xfs_attr_remove_iter (struct xfs_delattr_context *dac); +int xfs_attr_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);#endif /* __XFS_ATTR_H__ */ 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 +18
-19@@ -674,10 +674,12 @@ xfs_attr_rmtval_invalidate(*/ int xfs_attr_rmtval_remove ( -struct xfs_da_args *args) +struct xfs_da_args *args) { -int error; -int retval; +int error; +struct xfs_delattr_context dac = { + .da_args = args, + };trace_xfs_attr_rmtval_remove (args);@@ -685,19 +687,17 @@ 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 ; -/* -* 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 ); -return 0 ; + }while (true); + +return error; }/* @@ -707,9 +707,10 @@ xfs_attr_rmtval_remove(*/ int __xfs_attr_rmtval_remove ( -struct xfs_da_args *args) +struct xfs_delattr_context *dac) { -int error, done; +struct xfs_da_args *args = dac->da_args; +int error, done;/* * Unmap value blocks for this attr. @@ -719,12 +720,10 @@ __xfs_attr_rmtval_remove(if (error)return error; - error =xfs_defer_finish (&args->trans); -if (error) -return error; - -if (!done) +if (!done) { + dac->flags |=XFS_DAC_DEFER_FINISH ;return -EAGAIN ; + }return error; }fs/xfs/libxfs/xfs_attr_remote.h +1
-1@@ -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 v13 02/10] xfs: Add delay ready attr remove routines
In reply to Brian FosterQuoted 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 | 200 +++++++++++++++++++++++++++++----------- fs/xfs/libxfs/xfs_attr.h | 72 +++++++++++++++ fs/xfs/libxfs/xfs_attr_leaf.c | 2 +- fs/xfs/libxfs/xfs_attr_remote.c | 37 ++++---- fs/xfs/libxfs/xfs_attr_remote.h | 2 +- fs/xfs/xfs_attr_inactive.c | 2 +- 6 files changed, 241 insertions(+), 74 deletions(-)fs/xfs/libxfs/xfs_attr.c +0
-0
<snip>
Quoted 54 lines
Quoted 36 lines
fs/xfs/libxfs/xfs_attr.c +18
-8@@ -1282,31 +1356,53 @@ xfs_attr_node_remove_step(* * This routine will find the blocks of the name to remove, remove them and * shirnk 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; -int error; -struct xfs_inode *dp = args->dp; +struct xfs_da_args *args = dac->da_args; +struct xfs_da_state *state; +int error; +struct xfs_inode *dp = args->dp;trace_xfs_attr_node_removename (args); + state = dac->da_state; - error =xfs_attr_node_removename_setup (args, &state); -if (error) - goto out; +if ((dac->flags &XFS_DAC_NODE_RMVNAME_INIT ) ==0 ) { + dac->flags |=XFS_DAC_NODE_RMVNAME_INIT ; + error =xfs_attr_node_removename_setup (dac, &state); +if (error) + goto out; + }fs/xfs/libxfs/xfs_attr.c xfs_attr_node_remove_step( · line 1389
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +5
-3- error =xfs_attr_node_remove_step (args, state); -if (error) - goto out; +switch (dac->dela_state) { +case XFS_DAS_UNINIT : + error =xfs_attr_node_remove_step (dac); +if (error) +break ;I think there's a bit more preliminary refactoring to do here to isolate the state management to this one function. I.e., from the discussion on the previous version, we'd ideally pull the logic that checks for the subsequent shrink state out of
xfs_attr_node_remove_step()and lift it into this branch. See the pseudocode in the previous discussion for an example of what I mean:
Quoted 5 lines
https://lore.kernel.org/linux-xfs/20200901170020.GC174813@bfoster/
The general goal of that is to refactor the existing code such that all of the state transitions and whatnot are shown in one place and the rest is broken down into smaller functional helpers.
Agreed.
--D
Quoted 237 lines
Brian
Quoted 234 lines
fs/xfs/libxfs/xfs_attr.c +15
-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); +/* do not break, proceed to shrink if needed */ +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 ); +return -EINVAL ; + } + +if (error == -EAGAIN ) +return error; out:if (state)xfs_da_state_free (state);fs/xfs/libxfs/xfs_attr.h +72
-0@@ -74,6 +74,74 @@ struct xfs_attr_list_context { }; +/* +* ======================================================================== +* Structure used to pass context around among the delayed routines. +* ======================================================================== +*/ + +/* +* Below is a state machine diagram for attr remove operations. The XFS_DAS_* +* states indicate places where the function would return -EAGAIN, and then +* immediately resume from after being recalled by the calling function. States +* marked as a "subroutine state" indicate that they belong to a subroutine, and +* so the calling function needs to pass them back to that subroutine to allow +* it to finish where it left off. But they otherwise do not have a role in the +* calling function other than just passing through. +* +* xfs_attr_remove_iter() +* XFS_DAS_RM_SHRINK ─┐ +* (subroutine state) │ +* └─>xfs_attr_node_removename() +* │ +* v +* need to +* shrink tree? ─n─┐ +* │ │ +* y │ +* │ │ +* v │ +* XFS_DAS_RM_SHRINK │ +* │ │ +* v │ +* done <─────┘ +* +*/ + +/* +* Enum values for xfs_delattr_context.da_state +* +* These values are used by delayed attribute operations to keep track of where +* they were before they returned -EAGAIN. A return code of -EAGAIN signals the +* calling function to roll the transaction, and then recall the subroutine to +* finish the operation. The enum is then used by the subroutine to jump back +* to where it was and resume executing where it left off. +*/ +enum xfs_delattr_state { +XFS_DAS_UNINIT =0 ,/* No state has been set yet */ +XFS_DAS_RM_SHRINK ,/* We are shrinking the tree */ +}; + +/* +* Defines for xfs_delattr_context.flags +*/ +#define XFS_DAC_DEFER_FINISH 0x01/* finish the transaction */ +#define XFS_DAC_NODE_RMVNAME_INIT 0x02/* xfs_attr_node_removename init */ + +/* +* Context used for keeping track of delayed attribute operations +*/ +struct xfs_delattr_context { +struct xfs_da_args *da_args; + +/* Used in xfs_attr_node_removename to roll through removing blocks */ +struct xfs_da_state *da_state; + +/* Used to keep track of current state of delayed operation */ +unsigned int flags; +enum xfs_delattr_state dela_state; +}; +/*======================================================================== * Function prototypes for the kernel. *========================================================================*/ @@ -91,6 +159,10 @@ int xfs_attr_set(struct xfs_da_args *args);int xfs_attr_set_args (struct xfs_da_args *args);int xfs_has_attr (struct xfs_da_args *args);int xfs_attr_remove_args (struct xfs_da_args *args); +int xfs_attr_remove_iter (struct xfs_delattr_context *dac); +int xfs_attr_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);#endif /* __XFS_ATTR_H__ */ 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 +18
-19@@ -674,10 +674,12 @@ xfs_attr_rmtval_invalidate(*/ int xfs_attr_rmtval_remove ( -struct xfs_da_args *args) +struct xfs_da_args *args) { -int error; -int retval; +int error; +struct xfs_delattr_context dac = { + .da_args = args, + };trace_xfs_attr_rmtval_remove (args);@@ -685,19 +687,17 @@ 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 ; -/* -* 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 ); -return 0 ; + }while (true); + +return error; }/* @@ -707,9 +707,10 @@ xfs_attr_rmtval_remove(*/ int __xfs_attr_rmtval_remove ( -struct xfs_da_args *args) +struct xfs_delattr_context *dac) { -int error, done; +struct xfs_da_args *args = dac->da_args; +int error, done;/* * Unmap value blocks for this attr. @@ -719,12 +720,10 @@ __xfs_attr_rmtval_remove(if (error)return error; - error =xfs_defer_finish (&args->trans); -if (error) -return error; - -if (!done) +if (!done) { + dac->flags |=XFS_DAC_DEFER_FINISH ;return -EAGAIN ; + }return error; }fs/xfs/libxfs/xfs_attr_remote.h +1
-1@@ -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 v13 02/10] xfs: Add delay ready attr remove routines
In reply to Allison HendersonQuoted 74 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 | 200 +++++++++++++++++++++++++++++----------- fs/xfs/libxfs/xfs_attr.h | 72 +++++++++++++++ fs/xfs/libxfs/xfs_attr_leaf.c | 2 +- fs/xfs/libxfs/xfs_attr_remote.c | 37 ++++---- fs/xfs/libxfs/xfs_attr_remote.h | 2 +- fs/xfs/xfs_attr_inactive.c | 2 +- 6 files changed, 241 insertions(+), 74 deletions(-)fs/xfs/libxfs/xfs_attr.c +16
-1@@ -53,7 +53,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_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);@@ -264,6 +264,33 @@ xfs_attr_set_shortform( }/* +* 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 =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
fs/xfs/libxfs/xfs_attr.c xfs_attr_set_shortform( · line 291
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10
-0+* ops. +*/ + dac->flags &= ~XFS_DAC_DEFER_FINISH ; + error =xfs_defer_finish (&args->trans); +if (error) +return error; + } + +return xfs_trans_roll_inode (&args->trans, args->dp); +}
(Mostly ignoring these functions since they all go away by the end of the patchset...)
Quoted 40 lines
fs/xfs/libxfs/xfs_attr.c +29
-3+ +/* * Set the attribute specified in @args. */ int @@ -364,23 +391,54 @@ 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 =0 ; +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. +*/
fs/xfs/libxfs/xfs_attr.c xfs_has_attr( · line 431
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +9
-0+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 (dac->dela_state ==XFS_DAS_RM_SHRINK ) + goto node;
Might as well just make this part of the if statement dispatch:
if (dac->dela_state == XFS_DAS_RM_SHRINK) return xfs_attr_node_removename_iter(dac); else if (!xfs_inode_hasattr(dp)) return -ENOATTR;
Quoted 21 lines
fs/xfs/libxfs/xfs_attr.c +5
-7if (!xfs_inode_hasattr (dp)) { - error = -ENOATTR ; +return -ENOATTR ; }else if (dp->i_afp->if_format ==XFS_DINODE_FMT_LOCAL ) {ASSERT (dp->i_afp->if_flags &XFS_IFINLINE ); - error =xfs_attr_shortform_remove (args); +return xfs_attr_shortform_remove (args); }else if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) { - error =xfs_attr_leaf_removename (args); - }else { - error =xfs_attr_node_removename (args); +return xfs_attr_leaf_removename (args); } - -return error; +node: +return xfs_attr_node_removename_iter (dac); }/*
fs/xfs/libxfs/xfs_attr.c xfs_attr_leaf_mark_incomplete( · line 1240
Quoted 7 lines
fs/xfs/libxfs/xfs_attr.c +2
-2@@ -1178,10 +1236,11 @@ 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, +struct xfs_da_state **state)
AFAICT *state == &dac->da_state by the end of the series; can you should remove this argument too?
Quoted 9 lines
fs/xfs/libxfs/xfs_attr.c +2
-1{ -int error; +struct xfs_da_args *args = dac->da_args; +int error; error =xfs_attr_node_hasname (args, state);if (error != -EEXIST )@@ -1191,6 +1250,12 @@ int xfs_attr_node_removename_setup( ASSERT((*state)->path.blk[(*state)->path.active - 1].magic ==
fs/xfs/libxfs/xfs_attr.c int xfs_attr_node_removename_setup( · line 1260
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +6
-0XFS_ATTR_LEAF_MAGIC); +/* +* Store state in the context incase we need to cycle out the +* transaction +*/ + dac->da_state = *state; +if (args->rmtblkno >0 ) { error =xfs_attr_leaf_mark_incomplete (args, *state);
It doesn't make a lot of logical sense to me "we marked the attr incomplete to hide it" is the same state (UNINIT) as "we haven't done anything yet".
Quoted 44 lines
fs/xfs/libxfs/xfs_attr.c +15
-8if (error)@@ -1203,13 +1268,16 @@ int xfs_attr_node_removename_setup( } 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;@@ -1221,21 +1289,27 @@ xfs_attr_node_remove_rmt( }/* -* 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)
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_remove_rmt( · line 1312
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +5
-3{ -struct xfs_da_state_blk *blk; -int retval, error; -struct xfs_inode *dp = args->dp; +struct xfs_da_args *args = dac->da_args; +struct xfs_da_state *state; +struct xfs_da_state_blk *blk; +int retval, error =0 ; + state = dac->da_state;
Might as well initialize this when you declare state above.
Quoted 45 lines
fs/xfs/libxfs/xfs_attr.c +11
-11/* * If there is an out-of-line value, de-allocate the blocks. @@ -1243,7 +1317,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; }@@ -1257,21 +1334,18 @@ xfs_attr_node_remove_step(xfs_da3_fixhashpath (state, &state->path);/* -* Check to see if the tree needs to be collapsed. +* Check to see if the tree needs to be collapsed. Set the flag to +* indicate that the calling function needs to move the to shrink +* operation */ 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; + + dac->flags |=XFS_DAC_DEFER_FINISH ; + dac->dela_state =XFS_DAS_RM_SHRINK ; +return -EAGAIN ; }return error;
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_remove_step( · line 1358
Quoted 3 lines
fs/xfs/libxfs/xfs_attr.c +0
-0@@ -1282,31 +1356,53 @@ xfs_attr_node_remove_step(* * This routine will find the blocks of the name to remove, remove them and * shirnk the tree if needed.
"...and shrink the tree..."
Quoted 18 lines
fs/xfs/libxfs/xfs_attr.c +10
-5+* +* 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; -int error; -struct xfs_inode *dp = args->dp; +struct xfs_da_args *args = dac->da_args; +struct xfs_da_state *state; +int error;
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_remove_step( · line 1378
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +4
-3+struct xfs_inode *dp = args->dp;trace_xfs_attr_node_removename (args); + state = dac->da_state; - error =xfs_attr_node_removename_setup (args, &state); -if (error) - goto out; +if ((dac->flags &XFS_DAC_NODE_RMVNAME_INIT ) ==0 ) { + dac->flags |=XFS_DAC_NODE_RMVNAME_INIT ;
Can we determine if it's necessary to call _removename_setup by checking dac->da_state directly instead of having a flag?
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +6
-3+ error =xfs_attr_node_removename_setup (dac, &state); +if (error) + goto out; + } - error =xfs_attr_node_remove_step (args, state); -if (error) - goto out; +switch (dac->dela_state) { +case XFS_DAS_UNINIT :
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_remove_step( · line 1390
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +4
-5+ error =xfs_attr_node_remove_step (dac); +if (error) +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); +/* do not break, proceed to shrink if needed */
/* fall through */
...because otherwise the static checkers will get mad.
(Well clang will anyway because gcc, llvm, and the C18 body all have different incompatible ideas of what should be the magic tag that signals an intentional fall through, but this should at least be consistent with the rest of xfs.)
Quoted 184 lines
fs/xfs/libxfs/xfs_attr.c +14
-0+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 ); +return -EINVAL ; + } + +if (error == -EAGAIN ) +return error; out:if (state)xfs_da_state_free (state);fs/xfs/libxfs/xfs_attr.h +72
-0@@ -74,6 +74,74 @@ struct xfs_attr_list_context { }; +/* +* ======================================================================== +* Structure used to pass context around among the delayed routines. +* ======================================================================== +*/ + +/* +* Below is a state machine diagram for attr remove operations. The XFS_DAS_* +* states indicate places where the function would return -EAGAIN, and then +* immediately resume from after being recalled by the calling function. States +* marked as a "subroutine state" indicate that they belong to a subroutine, and +* so the calling function needs to pass them back to that subroutine to allow +* it to finish where it left off. But they otherwise do not have a role in the +* calling function other than just passing through. +* +* xfs_attr_remove_iter() +* XFS_DAS_RM_SHRINK ─┐ +* (subroutine state) │ +* └─>xfs_attr_node_removename() +* │ +* v +* need to +* shrink tree? ─n─┐ +* │ │ +* y │ +* │ │ +* v │ +* XFS_DAS_RM_SHRINK │ +* │ │ +* v │ +* done <─────┘ +* +*/ + +/* +* Enum values for xfs_delattr_context.da_state +* +* These values are used by delayed attribute operations to keep track of where +* they were before they returned -EAGAIN. A return code of -EAGAIN signals the +* calling function to roll the transaction, and then recall the subroutine to +* finish the operation. The enum is then used by the subroutine to jump back +* to where it was and resume executing where it left off. +*/ +enum xfs_delattr_state { +XFS_DAS_UNINIT =0 ,/* No state has been set yet */ +XFS_DAS_RM_SHRINK ,/* We are shrinking the tree */ +}; + +/* +* Defines for xfs_delattr_context.flags +*/ +#define XFS_DAC_DEFER_FINISH 0x01/* finish the transaction */ +#define XFS_DAC_NODE_RMVNAME_INIT 0x02/* xfs_attr_node_removename init */ + +/* +* Context used for keeping track of delayed attribute operations +*/ +struct xfs_delattr_context { +struct xfs_da_args *da_args; + +/* Used in xfs_attr_node_removename to roll through removing blocks */ +struct xfs_da_state *da_state; + +/* Used to keep track of current state of delayed operation */ +unsigned int flags; +enum xfs_delattr_state dela_state; +}; +/*======================================================================== * Function prototypes for the kernel. *========================================================================*/ @@ -91,6 +159,10 @@ int xfs_attr_set(struct xfs_da_args *args);int xfs_attr_set_args (struct xfs_da_args *args);int xfs_has_attr (struct xfs_da_args *args);int xfs_attr_remove_args (struct xfs_da_args *args); +int xfs_attr_remove_iter (struct xfs_delattr_context *dac); +int xfs_attr_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);#endif /* __XFS_ATTR_H__ */ 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 +15
-14@@ -674,10 +674,12 @@ xfs_attr_rmtval_invalidate(*/ int xfs_attr_rmtval_remove ( -struct xfs_da_args *args) +struct xfs_da_args *args) { -int error; -int retval; +int error; +struct xfs_delattr_context dac = { + .da_args = args, + };trace_xfs_attr_rmtval_remove (args);@@ -685,19 +687,17 @@ 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 ; -/* -* 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 ); -return 0 ; + }while (true); + +return error; }/* @@ -707,9 +707,10 @@ xfs_attr_rmtval_remove(*/ int __xfs_attr_rmtval_remove ( -struct xfs_da_args *args) +struct xfs_delattr_context *dac) { -int error, done; +struct xfs_da_args *args = dac->da_args; +int error, done;/* * Unmap value blocks for this attr. @@ -719,12 +720,10 @@ __xfs_attr_rmtval_remove(if (error)
fs/xfs/libxfs/xfs_attr_remote.c __xfs_attr_rmtval_remove( · line 725
Quoted 10 lines
fs/xfs/libxfs/xfs_attr_remote.c +2
-5return error; - error =xfs_defer_finish (&args->trans); -if (error) -return error; - -if (!done) +if (!done) { + dac->flags |=XFS_DAC_DEFER_FINISH ;return -EAGAIN ;
What state are we in when we return -EAGAIN here?
[jumps back to his whole-branch diff]
Hm, oh, I see, the next state could be a number of things--
RM_LBLK if we're removing an old remote value from a leaf block as part of an attr set operation; or
RM_NBLK if we're removing an old remote value from a node block as part of an attr set operation; and
UNINIT if we're removing a remote value as part of an attr set operation.
Oh! For the first two, it looks to me as though either we're already in the state we're setting (RM_[LN]BLK) or we were in either of the FLIP_[LN]FLAG state.
I think it would make more sense if you set the state before calling the rmtval_remove function, and leave a comment here saying that the caller is responsible for figuring out the next state.
For removals, I wonder if we should have advanced beyond UNINIT by the time we get here? I think you've added the minimum states that are necessary to resume work after a transaction roll, but from this and the next patch I feel like we do a lot of work while dela_state == UNINIT.
FWIW I will be taking a close look at all the new 'return -EAGAIN' statements to see if I can tell what state we're in when we trigger a transaction roll.
--D
Quoted 34 lines
fs/xfs/libxfs/xfs_attr_remote.c +1
-0+ }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 v13 02/10] xfs: Add delay ready attr remove routines
Quoted 35 lines · Darrick J. Wong
Quoted 7 lines · Allison Henderson
fs/xfs/libxfs/xfs_attr.c +6
-0+/* +* Remove the attribute specified in @args. +* +* This function may return -EAGAIN to signal that the transaction needs to be +* rolled. Callers should continue calling this function until they receive a +* return value other than -EAGAIN. fs/xfs/libxfs/xfs_attr.c xfs_has_attr( · line 430
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10
-0+*/ +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 (dac->dela_state ==XFS_DAS_RM_SHRINK ) + goto node;Might as well just make this part of the if statement dispatch:
if (dac->dela_state == XFS_DAS_RM_SHRINK) return xfs_attr_node_removename_iter(dac); else if (!xfs_inode_hasattr(dp)) return -ENOATTR;Quoted 9 lines
fs/xfs/libxfs/xfs_attr.c +2
-3if (!xfs_inode_hasattr (dp)) { - error = -ENOATTR ; +return -ENOATTR ; }else if (dp->i_afp->if_format ==XFS_DINODE_FMT_LOCAL ) {ASSERT (dp->i_afp->if_flags &XFS_IFINLINE ); - error =xfs_attr_shortform_remove (args); +return xfs_attr_shortform_remove (args); }else if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) { - error =xfs_attr_leaf_removename (args);
Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c xfs_has_attr( · line 441
Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c +3
-4- }else { - error =xfs_attr_node_removename (args); +return xfs_attr_leaf_removename (args); } - -return error; +node: +return xfs_attr_node_removename_iter (dac);
Just a nitpick on this anti-pattern: else is not necessary when the branch returns.
if (!xfs_inode_hasattr(dp))
return -ENOATTR;
if (dac->dela_state == XFS_DAS_RM_SHRINK)
return xfs_attr_node_removename_iter(dac);
if (dp->i_afp->if_format == XFS_DINODE_FMT_LOCAL) {
ASSERT(dp->i_afp->if_flags & XFS_IFINLINE);
return xfs_attr_shortform_remove(args);
}
if (xfs_bmap_one_block(dp, XFS_ATTR_FORK))
return xfs_attr_leaf_removename(args);
return xfs_attr_node_removename_iter(dac);-Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH v13 02/10] xfs: Add delay ready attr remove routines
Quoted 64 lines · Dave Chinner
Quoted 35 lines · Darrick J. Wong
Quoted 7 lines · Allison Henderson
fs/xfs/libxfs/xfs_attr.c +6
-0+/* +* Remove the attribute specified in @args. +* +* This function may return -EAGAIN to signal that the transaction needs to be +* rolled. Callers should continue calling this function until they receive a +* return value other than -EAGAIN. fs/xfs/libxfs/xfs_attr.c xfs_has_attr( · line 430
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10
-0+*/ +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 (dac->dela_state ==XFS_DAS_RM_SHRINK ) + goto node;Might as well just make this part of the if statement dispatch:
if (dac->dela_state == XFS_DAS_RM_SHRINK) return xfs_attr_node_removename_iter(dac); else if (!xfs_inode_hasattr(dp)) return -ENOATTR;Quoted 9 lines
if (!xfs_inode_hasattr(dp)) {fs/xfs/libxfs/xfs_attr.c +2
-3- error = -ENOATTR ; +return -ENOATTR ; }else if (dp->i_afp->if_format ==XFS_DINODE_FMT_LOCAL ) {ASSERT (dp->i_afp->if_flags &XFS_IFINLINE ); - error =xfs_attr_shortform_remove (args); +return xfs_attr_shortform_remove (args); }else if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) { - error =xfs_attr_leaf_removename (args);Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c xfs_has_attr( · line 441
Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c +3
-4- }else { - error =xfs_attr_node_removename (args); +return xfs_attr_leaf_removename (args); } - -return error; +node: +return xfs_attr_node_removename_iter (dac);Just a nitpick on this anti-pattern: else is not necessary when the branch returns.
if (!xfs_inode_hasattr(dp)) return -ENOATTR; if (dac->dela_state == XFS_DAS_RM_SHRINK) return xfs_attr_node_removename_iter(dac); if (dp->i_afp->if_format == XFS_DINODE_FMT_LOCAL) { ASSERT(dp->i_afp->if_flags & XFS_IFINLINE); return xfs_attr_shortform_remove(args); } if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) return xfs_attr_leaf_removename(args); return xfs_attr_node_removename_iter(dac);
Quoted 2 lines
-Dave.
Sure, I think its ok to clean out the elses sense they all return. Thanks!
Allison
Re: [PATCH v13 02/10] xfs: Add delay ready attr remove routines
In reply to Darrick J. WongQuoted 142 lines · Darrick J. Wong
Quoted 74 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 | 200 +++++++++++++++++++++++++++++----------- fs/xfs/libxfs/xfs_attr.h | 72 +++++++++++++++ fs/xfs/libxfs/xfs_attr_leaf.c | 2 +- fs/xfs/libxfs/xfs_attr_remote.c | 37 ++++---- fs/xfs/libxfs/xfs_attr_remote.h | 2 +- fs/xfs/xfs_attr_inactive.c | 2 +- 6 files changed, 241 insertions(+), 74 deletions(-)fs/xfs/libxfs/xfs_attr.c +16
-1@@ -53,7 +53,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_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);@@ -264,6 +264,33 @@ xfs_attr_set_shortform( }/* +* 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 =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 fs/xfs/libxfs/xfs_attr.c xfs_attr_set_shortform( · line 291
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10
-0+* ops. +*/ + dac->flags &= ~XFS_DAC_DEFER_FINISH ; + error =xfs_defer_finish (&args->trans); +if (error) +return error; + } + +return xfs_trans_roll_inode (&args->trans, args->dp); +}(Mostly ignoring these functions since they all go away by the end of the patchset...)
Quoted 40 lines
fs/xfs/libxfs/xfs_attr.c +29
-3+ +/* * Set the attribute specified in @args. */ int @@ -364,23 +391,54 @@ 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 =0 ; +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. +*/ fs/xfs/libxfs/xfs_attr.c xfs_has_attr( · line 431
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +9
-0+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 (dac->dela_state ==XFS_DAS_RM_SHRINK ) + goto node;Might as well just make this part of the if statement dispatch:
Quoted 4 lines
if (dac->dela_state == XFS_DAS_RM_SHRINK) return xfs_attr_node_removename_iter(dac); else if (!xfs_inode_hasattr(dp)) return -ENOATTR;
I think we did this once, but then people disliked having the same call in two places. We call the node function if XFS_DAS_RM_SHRINK is set OR if the other two cases fail which is actually the initial point of entry.
I think probably we need a comment somewhere. I've realized every time a question gets re-raised, it means we need a comment so we dont forget why :-)
Maybe for the goto we can have:
/* If we are shrinking a node, resume shrink */
and.....
Quoted 17 lines
Quoted 7 lines
fs/xfs/libxfs/xfs_attr.c +1
-2if (!xfs_inode_hasattr (dp)) { - error = -ENOATTR ; +return -ENOATTR ; }else if (dp->i_afp->if_format ==XFS_DINODE_FMT_LOCAL ) {ASSERT (dp->i_afp->if_flags &XFS_IFINLINE ); - error =xfs_attr_shortform_remove (args);fs/xfs/libxfs/xfs_attr.c xfs_has_attr( · line 440
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +3
-5+return xfs_attr_shortform_remove (args); }else if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) { - error =xfs_attr_leaf_removename (args); - }else { - error =xfs_attr_node_removename (args); +return xfs_attr_leaf_removename (args); } - -return error; +node:
/* If we are not short form or leaf, then remove node */
?
Quoted 16 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_leaf_mark_incomplete( · line 1240
Quoted 12 lines
fs/xfs/libxfs/xfs_attr.c +3
-2+return xfs_attr_node_removename_iter (dac); }/* @@ -1178,10 +1236,11 @@ 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, +struct xfs_da_state **state)AFAICT *state ==
&dac->da_stateby the end of the series; can you should remove this argument too?
Sure, I will see if I can collapse it down
Quoted 11 lines
Quoted 11 lines
fs/xfs/libxfs/xfs_attr.c +2
-1{ -int error; +struct xfs_da_args *args = dac->da_args; +int error; error =xfs_attr_node_hasname (args, state);if (error != -EEXIST )@@ -1191,6 +1250,12 @@ int xfs_attr_node_removename_setup(ASSERT ((*state)->path.blk[(*state)->path.active -1 ].magic ==XFS_ATTR_LEAF_MAGIC );
Quoted 12 lines
fs/xfs/libxfs/xfs_attr.c int xfs_attr_node_removename_setup( · line 1260
Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c +6
-0+/* +* Store state in the context incase we need to cycle out the +* transaction +*/ + dac->da_state = *state; +if (args->rmtblkno >0 ) { error =xfs_attr_leaf_mark_incomplete (args, *state);It doesn't make a lot of logical sense to me "we marked the attr incomplete to hide it" is the same state (UNINIT) as "we haven't done anything yet".
Not sure I quite follow what you mean here. This little function is just a set up helper. It doesnt jump in an out like the other functions do with the state machine. We separated it out for that reason. This routine executes once to stash the state. The da_state. not the dela_state. Different states :-)
So after we have that stored away, the calling function moves ontoxfs_attr_node_remove_step, which does get recalled quite a bit until there are no more remote blocks to remove.
Quoted 54 lines
Quoted 54 lines
fs/xfs/libxfs/xfs_attr.c +19
-11if (error)@@ -1203,13 +1268,16 @@ int xfs_attr_node_removename_setup( } 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;@@ -1221,21 +1289,27 @@ xfs_attr_node_remove_rmt( }/* -* 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) { -struct xfs_da_state_blk *blk; -int retval, error; -struct xfs_inode *dp = args->dp; +struct xfs_da_args *args = dac->da_args; +struct xfs_da_state *state; +struct xfs_da_state_blk *blk; +int retval, error =0 ;
Quoted 3 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_remove_rmt( · line 1312
Quoted 1 line
fs/xfs/libxfs/xfs_attr.c +1
-0+ state = dac->da_state;Might as well initialize this when you declare state above.
Sure
Quoted 44 lines
Quoted 44 lines
fs/xfs/libxfs/xfs_attr.c +11
-11/* * If there is an out-of-line value, de-allocate the blocks. @@ -1243,7 +1317,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; }@@ -1257,21 +1334,18 @@ xfs_attr_node_remove_step(xfs_da3_fixhashpath (state, &state->path);/* -* Check to see if the tree needs to be collapsed. +* Check to see if the tree needs to be collapsed. Set the flag to +* indicate that the calling function needs to move the to shrink +* operation */ 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; + + dac->flags |=XFS_DAC_DEFER_FINISH ; + dac->dela_state =XFS_DAS_RM_SHRINK ; +return -EAGAIN ; }
Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_remove_step( · line 1358
Quoted 5 lines
fs/xfs/libxfs/xfs_attr.c +0
-0return error;@@ -1282,31 +1356,53 @@ xfs_attr_node_remove_step(* * This routine will find the blocks of the name to remove, remove them and * shirnk the tree if needed. "...and shrink the tree..."
Will fix the shirnk :-)
Quoted 23 lines
Quoted 23 lines
fs/xfs/libxfs/xfs_attr.c +12
-5+* +* 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; -int error; -struct xfs_inode *dp = args->dp; +struct xfs_da_args *args = dac->da_args; +struct xfs_da_state *state; +int error; +struct xfs_inode *dp = args->dp;trace_xfs_attr_node_removename (args); + state = dac->da_state;
Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_remove_step( · line 1378
Quoted 5 lines
fs/xfs/libxfs/xfs_attr.c +2
-3- error =xfs_attr_node_removename_setup (args, &state); -if (error) - goto out; +if ((dac->flags &XFS_DAC_NODE_RMVNAME_INIT ) ==0 ) { + dac->flags |=XFS_DAC_NODE_RMVNAME_INIT ;Can we determine if it's necessary to call
_removename_setupby checkingdac->da_statedirectly instead of having a flag?
Initially I think I had another XFS_DAS_RMTVAL_REMOVE state for this. Alternatly we also discussed using the inverse like this:
if (dac->dela_state != XFS_DAS_RMTVAL_REMOVE)
do setup....
Though I think people liked having the init flag, since init routines we a sort of re-occuring pattern. So that's why were using the flag now.
Quoted 24 lines
Quoted 11 lines
fs/xfs/libxfs/xfs_attr.c +6
-3+ error =xfs_attr_node_removename_setup (dac, &state); +if (error) + goto out; + } - error =xfs_attr_node_remove_step (args, state); -if (error) - goto out; +switch (dac->dela_state) { +case XFS_DAS_UNINIT :fs/xfs/libxfs/xfs_attr.c xfs_attr_node_remove_step( · line 1390
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +4
-5+ error =xfs_attr_node_remove_step (dac); +if (error) +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); +/* do not break, proceed to shrink if needed */ /* fall through */
Quoted 6 lines
...because otherwise the static checkers will get mad.
(Well clang will anyway because gcc, llvm, and the C18 body all have different incompatible ideas of what should be the magic tag that signals an intentional fall through, but this should at least be consistent with the rest of xfs.)
Oh ok then, I did not know. Will update the comment
Quoted 211 lines
Quoted 185 lines
fs/xfs/libxfs/xfs_attr.c +14
-0+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 ); +return -EINVAL ; + } + +if (error == -EAGAIN ) +return error; out:if (state)xfs_da_state_free (state);fs/xfs/libxfs/xfs_attr.h +72
-0@@ -74,6 +74,74 @@ struct xfs_attr_list_context { }; +/* +* ======================================================================== +* Structure used to pass context around among the delayed routines. +* ======================================================================== +*/ + +/* +* Below is a state machine diagram for attr remove operations. The XFS_DAS_* +* states indicate places where the function would return -EAGAIN, and then +* immediately resume from after being recalled by the calling function. States +* marked as a "subroutine state" indicate that they belong to a subroutine, and +* so the calling function needs to pass them back to that subroutine to allow +* it to finish where it left off. But they otherwise do not have a role in the +* calling function other than just passing through. +* +* xfs_attr_remove_iter() +* XFS_DAS_RM_SHRINK ─┐ +* (subroutine state) │ +* └─>xfs_attr_node_removename() +* │ +* v +* need to +* shrink tree? ─n─┐ +* │ │ +* y │ +* │ │ +* v │ +* XFS_DAS_RM_SHRINK │ +* │ │ +* v │ +* done <─────┘ +* +*/ + +/* +* Enum values for xfs_delattr_context.da_state +* +* These values are used by delayed attribute operations to keep track of where +* they were before they returned -EAGAIN. A return code of -EAGAIN signals the +* calling function to roll the transaction, and then recall the subroutine to +* finish the operation. The enum is then used by the subroutine to jump back +* to where it was and resume executing where it left off. +*/ +enum xfs_delattr_state { +XFS_DAS_UNINIT =0 ,/* No state has been set yet */ +XFS_DAS_RM_SHRINK ,/* We are shrinking the tree */ +}; + +/* +* Defines for xfs_delattr_context.flags +*/ +#define XFS_DAC_DEFER_FINISH 0x01/* finish the transaction */ +#define XFS_DAC_NODE_RMVNAME_INIT 0x02/* xfs_attr_node_removename init */ + +/* +* Context used for keeping track of delayed attribute operations +*/ +struct xfs_delattr_context { +struct xfs_da_args *da_args; + +/* Used in xfs_attr_node_removename to roll through removing blocks */ +struct xfs_da_state *da_state; + +/* Used to keep track of current state of delayed operation */ +unsigned int flags; +enum xfs_delattr_state dela_state; +}; +/*======================================================================== * Function prototypes for the kernel. *========================================================================*/ @@ -91,6 +159,10 @@ int xfs_attr_set(struct xfs_da_args *args);int xfs_attr_set_args (struct xfs_da_args *args);int xfs_has_attr (struct xfs_da_args *args);int xfs_attr_remove_args (struct xfs_da_args *args); +int xfs_attr_remove_iter (struct xfs_delattr_context *dac); +int xfs_attr_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);#endif /* __XFS_ATTR_H__ */ 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 +15
-14@@ -674,10 +674,12 @@ xfs_attr_rmtval_invalidate(*/ int xfs_attr_rmtval_remove ( -struct xfs_da_args *args) +struct xfs_da_args *args) { -int error; -int retval; +int error; +struct xfs_delattr_context dac = { + .da_args = args, + };trace_xfs_attr_rmtval_remove (args);@@ -685,19 +687,17 @@ 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 ; -/* -* 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 ); -return 0 ; + }while (true); + +return error; }/* @@ -707,9 +707,10 @@ xfs_attr_rmtval_remove(*/ int __xfs_attr_rmtval_remove ( -struct xfs_da_args *args) +struct xfs_delattr_context *dac) { -int error, done; +struct xfs_da_args *args = dac->da_args; +int error, done;/* * Unmap value blocks for this attr. @@ -719,12 +720,10 @@ __xfs_attr_rmtval_remove(if (error)fs/xfs/libxfs/xfs_attr_remote.c __xfs_attr_rmtval_remove( · line 725
Quoted 10 lines
fs/xfs/libxfs/xfs_attr_remote.c +2
-5return error; - error =xfs_defer_finish (&args->trans); -if (error) -return error; - -if (!done) +if (!done) { + dac->flags |=XFS_DAC_DEFER_FINISH ;return -EAGAIN ;What state are we in when we return
-EAGAINhere?[jumps back to his whole-branch diff]
Hm, oh, I see, the next state could be a number of things--
RM_LBLKif we're removing an old remote value from a leaf block as part of an attr set operation; or
RM_NBLKif we're removing an old remote value from a node block as part of an attr set operation; andUNINIT if we're removing a remote value as part of an attr set operation.
Quoted 7 lines
Oh! For the first two, it looks to me as though either we're already in the state we're setting (RM_[LN]BLK) or we were in either of the FLIP_[LN]FLAG state.
I think it would make more sense if you set the state before calling the
rmtval_removefunction, and leave a comment here saying that the caller is responsible for figuring out the next state.
Sure, it should be ok
Quoted 5 lines
For removals, I wonder if we should have advanced beyond UNINIT by the time we get here? I think you've added the minimum states that are necessary to resume work after a transaction roll, but from this and the next patch I feel like we do a lot of work while
dela_state== UNINIT.
Yes, I think I went over that a little in my replies to your earlier reviews. Many times we can get away with out setting a state to accomplish the same behavior, though it may make it a little harder to visualize where it comes back.
I dunno this one seems like a preference in so far as what people want to see for simplification. I think haveing the explicit state setting makes the code easier for a reader to follow, though I will concede they dont actually have to be there to make it work.
Quoted 4 lines
FWIW I will be taking a close look at all the new 'return
-EAGAIN' statements to see if I can tell what state we're in when we trigger a transaction roll.
Well, ok, a lot of them are UNINIT. If we continue in the direrction of removing all unnecessary states, really it's the combination of the tree and the state that actually lands us back to where we need to be when the function is recalled.
If, for debugging or readability purposes, we wanted an explicit state for each EAGAIN, we would reintroduce a lot of states we've simplifid away over the reviews.
Maybe give it a day or two to sleep on, and let me know what you think :-)
Thanks for the reviews, I know it's really complicated. Allison
Quoted 37 lines
--D
Quoted 34 lines
fs/xfs/libxfs/xfs_attr_remote.c +1
-0+ }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 v13 02/10] xfs: Add delay ready attr remove routines
Quoted 151 lines · Allison Henderson
Quoted 140 lines · Darrick J. Wong
Quoted 73 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 | 200 +++++++++++++++++++++++++++++----------- fs/xfs/libxfs/xfs_attr.h | 72 +++++++++++++++ fs/xfs/libxfs/xfs_attr_leaf.c | 2 +- fs/xfs/libxfs/xfs_attr_remote.c | 37 ++++---- fs/xfs/libxfs/xfs_attr_remote.h | 2 +- fs/xfs/xfs_attr_inactive.c | 2 +- 6 files changed, 241 insertions(+), 74 deletions(-)fs/xfs/libxfs/xfs_attr.c +16
-1@@ -53,7 +53,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_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);@@ -264,6 +264,33 @@ xfs_attr_set_shortform( }/* +* 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 =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 fs/xfs/libxfs/xfs_attr.c xfs_attr_set_shortform( · line 290
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10
-0+* ops. +*/ + dac->flags &= ~XFS_DAC_DEFER_FINISH ; + error =xfs_defer_finish (&args->trans); +if (error) +return error; + } + +return xfs_trans_roll_inode (&args->trans, args->dp); +}(Mostly ignoring these functions since they all go away by the end of the patchset...)
Quoted 39 lines
fs/xfs/libxfs/xfs_attr.c +28
-3+ +/* * Set the attribute specified in @args. */ int @@ -364,23 +391,54 @@ 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 =0 ; +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. fs/xfs/libxfs/xfs_attr.c xfs_has_attr( · line 430
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10
-0+*/ +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 (dac->dela_state ==XFS_DAS_RM_SHRINK ) + goto node;Might as well just make this part of the if statement dispatch:
Quoted 4 lines
if (dac->dela_state == XFS_DAS_RM_SHRINK) return xfs_attr_node_removename_iter(dac); else if (!xfs_inode_hasattr(dp)) return -ENOATTR;I think we did this once, but then people disliked having the same call in two places. We call the node function if
XFS_DAS_RM_SHRINKis set OR if the other two cases fail which is actually the initial point of entry.
Quoted 8 lines
I think probably we need a comment somewhere. I've realized every time a question gets re-raised, it means we need a comment so we dont forget why :-)
Maybe for the goto we can have:
/* If we are shrinking a node, resume shrink */and.....
<shrug> This was a pretty minor point in my review, so if there's a better way of doing it, please feel free. :)
Admittedly I assume that a modern day compiler will slice and dice and rearrange to its heart's content, so for the most part I'm looking for higher level design errors and more or less don't care about the nitty gritty of what kind of machine code this all turns into.
(I'm probably doing that at everyone's peril, sadly...)
Quoted 64 lines
Quoted 18 lines
Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c +1
-2if (!xfs_inode_hasattr (dp)) { - error = -ENOATTR ; +return -ENOATTR ; }else if (dp->i_afp->if_format ==XFS_DINODE_FMT_LOCAL ) {ASSERT (dp->i_afp->if_flags &XFS_IFINLINE ); - error =xfs_attr_shortform_remove (args);fs/xfs/libxfs/xfs_attr.c xfs_has_attr( · line 440
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +3
-5+return xfs_attr_shortform_remove (args); }else if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) { - error =xfs_attr_leaf_removename (args); - }else { - error =xfs_attr_node_removename (args); +return xfs_attr_leaf_removename (args); } - -return error; +node:/* If we are not short form or leaf, then remove node */?
Quoted 6 lines
Quoted 6 lines
fs/xfs/libxfs/xfs_attr.c +1
-0+return xfs_attr_node_removename_iter (dac); }/* @@ -1178,10 +1236,11 @@ xfs_attr_leaf_mark_incomplete(*/ STATIC Quoted 9 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_leaf_mark_incomplete( · line 1240
Quoted 5 lines
fs/xfs/libxfs/xfs_attr.c +2
-2int xfs_attr_node_removename_setup ( -struct xfs_da_args *args, -struct xfs_da_state **state) +struct xfs_delattr_context *dac, +struct xfs_da_state **state)AFAICT *state ==
&dac->da_stateby the end of the series; can you should remove this argument too?Sure, I will see if I can collapse it down
Quoted 13 lines
Quoted 13 lines
fs/xfs/libxfs/xfs_attr.c +6
-1{ -int error; +struct xfs_da_args *args = dac->da_args; +int error; error =xfs_attr_node_hasname (args, state);if (error != -EEXIST )@@ -1191,6 +1250,12 @@ int xfs_attr_node_removename_setup(ASSERT ((*state)->path.blk[(*state)->path.active -1 ].magic ==XFS_ATTR_LEAF_MAGIC ); +/* +* Store state in the context incase we need to cycle out the +* transaction +*/ Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c int xfs_attr_node_removename_setup( · line 1260
Quoted 4 lines
fs/xfs/libxfs/xfs_attr.c +2
-0+ dac->da_state = *state; +if (args->rmtblkno >0 ) { error =xfs_attr_leaf_mark_incomplete (args, *state);It doesn't make a lot of logical sense to me "we marked the attr incomplete to hide it" is the same state (UNINIT) as "we haven't done anything yet".
Not sure I quite follow what you mean here. This little function is just a set up helper. It doesnt jump in an out like the other functions do with the state machine. We separated it out for that reason. This routine executes once to stash the state. The
da_state. not thedela_state. Different states :-)
Quoted 3 lines
So after we have that stored away, the calling function moves onto
xfs_attr_node_remove_step, which does get recalled quite a bit until there are no more remote blocks to remove.
<nod> I got that; I think my confusion here is that I was expecting each and every step to get its own state (which I think you said was how this used to be some ~5 revisions ago) even if it doesn't result in a transaction roll, whereas now the delattr code only introduces a new state when it needs to roll the transaction.
Hm. I've been reviewing this patchset by puzzling out each of the steps of the old attr setting and removing code, and then figuring out how the old code got from one step to another. Then I look at the end product of this whole patchset and try to figure out how the new state machine maps onto the old sequences, to determine if there are any serious discrepancies that also break things.
So I think in the first round of this review I was treading awfully close to suggesting that every little step of the old system had to become an explicit state in the new system's state machine, so that I could do a 1:1 comparison. That isn't the code that's before me now, and reworking all that sounds like (a) a big pain and (b) probably not where you and Brian were heading.
Perhaps an easier way to bridge the gap between the old way and the new way would be to make the ASCII art diagram call out each of these little steps (marking the attr incomplete, removing the value blocks, erasing the attr key, shrinking the attr tree, etc.) and then show where each of the XFS_DAS_* steps fall into that?
That way, the ASCII art would show that we start in XFS_DAS_UNINIT, mark the attr "incomplete", move on to XFS_DAS_RM_SHRINK, start removing attr blocks, etc. The machinery can omit the unnecessary pieces, so long as we have a map of the overall process.
How does that sound?
Quoted 135 lines
Quoted 44 lines
Quoted 44 lines
fs/xfs/libxfs/xfs_attr.c +15
-10if (error)@@ -1203,13 +1268,16 @@ int xfs_attr_node_removename_setup( } 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;@@ -1221,21 +1289,27 @@ xfs_attr_node_remove_rmt( }/* -* 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) { -struct xfs_da_state_blk *blk; -int retval, error;Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_remove_rmt( · line 1312
Quoted 6 lines
fs/xfs/libxfs/xfs_attr.c +5
-1-struct xfs_inode *dp = args->dp; +struct xfs_da_args *args = dac->da_args; +struct xfs_da_state *state; +struct xfs_da_state_blk *blk; +int retval, error =0 ; + state = dac->da_state;Might as well initialize this when you declare state above.
Sure
Quoted 40 lines
Quoted 40 lines
fs/xfs/libxfs/xfs_attr.c +11
-11/* * If there is an out-of-line value, de-allocate the blocks. @@ -1243,7 +1317,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; }@@ -1257,21 +1334,18 @@ xfs_attr_node_remove_step(xfs_da3_fixhashpath (state, &state->path);/* -* Check to see if the tree needs to be collapsed. +* Check to see if the tree needs to be collapsed. Set the flag to +* indicate that the calling function needs to move the to shrink +* operation */ 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; + + dac->flags |=XFS_DAC_DEFER_FINISH ; + dac->dela_state =XFS_DAS_RM_SHRINK ; +return -EAGAIN ;Quoted 9 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_remove_step( · line 1358
Quoted 6 lines
fs/xfs/libxfs/xfs_attr.c +0
-0}return error;@@ -1282,31 +1356,53 @@ xfs_attr_node_remove_step(* * This routine will find the blocks of the name to remove, remove them and * shirnk the tree if needed. "...and shrink the tree..."
Will fix the shirnk :-)
Quoted 21 lines
Quoted 21 lines
fs/xfs/libxfs/xfs_attr.c +12
-5+* +* 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; -int error; -struct xfs_inode *dp = args->dp; +struct xfs_da_args *args = dac->da_args; +struct xfs_da_state *state; +int error; +struct xfs_inode *dp = args->dp;trace_xfs_attr_node_removename (args); + state = dac->da_state;Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_remove_step( · line 1378
Quoted 5 lines
fs/xfs/libxfs/xfs_attr.c +2
-3- error =xfs_attr_node_removename_setup (args, &state); -if (error) - goto out; +if ((dac->flags &XFS_DAC_NODE_RMVNAME_INIT ) ==0 ) { + dac->flags |=XFS_DAC_NODE_RMVNAME_INIT ;Can we determine if it's necessary to call
_removename_setupby checkingdac->da_statedirectly instead of having a flag?
Quoted 8 lines
Initially I think I had another
XFS_DAS_RMTVAL_REMOVEstate for this. Alternatly we also discussed using the inverse like this:if (
dac->dela_state!=XFS_DAS_RMTVAL_REMOVE)do setup....Though I think people liked having the init flag, since init routines we a sort of re-occuring pattern. So that's why were using the flag now.
Oh, so (da_state != NULL) and (flags & XFS_DAC_NODE_RMVNAME_INIT) aren't a 1:1 correlation?
Quoted 249 lines
Quoted 22 lines
Quoted 9 lines
fs/xfs/libxfs/xfs_attr.c +5
-3+ error =xfs_attr_node_removename_setup (dac, &state); +if (error) + goto out; + } - error =xfs_attr_node_remove_step (args, state); -if (error) - goto out; +switch (dac->dela_state) {fs/xfs/libxfs/xfs_attr.c xfs_attr_node_remove_step( · line 1390
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +5
-5+case XFS_DAS_UNINIT : + error =xfs_attr_node_remove_step (dac); +if (error) +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); +/* do not break, proceed to shrink if needed */ /* fall through */
Quoted 6 lines
...because otherwise the static checkers will get mad.
(Well clang will anyway because gcc, llvm, and the C18 body all have different incompatible ideas of what should be the magic tag that signals an intentional fall through, but this should at least be consistent with the rest of xfs.)
Oh ok then, I did not know. Will update the comment
Quoted 200 lines
Quoted 174 lines
fs/xfs/libxfs/xfs_attr.c +14
-0+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 ); +return -EINVAL ; + } + +if (error == -EAGAIN ) +return error; out:if (state)xfs_da_state_free (state);fs/xfs/libxfs/xfs_attr.h +72
-0@@ -74,6 +74,74 @@ struct xfs_attr_list_context { }; +/* +* ======================================================================== +* Structure used to pass context around among the delayed routines. +* ======================================================================== +*/ + +/* +* Below is a state machine diagram for attr remove operations. The XFS_DAS_* +* states indicate places where the function would return -EAGAIN, and then +* immediately resume from after being recalled by the calling function. States +* marked as a "subroutine state" indicate that they belong to a subroutine, and +* so the calling function needs to pass them back to that subroutine to allow +* it to finish where it left off. But they otherwise do not have a role in the +* calling function other than just passing through. +* +* xfs_attr_remove_iter() +* XFS_DAS_RM_SHRINK ─┐ +* (subroutine state) │ +* └─>xfs_attr_node_removename() +* │ +* v +* need to +* shrink tree? ─n─┐ +* │ │ +* y │ +* │ │ +* v │ +* XFS_DAS_RM_SHRINK │ +* │ │ +* v │ +* done <─────┘ +* +*/ + +/* +* Enum values for xfs_delattr_context.da_state +* +* These values are used by delayed attribute operations to keep track of where +* they were before they returned -EAGAIN. A return code of -EAGAIN signals the +* calling function to roll the transaction, and then recall the subroutine to +* finish the operation. The enum is then used by the subroutine to jump back +* to where it was and resume executing where it left off. +*/ +enum xfs_delattr_state { +XFS_DAS_UNINIT =0 ,/* No state has been set yet */ +XFS_DAS_RM_SHRINK ,/* We are shrinking the tree */ +}; + +/* +* Defines for xfs_delattr_context.flags +*/ +#define XFS_DAC_DEFER_FINISH 0x01/* finish the transaction */ +#define XFS_DAC_NODE_RMVNAME_INIT 0x02/* xfs_attr_node_removename init */ + +/* +* Context used for keeping track of delayed attribute operations +*/ +struct xfs_delattr_context { +struct xfs_da_args *da_args; + +/* Used in xfs_attr_node_removename to roll through removing blocks */ +struct xfs_da_state *da_state; + +/* Used to keep track of current state of delayed operation */ +unsigned int flags; +enum xfs_delattr_state dela_state; +}; +/*======================================================================== * Function prototypes for the kernel. *========================================================================*/ @@ -91,6 +159,10 @@ int xfs_attr_set(struct xfs_da_args *args);int xfs_attr_set_args (struct xfs_da_args *args);int xfs_has_attr (struct xfs_da_args *args);int xfs_attr_remove_args (struct xfs_da_args *args); +int xfs_attr_remove_iter (struct xfs_delattr_context *dac); +int xfs_attr_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);#endif /* __XFS_ATTR_H__ */ 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 +15
-14@@ -674,10 +674,12 @@ xfs_attr_rmtval_invalidate(*/ int xfs_attr_rmtval_remove ( -struct xfs_da_args *args) +struct xfs_da_args *args) { -int error; -int retval; +int error; +struct xfs_delattr_context dac = { + .da_args = args, + };trace_xfs_attr_rmtval_remove (args);@@ -685,19 +687,17 @@ 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 ; -/* -* 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 ); -return 0 ; + }while (true); + +return error; }/* @@ -707,9 +707,10 @@ xfs_attr_rmtval_remove(*/ int __xfs_attr_rmtval_remove ( -struct xfs_da_args *args) +struct xfs_delattr_context *dac) { -int error, done; +struct xfs_da_args *args = dac->da_args; +int error, done;/* * Unmap value blocks for this attr. fs/xfs/libxfs/xfs_attr_remote.c __xfs_attr_rmtval_remove( · line 724
Quoted 10 lines
fs/xfs/libxfs/xfs_attr_remote.c +2
-5@@ -719,12 +720,10 @@ __xfs_attr_rmtval_remove(if (error)return error; - error =xfs_defer_finish (&args->trans); -if (error) -return error; - -if (!done) +if (!done) { + dac->flags |=XFS_DAC_DEFER_FINISH ;return -EAGAIN ;What state are we in when we return
-EAGAINhere?[jumps back to his whole-branch diff]
Hm, oh, I see, the next state could be a number of things--
RM_LBLKif we're removing an old remote value from a leaf block as part of an attr set operation; or
RM_NBLKif we're removing an old remote value from a node block as part of an attr set operation; andUNINIT if we're removing a remote value as part of an attr set operation.
Quoted 7 lines
Oh! For the first two, it looks to me as though either we're already in the state we're setting (RM_[LN]BLK) or we were in either of the FLIP_[LN]FLAG state.
I think it would make more sense if you set the state before calling the
rmtval_removefunction, and leave a comment here saying that the caller is responsible for figuring out the next state.Sure, it should be ok
Quoted 5 lines
For removals, I wonder if we should have advanced beyond UNINIT by the time we get here? I think you've added the minimum states that are necessary to resume work after a transaction roll, but from this and the next patch I feel like we do a lot of work while
dela_state== UNINIT.Yes, I think I went over that a little in my replies to your earlier reviews. Many times we can get away with out setting a state to accomplish the same behavior, though it may make it a little harder to visualize where it comes back.
Quoted 4 lines
I dunno this one seems like a preference in so far as what people want to see for simplification. I think haveing the explicit state setting makes the code easier for a reader to follow, though I will concede they dont actually have to be there to make it work.
<nod> Maybe (as I said earlier in this reply) we can get by with having the ascii art diagram point out all the things that happen while we're in "UNINIT" state before the first transaction roll.
I suspect that showing the steps and how the DAC state machine relates to those steps is the best we're going to be able to do w.r.t. restructuring a general key-value store implemented inside the kernel. :)
Quoted 9 lines
Quoted 4 lines
FWIW I will be taking a close look at all the new 'return
-EAGAIN' statements to see if I can tell what state we're in when we trigger a transaction roll.Well, ok, a lot of them are UNINIT. If we continue in the direrction of removing all unnecessary states, really it's the combination of the tree and the state that actually lands us back to where we need to be when the function is recalled.
Quoted 5 lines
If, for debugging or readability purposes, we wanted an explicit state for each EAGAIN, we would reintroduce a lot of states we've simplifid away over the reviews.
Maybe give it a day or two to sleep on, and let me know what you think :-)
<nod> OK.
--D
Quoted 39 lines
Thanks for the reviews, I know it's really complicated. Allison
Quoted 36 lines
--D
Quoted 33 lines
fs/xfs/libxfs/xfs_attr_remote.c +1
-0+ }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 v13 02/10] xfs: Add delay ready attr remove routines
Quoted 164 lines · Darrick J. Wong
Quoted 151 lines · Allison Henderson
Quoted 140 lines · Darrick J. Wong
Quoted 73 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 | 200 +++++++++++++++++++++++++++++----------- fs/xfs/libxfs/xfs_attr.h | 72 +++++++++++++++ fs/xfs/libxfs/xfs_attr_leaf.c | 2 +- fs/xfs/libxfs/xfs_attr_remote.c | 37 ++++---- fs/xfs/libxfs/xfs_attr_remote.h | 2 +- fs/xfs/xfs_attr_inactive.c | 2 +- 6 files changed, 241 insertions(+), 74 deletions(-)fs/xfs/libxfs/xfs_attr.c +16
-1@@ -53,7 +53,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_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);@@ -264,6 +264,33 @@ xfs_attr_set_shortform( }/* +* 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 =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 fs/xfs/libxfs/xfs_attr.c xfs_attr_set_shortform( · line 290
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10
-0+* ops. +*/ + dac->flags &= ~XFS_DAC_DEFER_FINISH ; + error =xfs_defer_finish (&args->trans); +if (error) +return error; + } + +return xfs_trans_roll_inode (&args->trans, args->dp); +}(Mostly ignoring these functions since they all go away by the end of the patchset...)
Quoted 39 lines
fs/xfs/libxfs/xfs_attr.c +28
-3+ +/* * Set the attribute specified in @args. */ int @@ -364,23 +391,54 @@ 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 =0 ; +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. fs/xfs/libxfs/xfs_attr.c xfs_has_attr( · line 430
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10
-0+*/ +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 (dac->dela_state ==XFS_DAS_RM_SHRINK ) + goto node;Might as well just make this part of the if statement dispatch:
Quoted 4 lines
if (dac->dela_state == XFS_DAS_RM_SHRINK) return xfs_attr_node_removename_iter(dac); else if (!xfs_inode_hasattr(dp)) return -ENOATTR;I think we did this once, but then people disliked having the same call in two places. We call the node function if
XFS_DAS_RM_SHRINKis set OR if the other two cases fail which is actually the initial point of entry.Quoted 8 lines
I think probably we need a comment somewhere. I've realized every time a question gets re-raised, it means we need a comment so we dont forget why :-)
Maybe for the goto we can have:
/* If we are shrinking a node, resume shrink */and.....
<shrug> This was a pretty minor point in my review, so if there's a better way of doing it, please feel free. :)
Quoted 6 lines
Admittedly I assume that a modern day compiler will slice and dice and rearrange to its heart's content, so for the most part I'm looking for higher level design errors and more or less don't care about the nitty gritty of what kind of machine code this all turns into.
(I'm probably doing that at everyone's peril, sadly...)
No worries, I just try my best to keep everyones commentary from prior review concidered. Just to make sure things keep moving in a progressive direction. At least as much as possible :-)
Quoted 69 lines
Quoted 65 lines
Quoted 19 lines
Quoted 9 lines
fs/xfs/libxfs/xfs_attr.c +1
-2if (!xfs_inode_hasattr (dp)) { - error = -ENOATTR ; +return -ENOATTR ; }else if (dp->i_afp->if_format ==XFS_DINODE_FMT_LOCAL ) {ASSERT (dp->i_afp->if_flags &XFS_IFINLINE ); - error =xfs_attr_shortform_remove (args);fs/xfs/libxfs/xfs_attr.c xfs_has_attr( · line 440
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +3
-5+return xfs_attr_shortform_remove (args); }else if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) { - error =xfs_attr_leaf_removename (args); - }else { - error =xfs_attr_node_removename (args); +return xfs_attr_leaf_removename (args); } - -return error; +node:/* If we are not short form or leaf, then remove node */?
Quoted 6 lines
Quoted 6 lines
fs/xfs/libxfs/xfs_attr.c +1
-0+return xfs_attr_node_removename_iter (dac); }/* @@ -1178,10 +1236,11 @@ xfs_attr_leaf_mark_incomplete(*/ STATIC Quoted 9 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_leaf_mark_incomplete( · line 1240
Quoted 5 lines
fs/xfs/libxfs/xfs_attr.c +2
-2int xfs_attr_node_removename_setup ( -struct xfs_da_args *args, -struct xfs_da_state **state) +struct xfs_delattr_context *dac, +struct xfs_da_state **state)AFAICT *state ==
&dac->da_stateby the end of the series; can you should remove this argument too?Sure, I will see if I can collapse it down
Quoted 13 lines
Quoted 13 lines
fs/xfs/libxfs/xfs_attr.c +6
-1{ -int error; +struct xfs_da_args *args = dac->da_args; +int error; error =xfs_attr_node_hasname (args, state);if (error != -EEXIST )@@ -1191,6 +1250,12 @@ int xfs_attr_node_removename_setup(ASSERT ((*state)->path.blk[(*state)->path.active -1 ].magic ==XFS_ATTR_LEAF_MAGIC ); +/* +* Store state in the context incase we need to cycle out the +* transaction +*/ Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c int xfs_attr_node_removename_setup( · line 1260
Quoted 4 lines
fs/xfs/libxfs/xfs_attr.c +2
-0+ dac->da_state = *state; +if (args->rmtblkno >0 ) { error =xfs_attr_leaf_mark_incomplete (args, *state);It doesn't make a lot of logical sense to me "we marked the attr incomplete to hide it" is the same state (UNINIT) as "we haven't done anything yet".
Not sure I quite follow what you mean here. This little function is just a set up helper. It doesnt jump in an out like the other functions do with the state machine. We separated it out for that reason. This routine executes once to stash the state. The
da_state. not thedela_state. Different states :-)Quoted 3 lines
So after we have that stored away, the calling function moves onto
xfs_attr_node_remove_step, which does get recalled quite a bit until there are no more remote blocks to remove.
Quoted 5 lines
<nod> I got that; I think my confusion here is that I was expecting each and every step to get its own state (which I think you said was how this used to be some ~5 revisions ago) even if it doesn't result in a transaction roll, whereas now the delattr code only introduces a new state when it needs to roll the transaction.
Well, I think the correct way to phrase it would be: all states are associated with an EAGAIN return (and thus a transaction roll), but not all such returns require a state. If there is something else that can be used in place of a state, we use that instead. Such at the state of the tree for example.
Quoted 7 lines
Hm. I've been reviewing this patchset by puzzling out each of the steps of the old attr setting and removing code, and then figuring out how the old code got from one step to another. Then I look at the end product of this whole patchset and try to figure out how the new state machine maps onto the old sequences, to determine if there are any serious discrepancies that also break things.
Oh gosh, that's a lot. Thank you for the thorough review though!
Quoted 7 lines
So I think in the first round of this review I was treading awfully close to suggesting that every little step of the old system had to become an explicit state in the new system's state machine, so that I could do a 1:1 comparison. That isn't the code that's before me now, and reworking all that sounds like (a) a big pain and (b) probably not where you and Brian were heading.
mmm, it wouldnt be tooooo bad. But I do think it's important for people to be on the same page about it so that everybody is happy and comfortable with the result. And to make sure development is moving in a progressive direction.
To be clear, putting back the explicit states would mean the re-installment of the pattern:
dac->dela_state = XFS_DAS_NEW_STATE; return -EAGAIN;
das_new_state:
For every "return -EAGAIN" that doesnt have an explicit state.
For the most part, I got the impression that people perceive this to be a sort of unpleasant pattern to look at, and would like to see it culled away where it can be though.
Quoted 6 lines
Perhaps an easier way to bridge the gap between the old way and the new way would be to make the ASCII art diagram call out each of these little steps (marking the attr incomplete, removing the value blocks, erasing the attr key, shrinking the attr tree, etc.) and then show where each of the XFS_DAS_* steps fall into that?
Sure, I can flesh out the diagram a bit more
Quoted 7 lines
That way, the ASCII art would show that we start in
XFS_DAS_UNINIT, mark the attr "incomplete", move on toXFS_DAS_RM_SHRINK, start removing attr blocks, etc. The machinery can omit the unnecessary pieces, so long as we have a map of the overall process.How does that sound?
That sounds reasonable :-)
Quoted 139 lines
Quoted 139 lines
Quoted 45 lines
Quoted 45 lines
fs/xfs/libxfs/xfs_attr.c +15
-10if (error)@@ -1203,13 +1268,16 @@ int xfs_attr_node_removename_setup( } 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;@@ -1221,21 +1289,27 @@ xfs_attr_node_remove_rmt( }/* -* 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) { -struct xfs_da_state_blk *blk; -int retval, error;Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_remove_rmt( · line 1312
Quoted 6 lines
fs/xfs/libxfs/xfs_attr.c +5
-1-struct xfs_inode *dp = args->dp; +struct xfs_da_args *args = dac->da_args; +struct xfs_da_state *state; +struct xfs_da_state_blk *blk; +int retval, error =0 ; + state = dac->da_state;Might as well initialize this when you declare state above.
Sure
Quoted 40 lines
Quoted 40 lines
fs/xfs/libxfs/xfs_attr.c +11
-11/* * If there is an out-of-line value, de-allocate the blocks. @@ -1243,7 +1317,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; }@@ -1257,21 +1334,18 @@ xfs_attr_node_remove_step(xfs_da3_fixhashpath (state, &state->path);/* -* Check to see if the tree needs to be collapsed. +* Check to see if the tree needs to be collapsed. Set the flag to +* indicate that the calling function needs to move the to shrink +* operation */ 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; + + dac->flags |=XFS_DAC_DEFER_FINISH ; + dac->dela_state =XFS_DAS_RM_SHRINK ; +return -EAGAIN ;Quoted 9 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_remove_step( · line 1358
Quoted 6 lines
fs/xfs/libxfs/xfs_attr.c +0
-0}return error;@@ -1282,31 +1356,53 @@ xfs_attr_node_remove_step(* * This routine will find the blocks of the name to remove, remove them and * shirnk the tree if needed. "...and shrink the tree..."
Will fix the shirnk :-)
Quoted 21 lines
Quoted 21 lines
fs/xfs/libxfs/xfs_attr.c +12
-5+* +* 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; -int error; -struct xfs_inode *dp = args->dp; +struct xfs_da_args *args = dac->da_args; +struct xfs_da_state *state; +int error; +struct xfs_inode *dp = args->dp;trace_xfs_attr_node_removename (args); + state = dac->da_state;Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_remove_step( · line 1378
Quoted 5 lines
fs/xfs/libxfs/xfs_attr.c +2
-3- error =xfs_attr_node_removename_setup (args, &state); -if (error) - goto out; +if ((dac->flags &XFS_DAC_NODE_RMVNAME_INIT ) ==0 ) { + dac->flags |=XFS_DAC_NODE_RMVNAME_INIT ;Can we determine if it's necessary to call
_removename_setupby checkingdac->da_statedirectly instead of having a flag?Initially I think I had another
XFS_DAS_RMTVAL_REMOVEstate for this. Alternatly we also discussed using the inverse like this:
Quoted 8 lines
Quoted 5 lines
if (
dac->dela_state!=XFS_DAS_RMTVAL_REMOVE)do setup....Though I think people liked having the init flag, since init routines we a sort of re-occuring pattern. So that's why were using the flag now.
Oh, so (
da_state!= NULL) and (flags &XFS_DAC_NODE_RMVNAME_INIT) aren't a 1:1 correlation?
Oooh, sorry... I was refering to the wrong state variable. Yes, da_state should never be null after it is set, so that should work. Will update :-)
Quoted 255 lines
Quoted 250 lines
Quoted 23 lines
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +5
-3+ error =xfs_attr_node_removename_setup (dac, &state); +if (error) + goto out; + } - error =xfs_attr_node_remove_step (args, state); -if (error) - goto out; +switch (dac->dela_state) {fs/xfs/libxfs/xfs_attr.c xfs_attr_node_remove_step( · line 1390
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +5
-5+case XFS_DAS_UNINIT : + error =xfs_attr_node_remove_step (dac); +if (error) +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); +/* do not break, proceed to shrink if needed */ /* fall through */
Quoted 6 lines
...because otherwise the static checkers will get mad.
(Well clang will anyway because gcc, llvm, and the C18 body all have different incompatible ideas of what should be the magic tag that signals an intentional fall through, but this should at least be consistent with the rest of xfs.)
Oh ok then, I did not know. Will update the comment
Quoted 200 lines
Quoted 174 lines
fs/xfs/libxfs/xfs_attr.c +14
-0+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 ); +return -EINVAL ; + } + +if (error == -EAGAIN ) +return error; out:if (state)xfs_da_state_free (state);fs/xfs/libxfs/xfs_attr.h +72
-0@@ -74,6 +74,74 @@ struct xfs_attr_list_context { }; +/* +* ======================================================================== +* Structure used to pass context around among the delayed routines. +* ======================================================================== +*/ + +/* +* Below is a state machine diagram for attr remove operations. The XFS_DAS_* +* states indicate places where the function would return -EAGAIN, and then +* immediately resume from after being recalled by the calling function. States +* marked as a "subroutine state" indicate that they belong to a subroutine, and +* so the calling function needs to pass them back to that subroutine to allow +* it to finish where it left off. But they otherwise do not have a role in the +* calling function other than just passing through. +* +* xfs_attr_remove_iter() +* XFS_DAS_RM_SHRINK ─┐ +* (subroutine state) │ +* └─>xfs_attr_node_removename() +* │ +* v +* need to +* shrink tree? ─n─┐ +* │ │ +* y │ +* │ │ +* v │ +* XFS_DAS_RM_SHRINK │ +* │ │ +* v │ +* done <─────┘ +* +*/ + +/* +* Enum values for xfs_delattr_context.da_state +* +* These values are used by delayed attribute operations to keep track of where +* they were before they returned -EAGAIN. A return code of -EAGAIN signals the +* calling function to roll the transaction, and then recall the subroutine to +* finish the operation. The enum is then used by the subroutine to jump back +* to where it was and resume executing where it left off. +*/ +enum xfs_delattr_state { +XFS_DAS_UNINIT =0 ,/* No state has been set yet */ +XFS_DAS_RM_SHRINK ,/* We are shrinking the tree */ +}; + +/* +* Defines for xfs_delattr_context.flags +*/ +#define XFS_DAC_DEFER_FINISH 0x01/* finish the transaction */ +#define XFS_DAC_NODE_RMVNAME_INIT 0x02/* xfs_attr_node_removename init */ + +/* +* Context used for keeping track of delayed attribute operations +*/ +struct xfs_delattr_context { +struct xfs_da_args *da_args; + +/* Used in xfs_attr_node_removename to roll through removing blocks */ +struct xfs_da_state *da_state; + +/* Used to keep track of current state of delayed operation */ +unsigned int flags; +enum xfs_delattr_state dela_state; +}; +/*======================================================================== * Function prototypes for the kernel. *========================================================================*/ @@ -91,6 +159,10 @@ int xfs_attr_set(struct xfs_da_args *args);int xfs_attr_set_args (struct xfs_da_args *args);int xfs_has_attr (struct xfs_da_args *args);int xfs_attr_remove_args (struct xfs_da_args *args); +int xfs_attr_remove_iter (struct xfs_delattr_context *dac); +int xfs_attr_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);#endif /* __XFS_ATTR_H__ */ 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 +15
-14@@ -674,10 +674,12 @@ xfs_attr_rmtval_invalidate(*/ int xfs_attr_rmtval_remove ( -struct xfs_da_args *args) +struct xfs_da_args *args) { -int error; -int retval; +int error; +struct xfs_delattr_context dac = { + .da_args = args, + };trace_xfs_attr_rmtval_remove (args);@@ -685,19 +687,17 @@ 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 ; -/* -* 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 ); -return 0 ; + }while (true); + +return error; }/* @@ -707,9 +707,10 @@ xfs_attr_rmtval_remove(*/ int __xfs_attr_rmtval_remove ( -struct xfs_da_args *args) +struct xfs_delattr_context *dac) { -int error, done; +struct xfs_da_args *args = dac->da_args; +int error, done;/* * Unmap value blocks for this attr. fs/xfs/libxfs/xfs_attr_remote.c __xfs_attr_rmtval_remove( · line 724
Quoted 10 lines
fs/xfs/libxfs/xfs_attr_remote.c +2
-5@@ -719,12 +720,10 @@ __xfs_attr_rmtval_remove(if (error)return error; - error =xfs_defer_finish (&args->trans); -if (error) -return error; - -if (!done) +if (!done) { + dac->flags |=XFS_DAC_DEFER_FINISH ;return -EAGAIN ;What state are we in when we return
-EAGAINhere?[jumps back to his whole-branch diff]
Hm, oh, I see, the next state could be a number of things--
RM_LBLKif we're removing an old remote value from a leaf block as part of an attr set operation; or
RM_NBLKif we're removing an old remote value from a node block as part of an attr set operation; andUNINIT if we're removing a remote value as part of an attr set operation.
Quoted 7 lines
Oh! For the first two, it looks to me as though either we're already in the state we're setting (RM_[LN]BLK) or we were in either of the FLIP_[LN]FLAG state.
I think it would make more sense if you set the state before calling the
rmtval_removefunction, and leave a comment here saying that the caller is responsible for figuring out the next state.Sure, it should be ok
Quoted 5 lines
For removals, I wonder if we should have advanced beyond UNINIT by the time we get here? I think you've added the minimum states that are necessary to resume work after a transaction roll, but from this and the next patch I feel like we do a lot of work while
dela_state== UNINIT.Yes, I think I went over that a little in my replies to your earlier reviews. Many times we can get away with out setting a state to accomplish the same behavior, though it may make it a little harder to visualize where it comes back.
Quoted 4 lines
I dunno this one seems like a preference in so far as what people want to see for simplification. I think haveing the explicit state setting makes the code easier for a reader to follow, though I will concede they dont actually have to be there to make it work.
Quoted 9 lines
<nod> Maybe (as I said earlier in this reply) we can get by with having the ascii art diagram point out all the things that happen while we're in "UNINIT" state before the first transaction roll.
I suspect that showing the steps and how the DAC state machine relates to those steps is the best we're going to be able to do w.r.t. restructuring a general key-value store implemented inside the kernel. :)
Alrighty, that sounds reasonable
Thank you for all the feed back!!
Allison
Quoted 58 lines
Quoted 9 lines
Quoted 4 lines
FWIW I will be taking a close look at all the new 'return
-EAGAIN' statements to see if I can tell what state we're in when we trigger a transaction roll.Well, ok, a lot of them are UNINIT. If we continue in the direrction of removing all unnecessary states, really it's the combination of the tree and the state that actually lands us back to where we need to be when the function is recalled.
Quoted 5 lines
If, for debugging or readability purposes, we wanted an explicit state for each EAGAIN, we would reintroduce a lot of states we've simplifid away over the reviews.
Maybe give it a day or two to sleep on, and let me know what you think :-)
<nod> OK.
--D
Quoted 39 lines
Thanks for the reviews, I know it's really complicated. Allison
Quoted 36 lines
--D
Quoted 33 lines
fs/xfs/libxfs/xfs_attr_remote.c +1
-0+ }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 v13 3/10 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_set_init and xfs_attr_rmtval_set_blk. They provide a subset of logic similar to xfs_attr_rmtval_set, but they store the current block in the delay attr context to allow the caller to roll the transaction between allocations. This helps to simplify and consolidate code used by xfs_attr_leaf_addname and xfs_attr_node_addname. xfs_attr_set_args has now become a simple loop to refresh the transaction until the operation is completed. Lastly, xfs_attr_rmtval_remove is no longer used, and is removed.
--- fs/xfs/libxfs/xfs_attr.c | 370 ++++++++++++++++++++++++++-------------- fs/xfs/libxfs/xfs_attr.h | 126 +++++++++++++- fs/xfs/libxfs/xfs_attr_remote.c | 99 +++++++---- fs/xfs/libxfs/xfs_attr_remote.h | 4 + fs/xfs/xfs_trace.h | 1 - 5 files changed, 439 insertions(+), 161 deletions(-)
fs/xfs/libxfs/xfs_attr.c +245 -125
@@ -44,7 +44,7 @@ STATIC int xfs_attr_shortform_addname(xfs_da_args_t *args);* Internal routines when attribute list is one block. */ STATIC int xfs_attr_leaf_get(xfs_da_args_t *args); -STATIC int xfs_attr_leaf_addname(xfs_da_args_t *args); +STATIC int xfs_attr_leaf_addname(struct xfs_delattr_context *dac); STATIC int xfs_attr_leaf_removename(xfs_da_args_t *args); STATIC int xfs_attr_leaf_hasname(struct xfs_da_args *args, struct xfs_buf **bp);
@@ -52,12 +52,15 @@ STATIC int xfs_attr_leaf_hasname(struct xfs_da_args *args, struct xfs_buf **bp);* Internal routines when attribute list is more than one block. */ STATIC int xfs_attr_node_get(xfs_da_args_t *args); -STATIC int xfs_attr_node_addname(xfs_da_args_t *args); +STATIC int xfs_attr_node_addname(struct xfs_delattr_context *dac); STATIC int xfs_attr_node_removename_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_leaf_try_add(struct xfs_da_args *args, struct xfs_buf *bp); +STATIC int xfs_attr_set_iter(struct xfs_delattr_context *dac, +struct xfs_buf **leaf_bp);int xfs_inode_hasattr(
@@ -218,8 +221,11 @@ xfs_attr_is_shortform(/* * Attempts to set an attr in shortform, or converts short form to leaf form if -* there is not enough room. If the attr is set, the transaction is committed -* and set to NULL. +* there is not enough room. This function is meant to operate as a helper +* routine to the delayed attribute functions. It returns -EAGAIN to indicate +* that the calling function should roll the transaction, and then proceed to +* add the attr in leaf form. This subroutine does not expect to be recalled +* again like the other delayed attr routines do. */ STATIC int xfs_attr_set_shortform(
@@ -227,16 +233,16 @@ xfs_attr_set_shortform( struct xfs_buf **leaf_bp) {struct xfs_inode *dp = args->dp; -int error, error2 =0 ; +int error =0 ;/* * Try to add the attr to the attribute list in the inode. */ error =xfs_attr_try_sf_addname (dp, args); + +/* Should only be 0, -EEXIST or ENOSPC */ if (error != -ENOSPC ) { - error2 =xfs_trans_commit (args->trans); - args->trans =NULL ; -return error ? error : error2; +return error; }/* * It won't fit in the shortform, transform to a leaf block. GROT:
@@ -249,18 +255,10 @@ xfs_attr_set_shortform(/* * Prevent the leaf buffer from being unlocked so that a concurrent AIL * push cannot grab the half-baked leaf buffer and run into problems -* with the write verifier. Once we're done rolling the transaction we -* can release the hold and add the attr to the leaf. +* with the write verifier. */ xfs_trans_bhold (args->trans, *leaf_bp); - error =xfs_defer_finish (&args->trans); -xfs_trans_bhold_release (args->trans, *leaf_bp); -if (error) { -xfs_trans_brelse (args->trans, *leaf_bp); -return error; - } - -return 0 ; +return -EAGAIN ; }/*
@@ -268,7 +266,7 @@ xfs_attr_set_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) {
@@ -297,61 +295,130 @@ intxfs_attr_set_args ( struct xfs_da_args *args) { -struct xfs_inode *dp = args->dp; -struct xfs_buf *leaf_bp =NULL ; -int error =0 ; +struct xfs_buf *leaf_bp =NULL ; +int error =0 ; +struct xfs_delattr_context dac = { + .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; + +if (leaf_bp) { +xfs_trans_bjoin (args->trans, leaf_bp); +xfs_trans_bhold (args->trans, leaf_bp); + } + + }while (true); + +return error; +} + +/* +* Set the attribute specified in @args. +* This routine is meant to function as a delayed operation, and may return +* -EAGAIN when the transaction needs to be rolled. Calling functions will need +* to handle this, and recall the function until a successful error code is +* returned. +*/ +STATIC int +xfs_attr_set_iter ( +struct xfs_delattr_context *dac, +struct xfs_buf **leaf_bp) +{ +struct xfs_da_args *args = dac->da_args; +struct xfs_inode *dp = args->dp; +int error =0 ; + +/* State machine switch */ +switch (dac->dela_state) { +case XFS_DAS_FLIP_LFLAG : +case XFS_DAS_FOUND_LBLK : + goto das_leaf; +case XFS_DAS_FOUND_NBLK : +case XFS_DAS_FLIP_NFLAG : +case XFS_DAS_ALLOC_NODE : + goto das_node; +default : +break ; + }/* * If the attribute list is already in leaf format, jump straight to * leaf handling. Otherwise, try to add the attribute to the shortform * list; if there's no room then convert the list to leaf format and try -* again. +* again. No need to set state as we will be in leaf form when we come +* back */ if (xfs_attr_is_shortform (dp)) {/* -* If the attr was successfully set in shortform, the -* transaction is committed and set to NULL. Otherwise, is it -* converted from shortform to leaf, and the transaction is -* retained. +* If the attr was successfully set in shortform, no need to +* continue. Otherwise, is it converted from shortform to leaf +* and -EAGAIN is returned. */ - error =xfs_attr_set_shortform (args, &leaf_bp); -if (error || !args->trans) -return error; + error =xfs_attr_set_shortform (args, leaf_bp); +if (error == -EAGAIN ) + dac->flags |=XFS_DAC_DEFER_FINISH ; + +return error; } -if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) { - error =xfs_attr_leaf_addname (args); -if (error != -ENOSPC ) -return error; +/* +* After a shortform to leaf conversion, we need to hold the leaf and +* cycle out the transaction. When we get back, we need to release +* the leaf. +*/ +if (*leaf_bp !=NULL ) { +xfs_trans_bhold_release (args->trans, *leaf_bp); + *leaf_bp =NULL ; + } -/* -* Promote the attribute list to the Btree format. -*/ - error =xfs_attr3_leaf_to_node (args); -if (error) -return error; +if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) { + error =xfs_attr_leaf_try_add (args, *leaf_bp); +switch (error) { +case -ENOSPC : +/* +* Promote the attribute list to the Btree format. +*/ + error =xfs_attr3_leaf_to_node (args); +if (error) +return error; -/* -* 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) +/* +* 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. +*/ + dac->flags |=XFS_DAC_DEFER_FINISH ; +return -EAGAIN ; +case 0 : + dac->dela_state =XFS_DAS_FOUND_LBLK ; +return -EAGAIN ; +default :return error; + } +das_leaf: + error =xfs_attr_leaf_addname (dac); +if (error == -ENOSPC ) +/* +* No need to set state. We will be in node form when +* we are recalled +*/ +return -EAGAIN ; -/* -* Commit the current trans (including the inode) and -* start a new one. -*/ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) -return error; +return error; } - - error =xfs_attr_node_addname (args); +das_node: + error =xfs_attr_node_addname (dac);return error; }
@@ -723,28 +790,30 @@ xfs_attr_leaf_try_add(* * This leaf block cannot have a "remote" value, we only call this routine * if bmap_one_block() says there is only one block (ie: no remote blks). +* +* This routine is meant to function as a delayed operation, and may return +* -EAGAIN when the transaction needs to be rolled. Calling functions will need +* to handle this, and recall the function until a successful error code is +* returned. */ STATIC intxfs_attr_leaf_addname ( -struct xfs_da_args *args) +struct xfs_delattr_context *dac) { -int error, forkoff; -struct xfs_buf *bp =NULL ; -struct xfs_inode *dp = args->dp; - -trace_xfs_attr_leaf_addname (args); - - error =xfs_attr_leaf_try_add (args, bp); -if (error) -return error; +struct xfs_da_args *args = dac->da_args; +struct xfs_buf *bp =NULL ; +int error, forkoff; +struct xfs_inode *dp = args->dp; -/* -* Commit the transaction that added the attr name so that -* later routines can manage their own transactions. -*/ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) -return error; +/* State machine switch */ +switch (dac->dela_state) { +case XFS_DAS_FLIP_LFLAG : + goto das_flip_flag; +case XFS_DAS_RM_LBLK : + goto das_rm_lblk; +default : +break ; + }/* * If there was an out-of-line value, allocate the blocks we
@@ -752,12 +821,34 @@ xfs_attr_leaf_addname(* after we create the attribute so that we don't overflow the * maximum size of a transaction and/or hit a deadlock. */ -if (args->rmtblkno >0 ) { - error =xfs_attr_rmtval_set (args); + +/* Open coded xfs_attr_rmtval_set without trans handling */ +if ((dac->flags &XFS_DAC_LEAF_ADDNAME_INIT ) ==0 ) { + dac->flags |=XFS_DAC_LEAF_ADDNAME_INIT ; +if (args->rmtblkno >0 ) { + error =xfs_attr_rmtval_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; + + dac->flags |=XFS_DAC_DEFER_FINISH ; +return -EAGAIN ; } + error =xfs_attr_rmtval_set_value (args); +if (error) +return error; +if (!(args->op_flags &XFS_DA_OP_RENAME )) {/* * Added a "remote" value, just clear the incomplete flag.
@@ -777,29 +868,29 @@ xfs_attr_leaf_addname(* In a separate transaction, set the incomplete flag on the "old" attr * and clear the incomplete flag on the "new" attr. */ - error =xfs_attr3_leaf_flipflags (args);if (error)return error;/* * Commit the flag value change and start the next trans in series. */ - error =xfs_trans_roll_inode (&args->trans, args->dp); -if (error) -return error; - + dac->dela_state =XFS_DAS_FLIP_LFLAG ; +return -EAGAIN ; +das_flip_flag:/* * Dismantle the "old" attribute/value pair by removing a "remote" value * (if it exists). */ xfs_attr_restore_rmt_blk (args); + error =xfs_attr_rmtval_invalidate (args); +if (error) +return error; +das_rm_lblk:if (args->rmtblkno) { - error =xfs_attr_rmtval_invalidate (args); -if (error) -return error; - - error =xfs_attr_rmtval_remove (args); + error =__xfs_attr_rmtval_remove (dac); +if (error == -EAGAIN ) + dac->dela_state =XFS_DAS_RM_LBLK ;if (error)return error; }
@@ -965,23 +1056,38 @@ xfs_attr_node_hasname(* * "Remote" attribute values confuse the issue and atomic rename operations * add a whole extra layer of confusion on top of that. +* +* This routine is meant to function as a delayed operation, and may return +* -EAGAIN when the transaction needs to be rolled. Calling functions will need +* to handle this, and recall the function until a successful error code is +*returned. */ STATIC intxfs_attr_node_addname ( -struct xfs_da_args *args) +struct xfs_delattr_context *dac) { -struct xfs_da_state *state; -struct xfs_da_state_blk *blk; -struct xfs_inode *dp; -int retval, error; +struct xfs_da_args *args = dac->da_args; +struct xfs_da_state *state =NULL ; +struct xfs_da_state_blk *blk; +int retval =0 ; +int error =0 ;trace_xfs_attr_node_addname (args); -/* -* Fill in bucket of arguments/results/context to carry around. -*/ - dp = args->dp; -restart: +/* State machine switch */ +switch (dac->dela_state) { +case XFS_DAS_FLIP_NFLAG : + goto das_flip_flag; +case XFS_DAS_FOUND_NBLK : + goto das_found_nblk; +case XFS_DAS_ALLOC_NODE : + goto das_alloc_node; +case XFS_DAS_RM_NBLK : + goto das_rm_nblk; +default : +break ; + } +/* * Search to see if name already exists, and get back a pointer * to where it should go.
@@ -1027,19 +1133,13 @@ xfs_attr_node_addname( error =xfs_attr3_leaf_to_node (args);if (error) goto out; - error =xfs_defer_finish (&args->trans); -if (error) - goto out;/* -* Commit the node conversion and start the next -* trans in the chain. +* Restart routine from the top. No need to set the +* state */ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) - goto out; - - goto restart; + dac->flags |=XFS_DAC_DEFER_FINISH ; +return -EAGAIN ; }/*
@@ -1051,9 +1151,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.
@@ -1068,13 +1166,9 @@ xfs_attr_node_addname(xfs_da_state_free (state); state =NULL ; -/* -* Commit the leaf addition or btree split and start the next -* trans in the chain. -*/ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) - goto out; + dac->dela_state =XFS_DAS_FOUND_NBLK ; +return -EAGAIN ; +das_found_nblk:/* * If there was an out-of-line value, allocate the blocks we
@@ -1083,7 +1177,27 @@ xfs_attr_node_addname(* maximum size of a transaction and/or hit a deadlock. */ if (args->rmtblkno >0 ) { - error =xfs_attr_rmtval_set (args); +/* Open coded xfs_attr_rmtval_set without trans handling */ + error =xfs_attr_rmtval_find_space (dac); +if (error) +return error; + +/* +* Roll through the "value", allocating blocks on disk as +* required. +*/ +das_alloc_node: +if (dac->blkcnt >0 ) { + error =xfs_attr_rmtval_set_blk (dac); +if (error) +return error; + + dac->flags |=XFS_DAC_DEFER_FINISH ; + dac->dela_state =XFS_DAS_ALLOC_NODE ; +return -EAGAIN ; + } + + error =xfs_attr_rmtval_set_value (args);if (error)return error; }
@@ -1113,22 +1227,28 @@ xfs_attr_node_addname(/* * Commit the flag value change and start the next trans in series */ - error =xfs_trans_roll_inode (&args->trans, args->dp); -if (error) - goto out; - + dac->dela_state =XFS_DAS_FLIP_NFLAG ; +return -EAGAIN ; +das_flip_flag:/* * Dismantle the "old" attribute/value pair by removing a "remote" value * (if it exists). */ xfs_attr_restore_rmt_blk (args); + error =xfs_attr_rmtval_invalidate (args); +if (error) +return error; + +das_rm_nblk:if (args->rmtblkno) { - error =xfs_attr_rmtval_invalidate (args); -if (error) -return error; + error =__xfs_attr_rmtval_remove (dac); + +if (error == -EAGAIN ) { + dac->dela_state =XFS_DAS_RM_NBLK ; +return -EAGAIN ; + } - error =xfs_attr_rmtval_remove (args);if (error)return error; }
fs/xfs/libxfs/xfs_attr.h +125 -1
156 lines not on this page · raw message
fs/xfs/libxfs/xfs_attr_remote.c +65 -34
123 lines not on this page · raw message
fs/xfs/libxfs/xfs_attr_remote.h +4 -0
@@ -15,4 +15,8 @@ int xfs_attr_rmtval_stale(struct xfs_inode *ip, struct xfs_bmbt_irec *map, xfs_buf_flags_t incore_flags);int xfs_attr_rmtval_invalidate (struct xfs_da_args *args);int __xfs_attr_rmtval_remove (struct xfs_delattr_context *dac); +int xfs_attr_rmt_find_hole (struct xfs_da_args *args); +int xfs_attr_rmtval_set_value (struct xfs_da_args *args); +int xfs_attr_rmtval_set_blk (struct xfs_delattr_context *dac); +int xfs_attr_rmtval_find_space (struct xfs_delattr_context *dac);#endif /* __XFS_ATTR_REMOTE_H__ */
fs/xfs/xfs_trace.h +0 -1
@@ -1925,7 +1925,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 v13 03/10] xfs: Add delay ready attr set routines
Quoted 7 lines · IST 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.
Quoted 9 lines
Two new helper functions have been added:
xfs_attr_rmtval_set_initandxfs_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.
One nit. xfs_attr_rmtval_remove()'s prototype declaration needs to be removed from xfs_attr_remote.h.
Quoted 121 lines
Signed-off-by Allison Henderson <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 370 ++++++++++++++++++++++++++-------------- fs/xfs/libxfs/xfs_attr.h | 126 +++++++++++++- fs/xfs/libxfs/xfs_attr_remote.c | 99 +++++++---- fs/xfs/libxfs/xfs_attr_remote.h | 4 + fs/xfs/xfs_trace.h | 1 - 5 files changed, 439 insertions(+), 161 deletions(-)fs/xfs/libxfs/xfs_attr.c +26
-22@@ -44,7 +44,7 @@ STATIC int xfs_attr_shortform_addname(xfs_da_args_t *args);* Internal routines when attribute list is one block. */ STATIC int xfs_attr_leaf_get(xfs_da_args_t *args); -STATIC int xfs_attr_leaf_addname(xfs_da_args_t *args); +STATIC int xfs_attr_leaf_addname(struct xfs_delattr_context *dac); STATIC int xfs_attr_leaf_removename(xfs_da_args_t *args); STATIC int xfs_attr_leaf_hasname(struct xfs_da_args *args, struct xfs_buf **bp);@@ -52,12 +52,15 @@ STATIC int xfs_attr_leaf_hasname(struct xfs_da_args *args, struct xfs_buf **bp);* Internal routines when attribute list is more than one block. */ STATIC int xfs_attr_node_get(xfs_da_args_t *args); -STATIC int xfs_attr_node_addname(xfs_da_args_t *args); +STATIC int xfs_attr_node_addname(struct xfs_delattr_context *dac); STATIC int xfs_attr_node_removename_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_leaf_try_add(struct xfs_da_args *args, struct xfs_buf *bp); +STATIC int xfs_attr_set_iter(struct xfs_delattr_context *dac, +struct xfs_buf **leaf_bp);int xfs_inode_hasattr(@@ -218,8 +221,11 @@ xfs_attr_is_shortform(/* * Attempts to set an attr in shortform, or converts short form to leaf form if -* there is not enough room. If the attr is set, the transaction is committed -* and set to NULL. +* there is not enough room. This function is meant to operate as a helper +* routine to the delayed attribute functions. It returns -EAGAIN to indicate +* that the calling function should roll the transaction, and then proceed to +* add the attr in leaf form. This subroutine does not expect to be recalled +* again like the other delayed attr routines do. */ STATIC int xfs_attr_set_shortform(@@ -227,16 +233,16 @@ xfs_attr_set_shortform( struct xfs_buf **leaf_bp) {struct xfs_inode *dp = args->dp; -int error, error2 =0 ; +int error =0 ;/* * Try to add the attr to the attribute list in the inode. */ error =xfs_attr_try_sf_addname (dp, args); + +/* Should only be 0, -EEXIST or ENOSPC */ if (error != -ENOSPC ) { - error2 =xfs_trans_commit (args->trans); - args->trans =NULL ; -return error ? error : error2; +return error; }/* * It won't fit in the shortform, transform to a leaf block. GROT: @@ -249,18 +255,10 @@ xfs_attr_set_shortform(/* * Prevent the leaf buffer from being unlocked so that a concurrent AIL * push cannot grab the half-baked leaf buffer and run into problems -* with the write verifier. Once we're done rolling the transaction we -* can release the hold and add the attr to the leaf. +* with the write verifier. */ xfs_trans_bhold (args->trans, *leaf_bp); - error =xfs_defer_finish (&args->trans); -xfs_trans_bhold_release (args->trans, *leaf_bp); -if (error) { -xfs_trans_brelse (args->trans, *leaf_bp); -return error; - } - -return 0 ; +return -EAGAIN ; }/* @@ -268,7 +266,7 @@ xfs_attr_set_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) {@@ -297,61 +295,130 @@ intxfs_attr_set_args ( struct xfs_da_args *args) { -struct xfs_inode *dp = args->dp; -struct xfs_buf *leaf_bp =NULL ; -int error =0 ; +struct xfs_buf *leaf_bp =NULL ; +int error =0 ; +struct xfs_delattr_context dac = { + .da_args = args, + }; + + do { + error = xfs_attr_set_iter(&dac, &leaf_bp); + if (error != -EAGAIN)
fs/xfs/libxfs/xfs_attr.c int · line 316
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10
-0+break ; + + error =xfs_attr_trans_roll (&dac); +if (error) +return error; + +if (leaf_bp) { +xfs_trans_bjoin (args->trans, leaf_bp); +xfs_trans_bhold (args->trans, leaf_bp); + }
When xfs_attr_set_iter() causes a "short form" attribute list to be converted to "leaf form", leaf_bp would point to an xfs_buf which has been added to the transaction and also XFS_BLI_HOLD flag is set on the buffer (last statement in xfs_attr_set_shortform()). XFS_BLI_HOLD flag makes sure that the new transaction allocated by xfs_attr_trans_roll() would continue to have leaf_bp in the transaction's item list. Hence I think the above calls to xfs_trans_bjoin() and xfs_trans_bhold() are not required. Please let me know if I am missing something obvious here.
Signature · 1 line
chandan
Re: [PATCH v13 03/10] xfs: Add delay ready attr set routines
Quoted 153 lines · Chandan Babu R
Quoted 7 lines · IST 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.Quoted 9 lines
Two new helper functions have been added:
xfs_attr_rmtval_set_initandxfs_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.One nit. xfs_attr_rmtval_remove()'s prototype declaration needs to be removed from
xfs_attr_remote.h.Quoted 121 lines
Signed-off-by Allison Henderson <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 370 ++++++++++++++++++++++++++-------------- fs/xfs/libxfs/xfs_attr.h | 126 +++++++++++++- fs/xfs/libxfs/xfs_attr_remote.c | 99 +++++++---- fs/xfs/libxfs/xfs_attr_remote.h | 4 + fs/xfs/xfs_trace.h | 1 - 5 files changed, 439 insertions(+), 161 deletions(-)fs/xfs/libxfs/xfs_attr.c +26
-22@@ -44,7 +44,7 @@ STATIC int xfs_attr_shortform_addname(xfs_da_args_t *args);* Internal routines when attribute list is one block. */ STATIC int xfs_attr_leaf_get(xfs_da_args_t *args); -STATIC int xfs_attr_leaf_addname(xfs_da_args_t *args); +STATIC int xfs_attr_leaf_addname(struct xfs_delattr_context *dac); STATIC int xfs_attr_leaf_removename(xfs_da_args_t *args); STATIC int xfs_attr_leaf_hasname(struct xfs_da_args *args, struct xfs_buf **bp);@@ -52,12 +52,15 @@ STATIC int xfs_attr_leaf_hasname(struct xfs_da_args *args, struct xfs_buf **bp);* Internal routines when attribute list is more than one block. */ STATIC int xfs_attr_node_get(xfs_da_args_t *args); -STATIC int xfs_attr_node_addname(xfs_da_args_t *args); +STATIC int xfs_attr_node_addname(struct xfs_delattr_context *dac); STATIC int xfs_attr_node_removename_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_leaf_try_add(struct xfs_da_args *args, struct xfs_buf *bp); +STATIC int xfs_attr_set_iter(struct xfs_delattr_context *dac, +struct xfs_buf **leaf_bp);int xfs_inode_hasattr(@@ -218,8 +221,11 @@ xfs_attr_is_shortform(/* * Attempts to set an attr in shortform, or converts short form to leaf form if -* there is not enough room. If the attr is set, the transaction is committed -* and set to NULL. +* there is not enough room. This function is meant to operate as a helper +* routine to the delayed attribute functions. It returns -EAGAIN to indicate +* that the calling function should roll the transaction, and then proceed to +* add the attr in leaf form. This subroutine does not expect to be recalled +* again like the other delayed attr routines do. */ STATIC int xfs_attr_set_shortform(@@ -227,16 +233,16 @@ xfs_attr_set_shortform( struct xfs_buf **leaf_bp) {struct xfs_inode *dp = args->dp; -int error, error2 =0 ; +int error =0 ;/* * Try to add the attr to the attribute list in the inode. */ error =xfs_attr_try_sf_addname (dp, args); + +/* Should only be 0, -EEXIST or ENOSPC */ if (error != -ENOSPC ) { - error2 =xfs_trans_commit (args->trans); - args->trans =NULL ; -return error ? error : error2; +return error; }/* * It won't fit in the shortform, transform to a leaf block. GROT: @@ -249,18 +255,10 @@ xfs_attr_set_shortform(/* * Prevent the leaf buffer from being unlocked so that a concurrent AIL * push cannot grab the half-baked leaf buffer and run into problems -* with the write verifier. Once we're done rolling the transaction we -* can release the hold and add the attr to the leaf. +* with the write verifier. */ xfs_trans_bhold (args->trans, *leaf_bp); - error =xfs_defer_finish (&args->trans); -xfs_trans_bhold_release (args->trans, *leaf_bp); -if (error) { -xfs_trans_brelse (args->trans, *leaf_bp); -return error; - } - -return 0 ; +return -EAGAIN ; }/* @@ -268,7 +266,7 @@ xfs_attr_set_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) {@@ -297,61 +295,130 @@ intxfs_attr_set_args ( struct xfs_da_args *args) { -struct xfs_inode *dp = args->dp; -struct xfs_buf *leaf_bp =NULL ; -int error =0 ; +struct xfs_buf *leaf_bp =NULL ; +int error =0 ; +struct xfs_delattr_context dac = { + .da_args = args, + }; + + do { + error = xfs_attr_set_iter(&dac, &leaf_bp); + if (error != -EAGAIN)fs/xfs/libxfs/xfs_attr.c int · line 316
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10
-0+break ; + + error =xfs_attr_trans_roll (&dac); +if (error) +return error; + +if (leaf_bp) { +xfs_trans_bjoin (args->trans, leaf_bp); +xfs_trans_bhold (args->trans, leaf_bp); + }
Quoted 7 lines
When
xfs_attr_set_iter()causes a "short form" attribute list to be converted to "leaf form",leaf_bpwould point to anxfs_bufwhich has been added to the transaction and alsoXFS_BLI_HOLDflag is set on the buffer (last statement inxfs_attr_set_shortform()).XFS_BLI_HOLDflag makes sure that the new transaction allocated byxfs_attr_trans_roll()would continue to haveleaf_bpin the transaction's item list. Hence I think the above calls toxfs_trans_bjoin()andxfs_trans_bhold()are not required.
I /think/ the defer ops will rejoin the buffer each time it rolls, which means that xfs_attr_trans_roll returns with the buffer already joined to the transaction? And I think you're right that the bhold isn't needed, because holding is dictated by the lower levels (i.e. _set_iter).
Quoted 1 line
Please let me know if I am missing something obvious here.
The entire function goes away by the end of the series. :)
--D
Quoted 6 lines
Signature · 2 lines
-- chandan
Re: [PATCH v13 03/10] xfs: Add delay ready attr set routines
Quoted 19 lines · Darrick J. Wong
Quoted 18 lines · Chandan Babu R
Quoted 16 lines · IST 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_set_initandxfs_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
Quoted 2 lines
One nit. xfs_attr_rmtval_remove()'s prototype declaration needs to be removed from
xfs_attr_remote.h.
Alrighty, will pull out
Quoted 132 lines
Quoted 132 lines
Quoted 132 lines
Signed-off-by Allison Henderson <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 370 ++++++++++++++++++++++++++-------------- fs/xfs/libxfs/xfs_attr.h | 126 +++++++++++++- fs/xfs/libxfs/xfs_attr_remote.c | 99 +++++++---- fs/xfs/libxfs/xfs_attr_remote.h | 4 + fs/xfs/xfs_trace.h | 1 - 5 files changed, 439 insertions(+), 161 deletions(-)fs/xfs/libxfs/xfs_attr.c +36
-22@@ -44,7 +44,7 @@ STATIC int xfs_attr_shortform_addname(xfs_da_args_t *args);* Internal routines when attribute list is one block. */ STATIC int xfs_attr_leaf_get(xfs_da_args_t *args); -STATIC int xfs_attr_leaf_addname(xfs_da_args_t *args); +STATIC int xfs_attr_leaf_addname(struct xfs_delattr_context *dac); STATIC int xfs_attr_leaf_removename(xfs_da_args_t *args); STATIC int xfs_attr_leaf_hasname(struct xfs_da_args *args, struct xfs_buf **bp);@@ -52,12 +52,15 @@ STATIC int xfs_attr_leaf_hasname(struct xfs_da_args *args, struct xfs_buf **bp);* Internal routines when attribute list is more than one block. */ STATIC int xfs_attr_node_get(xfs_da_args_t *args); -STATIC int xfs_attr_node_addname(xfs_da_args_t *args); +STATIC int xfs_attr_node_addname(struct xfs_delattr_context *dac); STATIC int xfs_attr_node_removename_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_leaf_try_add(struct xfs_da_args *args, struct xfs_buf *bp); +STATIC int xfs_attr_set_iter(struct xfs_delattr_context *dac, +struct xfs_buf **leaf_bp);int xfs_inode_hasattr(@@ -218,8 +221,11 @@ xfs_attr_is_shortform(/* * Attempts to set an attr in shortform, or converts short form to leaf form if -* there is not enough room. If the attr is set, the transaction is committed -* and set to NULL. +* there is not enough room. This function is meant to operate as a helper +* routine to the delayed attribute functions. It returns -EAGAIN to indicate +* that the calling function should roll the transaction, and then proceed to +* add the attr in leaf form. This subroutine does not expect to be recalled +* again like the other delayed attr routines do. */ STATIC int xfs_attr_set_shortform(@@ -227,16 +233,16 @@ xfs_attr_set_shortform( struct xfs_buf **leaf_bp) {struct xfs_inode *dp = args->dp; -int error, error2 =0 ; +int error =0 ;/* * Try to add the attr to the attribute list in the inode. */ error =xfs_attr_try_sf_addname (dp, args); + +/* Should only be 0, -EEXIST or ENOSPC */ if (error != -ENOSPC ) { - error2 =xfs_trans_commit (args->trans); - args->trans =NULL ; -return error ? error : error2; +return error; }/* * It won't fit in the shortform, transform to a leaf block. GROT: @@ -249,18 +255,10 @@ xfs_attr_set_shortform(/* * Prevent the leaf buffer from being unlocked so that a concurrent AIL * push cannot grab the half-baked leaf buffer and run into problems -* with the write verifier. Once we're done rolling the transaction we -* can release the hold and add the attr to the leaf. +* with the write verifier. */ xfs_trans_bhold (args->trans, *leaf_bp); - error =xfs_defer_finish (&args->trans); -xfs_trans_bhold_release (args->trans, *leaf_bp); -if (error) { -xfs_trans_brelse (args->trans, *leaf_bp); -return error; - } - -return 0 ; +return -EAGAIN ; }/* @@ -268,7 +266,7 @@ xfs_attr_set_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) {@@ -297,61 +295,130 @@ intxfs_attr_set_args ( struct xfs_da_args *args) { -struct xfs_inode *dp = args->dp; -struct xfs_buf *leaf_bp =NULL ; -int error =0 ; +struct xfs_buf *leaf_bp =NULL ; +int error =0 ; +struct xfs_delattr_context dac = { + .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; + + if (leaf_bp) { + xfs_trans_bjoin(args->trans, leaf_bp); + xfs_trans_bhold(args->trans, leaf_bp); + }
Quoted 8 lines
Quoted 8 lines
When
xfs_attr_set_iter()causes a "short form" attribute list to be converted to "leaf form",leaf_bpwould point to anxfs_bufwhich has been added to the transaction and alsoXFS_BLI_HOLDflag is set on the buffer (last statement inxfs_attr_set_shortform()).XFS_BLI_HOLDflag makes sure that the new transaction allocated byxfs_attr_trans_roll()would continue to haveleaf_bpin the transaction's item list. Hence I think the above calls toxfs_trans_bjoin()andxfs_trans_bhold()are not required.
Sorry, I just noticed Chandans commentary for this patch. Apologies. I think we can get away with out this now, but yes this routine disappears at the end of the set now. Will clean out anyway for bisecting reasons though. :-)
Quoted 18 lines
I /think/ the defer ops will rejoin the buffer each time it rolls, which means that
xfs_attr_trans_rollreturns with the buffer already joined to the transaction? And I think you're right that the bhold isn't needed, because holding is dictated by the lower levels (i.e._set_iter).Quoted 1 line
Please let me know if I am missing something obvious here.
The entire function goes away by the end of the series. :)
--D
Quoted 6 lines
Signature · 2 lines
-- chandan
Re: [PATCH v13 03/10] xfs: Add delay ready attr set routines
Quoted 165 lines · IST Allison Henderson
Quoted 19 lines · Darrick J. Wong
Quoted 18 lines · Chandan Babu R
Quoted 16 lines · IST 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_set_initandxfs_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
Quoted 2 lines
One nit. xfs_attr_rmtval_remove()'s prototype declaration needs to be removed from
xfs_attr_remote.h.Alrighty, will pull out
Quoted 132 lines
Quoted 132 lines
Quoted 132 lines
Signed-off-by Allison Henderson <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 370 ++++++++++++++++++++++++++-------------- fs/xfs/libxfs/xfs_attr.h | 126 +++++++++++++- fs/xfs/libxfs/xfs_attr_remote.c | 99 +++++++---- fs/xfs/libxfs/xfs_attr_remote.h | 4 + fs/xfs/xfs_trace.h | 1 - 5 files changed, 439 insertions(+), 161 deletions(-)fs/xfs/libxfs/xfs_attr.c +36
-22@@ -44,7 +44,7 @@ STATIC int xfs_attr_shortform_addname(xfs_da_args_t *args);* Internal routines when attribute list is one block. */ STATIC int xfs_attr_leaf_get(xfs_da_args_t *args); -STATIC int xfs_attr_leaf_addname(xfs_da_args_t *args); +STATIC int xfs_attr_leaf_addname(struct xfs_delattr_context *dac); STATIC int xfs_attr_leaf_removename(xfs_da_args_t *args); STATIC int xfs_attr_leaf_hasname(struct xfs_da_args *args, struct xfs_buf **bp);@@ -52,12 +52,15 @@ STATIC int xfs_attr_leaf_hasname(struct xfs_da_args *args, struct xfs_buf **bp);* Internal routines when attribute list is more than one block. */ STATIC int xfs_attr_node_get(xfs_da_args_t *args); -STATIC int xfs_attr_node_addname(xfs_da_args_t *args); +STATIC int xfs_attr_node_addname(struct xfs_delattr_context *dac); STATIC int xfs_attr_node_removename_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_leaf_try_add(struct xfs_da_args *args, struct xfs_buf *bp); +STATIC int xfs_attr_set_iter(struct xfs_delattr_context *dac, +struct xfs_buf **leaf_bp);int xfs_inode_hasattr(@@ -218,8 +221,11 @@ xfs_attr_is_shortform(/* * Attempts to set an attr in shortform, or converts short form to leaf form if -* there is not enough room. If the attr is set, the transaction is committed -* and set to NULL. +* there is not enough room. This function is meant to operate as a helper +* routine to the delayed attribute functions. It returns -EAGAIN to indicate +* that the calling function should roll the transaction, and then proceed to +* add the attr in leaf form. This subroutine does not expect to be recalled +* again like the other delayed attr routines do. */ STATIC int xfs_attr_set_shortform(@@ -227,16 +233,16 @@ xfs_attr_set_shortform( struct xfs_buf **leaf_bp) {struct xfs_inode *dp = args->dp; -int error, error2 =0 ; +int error =0 ;/* * Try to add the attr to the attribute list in the inode. */ error =xfs_attr_try_sf_addname (dp, args); + +/* Should only be 0, -EEXIST or ENOSPC */ if (error != -ENOSPC ) { - error2 =xfs_trans_commit (args->trans); - args->trans =NULL ; -return error ? error : error2; +return error; }/* * It won't fit in the shortform, transform to a leaf block. GROT: @@ -249,18 +255,10 @@ xfs_attr_set_shortform(/* * Prevent the leaf buffer from being unlocked so that a concurrent AIL * push cannot grab the half-baked leaf buffer and run into problems -* with the write verifier. Once we're done rolling the transaction we -* can release the hold and add the attr to the leaf. +* with the write verifier. */ xfs_trans_bhold (args->trans, *leaf_bp); - error =xfs_defer_finish (&args->trans); -xfs_trans_bhold_release (args->trans, *leaf_bp); -if (error) { -xfs_trans_brelse (args->trans, *leaf_bp); -return error; - } - -return 0 ; +return -EAGAIN ; }/* @@ -268,7 +266,7 @@ xfs_attr_set_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) {@@ -297,61 +295,130 @@ intxfs_attr_set_args ( struct xfs_da_args *args) { -struct xfs_inode *dp = args->dp; -struct xfs_buf *leaf_bp =NULL ; -int error =0 ; +struct xfs_buf *leaf_bp =NULL ; +int error =0 ; +struct xfs_delattr_context dac = { + .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; + + if (leaf_bp) { + xfs_trans_bjoin(args->trans, leaf_bp); + xfs_trans_bhold(args->trans, leaf_bp); + }Quoted 8 lines
Quoted 8 lines
When
xfs_attr_set_iter()causes a "short form" attribute list to be converted to "leaf form",leaf_bpwould point to anxfs_bufwhich has been added to the transaction and alsoXFS_BLI_HOLDflag is set on the buffer (last statement inxfs_attr_set_shortform()).XFS_BLI_HOLDflag makes sure that the new transaction allocated byxfs_attr_trans_roll()would continue to haveleaf_bpin the transaction's item list. Hence I think the above calls toxfs_trans_bjoin()andxfs_trans_bhold()are not required.
Quoted 4 lines
Sorry, I just noticed Chandans commentary for this patch. Apologies. I think we can get away with out this now, but yes this routine disappears at the end of the set now. Will clean out anyway for bisecting reasons though. :-)
No problem. As an aside, I stopped reviewing the patchset after I noticed Brian's review comments for "[PATCH v13 02/10] xfs: Add delay ready attr remove routines" suggesting some more code refactoring work.
Quoted 18 lines
Quoted 17 lines
I /think/ the defer ops will rejoin the buffer each time it rolls, which means that
xfs_attr_trans_rollreturns with the buffer already joined to the transaction? And I think you're right that the bhold isn't needed, because holding is dictated by the lower levels (i.e._set_iter).Quoted 1 line
Please let me know if I am missing something obvious here.
The entire function goes away by the end of the series. :)
--D
Quoted 4 lines
Signature · 1 line
chandan
Re: [PATCH v13 03/10] xfs: Add delay ready attr set routines
Quoted 166 lines · Chandan Babu R
Quoted 165 lines · IST Allison Henderson
Quoted 19 lines · Darrick J. Wong
Quoted 18 lines · Chandan Babu R
Quoted 16 lines · IST 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_set_initandxfs_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
Quoted 2 lines
One nit. xfs_attr_rmtval_remove()'s prototype declaration needs to be removed from
xfs_attr_remote.h.Alrighty, will pull out
Quoted 140 lines
Quoted 140 lines
Quoted 122 lines
Signed-off-by Allison Henderson <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 370 ++++++++++++++++++++++++++-------------- fs/xfs/libxfs/xfs_attr.h | 126 +++++++++++++- fs/xfs/libxfs/xfs_attr_remote.c | 99 +++++++---- fs/xfs/libxfs/xfs_attr_remote.h | 4 + fs/xfs/xfs_trace.h | 1 - 5 files changed, 439 insertions(+), 161 deletions(-)fs/xfs/libxfs/xfs_attr.c +26
-22@@ -44,7 +44,7 @@ STATIC int xfs_attr_shortform_addname(xfs_da_args_t *args);* Internal routines when attribute list is one block. */ STATIC int xfs_attr_leaf_get(xfs_da_args_t *args); -STATIC int xfs_attr_leaf_addname(xfs_da_args_t *args); +STATIC int xfs_attr_leaf_addname(struct xfs_delattr_context *dac); STATIC int xfs_attr_leaf_removename(xfs_da_args_t *args); STATIC int xfs_attr_leaf_hasname(struct xfs_da_args *args, struct xfs_buf **bp);@@ -52,12 +52,15 @@ STATIC int xfs_attr_leaf_hasname(struct xfs_da_args *args, struct xfs_buf **bp);* Internal routines when attribute list is more than one block. */ STATIC int xfs_attr_node_get(xfs_da_args_t *args); -STATIC int xfs_attr_node_addname(xfs_da_args_t *args); +STATIC int xfs_attr_node_addname(struct xfs_delattr_context *dac); STATIC int xfs_attr_node_removename_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_leaf_try_add(struct xfs_da_args *args, struct xfs_buf *bp); +STATIC int xfs_attr_set_iter(struct xfs_delattr_context *dac, +struct xfs_buf **leaf_bp);int xfs_inode_hasattr(@@ -218,8 +221,11 @@ xfs_attr_is_shortform(/* * Attempts to set an attr in shortform, or converts short form to leaf form if -* there is not enough room. If the attr is set, the transaction is committed -* and set to NULL. +* there is not enough room. This function is meant to operate as a helper +* routine to the delayed attribute functions. It returns -EAGAIN to indicate +* that the calling function should roll the transaction, and then proceed to +* add the attr in leaf form. This subroutine does not expect to be recalled +* again like the other delayed attr routines do. */ STATIC int xfs_attr_set_shortform(@@ -227,16 +233,16 @@ xfs_attr_set_shortform( struct xfs_buf **leaf_bp) {struct xfs_inode *dp = args->dp; -int error, error2 =0 ; +int error =0 ;/* * Try to add the attr to the attribute list in the inode. */ error =xfs_attr_try_sf_addname (dp, args); + +/* Should only be 0, -EEXIST or ENOSPC */ if (error != -ENOSPC ) { - error2 =xfs_trans_commit (args->trans); - args->trans =NULL ; -return error ? error : error2; +return error; }/* * It won't fit in the shortform, transform to a leaf block. GROT: @@ -249,18 +255,10 @@ xfs_attr_set_shortform(/* * Prevent the leaf buffer from being unlocked so that a concurrent AIL * push cannot grab the half-baked leaf buffer and run into problems -* with the write verifier. Once we're done rolling the transaction we -* can release the hold and add the attr to the leaf. +* with the write verifier. */ xfs_trans_bhold (args->trans, *leaf_bp); - error =xfs_defer_finish (&args->trans); -xfs_trans_bhold_release (args->trans, *leaf_bp); -if (error) { -xfs_trans_brelse (args->trans, *leaf_bp); -return error; - } - -return 0 ; +return -EAGAIN ; }/* @@ -268,7 +266,7 @@ xfs_attr_set_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) {@@ -297,61 +295,130 @@ intxfs_attr_set_args ( struct xfs_da_args *args) { -struct xfs_inode *dp = args->dp; -struct xfs_buf *leaf_bp =NULL ; -int error =0 ; +struct xfs_buf *leaf_bp =NULL ; +int error =0 ; +struct xfs_delattr_context dac = { + .da_args = args, + }; + + do { + error = xfs_attr_set_iter(&dac, &leaf_bp); + if (error != -EAGAIN)fs/xfs/libxfs/xfs_attr.c int · line 316
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10
-0+break ; + + error =xfs_attr_trans_roll (&dac); +if (error) +return error; + +if (leaf_bp) { +xfs_trans_bjoin (args->trans, leaf_bp); +xfs_trans_bhold (args->trans, leaf_bp); + }When
xfs_attr_set_iter()causes a "short form" attribute list to be converted to "leaf form",leaf_bpwould point to anxfs_bufwhich has been added to the transaction and alsoXFS_BLI_HOLDflag is set on the buffer (last statement inxfs_attr_set_shortform()).XFS_BLI_HOLDflag makes sure that the new transaction allocated byxfs_attr_trans_roll()would continue to haveleaf_bpin the transaction's item list. Hence I think the above calls toxfs_trans_bjoin()andxfs_trans_bhold()are not required.
Quoted 9 lines
Quoted 4 lines
Sorry, I just noticed Chandans commentary for this patch. Apologies. I think we can get away with out this now, but yes this routine disappears at the end of the set now. Will clean out anyway for bisecting reasons though. :-)
No problem. As an aside, I stopped reviewing the patchset after I noticed Brian's review comments for "[PATCH v13 02/10] xfs: Add delay ready attr remove routines" suggesting some more code refactoring work.
No worries, thats reasonable. It's why I only send this out in subsets to try and keep people sort of focused on a smaller area because stuff at the end of the set changes more often as a result of things moving around at the bottom of the set. It doesn't make sense to channel too much effort into something that's still moving around so much :-)
Allison
Quoted 20 lines
Quoted 18 lines
Quoted 17 lines
I /think/ the defer ops will rejoin the buffer each time it rolls, which means that
xfs_attr_trans_rollreturns with the buffer already joined to the transaction? And I think you're right that the bhold isn't needed, because holding is dictated by the lower levels (i.e._set_iter).Quoted 1 line
Please let me know if I am missing something obvious here.
The entire function goes away by the end of the series. :)
--D
Quoted 4 lines
Re: [PATCH v13 03/10] xfs: Add delay ready attr set routines
Quoted 173 lines · Allison Henderson
Quoted 161 lines · Chandan Babu R
Quoted 160 lines · IST Allison Henderson
Quoted 19 lines · Darrick J. Wong
Quoted 18 lines · Chandan Babu R
Quoted 16 lines · IST 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_set_initandxfs_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
Quoted 2 lines
One nit. xfs_attr_rmtval_remove()'s prototype declaration needs to be removed from
xfs_attr_remote.h.Alrighty, will pull out
Quoted 135 lines
Quoted 135 lines
Quoted 117 lines
Signed-off-by Allison Henderson <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 370 ++++++++++++++++++++++++++-------------- fs/xfs/libxfs/xfs_attr.h | 126 +++++++++++++- fs/xfs/libxfs/xfs_attr_remote.c | 99 +++++++---- fs/xfs/libxfs/xfs_attr_remote.h | 4 + fs/xfs/xfs_trace.h | 1 - 5 files changed, 439 insertions(+), 161 deletions(-)fs/xfs/libxfs/xfs_attr.c +26
-22@@ -44,7 +44,7 @@ STATIC int xfs_attr_shortform_addname(xfs_da_args_t *args);* Internal routines when attribute list is one block. */ STATIC int xfs_attr_leaf_get(xfs_da_args_t *args); -STATIC int xfs_attr_leaf_addname(xfs_da_args_t *args); +STATIC int xfs_attr_leaf_addname(struct xfs_delattr_context *dac); STATIC int xfs_attr_leaf_removename(xfs_da_args_t *args); STATIC int xfs_attr_leaf_hasname(struct xfs_da_args *args, struct xfs_buf **bp);@@ -52,12 +52,15 @@ STATIC int xfs_attr_leaf_hasname(struct xfs_da_args *args, struct xfs_buf **bp);* Internal routines when attribute list is more than one block. */ STATIC int xfs_attr_node_get(xfs_da_args_t *args); -STATIC int xfs_attr_node_addname(xfs_da_args_t *args); +STATIC int xfs_attr_node_addname(struct xfs_delattr_context *dac); STATIC int xfs_attr_node_removename_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_leaf_try_add(struct xfs_da_args *args, struct xfs_buf *bp); +STATIC int xfs_attr_set_iter(struct xfs_delattr_context *dac, +struct xfs_buf **leaf_bp);int xfs_inode_hasattr(@@ -218,8 +221,11 @@ xfs_attr_is_shortform(/* * Attempts to set an attr in shortform, or converts short form to leaf form if -* there is not enough room. If the attr is set, the transaction is committed -* and set to NULL. +* there is not enough room. This function is meant to operate as a helper +* routine to the delayed attribute functions. It returns -EAGAIN to indicate +* that the calling function should roll the transaction, and then proceed to +* add the attr in leaf form. This subroutine does not expect to be recalled +* again like the other delayed attr routines do. */ STATIC int xfs_attr_set_shortform(@@ -227,16 +233,16 @@ xfs_attr_set_shortform( struct xfs_buf **leaf_bp) {struct xfs_inode *dp = args->dp; -int error, error2 =0 ; +int error =0 ;/* * Try to add the attr to the attribute list in the inode. */ error =xfs_attr_try_sf_addname (dp, args); + +/* Should only be 0, -EEXIST or ENOSPC */ if (error != -ENOSPC ) { - error2 =xfs_trans_commit (args->trans); - args->trans =NULL ; -return error ? error : error2; +return error; }/* * It won't fit in the shortform, transform to a leaf block. GROT: @@ -249,18 +255,10 @@ xfs_attr_set_shortform(/* * Prevent the leaf buffer from being unlocked so that a concurrent AIL * push cannot grab the half-baked leaf buffer and run into problems -* with the write verifier. Once we're done rolling the transaction we -* can release the hold and add the attr to the leaf. +* with the write verifier. */ xfs_trans_bhold (args->trans, *leaf_bp); - error =xfs_defer_finish (&args->trans); -xfs_trans_bhold_release (args->trans, *leaf_bp); -if (error) { -xfs_trans_brelse (args->trans, *leaf_bp); -return error; - } - -return 0 ; +return -EAGAIN ; }/* @@ -268,7 +266,7 @@ xfs_attr_set_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) {@@ -297,61 +295,130 @@ intxfs_attr_set_args ( struct xfs_da_args *args) { -struct xfs_inode *dp = args->dp; -struct xfs_buf *leaf_bp =NULL ; -int error =0 ; +struct xfs_buf *leaf_bp =NULL ; +int error =0 ; +struct xfs_delattr_context dac = { + .da_args = args, + }; + + do { + error = xfs_attr_set_iter(&dac, &leaf_bp); + if (error != -EAGAIN)fs/xfs/libxfs/xfs_attr.c int · line 316
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10
-0+break ; + + error =xfs_attr_trans_roll (&dac); +if (error) +return error; + +if (leaf_bp) { +xfs_trans_bjoin (args->trans, leaf_bp); +xfs_trans_bhold (args->trans, leaf_bp); + }When
xfs_attr_set_iter()causes a "short form" attribute list to be converted to "leaf form",leaf_bpwould point to anxfs_bufwhich has been added to the transaction and alsoXFS_BLI_HOLDflag is set on the buffer (last statement inxfs_attr_set_shortform()).XFS_BLI_HOLDflag makes sure that the new transaction allocated byxfs_attr_trans_roll()would continue to haveleaf_bpin the transaction's item list. Hence I think the above calls toxfs_trans_bjoin()andxfs_trans_bhold()are not required.Quoted 9 lines
Quoted 4 lines
Sorry, I just noticed Chandans commentary for this patch. Apologies. I think we can get away with out this now, but yes this routine disappears at the end of the set now. Will clean out anyway for bisecting reasons though. :-)
No problem. As an aside, I stopped reviewing the patchset after I noticed Brian's review comments for "[PATCH v13 02/10] xfs: Add delay ready attr remove routines" suggesting some more code refactoring work.
Quoted 5 lines
No worries, thats reasonable. It's why I only send this out in subsets to try and keep people sort of focused on a smaller area because stuff at the end of the set changes more often as a result of things moving around at the bottom of the set. It doesn't make sense to channel too much effort into something that's still moving around so much :-)
<nod> TBH either I seem to make time to review the entire series or I just fail to find time to start it at all. :(
That said I also usually start at the end and work my way backwards, assuming that most people don't do that, and the author would probably like it if /someone/ covered the end parts.
--D
Quoted 21 lines
Allison
Quoted 20 lines
Quoted 18 lines
Quoted 17 lines
I /think/ the defer ops will rejoin the buffer each time it rolls, which means that
xfs_attr_trans_rollreturns with the buffer already joined to the transaction? And I think you're right that the bhold isn't needed, because holding is dictated by the lower levels (i.e._set_iter).Quoted 1 line
Please let me know if I am missing something obvious here.
The entire function goes away by the end of the series. :)
--D
Quoted 4 lines
Re: [PATCH v13 03/10] xfs: Add delay ready attr set routines
In reply to Allison HendersonQuoted 73 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_set_initandxfs_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.Signed-off-by Allison Henderson <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 370 ++++++++++++++++++++++++++-------------- fs/xfs/libxfs/xfs_attr.h | 126 +++++++++++++- fs/xfs/libxfs/xfs_attr_remote.c | 99 +++++++---- fs/xfs/libxfs/xfs_attr_remote.h | 4 + fs/xfs/xfs_trace.h | 1 - 5 files changed, 439 insertions(+), 161 deletions(-)fs/xfs/libxfs/xfs_attr.c +10
-4@@ -44,7 +44,7 @@ STATIC int xfs_attr_shortform_addname(xfs_da_args_t *args);* Internal routines when attribute list is one block. */ STATIC int xfs_attr_leaf_get(xfs_da_args_t *args); -STATIC int xfs_attr_leaf_addname(xfs_da_args_t *args); +STATIC int xfs_attr_leaf_addname(struct xfs_delattr_context *dac); STATIC int xfs_attr_leaf_removename(xfs_da_args_t *args); STATIC int xfs_attr_leaf_hasname(struct xfs_da_args *args, struct xfs_buf **bp);@@ -52,12 +52,15 @@ STATIC int xfs_attr_leaf_hasname(struct xfs_da_args *args, struct xfs_buf **bp);* Internal routines when attribute list is more than one block. */ STATIC int xfs_attr_node_get(xfs_da_args_t *args); -STATIC int xfs_attr_node_addname(xfs_da_args_t *args); +STATIC int xfs_attr_node_addname(struct xfs_delattr_context *dac); STATIC int xfs_attr_node_removename_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_leaf_try_add(struct xfs_da_args *args, struct xfs_buf *bp); +STATIC int xfs_attr_set_iter(struct xfs_delattr_context *dac, +struct xfs_buf **leaf_bp);int xfs_inode_hasattr(@@ -218,8 +221,11 @@ xfs_attr_is_shortform(/* * Attempts to set an attr in shortform, or converts short form to leaf form if -* there is not enough room. If the attr is set, the transaction is committed -* and set to NULL. +* there is not enough room. This function is meant to operate as a helper +* routine to the delayed attribute functions. It returns -EAGAIN to indicate +* that the calling function should roll the transaction, and then proceed to +* add the attr in leaf form. This subroutine does not expect to be recalled +* again like the other delayed attr routines do. */ STATIC int xfs_attr_set_shortform(@@ -227,16 +233,16 @@ xfs_attr_set_shortform( struct xfs_buf **leaf_bp) {
fs/xfs/libxfs/xfs_attr.c xfs_attr_set_shortform( · line 243
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +3
-1struct xfs_inode *dp = args->dp; -int error, error2 =0 ; +int error =0 ;/* * Try to add the attr to the attribute list in the inode. */ error =xfs_attr_try_sf_addname (dp, args); + +/* Should only be 0, -EEXIST or ENOSPC */
Nit: "...or -ENOSPC"
Also, this comment could go a couple of lines up:
/* * Try to add the attr to the attribute list in the inode. * This should only return 0, -EEXIST, or -ENOSPC. */ error = xfs_attr_try_sf_addname(dp, args); if (error != -ENOSPC) return error;
Quoted 16 lines
fs/xfs/libxfs/xfs_attr.c +2
-5if (error != -ENOSPC ) { - error2 =xfs_trans_commit (args->trans); - args->trans =NULL ; -return error ? error : error2; +return error; }/* * It won't fit in the shortform, transform to a leaf block. GROT: @@ -249,18 +255,10 @@ xfs_attr_set_shortform(/* * Prevent the leaf buffer from being unlocked so that a concurrent AIL * push cannot grab the half-baked leaf buffer and run into problems -* with the write verifier. Once we're done rolling the transaction we -* can release the hold and add the attr to the leaf. +* with the write verifier. */
fs/xfs/libxfs/xfs_attr.c xfs_attr_set_shortform( · line 261
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +1
-8xfs_trans_bhold (args->trans, *leaf_bp); - error =xfs_defer_finish (&args->trans); -xfs_trans_bhold_release (args->trans, *leaf_bp); -if (error) { -xfs_trans_brelse (args->trans, *leaf_bp); -return error; - } - -return 0 ; +return -EAGAIN ;
What state are we in when return -EAGAIN here? Are we still in XFS_DAS_UNINIT, but with an attr fork that is no longer in local format, which means that we skip the xfs_attr_is_shortform branch next time around?
Quoted 54 lines
fs/xfs/libxfs/xfs_attr.c +36
-4}/* @@ -268,7 +266,7 @@ xfs_attr_set_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) {@@ -297,61 +295,130 @@ intxfs_attr_set_args ( struct xfs_da_args *args) { -struct xfs_inode *dp = args->dp; -struct xfs_buf *leaf_bp =NULL ; -int error =0 ; +struct xfs_buf *leaf_bp =NULL ; +int error =0 ; +struct xfs_delattr_context dac = { + .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; + +if (leaf_bp) { +xfs_trans_bjoin (args->trans, leaf_bp); +xfs_trans_bhold (args->trans, leaf_bp); + } + + }while (true); + +return error; +} + +/* +* Set the attribute specified in @args. +* This routine is meant to function as a delayed operation, and may return +* -EAGAIN when the transaction needs to be rolled. Calling functions will need +* to handle this, and recall the function until a successful error code is +* returned. +*/ +STATIC int +xfs_attr_set_iter( + struct xfs_delattr_context *dac,
fs/xfs/libxfs/xfs_attr.c int · line 342
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10
-0+ struct xfs_buf **leaf_bp) +{ +struct xfs_da_args *args = dac->da_args; +struct xfs_inode *dp = args->dp; +int error =0 ; + +/* State machine switch */ +switch (dac->dela_state) { +case XFS_DAS_FLIP_LFLAG : +case XFS_DAS_FOUND_LBLK :
Do we need to catch XFS_DAS_RM_LBLK here?
Quoted 36 lines
fs/xfs/libxfs/xfs_attr.c +18
-8+ goto das_leaf; +case XFS_DAS_FOUND_NBLK : +case XFS_DAS_FLIP_NFLAG : +case XFS_DAS_ALLOC_NODE : + goto das_node; +default : +break ; + }/* * If the attribute list is already in leaf format, jump straight to * leaf handling. Otherwise, try to add the attribute to the shortform * list; if there's no room then convert the list to leaf format and try -* again. +* again. No need to set state as we will be in leaf form when we come +* back */ if (xfs_attr_is_shortform (dp)) {/* -* If the attr was successfully set in shortform, the -* transaction is committed and set to NULL. Otherwise, is it -* converted from shortform to leaf, and the transaction is -* retained. +* If the attr was successfully set in shortform, no need to +* continue. Otherwise, is it converted from shortform to leaf +* and -EAGAIN is returned. */ - error =xfs_attr_set_shortform (args, &leaf_bp); -if (error || !args->trans) -return error; + error =xfs_attr_set_shortform (args, leaf_bp); +if (error == -EAGAIN ) + dac->flags |=XFS_DAC_DEFER_FINISH ; + +return error;
fs/xfs/libxfs/xfs_attr.c int · line 376
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +4
-4} -if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) { - error =xfs_attr_leaf_addname (args); -if (error != -ENOSPC ) -return error; +/* +* After a shortform to leaf conversion, we need to hold the leaf and +* cycle out the transaction. When we get back, we need to release +* the leaf.
"...to release the hold on the leaf buffer."
Quoted 30 lines
fs/xfs/libxfs/xfs_attr.c +15
-13+*/ +if (*leaf_bp !=NULL ) { +xfs_trans_bhold_release (args->trans, *leaf_bp); + *leaf_bp =NULL ; + } -/* -* Promote the attribute list to the Btree format. -*/ - error =xfs_attr3_leaf_to_node (args); -if (error) -return error; +if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) { + error =xfs_attr_leaf_try_add (args, *leaf_bp); +switch (error) { +case -ENOSPC : +/* +* Promote the attribute list to the Btree format. +*/ + error =xfs_attr3_leaf_to_node (args); +if (error) +return error; -/* -* 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);
fs/xfs/libxfs/xfs_attr.c int · line 402
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +9
-1-if (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. +*/ + dac->flags |=XFS_DAC_DEFER_FINISH ; +return -EAGAIN ;
What state should we be in at this -EAGAIN return? Is it XFS_DAS_UNINIT, but with more than one extent in the attr fork?
/me is wishing these would get turned into explicit states, since afaict we don't unlock the inode and so we should find it in /exactly/ the state that the delattr_context says it should be in.
fs/xfs/libxfs/xfs_attr.c int · line 409
Quoted 7 lines
fs/xfs/libxfs/xfs_attr.c +6
-0+case 0 : + dac->dela_state =XFS_DAS_FOUND_LBLK ; +return -EAGAIN ; +default :return error; + } +das_leaf:
The only way to get to this block of code is by jumping to das_leaf, from the switch statement above, right? If so, then shouldn't it be up there in the switch statement?
fs/xfs/libxfs/xfs_attr.c int · line 416
Quoted 7 lines
fs/xfs/libxfs/xfs_attr.c +7
-0+ error =xfs_attr_leaf_addname (dac); +if (error == -ENOSPC ) +/* +* No need to set state. We will be in node form when +* we are recalled +*/ +return -EAGAIN ;
How do we get to node form?
Quoted 4 lines
fs/xfs/libxfs/xfs_attr.c +0
-4-/* -* Commit the current trans (including the inode) and -* start a new one. -*/
fs/xfs/libxfs/xfs_attr.c int · line 422
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +3
-5- error =xfs_trans_roll_inode (&args->trans, dp); -if (error) -return error; +return error; } - - error =xfs_attr_node_addname (args); +das_node: + error =xfs_attr_node_addname (dac);return error;
Similarly, I think the only way get to this block of code is if we're in the initial state (XFS_DAS_UNINIT?) and the inode wasn't in short format; or if we jumped here via DAS_{FOUND_NBLK,FLIP_NFLAG,ALLOC_NODE}, right?
I think you could straighten this out a bit further (I left out the comments):
switch (dac->dela_state) {
case XFS_DAS_FLIP_LFLAG:
case XFS_DAS_FOUND_LBLK:
error = xfs_attr_leaf_addname(dac);
if (error == -ENOSPC)
return -EAGAIN;
return error;
case XFS_DAS_FOUND_NBLK:
case XFS_DAS_FLIP_NFLAG:
case XFS_DAS_ALLOC_NODE:
return xfs_attr_node_addname(dac);
case XFS_DAS_UNINIT:
break;
default:
...assert on the XFS_DAS_RM_* flags...
}
if (xfs_attr_is_shortform(dp))
return xfs_attr_set_shortform(args, leaf_bp);
if (*leaf_bp != NULL) {
...release bhold...
}
if (!xfs_bmap_one_block(...))
return xfs_attr_node_addname(dac);
error = xfs_attr_leaf_try_add(args, *leaf_bp);
switch (error) {
...handle -ENOSPC and 0...
}
return error;Quoted 68 lines
fs/xfs/libxfs/xfs_attr.c +31
-19}@@ -723,28 +790,30 @@ xfs_attr_leaf_try_add(* * This leaf block cannot have a "remote" value, we only call this routine * if bmap_one_block() says there is only one block (ie: no remote blks). +* +* This routine is meant to function as a delayed operation, and may return +* -EAGAIN when the transaction needs to be rolled. Calling functions will need +* to handle this, and recall the function until a successful error code is +* returned. */ STATIC intxfs_attr_leaf_addname ( -struct xfs_da_args *args) +struct xfs_delattr_context *dac) { -int error, forkoff; -struct xfs_buf *bp =NULL ; -struct xfs_inode *dp = args->dp; - -trace_xfs_attr_leaf_addname (args); - - error =xfs_attr_leaf_try_add (args, bp); -if (error) -return error; +struct xfs_da_args *args = dac->da_args; +struct xfs_buf *bp =NULL ; +int error, forkoff; +struct xfs_inode *dp = args->dp; -/* -* Commit the transaction that added the attr name so that -* later routines can manage their own transactions. -*/ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) -return error; +/* State machine switch */ +switch (dac->dela_state) { +case XFS_DAS_FLIP_LFLAG : + goto das_flip_flag; +case XFS_DAS_RM_LBLK : + goto das_rm_lblk; +default : +break ; + }/* * If there was an out-of-line value, allocate the blocks we @@ -752,12 +821,34 @@ xfs_attr_leaf_addname(* after we create the attribute so that we don't overflow the * maximum size of a transaction and/or hit a deadlock. */ -if (args->rmtblkno >0 ) { - error =xfs_attr_rmtval_set (args); + +/* Open coded xfs_attr_rmtval_set without trans handling */ +if ((dac->flags &XFS_DAC_LEAF_ADDNAME_INIT ) ==0 ) { + dac->flags |=XFS_DAC_LEAF_ADDNAME_INIT ; +if (args->rmtblkno >0 ) { + error =xfs_attr_rmtval_find_space (dac); +if (error) +return error; + } + } + +/*
fs/xfs/libxfs/xfs_attr.c xfs_attr_leaf_addname( · line 845
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +8
-0+* 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; + + dac->flags |=XFS_DAC_DEFER_FINISH ; +return -EAGAIN ;
What state are we in here? FOUND_LBLK, with blkcnt slowly decreasing?
Quoted 109 lines
fs/xfs/libxfs/xfs_attr.c +39
-25} + 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. @@ -777,29 +868,29 @@ xfs_attr_leaf_addname(* In a separate transaction, set the incomplete flag on the "old" attr * and clear the incomplete flag on the "new" attr. */ - error =xfs_attr3_leaf_flipflags (args);if (error)return error;/* * Commit the flag value change and start the next trans in series. */ - error =xfs_trans_roll_inode (&args->trans, args->dp); -if (error) -return error; - + dac->dela_state =XFS_DAS_FLIP_LFLAG ; +return -EAGAIN ; +das_flip_flag:/* * Dismantle the "old" attribute/value pair by removing a "remote" value * (if it exists). */ xfs_attr_restore_rmt_blk (args); + error =xfs_attr_rmtval_invalidate (args); +if (error) +return error; +das_rm_lblk:if (args->rmtblkno) { - error =xfs_attr_rmtval_invalidate (args); -if (error) -return error; - - error =xfs_attr_rmtval_remove (args); + error =__xfs_attr_rmtval_remove (dac); +if (error == -EAGAIN ) + dac->dela_state =XFS_DAS_RM_LBLK ;if (error)return error; }@@ -965,23 +1056,38 @@ xfs_attr_node_hasname(* * "Remote" attribute values confuse the issue and atomic rename operations * add a whole extra layer of confusion on top of that. +* +* This routine is meant to function as a delayed operation, and may return +* -EAGAIN when the transaction needs to be rolled. Calling functions will need +* to handle this, and recall the function until a successful error code is +*returned. */ STATIC intxfs_attr_node_addname ( -struct xfs_da_args *args) +struct xfs_delattr_context *dac) { -struct xfs_da_state *state; -struct xfs_da_state_blk *blk; -struct xfs_inode *dp; -int retval, error; +struct xfs_da_args *args = dac->da_args; +struct xfs_da_state *state =NULL ; +struct xfs_da_state_blk *blk; +int retval =0 ; +int error =0 ;trace_xfs_attr_node_addname (args); -/* -* Fill in bucket of arguments/results/context to carry around. -*/ - dp = args->dp; -restart: +/* State machine switch */ +switch (dac->dela_state) { +case XFS_DAS_FLIP_NFLAG : + goto das_flip_flag; +case XFS_DAS_FOUND_NBLK : + goto das_found_nblk; +case XFS_DAS_ALLOC_NODE : + goto das_alloc_node; +case XFS_DAS_RM_NBLK : + goto das_rm_nblk; +default : +break ; + } +/* * Search to see if name already exists, and get back a pointer * to where it should go. @@ -1027,19 +1133,13 @@ xfs_attr_node_addname( error =xfs_attr3_leaf_to_node (args);if (error) goto out; - error =xfs_defer_finish (&args->trans); -if (error) - goto out;/* -* Commit the node conversion and start the next -* trans in the chain.
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_addname( · line 1142
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +4
-5+* Restart routine from the top. No need to set the +* state */ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) - goto out; - - goto restart; + dac->flags |=XFS_DAC_DEFER_FINISH ; +return -EAGAIN ;
What state are we in here? Are we still in the same state that we were at the start of the function, but ready to try xfs_attr3_leaf_add again?
Quoted 102 lines
fs/xfs/libxfs/xfs_attr.c +39
-19}/* @@ -1051,9 +1151,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. @@ -1068,13 +1166,9 @@ xfs_attr_node_addname(xfs_da_state_free (state); state =NULL ; -/* -* Commit the leaf addition or btree split and start the next -* trans in the chain. -*/ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) - goto out; + dac->dela_state =XFS_DAS_FOUND_NBLK ; +return -EAGAIN ; +das_found_nblk:/* * If there was an out-of-line value, allocate the blocks we @@ -1083,7 +1177,27 @@ xfs_attr_node_addname(* maximum size of a transaction and/or hit a deadlock. */ if (args->rmtblkno >0 ) { - error =xfs_attr_rmtval_set (args); +/* Open coded xfs_attr_rmtval_set without trans handling */ + error =xfs_attr_rmtval_find_space (dac); +if (error) +return error; + +/* +* Roll through the "value", allocating blocks on disk as +* required. +*/ +das_alloc_node: +if (dac->blkcnt >0 ) { + error =xfs_attr_rmtval_set_blk (dac); +if (error) +return error; + + dac->flags |=XFS_DAC_DEFER_FINISH ; + dac->dela_state =XFS_DAS_ALLOC_NODE ; +return -EAGAIN ; + } + + error =xfs_attr_rmtval_set_value (args);if (error)return error; }@@ -1113,22 +1227,28 @@ xfs_attr_node_addname(/* * Commit the flag value change and start the next trans in series */ - error =xfs_trans_roll_inode (&args->trans, args->dp); -if (error) - goto out; - + dac->dela_state =XFS_DAS_FLIP_NFLAG ; +return -EAGAIN ; +das_flip_flag:/* * Dismantle the "old" attribute/value pair by removing a "remote" value * (if it exists). */ xfs_attr_restore_rmt_blk (args); + error =xfs_attr_rmtval_invalidate (args); +if (error) +return error; + +das_rm_nblk:if (args->rmtblkno) { - error =xfs_attr_rmtval_invalidate (args); -if (error) -return error; + error =__xfs_attr_rmtval_remove (dac); + +if (error == -EAGAIN ) { + dac->dela_state =XFS_DAS_RM_NBLK ; +return -EAGAIN ; + } - error =xfs_attr_rmtval_remove (args);if (error)return error; }fs/xfs/libxfs/xfs_attr.h +0
-0
fs/xfs/libxfs/xfs_attr.h struct xfs_attr_list_context { · line 114
Quoted 9 lines
fs/xfs/libxfs/xfs_attr.h +6
-0@@ -106,6 +106,118 @@ struct xfs_attr_list_context {* v │ * done <─────┘ * +* +* Below is a state machine diagram for attr set operations. +* +* xfs_attr_set_iter() +* │ +* v
I think this diagram is missing the part where we attempt to add a shortform attr?
--D
Quoted 310 lines
fs/xfs/libxfs/xfs_attr.h +119
-1+* ┌───n── fork has +* │ only 1 blk? +* │ │ +* │ y +* │ │ +* │ v +* │ xfs_attr_leaf_try_add() +* │ │ +* │ v +* │ had enough +* ├───n────space? +* │ │ +* │ y +* │ │ +* │ v +* │ XFS_DAS_FOUND_LBLK ──┐ +* │ │ +* │ XFS_DAS_FLIP_LFLAG ──┤ +* │ (subroutine state) │ +* │ │ +* │ └─>xfs_attr_leaf_addname() +* │ │ +* │ v +* │ was this +* │ a rename? ──n─┐ +* │ │ │ +* │ y │ +* │ │ │ +* │ v │ +* │ flip incomplete │ +* │ flag │ +* │ │ │ +* │ v │ +* │ XFS_DAS_FLIP_LFLAG │ +* │ │ │ +* │ v │ +* │ remove │ +* │ XFS_DAS_RM_LBLK ─> old name │ +* │ ^ │ │ +* │ │ v │ +* │ └──────y── more to │ +* │ remove │ +* │ │ │ +* │ n │ +* │ │ │ +* │ v │ +* │ done <──────┘ +* └──> XFS_DAS_FOUND_NBLK ──┐ +* (subroutine state) │ +* │ +* XFS_DAS_ALLOC_NODE ──┤ +* (subroutine state) │ +* │ +* XFS_DAS_FLIP_NFLAG ──┤ +* (subroutine state) │ +* │ +* └─>xfs_attr_node_addname() +* │ +* v +* find space to store +* attr. Split if needed +* │ +* v +* XFS_DAS_FOUND_NBLK +* │ +* v +* ┌─────n── need to +* │ alloc blks? +* │ │ +* │ y +* │ │ +* │ v +* │ ┌─>XFS_DAS_ALLOC_NODE +* │ │ │ +* │ │ v +* │ └──y── need to alloc +* │ more blocks? +* │ │ +* │ n +* │ │ +* │ v +* │ was this +* └────────> a rename? ──n─┐ +* │ │ +* y │ +* │ │ +* v │ +* flip incomplete │ +* flag │ +* │ │ +* v │ +* XFS_DAS_FLIP_NFLAG │ +* │ │ +* v │ +* remove │ +* XFS_DAS_RM_NBLK ─> old name │ +* ^ │ │ +* │ v │ +* └──────y── more to │ +* remove │ +* │ │ +* n │ +* │ │ +* v │ +* done <──────┘ +* */ /* @@ -120,6 +232,13 @@ struct xfs_attr_list_context {enum xfs_delattr_state {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 */ };/* @@ -127,6 +246,7 @@ enum xfs_delattr_state {*/ #define XFS_DAC_DEFER_FINISH 0x01/* finish the transaction */ #define XFS_DAC_NODE_RMVNAME_INIT 0x02/* xfs_attr_node_removename init */ +#define XFS_DAC_LEAF_ADDNAME_INIT 0x04/* xfs_attr_leaf_addname init*/ /* * Context used for keeping track of delayed attribute operations @@ -134,6 +254,11 @@ enum xfs_delattr_state {struct xfs_delattr_context {struct xfs_da_args *da_args; +/* Used in xfs_attr_rmtval_set_blk to roll through allocating blocks */ +struct xfs_bmbt_irec map; +xfs_dablk_t lblkno; +int blkcnt; +/* Used in xfs_attr_node_removename to roll through removing blocks */ struct xfs_da_state *da_state;@@ -160,7 +285,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
-34@@ -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,38 +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
-0@@ -15,4 +15,8 @@ int xfs_attr_rmtval_stale(struct xfs_inode *ip, struct xfs_bmbt_irec *map, xfs_buf_flags_t incore_flags);int xfs_attr_rmtval_invalidate (struct xfs_da_args *args);int __xfs_attr_rmtval_remove (struct xfs_delattr_context *dac); +int xfs_attr_rmt_find_hole (struct xfs_da_args *args); +int xfs_attr_rmtval_set_value (struct xfs_da_args *args); +int xfs_attr_rmtval_set_blk (struct xfs_delattr_context *dac); +int xfs_attr_rmtval_find_space (struct xfs_delattr_context *dac);#endif /* __XFS_ATTR_REMOTE_H__ */ fs/xfs/xfs_trace.h +0
-1@@ -1925,7 +1925,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 v13 03/10] xfs: Add delay ready attr set routines
Quoted 87 lines · Darrick J. Wong
Quoted 73 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_set_initandxfs_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.Signed-off-by Allison Henderson <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 370 ++++++++++++++++++++++++++-------------- fs/xfs/libxfs/xfs_attr.h | 126 +++++++++++++- fs/xfs/libxfs/xfs_attr_remote.c | 99 +++++++---- fs/xfs/libxfs/xfs_attr_remote.h | 4 + fs/xfs/xfs_trace.h | 1 - 5 files changed, 439 insertions(+), 161 deletions(-)fs/xfs/libxfs/xfs_attr.c +10
-4@@ -44,7 +44,7 @@ STATIC int xfs_attr_shortform_addname(xfs_da_args_t *args);* Internal routines when attribute list is one block. */ STATIC int xfs_attr_leaf_get(xfs_da_args_t *args); -STATIC int xfs_attr_leaf_addname(xfs_da_args_t *args); +STATIC int xfs_attr_leaf_addname(struct xfs_delattr_context *dac); STATIC int xfs_attr_leaf_removename(xfs_da_args_t *args); STATIC int xfs_attr_leaf_hasname(struct xfs_da_args *args, struct xfs_buf **bp);@@ -52,12 +52,15 @@ STATIC int xfs_attr_leaf_hasname(struct xfs_da_args *args, struct xfs_buf **bp);* Internal routines when attribute list is more than one block. */ STATIC int xfs_attr_node_get(xfs_da_args_t *args); -STATIC int xfs_attr_node_addname(xfs_da_args_t *args); +STATIC int xfs_attr_node_addname(struct xfs_delattr_context *dac); STATIC int xfs_attr_node_removename_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_leaf_try_add(struct xfs_da_args *args, struct xfs_buf *bp); +STATIC int xfs_attr_set_iter(struct xfs_delattr_context *dac, +struct xfs_buf **leaf_bp);int xfs_inode_hasattr(@@ -218,8 +221,11 @@ xfs_attr_is_shortform(/* * Attempts to set an attr in shortform, or converts short form to leaf form if -* there is not enough room. If the attr is set, the transaction is committed -* and set to NULL. +* there is not enough room. This function is meant to operate as a helper +* routine to the delayed attribute functions. It returns -EAGAIN to indicate +* that the calling function should roll the transaction, and then proceed to +* add the attr in leaf form. This subroutine does not expect to be recalled +* again like the other delayed attr routines do. */ STATIC int xfs_attr_set_shortform(@@ -227,16 +233,16 @@ xfs_attr_set_shortform( struct xfs_buf **leaf_bp) {fs/xfs/libxfs/xfs_attr.c xfs_attr_set_shortform( · line 243
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +3
-1struct xfs_inode *dp = args->dp; -int error, error2 =0 ; +int error =0 ;/* * Try to add the attr to the attribute list in the inode. */ error =xfs_attr_try_sf_addname (dp, args); + +/* Should only be 0, -EEXIST or ENOSPC */ Nit: "...or
-ENOSPC"
Quoted 1 line
Also, this comment could go a couple of lines up:
Sure
Quoted 33 lines
/* * Try to add the attr to the attribute list in the inode. * This should only return 0, -EEXIST, or -ENOSPC. */ error = xfs_attr_try_sf_addname(dp, args); if (error != -ENOSPC) return error;Quoted 23 lines
fs/xfs/libxfs/xfs_attr.c +2
-11if (error != -ENOSPC ) { - error2 =xfs_trans_commit (args->trans); - args->trans =NULL ; -return error ? error : error2; +return error; }/* * It won't fit in the shortform, transform to a leaf block. GROT: @@ -249,18 +255,10 @@ xfs_attr_set_shortform(/* * Prevent the leaf buffer from being unlocked so that a concurrent AIL * push cannot grab the half-baked leaf buffer and run into problems -* with the write verifier. Once we're done rolling the transaction we -* can release the hold and add the attr to the leaf. +* with the write verifier. */ xfs_trans_bhold (args->trans, *leaf_bp); - error =xfs_defer_finish (&args->trans); -xfs_trans_bhold_release (args->trans, *leaf_bp); -if (error) { -xfs_trans_brelse (args->trans, *leaf_bp); -return error; - }
Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_set_shortform( · line 261
Quoted 3 lines
fs/xfs/libxfs/xfs_attr.c +1
-2- -return 0 ; +return -EAGAIN ;What state are we in when return
-EAGAINhere? Are we still inXFS_DAS_UNINIT, but with an attr fork that is no longer in local format, which means that we skip thexfs_attr_is_shortformbranch next time around?
Yes, that's correct. I think I used to have an explicit state for it, but it's really not needed for this reason. Though I think they do add some degree of readability. Maybe we could add a comment?
/* Restart attr operation in leaf format */
?
Quoted 59 lines
Quoted 59 lines
fs/xfs/libxfs/xfs_attr.c +40
-4}/* @@ -268,7 +266,7 @@ xfs_attr_set_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) {@@ -297,61 +295,130 @@ intxfs_attr_set_args ( struct xfs_da_args *args) { -struct xfs_inode *dp = args->dp; -struct xfs_buf *leaf_bp =NULL ; -int error =0 ; +struct xfs_buf *leaf_bp =NULL ; +int error =0 ; +struct xfs_delattr_context dac = { + .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; + +if (leaf_bp) { +xfs_trans_bjoin (args->trans, leaf_bp); +xfs_trans_bhold (args->trans, leaf_bp); + } + + }while (true); + +return error; +} + +/* +* Set the attribute specified in @args. +* This routine is meant to function as a delayed operation, and may return +* -EAGAIN when the transaction needs to be rolled. Calling functions will need +* to handle this, and recall the function until a successful error code is +* returned. +*/ +STATIC int +xfs_attr_set_iter ( +struct xfs_delattr_context *dac, +struct xfs_buf **leaf_bp) +{ +struct xfs_da_args *args = dac->da_args; +struct xfs_inode *dp = args->dp;
Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c int · line 342
Quoted 6 lines
fs/xfs/libxfs/xfs_attr.c +6
-0+int error =0 ; + +/* State machine switch */ +switch (dac->dela_state) { +case XFS_DAS_FLIP_LFLAG : +case XFS_DAS_FOUND_LBLK :Do we need to catch
XFS_DAS_RM_LBLKhere?
I think we fall into the correct code path without it, but I think it's better to have it here for consistency. Will add.
Quoted 39 lines
Quoted 39 lines
fs/xfs/libxfs/xfs_attr.c +18
-8+ goto das_leaf; +case XFS_DAS_FOUND_NBLK : +case XFS_DAS_FLIP_NFLAG : +case XFS_DAS_ALLOC_NODE : + goto das_node; +default : +break ; + }/* * If the attribute list is already in leaf format, jump straight to * leaf handling. Otherwise, try to add the attribute to the shortform * list; if there's no room then convert the list to leaf format and try -* again. +* again. No need to set state as we will be in leaf form when we come +* back */ if (xfs_attr_is_shortform (dp)) {/* -* If the attr was successfully set in shortform, the -* transaction is committed and set to NULL. Otherwise, is it -* converted from shortform to leaf, and the transaction is -* retained. +* If the attr was successfully set in shortform, no need to +* continue. Otherwise, is it converted from shortform to leaf +* and -EAGAIN is returned. */ - error =xfs_attr_set_shortform (args, &leaf_bp); -if (error || !args->trans) -return error; + error =xfs_attr_set_shortform (args, leaf_bp); +if (error == -EAGAIN ) + dac->flags |=XFS_DAC_DEFER_FINISH ; + +return error; }
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c int · line 376
Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c +4
-4-if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) { - error =xfs_attr_leaf_addname (args); -if (error != -ENOSPC ) -return error; +/* +* After a shortform to leaf conversion, we need to hold the leaf and +* cycle out the transaction. When we get back, we need to release +* the leaf. "...to release the hold on the leaf buffer."
Sure, will expand
Quoted 36 lines
Quoted 36 lines
fs/xfs/libxfs/xfs_attr.c +19
-14+*/ +if (*leaf_bp !=NULL ) { +xfs_trans_bhold_release (args->trans, *leaf_bp); + *leaf_bp =NULL ; + } -/* -* Promote the attribute list to the Btree format. -*/ - error =xfs_attr3_leaf_to_node (args); -if (error) -return error; +if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) { + error =xfs_attr_leaf_try_add (args, *leaf_bp); +switch (error) { +case -ENOSPC : +/* +* Promote the attribute list to the Btree format. +*/ + error =xfs_attr3_leaf_to_node (args); +if (error) +return error; -/* -* 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) +/* +* 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
Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c int · line 402
Quoted 5 lines
fs/xfs/libxfs/xfs_attr.c +5
-0+* same state (inode locked and joined, transaction +* clean) no matter how we got to this step. +*/ + dac->flags |=XFS_DAC_DEFER_FINISH ; +return -EAGAIN ;What state should we be in at this
-EAGAINreturn? Is itXFS_DAS_UNINIT, but with more than one extent in the attr fork?
It could be UNINIT, if the attr was already a leaf at the time we started. If we had to promote from a block to a leaf, and STILL counldnt fit in leaf form, then we're probably in some state reminiscent of the leaf routines. But because xfs_attr3_leaf_to_node just turned us into a node, we fall into the node path upon return.
I know that's confusing... which leads to your next question of.....
Quoted 4 lines
/me is wishing these would get turned into explicit states, since afaict we don't unlock the inode and so we should find it in /exactly/ the state that the
delattr_contextsays it should be in.
IIRC it used to have an explicit XFS_DC_LEAF_TO_NODE state, but I think we simplified it away at some point in the reviewing in an effort to simplify the statemachine as much as possible. v8 I think. But yes, I do think there is a trade off between removing the states where they can be, but then reducing the readability of where we are in the attr process. Because now your state isnt exactly represented by dela_state anymore, it's the combination of dela_state and the state of the tree.
I think I've been over this code so much by now, I can follow it either way, but if it's confusing to others, maybe we should put it back? Or maybe just a comment if that helps?
Quoted 12 lines
fs/xfs/libxfs/xfs_attr.c int · line 409
Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c +6
-0+case 0 : + dac->dela_state =XFS_DAS_FOUND_LBLK ; +return -EAGAIN ; +default :return error; + } +das_leaf:The only way to get to this block of code is by jumping to
das_leaf, from the switch statement above, right? If so, then shouldn't it be up there in the switch statement?
We could, though I think we were just trying to be consistent in that the switch is sort of a dispatcher for gotos? Otherwise we end up with a switch with giant cases. It's the same difference I suppose.
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c int · line 416
Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c +7
-0+ error =xfs_attr_leaf_addname (dac); +if (error == -ENOSPC ) +/* +* No need to set state. We will be in node form when +* we are recalled +*/ +return -EAGAIN ;How do we get to node form?
Hmm, I thought xfs_attr_leaf_addname did promote to node if theres not enough space, but now that you point it out, i'm not seeing it. We may have to put the LEAF_TO_NODE state back anyway.
maybe i can add a test case too, it doesnt look like any of the existing cases run across it.
Quoted 48 lines
Quoted 5 lines
fs/xfs/libxfs/xfs_attr.c +0
-4-/* -* Commit the current trans (including the inode) and -* start a new one. -*/ fs/xfs/libxfs/xfs_attr.c int · line 422
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +3
-5- error =xfs_trans_roll_inode (&args->trans, dp); -if (error) -return error; +return error; } - - error =xfs_attr_node_addname (args); +das_node: + error =xfs_attr_node_addname (dac);return error;Similarly, I think the only way get to this block of code is if we're in the initial state (
XFS_DAS_UNINIT?) and the inode wasn't in short format; or if we jumped here via DAS_{FOUND_NBLK,FLIP_NFLAG,ALLOC_NODE}, right?I think you could straighten this out a bit further (I left out the comments):
switch (dac->dela_state) { case XFS_DAS_FLIP_LFLAG: case XFS_DAS_FOUND_LBLK: error = xfs_attr_leaf_addname(dac); if (error == -ENOSPC) return -EAGAIN; return error; case XFS_DAS_FOUND_NBLK: case XFS_DAS_FLIP_NFLAG: case XFS_DAS_ALLOC_NODE: return xfs_attr_node_addname(dac); case XFS_DAS_UNINIT: break; default: ...assert on the XFS_DAS_RM_* flags... } if (xfs_attr_is_shortform(dp)) return xfs_attr_set_shortform(args, leaf_bp); if (*leaf_bp != NULL) { ...release bhold... }
Quoted 9 lines
if (!xfs_bmap_one_block(...))
return xfs_attr_node_addname(dac);
error = xfs_attr_leaf_try_add(args, *leaf_bp);
switch (error) {
...handle -ENOSPC and 0...
}
return error;Ok, I'll see if I can get something like that through the test cases. If if doesnt work out, I'll make a note of it.
Quoted 72 lines
Quoted 72 lines
fs/xfs/libxfs/xfs_attr.c +35
-19}@@ -723,28 +790,30 @@ xfs_attr_leaf_try_add(* * This leaf block cannot have a "remote" value, we only call this routine * if bmap_one_block() says there is only one block (ie: no remote blks). +* +* This routine is meant to function as a delayed operation, and may return +* -EAGAIN when the transaction needs to be rolled. Calling functions will need +* to handle this, and recall the function until a successful error code is +* returned. */ STATIC intxfs_attr_leaf_addname ( -struct xfs_da_args *args) +struct xfs_delattr_context *dac) { -int error, forkoff; -struct xfs_buf *bp =NULL ; -struct xfs_inode *dp = args->dp; - -trace_xfs_attr_leaf_addname (args); - - error =xfs_attr_leaf_try_add (args, bp); -if (error) -return error; +struct xfs_da_args *args = dac->da_args; +struct xfs_buf *bp =NULL ; +int error, forkoff; +struct xfs_inode *dp = args->dp; -/* -* Commit the transaction that added the attr name so that -* later routines can manage their own transactions. -*/ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) -return error; +/* State machine switch */ +switch (dac->dela_state) { +case XFS_DAS_FLIP_LFLAG : + goto das_flip_flag; +case XFS_DAS_RM_LBLK : + goto das_rm_lblk; +default : +break ; + }/* * If there was an out-of-line value, allocate the blocks we @@ -752,12 +821,34 @@ xfs_attr_leaf_addname(* after we create the attribute so that we don't overflow the * maximum size of a transaction and/or hit a deadlock. */ -if (args->rmtblkno >0 ) { - error =xfs_attr_rmtval_set (args); + +/* Open coded xfs_attr_rmtval_set without trans handling */ +if ((dac->flags &XFS_DAC_LEAF_ADDNAME_INIT ) ==0 ) { + dac->flags |=XFS_DAC_LEAF_ADDNAME_INIT ; +if (args->rmtblkno >0 ) { + error =xfs_attr_rmtval_find_space (dac); +if (error) +return error; + } + } + +/* +* Roll through the "value", allocating blocks on disk as +* required. +*/ +if (dac->blkcnt >0 ) {
Quoted 9 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_leaf_addname( · line 845
Quoted 6 lines
fs/xfs/libxfs/xfs_attr.c +4
-0+ error =xfs_attr_rmtval_set_blk (dac);if (error)return error; + + dac->flags |=XFS_DAC_DEFER_FINISH ; +return -EAGAIN ;What state are we in here?
FOUND_LBLK, with blkcnt slowly decreasing?
I used to have an ALLOC_LEAF state for this one. Used to look something like this:
+alloc_leaf:
+ while (args->dac.blkcnt > 0) {
+ error = xfs_attr_rmtval_set_blk(args);
+ if (error)
+ return error;
+
+ args->dac.flags |= XFS_DAC_FINISH_TRANS; + args->dac.dela_state = XFS_DAS_ALLOC_LEAF; + return -EAGAIN;
+ }
Again, it's not really needed, as we will fall into this logic with or with out the state. And the while loop doesnt really loop, though I guess it does sort of help the reader to understand that this is supposed to function like a loop. I think it's easy to see something like that, and then want to simplify away the extra semantics, but then on a second look, it's not quite as obvious why with out the recollection of what it once was. Maybe a comment is in order?
/* Repeat this until we have set all rmt blks */
?
To directly answer your question though, I think the state is still UNINIT at this point, since any of the other states would have branched off before this. It's important to note though that the functions that have states are meant to sort of take ownership the statemachine. IOW, if the state coming in does not apply to the scope of this function, or any of the subroutines there in, then the state is simply overwritten as this function decides appropriate. It doesnt throw an error if it is passed a state that used to belong to it's parent. Calling functions should understand that they have sort of "surrendered" the statemachine to this subfunction until it returns something other than EAGAIN. At least that's the idea. Honnestly, the only reason I have UNINIT at all is because we get warnings about setting the state to 0 when the enum needs to start at something other than 0.
Hope that helps?
Quoted 106 lines
Quoted 106 lines
fs/xfs/libxfs/xfs_attr.c +39
-23} + 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. @@ -777,29 +868,29 @@ xfs_attr_leaf_addname(* In a separate transaction, set the incomplete flag on the "old" attr * and clear the incomplete flag on the "new" attr. */ - error =xfs_attr3_leaf_flipflags (args);if (error)return error;/* * Commit the flag value change and start the next trans in series. */ - error =xfs_trans_roll_inode (&args->trans, args->dp); -if (error) -return error; - + dac->dela_state =XFS_DAS_FLIP_LFLAG ; +return -EAGAIN ; +das_flip_flag:/* * Dismantle the "old" attribute/value pair by removing a "remote" value * (if it exists). */ xfs_attr_restore_rmt_blk (args); + error =xfs_attr_rmtval_invalidate (args); +if (error) +return error; +das_rm_lblk:if (args->rmtblkno) { - error =xfs_attr_rmtval_invalidate (args); -if (error) -return error; - - error =xfs_attr_rmtval_remove (args); + error =__xfs_attr_rmtval_remove (dac); +if (error == -EAGAIN ) + dac->dela_state =XFS_DAS_RM_LBLK ;if (error)return error; }@@ -965,23 +1056,38 @@ xfs_attr_node_hasname(* * "Remote" attribute values confuse the issue and atomic rename operations * add a whole extra layer of confusion on top of that. +* +* This routine is meant to function as a delayed operation, and may return +* -EAGAIN when the transaction needs to be rolled. Calling functions will need +* to handle this, and recall the function until a successful error code is +*returned. */ STATIC intxfs_attr_node_addname ( -struct xfs_da_args *args) +struct xfs_delattr_context *dac) { -struct xfs_da_state *state; -struct xfs_da_state_blk *blk; -struct xfs_inode *dp; -int retval, error; +struct xfs_da_args *args = dac->da_args; +struct xfs_da_state *state =NULL ; +struct xfs_da_state_blk *blk; +int retval =0 ; +int error =0 ;trace_xfs_attr_node_addname (args); -/* -* Fill in bucket of arguments/results/context to carry around. -*/ - dp = args->dp; -restart: +/* State machine switch */ +switch (dac->dela_state) { +case XFS_DAS_FLIP_NFLAG : + goto das_flip_flag; +case XFS_DAS_FOUND_NBLK : + goto das_found_nblk; +case XFS_DAS_ALLOC_NODE : + goto das_alloc_node; +case XFS_DAS_RM_NBLK : + goto das_rm_nblk; +default : +break ; + } +/* * Search to see if name already exists, and get back a pointer * to where it should go. @@ -1027,19 +1133,13 @@ xfs_attr_node_addname( error =xfs_attr3_leaf_to_node (args);if (error) goto out; - error =xfs_defer_finish (&args->trans); -if (error) - goto out;
Quoted 16 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_addname( · line 1142
Quoted 13 lines
fs/xfs/libxfs/xfs_attr.c +4
-7/* -* Commit the node conversion and start the next -* trans in the chain. +* Restart routine from the top. No need to set the +* state */ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) - goto out; - - goto restart; + dac->flags |=XFS_DAC_DEFER_FINISH ; +return -EAGAIN ;What state are we in here? Are we still in the same state that we were at the start of the function, but ready to try
xfs_attr3_leaf_addagain?
To directly answer the question: we may be in UNINIT if we were already a node when we started the attr op. If we had to promote from leaf to node, it may be some state left over from the leaf routines.
Again though, in so far as this routine is concerned, the idea is that the state either one of the cases in the switch up top, or it's not.
Quoted 107 lines
Quoted 107 lines
fs/xfs/libxfs/xfs_attr.c +39
-19}/* @@ -1051,9 +1151,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. @@ -1068,13 +1166,9 @@ xfs_attr_node_addname(xfs_da_state_free (state); state =NULL ; -/* -* Commit the leaf addition or btree split and start the next -* trans in the chain. -*/ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) - goto out; + dac->dela_state =XFS_DAS_FOUND_NBLK ; +return -EAGAIN ; +das_found_nblk:/* * If there was an out-of-line value, allocate the blocks we @@ -1083,7 +1177,27 @@ xfs_attr_node_addname(* maximum size of a transaction and/or hit a deadlock. */ if (args->rmtblkno >0 ) { - error =xfs_attr_rmtval_set (args); +/* Open coded xfs_attr_rmtval_set without trans handling */ + error =xfs_attr_rmtval_find_space (dac); +if (error) +return error; + +/* +* Roll through the "value", allocating blocks on disk as +* required. +*/ +das_alloc_node: +if (dac->blkcnt >0 ) { + error =xfs_attr_rmtval_set_blk (dac); +if (error) +return error; + + dac->flags |=XFS_DAC_DEFER_FINISH ; + dac->dela_state =XFS_DAS_ALLOC_NODE ; +return -EAGAIN ; + } + + error =xfs_attr_rmtval_set_value (args);if (error)return error; }@@ -1113,22 +1227,28 @@ xfs_attr_node_addname(/* * Commit the flag value change and start the next trans in series */ - error =xfs_trans_roll_inode (&args->trans, args->dp); -if (error) - goto out; - + dac->dela_state =XFS_DAS_FLIP_NFLAG ; +return -EAGAIN ; +das_flip_flag:/* * Dismantle the "old" attribute/value pair by removing a "remote" value * (if it exists). */ xfs_attr_restore_rmt_blk (args); + error =xfs_attr_rmtval_invalidate (args); +if (error) +return error; + +das_rm_nblk:if (args->rmtblkno) { - error =xfs_attr_rmtval_invalidate (args); -if (error) -return error; + error =__xfs_attr_rmtval_remove (dac); + +if (error == -EAGAIN ) { + dac->dela_state =XFS_DAS_RM_NBLK ; +return -EAGAIN ; + } - error =xfs_attr_rmtval_remove (args);if (error)return error; }fs/xfs/libxfs/xfs_attr.h +1
-0@@ -106,6 +106,118 @@ struct xfs_attr_list_context {* v │ * done <─────┘ * +*
Quoted 8 lines
fs/xfs/libxfs/xfs_attr.h struct xfs_attr_list_context { · line 114
Quoted 5 lines
fs/xfs/libxfs/xfs_attr.h +5
-0+* Below is a state machine diagram for attr set operations. +* +* xfs_attr_set_iter() +* │ +* v I think this diagram is missing the part where we attempt to add a shortform attr?
I left if out because the short form doesnt make use of states. I can doodle that in though if you prefer:
┌───n── is shortform?
│ |
│ y
│ |
│ V
│ xfs_attr_set_shortform
│ |
│ V
├───n─── had enough
│ space?
│ │
│ y
│ │
│ V
│ done
└────────────┐
│V
Quoted 2 lines
--D
Thx for the thorough reviews!
Allison
Quoted 311 lines
Quoted 311 lines
fs/xfs/libxfs/xfs_attr.h +119
-1+* ┌───n── fork has +* │ only 1 blk? +* │ │ +* │ y +* │ │ +* │ v +* │ xfs_attr_leaf_try_add() +* │ │ +* │ v +* │ had enough +* ├───n────space? +* │ │ +* │ y +* │ │ +* │ v +* │ XFS_DAS_FOUND_LBLK ──┐ +* │ │ +* │ XFS_DAS_FLIP_LFLAG ──┤ +* │ (subroutine state) │ +* │ │ +* │ └─>xfs_attr_leaf_addname() +* │ │ +* │ v +* │ was this +* │ a rename? ──n─┐ +* │ │ │ +* │ y │ +* │ │ │ +* │ v │ +* │ flip incomplete │ +* │ flag │ +* │ │ │ +* │ v │ +* │ XFS_DAS_FLIP_LFLAG │ +* │ │ │ +* │ v │ +* │ remove │ +* │ XFS_DAS_RM_LBLK ─> old name │ +* │ ^ │ │ +* │ │ v │ +* │ └──────y── more to │ +* │ remove │ +* │ │ │ +* │ n │ +* │ │ │ +* │ v │ +* │ done <──────┘ +* └──> XFS_DAS_FOUND_NBLK ──┐ +* (subroutine state) │ +* │ +* XFS_DAS_ALLOC_NODE ──┤ +* (subroutine state) │ +* │ +* XFS_DAS_FLIP_NFLAG ──┤ +* (subroutine state) │ +* │ +* └─>xfs_attr_node_addname() +* │ +* v +* find space to store +* attr. Split if needed +* │ +* v +* XFS_DAS_FOUND_NBLK +* │ +* v +* ┌─────n── need to +* │ alloc blks? +* │ │ +* │ y +* │ │ +* │ v +* │ ┌─>XFS_DAS_ALLOC_NODE +* │ │ │ +* │ │ v +* │ └──y── need to alloc +* │ more blocks? +* │ │ +* │ n +* │ │ +* │ v +* │ was this +* └────────> a rename? ──n─┐ +* │ │ +* y │ +* │ │ +* v │ +* flip incomplete │ +* flag │ +* │ │ +* v │ +* XFS_DAS_FLIP_NFLAG │ +* │ │ +* v │ +* remove │ +* XFS_DAS_RM_NBLK ─> old name │ +* ^ │ │ +* │ v │ +* └──────y── more to │ +* remove │ +* │ │ +* n │ +* │ │ +* v │ +* done <──────┘ +* */ /* @@ -120,6 +232,13 @@ struct xfs_attr_list_context {enum xfs_delattr_state {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 */ };/* @@ -127,6 +246,7 @@ enum xfs_delattr_state {*/ #define XFS_DAC_DEFER_FINISH 0x01/* finish the transaction */ #define XFS_DAC_NODE_RMVNAME_INIT 0x02/* xfs_attr_node_removename init */ +#define XFS_DAC_LEAF_ADDNAME_INIT 0x04/* xfs_attr_leaf_addname init*/ /* * Context used for keeping track of delayed attribute operations @@ -134,6 +254,11 @@ enum xfs_delattr_state {struct xfs_delattr_context {struct xfs_da_args *da_args; +/* Used in xfs_attr_rmtval_set_blk to roll through allocating blocks */ +struct xfs_bmbt_irec map; +xfs_dablk_t lblkno; +int blkcnt; +/* Used in xfs_attr_node_removename to roll through removing blocks */ struct xfs_da_state *da_state;@@ -160,7 +285,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
-34@@ -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,38 +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
-0@@ -15,4 +15,8 @@ int xfs_attr_rmtval_stale(struct xfs_inode *ip, struct xfs_bmbt_irec *map, xfs_buf_flags_t incore_flags);int xfs_attr_rmtval_invalidate (struct xfs_da_args *args);int __xfs_attr_rmtval_remove (struct xfs_delattr_context *dac); +int xfs_attr_rmt_find_hole (struct xfs_da_args *args); +int xfs_attr_rmtval_set_value (struct xfs_da_args *args); +int xfs_attr_rmtval_set_blk (struct xfs_delattr_context *dac); +int xfs_attr_rmtval_find_space (struct xfs_delattr_context *dac);#endif /* __XFS_ATTR_REMOTE_H__ */ fs/xfs/xfs_trace.h +0
-1@@ -1925,7 +1925,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 v13 03/10] xfs: Add delay ready attr set routines
Quoted 129 lines · Allison Henderson
Quoted 83 lines · Darrick J. Wong
Quoted 69 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_set_initandxfs_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.Signed-off-by Allison Henderson <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 370 ++++++++++++++++++++++++++-------------- fs/xfs/libxfs/xfs_attr.h | 126 +++++++++++++- fs/xfs/libxfs/xfs_attr_remote.c | 99 +++++++---- fs/xfs/libxfs/xfs_attr_remote.h | 4 + fs/xfs/xfs_trace.h | 1 - 5 files changed, 439 insertions(+), 161 deletions(-)fs/xfs/libxfs/xfs_attr.c +10
-4@@ -44,7 +44,7 @@ STATIC int xfs_attr_shortform_addname(xfs_da_args_t *args);* Internal routines when attribute list is one block. */ STATIC int xfs_attr_leaf_get(xfs_da_args_t *args); -STATIC int xfs_attr_leaf_addname(xfs_da_args_t *args); +STATIC int xfs_attr_leaf_addname(struct xfs_delattr_context *dac); STATIC int xfs_attr_leaf_removename(xfs_da_args_t *args); STATIC int xfs_attr_leaf_hasname(struct xfs_da_args *args, struct xfs_buf **bp);@@ -52,12 +52,15 @@ STATIC int xfs_attr_leaf_hasname(struct xfs_da_args *args, struct xfs_buf **bp);* Internal routines when attribute list is more than one block. */ STATIC int xfs_attr_node_get(xfs_da_args_t *args); -STATIC int xfs_attr_node_addname(xfs_da_args_t *args); +STATIC int xfs_attr_node_addname(struct xfs_delattr_context *dac); STATIC int xfs_attr_node_removename_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_leaf_try_add(struct xfs_da_args *args, struct xfs_buf *bp); +STATIC int xfs_attr_set_iter(struct xfs_delattr_context *dac, +struct xfs_buf **leaf_bp);int xfs_inode_hasattr(@@ -218,8 +221,11 @@ xfs_attr_is_shortform(/* * Attempts to set an attr in shortform, or converts short form to leaf form if -* there is not enough room. If the attr is set, the transaction is committed -* and set to NULL. +* there is not enough room. This function is meant to operate as a helper +* routine to the delayed attribute functions. It returns -EAGAIN to indicate +* that the calling function should roll the transaction, and then proceed to +* add the attr in leaf form. This subroutine does not expect to be recalled +* again like the other delayed attr routines do. */ STATIC int xfs_attr_set_shortform(@@ -227,16 +233,16 @@ xfs_attr_set_shortform( struct xfs_buf **leaf_bp)fs/xfs/libxfs/xfs_attr.c xfs_attr_set_shortform( · line 242
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +3
-1{struct xfs_inode *dp = args->dp; -int error, error2 =0 ; +int error =0 ;/* * Try to add the attr to the attribute list in the inode. */ error =xfs_attr_try_sf_addname (dp, args); + +/* Should only be 0, -EEXIST or ENOSPC */ Nit: "...or
-ENOSPC"Quoted 1 line
Also, this comment could go a couple of lines up:
Sure
Quoted 33 lines
/* * Try to add the attr to the attribute list in the inode. * This should only return 0, -EEXIST, or -ENOSPC. */ error = xfs_attr_try_sf_addname(dp, args); if (error != -ENOSPC) return error;Quoted 23 lines
fs/xfs/libxfs/xfs_attr.c +2
-11if (error != -ENOSPC ) { - error2 =xfs_trans_commit (args->trans); - args->trans =NULL ; -return error ? error : error2; +return error; }/* * It won't fit in the shortform, transform to a leaf block. GROT: @@ -249,18 +255,10 @@ xfs_attr_set_shortform(/* * Prevent the leaf buffer from being unlocked so that a concurrent AIL * push cannot grab the half-baked leaf buffer and run into problems -* with the write verifier. Once we're done rolling the transaction we -* can release the hold and add the attr to the leaf. +* with the write verifier. */ xfs_trans_bhold (args->trans, *leaf_bp); - error =xfs_defer_finish (&args->trans); -xfs_trans_bhold_release (args->trans, *leaf_bp); -if (error) { -xfs_trans_brelse (args->trans, *leaf_bp); -return error; - }Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_set_shortform( · line 261
Quoted 3 lines
fs/xfs/libxfs/xfs_attr.c +1
-2- -return 0 ; +return -EAGAIN ;What state are we in when return
-EAGAINhere? Are we still inXFS_DAS_UNINIT, but with an attr fork that is no longer in local format, which means that we skip thexfs_attr_is_shortformbranch next time around?
Quoted 7 lines
Yes, that's correct. I think I used to have an explicit state for it, but it's really not needed for this reason. Though I think they do add some degree of readability. Maybe we could add a comment?
/* Restart attr operation in leaf format */
?
Or even mention the DAS state explicitly, e.g.
/*
* 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. */
Hmm, second question: Could you add some tracepoints that would fire every time we either change the DAS state or return -EAGAIN to trigger a roll? I bet that will make debugging the attr code easier in the future.
Quoted 180 lines
Quoted 59 lines
Quoted 59 lines
fs/xfs/libxfs/xfs_attr.c +40
-4}/* @@ -268,7 +266,7 @@ xfs_attr_set_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) {@@ -297,61 +295,130 @@ intxfs_attr_set_args ( struct xfs_da_args *args) { -struct xfs_inode *dp = args->dp; -struct xfs_buf *leaf_bp =NULL ; -int error =0 ; +struct xfs_buf *leaf_bp =NULL ; +int error =0 ; +struct xfs_delattr_context dac = { + .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; + +if (leaf_bp) { +xfs_trans_bjoin (args->trans, leaf_bp); +xfs_trans_bhold (args->trans, leaf_bp); + } + + }while (true); + +return error; +} + +/* +* Set the attribute specified in @args. +* This routine is meant to function as a delayed operation, and may return +* -EAGAIN when the transaction needs to be rolled. Calling functions will need +* to handle this, and recall the function until a successful error code is +* returned. +*/ +STATIC int +xfs_attr_set_iter ( +struct xfs_delattr_context *dac, +struct xfs_buf **leaf_bp) +{ +struct xfs_da_args *args = dac->da_args; +struct xfs_inode *dp = args->dp;Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c int · line 342
Quoted 6 lines
fs/xfs/libxfs/xfs_attr.c +6
-0+int error =0 ; + +/* State machine switch */ +switch (dac->dela_state) { +case XFS_DAS_FLIP_LFLAG : +case XFS_DAS_FOUND_LBLK :Do we need to catch
XFS_DAS_RM_LBLKhere?I think we fall into the correct code path without it, but I think it's better to have it here for consistency. Will add.
Quoted 38 lines
Quoted 38 lines
fs/xfs/libxfs/xfs_attr.c +18
-10+ goto das_leaf; +case XFS_DAS_FOUND_NBLK : +case XFS_DAS_FLIP_NFLAG : +case XFS_DAS_ALLOC_NODE : + goto das_node; +default : +break ; + }/* * If the attribute list is already in leaf format, jump straight to * leaf handling. Otherwise, try to add the attribute to the shortform * list; if there's no room then convert the list to leaf format and try -* again. +* again. No need to set state as we will be in leaf form when we come +* back */ if (xfs_attr_is_shortform (dp)) {/* -* If the attr was successfully set in shortform, the -* transaction is committed and set to NULL. Otherwise, is it -* converted from shortform to leaf, and the transaction is -* retained. +* If the attr was successfully set in shortform, no need to +* continue. Otherwise, is it converted from shortform to leaf +* and -EAGAIN is returned. */ - error =xfs_attr_set_shortform (args, &leaf_bp); -if (error || !args->trans) -return error; + error =xfs_attr_set_shortform (args, leaf_bp); +if (error == -EAGAIN ) + dac->flags |=XFS_DAC_DEFER_FINISH ; + +return error; } -if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) { - error =xfs_attr_leaf_addname (args);Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c int · line 376
Quoted 6 lines
fs/xfs/libxfs/xfs_attr.c +4
-2-if (error != -ENOSPC ) -return error; +/* +* After a shortform to leaf conversion, we need to hold the leaf and +* cycle out the transaction. When we get back, we need to release +* the leaf. "...to release the hold on the leaf buffer."
Sure, will expand
Quoted 34 lines
Quoted 34 lines
fs/xfs/libxfs/xfs_attr.c +19
-14+*/ +if (*leaf_bp !=NULL ) { +xfs_trans_bhold_release (args->trans, *leaf_bp); + *leaf_bp =NULL ; + } -/* -* Promote the attribute list to the Btree format. -*/ - error =xfs_attr3_leaf_to_node (args); -if (error) -return error; +if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) { + error =xfs_attr_leaf_try_add (args, *leaf_bp); +switch (error) { +case -ENOSPC : +/* +* Promote the attribute list to the Btree format. +*/ + error =xfs_attr3_leaf_to_node (args); +if (error) +return error; -/* -* 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) +/* +* 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 Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c int · line 402
Quoted 5 lines
fs/xfs/libxfs/xfs_attr.c +5
-0+* same state (inode locked and joined, transaction +* clean) no matter how we got to this step. +*/ + dac->flags |=XFS_DAC_DEFER_FINISH ; +return -EAGAIN ;What state should we be in at this
-EAGAINreturn? Is itXFS_DAS_UNINIT, but with more than one extent in the attr fork?It could be UNINIT, if the attr was already a leaf at the time we started. If we had to promote from a block to a leaf, and STILL counldnt fit in leaf form, then we're probably in some state reminiscent of the leaf routines. But because
xfs_attr3_leaf_to_nodejust turned us into a node, we fall into the node path upon return.I know that's confusing... which leads to your next question of.....
Quoted 4 lines
/me is wishing these would get turned into explicit states, since afaict we don't unlock the inode and so we should find it in /exactly/ the state that the
delattr_contextsays it should be in.IIRC it used to have an explicit
XFS_DC_LEAF_TO_NODEstate, but I think we simplified it away at some point in the reviewing in an effort to simplify the statemachine as much as possible. v8 I think. But yes, I do think there is a trade off between removing the states where they can be, but then reducing the readability of where we are in the attr process. Because now your state isnt exactly represented bydela_stateanymore, it's the combination ofdela_stateand the state of the tree.
Quoted 3 lines
I think I've been over this code so much by now, I can follow it either way, but if it's confusing to others, maybe we should put it back? Or maybe just a comment if that helps?
A comment laying out which states we could be in and how we got there. :)
Quoted 14 lines
Quoted 14 lines
fs/xfs/libxfs/xfs_attr.c int · line 409
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +6
-0+case 0 : + dac->dela_state =XFS_DAS_FOUND_LBLK ; +return -EAGAIN ; +default :return error; + } +das_leaf:The only way to get to this block of code is by jumping to
das_leaf, from the switch statement above, right? If so, then shouldn't it be up there in the switch statement?
Quoted 3 lines
We could, though I think we were just trying to be consistent in that the switch is sort of a dispatcher for gotos? Otherwise we end up with a switch with giant cases. It's the same difference I suppose.
With this comment in particular, I had to dig through the switch statement in the previous code block to figure out that it's not possible to fall into das_leaf from above.
Quoted 10 lines
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c int · line 416
Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c +7
-0+ error =xfs_attr_leaf_addname (dac); +if (error == -ENOSPC ) +/* +* No need to set state. We will be in node form when +* we are recalled +*/ +return -EAGAIN ;How do we get to node form?
Quoted 6 lines
Hmm, I thought
xfs_attr_leaf_addnamedid promote to node if theres not enough space, but now that you point it out, i'm not seeing it. We may have to put theLEAF_TO_NODEstate back anyway.maybe i can add a test case too, it doesnt look like any of the existing cases run across it.
Hm. At least in the old code, I thought it was xfs_attr_set_args that would call xfs_attr_leaf_addname and if it returned ENOSPC, it would then call xfs_attr3_leaf_to_node...
(Gosh, I can't even tell where we are anymore. :()
Quoted 51 lines
Quoted 51 lines
Quoted 5 lines
fs/xfs/libxfs/xfs_attr.c +0
-4-/* -* Commit the current trans (including the inode) and -* start a new one. -*/ fs/xfs/libxfs/xfs_attr.c int · line 422
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +3
-5- error =xfs_trans_roll_inode (&args->trans, dp); -if (error) -return error; +return error; } - - error =xfs_attr_node_addname (args); +das_node: + error =xfs_attr_node_addname (dac);return error;Similarly, I think the only way get to this block of code is if we're in the initial state (
XFS_DAS_UNINIT?) and the inode wasn't in short format; or if we jumped here via DAS_{FOUND_NBLK,FLIP_NFLAG,ALLOC_NODE}, right?I think you could straighten this out a bit further (I left out the comments):
switch (dac->dela_state) { case XFS_DAS_FLIP_LFLAG: case XFS_DAS_FOUND_LBLK: error = xfs_attr_leaf_addname(dac); if (error == -ENOSPC) return -EAGAIN; return error; case XFS_DAS_FOUND_NBLK: case XFS_DAS_FLIP_NFLAG: case XFS_DAS_ALLOC_NODE: return xfs_attr_node_addname(dac); case XFS_DAS_UNINIT: break; default: ...assert on the XFS_DAS_RM_* flags... } if (xfs_attr_is_shortform(dp)) return xfs_attr_set_shortform(args, leaf_bp); if (*leaf_bp != NULL) { ...release bhold... } if (!xfs_bmap_one_block(...)) return xfs_attr_node_addname(dac);
Quoted 8 lines
Quoted 6 lines
error = xfs_attr_leaf_try_add(args, *leaf_bp); switch (error) { ...handle -ENOSPC and 0... } return error;Ok, I'll see if I can get something like that through the test cases. If if doesnt work out, I'll make a note of it.
<nod>
Quoted 78 lines
Quoted 69 lines
Quoted 69 lines
fs/xfs/libxfs/xfs_attr.c +35
-19}@@ -723,28 +790,30 @@ xfs_attr_leaf_try_add(* * This leaf block cannot have a "remote" value, we only call this routine * if bmap_one_block() says there is only one block (ie: no remote blks). +* +* This routine is meant to function as a delayed operation, and may return +* -EAGAIN when the transaction needs to be rolled. Calling functions will need +* to handle this, and recall the function until a successful error code is +* returned. */ STATIC intxfs_attr_leaf_addname ( -struct xfs_da_args *args) +struct xfs_delattr_context *dac) { -int error, forkoff; -struct xfs_buf *bp =NULL ; -struct xfs_inode *dp = args->dp; - -trace_xfs_attr_leaf_addname (args); - - error =xfs_attr_leaf_try_add (args, bp); -if (error) -return error; +struct xfs_da_args *args = dac->da_args; +struct xfs_buf *bp =NULL ; +int error, forkoff; +struct xfs_inode *dp = args->dp; -/* -* Commit the transaction that added the attr name so that -* later routines can manage their own transactions. -*/ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) -return error; +/* State machine switch */ +switch (dac->dela_state) { +case XFS_DAS_FLIP_LFLAG : + goto das_flip_flag; +case XFS_DAS_RM_LBLK : + goto das_rm_lblk; +default : +break ; + }/* * If there was an out-of-line value, allocate the blocks we @@ -752,12 +821,34 @@ xfs_attr_leaf_addname(* after we create the attribute so that we don't overflow the * maximum size of a transaction and/or hit a deadlock. */ -if (args->rmtblkno >0 ) { - error =xfs_attr_rmtval_set (args); + +/* Open coded xfs_attr_rmtval_set without trans handling */ +if ((dac->flags &XFS_DAC_LEAF_ADDNAME_INIT ) ==0 ) { + dac->flags |=XFS_DAC_LEAF_ADDNAME_INIT ; +if (args->rmtblkno >0 ) { + error =xfs_attr_rmtval_find_space (dac); +if (error) +return error; + } + } + +/* +* Roll through the "value", allocating blocks on disk as +* required. +*/ +if (dac->blkcnt >0 ) {Quoted 9 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_leaf_addname( · line 845
Quoted 6 lines
fs/xfs/libxfs/xfs_attr.c +4
-0+ error =xfs_attr_rmtval_set_blk (dac);if (error)return error; + + dac->flags |=XFS_DAC_DEFER_FINISH ; +return -EAGAIN ;What state are we in here?
FOUND_LBLK, with blkcnt slowly decreasing?
Quoted 3 lines
I used to have an
ALLOC_LEAFstate for this one. Used to look something like this:
+alloc_leaf:
Aha, that's where ALLOC_LEAF went.
Quoted 18 lines
fs/xfs/libxfs/xfs_attr.c +9
-0+while (args->dac.blkcnt >0 ) { + error =xfs_attr_rmtval_set_blk (args); +if (error) +return error; + + args->dac.flags |=XFS_DAC_FINISH_TRANS ; + args->dac.dela_state =XFS_DAS_ALLOC_LEAF ; +return -EAGAIN ; + }Again, it's not really needed, as we will fall into this logic with or with out the state. And the while loop doesnt really loop, though I guess it does sort of help the reader to understand that this is supposed to function like a loop. I think it's easy to see something like that, and then want to simplify away the extra semantics, but then on a second look, it's not quite as obvious why with out the recollection of what it once was. Maybe a comment is in order?
Quoted 3 lines
/* Repeat this until we have set all rmt blks */
?
Well there already is a comment that we're repeating until we've set all the remote blocks, but it should capture which DAS state(s) we could be in, because I quickly get lost, especially in the attr set code.
Quoted 11 lines
To directly answer your question though, I think the state is still UNINIT at this point, since any of the other states would have branched off before this. It's important to note though that the functions that have states are meant to sort of take ownership the statemachine. IOW, if the state coming in does not apply to the scope of this function, or any of the subroutines there in, then the state is simply overwritten as this function decides appropriate. It doesnt throw an error if it is passed a state that used to belong to it's parent. Calling functions should understand that they have sort of "surrendered" the statemachine to this subfunction until it returns something other than EAGAIN.
That will become very obvious once we've arrived at the end of the series and everyone must use defer ops. :)
Quoted 5 lines
At least that's the idea. Honnestly, the only
reason I have UNINIT at all is because we get warnings about setting the state to 0 when the enum needs to start at something other than 0.Hope that helps?
Yeah.
Quoted 120 lines
Quoted 112 lines
Quoted 112 lines
fs/xfs/libxfs/xfs_attr.c +41
-27} + 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. @@ -777,29 +868,29 @@ xfs_attr_leaf_addname(* In a separate transaction, set the incomplete flag on the "old" attr * and clear the incomplete flag on the "new" attr. */ - error =xfs_attr3_leaf_flipflags (args);if (error)return error;/* * Commit the flag value change and start the next trans in series. */ - error =xfs_trans_roll_inode (&args->trans, args->dp); -if (error) -return error; - + dac->dela_state =XFS_DAS_FLIP_LFLAG ; +return -EAGAIN ; +das_flip_flag:/* * Dismantle the "old" attribute/value pair by removing a "remote" value * (if it exists). */ xfs_attr_restore_rmt_blk (args); + error =xfs_attr_rmtval_invalidate (args); +if (error) +return error; +das_rm_lblk:if (args->rmtblkno) { - error =xfs_attr_rmtval_invalidate (args); -if (error) -return error; - - error =xfs_attr_rmtval_remove (args); + error =__xfs_attr_rmtval_remove (dac); +if (error == -EAGAIN ) + dac->dela_state =XFS_DAS_RM_LBLK ;if (error)return error; }@@ -965,23 +1056,38 @@ xfs_attr_node_hasname(* * "Remote" attribute values confuse the issue and atomic rename operations * add a whole extra layer of confusion on top of that. +* +* This routine is meant to function as a delayed operation, and may return +* -EAGAIN when the transaction needs to be rolled. Calling functions will need +* to handle this, and recall the function until a successful error code is +*returned. */ STATIC intxfs_attr_node_addname ( -struct xfs_da_args *args) +struct xfs_delattr_context *dac) { -struct xfs_da_state *state; -struct xfs_da_state_blk *blk; -struct xfs_inode *dp; -int retval, error; +struct xfs_da_args *args = dac->da_args; +struct xfs_da_state *state =NULL ; +struct xfs_da_state_blk *blk; +int retval =0 ; +int error =0 ;trace_xfs_attr_node_addname (args); -/* -* Fill in bucket of arguments/results/context to carry around. -*/ - dp = args->dp; -restart: +/* State machine switch */ +switch (dac->dela_state) { +case XFS_DAS_FLIP_NFLAG : + goto das_flip_flag; +case XFS_DAS_FOUND_NBLK : + goto das_found_nblk; +case XFS_DAS_ALLOC_NODE : + goto das_alloc_node; +case XFS_DAS_RM_NBLK : + goto das_rm_nblk; +default : +break ; + } +/* * Search to see if name already exists, and get back a pointer * to where it should go. @@ -1027,19 +1133,13 @@ xfs_attr_node_addname( error =xfs_attr3_leaf_to_node (args);if (error) goto out; - error =xfs_defer_finish (&args->trans); -if (error) - goto out;/* -* Commit the node conversion and start the next -* trans in the chain. +* Restart routine from the top. No need to set the +* state */ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error)Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_addname( · line 1142
Quoted 5 lines
fs/xfs/libxfs/xfs_attr.c +2
-3- goto out; - - goto restart; + dac->flags |=XFS_DAC_DEFER_FINISH ; +return -EAGAIN ;What state are we in here? Are we still in the same state that we were at the start of the function, but ready to try
xfs_attr3_leaf_addagain?
Quoted 6 lines
To directly answer the question: we may be in UNINIT if we were already a node when we started the attr op. If we had to promote from leaf to node, it may be some state left over from the leaf routines.
Again though, in so far as this routine is concerned, the idea is that the state either one of the cases in the switch up top, or it's not.
<nod> Comment please. :)
Quoted 130 lines
Quoted 102 lines
Quoted 102 lines
fs/xfs/libxfs/xfs_attr.c +39
-19}/* @@ -1051,9 +1151,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. @@ -1068,13 +1166,9 @@ xfs_attr_node_addname(xfs_da_state_free (state); state =NULL ; -/* -* Commit the leaf addition or btree split and start the next -* trans in the chain. -*/ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) - goto out; + dac->dela_state =XFS_DAS_FOUND_NBLK ; +return -EAGAIN ; +das_found_nblk:/* * If there was an out-of-line value, allocate the blocks we @@ -1083,7 +1177,27 @@ xfs_attr_node_addname(* maximum size of a transaction and/or hit a deadlock. */ if (args->rmtblkno >0 ) { - error =xfs_attr_rmtval_set (args); +/* Open coded xfs_attr_rmtval_set without trans handling */ + error =xfs_attr_rmtval_find_space (dac); +if (error) +return error; + +/* +* Roll through the "value", allocating blocks on disk as +* required. +*/ +das_alloc_node: +if (dac->blkcnt >0 ) { + error =xfs_attr_rmtval_set_blk (dac); +if (error) +return error; + + dac->flags |=XFS_DAC_DEFER_FINISH ; + dac->dela_state =XFS_DAS_ALLOC_NODE ; +return -EAGAIN ; + } + + error =xfs_attr_rmtval_set_value (args);if (error)return error; }@@ -1113,22 +1227,28 @@ xfs_attr_node_addname(/* * Commit the flag value change and start the next trans in series */ - error =xfs_trans_roll_inode (&args->trans, args->dp); -if (error) - goto out; - + dac->dela_state =XFS_DAS_FLIP_NFLAG ; +return -EAGAIN ; +das_flip_flag:/* * Dismantle the "old" attribute/value pair by removing a "remote" value * (if it exists). */ xfs_attr_restore_rmt_blk (args); + error =xfs_attr_rmtval_invalidate (args); +if (error) +return error; + +das_rm_nblk:if (args->rmtblkno) { - error =xfs_attr_rmtval_invalidate (args); -if (error) -return error; + error =__xfs_attr_rmtval_remove (dac); + +if (error == -EAGAIN ) { + dac->dela_state =XFS_DAS_RM_NBLK ; +return -EAGAIN ; + } - error =xfs_attr_rmtval_remove (args);if (error)return error; }fs/xfs/libxfs/xfs_attr.h +1
-0@@ -106,6 +106,118 @@ struct xfs_attr_list_context {* v │ * done <─────┘ * +* Quoted 8 lines
fs/xfs/libxfs/xfs_attr.h struct xfs_attr_list_context { · line 114
Quoted 5 lines
fs/xfs/libxfs/xfs_attr.h +5
-0+* Below is a state machine diagram for attr set operations. +* +* xfs_attr_set_iter() +* │ +* v I think this diagram is missing the part where we attempt to add a shortform attr?
I left if out because the short form doesnt make use of states. I can doodle that in though if you prefer:
┌───n── is shortform? │ | │ y │ | │ V │ xfs_attr_set_shortform │ | │ V ├───n─── had enough │ space? │ │ │ y │ │ │ V │ done └────────────┐ │
Quoted 1 line
V
Yes, please do capture the entire mechanism so that 2025 us aren't sitting here muttering about why we didn't do that when everything was still warm in our L1 brain cache. ;)
--D
Quoted 309 lines
Quoted 3 lines
--D
Thx for the thorough reviews!
Allison
Quoted 301 lines
Quoted 301 lines
fs/xfs/libxfs/xfs_attr.h +119
-1+* ┌───n── fork has +* │ only 1 blk? +* │ │ +* │ y +* │ │ +* │ v +* │ xfs_attr_leaf_try_add() +* │ │ +* │ v +* │ had enough +* ├───n────space? +* │ │ +* │ y +* │ │ +* │ v +* │ XFS_DAS_FOUND_LBLK ──┐ +* │ │ +* │ XFS_DAS_FLIP_LFLAG ──┤ +* │ (subroutine state) │ +* │ │ +* │ └─>xfs_attr_leaf_addname() +* │ │ +* │ v +* │ was this +* │ a rename? ──n─┐ +* │ │ │ +* │ y │ +* │ │ │ +* │ v │ +* │ flip incomplete │ +* │ flag │ +* │ │ │ +* │ v │ +* │ XFS_DAS_FLIP_LFLAG │ +* │ │ │ +* │ v │ +* │ remove │ +* │ XFS_DAS_RM_LBLK ─> old name │ +* │ ^ │ │ +* │ │ v │ +* │ └──────y── more to │ +* │ remove │ +* │ │ │ +* │ n │ +* │ │ │ +* │ v │ +* │ done <──────┘ +* └──> XFS_DAS_FOUND_NBLK ──┐ +* (subroutine state) │ +* │ +* XFS_DAS_ALLOC_NODE ──┤ +* (subroutine state) │ +* │ +* XFS_DAS_FLIP_NFLAG ──┤ +* (subroutine state) │ +* │ +* └─>xfs_attr_node_addname() +* │ +* v +* find space to store +* attr. Split if needed +* │ +* v +* XFS_DAS_FOUND_NBLK +* │ +* v +* ┌─────n── need to +* │ alloc blks? +* │ │ +* │ y +* │ │ +* │ v +* │ ┌─>XFS_DAS_ALLOC_NODE +* │ │ │ +* │ │ v +* │ └──y── need to alloc +* │ more blocks? +* │ │ +* │ n +* │ │ +* │ v +* │ was this +* └────────> a rename? ──n─┐ +* │ │ +* y │ +* │ │ +* v │ +* flip incomplete │ +* flag │ +* │ │ +* v │ +* XFS_DAS_FLIP_NFLAG │ +* │ │ +* v │ +* remove │ +* XFS_DAS_RM_NBLK ─> old name │ +* ^ │ │ +* │ v │ +* └──────y── more to │ +* remove │ +* │ │ +* n │ +* │ │ +* v │ +* done <──────┘ +* */ /* @@ -120,6 +232,13 @@ struct xfs_attr_list_context {enum xfs_delattr_state {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 */ };/* @@ -127,6 +246,7 @@ enum xfs_delattr_state {*/ #define XFS_DAC_DEFER_FINISH 0x01/* finish the transaction */ #define XFS_DAC_NODE_RMVNAME_INIT 0x02/* xfs_attr_node_removename init */ +#define XFS_DAC_LEAF_ADDNAME_INIT 0x04/* xfs_attr_leaf_addname init*/ /* * Context used for keeping track of delayed attribute operations @@ -134,6 +254,11 @@ enum xfs_delattr_state {struct xfs_delattr_context {struct xfs_da_args *da_args; +/* Used in xfs_attr_rmtval_set_blk to roll through allocating blocks */ +struct xfs_bmbt_irec map; +xfs_dablk_t lblkno; +int blkcnt; +/* Used in xfs_attr_node_removename to roll through removing blocks */ struct xfs_da_state *da_state;@@ -160,7 +285,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
-34@@ -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,38 +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
-0@@ -15,4 +15,8 @@ int xfs_attr_rmtval_stale(struct xfs_inode *ip, struct xfs_bmbt_irec *map, xfs_buf_flags_t incore_flags);int xfs_attr_rmtval_invalidate (struct xfs_da_args *args);int __xfs_attr_rmtval_remove (struct xfs_delattr_context *dac); +int xfs_attr_rmt_find_hole (struct xfs_da_args *args); +int xfs_attr_rmtval_set_value (struct xfs_da_args *args); +int xfs_attr_rmtval_set_blk (struct xfs_delattr_context *dac); +int xfs_attr_rmtval_find_space (struct xfs_delattr_context *dac);#endif /* __XFS_ATTR_REMOTE_H__ */ fs/xfs/xfs_trace.h +0
-1@@ -1925,7 +1925,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 v13 03/10] xfs: Add delay ready attr set routines
Quoted 140 lines · Darrick J. Wong
Quoted 129 lines · Allison Henderson
Quoted 83 lines · Darrick J. Wong
Quoted 69 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_set_initandxfs_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.Signed-off-by Allison Henderson <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 370 ++++++++++++++++++++++++++-------------- fs/xfs/libxfs/xfs_attr.h | 126 +++++++++++++- fs/xfs/libxfs/xfs_attr_remote.c | 99 +++++++---- fs/xfs/libxfs/xfs_attr_remote.h | 4 + fs/xfs/xfs_trace.h | 1 - 5 files changed, 439 insertions(+), 161 deletions(-)fs/xfs/libxfs/xfs_attr.c +10
-4@@ -44,7 +44,7 @@ STATIC int xfs_attr_shortform_addname(xfs_da_args_t *args);* Internal routines when attribute list is one block. */ STATIC int xfs_attr_leaf_get(xfs_da_args_t *args); -STATIC int xfs_attr_leaf_addname(xfs_da_args_t *args); +STATIC int xfs_attr_leaf_addname(struct xfs_delattr_context *dac); STATIC int xfs_attr_leaf_removename(xfs_da_args_t *args); STATIC int xfs_attr_leaf_hasname(struct xfs_da_args *args, struct xfs_buf **bp);@@ -52,12 +52,15 @@ STATIC int xfs_attr_leaf_hasname(struct xfs_da_args *args, struct xfs_buf **bp);* Internal routines when attribute list is more than one block. */ STATIC int xfs_attr_node_get(xfs_da_args_t *args); -STATIC int xfs_attr_node_addname(xfs_da_args_t *args); +STATIC int xfs_attr_node_addname(struct xfs_delattr_context *dac); STATIC int xfs_attr_node_removename_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_leaf_try_add(struct xfs_da_args *args, struct xfs_buf *bp); +STATIC int xfs_attr_set_iter(struct xfs_delattr_context *dac, +struct xfs_buf **leaf_bp);int xfs_inode_hasattr(@@ -218,8 +221,11 @@ xfs_attr_is_shortform(/* * Attempts to set an attr in shortform, or converts short form to leaf form if -* there is not enough room. If the attr is set, the transaction is committed -* and set to NULL. +* there is not enough room. This function is meant to operate as a helper +* routine to the delayed attribute functions. It returns -EAGAIN to indicate +* that the calling function should roll the transaction, and then proceed to +* add the attr in leaf form. This subroutine does not expect to be recalled +* again like the other delayed attr routines do. */ STATIC int xfs_attr_set_shortform(@@ -227,16 +233,16 @@ xfs_attr_set_shortform( struct xfs_buf **leaf_bp)fs/xfs/libxfs/xfs_attr.c xfs_attr_set_shortform( · line 242
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +3
-1{struct xfs_inode *dp = args->dp; -int error, error2 =0 ; +int error =0 ;/* * Try to add the attr to the attribute list in the inode. */ error =xfs_attr_try_sf_addname (dp, args); + +/* Should only be 0, -EEXIST or ENOSPC */ Nit: "...or
-ENOSPC"Quoted 1 line
Also, this comment could go a couple of lines up:
Sure
Quoted 33 lines
/* * Try to add the attr to the attribute list in the inode. * This should only return 0, -EEXIST, or -ENOSPC. */ error = xfs_attr_try_sf_addname(dp, args); if (error != -ENOSPC) return error;Quoted 23 lines
fs/xfs/libxfs/xfs_attr.c +2
-11if (error != -ENOSPC ) { - error2 =xfs_trans_commit (args->trans); - args->trans =NULL ; -return error ? error : error2; +return error; }/* * It won't fit in the shortform, transform to a leaf block. GROT: @@ -249,18 +255,10 @@ xfs_attr_set_shortform(/* * Prevent the leaf buffer from being unlocked so that a concurrent AIL * push cannot grab the half-baked leaf buffer and run into problems -* with the write verifier. Once we're done rolling the transaction we -* can release the hold and add the attr to the leaf. +* with the write verifier. */ xfs_trans_bhold (args->trans, *leaf_bp); - error =xfs_defer_finish (&args->trans); -xfs_trans_bhold_release (args->trans, *leaf_bp); -if (error) { -xfs_trans_brelse (args->trans, *leaf_bp); -return error; - }Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_set_shortform( · line 261
Quoted 3 lines
fs/xfs/libxfs/xfs_attr.c +1
-2- -return 0 ; +return -EAGAIN ;What state are we in when return
-EAGAINhere? Are we still inXFS_DAS_UNINIT, but with an attr fork that is no longer in local format, which means that we skip thexfs_attr_is_shortformbranch next time around?Quoted 7 lines
Yes, that's correct. I think I used to have an explicit state for it, but it's really not needed for this reason. Though I think they do add some degree of readability. Maybe we could add a comment?
/* Restart attr operation in leaf format */
?
Or even mention the DAS state explicitly, e.g.
Quoted 8 lines
/*
* We're still inXFS_DAS_UNINITstate here. We've converted the attr
* fork to leaf format and will restart with the leaf add. */Hmm, second question: Could you add some tracepoints that would fire every time we either change the DAS state or return
-EAGAINto trigger a roll? I bet that will make debugging the attr code easier in the future.
Sure, I will look into adding some tracing here.
Quoted 181 lines
Quoted 181 lines
Quoted 60 lines
Quoted 60 lines
fs/xfs/libxfs/xfs_attr.c +40
-4}/* @@ -268,7 +266,7 @@ xfs_attr_set_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) {@@ -297,61 +295,130 @@ intxfs_attr_set_args ( struct xfs_da_args *args) { -struct xfs_inode *dp = args->dp; -struct xfs_buf *leaf_bp =NULL ; -int error =0 ; +struct xfs_buf *leaf_bp =NULL ; +int error =0 ; +struct xfs_delattr_context dac = { + .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; + +if (leaf_bp) { +xfs_trans_bjoin (args->trans, leaf_bp); +xfs_trans_bhold (args->trans, leaf_bp); + } + + }while (true); + +return error; +} + +/* +* Set the attribute specified in @args. +* This routine is meant to function as a delayed operation, and may return +* -EAGAIN when the transaction needs to be rolled. Calling functions will need +* to handle this, and recall the function until a successful error code is +* returned. +*/ +STATIC int +xfs_attr_set_iter ( +struct xfs_delattr_context *dac, +struct xfs_buf **leaf_bp) +{ +struct xfs_da_args *args = dac->da_args; +struct xfs_inode *dp = args->dp;Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c int · line 342
Quoted 6 lines
fs/xfs/libxfs/xfs_attr.c +6
-0+int error =0 ; + +/* State machine switch */ +switch (dac->dela_state) { +case XFS_DAS_FLIP_LFLAG : +case XFS_DAS_FOUND_LBLK :Do we need to catch
XFS_DAS_RM_LBLKhere?I think we fall into the correct code path without it, but I think it's better to have it here for consistency. Will add.
Quoted 38 lines
Quoted 38 lines
fs/xfs/libxfs/xfs_attr.c +18
-10+ goto das_leaf; +case XFS_DAS_FOUND_NBLK : +case XFS_DAS_FLIP_NFLAG : +case XFS_DAS_ALLOC_NODE : + goto das_node; +default : +break ; + }/* * If the attribute list is already in leaf format, jump straight to * leaf handling. Otherwise, try to add the attribute to the shortform * list; if there's no room then convert the list to leaf format and try -* again. +* again. No need to set state as we will be in leaf form when we come +* back */ if (xfs_attr_is_shortform (dp)) {/* -* If the attr was successfully set in shortform, the -* transaction is committed and set to NULL. Otherwise, is it -* converted from shortform to leaf, and the transaction is -* retained. +* If the attr was successfully set in shortform, no need to +* continue. Otherwise, is it converted from shortform to leaf +* and -EAGAIN is returned. */ - error =xfs_attr_set_shortform (args, &leaf_bp); -if (error || !args->trans) -return error; + error =xfs_attr_set_shortform (args, leaf_bp); +if (error == -EAGAIN ) + dac->flags |=XFS_DAC_DEFER_FINISH ; + +return error; } -if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) { - error =xfs_attr_leaf_addname (args);Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c int · line 376
Quoted 6 lines
fs/xfs/libxfs/xfs_attr.c +4
-2-if (error != -ENOSPC ) -return error; +/* +* After a shortform to leaf conversion, we need to hold the leaf and +* cycle out the transaction. When we get back, we need to release +* the leaf. "...to release the hold on the leaf buffer."
Sure, will expand
Quoted 34 lines
Quoted 34 lines
fs/xfs/libxfs/xfs_attr.c +19
-14+*/ +if (*leaf_bp !=NULL ) { +xfs_trans_bhold_release (args->trans, *leaf_bp); + *leaf_bp =NULL ; + } -/* -* Promote the attribute list to the Btree format. -*/ - error =xfs_attr3_leaf_to_node (args); -if (error) -return error; +if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) { + error =xfs_attr_leaf_try_add (args, *leaf_bp); +switch (error) { +case -ENOSPC : +/* +* Promote the attribute list to the Btree format. +*/ + error =xfs_attr3_leaf_to_node (args); +if (error) +return error; -/* -* 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) +/* +* 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 Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c int · line 402
Quoted 5 lines
fs/xfs/libxfs/xfs_attr.c +5
-0+* same state (inode locked and joined, transaction +* clean) no matter how we got to this step. +*/ + dac->flags |=XFS_DAC_DEFER_FINISH ; +return -EAGAIN ;What state should we be in at this
-EAGAINreturn? Is itXFS_DAS_UNINIT, but with more than one extent in the attr fork?It could be UNINIT, if the attr was already a leaf at the time we started. If we had to promote from a block to a leaf, and STILL counldnt fit in leaf form, then we're probably in some state reminiscent of the leaf routines. But because
xfs_attr3_leaf_to_nodejust turned us into a node, we fall into the node path upon return.I know that's confusing... which leads to your next question of.....
Quoted 4 lines
/me is wishing these would get turned into explicit states, since afaict we don't unlock the inode and so we should find it in /exactly/ the state that the
delattr_contextsays it should be in.IIRC it used to have an explicit
XFS_DC_LEAF_TO_NODEstate, but I think we simplified it away at some point in the reviewing in an effort to simplify the statemachine as much as possible. v8 I think. But yes, I do think there is a trade off between removing the states where they can be, but then reducing the readability of where we are in the attr process. Because now your state isnt exactly represented bydela_stateanymore, it's the combination ofdela_stateand the state of the tree.
Quoted 5 lines
Quoted 3 lines
I think I've been over this code so much by now, I can follow it either way, but if it's confusing to others, maybe we should put it back? Or maybe just a comment if that helps?
A comment laying out which states we could be in and how we got there. :)
Sure, will add in comments and traceing too. I'm thinking the comment from below should probably come up here. Jump my next comment below...
Quoted 37 lines
Quoted 15 lines
Quoted 4 lines
Quoted 11 lines
fs/xfs/libxfs/xfs_attr.c int · line 409
Quoted 7 lines
fs/xfs/libxfs/xfs_attr.c +6
-0+case 0 : + dac->dela_state =XFS_DAS_FOUND_LBLK ; +return -EAGAIN ; +default :return error; + } +das_leaf:The only way to get to this block of code is by jumping to
das_leaf, from the switch statement above, right? If so, then shouldn't it be up there in the switch statement?Quoted 3 lines
We could, though I think we were just trying to be consistent in that the switch is sort of a dispatcher for gotos? Otherwise we end up with a switch with giant cases. It's the same difference I suppose.
With this comment in particular, I had to dig through the switch statement in the previous code block to figure out that it's not possible to fall into
das_leaffrom above.Quoted 14 lines
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c int · line 416
Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c +7
-0+ error =xfs_attr_leaf_addname (dac); +if (error == -ENOSPC ) +/* +* No need to set state. We will be in node form when +* we are recalled +*/ +return -EAGAIN ;How do we get to node form?
Hmm, I thought
xfs_attr_leaf_addnamedid promote to node if theres not enough space, but now that you point it out, i'm not seeing it. We may have to put theLEAF_TO_NODEstate back anyway.
Quoted 8 lines
Quoted 2 lines
maybe i can add a test case too, it doesnt look like any of the existing cases run across it.
Hm. At least in the old code, I thought it was
xfs_attr_set_argsthat would callxfs_attr_leaf_addnameand if it returned ENOSPC, it would then callxfs_attr3_leaf_to_node...(Gosh, I can't even tell where we are anymore. :()
Ok, sorry, so what happens is:
We pull xfs_attr_leaf_try_add out of xfs_attr_leaf_addname, and the ENOSPC handler with it. But I think that's the only place in xfs_attr_leaf_addname where ENOSPC used to come from. So I think this old ENOSPC handler here can go away, I dont see that theres any other way an ENOSPC comes back, or if it does its not expected. That's likely why this ENOSPC handler isnt getting triggered in the test cases. The ENOSPC condition is already getting handled in the case above.
So I think this line can just turn into
"return xfs_attr_leaf_addname(dac);"
Sorry for the condufsion!! :-(
Going back to your request for comments above, how about we expand the existing coment up there and add:
/*
* We do not need to set a state here, because when we come back, we
* will be in node form. dela_state is still XFS_DAS_UNINIT at this time */
Quoted 165 lines
Quoted 52 lines
Quoted 52 lines
Quoted 6 lines
fs/xfs/libxfs/xfs_attr.c +0
-4-/* -* Commit the current trans (including the inode) and -* start a new one. -*/ fs/xfs/libxfs/xfs_attr.c int · line 422
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +3
-5- error =xfs_trans_roll_inode (&args->trans, dp); -if (error) -return error; +return error; } - - error =xfs_attr_node_addname (args); +das_node: + error =xfs_attr_node_addname (dac);return error;Similarly, I think the only way get to this block of code is if we're in the initial state (
XFS_DAS_UNINIT?) and the inode wasn't in short format; or if we jumped here via DAS_{FOUND_NBLK,FLIP_NFLAG,ALLOC_NODE}, right?I think you could straighten this out a bit further (I left out the comments):
switch (dac->dela_state) { case XFS_DAS_FLIP_LFLAG: case XFS_DAS_FOUND_LBLK: error = xfs_attr_leaf_addname(dac); if (error == -ENOSPC) return -EAGAIN; return error; case XFS_DAS_FOUND_NBLK: case XFS_DAS_FLIP_NFLAG: case XFS_DAS_ALLOC_NODE: return xfs_attr_node_addname(dac); case XFS_DAS_UNINIT: break; default: ...assert on the XFS_DAS_RM_* flags... } if (xfs_attr_is_shortform(dp)) return xfs_attr_set_shortform(args, leaf_bp); if (*leaf_bp != NULL) { ...release bhold... } if (!xfs_bmap_one_block(...)) return xfs_attr_node_addname(dac);Quoted 8 lines
Quoted 6 lines
error = xfs_attr_leaf_try_add(args, *leaf_bp); switch (error) { ...handle -ENOSPC and 0... } return error;Ok, I'll see if I can get something like that through the test cases. If if doesnt work out, I'll make a note of it.
<nod>
Quoted 78 lines
Quoted 69 lines
Quoted 69 lines
fs/xfs/libxfs/xfs_attr.c +35
-19}@@ -723,28 +790,30 @@ xfs_attr_leaf_try_add(* * This leaf block cannot have a "remote" value, we only call this routine * if bmap_one_block() says there is only one block (ie: no remote blks). +* +* This routine is meant to function as a delayed operation, and may return +* -EAGAIN when the transaction needs to be rolled. Calling functions will need +* to handle this, and recall the function until a successful error code is +* returned. */ STATIC intxfs_attr_leaf_addname ( -struct xfs_da_args *args) +struct xfs_delattr_context *dac) { -int error, forkoff; -struct xfs_buf *bp =NULL ; -struct xfs_inode *dp = args->dp; - -trace_xfs_attr_leaf_addname (args); - - error =xfs_attr_leaf_try_add (args, bp); -if (error) -return error; +struct xfs_da_args *args = dac->da_args; +struct xfs_buf *bp =NULL ; +int error, forkoff; +struct xfs_inode *dp = args->dp; -/* -* Commit the transaction that added the attr name so that -* later routines can manage their own transactions. -*/ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) -return error; +/* State machine switch */ +switch (dac->dela_state) { +case XFS_DAS_FLIP_LFLAG : + goto das_flip_flag; +case XFS_DAS_RM_LBLK : + goto das_rm_lblk; +default : +break ; + }/* * If there was an out-of-line value, allocate the blocks we @@ -752,12 +821,34 @@ xfs_attr_leaf_addname(* after we create the attribute so that we don't overflow the * maximum size of a transaction and/or hit a deadlock. */ -if (args->rmtblkno >0 ) { - error =xfs_attr_rmtval_set (args); + +/* Open coded xfs_attr_rmtval_set without trans handling */ +if ((dac->flags &XFS_DAC_LEAF_ADDNAME_INIT ) ==0 ) { + dac->flags |=XFS_DAC_LEAF_ADDNAME_INIT ; +if (args->rmtblkno >0 ) { + error =xfs_attr_rmtval_find_space (dac); +if (error) +return error; + } + } + +/* +* Roll through the "value", allocating blocks on disk as +* required. +*/ +if (dac->blkcnt >0 ) {Quoted 9 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_leaf_addname( · line 845
Quoted 6 lines
fs/xfs/libxfs/xfs_attr.c +4
-0+ error =xfs_attr_rmtval_set_blk (dac);if (error)return error; + + dac->flags |=XFS_DAC_DEFER_FINISH ; +return -EAGAIN ;What state are we in here?
FOUND_LBLK, with blkcnt slowly decreasing?Quoted 3 lines
I used to have an
ALLOC_LEAFstate for this one. Used to look something like this:
+alloc_leaf:Aha, that's where
ALLOC_LEAFwent.Quoted 18 lines
fs/xfs/libxfs/xfs_attr.c +9
-0+while (args->dac.blkcnt >0 ) { + error =xfs_attr_rmtval_set_blk (args); +if (error) +return error; + + args->dac.flags |=XFS_DAC_FINISH_TRANS ; + args->dac.dela_state =XFS_DAS_ALLOC_LEAF ; +return -EAGAIN ; + }Again, it's not really needed, as we will fall into this logic with or with out the state. And the while loop doesnt really loop, though I guess it does sort of help the reader to understand that this is supposed to function like a loop. I think it's easy to see something like that, and then want to simplify away the extra semantics, but then on a second look, it's not quite as obvious why with out the recollection of what it once was. Maybe a comment is in order?
Quoted 7 lines
Quoted 3 lines
/* Repeat this until we have set all rmt blks */
?
Well there already is a comment that we're repeating until we've set all the remote blocks, but it should capture which DAS state(s) we could be in, because I quickly get lost, especially in the attr set code.
OK, how about:
/*
* We dont set a state because we can use dac->blkcnt to know if we need
* to continue setting blocks. dac.dela_state is still XFS_DAS_UNINIT */
Quoted 144 lines
Quoted 12 lines
To directly answer your question though, I think the state is still UNINIT at this point, since any of the other states would have branched off before this. It's important to note though that the functions that have states are meant to sort of take ownership the statemachine. IOW, if the state coming in does not apply to the scope of this function, or any of the subroutines there in, then the state is simply overwritten as this function decides appropriate. It doesnt throw an error if it is passed a state that used to belong to it's parent. Calling functions should understand that they have sort of "surrendered" the statemachine to this subfunction until it returns something other than EAGAIN.
That will become very obvious once we've arrived at the end of the series and everyone must use defer ops. :)
Quoted 5 lines
At least that's the idea. Honnestly, the only
reason I have UNINIT at all is because we get warnings about setting the state to 0 when the enum needs to start at something other than 0.Hope that helps?
Yeah.
Quoted 120 lines
Quoted 120 lines
Quoted 107 lines
fs/xfs/libxfs/xfs_attr.c +39
-25} + 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. @@ -777,29 +868,29 @@ xfs_attr_leaf_addname(* In a separate transaction, set the incomplete flag on the "old" attr * and clear the incomplete flag on the "new" attr. */ - error =xfs_attr3_leaf_flipflags (args);if (error)return error;/* * Commit the flag value change and start the next trans in series. */ - error =xfs_trans_roll_inode (&args->trans, args->dp); -if (error) -return error; - + dac->dela_state =XFS_DAS_FLIP_LFLAG ; +return -EAGAIN ; +das_flip_flag:/* * Dismantle the "old" attribute/value pair by removing a "remote" value * (if it exists). */ xfs_attr_restore_rmt_blk (args); + error =xfs_attr_rmtval_invalidate (args); +if (error) +return error; +das_rm_lblk:if (args->rmtblkno) { - error =xfs_attr_rmtval_invalidate (args); -if (error) -return error; - - error =xfs_attr_rmtval_remove (args); + error =__xfs_attr_rmtval_remove (dac); +if (error == -EAGAIN ) + dac->dela_state =XFS_DAS_RM_LBLK ;if (error)return error; }@@ -965,23 +1056,38 @@ xfs_attr_node_hasname(* * "Remote" attribute values confuse the issue and atomic rename operations * add a whole extra layer of confusion on top of that. +* +* This routine is meant to function as a delayed operation, and may return +* -EAGAIN when the transaction needs to be rolled. Calling functions will need +* to handle this, and recall the function until a successful error code is +*returned. */ STATIC intxfs_attr_node_addname ( -struct xfs_da_args *args) +struct xfs_delattr_context *dac) { -struct xfs_da_state *state; -struct xfs_da_state_blk *blk; -struct xfs_inode *dp; -int retval, error; +struct xfs_da_args *args = dac->da_args; +struct xfs_da_state *state =NULL ; +struct xfs_da_state_blk *blk; +int retval =0 ; +int error =0 ;trace_xfs_attr_node_addname (args); -/* -* Fill in bucket of arguments/results/context to carry around. -*/ - dp = args->dp; -restart: +/* State machine switch */ +switch (dac->dela_state) { +case XFS_DAS_FLIP_NFLAG : + goto das_flip_flag; +case XFS_DAS_FOUND_NBLK : + goto das_found_nblk; +case XFS_DAS_ALLOC_NODE : + goto das_alloc_node; +case XFS_DAS_RM_NBLK : + goto das_rm_nblk; +default : +break ; + } +/* * Search to see if name already exists, and get back a pointer * to where it should go. @@ -1027,19 +1133,13 @@ xfs_attr_node_addname( error =xfs_attr3_leaf_to_node (args);if (error) goto out; - error =xfs_defer_finish (&args->trans); -if (error) - goto out;/* -* Commit the node conversion and start the next -* trans in the chain. fs/xfs/libxfs/xfs_attr.c xfs_attr_node_addname( · line 1141
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +4
-5+* Restart routine from the top. No need to set the +* state */ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) - goto out; - - goto restart; + dac->flags |=XFS_DAC_DEFER_FINISH ; +return -EAGAIN ;What state are we in here? Are we still in the same state that we were at the start of the function, but ready to try
xfs_attr3_leaf_addagain?
Quoted 8 lines
Quoted 6 lines
To directly answer the question: we may be in UNINIT if we were already a node when we started the attr op. If we had to promote from leaf to node, it may be some state left over from the leaf routines.
Again though, in so far as this routine is concerned, the idea is that the state either one of the cases in the switch up top, or it's not.
<nod> Comment please. :)
Sure, how about:
/*
* 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.
*/
Quoted 133 lines
Quoted 131 lines
Quoted 103 lines
Quoted 103 lines
fs/xfs/libxfs/xfs_attr.c +39
-19}/* @@ -1051,9 +1151,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. @@ -1068,13 +1166,9 @@ xfs_attr_node_addname(xfs_da_state_free (state); state =NULL ; -/* -* Commit the leaf addition or btree split and start the next -* trans in the chain. -*/ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) - goto out; + dac->dela_state =XFS_DAS_FOUND_NBLK ; +return -EAGAIN ; +das_found_nblk:/* * If there was an out-of-line value, allocate the blocks we @@ -1083,7 +1177,27 @@ xfs_attr_node_addname(* maximum size of a transaction and/or hit a deadlock. */ if (args->rmtblkno >0 ) { - error =xfs_attr_rmtval_set (args); +/* Open coded xfs_attr_rmtval_set without trans handling */ + error =xfs_attr_rmtval_find_space (dac); +if (error) +return error; + +/* +* Roll through the "value", allocating blocks on disk as +* required. +*/ +das_alloc_node: +if (dac->blkcnt >0 ) { + error =xfs_attr_rmtval_set_blk (dac); +if (error) +return error; + + dac->flags |=XFS_DAC_DEFER_FINISH ; + dac->dela_state =XFS_DAS_ALLOC_NODE ; +return -EAGAIN ; + } + + error =xfs_attr_rmtval_set_value (args);if (error)return error; }@@ -1113,22 +1227,28 @@ xfs_attr_node_addname(/* * Commit the flag value change and start the next trans in series */ - error =xfs_trans_roll_inode (&args->trans, args->dp); -if (error) - goto out; - + dac->dela_state =XFS_DAS_FLIP_NFLAG ; +return -EAGAIN ; +das_flip_flag:/* * Dismantle the "old" attribute/value pair by removing a "remote" value * (if it exists). */ xfs_attr_restore_rmt_blk (args); + error =xfs_attr_rmtval_invalidate (args); +if (error) +return error; + +das_rm_nblk:if (args->rmtblkno) { - error =xfs_attr_rmtval_invalidate (args); -if (error) -return error; + error =__xfs_attr_rmtval_remove (dac); + +if (error == -EAGAIN ) { + dac->dela_state =XFS_DAS_RM_NBLK ; +return -EAGAIN ; + } - error =xfs_attr_rmtval_remove (args);if (error)return error; }fs/xfs/libxfs/xfs_attr.h +1
-0@@ -106,6 +106,118 @@ struct xfs_attr_list_context {* v │ * done <─────┘ * +* Quoted 8 lines
fs/xfs/libxfs/xfs_attr.h struct xfs_attr_list_context { · line 114
Quoted 5 lines
fs/xfs/libxfs/xfs_attr.h +5
-0+* Below is a state machine diagram for attr set operations. +* +* xfs_attr_set_iter() +* │ +* v I think this diagram is missing the part where we attempt to add a shortform attr?
I left if out because the short form doesnt make use of states. I can doodle that in though if you prefer:
┌───n── is shortform? │ | │ y │ | │ V │ xfs_attr_set_shortform │ | │ V ├───n─── had enough │ space? │ │ │ y │ │ │ V │ done └────────────┐ │Quoted 1 line
V
Quoted 5 lines
Yes, please do capture the entire mechanism so that 2025 us aren't sitting here muttering about why we didn't do that when everything was still warm in our L1 brain cache. ;)
--D
Alrighty, will do :-)
Thank you!!!
Allison
Quoted 310 lines
Quoted 310 lines
Quoted 4 lines
--D
Thx for the thorough reviews!
Allison
Quoted 301 lines
Quoted 301 lines
fs/xfs/libxfs/xfs_attr.h +119
-1+* ┌───n── fork has +* │ only 1 blk? +* │ │ +* │ y +* │ │ +* │ v +* │ xfs_attr_leaf_try_add() +* │ │ +* │ v +* │ had enough +* ├───n────space? +* │ │ +* │ y +* │ │ +* │ v +* │ XFS_DAS_FOUND_LBLK ──┐ +* │ │ +* │ XFS_DAS_FLIP_LFLAG ──┤ +* │ (subroutine state) │ +* │ │ +* │ └─>xfs_attr_leaf_addname() +* │ │ +* │ v +* │ was this +* │ a rename? ──n─┐ +* │ │ │ +* │ y │ +* │ │ │ +* │ v │ +* │ flip incomplete │ +* │ flag │ +* │ │ │ +* │ v │ +* │ XFS_DAS_FLIP_LFLAG │ +* │ │ │ +* │ v │ +* │ remove │ +* │ XFS_DAS_RM_LBLK ─> old name │ +* │ ^ │ │ +* │ │ v │ +* │ └──────y── more to │ +* │ remove │ +* │ │ │ +* │ n │ +* │ │ │ +* │ v │ +* │ done <──────┘ +* └──> XFS_DAS_FOUND_NBLK ──┐ +* (subroutine state) │ +* │ +* XFS_DAS_ALLOC_NODE ──┤ +* (subroutine state) │ +* │ +* XFS_DAS_FLIP_NFLAG ──┤ +* (subroutine state) │ +* │ +* └─>xfs_attr_node_addname() +* │ +* v +* find space to store +* attr. Split if needed +* │ +* v +* XFS_DAS_FOUND_NBLK +* │ +* v +* ┌─────n── need to +* │ alloc blks? +* │ │ +* │ y +* │ │ +* │ v +* │ ┌─>XFS_DAS_ALLOC_NODE +* │ │ │ +* │ │ v +* │ └──y── need to alloc +* │ more blocks? +* │ │ +* │ n +* │ │ +* │ v +* │ was this +* └────────> a rename? ──n─┐ +* │ │ +* y │ +* │ │ +* v │ +* flip incomplete │ +* flag │ +* │ │ +* v │ +* XFS_DAS_FLIP_NFLAG │ +* │ │ +* v │ +* remove │ +* XFS_DAS_RM_NBLK ─> old name │ +* ^ │ │ +* │ v │ +* └──────y── more to │ +* remove │ +* │ │ +* n │ +* │ │ +* v │ +* done <──────┘ +* */ /* @@ -120,6 +232,13 @@ struct xfs_attr_list_context {enum xfs_delattr_state {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 */ };/* @@ -127,6 +246,7 @@ enum xfs_delattr_state {*/ #define XFS_DAC_DEFER_FINISH 0x01/* finish the transaction */ #define XFS_DAC_NODE_RMVNAME_INIT 0x02/* xfs_attr_node_removename init */ +#define XFS_DAC_LEAF_ADDNAME_INIT 0x04/* xfs_attr_leaf_addname init*/ /* * Context used for keeping track of delayed attribute operations @@ -134,6 +254,11 @@ enum xfs_delattr_state {struct xfs_delattr_context {struct xfs_da_args *da_args; +/* Used in xfs_attr_rmtval_set_blk to roll through allocating blocks */ +struct xfs_bmbt_irec map; +xfs_dablk_t lblkno; +int blkcnt; +/* Used in xfs_attr_node_removename to roll through removing blocks */ struct xfs_da_state *da_state;@@ -160,7 +285,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
-34@@ -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,38 +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
-0@@ -15,4 +15,8 @@ int xfs_attr_rmtval_stale(struct xfs_inode *ip, struct xfs_bmbt_irec *map, xfs_buf_flags_t incore_flags);int xfs_attr_rmtval_invalidate (struct xfs_da_args *args);int __xfs_attr_rmtval_remove (struct xfs_delattr_context *dac); +int xfs_attr_rmt_find_hole (struct xfs_da_args *args); +int xfs_attr_rmtval_set_value (struct xfs_da_args *args); +int xfs_attr_rmtval_set_blk (struct xfs_delattr_context *dac); +int xfs_attr_rmtval_find_space (struct xfs_delattr_context *dac);#endif /* __XFS_ATTR_REMOTE_H__ */ fs/xfs/xfs_trace.h +0
-1@@ -1925,7 +1925,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