Commit 7c93d4a8 authored by Allison Collins's avatar Allison Collins Committed by Darrick J. Wong

xfs: Split apart xfs_attr_leaf_addname

Split out new helper function xfs_attr_leaf_try_add from
xfs_attr_leaf_addname. Because new delayed attribute routines cannot
roll transactions, we split off the parts of xfs_attr_leaf_addname that
we can use, and move the commit into the calling function.
Signed-off-by: default avatarAllison Collins <allison.henderson@oracle.com>
Reviewed-by: default avatarBrian Foster <bfoster@redhat.com>
Reviewed-by: default avatarChandan Rajendra <chandanrlinux@gmail.com>
Reviewed-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
Acked-by: default avatarDave Chinner <dchinner@redhat.com>
parent e3be1272
...@@ -256,10 +256,31 @@ xfs_attr_set_args( ...@@ -256,10 +256,31 @@ xfs_attr_set_args(
} }
} }
if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
error = xfs_attr_leaf_addname(args); error = xfs_attr_leaf_addname(args);
else if (error != -ENOSPC)
error = xfs_attr_node_addname(args); return error;
/*
* Finish any deferred work items and roll the transaction once
* more. The goal here is to call node_addname with the inode
* and transaction in the same state (inode locked and joined,
* transaction clean) no matter how we got to this step.
*/
error = xfs_defer_finish(&args->trans);
if (error)
return error;
/*
* Commit the current trans (including the inode) and
* start a new one.
*/
error = xfs_trans_roll_inode(&args->trans, dp);
if (error)
return error;
}
error = xfs_attr_node_addname(args);
return error; return error;
} }
...@@ -507,20 +528,21 @@ xfs_attr_shortform_addname(xfs_da_args_t *args) ...@@ -507,20 +528,21 @@ xfs_attr_shortform_addname(xfs_da_args_t *args)
*========================================================================*/ *========================================================================*/
/* /*
* Add a name to the leaf attribute list structure * Tries to add an attribute to an inode in leaf form
* *
* This leaf block cannot have a "remote" value, we only call this routine * This function is meant to execute as part of a delayed operation and leaves
* if bmap_one_block() says there is only one block (ie: no remote blks). * the transaction handling to the caller. On success the attribute is added
* and the inode and transaction are left dirty. If there is not enough space,
* the attr data is converted to node format and -ENOSPC is returned. Caller is
* responsible for handling the dirty inode and transaction or adding the attr
* in node format.
*/ */
STATIC int STATIC int
xfs_attr_leaf_addname( xfs_attr_leaf_try_add(
struct xfs_da_args *args) struct xfs_da_args *args,
struct xfs_buf *bp)
{ {
struct xfs_buf *bp; int retval, error;
int retval, error, forkoff;
struct xfs_inode *dp = args->dp;
trace_xfs_attr_leaf_addname(args);
/* /*
* Look up the given attribute in the leaf block. Figure out if * Look up the given attribute in the leaf block. Figure out if
...@@ -562,31 +584,39 @@ xfs_attr_leaf_addname( ...@@ -562,31 +584,39 @@ xfs_attr_leaf_addname(
retval = xfs_attr3_leaf_add(bp, args); retval = xfs_attr3_leaf_add(bp, args);
if (retval == -ENOSPC) { if (retval == -ENOSPC) {
/* /*
* Promote the attribute list to the Btree format, then * Promote the attribute list to the Btree format. Unless an
* Commit that transaction so that the node_addname() call * error occurs, retain the -ENOSPC retval
* can manage its own transactions.
*/ */
error = xfs_attr3_leaf_to_node(args); error = xfs_attr3_leaf_to_node(args);
if (error) if (error)
return error; return error;
error = xfs_defer_finish(&args->trans); }
if (error) return retval;
return error; out_brelse:
xfs_trans_brelse(args->trans, bp);
return retval;
}
/*
* Commit the current trans (including the inode) and start
* a new one.
*/
error = xfs_trans_roll_inode(&args->trans, dp);
if (error)
return error;
/* /*
* Fob the whole rest of the problem off on the Btree code. * Add a name to the leaf attribute list structure
*/ *
error = xfs_attr_node_addname(args); * This leaf block cannot have a "remote" value, we only call this routine
* if bmap_one_block() says there is only one block (ie: no remote blks).
*/
STATIC int
xfs_attr_leaf_addname(
struct xfs_da_args *args)
{
int error, forkoff;
struct xfs_buf *bp = NULL;
struct xfs_inode *dp = args->dp;
trace_xfs_attr_leaf_addname(args);
error = xfs_attr_leaf_try_add(args, bp);
if (error)
return error; return error;
}
/* /*
* Commit the transaction that added the attr name so that * Commit the transaction that added the attr name so that
...@@ -681,9 +711,6 @@ xfs_attr_leaf_addname( ...@@ -681,9 +711,6 @@ xfs_attr_leaf_addname(
error = xfs_attr3_leaf_clearflag(args); error = xfs_attr3_leaf_clearflag(args);
} }
return error; return error;
out_brelse:
xfs_trans_brelse(args->trans, bp);
return retval;
} }
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment