Linux-XFS Archive on lore.kernel.org
 help / color / Atom feed
* [PATCHSET 0/4] xfs: minor cleanups of the quota functions
@ 2021-01-18 22:11 Darrick J. Wong
  2021-01-18 22:11 ` [PATCH 1/4] xfs: clean up quota reservation callsites Darrick J. Wong
                   ` (3 more replies)
  0 siblings, 4 replies; 16+ messages in thread
From: Darrick J. Wong @ 2021-01-18 22:11 UTC (permalink / raw)
  To: djwong; +Cc: linux-xfs

Hi all,

This series reworks some of the internal quota APIs and cleans up some
of the function calls so that we have a clean(er) place to start the
space reclamation patchset.  There should be no behavioral changes in
this series.

If you're going to start using this mess, you probably ought to just
pull from my git trees, which are linked below.

This is an extraordinary way to destroy everything.  Enjoy!
Comments and questions are, as always, welcome.

--D

kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=quota-function-cleanups-5.12
---
 fs/xfs/libxfs/xfs_bmap.c |    9 +++------
 fs/xfs/xfs_bmap_util.c   |    4 ++--
 fs/xfs/xfs_inode.c       |    8 ++++----
 fs/xfs/xfs_quota.h       |   40 +++++++++++++++++++++++++++++++++++-----
 fs/xfs/xfs_reflink.c     |    3 +--
 fs/xfs/xfs_symlink.c     |    4 ++--
 fs/xfs/xfs_trans_dquot.c |   21 +++++++++++++++++++++
 7 files changed, 68 insertions(+), 21 deletions(-)


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH 1/4] xfs: clean up quota reservation callsites
  2021-01-18 22:11 [PATCHSET 0/4] xfs: minor cleanups of the quota functions Darrick J. Wong
@ 2021-01-18 22:11 ` Darrick J. Wong
  2021-01-19  6:35   ` Christoph Hellwig
  2021-01-18 22:11 ` [PATCH 2/4] xfs: clean up quota reservation wrappers Darrick J. Wong
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 16+ messages in thread
From: Darrick J. Wong @ 2021-01-18 22:11 UTC (permalink / raw)
  To: djwong; +Cc: linux-xfs

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

Convert a few xfs_trans_*reserve* callsites that are open-coding other
convenience functions.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 fs/xfs/libxfs/xfs_bmap.c |    3 +--
 fs/xfs/xfs_bmap_util.c   |    4 ++--
 fs/xfs/xfs_reflink.c     |    4 ++--
 3 files changed, 5 insertions(+), 6 deletions(-)


diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
index bc446418e227..21076ac2485a 100644
--- a/fs/xfs/libxfs/xfs_bmap.c
+++ b/fs/xfs/libxfs/xfs_bmap.c
@@ -4826,8 +4826,7 @@ xfs_bmap_del_extent_delay(
 	 * sb counters as we might have to borrow some blocks for the
 	 * indirect block accounting.
 	 */
-	error = xfs_trans_reserve_quota_nblks(NULL, ip,
-			-((long)del->br_blockcount), 0,
+	error = xfs_trans_unreserve_quota_nblks(NULL, ip, del->br_blockcount, 0,
 			isrt ? XFS_QMOPT_RES_RTBLKS : XFS_QMOPT_RES_REGBLKS);
 	if (error)
 		return error;
diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c
index 7371a7f7c652..671cb104861e 100644
--- a/fs/xfs/xfs_bmap_util.c
+++ b/fs/xfs/xfs_bmap_util.c
@@ -879,8 +879,8 @@ xfs_unmap_extent(
 	}
 
 	xfs_ilock(ip, XFS_ILOCK_EXCL);
-	error = xfs_trans_reserve_quota(tp, mp, ip->i_udquot, ip->i_gdquot,
-			ip->i_pdquot, resblks, 0, XFS_QMOPT_RES_REGBLKS);
+	error = xfs_trans_reserve_quota_nblks(tp, ip, resblks, 0,
+			XFS_QMOPT_RES_REGBLKS);
 	if (error)
 		goto out_trans_cancel;
 
diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c
index 6fa05fb78189..20321d03e31c 100644
--- a/fs/xfs/xfs_reflink.c
+++ b/fs/xfs/xfs_reflink.c
@@ -508,8 +508,8 @@ xfs_reflink_cancel_cow_blocks(
 			xfs_bmap_del_extent_cow(ip, &icur, &got, &del);
 
 			/* Remove the quota reservation */
-			error = xfs_trans_reserve_quota_nblks(NULL, ip,
-					-(long)del.br_blockcount, 0,
+			error = xfs_trans_unreserve_quota_nblks(NULL, ip,
+					del.br_blockcount, 0,
 					XFS_QMOPT_RES_REGBLKS);
 			if (error)
 				break;


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH 2/4] xfs: clean up quota reservation wrappers
  2021-01-18 22:11 [PATCHSET 0/4] xfs: minor cleanups of the quota functions Darrick J. Wong
  2021-01-18 22:11 ` [PATCH 1/4] xfs: clean up quota reservation callsites Darrick J. Wong
@ 2021-01-18 22:11 ` Darrick J. Wong
  2021-01-19  6:38   ` Christoph Hellwig
  2021-01-18 22:11 ` [PATCH 3/4] xfs: create convenience wrappers for incore quota block reservations Darrick J. Wong
  2021-01-18 22:11 ` [PATCH 4/4] xfs: clean up icreate quota reservation calls Darrick J. Wong
  3 siblings, 1 reply; 16+ messages in thread
From: Darrick J. Wong @ 2021-01-18 22:11 UTC (permalink / raw)
  To: djwong; +Cc: linux-xfs

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

Replace a couple of quota reservation macros with properly typechecked
static inline functions ahead of more restructuring in the next patches.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 fs/xfs/xfs_quota.h |    9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)


diff --git a/fs/xfs/xfs_quota.h b/fs/xfs/xfs_quota.h
index 5a62398940d0..bd28d17941e7 100644
--- a/fs/xfs/xfs_quota.h
+++ b/fs/xfs/xfs_quota.h
@@ -151,8 +151,13 @@ static inline int xfs_trans_reserve_quota_bydquots(struct xfs_trans *tp,
 #define xfs_qm_unmount_quotas(mp)
 #endif /* CONFIG_XFS_QUOTA */
 
-#define xfs_trans_unreserve_quota_nblks(tp, ip, nblks, ninos, flags) \
-	xfs_trans_reserve_quota_nblks(tp, ip, -(nblks), -(ninos), flags)
+static inline int
+xfs_trans_unreserve_quota_nblks(struct xfs_trans *tp, struct xfs_inode *ip,
+		int64_t nblks, long ninos, unsigned int flags)
+{
+	return xfs_trans_reserve_quota_nblks(tp, ip, -nblks, -ninos, flags);
+}
+
 #define xfs_trans_reserve_quota(tp, mp, ud, gd, pd, nb, ni, f) \
 	xfs_trans_reserve_quota_bydquots(tp, mp, ud, gd, pd, nb, ni, \
 				f | XFS_QMOPT_RES_REGBLKS)


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH 3/4] xfs: create convenience wrappers for incore quota block reservations
  2021-01-18 22:11 [PATCHSET 0/4] xfs: minor cleanups of the quota functions Darrick J. Wong
  2021-01-18 22:11 ` [PATCH 1/4] xfs: clean up quota reservation callsites Darrick J. Wong
  2021-01-18 22:11 ` [PATCH 2/4] xfs: clean up quota reservation wrappers Darrick J. Wong
