xfs: consolidate the xfs_attr_defer_* helpers

Consolidate the xfs_attr_defer_* helpers into a single xfs_attr_defer_add
one that picks the right dela_state based on the passed in operation.
Also move to a single trace point as the actual operation is visible
through the flags in the delta_state passed to the trace point.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>
This commit is contained in:
Christoph Hellwig 2023-12-13 10:06:29 +01:00 committed by Chandan Babu R
parent 19b366dae1
commit c00eebd09e
2 changed files with 21 additions and 71 deletions

View File

@ -880,11 +880,10 @@ xfs_attr_lookup(
return error; return error;
} }
static int static void
xfs_attr_intent_init( xfs_attr_defer_add(
struct xfs_da_args *args, struct xfs_da_args *args,
unsigned int op_flags, /* op flag (set or remove) */ unsigned int op_flags)
struct xfs_attr_intent **attr) /* new xfs_attr_intent */
{ {
struct xfs_attr_intent *new; struct xfs_attr_intent *new;
@ -893,66 +892,22 @@ xfs_attr_intent_init(
new->xattri_op_flags = op_flags; new->xattri_op_flags = op_flags;
new->xattri_da_args = args; new->xattri_da_args = args;
*attr = new; switch (op_flags) {
return 0; case XFS_ATTRI_OP_FLAGS_SET:
} new->xattri_dela_state = xfs_attr_init_add_state(args);
break;
case XFS_ATTRI_OP_FLAGS_REPLACE:
new->xattri_dela_state = xfs_attr_init_replace_state(args);
break;
case XFS_ATTRI_OP_FLAGS_REMOVE:
new->xattri_dela_state = xfs_attr_init_remove_state(args);
break;
default:
ASSERT(0);
}
/* Sets an attribute for an inode as a deferred operation */
static int
xfs_attr_defer_add(
struct xfs_da_args *args)
{
struct xfs_attr_intent *new;
int error = 0;
error = xfs_attr_intent_init(args, XFS_ATTRI_OP_FLAGS_SET, &new);
if (error)
return error;
new->xattri_dela_state = xfs_attr_init_add_state(args);
xfs_defer_add(args->trans, XFS_DEFER_OPS_TYPE_ATTR, &new->xattri_list); xfs_defer_add(args->trans, XFS_DEFER_OPS_TYPE_ATTR, &new->xattri_list);
trace_xfs_attr_defer_add(new->xattri_dela_state, args->dp); trace_xfs_attr_defer_add(new->xattri_dela_state, args->dp);
return 0;
}
/* Sets an attribute for an inode as a deferred operation */
static int
xfs_attr_defer_replace(
struct xfs_da_args *args)
{
struct xfs_attr_intent *new;
int error = 0;
error = xfs_attr_intent_init(args, XFS_ATTRI_OP_FLAGS_REPLACE, &new);
if (error)
return error;
new->xattri_dela_state = xfs_attr_init_replace_state(args);
xfs_defer_add(args->trans, XFS_DEFER_OPS_TYPE_ATTR, &new->xattri_list);
trace_xfs_attr_defer_replace(new->xattri_dela_state, args->dp);
return 0;
}
/* Removes an attribute for an inode as a deferred operation */
static int
xfs_attr_defer_remove(
struct xfs_da_args *args)
{
struct xfs_attr_intent *new;
int error;
error = xfs_attr_intent_init(args, XFS_ATTRI_OP_FLAGS_REMOVE, &new);
if (error)
return error;
new->xattri_dela_state = xfs_attr_init_remove_state(args);
xfs_defer_add(args->trans, XFS_DEFER_OPS_TYPE_ATTR, &new->xattri_list);
trace_xfs_attr_defer_remove(new->xattri_dela_state, args->dp);
return 0;
} }
/* /*
@ -1038,16 +993,16 @@ xfs_attr_set(
error = xfs_attr_lookup(args); error = xfs_attr_lookup(args);
switch (error) { switch (error) {
case -EEXIST: case -EEXIST:
/* if no value, we are performing a remove operation */
if (!args->value) { if (!args->value) {
error = xfs_attr_defer_remove(args); /* if no value, we are performing a remove operation */
xfs_attr_defer_add(args, XFS_ATTRI_OP_FLAGS_REMOVE);
break; break;
} }
/* Pure create fails if the attr already exists */ /* Pure create fails if the attr already exists */
if (args->attr_flags & XATTR_CREATE) if (args->attr_flags & XATTR_CREATE)
goto out_trans_cancel; goto out_trans_cancel;
xfs_attr_defer_add(args, XFS_ATTRI_OP_FLAGS_REPLACE);
error = xfs_attr_defer_replace(args);
break; break;
case -ENOATTR: case -ENOATTR:
/* Can't remove what isn't there. */ /* Can't remove what isn't there. */
@ -1057,14 +1012,11 @@ xfs_attr_set(
/* Pure replace fails if no existing attr to replace. */ /* Pure replace fails if no existing attr to replace. */
if (args->attr_flags & XATTR_REPLACE) if (args->attr_flags & XATTR_REPLACE)
goto out_trans_cancel; goto out_trans_cancel;
xfs_attr_defer_add(args, XFS_ATTRI_OP_FLAGS_SET);
error = xfs_attr_defer_add(args);
break; break;
default: default:
goto out_trans_cancel; goto out_trans_cancel;
} }
if (error)
goto out_trans_cancel;
/* /*
* If this is a synchronous mount, make sure that the * If this is a synchronous mount, make sure that the

View File

@ -4408,8 +4408,6 @@ DEFINE_DAS_STATE_EVENT(xfs_attr_remove_iter_return);
DEFINE_DAS_STATE_EVENT(xfs_attr_rmtval_alloc); DEFINE_DAS_STATE_EVENT(xfs_attr_rmtval_alloc);
DEFINE_DAS_STATE_EVENT(xfs_attr_rmtval_remove_return); DEFINE_DAS_STATE_EVENT(xfs_attr_rmtval_remove_return);
DEFINE_DAS_STATE_EVENT(xfs_attr_defer_add); DEFINE_DAS_STATE_EVENT(xfs_attr_defer_add);
DEFINE_DAS_STATE_EVENT(xfs_attr_defer_replace);
DEFINE_DAS_STATE_EVENT(xfs_attr_defer_remove);
TRACE_EVENT(xfs_force_shutdown, TRACE_EVENT(xfs_force_shutdown,