Commit 3e0ee78f authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Dave Chinner

xfs: optimize xfs_reflink_cancel_cow_blocks

Rewrite xfs_reflink_cancel_cow_blocks so that we only do a search for
the first extent in the extent list and then iterate over the remaining
extents using the extent index, passing the extent we operate on
directly to xfs_bmap_del_extent_delay or xfs_bmap_del_extent_cow instead
of going through xfs_bunmapi and doing yet another extent list lookup.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: default avatarBrian Foster <bfoster@redhat.com>
Signed-off-by: default avatarDave Chinner <david@fromorbit.com>
parent fa5c836c
...@@ -511,53 +511,49 @@ xfs_reflink_cancel_cow_blocks( ...@@ -511,53 +511,49 @@ xfs_reflink_cancel_cow_blocks(
xfs_fileoff_t offset_fsb, xfs_fileoff_t offset_fsb,
xfs_fileoff_t end_fsb) xfs_fileoff_t end_fsb)
{ {
struct xfs_bmbt_irec irec; struct xfs_ifork *ifp = XFS_IFORK_PTR(ip, XFS_COW_FORK);
xfs_filblks_t count_fsb; struct xfs_bmbt_irec got, prev, del;
xfs_extnum_t idx;
xfs_fsblock_t firstfsb; xfs_fsblock_t firstfsb;
struct xfs_defer_ops dfops; struct xfs_defer_ops dfops;
int error = 0; int error = 0, eof = 0;
int nimaps;
if (!xfs_is_reflink_inode(ip)) if (!xfs_is_reflink_inode(ip))
return 0; return 0;
/* Go find the old extent in the CoW fork. */ xfs_bmap_search_extents(ip, offset_fsb, XFS_COW_FORK, &eof, &idx,
while (offset_fsb < end_fsb) { &got, &prev);
nimaps = 1; if (eof)
count_fsb = (xfs_filblks_t)(end_fsb - offset_fsb); return 0;
error = xfs_bmapi_read(ip, offset_fsb, count_fsb, &irec,
&nimaps, XFS_BMAPI_COWFORK);
if (error)
break;
ASSERT(nimaps == 1);
trace_xfs_reflink_cancel_cow(ip, &irec); while (got.br_startoff < end_fsb) {
del = got;
xfs_trim_extent(&del, offset_fsb, end_fsb - offset_fsb);
trace_xfs_reflink_cancel_cow(ip, &del);
if (irec.br_startblock == DELAYSTARTBLOCK) { if (isnullstartblock(del.br_startblock)) {
/* Remove the mapping from the CoW fork. */ error = xfs_bmap_del_extent_delay(ip, XFS_COW_FORK,
error = xfs_bunmapi_cow(ip, &irec); &idx, &got, &del);
if (error) if (error)
break; break;
} else if (irec.br_startblock == HOLESTARTBLOCK) {
/* empty */
} else { } else {
xfs_trans_ijoin(*tpp, ip, 0); xfs_trans_ijoin(*tpp, ip, 0);
xfs_defer_init(&dfops, &firstfsb); xfs_defer_init(&dfops, &firstfsb);
/* Free the CoW orphan record. */ /* Free the CoW orphan record. */
error = xfs_refcount_free_cow_extent(ip->i_mount, error = xfs_refcount_free_cow_extent(ip->i_mount,
&dfops, irec.br_startblock, &dfops, del.br_startblock,
irec.br_blockcount); del.br_blockcount);
if (error) if (error)
break; break;
xfs_bmap_add_free(ip->i_mount, &dfops, xfs_bmap_add_free(ip->i_mount, &dfops,
irec.br_startblock, irec.br_blockcount, del.br_startblock, del.br_blockcount,
NULL); NULL);
/* Update quota accounting */ /* Update quota accounting */
xfs_trans_mod_dquot_byino(*tpp, ip, XFS_TRANS_DQ_BCOUNT, xfs_trans_mod_dquot_byino(*tpp, ip, XFS_TRANS_DQ_BCOUNT,
-(long)irec.br_blockcount); -(long)del.br_blockcount);
/* Roll the transaction */ /* Roll the transaction */
error = xfs_defer_finish(tpp, &dfops, ip); error = xfs_defer_finish(tpp, &dfops, ip);
...@@ -567,13 +563,12 @@ xfs_reflink_cancel_cow_blocks( ...@@ -567,13 +563,12 @@ xfs_reflink_cancel_cow_blocks(
} }
/* Remove the mapping from the CoW fork. */ /* Remove the mapping from the CoW fork. */
error = xfs_bunmapi_cow(ip, &irec); xfs_bmap_del_extent_cow(ip, &idx, &got, &del);
if (error)
break;
} }
/* Roll on... */ if (++idx >= ifp->if_bytes / sizeof(struct xfs_bmbt_rec))
offset_fsb = irec.br_startoff + irec.br_blockcount; return 0;
xfs_bmbt_get_all(xfs_iext_get_ext(ifp, idx), &got);
} }
return error; return error;
......
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