diff options
author | Darrick J. Wong <darrick.wong@oracle.com> | 2020-03-30 11:29:41 -0700 |
---|---|---|
committer | Darrick J. Wong <darrick.wong@oracle.com> | 2020-06-01 21:16:49 -0700 |
commit | 83607a0c73fa213cd9b67598b044fd5376788358 (patch) | |
tree | 9b8172dc5a32171495dd30e8423560f4700b3c9e /fs | |
parent | 08a61f85277c72795c9ded8a7a6a29abd78c3723 (diff) |
xfs: port xfs_swap_extents_rmap to our new code
The inner loop of xfs_swap_extents_rmap does the same work as
xfs_swapext_finish_one, so adapt it to use that. Doing so has the side
benefit that the older code path no longer wastes its time remapping
shared extents.
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/xfs/libxfs/xfs_swapext.c | 40 | ||||
-rw-r--r-- | fs/xfs/libxfs/xfs_swapext.h | 3 | ||||
-rw-r--r-- | fs/xfs/xfs_bmap_util.c | 149 | ||||
-rw-r--r-- | fs/xfs/xfs_trace.h | 5 |
4 files changed, 59 insertions, 138 deletions
diff --git a/fs/xfs/libxfs/xfs_swapext.c b/fs/xfs/libxfs/xfs_swapext.c index a53f25636dae..5f90d49dbc26 100644 --- a/fs/xfs/libxfs/xfs_swapext.c +++ b/fs/xfs/libxfs/xfs_swapext.c @@ -586,3 +586,43 @@ xfs_swapext_atomic( xfs_swapext_reflink_finish(*tpp, req, reflink_state); return 0; } + +/* + * Swap a range of extents from one inode to another, non-atomically. + * + * Use deferred bmap log items swap a range of extents from one inode with + * another. Overall extent swap progress is /not/ tracked through the log, + * which means that while log recovery can finish remapping a single extent, + * it cannot finish the entire operation. + */ +int +xfs_swapext_deferred_bmap( + struct xfs_trans **tpp, + const struct xfs_swapext_req *req) +{ + struct xfs_swapext_intent sxi; + unsigned int state; + int error; + + ASSERT(xfs_isilocked(req->ip1, XFS_ILOCK_EXCL)); + ASSERT(xfs_isilocked(req->ip2, XFS_ILOCK_EXCL)); + ASSERT(req->whichfork == XFS_DATA_FORK); + if (req->flags & XFS_SWAPEXT_SET_SIZES) + ASSERT(req->whichfork == XFS_DATA_FORK); + + state = xfs_swapext_reflink_prep(req); + + xfs_swapext_init_intent(&sxi, req); + + while (sxi.sxi_blockcount > 0) { + error = xfs_swapext_finish_one(*tpp, &sxi); + if (error) + return error; + error = xfs_defer_finish(tpp); + if (error) + return error; + } + + xfs_swapext_reflink_finish(*tpp, req, state); + return 0; +} diff --git a/fs/xfs/libxfs/xfs_swapext.h b/fs/xfs/libxfs/xfs_swapext.h index 8579b6584bca..6dc8079c6fe8 100644 --- a/fs/xfs/libxfs/xfs_swapext.h +++ b/fs/xfs/libxfs/xfs_swapext.h @@ -76,4 +76,7 @@ int xfs_swapext_finish_one(struct xfs_trans *tp, int xfs_swapext_atomic(struct xfs_trans **tpp, const struct xfs_swapext_req *req); +int xfs_swapext_deferred_bmap(struct xfs_trans **tpp, + const struct xfs_swapext_req *req); + #endif /* __XFS_SWAPEXT_H_ */ diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c index 240b540e172f..4ca2688ab14e 100644 --- a/fs/xfs/xfs_bmap_util.c +++ b/fs/xfs/xfs_bmap_util.c @@ -1350,135 +1350,6 @@ xfs_swap_extent_flush( return 0; } -/* - * Move extents from one file to another, when rmap is enabled. - */ -STATIC int -xfs_swap_extent_rmap( - struct xfs_trans **tpp, - struct xfs_inode *ip, - struct xfs_inode *tip) -{ - struct xfs_trans *tp = *tpp; - struct xfs_bmbt_irec irec; - struct xfs_bmbt_irec uirec; - struct xfs_bmbt_irec tirec; - xfs_fileoff_t offset_fsb; - xfs_fileoff_t end_fsb; - xfs_filblks_t count_fsb; - int error; - xfs_filblks_t ilen; - xfs_filblks_t rlen; - int nimaps; - uint64_t tip_flags2; - - /* - * If the source file has shared blocks, we must flag the donor - * file as having shared blocks so that we get the shared-block - * rmap functions when we go to fix up the rmaps. The flags - * will be switch for reals later. - */ - tip_flags2 = tip->i_d.di_flags2; - if (ip->i_d.di_flags2 & XFS_DIFLAG2_REFLINK) - tip->i_d.di_flags2 |= XFS_DIFLAG2_REFLINK; - - offset_fsb = 0; - end_fsb = XFS_B_TO_FSB(ip->i_mount, i_size_read(VFS_I(ip))); - count_fsb = (xfs_filblks_t)(end_fsb - offset_fsb); - - while (count_fsb) { - /* Read extent from the donor file */ - nimaps = 1; - error = xfs_bmapi_read(tip, offset_fsb, count_fsb, &tirec, - &nimaps, 0); - if (error) - goto out; - ASSERT(nimaps == 1); - ASSERT(tirec.br_startblock != DELAYSTARTBLOCK); - - trace_xfs_swap_extent_rmap_remap(tip, &tirec); - ilen = tirec.br_blockcount; - - /* Unmap the old blocks in the source file. */ - while (tirec.br_blockcount) { - int64_t ip_delta = 0, tip_delta = 0; - - ASSERT(tp->t_firstblock == NULLFSBLOCK); - trace_xfs_swap_extent_rmap_remap_piece(tip, &tirec); - - /* Read extent from the source file */ - nimaps = 1; - error = xfs_bmapi_read(ip, tirec.br_startoff, - tirec.br_blockcount, &irec, - &nimaps, 0); - if (error) - goto out; - ASSERT(nimaps == 1); - ASSERT(tirec.br_startoff == irec.br_startoff); - trace_xfs_swap_extent_rmap_remap_piece(ip, &irec); - - /* Trim the extent. */ - uirec = tirec; - uirec.br_blockcount = rlen = min_t(xfs_filblks_t, - tirec.br_blockcount, - irec.br_blockcount); - trace_xfs_swap_extent_rmap_remap_piece(tip, &uirec); - - /* Update quota accounting. */ - if (xfs_bmap_is_mapped_extent(&irec)) { - tip_delta += irec.br_blockcount; - ip_delta -= irec.br_blockcount; - } - if (xfs_bmap_is_mapped_extent(&uirec)) { - tip_delta -= uirec.br_blockcount; - ip_delta += uirec.br_blockcount; - } - - if (tip_delta) - xfs_trans_mod_dquot_byino(tp, tip, - XFS_TRANS_DQ_BCOUNT, tip_delta); - if (ip_delta) - xfs_trans_mod_dquot_byino(tp, ip, - XFS_TRANS_DQ_BCOUNT, ip_delta); - - /* Remove the mapping from the donor file. */ - xfs_bmap_unmap_extent(tp, tip, XFS_DATA_FORK, &uirec); - - /* Remove the mapping from the source file. */ - xfs_bmap_unmap_extent(tp, ip, XFS_DATA_FORK, &irec); - - /* Map the donor file's blocks into the source file. */ - xfs_bmap_map_extent(tp, ip, XFS_DATA_FORK, &uirec); - - /* Map the source file's blocks into the donor file. */ - xfs_bmap_map_extent(tp, tip, XFS_DATA_FORK, &irec); - - error = xfs_defer_finish(tpp); - tp = *tpp; - if (error) - goto out; - - tirec.br_startoff += rlen; - if (tirec.br_startblock != HOLESTARTBLOCK && - tirec.br_startblock != DELAYSTARTBLOCK) - tirec.br_startblock += rlen; - tirec.br_blockcount -= rlen; - } - - /* Roll on... */ - count_fsb -= ilen; - offset_fsb += ilen; - } - - tip->i_d.di_flags2 = tip_flags2; - return 0; - -out: - trace_xfs_swap_extent_rmap_error(ip, error, _RET_IP_); - tip->i_d.di_flags2 = tip_flags2; - return error; -} - /* Swap the extents of two files by swapping data forks. */ STATIC int xfs_swap_extent_forks( @@ -1873,16 +1744,26 @@ xfs_swap_extents( src_log_flags = XFS_ILOG_CORE; target_log_flags = XFS_ILOG_CORE; - if (xfs_sb_version_hasrmapbt(&mp->m_sb)) - error = xfs_swap_extent_rmap(&tp, ip, tip); - else + if (xfs_sb_version_hasrmapbt(&mp->m_sb)) { + struct xfs_swapext_req req = { + .ip1 = ip, + .ip2 = tip, + .whichfork = XFS_DATA_FORK, + .blockcount = XFS_B_TO_FSB(ip->i_mount, + i_size_read(VFS_I(ip))), + }; + error = xfs_swapext_deferred_bmap(&tp, &req); + } else error = xfs_swap_extent_forks(tp, ip, tip, &src_log_flags, &target_log_flags); - if (error) + if (error) { + trace_xfs_swap_extent_error(ip, error, _THIS_IP_); goto out_trans_cancel; + } /* Do we have to swap reflink flags? */ - if ((ip->i_d.di_flags2 & XFS_DIFLAG2_REFLINK) ^ + if (!xfs_sb_version_hasrmapbt(&mp->m_sb) && + (ip->i_d.di_flags2 & XFS_DIFLAG2_REFLINK) ^ (tip->i_d.di_flags2 & XFS_DIFLAG2_REFLINK)) { f = ip->i_d.di_flags2 & XFS_DIFLAG2_REFLINK; ip->i_d.di_flags2 &= ~XFS_DIFLAG2_REFLINK; diff --git a/fs/xfs/xfs_trace.h b/fs/xfs/xfs_trace.h index 2b2752152a94..37ff54c34b0b 100644 --- a/fs/xfs/xfs_trace.h +++ b/fs/xfs/xfs_trace.h @@ -3160,14 +3160,11 @@ DEFINE_INODE_ERROR_EVENT(xfs_reflink_end_cow_error); DEFINE_INODE_IREC_EVENT(xfs_reflink_cancel_cow); -/* rmap swapext tracepoints */ -DEFINE_INODE_IREC_EVENT(xfs_swap_extent_rmap_remap); -DEFINE_INODE_IREC_EVENT(xfs_swap_extent_rmap_remap_piece); -DEFINE_INODE_ERROR_EVENT(xfs_swap_extent_rmap_error); /* swapext tracepoints */ DEFINE_DOUBLE_IO_EVENT(xfs_file_swap_range); DEFINE_INODE_ERROR_EVENT(xfs_file_swap_range_error); +DEFINE_INODE_ERROR_EVENT(xfs_swap_extent_error); DEFINE_INODE_IREC_EVENT(xfs_swapext_extent1); DEFINE_INODE_IREC_EVENT(xfs_swapext_extent2); DEFINE_ITRUNC_EVENT(xfs_swapext_update_inode_size); |