aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Chinner <dchinner@redhat.com>2022-06-22 14:28:52 -0500
committerEric Sandeen <sandeen@sandeen.net>2022-06-22 14:28:52 -0500
commit03a861f4ddedcbb054fdeaee471531f318d47c1a (patch)
tree2ef7d3a4b1f4de58f80ec5c30d4e67cc806cd500
parent21b9a05df03df12bae194c7dbad217d7fbda0c99 (diff)
downloadxfsprogs-dev-03a861f4ddedcbb054fdeaee471531f318d47c1a.tar.gz
xfs: split remote attr setting out from replace path
Source kernel commit: 7d03533629d1c3fca395e6fd0935ca1de676f2bc When we set a new xattr, we have three exit paths: 1. nothing else to do 2. allocate and set the remote xattr value 3. perform the rest of a replace operation Currently we push both 2 and 3 into the same state, regardless of whether we just set a remote attribute or not. Once we've set the remote xattr, we have two exit states: 1. nothing else to do 2. perform the rest of a replace operation Hence we can split the remote xattr allocation and setting into their own states and factor it out of xfs_attr_set_iter() to further clean up the state machine and the implementation of the state machine. Signed-off-by: Dave Chinner <dchinner@redhat.com> Reviewed-by: Allison Henderson<allison.henderson@oracle.com> Reviewed-by: Dave Chinner <david@fromorbit.com> Signed-off-by: Dave Chinner <david@fromorbit.com> Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
-rw-r--r--include/xfs_trace.h1
-rw-r--r--libxfs/xfs_attr.c113
-rw-r--r--libxfs/xfs_attr.h14
3 files changed, 72 insertions, 56 deletions
diff --git a/include/xfs_trace.h b/include/xfs_trace.h
index 3484b53f3f..5460905e43 100644
--- a/include/xfs_trace.h
+++ b/include/xfs_trace.h
@@ -47,6 +47,7 @@
#define trace_xfs_attr_leaf_addname_return(...) ((void) 0)
#define trace_xfs_attr_node_addname_return(...) ((void) 0)
#define trace_xfs_attr_remove_iter_return(...) ((void) 0)
+#define trace_xfs_attr_rmtval_alloc(...) ((void) 0)
#define trace_xfs_attr_rmtval_remove_return(...) ((void) 0)
#define trace_xfs_log_recover_item_add_cont(a,b,c,d) ((void) 0)
diff --git a/libxfs/xfs_attr.c b/libxfs/xfs_attr.c
index d0919e2ffe..cfad25d3af 100644
--- a/libxfs/xfs_attr.c
+++ b/libxfs/xfs_attr.c
@@ -331,9 +331,11 @@ xfs_attr_leaf_addname(
* or perform more xattr manipulations. Otherwise there is nothing more
* to do and we can return success.
*/
- if (args->rmtblkno ||
- (args->op_flags & XFS_DA_OP_RENAME)) {
- attr->xattri_dela_state = XFS_DAS_FOUND_LBLK;
+ if (args->rmtblkno) {
+ attr->xattri_dela_state = XFS_DAS_LEAF_SET_RMT;
+ error = -EAGAIN;
+ } else if (args->op_flags & XFS_DA_OP_RENAME) {
+ attr->xattri_dela_state = XFS_DAS_LEAF_REPLACE;
error = -EAGAIN;
} else {
attr->xattri_dela_state = XFS_DAS_DONE;
@@ -360,9 +362,11 @@ xfs_attr_node_addname(
if (error)
return error;
- if (args->rmtblkno ||
- (args->op_flags & XFS_DA_OP_RENAME)) {
- attr->xattri_dela_state = XFS_DAS_FOUND_NBLK;
+ if (args->rmtblkno) {
+ attr->xattri_dela_state = XFS_DAS_NODE_SET_RMT;
+ error = -EAGAIN;
+ } else if (args->op_flags & XFS_DA_OP_RENAME) {
+ attr->xattri_dela_state = XFS_DAS_NODE_REPLACE;
error = -EAGAIN;
} else {
attr->xattri_dela_state = XFS_DAS_DONE;
@@ -372,6 +376,40 @@ xfs_attr_node_addname(
return error;
}
+static int
+xfs_attr_rmtval_alloc(
+ struct xfs_attr_item *attr)
+{
+ struct xfs_da_args *args = attr->xattri_da_args;
+ int error = 0;
+
+ /*
+ * If there was an out-of-line value, allocate the blocks we
+ * identified for its storage and copy the value. This is done
+ * after we create the attribute so that we don't overflow the
+ * maximum size of a transaction and/or hit a deadlock.
+ */
+ if (attr->xattri_blkcnt > 0) {
+ error = xfs_attr_rmtval_set_blk(attr);
+ if (error)
+ return error;
+ error = -EAGAIN;
+ goto out;
+ }
+
+ error = xfs_attr_rmtval_set_value(args);
+ if (error)
+ return error;
+
+ /* If this is not a rename, clear the incomplete flag and we're done. */
+ if (!(args->op_flags & XFS_DA_OP_RENAME)) {
+ error = xfs_attr3_leaf_clearflag(args);
+ attr->xattri_dela_state = XFS_DAS_DONE;
+ }
+out:
+ trace_xfs_attr_rmtval_alloc(attr->xattri_dela_state, args->dp);
+ return error;
+}
/*
* Set the attribute specified in @args.
@@ -403,54 +441,26 @@ next_state:
case XFS_DAS_NODE_ADD:
return xfs_attr_node_addname(attr);
- case XFS_DAS_FOUND_LBLK:
- case XFS_DAS_FOUND_NBLK:
- /*
- * Find space for remote blocks and fall into the allocation
- * state.
- */
- if (args->rmtblkno > 0) {
- error = xfs_attr_rmtval_find_space(attr);
- if (error)
- return error;
- }
+ case XFS_DAS_LEAF_SET_RMT:
+ case XFS_DAS_NODE_SET_RMT:
+ error = xfs_attr_rmtval_find_space(attr);
+ if (error)
+ return error;
attr->xattri_dela_state++;
fallthrough;
+
case XFS_DAS_LEAF_ALLOC_RMT:
case XFS_DAS_NODE_ALLOC_RMT:
-
- /*
- * If there was an out-of-line value, allocate the blocks we
- * identified for its storage and copy the value. This is done
- * after we create the attribute so that we don't overflow the
- * maximum size of a transaction and/or hit a deadlock.
- */
- if (args->rmtblkno > 0) {
- if (attr->xattri_blkcnt > 0) {
- error = xfs_attr_rmtval_set_blk(attr);
- if (error)
- return error;
- trace_xfs_attr_set_iter_return(
- attr->xattri_dela_state,
- args->dp);
- return -EAGAIN;
- }
-
- error = xfs_attr_rmtval_set_value(args);
- if (error)
- return error;
- }
-
- /*
- * If this is not a rename, clear the incomplete flag and we're
- * done.
- */
- if (!(args->op_flags & XFS_DA_OP_RENAME)) {
- if (args->rmtblkno > 0)
- error = xfs_attr3_leaf_clearflag(args);
+ error = xfs_attr_rmtval_alloc(attr);
+ if (error)
return error;
- }
+ if (attr->xattri_dela_state == XFS_DAS_DONE)
+ break;
+ attr->xattri_dela_state++;
+ fallthrough;
+ case XFS_DAS_LEAF_REPLACE:
+ case XFS_DAS_NODE_REPLACE:
/*
* If this is an atomic rename operation, we must "flip" the
* incomplete flags on the "new" and "old" attribute/value pairs
@@ -468,10 +478,9 @@ next_state:
* Commit the flag value change and start the next trans
* in series at FLIP_FLAG.
*/
+ error = -EAGAIN;
attr->xattri_dela_state++;
- trace_xfs_attr_set_iter_return(attr->xattri_dela_state,
- args->dp);
- return -EAGAIN;
+ break;
}
attr->xattri_dela_state++;
@@ -546,6 +555,8 @@ next_state:
ASSERT(0);
break;
}
+
+ trace_xfs_attr_set_iter_return(attr->xattri_dela_state, args->dp);
return error;
}
diff --git a/libxfs/xfs_attr.h b/libxfs/xfs_attr.h
index 908a13d617..a0e631df1e 100644
--- a/libxfs/xfs_attr.h
+++ b/libxfs/xfs_attr.h
@@ -452,15 +452,17 @@ enum xfs_delattr_state {
XFS_DAS_RM_SHRINK, /* We are shrinking the tree */
/* Leaf state set sequence */
- XFS_DAS_FOUND_LBLK, /* We found leaf blk for attr */
+ XFS_DAS_LEAF_SET_RMT, /* set a remote xattr from a leaf */
XFS_DAS_LEAF_ALLOC_RMT, /* We are allocating remote blocks */
+ XFS_DAS_LEAF_REPLACE, /* Perform replace ops on a leaf */
XFS_DAS_FLIP_LFLAG, /* Flipped leaf INCOMPLETE attr flag */
XFS_DAS_RM_LBLK, /* A rename is removing leaf blocks */
XFS_DAS_RD_LEAF, /* Read in the new leaf */
/* Node state set sequence, must match leaf state above */
- XFS_DAS_FOUND_NBLK, /* We found node blk for attr */
+ XFS_DAS_NODE_SET_RMT, /* set a remote xattr from a node */
XFS_DAS_NODE_ALLOC_RMT, /* We are allocating remote blocks */
+ XFS_DAS_NODE_REPLACE, /* Perform replace ops on a node */
XFS_DAS_FLIP_NFLAG, /* Flipped node INCOMPLETE attr flag */
XFS_DAS_RM_NBLK, /* A rename is removing node blocks */
XFS_DAS_CLR_FLAG, /* Clear incomplete flag */
@@ -476,13 +478,15 @@ enum xfs_delattr_state {
{ XFS_DAS_RMTBLK, "XFS_DAS_RMTBLK" }, \
{ XFS_DAS_RM_NAME, "XFS_DAS_RM_NAME" }, \
{ XFS_DAS_RM_SHRINK, "XFS_DAS_RM_SHRINK" }, \
- { XFS_DAS_FOUND_LBLK, "XFS_DAS_FOUND_LBLK" }, \
+ { XFS_DAS_LEAF_SET_RMT, "XFS_DAS_LEAF_SET_RMT" }, \
{ XFS_DAS_LEAF_ALLOC_RMT, "XFS_DAS_LEAF_ALLOC_RMT" }, \
- { XFS_DAS_FOUND_NBLK, "XFS_DAS_FOUND_NBLK" }, \
- { XFS_DAS_NODE_ALLOC_RMT, "XFS_DAS_NODE_ALLOC_RMT" }, \
+ { XFS_DAS_LEAF_REPLACE, "XFS_DAS_LEAF_REPLACE" }, \
{ XFS_DAS_FLIP_LFLAG, "XFS_DAS_FLIP_LFLAG" }, \
{ XFS_DAS_RM_LBLK, "XFS_DAS_RM_LBLK" }, \
{ XFS_DAS_RD_LEAF, "XFS_DAS_RD_LEAF" }, \
+ { XFS_DAS_NODE_SET_RMT, "XFS_DAS_NODE_SET_RMT" }, \
+ { XFS_DAS_NODE_ALLOC_RMT, "XFS_DAS_NODE_ALLOC_RMT" }, \
+ { XFS_DAS_NODE_REPLACE, "XFS_DAS_NODE_REPLACE" }, \
{ XFS_DAS_FLIP_NFLAG, "XFS_DAS_FLIP_NFLAG" }, \
{ XFS_DAS_RM_NBLK, "XFS_DAS_RM_NBLK" }, \
{ XFS_DAS_CLR_FLAG, "XFS_DAS_CLR_FLAG" }, \