summaryrefslogtreecommitdiff
path: root/fs/xfs/xfs_swaprange.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/xfs/xfs_swaprange.c')
-rw-r--r--fs/xfs/xfs_swaprange.c41
1 files changed, 36 insertions, 5 deletions
diff --git a/fs/xfs/xfs_swaprange.c b/fs/xfs/xfs_swaprange.c
index 68efdda61c5e..901440b812ec 100644
--- a/fs/xfs/xfs_swaprange.c
+++ b/fs/xfs/xfs_swaprange.c
@@ -174,9 +174,6 @@ xfs_swap_range(
struct xfs_trans *tp;
int error;
- if (!xfs_sb_version_hasatomicswap(&mp->m_sb))
- return -EOPNOTSUPP;
-
req.startoff1 = XFS_B_TO_FSBT(mp, fsr->file1_offset);
req.startoff2 = XFS_B_TO_FSBT(mp, fsr->file2_offset);
req.blockcount = XFS_B_TO_FSB(mp, fsr->length);
@@ -246,11 +243,45 @@ xfs_swap_range(
if (error)
goto out_trans_cancel;
- /* Perform the file range swap. */
if (fsr->flags & FILE_SWAP_RANGE_TO_EOF)
req.flags |= XFS_SWAPEXT_SET_SIZES;
- error = xfs_swapext_atomic(&tp, &req);
+ /* Perform the file range swap... */
+ if (xfs_sb_version_hasatomicswap(&mp->m_sb)) {
+ /* ...by using the atomic swap, since it's available. */
+ error = xfs_swapext_atomic(&tp, &req);
+ } else if ((fsr->flags & FILE_SWAP_RANGE_NONATOMIC) &&
+ (xfs_sb_version_hasreflink(&mp->m_sb) ||
+ xfs_sb_version_hasrmapbt(&mp->m_sb))) {
+ /*
+ * ...by using deferred bmap operations, which are only
+ * supported if userspace is ok with a non-atomic swap
+ * (e.g. xfs_fsr) and the log supports deferred bmap.
+ */
+ error = xfs_swapext_deferred_bmap(&tp, &req);
+ } else if ((fsr->flags & FILE_SWAP_RANGE_NONATOMIC) &&
+ (fsr->flags & FILE_SWAP_RANGE_FULL_FILES) &&
+ !(fsr->flags & FILE_SWAP_RANGE_TO_EOF) &&
+ fsr->file1_offset == 0 && fsr->file2_offset == 0 &&
+ fsr->length == ip1->i_d.di_size &&
+ fsr->length == ip2->i_d.di_size) {
+ /*
+ * ...by using the old bmap owner change code, if we're a
+ * defrag tool doing a full file swap and we're ok with
+ * non-atomic mode.
+ */
+ error = xfs_swap_extents_check_format(ip2, ip1);
+ if (error) {
+ xfs_notice(mp,
+ "%s: inode 0x%llx format is incompatible for exchanging.",
+ __func__, ip2->i_ino);
+ goto out_trans_cancel;
+ }
+ error = xfs_swap_extent_forks(&tp, &req);
+ } else {
+ /* ...or not at all, because we cannot do it. */
+ error = -EOPNOTSUPP;
+ }
if (error)
goto out_trans_cancel;