diff mbox series

[14/34] xfs: make the xfs_dir3_icfree_hdr available to xfs_dir2_node_addname_int

Message ID 20191101220719.29100-15-hch@lst.de (mailing list archive)
State Superseded, archived
Headers show
Series [01/34] xfs: move incore structures out of xfs_da_format.h | expand

Commit Message

Christoph Hellwig Nov. 1, 2019, 10:06 p.m. UTC
Return the xfs_dir3_icfree_hdr used by the helpers called from
xfs_dir2_node_addname_int to the main function to prepare for the
next round of changes.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/xfs/libxfs/xfs_dir2_node.c | 42 +++++++++++++++++------------------
 1 file changed, 20 insertions(+), 22 deletions(-)

Comments

Darrick J. Wong Nov. 4, 2019, 8:25 p.m. UTC | #1
On Fri, Nov 01, 2019 at 03:06:59PM -0700, Christoph Hellwig wrote:
> Return the xfs_dir3_icfree_hdr used by the helpers called from
> xfs_dir2_node_addname_int to the main function to prepare for the
> next round of changes.

How does this help?  Is this purely to reduce stack usage?  Or will we
use this later to skip some xfs_dir2_free_hdr_from_disk calls?

--D

> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>  fs/xfs/libxfs/xfs_dir2_node.c | 42 +++++++++++++++++------------------
>  1 file changed, 20 insertions(+), 22 deletions(-)
> 
> diff --git a/fs/xfs/libxfs/xfs_dir2_node.c b/fs/xfs/libxfs/xfs_dir2_node.c
> index 26032eba1e32..d400243c9556 100644
> --- a/fs/xfs/libxfs/xfs_dir2_node.c
> +++ b/fs/xfs/libxfs/xfs_dir2_node.c
> @@ -1660,14 +1660,13 @@ xfs_dir2_node_add_datablk(
>  	xfs_dir2_db_t		*dbno,
>  	struct xfs_buf		**dbpp,
>  	struct xfs_buf		**fbpp,
> +	struct xfs_dir3_icfree_hdr *hdr,
>  	int			*findex)
>  {
>  	struct xfs_inode	*dp = args->dp;
>  	struct xfs_trans	*tp = args->trans;
>  	struct xfs_mount	*mp = dp->i_mount;
> -	struct xfs_dir3_icfree_hdr freehdr;
>  	struct xfs_dir2_data_free *bf;
> -	struct xfs_dir2_data_hdr *hdr;
>  	struct xfs_dir2_free	*free = NULL;
>  	xfs_dir2_db_t		fbno;
>  	struct xfs_buf		*fbp;
> @@ -1730,25 +1729,25 @@ xfs_dir2_node_add_datablk(
>  			return error;
>  		free = fbp->b_addr;
>  		bests = dp->d_ops->free_bests_p(free);
> -		xfs_dir2_free_hdr_from_disk(mp, &freehdr, free);
> +		xfs_dir2_free_hdr_from_disk(mp, hdr, free);
>  
>  		/* Remember the first slot as our empty slot. */
> -		freehdr.firstdb = (fbno - xfs_dir2_byte_to_db(args->geo,
> +		hdr->firstdb = (fbno - xfs_dir2_byte_to_db(args->geo,
>  							XFS_DIR2_FREE_OFFSET)) *
>  				dp->d_ops->free_max_bests(args->geo);
>  	} else {
>  		free = fbp->b_addr;
>  		bests = dp->d_ops->free_bests_p(free);
> -		xfs_dir2_free_hdr_from_disk(mp, &freehdr, free);
> +		xfs_dir2_free_hdr_from_disk(mp, hdr, free);
>  	}
>  
>  	/* Set the freespace block index from the data block number. */
>  	*findex = dp->d_ops->db_to_fdindex(args->geo, *dbno);
>  
>  	/* Extend the freespace table if the new data block is off the end. */
> -	if (*findex >= freehdr.nvalid) {
> +	if (*findex >= hdr->nvalid) {
>  		ASSERT(*findex < dp->d_ops->free_max_bests(args->geo));
> -		freehdr.nvalid = *findex + 1;
> +		hdr->nvalid = *findex + 1;
>  		bests[*findex] = cpu_to_be16(NULLDATAOFF);
>  	}
>  
> @@ -1757,14 +1756,13 @@ xfs_dir2_node_add_datablk(
>  	 * true) then update the header.
>  	 */
>  	if (bests[*findex] == cpu_to_be16(NULLDATAOFF)) {
> -		freehdr.nused++;
> -		xfs_dir2_free_hdr_to_disk(mp, fbp->b_addr, &freehdr);
> +		hdr->nused++;
> +		xfs_dir2_free_hdr_to_disk(mp, fbp->b_addr, hdr);
>  		xfs_dir2_free_log_header(args, fbp);
>  	}
>  
>  	/* Update the freespace value for the new block in the table. */
> -	hdr = dbp->b_addr;
> -	bf = dp->d_ops->data_bestfree_p(hdr);
> +	bf = dp->d_ops->data_bestfree_p(dbp->b_addr);
>  	bests[*findex] = bf[0].length;
>  
>  	*dbpp = dbp;
> @@ -1778,10 +1776,10 @@ xfs_dir2_node_find_freeblk(
>  	struct xfs_da_state_blk	*fblk,
>  	xfs_dir2_db_t		*dbnop,
>  	struct xfs_buf		**fbpp,
> +	struct xfs_dir3_icfree_hdr *hdr,
>  	int			*findexp,
>  	int			length)
>  {
> -	struct xfs_dir3_icfree_hdr freehdr;
>  	struct xfs_dir2_free	*free = NULL;
>  	struct xfs_inode	*dp = args->dp;
>  	struct xfs_trans	*tp = args->trans;
> @@ -1808,13 +1806,12 @@ xfs_dir2_node_find_freeblk(
>  		if (findex >= 0) {
>  			/* caller already found the freespace for us. */
>  			bests = dp->d_ops->free_bests_p(free);
> -			xfs_dir2_free_hdr_from_disk(dp->i_mount, &freehdr,
> -						    free);
> +			xfs_dir2_free_hdr_from_disk(dp->i_mount, hdr, free);
>  
> -			ASSERT(findex < freehdr.nvalid);
> +			ASSERT(findex < hdr->nvalid);
>  			ASSERT(be16_to_cpu(bests[findex]) != NULLDATAOFF);
>  			ASSERT(be16_to_cpu(bests[findex]) >= length);
> -			dbno = freehdr.firstdb + findex;
> +			dbno = hdr->firstdb + findex;
>  			goto found_block;
>  		}
>  
> @@ -1858,13 +1855,13 @@ xfs_dir2_node_find_freeblk(
>  
>  		free = fbp->b_addr;
>  		bests = dp->d_ops->free_bests_p(free);
> -		xfs_dir2_free_hdr_from_disk(dp->i_mount, &freehdr, free);
> +		xfs_dir2_free_hdr_from_disk(dp->i_mount, hdr, free);
>  
>  		/* Scan the free entry array for a large enough free space. */
> -		for (findex = freehdr.nvalid - 1; findex >= 0; findex--) {
> +		for (findex = hdr->nvalid - 1; findex >= 0; findex--) {
>  			if (be16_to_cpu(bests[findex]) != NULLDATAOFF &&
>  			    be16_to_cpu(bests[findex]) >= length) {
> -				dbno = freehdr.firstdb + findex;
> +				dbno = hdr->firstdb + findex;
>  				goto found_block;
>  			}
>  		}
> @@ -1898,6 +1895,7 @@ xfs_dir2_node_addname_int(
>  	struct xfs_dir2_free	*free = NULL;	/* freespace block structure */
>  	struct xfs_trans	*tp = args->trans;
>  	struct xfs_inode	*dp = args->dp;
> +	struct xfs_dir3_icfree_hdr freehdr;
>  	struct xfs_buf		*dbp;		/* data block buffer */
>  	struct xfs_buf		*fbp;		/* freespace buffer */
>  	xfs_dir2_data_aoff_t	aoff;
> @@ -1912,8 +1910,8 @@ xfs_dir2_node_addname_int(
>  	__be16			*bests;
>  
>  	length = dp->d_ops->data_entsize(args->namelen);
> -	error = xfs_dir2_node_find_freeblk(args, fblk, &dbno, &fbp, &findex,
> -					   length);
> +	error = xfs_dir2_node_find_freeblk(args, fblk, &dbno, &fbp, &freehdr,
> +					   &findex, length);
>  	if (error)
>  		return error;
>  
> @@ -1935,7 +1933,7 @@ xfs_dir2_node_addname_int(
>  		/* we're going to have to log the free block index later */
>  		logfree = 1;
>  		error = xfs_dir2_node_add_datablk(args, fblk, &dbno, &dbp, &fbp,
> -						  &findex);
> +						  &freehdr, &findex);
>  	} else {
>  		/* Read the data block in. */
>  		error = xfs_dir3_data_read(tp, dp,
> -- 
> 2.20.1
>
Christoph Hellwig Nov. 5, 2019, 1:52 a.m. UTC | #2
On Mon, Nov 04, 2019 at 12:25:23PM -0800, Darrick J. Wong wrote:
> On Fri, Nov 01, 2019 at 03:06:59PM -0700, Christoph Hellwig wrote:
> > Return the xfs_dir3_icfree_hdr used by the helpers called from
> > xfs_dir2_node_addname_int to the main function to prepare for the
> > next round of changes.
> 
> How does this help?  Is this purely to reduce stack usage?  Or will we
> use this later to skip some xfs_dir2_free_hdr_from_disk calls?

The latter.
Darrick J. Wong Nov. 5, 2019, 1:59 a.m. UTC | #3
On Tue, Nov 05, 2019 at 02:52:54AM +0100, Christoph Hellwig wrote:
> On Mon, Nov 04, 2019 at 12:25:23PM -0800, Darrick J. Wong wrote:
> > On Fri, Nov 01, 2019 at 03:06:59PM -0700, Christoph Hellwig wrote:
> > > Return the xfs_dir3_icfree_hdr used by the helpers called from
> > > xfs_dir2_node_addname_int to the main function to prepare for the
> > > next round of changes.
> > 
> > How does this help?  Is this purely to reduce stack usage?  Or will we
> > use this later to skip some xfs_dir2_free_hdr_from_disk calls?
> 
> The latter.

Might be a good idea at least to hint at that in the commit message.

--D
diff mbox series

Patch

diff --git a/fs/xfs/libxfs/xfs_dir2_node.c b/fs/xfs/libxfs/xfs_dir2_node.c
index 26032eba1e32..d400243c9556 100644
--- a/fs/xfs/libxfs/xfs_dir2_node.c
+++ b/fs/xfs/libxfs/xfs_dir2_node.c
@@ -1660,14 +1660,13 @@  xfs_dir2_node_add_datablk(
 	xfs_dir2_db_t		*dbno,
 	struct xfs_buf		**dbpp,
 	struct xfs_buf		**fbpp,
+	struct xfs_dir3_icfree_hdr *hdr,
 	int			*findex)
 {
 	struct xfs_inode	*dp = args->dp;
 	struct xfs_trans	*tp = args->trans;
 	struct xfs_mount	*mp = dp->i_mount;
-	struct xfs_dir3_icfree_hdr freehdr;
 	struct xfs_dir2_data_free *bf;
-	struct xfs_dir2_data_hdr *hdr;
 	struct xfs_dir2_free	*free = NULL;
 	xfs_dir2_db_t		fbno;
 	struct xfs_buf		*fbp;
@@ -1730,25 +1729,25 @@  xfs_dir2_node_add_datablk(
 			return error;
 		free = fbp->b_addr;
 		bests = dp->d_ops->free_bests_p(free);
-		xfs_dir2_free_hdr_from_disk(mp, &freehdr, free);
+		xfs_dir2_free_hdr_from_disk(mp, hdr, free);
 
 		/* Remember the first slot as our empty slot. */
-		freehdr.firstdb = (fbno - xfs_dir2_byte_to_db(args->geo,
+		hdr->firstdb = (fbno - xfs_dir2_byte_to_db(args->geo,
 							XFS_DIR2_FREE_OFFSET)) *
 				dp->d_ops->free_max_bests(args->geo);
 	} else {
 		free = fbp->b_addr;
 		bests = dp->d_ops->free_bests_p(free);
-		xfs_dir2_free_hdr_from_disk(mp, &freehdr, free);
+		xfs_dir2_free_hdr_from_disk(mp, hdr, free);
 	}
 
 	/* Set the freespace block index from the data block number. */
 	*findex = dp->d_ops->db_to_fdindex(args->geo, *dbno);
 
 	/* Extend the freespace table if the new data block is off the end. */
-	if (*findex >= freehdr.nvalid) {
+	if (*findex >= hdr->nvalid) {
 		ASSERT(*findex < dp->d_ops->free_max_bests(args->geo));
-		freehdr.nvalid = *findex + 1;
+		hdr->nvalid = *findex + 1;
 		bests[*findex] = cpu_to_be16(NULLDATAOFF);
 	}
 
@@ -1757,14 +1756,13 @@  xfs_dir2_node_add_datablk(
 	 * true) then update the header.
 	 */
 	if (bests[*findex] == cpu_to_be16(NULLDATAOFF)) {
-		freehdr.nused++;
-		xfs_dir2_free_hdr_to_disk(mp, fbp->b_addr, &freehdr);
+		hdr->nused++;
+		xfs_dir2_free_hdr_to_disk(mp, fbp->b_addr, hdr);
 		xfs_dir2_free_log_header(args, fbp);
 	}
 
 	/* Update the freespace value for the new block in the table. */
-	hdr = dbp->b_addr;
-	bf = dp->d_ops->data_bestfree_p(hdr);
+	bf = dp->d_ops->data_bestfree_p(dbp->b_addr);
 	bests[*findex] = bf[0].length;
 
 	*dbpp = dbp;
@@ -1778,10 +1776,10 @@  xfs_dir2_node_find_freeblk(
 	struct xfs_da_state_blk	*fblk,
 	xfs_dir2_db_t		*dbnop,
 	struct xfs_buf		**fbpp,
+	struct xfs_dir3_icfree_hdr *hdr,
 	int			*findexp,
 	int			length)
 {
-	struct xfs_dir3_icfree_hdr freehdr;
 	struct xfs_dir2_free	*free = NULL;
 	struct xfs_inode	*dp = args->dp;
 	struct xfs_trans	*tp = args->trans;
@@ -1808,13 +1806,12 @@  xfs_dir2_node_find_freeblk(
 		if (findex >= 0) {
 			/* caller already found the freespace for us. */
 			bests = dp->d_ops->free_bests_p(free);
-			xfs_dir2_free_hdr_from_disk(dp->i_mount, &freehdr,
-						    free);
+			xfs_dir2_free_hdr_from_disk(dp->i_mount, hdr, free);
 
-			ASSERT(findex < freehdr.nvalid);
+			ASSERT(findex < hdr->nvalid);
 			ASSERT(be16_to_cpu(bests[findex]) != NULLDATAOFF);
 			ASSERT(be16_to_cpu(bests[findex]) >= length);
-			dbno = freehdr.firstdb + findex;
+			dbno = hdr->firstdb + findex;
 			goto found_block;
 		}
 
@@ -1858,13 +1855,13 @@  xfs_dir2_node_find_freeblk(
 
 		free = fbp->b_addr;
 		bests = dp->d_ops->free_bests_p(free);
-		xfs_dir2_free_hdr_from_disk(dp->i_mount, &freehdr, free);
+		xfs_dir2_free_hdr_from_disk(dp->i_mount, hdr, free);
 
 		/* Scan the free entry array for a large enough free space. */
-		for (findex = freehdr.nvalid - 1; findex >= 0; findex--) {
+		for (findex = hdr->nvalid - 1; findex >= 0; findex--) {
 			if (be16_to_cpu(bests[findex]) != NULLDATAOFF &&
 			    be16_to_cpu(bests[findex]) >= length) {
-				dbno = freehdr.firstdb + findex;
+				dbno = hdr->firstdb + findex;
 				goto found_block;
 			}
 		}
@@ -1898,6 +1895,7 @@  xfs_dir2_node_addname_int(
 	struct xfs_dir2_free	*free = NULL;	/* freespace block structure */
 	struct xfs_trans	*tp = args->trans;
 	struct xfs_inode	*dp = args->dp;
+	struct xfs_dir3_icfree_hdr freehdr;
 	struct xfs_buf		*dbp;		/* data block buffer */
 	struct xfs_buf		*fbp;		/* freespace buffer */
 	xfs_dir2_data_aoff_t	aoff;
@@ -1912,8 +1910,8 @@  xfs_dir2_node_addname_int(
 	__be16			*bests;
 
 	length = dp->d_ops->data_entsize(args->namelen);
-	error = xfs_dir2_node_find_freeblk(args, fblk, &dbno, &fbp, &findex,
-					   length);
+	error = xfs_dir2_node_find_freeblk(args, fblk, &dbno, &fbp, &freehdr,
+					   &findex, length);
 	if (error)
 		return error;
 
@@ -1935,7 +1933,7 @@  xfs_dir2_node_addname_int(
 		/* we're going to have to log the free block index later */
 		logfree = 1;
 		error = xfs_dir2_node_add_datablk(args, fblk, &dbno, &dbp, &fbp,
-						  &findex);
+						  &freehdr, &findex);
 	} else {
 		/* Read the data block in. */
 		error = xfs_dir3_data_read(tp, dp,