Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

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

xfs: remove all boilerplate defer init/finish code



At this point, the transaction subsystem completely manages deferred
items internally such that the common and boilerplate
xfs_trans_alloc() -> xfs_defer_init() -> xfs_defer_finish() ->
xfs_trans_commit() sequence can be replaced with a simple
transaction allocation and commit.

Remove all such boilerplate deferred ops code. In doing so, we
change each case over to use the dfops in the transaction and
specifically eliminate:

- The on-stack dfops and associated xfs_defer_init() call, as the
  internal dfops is initialized on transaction allocation.
- xfs_bmap_finish() calls that precede a final xfs_trans_commit() of
  a transaction.
- xfs_defer_cancel() calls in error handlers that precede a
  transaction cancel.

The only deferred ops calls that remain are those that are
non-deterministic with respect to the final commit of the associated
transaction or are open-coded due to special handling.

Signed-off-by: default avatarBrian Foster <bfoster@redhat.com>
Reviewed-by: default avatarBill O'Donnell <billodo@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 91ef75b6
Loading
Loading
Loading
Loading
+1 −15
Original line number Diff line number Diff line
@@ -1018,7 +1018,6 @@ xfs_bmap_add_attrfork(
	int			size,		/* space new attribute needs */
	int			rsvd)		/* xact may use reserved blks */
{
	struct xfs_defer_ops	dfops;		/* freed extent records */
	xfs_mount_t		*mp;		/* mount structure */
	xfs_trans_t		*tp;		/* transaction pointer */
	int			blks;		/* space reservation */
@@ -1037,7 +1036,6 @@ xfs_bmap_add_attrfork(
			rsvd ? XFS_TRANS_RESERVE : 0, &tp);
	if (error)
		return error;
	xfs_defer_init(tp, &dfops);

	xfs_ilock(ip, XFS_ILOCK_EXCL);
	error = xfs_trans_reserve_quota_nblks(tp, ip, blks, 0, rsvd ?
@@ -1102,7 +1100,7 @@ xfs_bmap_add_attrfork(
	if (logflags)
		xfs_trans_log_inode(tp, ip, logflags);
	if (error)
		goto bmap_cancel;
		goto trans_cancel;
	if (!xfs_sb_version_hasattr(&mp->m_sb) ||
	   (!xfs_sb_version_hasattr2(&mp->m_sb) && version == 2)) {
		bool log_sb = false;
@@ -1121,15 +1119,10 @@ xfs_bmap_add_attrfork(
			xfs_log_sb(tp);
	}

	error = xfs_defer_finish(&tp, &dfops);
	if (error)
		goto bmap_cancel;
	error = xfs_trans_commit(tp);
	xfs_iunlock(ip, XFS_ILOCK_EXCL);
	return error;

bmap_cancel:
	xfs_defer_cancel(&dfops);
trans_cancel:
	xfs_trans_cancel(tp);
	xfs_iunlock(ip, XFS_ILOCK_EXCL);
@@ -5953,14 +5946,12 @@ xfs_bmap_split_extent(
{
	struct xfs_mount        *mp = ip->i_mount;
	struct xfs_trans        *tp;
	struct xfs_defer_ops    dfops;
	int                     error;

	error = xfs_trans_alloc(mp, &M_RES(mp)->tr_write,
			XFS_DIOSTRAT_SPACE_RES(mp, 0), 0, 0, &tp);
	if (error)
		return error;
	xfs_defer_init(tp, &dfops);

	xfs_ilock(ip, XFS_ILOCK_EXCL);
	xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
@@ -5969,14 +5960,9 @@ xfs_bmap_split_extent(
	if (error)
		goto out;

	error = xfs_defer_finish(&tp, &dfops);
	if (error)
		goto out;

	return xfs_trans_commit(tp);

out:
	xfs_defer_cancel(&dfops);
	xfs_trans_cancel(tp);
	return error;
}
+1 −9
Original line number Diff line number Diff line
@@ -1635,7 +1635,6 @@ xfs_refcount_recover_cow_leftovers(
	struct list_head		debris;
	union xfs_btree_irec		low;
	union xfs_btree_irec		high;
	struct xfs_defer_ops		dfops;
	xfs_fsblock_t			fsb;
	xfs_agblock_t			agbno;
	int				error;
@@ -1691,22 +1690,17 @@ xfs_refcount_recover_cow_leftovers(
		trace_xfs_refcount_recover_extent(mp, agno, &rr->rr_rrec);

		/* Free the orphan record */
		xfs_defer_init(tp, &dfops);
		agbno = rr->rr_rrec.rc_startblock - XFS_REFC_COW_START;
		fsb = XFS_AGB_TO_FSB(mp, agno, agbno);
		error = xfs_refcount_free_cow_extent(mp, tp->t_dfops, fsb,
				rr->rr_rrec.rc_blockcount);
		if (error)
			goto out_defer;
			goto out_trans;

		/* Free the block. */
		xfs_bmap_add_free(mp, tp->t_dfops, fsb,
				rr->rr_rrec.rc_blockcount, NULL);

		error = xfs_defer_finish(&tp, tp->t_dfops);
		if (error)
			goto out_defer;

		error = xfs_trans_commit(tp);
		if (error)
			goto out_free;
@@ -1716,8 +1710,6 @@ xfs_refcount_recover_cow_leftovers(
	}

	return error;
out_defer:
	xfs_defer_cancel(tp->t_dfops);
out_trans:
	xfs_trans_cancel(tp);
out_free:
+0 −2
Original line number Diff line number Diff line
@@ -382,7 +382,6 @@ xfs_attr_inactive(
{
	struct xfs_trans	*trans;
	struct xfs_mount	*mp;
	struct xfs_defer_ops	dfops;
	int			lock_mode = XFS_ILOCK_SHARED;
	int			error = 0;

@@ -399,7 +398,6 @@ xfs_attr_inactive(
	error = xfs_trans_alloc(mp, &M_RES(mp)->tr_attrinval, 0, 0, 0, &trans);
	if (error)
		goto out_destroy_fork;
	xfs_defer_init(trans, &dfops);

	lock_mode = XFS_ILOCK_EXCL;
	xfs_ilock(dp, lock_mode);
+6 −37
Original line number Diff line number Diff line
@@ -792,7 +792,6 @@ xfs_free_eofblocks(
	int			nimaps;
	struct xfs_bmbt_irec	imap;
	struct xfs_mount	*mp = ip->i_mount;
	struct xfs_defer_ops	dfops;

	/*
	 * Figure out if there are any blocks beyond the end
@@ -832,7 +831,6 @@ xfs_free_eofblocks(
			ASSERT(XFS_FORCED_SHUTDOWN(mp));
			return error;
		}
		xfs_defer_init(tp, &dfops);

		xfs_ilock(ip, XFS_ILOCK_EXCL);
		xfs_trans_ijoin(tp, ip, 0);
@@ -880,7 +878,6 @@ xfs_alloc_file_space(
	int			rt;
	xfs_trans_t		*tp;
	xfs_bmbt_irec_t		imaps[1], *imapp;
	struct xfs_defer_ops	dfops;
	uint			qblocks, resblks, resrtextents;
	int			error;

@@ -973,7 +970,6 @@ xfs_alloc_file_space(

		xfs_trans_ijoin(tp, ip, 0);

		xfs_defer_init(tp, &dfops);
		error = xfs_bmapi_write(tp, ip, startoffset_fsb,
					allocatesize_fsb, alloc_type, resblks,
					imapp, &nimaps);
@@ -983,10 +979,6 @@ xfs_alloc_file_space(
		/*
		 * Complete the transaction
		 */
		error = xfs_defer_finish(&tp, tp->t_dfops);
		if (error)
			goto error0;

		error = xfs_trans_commit(tp);
		xfs_iunlock(ip, XFS_ILOCK_EXCL);
		if (error)
@@ -1005,8 +997,7 @@ xfs_alloc_file_space(

	return error;

error0:	/* Cancel bmap, unlock inode, unreserve quota blocks, cancel trans */
	xfs_defer_cancel(&dfops);
error0:	/* unlock inode, unreserve quota blocks, cancel trans */
	xfs_trans_unreserve_quota_nblks(tp, ip, (long)qblocks, 0, quota_flag);

error1:	/* Just cancel transaction */
@@ -1024,7 +1015,6 @@ xfs_unmap_extent(
{
	struct xfs_mount	*mp = ip->i_mount;
	struct xfs_trans	*tp;
	struct xfs_defer_ops	dfops;
	uint			resblks = XFS_DIOSTRAT_SPACE_RES(mp, 0);
	int			error;

@@ -1042,23 +1032,17 @@ xfs_unmap_extent(

	xfs_trans_ijoin(tp, ip, 0);

	xfs_defer_init(tp, &dfops);
	error = xfs_bunmapi(tp, ip, startoffset_fsb, len_fsb, 0, 2, done);
	if (error)
		goto out_bmap_cancel;
		goto out_trans_cancel;

	xfs_defer_ijoin(tp->t_dfops, ip);
	error = xfs_defer_finish(&tp, tp->t_dfops);
	if (error)
		goto out_bmap_cancel;

	error = xfs_trans_commit(tp);
out_unlock:
	xfs_iunlock(ip, XFS_ILOCK_EXCL);
	return error;

out_bmap_cancel:
	xfs_defer_cancel(tp->t_dfops);
out_trans_cancel:
	xfs_trans_cancel(tp);
	goto out_unlock;
@@ -1310,7 +1294,6 @@ xfs_collapse_file_space(
	struct xfs_mount	*mp = ip->i_mount;
	struct xfs_trans	*tp;
	int			error;
	struct xfs_defer_ops	dfops;
	xfs_fileoff_t		next_fsb = XFS_B_TO_FSB(mp, offset + len);
	xfs_fileoff_t		shift_fsb = XFS_B_TO_FSB(mp, len);
	uint			resblks = XFS_DIOSTRAT_SPACE_RES(mp, 0);
@@ -1343,22 +1326,16 @@ xfs_collapse_file_space(
			goto out_trans_cancel;
		xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);

		xfs_defer_init(tp, &dfops);
		error = xfs_bmap_collapse_extents(tp, ip, &next_fsb, shift_fsb,
				&done);
		if (error)
			goto out_bmap_cancel;
			goto out_trans_cancel;

		error = xfs_defer_finish(&tp, tp->t_dfops);
		if (error)
			goto out_bmap_cancel;
		error = xfs_trans_commit(tp);
	}

	return error;

out_bmap_cancel:
	xfs_defer_cancel(tp->t_dfops);
out_trans_cancel:
	xfs_trans_cancel(tp);
	return error;
@@ -1385,7 +1362,6 @@ xfs_insert_file_space(
	struct xfs_mount	*mp = ip->i_mount;
	struct xfs_trans	*tp;
	int			error;
	struct xfs_defer_ops	dfops;
	xfs_fileoff_t		stop_fsb = XFS_B_TO_FSB(mp, offset);
	xfs_fileoff_t		next_fsb = NULLFSBLOCK;
	xfs_fileoff_t		shift_fsb = XFS_B_TO_FSB(mp, len);
@@ -1421,22 +1397,17 @@ xfs_insert_file_space(

		xfs_ilock(ip, XFS_ILOCK_EXCL);
		xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
		xfs_defer_init(tp, &dfops);
		error = xfs_bmap_insert_extents(tp, ip, &next_fsb, shift_fsb,
				&done, stop_fsb);
		if (error)
			goto out_bmap_cancel;
			goto out_trans_cancel;

		error = xfs_defer_finish(&tp, tp->t_dfops);
		if (error)
			goto out_bmap_cancel;
		error = xfs_trans_commit(tp);
	}

	return error;

out_bmap_cancel:
	xfs_defer_cancel(tp->t_dfops);
out_trans_cancel:
	xfs_trans_cancel(tp);
	return error;
}
@@ -1607,7 +1578,7 @@ xfs_swap_extent_rmap(

		/* Unmap the old blocks in the source file. */
		while (tirec.br_blockcount) {
			xfs_defer_init(tp, tp->t_dfops);
			ASSERT(tp->t_firstblock == NULLFSBLOCK);
			trace_xfs_swap_extent_rmap_remap_piece(tip, &tirec);

			/* Read extent from the source file */
@@ -1831,7 +1802,6 @@ xfs_swap_extents(
{
	struct xfs_mount	*mp = ip->i_mount;
	struct xfs_trans	*tp;
	struct xfs_defer_ops	dfops;
	struct xfs_bstat	*sbp = &sxp->sx_stat;
	int			src_log_flags, target_log_flags;
	int			error = 0;
@@ -1900,7 +1870,6 @@ xfs_swap_extents(
	error = xfs_trans_alloc(mp, &M_RES(mp)->tr_write, resblks, 0, 0, &tp);
	if (error)
		goto out_unlock;
	xfs_defer_init(tp, &dfops);

	/*
	 * Lock and join the inodes to the tansaction so that transaction commit
+0 −4
Original line number Diff line number Diff line
@@ -295,8 +295,6 @@ xfs_dquot_disk_alloc(

	trace_xfs_dqalloc(dqp);

	xfs_defer_init(tp, tp->t_dfops);

	xfs_ilock(quotip, XFS_ILOCK_EXCL);
	if (!xfs_this_quota_on(dqp->q_mount, dqp->dq_flags)) {
		/*
@@ -538,7 +536,6 @@ xfs_qm_dqread_alloc(
	struct xfs_buf		**bpp)
{
	struct xfs_trans	*tp;
	struct xfs_defer_ops	dfops;
	struct xfs_buf		*bp;
	int			error;

@@ -546,7 +543,6 @@ xfs_qm_dqread_alloc(
			XFS_QM_DQALLOC_SPACE_RES(mp), 0, 0, &tp);
	if (error)
		goto err;
	xfs_defer_init(tp, &dfops);

	error = xfs_dquot_disk_alloc(&tp, dqp, &bp);
	if (error)
Loading