All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <djwong@kernel.org>
To: djwong@kernel.org
Cc: linux-xfs@vger.kernel.org, hch@infradead.org,
	david@fromorbit.com, bfoster@redhat.com
Subject: [PATCH 09/12] xfs: flush eof/cowblocks if we can't reserve quota for chown
Date: Thu, 28 Jan 2021 18:18:37 -0800	[thread overview]
Message-ID: <161188671741.1943978.420169006925452801.stgit@magnolia> (raw)
In-Reply-To: <161188666613.1943978.971196931920996596.stgit@magnolia>

From: Darrick J. Wong <djwong@kernel.org>

If a file user, group, or project change is unable to reserve enough
quota to handle the modification, try clearing whatever space the
filesystem might have been hanging onto in the hopes of speeding up the
filesystem.  The flushing behavior will become particularly important
when we add deferred inode inactivation because that will increase the
amount of space that isn't actively tied to user data.

Note that the retry loop is open-coded here because there are only two
places in the codebase where we ever change [ugp]id; and the setattr and
setxattr code is already tricky enough.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 fs/xfs/xfs_ioctl.c       |   10 +++++++++-
 fs/xfs/xfs_iops.c        |   11 ++++++++++-
 fs/xfs/xfs_quota.h       |    4 ++--
 fs/xfs/xfs_trans_dquot.c |   28 ++++++++++++++++++++++++----
 4 files changed, 45 insertions(+), 8 deletions(-)


diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
index 73cfee8007a8..e945ab5cfa55 100644
--- a/fs/xfs/xfs_ioctl.c
+++ b/fs/xfs/xfs_ioctl.c
@@ -1436,6 +1436,7 @@ xfs_ioctl_setattr(
 	struct xfs_trans	*tp;
 	struct xfs_dquot	*pdqp = NULL;
 	struct xfs_dquot	*olddquot = NULL;
+	unsigned int		quota_retry = 0;
 	int			code;
 
 	trace_xfs_ioctl_setattr(ip);
@@ -1462,6 +1463,7 @@ xfs_ioctl_setattr(
 
 	xfs_ioctl_setattr_prepare_dax(ip, fa);
 
+retry:
 	tp = xfs_ioctl_setattr_get_trans(ip);
 	if (IS_ERR(tp)) {
 		code = PTR_ERR(tp);
@@ -1471,9 +1473,15 @@ xfs_ioctl_setattr(
 	if (XFS_IS_QUOTA_RUNNING(mp) && XFS_IS_PQUOTA_ON(mp) &&
 	    ip->i_d.di_projid != fa->fsx_projid) {
 		code = xfs_trans_reserve_quota_chown(tp, ip, NULL, NULL, pdqp,
-				capable(CAP_FOWNER));
+				capable(CAP_FOWNER), &quota_retry);
 		if (code)	/* out of quota */
 			goto error_trans_cancel;
+		if (quota_retry) {
+			xfs_trans_cancel(tp);
+			xfs_iunlock(ip, XFS_ILOCK_EXCL);
+			xfs_blockgc_free_dquots(NULL, NULL, pdqp, 0);
+			goto retry;
+		}
 	}
 
 	xfs_fill_fsxattr(ip, false, &old_fa);
diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
index 51c877ce90bc..f5bb390b7373 100644
--- a/fs/xfs/xfs_iops.c
+++ b/fs/xfs/xfs_iops.c
@@ -660,6 +660,7 @@ xfs_setattr_nonsize(
 	kgid_t			gid = GLOBAL_ROOT_GID, igid = GLOBAL_ROOT_GID;
 	struct xfs_dquot	*udqp = NULL, *gdqp = NULL;
 	struct xfs_dquot	*olddquot1 = NULL, *olddquot2 = NULL;
+	unsigned int		quota_retry = 0;
 
 	ASSERT((mask & ATTR_SIZE) == 0);
 
@@ -700,6 +701,7 @@ xfs_setattr_nonsize(
 			return error;
 	}
 
+retry:
 	error = xfs_trans_alloc(mp, &M_RES(mp)->tr_ichange, 0, 0, 0, &tp);
 	if (error)
 		goto out_dqrele;
@@ -731,9 +733,16 @@ xfs_setattr_nonsize(
 		     (XFS_IS_GQUOTA_ON(mp) && !gid_eq(igid, gid)))) {
 			ASSERT(tp);
 			error = xfs_trans_reserve_quota_chown(tp, ip, udqp,
-					gdqp, NULL, capable(CAP_FOWNER));
+					gdqp, NULL, capable(CAP_FOWNER),
+					&quota_retry);
 			if (error)	/* out of quota */
 				goto out_cancel;
+			if (quota_retry) {
+				xfs_trans_cancel(tp);
+				xfs_iunlock(ip, XFS_ILOCK_EXCL);
+				xfs_blockgc_free_dquots(udqp, gdqp, NULL, 0);
+				goto retry;
+			}
 		}
 
 		/*
diff --git a/fs/xfs/xfs_quota.h b/fs/xfs/xfs_quota.h
index 4360d73a0e99..f1cdd6de56ea 100644
--- a/fs/xfs/xfs_quota.h
+++ b/fs/xfs/xfs_quota.h
@@ -101,7 +101,7 @@ extern struct xfs_dquot *xfs_qm_vop_chown(struct xfs_trans *,
 		struct xfs_inode *, struct xfs_dquot **, struct xfs_dquot *);
 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, bool force);
+		struct xfs_dquot *pdqp, bool force, unsigned int *retry);
 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 *);
@@ -167,7 +167,7 @@ xfs_trans_reserve_quota_icreate(struct xfs_trans *tp, struct xfs_dquot *udqp,
 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, bool force)
+		struct xfs_dquot *pdqp, bool force, unsigned int *retry)
 {
 	return 0;
 }
diff --git a/fs/xfs/xfs_trans_dquot.c b/fs/xfs/xfs_trans_dquot.c
index 00b40813f77d..086de621f431 100644
--- a/fs/xfs/xfs_trans_dquot.c
+++ b/fs/xfs/xfs_trans_dquot.c
@@ -907,7 +907,15 @@ xfs_trans_reserve_quota_icreate(
 }
 
 /*
- * Quota reservations for setattr(AT_UID|AT_GID|AT_PROJID).
+ * Chagnge quota reservations for setattr(AT_UID|AT_GID|AT_PROJID).  This
+ * doesn't change the actual usage, just the reservation.  The caller must hold
+ * ILOCK_EXCL on the inode.  If @retry is not a NULL pointer, the caller must
+ * ensure that *retry is set to zero before the first time this function is
+ * called.
+ *
+ * If the quota reservation fails because we hit a quota limit (and retry is
+ * not a NULL pointer, and *retry is zero), this function will set *retry to
+ * nonzero and return zero.
  */
 int
 xfs_trans_reserve_quota_chown(
@@ -916,7 +924,8 @@ xfs_trans_reserve_quota_chown(
 	struct xfs_dquot	*udqp,
 	struct xfs_dquot	*gdqp,
 	struct xfs_dquot	*pdqp,
-	bool			force)
+	bool			force,
+	unsigned int		*retry)
 {
 	struct xfs_mount	*mp = ip->i_mount;
 	struct xfs_dquot	*udq_unres = NULL;	/* old dquots */
@@ -976,7 +985,7 @@ xfs_trans_reserve_quota_chown(
 			gdq_delblks, pdq_delblks, ip->i_d.di_nblocks, 1,
 			qflags);
 	if (error)
-		return error;
+		goto err;
 
 	/*
 	 * Do the delayed blks reservations/unreservations now. Since, these
@@ -994,13 +1003,24 @@ xfs_trans_reserve_quota_chown(
 				udq_delblks, gdq_delblks, pdq_delblks,
 				(xfs_qcnt_t)delblks, 0, qflags);
 		if (error)
-			return error;
+			goto err;
 		xfs_trans_reserve_quota_bydquots(NULL, ip->i_mount, udq_unres,
 				gdq_unres, pdq_unres, -((xfs_qcnt_t)delblks),
 				0, qflags);
 	}
 
 	return 0;
+err:
+	/*
+	 * Handle all quota reservation failures in the same place because we
+	 * don't want reservation_success() to clear REGBLKS from the retry
+	 * flags after we _reserve_quota for the ondisk blocks but before we
+	 * _reserve_quota for the delalloc blocks.  If we were called with a
+	 * nonzero *retry, that means we failed to get the quota reservation
+	 * once before and do not want to schedule a retry on a second error.
+	 */
+	reservation_success(XFS_QMOPT_RES_REGBLKS, retry, &error);
+	return error;
 }
 
 /*


  parent reply	other threads:[~2021-01-29  2:19 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-29  2:17 [PATCHSET v6 00/12] xfs: try harder to reclaim space when we run out Darrick J. Wong
2021-01-29  2:17 ` [PATCH 01/12] xfs: trigger all block gc scans when low on quota space Darrick J. Wong
2021-01-29  2:17 ` [PATCH 02/12] xfs: don't stall cowblocks scan if we can't take locks Darrick J. Wong
2021-01-29  2:18 ` [PATCH 03/12] xfs: xfs_inode_free_quota_blocks should scan project quota Darrick J. Wong
2021-01-29  2:18 ` [PATCH 04/12] xfs: move and rename xfs_inode_free_quota_blocks to avoid conflicts Darrick J. Wong
2021-01-29  2:18 ` [PATCH 05/12] xfs: pass flags and return gc errors from xfs_blockgc_free_quota Darrick J. Wong
2021-01-29  2:18 ` [PATCH 06/12] xfs: try worst case space reservation upfront in xfs_reflink_remap_extent Darrick J. Wong
2021-01-29  2:18 ` [PATCH 07/12] xfs: flush eof/cowblocks if we can't reserve quota for file blocks Darrick J. Wong
     [not found]   ` <20210129160944.GE2665284@bfoster>
2021-01-29 17:47     ` Darrick J. Wong
2021-01-29  2:18 ` [PATCH 08/12] xfs: flush eof/cowblocks if we can't reserve quota for inode creation Darrick J. Wong
2021-01-29  2:18 ` Darrick J. Wong [this message]
2021-01-29  2:18 ` [PATCH 10/12] xfs: add a tracepoint for blockgc scans Darrick J. Wong
2021-01-29  2:18 ` [PATCH 11/12] xfs: refactor xfs_icache_free_{eof,cow}blocks call sites Darrick J. Wong
2021-01-29  2:18 ` [PATCH 12/12] xfs: flush speculative space allocations when we run out of space Darrick J. Wong
     [not found]   ` <20210129161047.GH2665284@bfoster>
2021-01-29 17:34     ` Darrick J. Wong
2021-02-01  2:05 [PATCHSET v7 00/12] xfs: try harder to reclaim space when we run out Darrick J. Wong
2021-02-01  2:06 ` [PATCH 09/12] xfs: flush eof/cowblocks if we can't reserve quota for chown Darrick J. Wong
2021-02-01 12:36   ` Christoph Hellwig
2021-02-01 19:12     ` Darrick J. Wong
2021-02-02 15:39   ` Brian Foster

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=161188671741.1943978.420169006925452801.stgit@magnolia \
    --to=djwong@kernel.org \
    --cc=bfoster@redhat.com \
    --cc=david@fromorbit.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.