Skip to content

Commit 7d03533

Browse files
dgchinnerdchinner
authored andcommitted
xfs: split remote attr setting out from replace path
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>
1 parent 251b29c commit 7d03533

3 files changed

Lines changed: 77 additions & 59 deletions

File tree

fs/xfs/libxfs/xfs_attr.c

Lines changed: 62 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -333,9 +333,11 @@ xfs_attr_leaf_addname(
333333
* or perform more xattr manipulations. Otherwise there is nothing more
334334
* to do and we can return success.
335335
*/
336-
if (args->rmtblkno ||
337-
(args->op_flags & XFS_DA_OP_RENAME)) {
338-
attr->xattri_dela_state = XFS_DAS_FOUND_LBLK;
336+
if (args->rmtblkno) {
337+
attr->xattri_dela_state = XFS_DAS_LEAF_SET_RMT;
338+
error = -EAGAIN;
339+
} else if (args->op_flags & XFS_DA_OP_RENAME) {
340+
attr->xattri_dela_state = XFS_DAS_LEAF_REPLACE;
339341
error = -EAGAIN;
340342
} else {
341343
attr->xattri_dela_state = XFS_DAS_DONE;
@@ -362,9 +364,11 @@ xfs_attr_node_addname(
362364
if (error)
363365
return error;
364366

365-
if (args->rmtblkno ||
366-
(args->op_flags & XFS_DA_OP_RENAME)) {
367-
attr->xattri_dela_state = XFS_DAS_FOUND_NBLK;
367+
if (args->rmtblkno) {
368+
attr->xattri_dela_state = XFS_DAS_NODE_SET_RMT;
369+
error = -EAGAIN;
370+
} else if (args->op_flags & XFS_DA_OP_RENAME) {
371+
attr->xattri_dela_state = XFS_DAS_NODE_REPLACE;
368372
error = -EAGAIN;
369373
} else {
370374
attr->xattri_dela_state = XFS_DAS_DONE;
@@ -374,6 +378,40 @@ xfs_attr_node_addname(
374378
return error;
375379
}
376380

381+
static int
382+
xfs_attr_rmtval_alloc(
383+
struct xfs_attr_item *attr)
384+
{
385+
struct xfs_da_args *args = attr->xattri_da_args;
386+
int error = 0;
387+
388+
/*
389+
* If there was an out-of-line value, allocate the blocks we
390+
* identified for its storage and copy the value. This is done
391+
* after we create the attribute so that we don't overflow the
392+
* maximum size of a transaction and/or hit a deadlock.
393+
*/
394+
if (attr->xattri_blkcnt > 0) {
395+
error = xfs_attr_rmtval_set_blk(attr);
396+
if (error)
397+
return error;
398+
error = -EAGAIN;
399+
goto out;
400+
}
401+
402+
error = xfs_attr_rmtval_set_value(args);
403+
if (error)
404+
return error;
405+
406+
/* If this is not a rename, clear the incomplete flag and we're done. */
407+
if (!(args->op_flags & XFS_DA_OP_RENAME)) {
408+
error = xfs_attr3_leaf_clearflag(args);
409+
attr->xattri_dela_state = XFS_DAS_DONE;
410+
}
411+
out:
412+
trace_xfs_attr_rmtval_alloc(attr->xattri_dela_state, args->dp);
413+
return error;
414+
}
377415

378416
/*
379417
* Set the attribute specified in @args.
@@ -405,54 +443,26 @@ xfs_attr_set_iter(
405443
case XFS_DAS_NODE_ADD:
406444
return xfs_attr_node_addname(attr);
407445

408-
case XFS_DAS_FOUND_LBLK:
409-
case XFS_DAS_FOUND_NBLK:
410-
/*
411-
* Find space for remote blocks and fall into the allocation
412-
* state.
413-
*/
414-
if (args->rmtblkno > 0) {
415-
error = xfs_attr_rmtval_find_space(attr);
416-
if (error)
417-
return error;
418-
}
446+
case XFS_DAS_LEAF_SET_RMT:
447+
case XFS_DAS_NODE_SET_RMT:
448+
error = xfs_attr_rmtval_find_space(attr);
449+
if (error)
450+
return error;
419451
attr->xattri_dela_state++;
420452
fallthrough;
453+
421454
case XFS_DAS_LEAF_ALLOC_RMT:
422455
case XFS_DAS_NODE_ALLOC_RMT:
423-
424-
/*
425-
* If there was an out-of-line value, allocate the blocks we
426-
* identified for its storage and copy the value. This is done
427-
* after we create the attribute so that we don't overflow the
428-
* maximum size of a transaction and/or hit a deadlock.
429-
*/
430-
if (args->rmtblkno > 0) {
431-
if (attr->xattri_blkcnt > 0) {
432-
error = xfs_attr_rmtval_set_blk(attr);
433-
if (error)
434-
return error;
435-
trace_xfs_attr_set_iter_return(
436-
attr->xattri_dela_state,
437-
args->dp);
438-
return -EAGAIN;
439-
}
440-
441-
error = xfs_attr_rmtval_set_value(args);
442-
if (error)
443-
return error;
444-
}
445-
446-
/*
447-
* If this is not a rename, clear the incomplete flag and we're
448-
* done.
449-
*/
450-
if (!(args->op_flags & XFS_DA_OP_RENAME)) {
451-
if (args->rmtblkno > 0)
452-
error = xfs_attr3_leaf_clearflag(args);
456+
error = xfs_attr_rmtval_alloc(attr);
457+
if (error)
453458
return error;
454-
}
459+
if (attr->xattri_dela_state == XFS_DAS_DONE)
460+
break;
461+
attr->xattri_dela_state++;
462+
fallthrough;
455463

464+
case XFS_DAS_LEAF_REPLACE:
465+
case XFS_DAS_NODE_REPLACE:
456466
/*
457467
* If this is an atomic rename operation, we must "flip" the
458468
* incomplete flags on the "new" and "old" attribute/value pairs
@@ -470,10 +480,9 @@ xfs_attr_set_iter(
470480
* Commit the flag value change and start the next trans
471481
* in series at FLIP_FLAG.
472482
*/
483+
error = -EAGAIN;
473484
attr->xattri_dela_state++;
474-
trace_xfs_attr_set_iter_return(attr->xattri_dela_state,
475-
args->dp);
476-
return -EAGAIN;
485+
break;
477486
}
478487

479488
attr->xattri_dela_state++;
@@ -548,6 +557,8 @@ xfs_attr_set_iter(
548557
ASSERT(0);
549558
break;
550559
}
560+
561+
trace_xfs_attr_set_iter_return(attr->xattri_dela_state, args->dp);
551562
return error;
552563
}
553564

fs/xfs/libxfs/xfs_attr.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -452,15 +452,17 @@ enum xfs_delattr_state {
452452
XFS_DAS_RM_SHRINK, /* We are shrinking the tree */
453453

454454
/* Leaf state set sequence */
455-
XFS_DAS_FOUND_LBLK, /* We found leaf blk for attr */
455+
XFS_DAS_LEAF_SET_RMT, /* set a remote xattr from a leaf */
456456
XFS_DAS_LEAF_ALLOC_RMT, /* We are allocating remote blocks */
457+
XFS_DAS_LEAF_REPLACE, /* Perform replace ops on a leaf */
457458
XFS_DAS_FLIP_LFLAG, /* Flipped leaf INCOMPLETE attr flag */
458459
XFS_DAS_RM_LBLK, /* A rename is removing leaf blocks */
459460
XFS_DAS_RD_LEAF, /* Read in the new leaf */
460461

461462
/* Node state set sequence, must match leaf state above */
462-
XFS_DAS_FOUND_NBLK, /* We found node blk for attr */
463+
XFS_DAS_NODE_SET_RMT, /* set a remote xattr from a node */
463464
XFS_DAS_NODE_ALLOC_RMT, /* We are allocating remote blocks */
465+
XFS_DAS_NODE_REPLACE, /* Perform replace ops on a node */
464466
XFS_DAS_FLIP_NFLAG, /* Flipped node INCOMPLETE attr flag */
465467
XFS_DAS_RM_NBLK, /* A rename is removing node blocks */
466468
XFS_DAS_CLR_FLAG, /* Clear incomplete flag */
@@ -476,13 +478,15 @@ enum xfs_delattr_state {
476478
{ XFS_DAS_RMTBLK, "XFS_DAS_RMTBLK" }, \
477479
{ XFS_DAS_RM_NAME, "XFS_DAS_RM_NAME" }, \
478480
{ XFS_DAS_RM_SHRINK, "XFS_DAS_RM_SHRINK" }, \
479-
{ XFS_DAS_FOUND_LBLK, "XFS_DAS_FOUND_LBLK" }, \
481+
{ XFS_DAS_LEAF_SET_RMT, "XFS_DAS_LEAF_SET_RMT" }, \
480482
{ XFS_DAS_LEAF_ALLOC_RMT, "XFS_DAS_LEAF_ALLOC_RMT" }, \
481-
{ XFS_DAS_FOUND_NBLK, "XFS_DAS_FOUND_NBLK" }, \
482-
{ XFS_DAS_NODE_ALLOC_RMT, "XFS_DAS_NODE_ALLOC_RMT" }, \
483+
{ XFS_DAS_LEAF_REPLACE, "XFS_DAS_LEAF_REPLACE" }, \
483484
{ XFS_DAS_FLIP_LFLAG, "XFS_DAS_FLIP_LFLAG" }, \
484485
{ XFS_DAS_RM_LBLK, "XFS_DAS_RM_LBLK" }, \
485486
{ XFS_DAS_RD_LEAF, "XFS_DAS_RD_LEAF" }, \
487+
{ XFS_DAS_NODE_SET_RMT, "XFS_DAS_NODE_SET_RMT" }, \
488+
{ XFS_DAS_NODE_ALLOC_RMT, "XFS_DAS_NODE_ALLOC_RMT" }, \
489+
{ XFS_DAS_NODE_REPLACE, "XFS_DAS_NODE_REPLACE" }, \
486490
{ XFS_DAS_FLIP_NFLAG, "XFS_DAS_FLIP_NFLAG" }, \
487491
{ XFS_DAS_RM_NBLK, "XFS_DAS_RM_NBLK" }, \
488492
{ XFS_DAS_CLR_FLAG, "XFS_DAS_CLR_FLAG" }, \

fs/xfs/xfs_trace.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4136,13 +4136,15 @@ TRACE_DEFINE_ENUM(XFS_DAS_NODE_ADD);
41364136
TRACE_DEFINE_ENUM(XFS_DAS_RMTBLK);
41374137
TRACE_DEFINE_ENUM(XFS_DAS_RM_NAME);
41384138
TRACE_DEFINE_ENUM(XFS_DAS_RM_SHRINK);
4139-
TRACE_DEFINE_ENUM(XFS_DAS_FOUND_LBLK);
4139+
TRACE_DEFINE_ENUM(XFS_DAS_LEAF_SET_RMT);
41404140
TRACE_DEFINE_ENUM(XFS_DAS_LEAF_ALLOC_RMT);
4141-
TRACE_DEFINE_ENUM(XFS_DAS_FOUND_NBLK);
4142-
TRACE_DEFINE_ENUM(XFS_DAS_NODE_ALLOC_RMT);
4141+
TRACE_DEFINE_ENUM(XFS_DAS_LEAF_REPLACE);
41434142
TRACE_DEFINE_ENUM(XFS_DAS_FLIP_LFLAG);
41444143
TRACE_DEFINE_ENUM(XFS_DAS_RM_LBLK);
41454144
TRACE_DEFINE_ENUM(XFS_DAS_RD_LEAF);
4145+
TRACE_DEFINE_ENUM(XFS_DAS_NODE_SET_RMT);
4146+
TRACE_DEFINE_ENUM(XFS_DAS_NODE_ALLOC_RMT);
4147+
TRACE_DEFINE_ENUM(XFS_DAS_NODE_REPLACE);
41464148
TRACE_DEFINE_ENUM(XFS_DAS_FLIP_NFLAG);
41474149
TRACE_DEFINE_ENUM(XFS_DAS_RM_NBLK);
41484150
TRACE_DEFINE_ENUM(XFS_DAS_CLR_FLAG);
@@ -4172,6 +4174,7 @@ DEFINE_DAS_STATE_EVENT(xfs_attr_set_iter_return);
41724174
DEFINE_DAS_STATE_EVENT(xfs_attr_leaf_addname_return);
41734175
DEFINE_DAS_STATE_EVENT(xfs_attr_node_addname_return);
41744176
DEFINE_DAS_STATE_EVENT(xfs_attr_remove_iter_return);
4177+
DEFINE_DAS_STATE_EVENT(xfs_attr_rmtval_alloc);
41754178
DEFINE_DAS_STATE_EVENT(xfs_attr_rmtval_remove_return);
41764179
DEFINE_DAS_STATE_EVENT(xfs_attr_defer_add);
41774180
DEFINE_DAS_STATE_EVENT(xfs_attr_defer_replace);

0 commit comments

Comments
 (0)