diff mbox series

[5/9] xfs: only reserve quota blocks if we're mapping into a hole

Message ID 159304789231.874036.3844840616429094322.stgit@magnolia (mailing list archive)
State Accepted
Headers show
Series xfs: reflink cleanups | expand

Commit Message

Darrick J. Wong June 25, 2020, 1:18 a.m. UTC
From: Darrick J. Wong <darrick.wong@oracle.com>

When logging quota block count updates during a reflink operation, we
only log the /delta/ of the block count changes to the dquot.  Since we
now know ahead of time the extent type of both dmap and smap (and that
they have the same length), we know that we only need to reserve quota
blocks for dmap's blockcount if we're mapping it into a hole.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 fs/xfs/xfs_reflink.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Brian Foster June 25, 2020, 12:28 p.m. UTC | #1
On Wed, Jun 24, 2020 at 06:18:12PM -0700, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> When logging quota block count updates during a reflink operation, we
> only log the /delta/ of the block count changes to the dquot.  Since we
> now know ahead of time the extent type of both dmap and smap (and that
> they have the same length), we know that we only need to reserve quota
> blocks for dmap's blockcount if we're mapping it into a hole.
> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> ---

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

>  fs/xfs/xfs_reflink.c |    6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> 
> diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c
> index 9cc1c340d0ec..72de7179399d 100644
> --- a/fs/xfs/xfs_reflink.c
> +++ b/fs/xfs/xfs_reflink.c
> @@ -1051,7 +1051,9 @@ xfs_reflink_remap_extent(
>  	 *
>  	 * If we are mapping a written extent into the file, we need to have
>  	 * enough quota block count reservation to handle the blocks in that
> -	 * extent.
> +	 * extent.  We log only the delta to the quota block counts, so if the
> +	 * extent we're unmapping also has blocks allocated to it, we don't
> +	 * need a quota reservation for the extent itself.
>  	 *
>  	 * Note that if we're replacing a delalloc reservation with a written
>  	 * extent, we have to take the full quota reservation because removing
> @@ -1063,7 +1065,7 @@ xfs_reflink_remap_extent(
>  	qres = qdelta = 0;
>  	if (smap_mapped || dmap_written)
>  		qres = XFS_EXTENTADD_SPACE_RES(mp, XFS_DATA_FORK);
> -	if (dmap_written)
> +	if (!smap_mapped && dmap_written)
>  		qres += dmap->br_blockcount;
>  	if (qres > 0) {
>  		error = xfs_trans_reserve_quota_nblks(tp, ip, qres, 0,
>
Christoph Hellwig July 1, 2020, 8:22 a.m. UTC | #2
Looks good,

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

Patch

diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c
index 9cc1c340d0ec..72de7179399d 100644
--- a/fs/xfs/xfs_reflink.c
+++ b/fs/xfs/xfs_reflink.c
@@ -1051,7 +1051,9 @@  xfs_reflink_remap_extent(
 	 *
 	 * If we are mapping a written extent into the file, we need to have
 	 * enough quota block count reservation to handle the blocks in that
-	 * extent.
+	 * extent.  We log only the delta to the quota block counts, so if the
+	 * extent we're unmapping also has blocks allocated to it, we don't
+	 * need a quota reservation for the extent itself.
 	 *
 	 * Note that if we're replacing a delalloc reservation with a written
 	 * extent, we have to take the full quota reservation because removing
@@ -1063,7 +1065,7 @@  xfs_reflink_remap_extent(
 	qres = qdelta = 0;
 	if (smap_mapped || dmap_written)
 		qres = XFS_EXTENTADD_SPACE_RES(mp, XFS_DATA_FORK);
-	if (dmap_written)
+	if (!smap_mapped && dmap_written)
 		qres += dmap->br_blockcount;
 	if (qres > 0) {
 		error = xfs_trans_reserve_quota_nblks(tp, ip, qres, 0,