Unverified Commit d14e41f4 authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files

!14235 xfs: fix attr inactive issue

Merge Pull Request from: @ci-robot 
 
PR sync from: Long Li <leo.lilong@huawei.com>
https://mailweb.openeuler.org/hyperkitty/list/kernel@openeuler.org/message/KIRUBEOGSTTP23ZRIGWMA3TNZV2UCTZB/ 
This patch set fix fix attr inactive issue.

Long Li (3):
  xfs: factor out xfs_da3_node_entry_remove
  xfs: factor out xfs_attr3_leaf_init
  xfs: handle attr node/leaf blocks atomically during inactive


-- 
2.39.2
 
https://gitee.com/openeuler/kernel/issues/IBALAU 
 
Link:https://gitee.com/openeuler/kernel/pulls/14235

 

Reviewed-by: default avatarzhangyi (F) <yi.zhang@huawei.com>
Reviewed-by: default avatarLi Nan <linan122@huawei.com>
Signed-off-by: default avatarLi Nan <linan122@huawei.com>
parents 10f7cc85 ef1616f2
Loading
Loading
Loading
Loading
+40 −16
Original line number Diff line number Diff line
@@ -1241,36 +1241,30 @@ xfs_attr3_leaf_to_node(
 * Routines used for growing the Btree.
 *========================================================================*/

/*
 * Create the initial contents of a leaf attribute list
 * or a leaf in a node attribute list.
 */
STATIC int
xfs_attr3_leaf_create(
	struct xfs_da_args	*args,
__xfs_attr3_leaf_create(
	struct xfs_trans	*tp,
	struct xfs_inode	*dp,
	struct xfs_da_geometry	*geo,
	xfs_dablk_t		blkno,
	struct xfs_buf		**bpp)
{
	struct xfs_attr_leafblock *leaf;
	struct xfs_attr3_icleaf_hdr ichdr;
	struct xfs_inode	*dp = args->dp;
	struct xfs_mount	*mp = dp->i_mount;
	struct xfs_buf		*bp;
	int			error;

	trace_xfs_attr_leaf_create(args);

	error = xfs_da_get_buf(args->trans, args->dp, blkno, &bp,
					    XFS_ATTR_FORK);
	error = xfs_da_get_buf(tp, dp, blkno, &bp, XFS_ATTR_FORK);
	if (error)
		return error;
	bp->b_ops = &xfs_attr3_leaf_buf_ops;
	xfs_trans_buf_set_type(args->trans, bp, XFS_BLFT_ATTR_LEAF_BUF);
	xfs_trans_buf_set_type(tp, bp, XFS_BLFT_ATTR_LEAF_BUF);
	leaf = bp->b_addr;
	memset(leaf, 0, args->geo->blksize);
	memset(leaf, 0, geo->blksize);

	memset(&ichdr, 0, sizeof(ichdr));
	ichdr.firstused = args->geo->blksize;
	ichdr.firstused = geo->blksize;

	if (xfs_has_crc(mp)) {
		struct xfs_da3_blkinfo *hdr3 = bp->b_addr;
@@ -1288,13 +1282,43 @@ xfs_attr3_leaf_create(
	}
	ichdr.freemap[0].size = ichdr.firstused - ichdr.freemap[0].base;

	xfs_attr3_leaf_hdr_to_disk(args->geo, leaf, &ichdr);
	xfs_trans_log_buf(args->trans, bp, 0, args->geo->blksize - 1);
	xfs_attr3_leaf_hdr_to_disk(geo, leaf, &ichdr);
	xfs_trans_log_buf(tp, bp, 0, geo->blksize - 1);

	*bpp = bp;
	return 0;
}

/*
 * Create the initial contents of a leaf attribute list
 * or a leaf in a node attribute list.
 */
STATIC int
xfs_attr3_leaf_create(
	struct xfs_da_args	*args,
	xfs_dablk_t		blkno,
	struct xfs_buf		**bpp)
{
	trace_xfs_attr_leaf_create(args);
	return __xfs_attr3_leaf_create(args->trans, args->dp,
			args->geo, blkno, bpp);
}

/*
 * Wrapper function of initializing leaf node, export for external use.
 */
int
xfs_attr3_leaf_init(
	struct xfs_trans	*tp,
	struct xfs_inode	*dp,
	xfs_dablk_t		blkno)
{
	struct xfs_buf		*bp = NULL;
	struct xfs_da_geometry  *geo = dp->i_mount->m_attr_geo;

	return __xfs_attr3_leaf_create(tp, dp, geo, blkno, &bp);
}

/*
 * Split the leaf node, rebalance, then add the new entry.
 */
+3 −0
Original line number Diff line number Diff line
@@ -73,6 +73,9 @@ int xfs_attr3_leaf_flipflags(struct xfs_da_args *args);
/*
 * Routines used for growing the Btree.
 */

int	xfs_attr3_leaf_init(struct xfs_trans *tp, struct xfs_inode *dp,
				xfs_dablk_t blkno);
int	xfs_attr3_leaf_split(struct xfs_da_state *state,
				   struct xfs_da_state_blk *oldblk,
				   struct xfs_da_state_blk *newblk);
+41 −13
Original line number Diff line number Diff line
@@ -1430,12 +1430,11 @@ xfs_da3_fixhashpath(
	}
}

/*
 * Remove an entry from an intermediate node.
 */
STATIC void
xfs_da3_node_remove(
	struct xfs_da_state	*state,
__xfs_da3_node_remove(
	struct xfs_trans	*tp,
	struct xfs_inode	*dp,
	struct xfs_da_geometry  *geo,
	struct xfs_da_state_blk *drop_blk)
{
	struct xfs_da_intnode	*node;
@@ -1443,9 +1442,6 @@ xfs_da3_node_remove(
	struct xfs_da_node_entry *btree;
	int			index;
	int			tmp;
	struct xfs_inode	*dp = state->args->dp;

	trace_xfs_da_node_remove(state->args);

	node = drop_blk->bp->b_addr;
	xfs_da3_node_hdr_from_disk(dp->i_mount, &nodehdr, node);
@@ -1461,17 +1457,17 @@ xfs_da3_node_remove(
		tmp  = nodehdr.count - index - 1;
		tmp *= (uint)sizeof(xfs_da_node_entry_t);
		memmove(&btree[index], &btree[index + 1], tmp);
		xfs_trans_log_buf(state->args->trans, drop_blk->bp,
		xfs_trans_log_buf(tp, drop_blk->bp,
		    XFS_DA_LOGRANGE(node, &btree[index], tmp));
		index = nodehdr.count - 1;
	}
	memset(&btree[index], 0, sizeof(xfs_da_node_entry_t));
	xfs_trans_log_buf(state->args->trans, drop_blk->bp,
	xfs_trans_log_buf(tp, drop_blk->bp,
	    XFS_DA_LOGRANGE(node, &btree[index], sizeof(btree[index])));
	nodehdr.count -= 1;
	xfs_da3_node_hdr_to_disk(dp->i_mount, node, &nodehdr);
	xfs_trans_log_buf(state->args->trans, drop_blk->bp,
	    XFS_DA_LOGRANGE(node, &node->hdr, state->args->geo->node_hdr_size));
	xfs_trans_log_buf(tp, drop_blk->bp,
	    XFS_DA_LOGRANGE(node, &node->hdr, geo->node_hdr_size));

	/*
	 * Copy the last hash value from the block to propagate upwards.
@@ -1479,6 +1475,38 @@ xfs_da3_node_remove(
	drop_blk->hashval = be32_to_cpu(btree[index - 1].hashval);
}

/*
 * Remove an entry from an intermediate node.
 */
STATIC void
xfs_da3_node_remove(
	struct xfs_da_state	*state,
	struct xfs_da_state_blk	*drop_blk)
{
	trace_xfs_da_node_remove(state->args);
	__xfs_da3_node_remove(state->args->trans, state->args->dp,
			state->args->geo, drop_blk);
}

/*
 * Wrapper function of remove an entry from node, export for external use.
 */
void
xfs_da3_node_entry_remove(
	struct xfs_trans	*tp,
	struct xfs_inode	*dp,
	struct xfs_buf		*bp,
	int			index)
{
	struct xfs_da_state_blk blk;

	memset(&blk, 0, sizeof(blk));
	blk.index = index;
	blk.bp = bp;

	__xfs_da3_node_remove(tp, dp, dp->i_mount->m_attr_geo, &blk);
}

/*
 * Unbalance the elements between two intermediate nodes,
 * move all Btree elements from one node into another.
+2 −0
Original line number Diff line number Diff line
@@ -212,6 +212,8 @@ int xfs_da_reada_buf(struct xfs_inode *dp, xfs_dablk_t bno,
		const struct xfs_buf_ops *ops);
int	xfs_da_shrink_inode(xfs_da_args_t *args, xfs_dablk_t dead_blkno,
					  struct xfs_buf *dead_buf);
void	xfs_da3_node_entry_remove(struct xfs_trans *tp, struct xfs_inode *dp,
		struct xfs_buf *bp, int index);

uint xfs_da_hashname(const uint8_t *name_string, int name_length);
enum xfs_dacmp xfs_da_compname(struct xfs_da_args *args,
+51 −43
Original line number Diff line number Diff line
@@ -139,7 +139,7 @@ xfs_attr3_node_inactive(
	xfs_daddr_t		parent_blkno, child_blkno;
	struct xfs_buf		*child_bp;
	struct xfs_da3_icnode_hdr ichdr;
	int			error, i;
	int			error;

	/*
	 * Since this code is recursive (gasp!) we must protect ourselves.
@@ -165,7 +165,7 @@ xfs_attr3_node_inactive(
	 * over the leaves removing all of them.  If this is higher up
	 * in the tree, recurse downward.
	 */
	for (i = 0; i < ichdr.count; i++) {
	while (ichdr.count > 0) {
		/*
		 * Read the subsidiary block to see what we have to work with.
		 * Don't do this in a transaction.  This is a depth-first
@@ -215,23 +215,25 @@ xfs_attr3_node_inactive(
		xfs_trans_binval(*trans, child_bp);
		child_bp = NULL;

		/*
		 * If we're not done, re-read the parent to get the next
		 * child block number.
		 */
		if (i + 1 < ichdr.count) {
			struct xfs_da3_icnode_hdr phdr;

		error = xfs_da3_node_read_mapped(*trans, dp,
				parent_blkno, &bp, XFS_ATTR_FORK);
		if (error)
			return error;
			xfs_da3_node_hdr_from_disk(dp->i_mount, &phdr,
						  bp->b_addr);
			child_fsb = be32_to_cpu(phdr.btree[i + 1].before);
			xfs_trans_brelse(*trans, bp);

		/*
		 * Remove entry form parent node, prevents being indexed to.
		 */
		xfs_da3_node_entry_remove(*trans, dp, bp, 0);

		xfs_da3_node_hdr_from_disk(dp->i_mount, &ichdr, bp->b_addr);
		bp = NULL;
		}

		if (ichdr.count > 0) {
			/*
			 * If we're not done, get the next child block number.
			 */
			child_fsb = be32_to_cpu(ichdr.btree[0].before);

			/*
			 * Atomically commit the whole invalidate stuff.
			 */
@@ -239,6 +241,7 @@ xfs_attr3_node_inactive(
			if (error)
				return  error;
		}
	}

	return 0;
}
@@ -254,10 +257,8 @@ xfs_attr3_root_inactive(
	struct xfs_trans	**trans,
	struct xfs_inode	*dp)
{
	struct xfs_mount	*mp = dp->i_mount;
	struct xfs_da_blkinfo	*info;
	struct xfs_buf		*bp;
	xfs_daddr_t		blkno;
	int			error;

	/*
@@ -269,7 +270,6 @@ xfs_attr3_root_inactive(
	error = xfs_da3_node_read(*trans, dp, 0, &bp, XFS_ATTR_FORK);
	if (error)
		return error;
	blkno = bp->b_bn;

	/*
	 * Invalidate the tree, even if the "tree" is only a single leaf block.
@@ -280,6 +280,16 @@ xfs_attr3_root_inactive(
	case cpu_to_be16(XFS_DA_NODE_MAGIC):
	case cpu_to_be16(XFS_DA3_NODE_MAGIC):
		error = xfs_attr3_node_inactive(trans, dp, bp, 1);
		if (error)
			return error;

		/*
		 * Empty root node blocks are not allowed, convert it to leaf.
		 */
		error = xfs_attr3_leaf_init(*trans, dp, 0);
		if (error)
			return error;
		error = xfs_trans_roll_inode(trans, dp);
		break;
	case cpu_to_be16(XFS_ATTR_LEAF_MAGIC):
	case cpu_to_be16(XFS_ATTR3_LEAF_MAGIC):
@@ -291,26 +301,6 @@ xfs_attr3_root_inactive(
		xfs_trans_brelse(*trans, bp);
		break;
	}
	if (error)
		return error;

	/*
	 * Invalidate the incore copy of the root block.
	 */
	error = xfs_trans_get_buf(*trans, mp->m_ddev_targp, blkno,
			XFS_FSB_TO_BB(mp, mp->m_attr_geo->fsbcount), 0, &bp);
	if (error)
		return error;
	error = bp->b_error;
	if (error) {
		xfs_trans_brelse(*trans, bp);
		return error;
	}
	xfs_trans_binval(*trans, bp);	/* remove from cache */
	/*
	 * Commit the invalidate and start the next transaction.
	 */
	error = xfs_trans_roll_inode(trans, dp);

	return error;
}
@@ -329,6 +319,7 @@ xfs_attr_inactive(
{
	struct xfs_trans	*trans;
	struct xfs_mount	*mp;
	struct xfs_buf          *bp;
	int			lock_mode = XFS_ILOCK_SHARED;
	int			error = 0;

@@ -365,10 +356,27 @@ xfs_attr_inactive(
	 * removal below.
	 */
	if (dp->i_af.if_nextents > 0) {
		/*
		 * Invalidate and truncate all blocks but leave the root block.
		 */
		error = xfs_attr3_root_inactive(&trans, dp);
		if (error)
			goto out_shutdown;

		error = xfs_itruncate_extents(&trans, dp, XFS_ATTR_FORK,
				XFS_FSB_TO_B(mp, mp->m_attr_geo->fsbcount));
		if (error)
			goto out_cancel;

		/*
		 * Invalidate and truncate the root block.
		 */
		error = xfs_da_get_buf(trans, dp, 0, &bp, XFS_ATTR_FORK);
		if (error)
			goto out_cancel;

		xfs_trans_binval(trans, bp);

		error = xfs_itruncate_extents(&trans, dp, XFS_ATTR_FORK, 0);
		if (error)
			goto out_cancel;
Loading