diff mbox series

[02/16] xfs: remove an extra buffer allocation in xfs_attr_shortform_to_leaf

Message ID 20240430124926.1775355-3-hch@lst.de (mailing list archive)
State New
Headers show
Series [01/16] xfs: allow non-empty forks in xfs_bmap_local_to_extents_empty | expand

Commit Message

Christoph Hellwig April 30, 2024, 12:49 p.m. UTC
Make use of the new ability to call xfs_bmap_local_to_extents_empty on
a non-empty local fork to reuse the old inode fork data to build the leaf
block to replace the local temporary buffer.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/xfs/libxfs/xfs_attr_leaf.c | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)

Comments

Darrick J. Wong May 1, 2024, 9:11 p.m. UTC | #1
On Tue, Apr 30, 2024 at 02:49:12PM +0200, Christoph Hellwig wrote:
> Make use of the new ability to call xfs_bmap_local_to_extents_empty on
> a non-empty local fork to reuse the old inode fork data to build the leaf
> block to replace the local temporary buffer.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Makes sense,
Reviewed-by: Darrick J. Wong <djwong@kernel.org>

--D

> ---
>  fs/xfs/libxfs/xfs_attr_leaf.c | 14 +++-----------
>  1 file changed, 3 insertions(+), 11 deletions(-)
> 
> diff --git a/fs/xfs/libxfs/xfs_attr_leaf.c b/fs/xfs/libxfs/xfs_attr_leaf.c
> index b9e98950eb3d81..d9285614d7c21b 100644
> --- a/fs/xfs/libxfs/xfs_attr_leaf.c
> +++ b/fs/xfs/libxfs/xfs_attr_leaf.c
> @@ -942,24 +942,16 @@ xfs_attr_shortform_to_leaf(
>  	struct xfs_da_args		*args)
>  {
>  	struct xfs_inode		*dp = args->dp;
> -	struct xfs_ifork		*ifp = &dp->i_af;
> -	struct xfs_attr_sf_hdr		*sf = ifp->if_data;
> +	struct xfs_attr_sf_hdr		*sf;
>  	struct xfs_attr_sf_entry	*sfe;
> -	int				size = be16_to_cpu(sf->totsize);
>  	struct xfs_da_args		nargs;
> -	char				*tmpbuffer;
>  	int				error, i;
>  	xfs_dablk_t			blkno;
>  	struct xfs_buf			*bp;
>  
>  	trace_xfs_attr_sf_to_leaf(args);
>  
> -	tmpbuffer = kmalloc(size, GFP_KERNEL | __GFP_NOFAIL);
> -	memcpy(tmpbuffer, ifp->if_data, size);
> -	sf = (struct xfs_attr_sf_hdr *)tmpbuffer;
> -
> -	xfs_idata_realloc(dp, -size, XFS_ATTR_FORK);
> -	xfs_bmap_local_to_extents_empty(args->trans, dp, XFS_ATTR_FORK);
> +	sf = xfs_bmap_local_to_extents_empty(args->trans, dp, XFS_ATTR_FORK);
>  
>  	bp = NULL;
>  	error = xfs_da_grow_inode(args, &blkno);
> @@ -1003,7 +995,7 @@ xfs_attr_shortform_to_leaf(
>  	}
>  	error = 0;
>  out:
> -	kfree(tmpbuffer);
> +	kfree(sf);
>  	return error;
>  }
>  
> -- 
> 2.39.2
> 
>
diff mbox series

Patch

diff --git a/fs/xfs/libxfs/xfs_attr_leaf.c b/fs/xfs/libxfs/xfs_attr_leaf.c
index b9e98950eb3d81..d9285614d7c21b 100644
--- a/fs/xfs/libxfs/xfs_attr_leaf.c
+++ b/fs/xfs/libxfs/xfs_attr_leaf.c
@@ -942,24 +942,16 @@  xfs_attr_shortform_to_leaf(
 	struct xfs_da_args		*args)
 {
 	struct xfs_inode		*dp = args->dp;
-	struct xfs_ifork		*ifp = &dp->i_af;
-	struct xfs_attr_sf_hdr		*sf = ifp->if_data;
+	struct xfs_attr_sf_hdr		*sf;
 	struct xfs_attr_sf_entry	*sfe;
-	int				size = be16_to_cpu(sf->totsize);
 	struct xfs_da_args		nargs;
-	char				*tmpbuffer;
 	int				error, i;
 	xfs_dablk_t			blkno;
 	struct xfs_buf			*bp;
 
 	trace_xfs_attr_sf_to_leaf(args);
 
-	tmpbuffer = kmalloc(size, GFP_KERNEL | __GFP_NOFAIL);
-	memcpy(tmpbuffer, ifp->if_data, size);
-	sf = (struct xfs_attr_sf_hdr *)tmpbuffer;
-
-	xfs_idata_realloc(dp, -size, XFS_ATTR_FORK);
-	xfs_bmap_local_to_extents_empty(args->trans, dp, XFS_ATTR_FORK);
+	sf = xfs_bmap_local_to_extents_empty(args->trans, dp, XFS_ATTR_FORK);
 
 	bp = NULL;
 	error = xfs_da_grow_inode(args, &blkno);
@@ -1003,7 +995,7 @@  xfs_attr_shortform_to_leaf(
 	}
 	error = 0;
 out:
-	kfree(tmpbuffer);
+	kfree(sf);
 	return error;
 }