Commit ca1862b0 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Darrick J. Wong

xfs: refactor delalloc accounting in xfs_bmap_add_extent_delay_real

Account for all changes to the delalloc reservation in da_new, and use a
single call xfs_mod_fdblocks to reserve/free blocks, including always
checking for an error.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarBrian Foster <bfoster@redhat.com>
Reviewed-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
parent 4dcb8869
...@@ -1574,7 +1574,6 @@ xfs_bmap_add_extent_delay_real( ...@@ -1574,7 +1574,6 @@ xfs_bmap_add_extent_delay_real(
int whichfork) int whichfork)
{ {
struct xfs_bmbt_irec *new = &bma->got; struct xfs_bmbt_irec *new = &bma->got;
int diff; /* temp value */
int error; /* error return value */ int error; /* error return value */
int i; /* temp state */ int i; /* temp state */
xfs_ifork_t *ifp; /* inode fork pointer */ xfs_ifork_t *ifp; /* inode fork pointer */
...@@ -2072,17 +2071,6 @@ xfs_bmap_add_extent_delay_real( ...@@ -2072,17 +2071,6 @@ xfs_bmap_add_extent_delay_real(
da_new = startblockval(PREV.br_startblock) + da_new = startblockval(PREV.br_startblock) +
startblockval(RIGHT.br_startblock); startblockval(RIGHT.br_startblock);
diff = da_new - startblockval(old.br_startblock);
if (bma->cur)
diff += bma->cur->bc_private.b.allocated;
if (diff > 0) {
error = xfs_mod_fdblocks(bma->ip->i_mount,
-((int64_t)diff), false);
ASSERT(!error);
if (error)
goto done;
}
bma->idx++; bma->idx++;
break; break;
...@@ -2117,19 +2105,17 @@ xfs_bmap_add_extent_delay_real( ...@@ -2117,19 +2105,17 @@ xfs_bmap_add_extent_delay_real(
goto done; goto done;
} }
/* adjust for changes in reserved delayed indirect blocks */ if (bma->cur) {
if (da_old || da_new) { da_new += bma->cur->bc_private.b.allocated;
temp = da_new; bma->cur->bc_private.b.allocated = 0;
if (bma->cur)
temp += bma->cur->bc_private.b.allocated;
if (temp < da_old)
xfs_mod_fdblocks(bma->ip->i_mount,
(int64_t)(da_old - temp), false);
} }
/* clear out the allocated field, done with it now in any case. */ /* adjust for changes in reserved delayed indirect blocks */
if (bma->cur) if (da_new != da_old) {
bma->cur->bc_private.b.allocated = 0; ASSERT(state == 0 || da_new < da_old);
error = xfs_mod_fdblocks(mp, (int64_t)(da_old - da_new),
false);
}
xfs_bmap_check_leaf_extents(bma->cur, bma->ip, whichfork); xfs_bmap_check_leaf_extents(bma->cur, bma->ip, whichfork);
done: done:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment