xfs: only reserve quota blocks for bmbt changes if we're changing the data fork

Now that we've reworked xfs_reflink_remap_extent to remap only one
extent per transaction, we actually know if the extent being removed is
an allocated mapping.  This means that we now know ahead of time if
we're going to be touching the data fork.

Since we only need blocks for a bmbt split if we're going to update the
data fork, we only need to get quota reservation if we know we're going
to touch the data fork.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
This commit is contained in:
Darrick J. Wong 2020-06-29 14:47:19 -07:00
parent 00fd1d56dd
commit aa5d0ba0b5
1 changed files with 14 additions and 7 deletions

View File

@ -1047,7 +1047,11 @@ xfs_reflink_remap_extent(
* Compute quota reservation if we think the quota block counter for
* this file could increase.
*
* We start by reserving enough blocks to handle a bmbt split.
* Adding a written extent to the extent map can cause a bmbt split,
* and removing a mapped extent from the extent can cause a bmbt split.
* The two operations cannot both cause a split since they operate on
* the same index in the bmap btree, so we only need a reservation for
* one bmbt split if either thing is happening.
*
* 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
@ -1060,14 +1064,17 @@ xfs_reflink_remap_extent(
* before we started. That should have removed all the delalloc
* reservations, but we code defensively.
*/
qdelta = 0;
qres = qdelta = 0;
if (smap_real || dmap_written)
qres = XFS_EXTENTADD_SPACE_RES(mp, XFS_DATA_FORK);
if (dmap_written)
qres += dmap->br_blockcount;
if (qres > 0) {
error = xfs_trans_reserve_quota_nblks(tp, ip, qres, 0,
XFS_QMOPT_RES_REGBLKS);
if (error)
goto out_cancel;
}
if (smap_real) {
/*