@ 2021-01-18 22:11 ` Darrick J. Wong
  2021-01-19  6:44   ` Christoph Hellwig
  2021-01-20  4:33   ` [PATCH v2.1 " Darrick J. Wong
  2021-01-18 22:11 ` [PATCH 4/4] xfs: clean up icreate quota reservation calls Darrick J. Wong
  3 siblings, 2 replies; 16+ messages in thread
From: Darrick J. Wong @ 2021-01-18 22:11 UTC (permalink / raw)
  To: djwong; +Cc: linux-xfs

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

Create a couple of convenience wrappers for creating and deleting quota
block reservations against future changes.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 fs/xfs/libxfs/xfs_bmap.c |    8 +++-----
 fs/xfs/xfs_quota.h       |   19 +++++++++++++++++++
 fs/xfs/xfs_reflink.c     |    3 +--
 3 files changed, 23 insertions(+), 7 deletions(-)


diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
index 21076ac2485a..fa6b442eb75f 100644
--- a/fs/xfs/libxfs/xfs_bmap.c
+++ b/fs/xfs/libxfs/xfs_bmap.c
@@ -4001,8 +4001,7 @@ xfs_bmapi_reserve_delalloc(
 	 * blocks.  This number gets adjusted later.  We return if we haven't
 	 * allocated blocks already inside this loop.
 	 */
-	error = xfs_trans_reserve_quota_nblks(NULL, ip, (long)alen, 0,
-						XFS_QMOPT_RES_REGBLKS);
+	error = xfs_quota_reserve_blkres(ip, alen, XFS_QMOPT_RES_REGBLKS);
 	if (error)
 		return error;
 
@@ -4048,8 +4047,7 @@ xfs_bmapi_reserve_delalloc(
 	xfs_mod_fdblocks(mp, alen, false);
 out_unreserve_quota:
 	if (XFS_IS_QUOTA_ON(mp))
-		xfs_trans_unreserve_quota_nblks(NULL, ip, (long)alen, 0,
-						XFS_QMOPT_RES_REGBLKS);
+		xfs_quota_unreserve_blkres(ip, alen, XFS_QMOPT_RES_REGBLKS);
 	return error;
 }
 
@@ -4826,7 +4824,7 @@ xfs_bmap_del_extent_delay(
 	 * sb counters as we might have to borrow some blocks for the
 	 * indirect block accounting.
 	 */
-	error = xfs_trans_unreserve_quota_nblks(NULL, ip, del->br_blockcount, 0,
+	error = xfs_quota_unreserve_blkres(ip, del->br_blockcount,
 			isrt ? XFS_QMOPT_RES_RTBLKS : XFS_QMOPT_RES_REGBLKS);
 	if (error)
 		return error;
diff --git a/fs/xfs/xfs_quota.h b/fs/xfs/xfs_quota.h
index bd28d17941e7..b1411d25c9e5 100644
--- a/fs/xfs/xfs_quota.h
+++ b/fs/xfs/xfs_quota.h
@@ -136,6 +136,11 @@ static inline int xfs_trans_reserve_quota_bydquots(struct xfs_trans *tp,
 {
 	return 0;
 }
+static inline int xfs_quota_reserve_blkres(struct xfs_inode *ip,
+		int64_t nblks, unsigned int flags)
+{
+	return 0;
+}
 #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)
@@ -162,6 +167,20 @@ xfs_trans_unreserve_quota_nblks(struct xfs_trans *tp, struct xfs_inode *ip,
 	xfs_trans_reserve_quota_bydquots(tp, mp, ud, gd, pd, nb, ni, \
 				f | XFS_QMOPT_RES_REGBLKS)
 
+static inline int
+xfs_quota_reserve_blkres(struct xfs_inode *ip, int64_t nblks,
+		unsigned int flags)
+{
+	return xfs_trans_reserve_quota_nblks(NULL, ip, nblks, 0, flags);
+}
+
+static inline int
+xfs_quota_unreserve_blkres(struct xfs_inode *ip, int64_t nblks,
+		unsigned int flags)
+{
+	return xfs_quota_reserve_blkres(ip, -nblks, flags);
+}
+
 extern int xfs_mount_reset_sbqflags(struct xfs_mount *);
 
 #endif	/* __XFS_QUOTA_H__ */
diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c
index 20321d03e31c..1f3270ffaea5 100644
--- a/fs/xfs/xfs_reflink.c
+++ b/fs/xfs/xfs_reflink.c
@@ -508,8 +508,7 @@ xfs_reflink_cancel_cow_blocks(
 			xfs_bmap_del_extent_cow(ip, &icur, &got, &del);
 
 			/* Remove the quota reservation */
-			error = xfs_trans_unreserve_quota_nblks(NULL, ip,
-					del.br_blockcount, 0,
+			error = xfs_quota_unreserve_blkres(ip, del.br_blockcount,
 					XFS_QMOPT_RES_REGBLKS);
 			if (error)
 				break;


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH 4/4] xfs: clean up icreate quota reservation calls
  2021-01-18 22:11 [PATCHSET 0/4] xfs: minor cleanups of the quota functions Darrick J. Wong
                   ` (2 preceding siblings ...)
  2021-01-18 22:11 ` [PATCH 3/4] xfs: create convenience wrappers for incore quota block reservations Darrick J. Wong
@ 2021-01-18 22:11 ` Darrick J. Wong
  2021-01-19  6:46   ` Christoph Hellwig
  3 siblings, 1 reply; 16+ messages in thread
From: Darrick J. Wong @ 2021-01-18 22:11 UTC (permalink / raw)
  To: djwong; +Cc: linux-xfs

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

Create a proper helper so that inode creation calls can reserve quota
with a dedicated function.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 fs/xfs/xfs_inode.c       |    8 ++++----
 fs/xfs/xfs_quota.h       |   14 ++++++++++----
 fs/xfs/xfs_symlink.c     |    4 ++--
 fs/xfs/xfs_trans_dquot.c |   21 +++++++++++++++++++++
 4 files changed, 37 insertions(+), 10 deletions(-)


diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c
index e5dc41b10ebb..43cff78c20c4 100644
--- a/fs/xfs/xfs_inode.c
+++ b/fs/xfs/xfs_inode.c
@@ -1037,8 +1037,8 @@ xfs_create(
 	/*
 	 * Reserve disk quota and the inode.
 	 */
-	error = xfs_trans_reserve_quota(tp, mp, udqp, gdqp,
-						pdqp, resblks, 1, 0);
+	error = xfs_trans_reserve_quota_icreate(tp, dp, udqp, gdqp, pdqp,
+			resblks);
 	if (error)
 		goto out_trans_cancel;
 
@@ -1164,8 +1164,8 @@ xfs_create_tmpfile(
 	if (error)
 		goto out_release_inode;
 
-	error = xfs_trans_reserve_quota(tp, mp, udqp, gdqp,
-						pdqp, resblks, 1, 0);
+	error = xfs_trans_reserve_quota_icreate(tp, dp, udqp, gdqp, pdqp,
+			resblks);
 	if (error)
 		goto out_trans_cancel;
 
diff --git a/fs/xfs/xfs_quota.h b/fs/xfs/xfs_quota.h
index b1411d25c9e5..1c37b5be60c3 100644
--- a/fs/xfs/xfs_quota.h
+++ b/fs/xfs/xfs_quota.h
@@ -86,6 +86,9 @@ extern int xfs_trans_reserve_quota_nblks(struct xfs_trans *,
 extern int xfs_trans_reserve_quota_bydquots(struct xfs_trans *,
 		struct xfs_mount *, struct xfs_dquot *,
 		struct xfs_dquot *, struct xfs_dquot *, int64_t, long, uint);
+int xfs_trans_reserve_quota_icreate(struct xfs_trans *tp, struct xfs_inode *dp,
+		struct xfs_dquot *udqp, struct xfs_dquot *gdqp,
+		struct xfs_dquot *pdqp, int64_t nblks);
 
 extern int xfs_qm_vop_dqalloc(struct xfs_inode *, kuid_t, kgid_t,
 		prid_t, uint, struct xfs_dquot **, struct xfs_dquot **,
@@ -141,6 +144,13 @@ static inline int xfs_quota_reserve_blkres(struct xfs_inode *ip,
 {
 	return 0;
 }
+static inline int
+xfs_trans_reserve_quota_icreate(struct xfs_trans *tp, struct xfs_inode *dp,
+		struct xfs_dquot *udqp, struct xfs_dquot *gdqp,
+		struct xfs_dquot *pdqp, int64_t nblks)
+{
+	return 0;
+}
 #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)
@@ -163,10 +173,6 @@ xfs_trans_unreserve_quota_nblks(struct xfs_trans *tp, struct xfs_inode *ip,
 	return xfs_trans_reserve_quota_nblks(tp, ip, -nblks, -ninos, flags);
 }
 
-#define xfs_trans_reserve_quota(tp, mp, ud, gd, pd, nb, ni, f) \
-	xfs_trans_reserve_quota_bydquots(tp, mp, ud, gd, pd, nb, ni, \
-				f | XFS_QMOPT_RES_REGBLKS)
-
 static inline int
 xfs_quota_reserve_blkres(struct xfs_inode *ip, int64_t nblks,
 		unsigned int flags)
diff --git a/fs/xfs/xfs_symlink.c b/fs/xfs/xfs_symlink.c
index 1f43fd7f3209..e53f7bc2b820 100644
--- a/fs/xfs/xfs_symlink.c
+++ b/fs/xfs/xfs_symlink.c
@@ -215,8 +215,8 @@ xfs_symlink(
 	/*
 	 * Reserve disk quota : blocks and inode.
 	 */
-	error = xfs_trans_reserve_quota(tp, mp, udqp, gdqp,
-						pdqp, resblks, 1, 0);
+	error = xfs_trans_reserve_quota_icreate(tp, dp, udqp, gdqp, pdqp,
+			resblks);
 	if (error)
 		goto out_trans_cancel;
 
diff --git a/fs/xfs/xfs_trans_dquot.c b/fs/xfs/xfs_trans_dquot.c
index 28b8ac701919..3315498a6fa1 100644
--- a/fs/xfs/xfs_trans_dquot.c
+++ b/fs/xfs/xfs_trans_dquot.c
@@ -804,6 +804,27 @@ xfs_trans_reserve_quota_nblks(
 						nblks, ninos, flags);
 }
 
+/* Change the quota reservations for an inode creation activity. */
+int
+xfs_trans_reserve_quota_icreate(
+	struct xfs_trans	*tp,
+	struct xfs_inode	*dp,
+	struct xfs_dquot	*udqp,
+	struct xfs_dquot	*gdqp,
+	struct xfs_dquot	*pdqp,
+	int64_t			nblks)
+{
+	struct xfs_mount	*mp = dp->i_mount;
+
+	if (!XFS_IS_QUOTA_RUNNING(mp) || !XFS_IS_QUOTA_ON(mp))
+		return 0;
+
+	ASSERT(!xfs_is_quota_inode(&mp->m_sb, dp->i_ino));
+
+	return xfs_trans_reserve_quota_bydquots(tp, dp->i_mount, udqp, gdqp,
+			pdqp, nblks, 1, XFS_QMOPT_RES_REGBLKS);
+}
+
 /*
  * This routine is called to allocate a quotaoff log item.
  */


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 1/4] xfs: clean up quota reservation callsites
  2021-01-18 22:11 ` [PATCH 1/4] xfs: clean up quota reservation callsites Darrick J. Wong
@ 2021-01-19  6:35   ` Christoph Hellwig
  0 siblings, 0 replies; 16+ messages in thread
From: Christoph Hellwig @ 2021-01-19  6:35 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: linux-xfs

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 2/4] xfs: clean up quota reservation wrappers
  2021-01-18 22:11 ` [PATCH 2/4] xfs: clean up quota reservation wrappers Darrick J. Wong
@ 2021-01-19  6:38   ` Christoph Hellwig
  0 siblings, 0 replies; 16+ messages in thread
From: Christoph Hellwig @ 2021-01-19  6:38 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: linux-xfs

On Mon, Jan 18, 2021 at 02:11:44PM -0800, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
> 
> Replace a couple of quota reservation macros with properly typechecked
> static inline functions ahead of more restructuring in the next patches.
> 
> Signed-off-by: Darrick J. Wong <djwong@kernel.org>

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 3/4] xfs: create convenience wrappers for incore quota block reservations
  2021-01-18 22:11 ` [PATCH 3/4] xfs: create convenience wrappers for incore quota block reservations Darrick J. Wong
@ 2021-01-19  6:44   ` Christoph Hellwig
  2021-01-19 19:47     ` Darrick J. Wong
  2021-01-20  4:33   ` [PATCH v2.1 " Darrick J. Wong
  1 sibling, 1 reply; 16+ messages in thread
From: Christoph Hellwig @ 2021-01-19  6:44 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: linux-xfs

> -	error = xfs_trans_reserve_quota_nblks(NULL, ip, (long)alen, 0,
> -						XFS_QMOPT_RES_REGBLKS);
> +	error = xfs_quota_reserve_blkres(ip, alen, XFS_QMOPT_RES_REGBLKS);

This is the only callsite outside of xfs_quota_unreserve_blkres,
so I'm not sure how useful the wrapper is.  Also even on the unreserved
side we always pass XFS_QMOPT_RES_REGBLKS except for one case that
conditionally passes XFS_QMOPT_RES_RTBLKS.  So if we think these helpers
are useful enough I'd at least just pass a bool is_rt argument and hide
the flags entirely.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 4/4] xfs: clean up icreate quota reservation calls
  2021-01-18 22:11 ` [PATCH 4/4] xfs: clean up icreate quota reservation calls Darrick J. Wong
@ 2021-01-19  6:46   ` Christoph Hellwig
  0 siblings, 0 replies; 16+ messages in thread
From: Christoph Hellwig @ 2021-01-19  6:46 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: linux-xfs

On Mon, Jan 18, 2021 at 02:11:55PM -0800, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
> 
> Create a proper helper so that inode creation calls can reserve quota
> with a dedicated function.
> 
> Signed-off-by: Darrick J. Wong <djwong@kernel.org>

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 3/4] xfs: create convenience wrappers for incore quota block reservations
  2021-01-19  6:44   ` Christoph Hellwig
@ 2021-01-19 19:47     ` Darrick J. Wong
  2021-01-19 20:26       ` Darrick J. Wong
  0 siblings, 1 reply; 16+ messages in thread
From: Darrick J. Wong @ 2021-01-19 19:47 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: linux-xfs

On Tue, Jan 19, 2021 at 07:44:03AM +0100, Christoph Hellwig wrote:
> > -	error = xfs_trans_reserve_quota_nblks(NULL, ip, (long)alen, 0,
> > -						XFS_QMOPT_RES_REGBLKS);
> > +	error = xfs_quota_reserve_blkres(ip, alen, XFS_QMOPT_RES_REGBLKS);
> 
> This is the only callsite outside of xfs_quota_unreserve_blkres,
> so I'm not sure how useful the wrapper is.  Also even on the unreserved
> side we always pass XFS_QMOPT_RES_REGBLKS except for one case that
> conditionally passes XFS_QMOPT_RES_RTBLKS.  So if we think these helpers
> are useful enough I'd at least just pass a bool is_rt argument and hide
> the flags entirely.

Seeing as XFS doesn't even let you mount with quota and rt, I elect to
get rid of the third parameter entirely.  Whoever decides to make them
work together will have a lot of work to do beyond fixing that one
unreserve call.

--D

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 3/4] xfs: create convenience wrappers for incore quota block reservations
  2021-01-19 19:47     ` Darrick J. Wong
@ 2021-01-19 20:26       ` Darrick J. Wong
  0 siblings, 0 replies; 16+ messages in thread
From: Darrick J. Wong @ 2021-01-19 20:26 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: linux-xfs

On Tue, Jan 19, 2021 at 11:47:19AM -0800, Darrick J. Wong wrote:
> On Tue, Jan 19, 2021 at 07:44:03AM +0100, Christoph Hellwig wrote:
> > > -	error = xfs_trans_reserve_quota_nblks(NULL, ip, (long)alen, 0,
> > > -						XFS_QMOPT_RES_REGBLKS);
> > > +	error = xfs_quota_reserve_blkres(ip, alen, XFS_QMOPT_RES_REGBLKS);
> > 
> > This is the only callsite outside of xfs_quota_unreserve_blkres,
> > so I'm not sure how useful the wrapper is.  Also even on the unreserved
> > side we always pass XFS_QMOPT_RES_REGBLKS except for one case that
> > conditionally passes XFS_QMOPT_RES_RTBLKS.  So if we think these helpers
> > are useful enough I'd at least just pass a bool is_rt argument and hide
> > the flags entirely.
> 
> Seeing as XFS doesn't even let you mount with quota and rt, I elect to
> get rid of the third parameter entirely.  Whoever decides to make them
> work together will have a lot of work to do beyond fixing that one
> unreserve call.

And having said that, I reverse myself, because looking at the rt
reflink patchset I'll have to add that switch to the reserve/unreserve
callers anyway.  I'll change the last arg to 'bool isrt'.

--D

> --D

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH v2.1 3/4] xfs: create convenience wrappers for incore quota block reservations
  2021-01-18 22:11 ` [PATCH 3/4] xfs: create convenience wrappers for incore quota block reservations Darrick J. Wong
  2021-01-19  6:44   ` Christoph Hellwig
@ 2021-01-20  4:33   ` Darrick J. Wong
  1 sibling, 0 replies; 16+ messages in thread
From: Darrick J. Wong @ 2021-01-20  4:33 UTC (permalink / raw)
  To: linux-xfs; +Cc: Christoph Hellwig

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

Create a couple of convenience wrappers for creating and deleting quota
block reservations against future changes.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
v2.1: change the third argument to an "is rt?" boolean from raw qmopt flags
---
 fs/xfs/libxfs/xfs_bmap.c |   12 ++++++------
 fs/xfs/xfs_quota.h       |   19 +++++++++++++++++++
 fs/xfs/xfs_reflink.c     |    6 +++---
 3 files changed, 28 insertions(+), 9 deletions(-)

diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
index 21076ac2485a..d35e90db6135 100644
--- a/fs/xfs/libxfs/xfs_bmap.c
+++ b/fs/xfs/libxfs/xfs_bmap.c
@@ -3970,9 +3970,12 @@ xfs_bmapi_reserve_delalloc(
 	struct xfs_ifork	*ifp = XFS_IFORK_PTR(ip, whichfork);
 	xfs_extlen_t		alen;
 	xfs_extlen_t		indlen;
+	bool			isrt;
 	int			error;
 	xfs_fileoff_t		aoff = off;
 
+	isrt = (whichfork == XFS_DATA_FORK) && XFS_IS_REALTIME_INODE(ip);
+
 	/*
 	 * Cap the alloc length. Keep track of prealloc so we know whether to
 	 * tag the inode before we return.
@@ -4001,8 +4004,7 @@ xfs_bmapi_reserve_delalloc(
 	 * blocks.  This number gets adjusted later.  We return if we haven't
 	 * allocated blocks already inside this loop.
 	 */
-	error = xfs_trans_reserve_quota_nblks(NULL, ip, (long)alen, 0,
-						XFS_QMOPT_RES_REGBLKS);
+	error = xfs_quota_reserve_blkres(ip, alen, isrt);
 	if (error)
 		return error;
 
@@ -4048,8 +4050,7 @@ xfs_bmapi_reserve_delalloc(
 	xfs_mod_fdblocks(mp, alen, false);
 out_unreserve_quota:
 	if (XFS_IS_QUOTA_ON(mp))
-		xfs_trans_unreserve_quota_nblks(NULL, ip, (long)alen, 0,
-						XFS_QMOPT_RES_REGBLKS);
+		xfs_quota_unreserve_blkres(ip, alen, isrt);
 	return error;
 }
 
@@ -4826,8 +4827,7 @@ xfs_bmap_del_extent_delay(
 	 * sb counters as we might have to borrow some blocks for the
 	 * indirect block accounting.
 	 */
-	error = xfs_trans_unreserve_quota_nblks(NULL, ip, del->br_blockcount, 0,
-			isrt ? XFS_QMOPT_RES_RTBLKS : XFS_QMOPT_RES_REGBLKS);
+	error = xfs_quota_unreserve_blkres(ip, del->br_blockcount, isrt);
 	if (error)
 		return error;
 	ip->i_delayed_blks -= del->br_blockcount;
diff --git a/fs/xfs/xfs_quota.h b/fs/xfs/xfs_quota.h
index bd28d17941e7..a25e3ce04c60 100644
--- a/fs/xfs/xfs_quota.h
+++ b/fs/xfs/xfs_quota.h
@@ -108,6 +108,12 @@ extern void xfs_qm_mount_quotas(struct xfs_mount *);
 extern void xfs_qm_unmount(struct xfs_mount *);
 extern void xfs_qm_unmount_quotas(struct xfs_mount *);
 
+static inline int
+xfs_quota_reserve_blkres(struct xfs_inode *ip, int64_t nblks, bool isrt)
+{
+	return xfs_trans_reserve_quota_nblks(NULL, ip, nblks, 0,
+			isrt ? XFS_QMOPT_RES_RTBLKS : XFS_QMOPT_RES_REGBLKS);
+}
 #else
 static inline int
 xfs_qm_vop_dqalloc(struct xfs_inode *ip, kuid_t kuid, kgid_t kgid,
@@ -136,6 +142,13 @@ static inline int xfs_trans_reserve_quota_bydquots(struct xfs_trans *tp,
 {
 	return 0;
 }
+
+static inline int
+xfs_quota_reserve_blkres(struct xfs_inode *ip, int64_t nblks, bool isrt)
+{
+	return 0;
+}
+
 #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)
@@ -162,6 +175,12 @@ xfs_trans_unreserve_quota_nblks(struct xfs_trans *tp, struct xfs_inode *ip,
 	xfs_trans_reserve_quota_bydquots(tp, mp, ud, gd, pd, nb, ni, \
 				f | XFS_QMOPT_RES_REGBLKS)
 
+static inline int
+xfs_quota_unreserve_blkres(struct xfs_inode *ip, int64_t nblks, bool isrt)
+{
+	return xfs_quota_reserve_blkres(ip, -nblks, isrt);
+}
+
 extern int xfs_mount_reset_sbqflags(struct xfs_mount *);
 
 #endif	/* __XFS_QUOTA_H__ */
diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c
index 20321d03e31c..afd1d5b0ad4c 100644
--- a/fs/xfs/xfs_reflink.c
+++ b/fs/xfs/xfs_reflink.c
@@ -508,9 +508,9 @@ xfs_reflink_cancel_cow_blocks(
 			xfs_bmap_del_extent_cow(ip, &icur, &got, &del);
 
 			/* Remove the quota reservation */
-			error = xfs_trans_unreserve_quota_nblks(NULL, ip,
-					del.br_blockcount, 0,
-					XFS_QMOPT_RES_REGBLKS);
+			error = xfs_quota_unreserve_blkres(ip,
+					del.br_blockcount,
+					XFS_IS_REALTIME_INODE(ip));
 			if (error)
 				break;
 		} else {

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 3/4] xfs: create convenience wrappers for incore quota block reservations
  2021-01-25 15:15   ` Brian Foster
@ 2021-01-26 20:37     ` Darrick J. Wong
  0 siblings, 0 replies; 16+ messages in thread
From: Darrick J. Wong @ 2021-01-26 20:37 UTC (permalink / raw)
  To: Brian Foster; +Cc: linux-xfs, hch, david

On Mon, Jan 25, 2021 at 10:15:19AM -0500, Brian Foster wrote:
> On Sat, Jan 23, 2021 at 10:51:51AM -0800, Darrick J. Wong wrote:
> > From: Darrick J. Wong <djwong@kernel.org>
> > 
> > Create a couple of convenience wrappers for creating and deleting quota
> > block reservations against future changes.
> > 
> > Signed-off-by: Darrick J. Wong <djwong@kernel.org>
> > ---
> >  fs/xfs/libxfs/xfs_bmap.c |   12 ++++++------
> >  fs/xfs/xfs_quota.h       |   19 +++++++++++++++++++
> >  fs/xfs/xfs_reflink.c     |    6 +++---
> >  3 files changed, 28 insertions(+), 9 deletions(-)
> > 
> > 
> > diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
> > index aea179212946..908b7d49da60 100644
> > --- a/fs/xfs/libxfs/xfs_bmap.c
> > +++ b/fs/xfs/libxfs/xfs_bmap.c
> > @@ -4067,9 +4067,12 @@ xfs_bmapi_reserve_delalloc(
> >  	struct xfs_ifork	*ifp = XFS_IFORK_PTR(ip, whichfork);
> >  	xfs_extlen_t		alen;
> >  	xfs_extlen_t		indlen;
> > +	bool			isrt;
> >  	int			error;
> >  	xfs_fileoff_t		aoff = off;
> >  
> > +	isrt = (whichfork == XFS_DATA_FORK) && XFS_IS_REALTIME_INODE(ip);
> > + 
> What's the reason for checking isrt where we didn't before? Is that what
> the commit log means by "... against future changes?" (If so, a sentence
> or two more of "why" context in the commit log please..? :)

Well right now this function makes a delalloc reservation .... oh , the
rest of the function is totally broken wrt realtime anyway, so maybe I
should just ditch that isrt parameter completely.

--D

> Brian
> 
> >  	/*
> >  	 * Cap the alloc length. Keep track of prealloc so we know whether to
> >  	 * tag the inode before we return.
> > @@ -4098,8 +4101,7 @@ xfs_bmapi_reserve_delalloc(
> >  	 * blocks.  This number gets adjusted later.  We return if we haven't
> >  	 * allocated blocks already inside this loop.
> >  	 */
> > -	error = xfs_trans_reserve_quota_nblks(NULL, ip, (long)alen, 0,
> > -						XFS_QMOPT_RES_REGBLKS);
> > +	error = xfs_quota_reserve_blkres(ip, alen, isrt);
> >  	if (error)
> >  		return error;
> >  
> > @@ -4145,8 +4147,7 @@ xfs_bmapi_reserve_delalloc(
> >  	xfs_mod_fdblocks(mp, alen, false);
> >  out_unreserve_quota:
> >  	if (XFS_IS_QUOTA_ON(mp))
> > -		xfs_trans_unreserve_quota_nblks(NULL, ip, (long)alen, 0,
> > -						XFS_QMOPT_RES_REGBLKS);
> > +		xfs_quota_unreserve_blkres(ip, alen, isrt);
> >  	return error;
> >  }
> >  
> > @@ -4938,8 +4939,7 @@ xfs_bmap_del_extent_delay(
> >  	 * sb counters as we might have to borrow some blocks for the
> >  	 * indirect block accounting.
> >  	 */
> > -	error = xfs_trans_unreserve_quota_nblks(NULL, ip, del->br_blockcount, 0,
> > -			isrt ? XFS_QMOPT_RES_RTBLKS : XFS_QMOPT_RES_REGBLKS);
> > +	error = xfs_quota_unreserve_blkres(ip, del->br_blockcount, isrt);
> >  	if (error)
> >  		return error;
> >  	ip->i_delayed_blks -= del->br_blockcount;
> > diff --git a/fs/xfs/xfs_quota.h b/fs/xfs/xfs_quota.h
> > index bd28d17941e7..a25e3ce04c60 100644
> > --- a/fs/xfs/xfs_quota.h
> > +++ b/fs/xfs/xfs_quota.h
> > @@ -108,6 +108,12 @@ extern void xfs_qm_mount_quotas(struct xfs_mount *);
> >  extern void xfs_qm_unmount(struct xfs_mount *);
> >  extern void xfs_qm_unmount_quotas(struct xfs_mount *);
> >  
> > +static inline int
> > +xfs_quota_reserve_blkres(struct xfs_inode *ip, int64_t nblks, bool isrt)
> > +{
> > +	return xfs_trans_reserve_quota_nblks(NULL, ip, nblks, 0,
> > +			isrt ? XFS_QMOPT_RES_RTBLKS : XFS_QMOPT_RES_REGBLKS);
> > +}
> >  #else
> >  static inline int
> >  xfs_qm_vop_dqalloc(struct xfs_inode *ip, kuid_t kuid, kgid_t kgid,
> > @@ -136,6 +142,13 @@ static inline int xfs_trans_reserve_quota_bydquots(struct xfs_trans *tp,
> >  {
> >  	return 0;
> >  }
> > +
> > +static inline int
> > +xfs_quota_reserve_blkres(struct xfs_inode *ip, int64_t nblks, bool isrt)
> > +{
> > +	return 0;
> > +}
> > +
> >  #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)
> > @@ -162,6 +175,12 @@ xfs_trans_unreserve_quota_nblks(struct xfs_trans *tp, struct xfs_inode *ip,
> >  	xfs_trans_reserve_quota_bydquots(tp, mp, ud, gd, pd, nb, ni, \
> >  				f | XFS_QMOPT_RES_REGBLKS)
> >  
> > +static inline int
> > +xfs_quota_unreserve_blkres(struct xfs_inode *ip, int64_t nblks, bool isrt)
> > +{
> > +	return xfs_quota_reserve_blkres(ip, -nblks, isrt);
> > +}
> > +
> >  extern int xfs_mount_reset_sbqflags(struct xfs_mount *);
> >  
> >  #endif	/* __XFS_QUOTA_H__ */
> > diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c
> > index 183142fd0961..0da1a603b7d8 100644
> > --- a/fs/xfs/xfs_reflink.c
> > +++ b/fs/xfs/xfs_reflink.c
> > @@ -508,9 +508,9 @@ xfs_reflink_cancel_cow_blocks(
> >  			xfs_bmap_del_extent_cow(ip, &icur, &got, &del);
> >  
> >  			/* Remove the quota reservation */
> > -			error = xfs_trans_unreserve_quota_nblks(NULL, ip,
> > -					del.br_blockcount, 0,
> > -					XFS_QMOPT_RES_REGBLKS);
> > +			error = xfs_quota_unreserve_blkres(ip,
> > +					del.br_blockcount,
> > +					XFS_IS_REALTIME_INODE(ip));
> >  			if (error)
> >  				break;
> >  		} else {
> > 
> 

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 3/4] xfs: create convenience wrappers for incore quota block reservations
  2021-01-23 18:51 ` [PATCH 3/4] xfs: create convenience wrappers for incore quota block reservations Darrick J. Wong
  2021-01-24  9:33   ` Christoph Hellwig
@ 2021-01-25 15:15   ` Brian Foster
  2021-01-26 20:37     ` Darrick J. Wong
  1 sibling, 1 reply; 16+ messages in thread
From: Brian Foster @ 2021-01-25 15:15 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: linux-xfs, hch, david

On Sat, Jan 23, 2021 at 10:51:51AM -0800, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
> 
> Create a couple of convenience wrappers for creating and deleting quota
> block reservations against future changes.
> 
> Signed-off-by: Darrick J. Wong <djwong@kernel.org>
> ---
>  fs/xfs/libxfs/xfs_bmap.c |   12 ++++++------
>  fs/xfs/xfs_quota.h       |   19 +++++++++++++++++++
>  fs/xfs/xfs_reflink.c     |    6 +++---
>  3 files changed, 28 insertions(+), 9 deletions(-)
> 
> 
> diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
> index aea179212946..908b7d49da60 100644
> --- a/fs/xfs/libxfs/xfs_bmap.c
> +++ b/fs/xfs/libxfs/xfs_bmap.c
> @@ -4067,9 +4067,12 @@ xfs_bmapi_reserve_delalloc(
>  	struct xfs_ifork	*ifp = XFS_IFORK_PTR(ip, whichfork);
>  	xfs_extlen_t		alen;
>  	xfs_extlen_t		indlen;
> +	bool			isrt;
>  	int			error;
>  	xfs_fileoff_t		aoff = off;
>  
> +	isrt = (whichfork == XFS_DATA_FORK) && XFS_IS_REALTIME_INODE(ip);
> +

What's the reason for checking isrt where we didn't before? Is that what
the commit log means by "... against future changes?" (If so, a sentence
or two more of "why" context in the commit log please..? :)

Brian

>  	/*
>  	 * Cap the alloc length. Keep track of prealloc so we know whether to
>  	 * tag the inode before we return.
> @@ -4098,8 +4101,7 @@ xfs_bmapi_reserve_delalloc(
>  	 * blocks.  This number gets adjusted later.  We return if we haven't
>  	 * allocated blocks already inside this loop.
>  	 */
> -	error = xfs_trans_reserve_quota_nblks(NULL, ip, (long)alen, 0,
> -						XFS_QMOPT_RES_REGBLKS);
> +	error = xfs_quota_reserve_blkres(ip, alen, isrt);
>  	if (error)
>  		return error;
>  
> @@ -4145,8 +4147,7 @@ xfs_bmapi_reserve_delalloc(
>  	xfs_mod_fdblocks(mp, alen, false);
>  out_unreserve_quota:
>  	if (XFS_IS_QUOTA_ON(mp))
> -		xfs_trans_unreserve_quota_nblks(NULL, ip, (long)alen, 0,
> -						XFS_QMOPT_RES_REGBLKS);
> +		xfs_quota_unreserve_blkres(ip, alen, isrt);
>  	return error;
>  }
>  
> @@ -4938,8 +4939,7 @@ xfs_bmap_del_extent_delay(
>  	 * sb counters as we might have to borrow some blocks for the
>  	 * indirect block accounting.
>  	 */
> -	error = xfs_trans_unreserve_quota_nblks(NULL, ip, del->br_blockcount, 0,
> -			isrt ? XFS_QMOPT_RES_RTBLKS : XFS_QMOPT_RES_REGBLKS);
> +	error = xfs_quota_unreserve_blkres(ip, del->br_blockcount, isrt);
>  	if (error)
>  		return error;
>  	ip->i_delayed_blks -= del->br_blockcount;
> diff --git a/fs/xfs/xfs_quota.h b/fs/xfs/xfs_quota.h
> index bd28d17941e7..a25e3ce04c60 100644
> --- a/fs/xfs/xfs_quota.h
> +++ b/fs/xfs/xfs_quota.h
> @@ -108,6 +108,12 @@ extern void xfs_qm_mount_quotas(struct xfs_mount *);
>  extern void xfs_qm_unmount(struct xfs_mount *);
>  extern void xfs_qm_unmount_quotas(struct xfs_mount *);
>  
> +static inline int
> +xfs_quota_reserve_blkres(struct xfs_inode *ip, int64_t nblks, bool isrt)
> +{
> +	return xfs_trans_reserve_quota_nblks(NULL, ip, nblks, 0,
> +			isrt ? XFS_QMOPT_RES_RTBLKS : XFS_QMOPT_RES_REGBLKS);
> +}
>  #else
>  static inline int
>  xfs_qm_vop_dqalloc(struct xfs_inode *ip, kuid_t kuid, kgid_t kgid,
> @@ -136,6 +142,13 @@ static inline int xfs_trans_reserve_quota_bydquots(struct xfs_trans *tp,
>  {
>  	return 0;
>  }
> +
> +static inline int
> +xfs_quota_reserve_blkres(struct xfs_inode *ip, int64_t nblks, bool isrt)
> +{
> +	return 0;
> +}
> +
>  #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)
> @@ -162,6 +175,12 @@ xfs_trans_unreserve_quota_nblks(struct xfs_trans *tp, struct xfs_inode *ip,
>  	xfs_trans_reserve_quota_bydquots(tp, mp, ud, gd, pd, nb, ni, \
>  				f | XFS_QMOPT_RES_REGBLKS)
>  
> +static inline int
> +xfs_quota_unreserve_blkres(struct xfs_inode *ip, int64_t nblks, bool isrt)
> +{
> +	return xfs_quota_reserve_blkres(ip, -nblks, isrt);
> +}
> +
>  extern int xfs_mount_reset_sbqflags(struct xfs_mount *);
>  
>  #endif	/* __XFS_QUOTA_H__ */
> diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c
> index 183142fd0961..0da1a603b7d8 100644
> --- a/fs/xfs/xfs_reflink.c
> +++ b/fs/xfs/xfs_reflink.c
> @@ -508,9 +508,9 @@ xfs_reflink_cancel_cow_blocks(
>  			xfs_bmap_del_extent_cow(ip, &icur, &got, &del);
>  
>  			/* Remove the quota reservation */
> -			error = xfs_trans_unreserve_quota_nblks(NULL, ip,
> -					del.br_blockcount, 0,
> -					XFS_QMOPT_RES_REGBLKS);
> +			error = xfs_quota_unreserve_blkres(ip,
> +					del.br_blockcount,
> +					XFS_IS_REALTIME_INODE(ip));
>  			if (error)
>  				break;
>  		} else {
> 


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 3/4] xfs: create convenience wrappers for incore quota block reservations
  2021-01-23 18:51 ` [PATCH 3/4] xfs: create convenience wrappers for incore quota block reservations Darrick J. Wong
@ 2021-01-24  9:33   ` Christoph Hellwig
  2021-01-25 15:15   ` Brian Foster
  1 sibling, 0 replies; 16+ messages in thread
From: Christoph Hellwig @ 2021-01-24  9:33 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: linux-xfs, hch, david

On Sat, Jan 23, 2021 at 10:51:51AM -0800, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
> 
> Create a couple of convenience wrappers for creating and deleting quota
> block reservations against future changes.
> 
> Signed-off-by: Darrick J. Wong <djwong@kernel.org>

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH 3/4] xfs: create convenience wrappers for incore quota block reservations
  2021-01-23 18:51 [PATCHSET v2 0/4] xfs: minor cleanups of the quota functions Darrick J. Wong
@ 2021-01-23 18:51 ` Darrick J. Wong
  2021-01-24  9:33   ` Christoph Hellwig
  2021-01-25 15:15   ` Brian Foster
  0 siblings, 2 replies; 16+ messages in thread
From: Darrick J. Wong @ 2021-01-23 18:51 UTC (permalink / raw)
  To: djwong; +Cc: linux-xfs, hch, david

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

Create a couple of convenience wrappers for creating and deleting quota
block reservations against future changes.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 fs/xfs/libxfs/xfs_bmap.c |   12 ++++++------
 fs/xfs/xfs_quota.h       |   19 +++++++++++++++++++
 fs/xfs/xfs_reflink.c     |    6 +++---
 3 files changed, 28 insertions(+), 9 deletions(-)


diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
index aea179212946..908b7d49da60 100644
--- a/fs/xfs/libxfs/xfs_bmap.c
+++ b/fs/xfs/libxfs/xfs_bmap.c
@@ -4067,9 +4067,12 @@ xfs_bmapi_reserve_delalloc(
 	struct xfs_ifork	*ifp = XFS_IFORK_PTR(ip, whichfork);
 	xfs_extlen_t		alen;
 	xfs_extlen_t		indlen;
+	bool			isrt;
 	int			error;
 	xfs_fileoff_t		aoff = off;
 
+	isrt = (whichfork == XFS_DATA_FORK) && XFS_IS_REALTIME_INODE(ip);
+
 	/*
 	 * Cap the alloc length. Keep track of prealloc so we know whether to
 	 * tag the inode before we return.
@@ -4098,8 +4101,7 @@ xfs_bmapi_reserve_delalloc(
 	 * blocks.  This number gets adjusted later.  We return if we haven't
 	 * allocated blocks already inside this loop.
 	 */
-	error = xfs_trans_reserve_quota_nblks(NULL, ip, (long)alen, 0,
-						XFS_QMOPT_RES_REGBLKS);
+	error = xfs_quota_reserve_blkres(ip, alen, isrt);
 	if (error)
 		return error;
 
@@ -4145,8 +4147,7 @@ xfs_bmapi_reserve_delalloc(
 	xfs_mod_fdblocks(mp, alen, false);
 out_unreserve_quota:
 	if (XFS_IS_QUOTA_ON(mp))
-		xfs_trans_unreserve_quota_nblks(NULL, ip, (long)alen, 0,
-						XFS_QMOPT_RES_REGBLKS);
+		xfs_quota_unreserve_blkres(ip, alen, isrt);
 	return error;
 }
 
@@ -4938,8 +4939,7 @@ xfs_bmap_del_extent_delay(
 	 * sb counters as we might have to borrow some blocks for the
 	 * indirect block accounting.
 	 */
-	error = xfs_trans_unreserve_quota_nblks(NULL, ip, del->br_blockcount, 0,
-			isrt ? XFS_QMOPT_RES_RTBLKS : XFS_QMOPT_RES_REGBLKS);
+	error = xfs_quota_unreserve_blkres(ip, del->br_blockcount, isrt);
 	if (error)
 		return error;
 	ip->i_delayed_blks -= del->br_blockcount;
diff --git a/fs/xfs/xfs_quota.h b/fs/xfs/xfs_quota.h
index bd28d17941e7..a25e3ce04c60 100644
--- a/fs/xfs/xfs_quota.h
+++ b/fs/xfs/xfs_quota.h
@@ -108,6 +108,12 @@ extern void xfs_qm_mount_quotas(struct xfs_mount *);
 extern void xfs_qm_unmount(struct xfs_mount *);
 extern void xfs_qm_unmount_quotas(struct xfs_mount *);
 
+static inline int
+xfs_quota_reserve_blkres(struct xfs_inode *ip, int64_t nblks, bool isrt)
+{
+	return xfs_trans_reserve_quota_nblks(NULL, ip, nblks, 0,
+			isrt ? XFS_QMOPT_RES_RTBLKS : XFS_QMOPT_RES_REGBLKS);
+}
 #else
 static inline int
 xfs_qm_vop_dqalloc(struct xfs_inode *ip, kuid_t kuid, kgid_t kgid,
@@ -136,6 +142,13 @@ static inline int xfs_trans_reserve_quota_bydquots(struct xfs_trans *tp,
 {
 	return 0;
 }
+
+static inline int
+xfs_quota_reserve_blkres(struct xfs_inode *ip, int64_t nblks, bool isrt)
+{
+	return 0;
+}
+
 #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)
@@ -162,6 +175,12 @@ xfs_trans_unreserve_quota_nblks(struct xfs_trans *tp, struct xfs_inode *ip,
 	xfs_trans_reserve_quota_bydquots(tp, mp, ud, gd, pd, nb, ni, \
 				f | XFS_QMOPT_RES_REGBLKS)
 
+static inline int
+xfs_quota_unreserve_blkres(struct xfs_inode *ip, int64_t nblks, bool isrt)
+{
+	return xfs_quota_reserve_blkres(ip, -nblks, isrt);
+}
+
 extern int xfs_mount_reset_sbqflags(struct xfs_mount *);
 
 #endif	/* __XFS_QUOTA_H__ */
diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c
index 183142fd0961..0da1a603b7d8 100644
--- a/fs/xfs/xfs_reflink.c
+++ b/fs/xfs/xfs_reflink.c
@@ -508,9 +508,9 @@ xfs_reflink_cancel_cow_blocks(
 			xfs_bmap_del_extent_cow(ip, &icur, &got, &del);
 
 			/* Remove the quota reservation */
-			error = xfs_trans_unreserve_quota_nblks(NULL, ip,
-					del.br_blockcount, 0,
-					XFS_QMOPT_RES_REGBLKS);
+			error = xfs_quota_unreserve_blkres(ip,
+					del.br_blockcount,
+					XFS_IS_REALTIME_INODE(ip));
 			if (error)
 				break;
 		} else {


^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, back to index

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-18 22:11 [PATCHSET 0/4] xfs: minor cleanups of the quota functions Darrick J. Wong
2021-01-18 22:11 ` [PATCH 1/4] xfs: clean up quota reservation callsites Darrick J. Wong
2021-01-19  6:35   ` Christoph Hellwig
2021-01-18 22:11 ` [PATCH 2/4] xfs: clean up quota reservation wrappers Darrick J. Wong
2021-01-19  6:38   ` Christoph Hellwig
2021-01-18 22:11 ` [PATCH 3/4] xfs: create convenience wrappers for incore quota block reservations Darrick J. Wong
2021-01-19  6:44   ` Christoph Hellwig
2021-01-19 19:47     ` Darrick J. Wong
2021-01-19 20:26       ` Darrick J. Wong
2021-01-20  4:33   ` [PATCH v2.1 " Darrick J. Wong
2021-01-18 22:11 ` [PATCH 4/4] xfs: clean up icreate quota reservation calls Darrick J. Wong
2021-01-19  6:46   ` Christoph Hellwig
2021-01-23 18:51 [PATCHSET v2 0/4] xfs: minor cleanups of the quota functions Darrick J. Wong
2021-01-23 18:51 ` [PATCH 3/4] xfs: create convenience wrappers for incore quota block reservations Darrick J. Wong
2021-01-24  9:33   ` Christoph Hellwig
2021-01-25 15:15   ` Brian Foster
2021-01-26 20:37     ` Darrick J. Wong

Linux-XFS Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-xfs/0 linux-xfs/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-xfs linux-xfs/ https://lore.kernel.org/linux-xfs \
		linux-xfs@vger.kernel.org
	public-inbox-index linux-xfs

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-xfs


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git