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 12/13] xfs: move xfs_qm_vop_chown_reserve to xfs_trans_dquot.c
Date: Thu, 28 Jan 2021 13:23:30 -0500 [thread overview]
Message-ID: <20210128182330.GK2619139@bfoster> (raw)
In-Reply-To: <161181373258.1523592.242724679476042204.stgit@magnolia>
On Wed, Jan 27, 2021 at 10:02:12PM -0800, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
>
> Move xfs_qm_vop_chown_reserve to xfs_trans_dquot.c and rename it
> xfs_trans_reserve_quota_chown. This will enable us to share code with
> the other quota reservation helpers, which will be very useful in the
> next patchset when we implement retry loops. No functional changes
> here, we're just moving code.
>
> Signed-off-by: Darrick J. Wong <djwong@kernel.org>
> ---
Reviewed-by: Brian Foster <bfoster@redhat.com>
> fs/xfs/xfs_ioctl.c | 2 -
> fs/xfs/xfs_iops.c | 6 +--
> fs/xfs/xfs_qm.c | 93 ----------------------------------------------
> fs/xfs/xfs_quota.h | 14 +++++--
> fs/xfs/xfs_trans_dquot.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++
> 5 files changed, 107 insertions(+), 101 deletions(-)
>
>
> diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
> index 3fbd98f61ea5..e299fbd9ef13 100644
> --- a/fs/xfs/xfs_ioctl.c
> +++ b/fs/xfs/xfs_ioctl.c
> @@ -1470,7 +1470,7 @@ xfs_ioctl_setattr(
>
> if (XFS_IS_QUOTA_RUNNING(mp) && XFS_IS_PQUOTA_ON(mp) &&
> ip->i_d.di_projid != fa->fsx_projid) {
> - code = xfs_qm_vop_chown_reserve(tp, ip, NULL, NULL, pdqp,
> + code = xfs_trans_reserve_quota_chown(tp, ip, NULL, NULL, pdqp,
> capable(CAP_FOWNER) ? XFS_QMOPT_FORCE_RES : 0);
> if (code) /* out of quota */
> goto error_trans_cancel;
> diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
> index f1e21b6cfa48..cb68be87e0a4 100644
> --- a/fs/xfs/xfs_iops.c
> +++ b/fs/xfs/xfs_iops.c
> @@ -730,9 +730,9 @@ xfs_setattr_nonsize(
> ((XFS_IS_UQUOTA_ON(mp) && !uid_eq(iuid, uid)) ||
> (XFS_IS_GQUOTA_ON(mp) && !gid_eq(igid, gid)))) {
> ASSERT(tp);
> - error = xfs_qm_vop_chown_reserve(tp, ip, udqp, gdqp,
> - NULL, capable(CAP_FOWNER) ?
> - XFS_QMOPT_FORCE_RES : 0);
> + error = xfs_trans_reserve_quota_chown(tp, ip, udqp,
> + gdqp, NULL, capable(CAP_FOWNER) ?
> + XFS_QMOPT_FORCE_RES : 0);
> if (error) /* out of quota */
> goto out_cancel;
> }
> diff --git a/fs/xfs/xfs_qm.c b/fs/xfs/xfs_qm.c
> index c134eb4aeaa8..6c2a9fa78e7c 100644
> --- a/fs/xfs/xfs_qm.c
> +++ b/fs/xfs/xfs_qm.c
> @@ -1794,99 +1794,6 @@ xfs_qm_vop_chown(
> return prevdq;
> }
>
> -/*
> - * Quota reservations for setattr(AT_UID|AT_GID|AT_PROJID).
> - */
> -int
> -xfs_qm_vop_chown_reserve(
> - struct xfs_trans *tp,
> - struct xfs_inode *ip,
> - struct xfs_dquot *udqp,
> - struct xfs_dquot *gdqp,
> - struct xfs_dquot *pdqp,
> - uint flags)
> -{
> - struct xfs_mount *mp = ip->i_mount;
> - uint64_t delblks;
> - unsigned int blkflags;
> - struct xfs_dquot *udq_unres = NULL;
> - struct xfs_dquot *gdq_unres = NULL;
> - struct xfs_dquot *pdq_unres = NULL;
> - struct xfs_dquot *udq_delblks = NULL;
> - struct xfs_dquot *gdq_delblks = NULL;
> - struct xfs_dquot *pdq_delblks = NULL;
> - int error;
> -
> -
> - ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL|XFS_ILOCK_SHARED));
> - ASSERT(XFS_IS_QUOTA_RUNNING(mp));
> -
> - delblks = ip->i_delayed_blks;
> - blkflags = XFS_IS_REALTIME_INODE(ip) ?
> - XFS_QMOPT_RES_RTBLKS : XFS_QMOPT_RES_REGBLKS;
> -
> - if (XFS_IS_UQUOTA_ON(mp) && udqp &&
> - i_uid_read(VFS_I(ip)) != udqp->q_id) {
> - udq_delblks = udqp;
> - /*
> - * If there are delayed allocation blocks, then we have to
> - * unreserve those from the old dquot, and add them to the
> - * new dquot.
> - */
> - if (delblks) {
> - ASSERT(ip->i_udquot);
> - udq_unres = ip->i_udquot;
> - }
> - }
> - if (XFS_IS_GQUOTA_ON(ip->i_mount) && gdqp &&
> - i_gid_read(VFS_I(ip)) != gdqp->q_id) {
> - gdq_delblks = gdqp;
> - if (delblks) {
> - ASSERT(ip->i_gdquot);
> - gdq_unres = ip->i_gdquot;
> - }
> - }
> -
> - if (XFS_IS_PQUOTA_ON(ip->i_mount) && pdqp &&
> - ip->i_d.di_projid != pdqp->q_id) {
> - pdq_delblks = pdqp;
> - if (delblks) {
> - ASSERT(ip->i_pdquot);
> - pdq_unres = ip->i_pdquot;
> - }
> - }
> -
> - error = xfs_trans_reserve_quota_bydquots(tp, ip->i_mount,
> - udq_delblks, gdq_delblks, pdq_delblks,
> - ip->i_d.di_nblocks, 1, flags | blkflags);
> - if (error)
> - return error;
> -
> - /*
> - * Do the delayed blks reservations/unreservations now. Since, these
> - * are done without the help of a transaction, if a reservation fails
> - * its previous reservations won't be automatically undone by trans
> - * code. So, we have to do it manually here.
> - */
> - if (delblks) {
> - /*
> - * Do the reservations first. Unreservation can't fail.
> - */
> - ASSERT(udq_delblks || gdq_delblks || pdq_delblks);
> - ASSERT(udq_unres || gdq_unres || pdq_unres);
> - error = xfs_trans_reserve_quota_bydquots(NULL, ip->i_mount,
> - udq_delblks, gdq_delblks, pdq_delblks,
> - (xfs_qcnt_t)delblks, 0, flags | blkflags);
> - if (error)
> - return error;
> - xfs_trans_reserve_quota_bydquots(NULL, ip->i_mount,
> - udq_unres, gdq_unres, pdq_unres,
> - -((xfs_qcnt_t)delblks), 0, blkflags);
> - }
> -
> - return 0;
> -}
> -
> int
> xfs_qm_vop_rename_dqattach(
> struct xfs_inode **i_tab)
> diff --git a/fs/xfs/xfs_quota.h b/fs/xfs/xfs_quota.h
> index efd04f84d9b4..d3876c71be8f 100644
> --- a/fs/xfs/xfs_quota.h
> +++ b/fs/xfs/xfs_quota.h
> @@ -98,9 +98,9 @@ extern void xfs_qm_vop_create_dqattach(struct xfs_trans *, struct xfs_inode *,
> extern int xfs_qm_vop_rename_dqattach(struct xfs_inode **);
> extern struct xfs_dquot *xfs_qm_vop_chown(struct xfs_trans *,
> struct xfs_inode *, struct xfs_dquot **, struct xfs_dquot *);
> -extern int xfs_qm_vop_chown_reserve(struct xfs_trans *, struct xfs_inode *,
> - struct xfs_dquot *, struct xfs_dquot *,
> - struct xfs_dquot *, uint);
> +int xfs_trans_reserve_quota_chown(struct xfs_trans *tp, struct xfs_inode *ip,
> + struct xfs_dquot *udqp, struct xfs_dquot *gdqp,
> + struct xfs_dquot *pdqp, unsigned int flags);
> extern int xfs_qm_dqattach(struct xfs_inode *);
> extern int xfs_qm_dqattach_locked(struct xfs_inode *ip, bool doalloc);
> extern void xfs_qm_dqdetach(struct xfs_inode *);
> @@ -162,7 +162,13 @@ xfs_trans_reserve_quota_icreate(struct xfs_trans *tp, struct xfs_dquot *udqp,
> #define xfs_qm_vop_create_dqattach(tp, ip, u, g, p)
> #define xfs_qm_vop_rename_dqattach(it) (0)
> #define xfs_qm_vop_chown(tp, ip, old, new) (NULL)
> -#define xfs_qm_vop_chown_reserve(tp, ip, u, g, p, fl) (0)
> +static inline int
> +xfs_trans_reserve_quota_chown(struct xfs_trans *tp, struct xfs_inode *ip,
> + struct xfs_dquot *udqp, struct xfs_dquot *gdqp,
> + struct xfs_dquot *pdqp, unsigned int flags)
> +{
> + return 0;
> +}
> #define xfs_qm_dqattach(ip) (0)
> #define xfs_qm_dqattach_locked(ip, fl) (0)
> #define xfs_qm_dqdetach(ip)
> diff --git a/fs/xfs/xfs_trans_dquot.c b/fs/xfs/xfs_trans_dquot.c
> index a1a72b7900c5..88146280a177 100644
> --- a/fs/xfs/xfs_trans_dquot.c
> +++ b/fs/xfs/xfs_trans_dquot.c
> @@ -836,6 +836,99 @@ xfs_trans_reserve_quota_icreate(
> dblocks, 1, XFS_QMOPT_RES_REGBLKS);
> }
>
> +/*
> + * Quota reservations for setattr(AT_UID|AT_GID|AT_PROJID).
> + */
> +int
> +xfs_trans_reserve_quota_chown(
> + struct xfs_trans *tp,
> + struct xfs_inode *ip,
> + struct xfs_dquot *udqp,
> + struct xfs_dquot *gdqp,
> + struct xfs_dquot *pdqp,
> + unsigned int flags)
> +{
> + struct xfs_mount *mp = ip->i_mount;
> + uint64_t delblks;
> + unsigned int blkflags;
> + struct xfs_dquot *udq_unres = NULL;
> + struct xfs_dquot *gdq_unres = NULL;
> + struct xfs_dquot *pdq_unres = NULL;
> + struct xfs_dquot *udq_delblks = NULL;
> + struct xfs_dquot *gdq_delblks = NULL;
> + struct xfs_dquot *pdq_delblks = NULL;
> + int error;
> +
> +
> + ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL|XFS_ILOCK_SHARED));
> + ASSERT(XFS_IS_QUOTA_RUNNING(mp));
> +
> + delblks = ip->i_delayed_blks;
> + blkflags = XFS_IS_REALTIME_INODE(ip) ?
> + XFS_QMOPT_RES_RTBLKS : XFS_QMOPT_RES_REGBLKS;
> +
> + if (XFS_IS_UQUOTA_ON(mp) && udqp &&
> + i_uid_read(VFS_I(ip)) != udqp->q_id) {
> + udq_delblks = udqp;
> + /*
> + * If there are delayed allocation blocks, then we have to
> + * unreserve those from the old dquot, and add them to the
> + * new dquot.
> + */
> + if (delblks) {
> + ASSERT(ip->i_udquot);
> + udq_unres = ip->i_udquot;
> + }
> + }
> + if (XFS_IS_GQUOTA_ON(ip->i_mount) && gdqp &&
> + i_gid_read(VFS_I(ip)) != gdqp->q_id) {
> + gdq_delblks = gdqp;
> + if (delblks) {
> + ASSERT(ip->i_gdquot);
> + gdq_unres = ip->i_gdquot;
> + }
> + }
> +
> + if (XFS_IS_PQUOTA_ON(ip->i_mount) && pdqp &&
> + ip->i_d.di_projid != pdqp->q_id) {
> + pdq_delblks = pdqp;
> + if (delblks) {
> + ASSERT(ip->i_pdquot);
> + pdq_unres = ip->i_pdquot;
> + }
> + }
> +
> + error = xfs_trans_reserve_quota_bydquots(tp, ip->i_mount,
> + udq_delblks, gdq_delblks, pdq_delblks,
> + ip->i_d.di_nblocks, 1, flags | blkflags);
> + if (error)
> + return error;
> +
> + /*
> + * Do the delayed blks reservations/unreservations now. Since, these
> + * are done without the help of a transaction, if a reservation fails
> + * its previous reservations won't be automatically undone by trans
> + * code. So, we have to do it manually here.
> + */
> + if (delblks) {
> + /*
> + * Do the reservations first. Unreservation can't fail.
> + */
> + ASSERT(udq_delblks || gdq_delblks || pdq_delblks);
> + ASSERT(udq_unres || gdq_unres || pdq_unres);
> + error = xfs_trans_reserve_quota_bydquots(NULL, ip->i_mount,
> + udq_delblks, gdq_delblks, pdq_delblks,
> + (xfs_qcnt_t)delblks, 0, flags | blkflags);
> + if (error)
> + return error;
> + xfs_trans_reserve_quota_bydquots(NULL, ip->i_mount,
> + udq_unres, gdq_unres, pdq_unres,
> + -((xfs_qcnt_t)delblks), 0, blkflags);
> + }
> +
> + return 0;
> +}
> +
> /*
> * This routine is called to allocate a quotaoff log item.
> */
>
next prev parent reply other threads:[~2021-01-28 18:27 UTC|newest]
Thread overview: 42+ 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
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 [this message]
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 12/13] xfs: move xfs_qm_vop_chown_reserve to xfs_trans_dquot.c Darrick J. Wong
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=20210128182330.GK2619139@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