Commit 88ee2f48 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Darrick J. Wong
Browse files

xfs: split the per-btree union in struct xfs_btree_cur



Split up the union that encodes btree-specific fields in struct
xfs_btree_cur.  Most fields in there are specific to the btree type
encoded in xfs_btree_ops.type, and we can use the obviously named union
for that.  But one field is specific to the bmapbt and two are shared by
the refcount and rtrefcountbt.  Move those to a separate union to make
the usage clear and not need a separate struct for the refcount-related
fields.

This will also make unnecessary some very awkward btree cursor
refc/rtrefc switching logic in the rtrefcount patchset.

Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarDarrick J. Wong <djwong@kernel.org>
Signed-off-by: default avatarDarrick J. Wong <djwong@kernel.org>
parent 4f0cd5a5
Loading
Loading
Loading
Loading
+11 −11
Original line number Diff line number Diff line
@@ -676,7 +676,7 @@ xfs_bmap_extents_to_btree(
		goto out_root_realloc;
	}

	cur->bc_ino.allocated++;
	cur->bc_bmap.allocated++;
	ip->i_nblocks++;
	xfs_trans_mod_dquot_byino(tp, ip, XFS_TRANS_DQ_BCOUNT, 1L);
	error = xfs_trans_get_buf(tp, mp->m_ddev_targp,
@@ -894,7 +894,7 @@ xfs_bmap_add_attrfork_btree(
			xfs_btree_del_cursor(cur, XFS_BTREE_NOERROR);
			return -ENOSPC;
		}
		cur->bc_ino.allocated = 0;
		cur->bc_bmap.allocated = 0;
		xfs_btree_del_cursor(cur, XFS_BTREE_NOERROR);
	}
	return 0;
@@ -922,7 +922,7 @@ xfs_bmap_add_attrfork_extents(
	error = xfs_bmap_extents_to_btree(tp, ip, &cur, 0, flags,
					  XFS_DATA_FORK);
	if (cur) {
		cur->bc_ino.allocated = 0;
		cur->bc_bmap.allocated = 0;
		xfs_btree_del_cursor(cur, error);
	}
	return error;
@@ -1746,7 +1746,7 @@ xfs_bmap_add_extent_delay_real(
		temp = PREV.br_blockcount - new->br_blockcount;
		da_new = XFS_FILBLKS_MIN(xfs_bmap_worst_indlen(bma->ip, temp),
			startblockval(PREV.br_startblock) -
			(bma->cur ? bma->cur->bc_ino.allocated : 0));
			(bma->cur ? bma->cur->bc_bmap.allocated : 0));

		PREV.br_startoff = new_endoff;
		PREV.br_blockcount = temp;
@@ -1836,7 +1836,7 @@ xfs_bmap_add_extent_delay_real(
		temp = PREV.br_blockcount - new->br_blockcount;
		da_new = XFS_FILBLKS_MIN(xfs_bmap_worst_indlen(bma->ip, temp),
			startblockval(PREV.br_startblock) -
			(bma->cur ? bma->cur->bc_ino.allocated : 0));
			(bma->cur ? bma->cur->bc_bmap.allocated : 0));

		PREV.br_startblock = nullstartblock(da_new);
		PREV.br_blockcount = temp;
@@ -1959,8 +1959,8 @@ xfs_bmap_add_extent_delay_real(
		xfs_mod_delalloc(mp, (int64_t)da_new - da_old);

	if (bma->cur) {
		da_new += bma->cur->bc_ino.allocated;
		bma->cur->bc_ino.allocated = 0;
		da_new += bma->cur->bc_bmap.allocated;
		bma->cur->bc_bmap.allocated = 0;
	}

	/* adjust for changes in reserved delayed indirect blocks */
@@ -2525,7 +2525,7 @@ xfs_bmap_add_extent_unwritten_real(

	/* clear out the allocated field, done with it now in any case. */
	if (cur) {
		cur->bc_ino.allocated = 0;
		cur->bc_bmap.allocated = 0;
		*curp = cur;
	}

@@ -2913,7 +2913,7 @@ xfs_bmap_add_extent_hole_real(

	/* clear out the allocated field, done with it now in any case. */
	if (cur)
		cur->bc_ino.allocated = 0;
		cur->bc_bmap.allocated = 0;

	xfs_bmap_check_leaf_extents(cur, ip, whichfork);
done:
@@ -5629,7 +5629,7 @@ __xfs_bunmapi(
		xfs_trans_log_inode(tp, ip, logflags);
	if (cur) {
		if (!error)
			cur->bc_ino.allocated = 0;
			cur->bc_bmap.allocated = 0;
		xfs_btree_del_cursor(cur, error);
	}
	return error;
@@ -6145,7 +6145,7 @@ xfs_bmap_split_extent(

del_cursor:
	if (cur) {
		cur->bc_ino.allocated = 0;
		cur->bc_bmap.allocated = 0;
		xfs_btree_del_cursor(cur, error);
	}

+4 −5
Original line number Diff line number Diff line
@@ -198,10 +198,10 @@ xfs_bmbt_update_cursor(
	ASSERT((dst->bc_tp->t_highest_agno != NULLAGNUMBER) ||
	       (dst->bc_ino.ip->i_diflags & XFS_DIFLAG_REALTIME));

	dst->bc_ino.allocated += src->bc_ino.allocated;
	dst->bc_bmap.allocated += src->bc_bmap.allocated;
	dst->bc_tp->t_highest_agno = src->bc_tp->t_highest_agno;

	src->bc_ino.allocated = 0;
	src->bc_bmap.allocated = 0;
}

STATIC int
@@ -256,7 +256,7 @@ xfs_bmbt_alloc_block(
	}

	ASSERT(args.len == 1);
	cur->bc_ino.allocated++;
	cur->bc_bmap.allocated++;
	cur->bc_ino.ip->i_nblocks++;
	xfs_trans_log_inode(args.tp, cur->bc_ino.ip, XFS_ILOG_CORE);
	xfs_trans_mod_dquot_byino(args.tp, cur->bc_ino.ip,
@@ -568,8 +568,7 @@ xfs_bmbt_init_common(
			mp->m_bm_maxlevels[whichfork], xfs_bmbt_cur_cache);

	cur->bc_ino.ip = ip;
	cur->bc_ino.allocated = 0;

	cur->bc_bmap.allocated = 0;
	return cur;
}

+1 −1
Original line number Diff line number Diff line
@@ -445,7 +445,7 @@ xfs_btree_del_cursor(
	 * zero, then we should be shut down or on our way to shutdown due to
	 * cancelling a dirty transaction on error.
	 */
	ASSERT(cur->bc_btnum != XFS_BTNUM_BMAP || cur->bc_ino.allocated == 0 ||
	ASSERT(cur->bc_btnum != XFS_BTNUM_BMAP || cur->bc_bmap.allocated == 0 ||
	       xfs_is_shutdown(cur->bc_mp) || error != 0);

	switch (cur->bc_ops->type) {
+23 −32
Original line number Diff line number Diff line
@@ -243,30 +243,6 @@ union xfs_btree_irec {
	struct xfs_refcount_irec	rc;
};

/* Per-AG btree information. */
struct xfs_btree_cur_ag {
	struct xfs_perag		*pag;
	union {
		struct xfs_buf		*agbp;
		struct xbtree_afakeroot	*afake;	/* for staging cursor */
	};
	union {
		struct {
			unsigned int	nr_ops;	/* # record updates */
			unsigned int	shape_changes;	/* # of extent splits */
		} refc;
	};
};

/* Btree-in-inode cursor information */
struct xfs_btree_cur_ino {
	struct xfs_inode		*ip;
	struct xbtree_ifakeroot		*ifake;	/* for staging cursor */
	int				allocated;
	short				forksize;
	char				whichfork;
};

struct xfs_btree_level {
	/* buffer pointer */
	struct xfs_buf		*bp;
@@ -296,15 +272,30 @@ struct xfs_btree_cur
	uint8_t			bc_nlevels; /* number of levels in the tree */
	uint8_t			bc_maxlevels; /* maximum levels for this btree type */

	/*
	 * Short btree pointers need an agno to be able to turn the pointers
	 * into physical addresses for IO, so the btree cursor switches between
	 * bc_ino and bc_ag based on bc_ops->type.
	 * the cursor.
	 */
	/* per-type information */
	union {
		struct xfs_btree_cur_ag	bc_ag;
		struct xfs_btree_cur_ino bc_ino;
		struct {
			struct xfs_inode	*ip;
			short			forksize;
			char			whichfork;
			struct xbtree_ifakeroot	*ifake;	/* for staging cursor */
		} bc_ino;
		struct {
			struct xfs_perag	*pag;
			struct xfs_buf		*agbp;
			struct xbtree_afakeroot	*afake;	/* for staging cursor */
		} bc_ag;
	};

	/* per-format private data */
	union {
		struct {
			int		allocated;
		} bc_bmap;	/* bmapbt */
		struct {
			unsigned int	nr_ops;		/* # record updates */
			unsigned int	shape_changes;	/* # of extent splits */
		} bc_refc;	/* refcountbt */
	};

	/* Must be at the end of the struct! */
+1 −0
Original line number Diff line number Diff line
@@ -172,6 +172,7 @@ xfs_btree_commit_afakeroot(
	trace_xfs_btree_commit_afakeroot(cur);

	kfree((void *)cur->bc_ops);
	cur->bc_ag.afake = NULL;
	cur->bc_ag.agbp = agbp;
	cur->bc_ops = ops;
	cur->bc_flags &= ~XFS_BTREE_STAGING;
Loading