public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Brian Foster <bfoster@redhat.com>
To: "Darrick J. Wong" <djwong@kernel.org>
Cc: linux-xfs@vger.kernel.org, hch@infradead.org, david@fromorbit.com
Subject: Re: [PATCH 11/13] xfs: refactor inode creation transaction/inode/quota allocation idiom
Date: Thu, 28 Jan 2021 13:23:23 -0500	[thread overview]
Message-ID: <20210128182323.GJ2619139@bfoster> (raw)
In-Reply-To: <161181372686.1523592.6379270446924577363.stgit@magnolia>

On Wed, Jan 27, 2021 at 10:02:06PM -0800, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
> 
> For file creation, create a new helper xfs_trans_alloc_icreate that
> allocates a transaction and reserves the appropriate amount of quota
> against that transction.  Replace all the open-coded idioms with a
> single call to this helper so that we can contain the retry loops in the
> next patchset.
> 
> Signed-off-by: Darrick J. Wong <djwong@kernel.org>
> ---

Reviewed-by: Brian Foster <bfoster@redhat.com>

>  fs/xfs/xfs_inode.c   |   28 ++++++++++------------------
>  fs/xfs/xfs_symlink.c |   14 ++++----------
>  fs/xfs/xfs_trans.c   |   33 +++++++++++++++++++++++++++++++++
>  fs/xfs/xfs_trans.h   |    6 ++++++
>  4 files changed, 53 insertions(+), 28 deletions(-)
> 
> 
> diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c
> index 4bbd2fb628f7..636ac13b1df2 100644
> --- a/fs/xfs/xfs_inode.c
> +++ b/fs/xfs/xfs_inode.c
> @@ -1022,25 +1022,20 @@ xfs_create(
>  	 * the case we'll drop the one we have and get a more
>  	 * appropriate transaction later.
>  	 */
> -	error = xfs_trans_alloc(mp, tres, resblks, 0, 0, &tp);
> +	error = xfs_trans_alloc_icreate(mp, tres, udqp, gdqp, pdqp, resblks,
> +			&tp);
>  	if (error == -ENOSPC) {
>  		/* flush outstanding delalloc blocks and retry */
>  		xfs_flush_inodes(mp);
> -		error = xfs_trans_alloc(mp, tres, resblks, 0, 0, &tp);
> +		error = xfs_trans_alloc_icreate(mp, tres, udqp, gdqp, pdqp,
> +				resblks, &tp);
>  	}
>  	if (error)
> -		goto out_release_inode;
> +		goto out_release_dquots;
>  
>  	xfs_ilock(dp, XFS_ILOCK_EXCL | XFS_ILOCK_PARENT);
>  	unlock_dp_on_error = true;
>  
> -	/*
> -	 * Reserve disk quota and the inode.
> -	 */
> -	error = xfs_trans_reserve_quota_icreate(tp, udqp, gdqp, pdqp, resblks);
> -	if (error)
> -		goto out_trans_cancel;
> -
>  	error = xfs_iext_count_may_overflow(dp, XFS_DATA_FORK,
>  			XFS_IEXT_DIR_MANIP_CNT(mp));
>  	if (error)
> @@ -1120,7 +1115,7 @@ xfs_create(
>  		xfs_finish_inode_setup(ip);
>  		xfs_irele(ip);
>  	}
> -
> + out_release_dquots:
>  	xfs_qm_dqrele(udqp);
>  	xfs_qm_dqrele(gdqp);
>  	xfs_qm_dqrele(pdqp);
> @@ -1164,13 +1159,10 @@ xfs_create_tmpfile(
>  	resblks = XFS_IALLOC_SPACE_RES(mp);
>  	tres = &M_RES(mp)->tr_create_tmpfile;
>  
> -	error = xfs_trans_alloc(mp, tres, resblks, 0, 0, &tp);
> +	error = xfs_trans_alloc_icreate(mp, tres, udqp, gdqp, pdqp, resblks,
> +			&tp);
>  	if (error)
> -		goto out_release_inode;
> -
> -	error = xfs_trans_reserve_quota_icreate(tp, udqp, gdqp, pdqp, resblks);
> -	if (error)
> -		goto out_trans_cancel;
> +		goto out_release_dquots;
>  
>  	error = xfs_dir_ialloc(&tp, dp, mode, 0, 0, prid, &ip);
>  	if (error)
> @@ -1213,7 +1205,7 @@ xfs_create_tmpfile(
>  		xfs_finish_inode_setup(ip);
>  		xfs_irele(ip);
>  	}
> -
> + out_release_dquots:
>  	xfs_qm_dqrele(udqp);
>  	xfs_qm_dqrele(gdqp);
>  	xfs_qm_dqrele(pdqp);
> diff --git a/fs/xfs/xfs_symlink.c b/fs/xfs/xfs_symlink.c
> index d5dee8f409b2..8565663b16cd 100644
> --- a/fs/xfs/xfs_symlink.c
> +++ b/fs/xfs/xfs_symlink.c
> @@ -197,9 +197,10 @@ xfs_symlink(
>  		fs_blocks = xfs_symlink_blocks(mp, pathlen);
>  	resblks = XFS_SYMLINK_SPACE_RES(mp, link_name->len, fs_blocks);
>  
> -	error = xfs_trans_alloc(mp, &M_RES(mp)->tr_symlink, resblks, 0, 0, &tp);
> +	error = xfs_trans_alloc_icreate(mp, &M_RES(mp)->tr_symlink, udqp, gdqp,
> +			pdqp, resblks, &tp);
>  	if (error)
> -		goto out_release_inode;
> +		goto out_release_dquots;
>  
>  	xfs_ilock(dp, XFS_ILOCK_EXCL | XFS_ILOCK_PARENT);
>  	unlock_dp_on_error = true;
> @@ -212,13 +213,6 @@ xfs_symlink(
>  		goto out_trans_cancel;
>  	}
>  
> -	/*
> -	 * Reserve disk quota : blocks and inode.
> -	 */
> -	error = xfs_trans_reserve_quota_icreate(tp, udqp, gdqp, pdqp, resblks);
> -	if (error)
> -		goto out_trans_cancel;
> -
>  	error = xfs_iext_count_may_overflow(dp, XFS_DATA_FORK,
>  			XFS_IEXT_DIR_MANIP_CNT(mp));
>  	if (error)
> @@ -347,7 +341,7 @@ xfs_symlink(
>  		xfs_finish_inode_setup(ip);
>  		xfs_irele(ip);
>  	}
> -
> +out_release_dquots:
>  	xfs_qm_dqrele(udqp);
>  	xfs_qm_dqrele(gdqp);
>  	xfs_qm_dqrele(pdqp);
> diff --git a/fs/xfs/xfs_trans.c b/fs/xfs/xfs_trans.c
> index 151f274eee43..bfb8b2a1594f 100644
> --- a/fs/xfs/xfs_trans.c
> +++ b/fs/xfs/xfs_trans.c
> @@ -21,6 +21,8 @@
>  #include "xfs_error.h"
>  #include "xfs_defer.h"
>  #include "xfs_inode.h"
> +#include "xfs_dquot_item.h"
> +#include "xfs_dquot.h"
>  
>  kmem_zone_t	*xfs_trans_zone;
>  
> @@ -1074,3 +1076,34 @@ xfs_trans_alloc_inode(
>  	xfs_iunlock(ip, XFS_ILOCK_EXCL);
>  	return error;
>  }
> +
> +/*
> + * Allocate an transaction in preparation for inode creation by reserving quota
> + * against the given dquots.
> + */
> +int
> +xfs_trans_alloc_icreate(
> +	struct xfs_mount	*mp,
> +	struct xfs_trans_res	*resv,
> +	struct xfs_dquot	*udqp,
> +	struct xfs_dquot	*gdqp,
> +	struct xfs_dquot	*pdqp,
> +	unsigned int		dblocks,
> +	struct xfs_trans	**tpp)
> +{
> +	struct xfs_trans	*tp;
> +	int			error;
> +
> +	error = xfs_trans_alloc(mp, resv, dblocks, 0, 0, &tp);
> +	if (error)
> +		return error;
> +
> +	error = xfs_trans_reserve_quota_icreate(tp, udqp, gdqp, pdqp, dblocks);
> +	if (error) {
> +		xfs_trans_cancel(tp);
> +		return error;
> +	}
> +
> +	*tpp = tp;
> +	return 0;
> +}
> diff --git a/fs/xfs/xfs_trans.h b/fs/xfs/xfs_trans.h
> index 52bbd7e6a552..04c132c55e9b 100644
> --- a/fs/xfs/xfs_trans.h
> +++ b/fs/xfs/xfs_trans.h
> @@ -268,8 +268,14 @@ xfs_trans_item_relog(
>  	return lip->li_ops->iop_relog(lip, tp);
>  }
>  
> +struct xfs_dquot;
> +
>  int xfs_trans_alloc_inode(struct xfs_inode *ip, struct xfs_trans_res *resv,
>  		unsigned int dblocks, unsigned int rblocks, bool force,
>  		struct xfs_trans **tpp);
> +int xfs_trans_alloc_icreate(struct xfs_mount *mp, struct xfs_trans_res *resv,
> +		struct xfs_dquot *udqp, struct xfs_dquot *gdqp,
> +		struct xfs_dquot *pdqp, unsigned int dblocks,
> +		struct xfs_trans **tpp);
>  
>  #endif	/* __XFS_TRANS_H__ */
> 


  parent reply	other threads:[~2021-01-28 18:27 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-28  6:01 [PATCHSET v3 00/13] xfs: minor cleanups of the quota functions Darrick J. Wong
2021-01-28  6:01 ` [PATCH 01/13] xfs: clean up quota reservation callsites Darrick J. Wong
2021-01-28  6:01 ` [PATCH 02/13] xfs: create convenience wrappers for incore quota block reservations Darrick J. Wong
2021-01-28 18:08   ` Brian Foster
2021-01-28  6:01 ` [PATCH 03/13] xfs: remove xfs_trans_unreserve_quota_nblks completely Darrick J. Wong
2021-01-28  9:46   ` Christoph Hellwig
2021-01-28 18:08   ` Brian Foster
2021-01-28  6:01 ` [PATCH 04/13] xfs: clean up icreate quota reservation calls Darrick J. Wong
2021-01-28 18:09   ` Brian Foster
2021-01-28  6:01 ` [PATCH 05/13] xfs: fix up build warnings when quotas are disabled Darrick J. Wong
2021-01-28 18:09   ` Brian Foster
2021-01-28 18:22     ` Darrick J. Wong
2021-01-28 18:23       ` Christoph Hellwig
2021-01-28  6:01 ` [PATCH 06/13] xfs: reserve data and rt quota at the same time Darrick J. Wong
2021-01-28  9:49   ` Christoph Hellwig
2021-01-28 18:01     ` Darrick J. Wong
2021-01-28 18:10   ` Brian Foster
2021-01-28 18:52     ` Darrick J. Wong
2021-01-28  6:01 ` [PATCH 07/13] xfs: refactor common transaction/inode/quota allocation idiom Darrick J. Wong
2021-01-28  9:50   ` Christoph Hellwig
2021-01-28 18:22   ` Brian Foster
2021-01-28  6:01 ` [PATCH 08/13] xfs: allow reservation of rtblocks with xfs_trans_alloc_inode Darrick J. Wong
2021-01-28  9:51   ` Christoph Hellwig
2021-01-28 18:22   ` Brian Foster
2021-01-28  6:01 ` [PATCH 09/13] xfs: refactor reflink functions to use xfs_trans_alloc_inode Darrick J. Wong
2021-01-28  9:53   ` Christoph Hellwig
2021-01-28 18:06     ` Darrick J. Wong
2021-01-28 18:23   ` Brian Foster
2021-01-28  6:02 ` [PATCH 10/13] xfs: try worst case space reservation upfront in xfs_reflink_remap_extent Darrick J. Wong
2021-01-28  9:55   ` Christoph Hellwig
2021-01-28 18:23   ` Brian Foster
2021-01-28  6:02 ` [PATCH 11/13] xfs: refactor inode creation transaction/inode/quota allocation idiom Darrick J. Wong
2021-01-28  9:57   ` Christoph Hellwig
2021-01-28 18:18     ` Darrick J. Wong
2021-01-28 18:23   ` Brian Foster [this message]
2021-01-28  6:02 ` [PATCH 12/13] xfs: move xfs_qm_vop_chown_reserve to xfs_trans_dquot.c Darrick J. Wong
2021-01-28  9:58   ` Christoph Hellwig
2021-01-28 18:23   ` Brian Foster
2021-01-28  6:02 ` [PATCH 13/13] xfs: clean up xfs_trans_reserve_quota_chown a bit Darrick J. Wong
2021-01-28 10:00   ` Christoph Hellwig
2021-01-28 18:23   ` Brian Foster
  -- strict thread matches above, loose matches on Subject: below --
2021-01-29  2:16 [PATCHSET v4 00/13] xfs: minor cleanups of the quota functions Darrick J. Wong
2021-01-29  2:17 ` [PATCH 11/13] xfs: refactor inode creation transaction/inode/quota allocation idiom Darrick J. Wong
2021-01-29  6:01   ` Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210128182323.GJ2619139@bfoster \
    --to=bfoster@redhat.com \
    --cc=david@fromorbit.com \
    --cc=djwong@kernel.org \
    --cc=hch@infradead.org \
    --cc=linux-xfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox