Commit bcd2c9f3 authored by Brian Foster's avatar Brian Foster Committed by Darrick J. Wong
Browse files

xfs: refactor dfops init to attach to transaction



Most callers of xfs_defer_init() immediately attach the dfops
structure to a transaction. Add a transaction parameter to eliminate
much of this boilerplate code. This also helps self-document the
fact that many codepaths now expect a dfops pointer implicitly via
xfs_trans->t_dfops.

Signed-off-by: default avatarBrian Foster <bfoster@redhat.com>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
parent d5669ed5
Loading
Loading
Loading
Loading
+14 −12
Original line number Diff line number Diff line
@@ -253,8 +253,7 @@ xfs_attr_set(
			rsvd ? XFS_TRANS_RESERVE : 0, &args.trans);
	if (error)
		return error;
	xfs_defer_init(&dfops, &firstblock);
	args.trans->t_dfops = &dfops;
	xfs_defer_init(args.trans, &dfops, &firstblock);

	xfs_ilock(dp, XFS_ILOCK_EXCL);
	error = xfs_trans_reserve_quota_nblks(args.trans, dp, args.total, 0,
@@ -428,8 +427,7 @@ xfs_attr_remove(
			&args.trans);
	if (error)
		return error;
	xfs_defer_init(&dfops, &firstblock);
	args.trans->t_dfops = &dfops;
	xfs_defer_init(args.trans, &dfops, &firstblock);

	xfs_ilock(dp, XFS_ILOCK_EXCL);
	/*
@@ -600,7 +598,7 @@ xfs_attr_leaf_addname(
		 * Commit that transaction so that the node_addname() call
		 * can manage its own transactions.
		 */
		xfs_defer_init(args->trans->t_dfops, args->firstblock);
		xfs_defer_init(NULL, args->trans->t_dfops, args->firstblock);
		error = xfs_attr3_leaf_to_node(args);
		if (error)
			goto out_defer_cancel;
@@ -689,7 +687,8 @@ xfs_attr_leaf_addname(
		 * If the result is small enough, shrink it all into the inode.
		 */
		if ((forkoff = xfs_attr_shortform_allfit(bp, dp))) {
			xfs_defer_init(args->trans->t_dfops, args->firstblock);
			xfs_defer_init(NULL, args->trans->t_dfops,
				       args->firstblock);
			error = xfs_attr3_leaf_to_shortform(bp, args, forkoff);
			/* bp is gone due to xfs_da_shrink_inode */
			if (error)
@@ -754,7 +753,7 @@ xfs_attr_leaf_removename(
	 * If the result is small enough, shrink it all into the inode.
	 */
	if ((forkoff = xfs_attr_shortform_allfit(bp, dp))) {
		xfs_defer_init(args->trans->t_dfops, args->firstblock);
		xfs_defer_init(NULL, args->trans->t_dfops, args->firstblock);
		error = xfs_attr3_leaf_to_shortform(bp, args, forkoff);
		/* bp is gone due to xfs_da_shrink_inode */
		if (error)
@@ -883,7 +882,8 @@ restart:
			 */
			xfs_da_state_free(state);
			state = NULL;
			xfs_defer_init(args->trans->t_dfops, args->firstblock);
			xfs_defer_init(NULL, args->trans->t_dfops,
				       args->firstblock);
			error = xfs_attr3_leaf_to_node(args);
			if (error)
				goto out_defer_cancel;
@@ -910,7 +910,7 @@ restart:
		 * in the index/blkno/rmtblkno/rmtblkcnt fields and
		 * in the index2/blkno2/rmtblkno2/rmtblkcnt2 fields.
		 */
		xfs_defer_init(args->trans->t_dfops, args->firstblock);
		xfs_defer_init(NULL, args->trans->t_dfops, args->firstblock);
		error = xfs_da3_split(state);
		if (error)
			goto out_defer_cancel;
@@ -1008,7 +1008,8 @@ restart:
		 * Check to see if the tree needs to be collapsed.
		 */
		if (retval && (state->path.active > 1)) {
			xfs_defer_init(args->trans->t_dfops, args->firstblock);
			xfs_defer_init(NULL, args->trans->t_dfops,
				       args->firstblock);
			error = xfs_da3_join(state);
			if (error)
				goto out_defer_cancel;
@@ -1133,7 +1134,7 @@ xfs_attr_node_removename(
	 * Check to see if the tree needs to be collapsed.
	 */
	if (retval && (state->path.active > 1)) {
		xfs_defer_init(args->trans->t_dfops, args->firstblock);
		xfs_defer_init(NULL, args->trans->t_dfops, args->firstblock);
		error = xfs_da3_join(state);
		if (error)
			goto out_defer_cancel;
@@ -1165,7 +1166,8 @@ xfs_attr_node_removename(
			goto out;

		if ((forkoff = xfs_attr_shortform_allfit(bp, dp))) {
			xfs_defer_init(args->trans->t_dfops, args->firstblock);
			xfs_defer_init(NULL, args->trans->t_dfops,
				       args->firstblock);
			error = xfs_attr3_leaf_to_shortform(bp, args, forkoff);
			/* bp is gone due to xfs_da_shrink_inode */
			if (error)
+3 −3
Original line number Diff line number Diff line
@@ -480,7 +480,7 @@ xfs_attr_rmtval_set(
		 * extent and then crash then the block may not contain the
		 * correct metadata after log recovery occurs.
		 */
		xfs_defer_init(args->trans->t_dfops, args->firstblock);
		xfs_defer_init(NULL, args->trans->t_dfops, args->firstblock);
		nmap = 1;
		error = xfs_bmapi_write(args->trans, dp, (xfs_fileoff_t)lblkno,
				  blkcnt, XFS_BMAPI_ATTRFORK, args->firstblock,
@@ -522,7 +522,7 @@ xfs_attr_rmtval_set(

		ASSERT(blkcnt > 0);

		xfs_defer_init(args->trans->t_dfops, args->firstblock);
		xfs_defer_init(NULL, args->trans->t_dfops, args->firstblock);
		nmap = 1;
		error = xfs_bmapi_read(dp, (xfs_fileoff_t)lblkno,
				       blkcnt, &map, &nmap,
@@ -626,7 +626,7 @@ xfs_attr_rmtval_remove(
	blkcnt = args->rmtblkcnt;
	done = 0;
	while (!done) {
		xfs_defer_init(args->trans->t_dfops, args->firstblock);
		xfs_defer_init(NULL, args->trans->t_dfops, args->firstblock);
		error = xfs_bunmapi(args->trans, args->dp, lblkno, blkcnt,
				    XFS_BMAPI_ATTRFORK, 1, args->firstblock,
				    &done);
+2 −4
Original line number Diff line number Diff line
@@ -1050,8 +1050,7 @@ xfs_bmap_add_attrfork(
			rsvd ? XFS_TRANS_RESERVE : 0, &tp);
	if (error)
		return error;
	xfs_defer_init(&dfops, &firstblock);
	tp->t_dfops = &dfops;
	xfs_defer_init(tp, &dfops, &firstblock);

	xfs_ilock(ip, XFS_ILOCK_EXCL);
	error = xfs_trans_reserve_quota_nblks(tp, ip, blks, 0, rsvd ?
@@ -6025,8 +6024,7 @@ xfs_bmap_split_extent(
			XFS_DIOSTRAT_SPACE_RES(mp, 0), 0, 0, &tp);
	if (error)
		return error;
	xfs_defer_init(&dfops, &firstfsb);
	tp->t_dfops = &dfops;
	xfs_defer_init(tp, &dfops, &firstfsb);

	xfs_ilock(ip, XFS_ILOCK_EXCL);
	xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
+8 −1
Original line number Diff line number Diff line
@@ -523,12 +523,19 @@ xfs_defer_init_op_type(
/* Initialize a deferred operation. */
void
xfs_defer_init(
	struct xfs_trans		*tp,
	struct xfs_defer_ops		*dop,
	xfs_fsblock_t			*fbp)
{
	struct xfs_mount		*mp = NULL;

	memset(dop, 0, sizeof(struct xfs_defer_ops));
	*fbp = NULLFSBLOCK;
	INIT_LIST_HEAD(&dop->dop_intake);
	INIT_LIST_HEAD(&dop->dop_pending);
	trace_xfs_defer_init(NULL, dop, _RET_IP_);
	if (tp) {
		tp->t_dfops = dop;
		mp = tp->t_mountp;
	}
	trace_xfs_defer_init(mp, dop, _RET_IP_);
}
+2 −1
Original line number Diff line number Diff line
@@ -63,7 +63,8 @@ void xfs_defer_add(struct xfs_defer_ops *dop, enum xfs_defer_ops_type type,
		struct list_head *h);
int xfs_defer_finish(struct xfs_trans **tp, struct xfs_defer_ops *dop);
void xfs_defer_cancel(struct xfs_defer_ops *dop);
void xfs_defer_init(struct xfs_defer_ops *dop, xfs_fsblock_t *fbp);
void xfs_defer_init(struct xfs_trans *tp, struct xfs_defer_ops *dop,
		    xfs_fsblock_t *fbp);
bool xfs_defer_has_unfinished_work(struct xfs_defer_ops *dop);
int xfs_defer_ijoin(struct xfs_defer_ops *dop, struct xfs_inode *ip);
int xfs_defer_bjoin(struct xfs_defer_ops *dop, struct xfs_buf *bp);
Loading