summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarrick J. Wong <darrick.wong@oracle.com>2020-04-09 10:24:19 -0700
committerDarrick J. Wong <darrick.wong@oracle.com>2020-06-01 21:16:49 -0700
commit558a2e12d27a76a4b6d8501f3af9415dd6178581 (patch)
tree7d151788577260d33c0bab7990e6c088fc5139cb
parent0d456752a3e273b755bd993537b2e6246bdb88a5 (diff)
xfs: allow xfs_swap_range to use older extent swap algorithms
If userspace permits non-atomic swap operations, use the older code paths to implement the same functionality. Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
-rw-r--r--fs/xfs/xfs_bmap_util.c4
-rw-r--r--fs/xfs/xfs_bmap_util.h4
-rw-r--r--fs/xfs/xfs_swaprange.c41
3 files changed, 42 insertions, 7 deletions
diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c
index 71165ae1aa7c..a0ce5e5dd5e4 100644
--- a/fs/xfs/xfs_bmap_util.c
+++ b/fs/xfs/xfs_bmap_util.c
@@ -1256,7 +1256,7 @@ out_trans_cancel:
* reject and log the attempt. basically we are putting the responsibility on
* userspace to get this right.
*/
-static int
+int
xfs_swap_extents_check_format(
struct xfs_inode *ip, /* target inode */
struct xfs_inode *tip) /* tmp inode */
@@ -1393,7 +1393,7 @@ xfs_swap_change_owner(
}
/* Swap the extents of two files by swapping data forks. */
-STATIC int
+int
xfs_swap_extent_forks(
struct xfs_trans **tpp,
struct xfs_swapext_req *req)
diff --git a/fs/xfs/xfs_bmap_util.h b/fs/xfs/xfs_bmap_util.h
index 9f993168b55b..de3173e64f47 100644
--- a/fs/xfs/xfs_bmap_util.h
+++ b/fs/xfs/xfs_bmap_util.h
@@ -69,6 +69,10 @@ int xfs_free_eofblocks(struct xfs_inode *ip);
int xfs_swap_extents(struct xfs_inode *ip, struct xfs_inode *tip,
struct xfs_swapext *sx);
+struct xfs_swapext_req;
+int xfs_swap_extent_forks(struct xfs_trans **tpp, struct xfs_swapext_req *req);
+int xfs_swap_extents_check_format(struct xfs_inode *ip, struct xfs_inode *tip);
+
xfs_daddr_t xfs_fsb_to_db(struct xfs_inode *ip, xfs_fsblock_t fsb);
xfs_extnum_t xfs_bmap_count_leaves(struct xfs_ifork *ifp, xfs_filblks_t *count);
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;