summaryrefslogtreecommitdiff
path: root/fs/xfs/xfs_reflink.c
diff options
context:
space:
mode:
authorDarrick J. Wong <darrick.wong@oracle.com>2018-10-30 10:47:06 +1100
committerDave Chinner <david@fromorbit.com>2018-10-30 10:47:06 +1100
commit3f68c1f562f1e4c5e1a515b392a2e0a509a342d5 (patch)
tree0514695ce6f460cc00d532e88438c14af1431594 /fs/xfs/xfs_reflink.c
parent9f04aaffddb3e487f3eda1945f1a9531d6cc7628 (diff)
xfs: support returning partial reflink results
Back when the XFS reflink code only supported clone_file_range, we were only able to return zero or negative error codes to userspace. However, now that copy_file_range (which returns bytes copied) can use XFS' clone_file_range, we have the opportunity to return partial results. For example, if userspace sends a 1GB clone request and we run out of space halfway through, we at least can tell userspace that we completed 512M of that request like a regular write. Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com> Reviewed-by: Dave Chinner <dchinner@redhat.com> Signed-off-by: Dave Chinner <david@fromorbit.com>
Diffstat (limited to 'fs/xfs/xfs_reflink.c')
-rw-r--r--fs/xfs/xfs_reflink.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c
index 79dec457f7fb..4abb2aea8f31 100644
--- a/fs/xfs/xfs_reflink.c
+++ b/fs/xfs/xfs_reflink.c
@@ -1122,13 +1122,15 @@ xfs_reflink_remap_blocks(
loff_t pos_in,
struct xfs_inode *dest,
loff_t pos_out,
- loff_t remap_len)
+ loff_t remap_len,
+ loff_t *remapped)
{
struct xfs_bmbt_irec imap;
xfs_fileoff_t srcoff;
xfs_fileoff_t destoff;
xfs_filblks_t len;
xfs_filblks_t range_len;
+ xfs_filblks_t remapped_len = 0;
xfs_off_t new_isize = pos_out + remap_len;
int nimaps;
int error = 0;
@@ -1175,10 +1177,13 @@ xfs_reflink_remap_blocks(
srcoff += range_len;
destoff += range_len;
len -= range_len;
+ remapped_len += range_len;
}
if (error)
trace_xfs_reflink_remap_blocks_error(dest, error, _RET_IP_);
+ *remapped = min_t(loff_t, remap_len,
+ XFS_FSB_TO_B(src->i_mount, remapped_len));
return error;
}
@@ -1387,7 +1392,7 @@ out_unlock:
/*
* Link a range of blocks from one file to another.
*/
-int
+loff_t
xfs_reflink_remap_range(
struct file *file_in,
loff_t pos_in,
@@ -1401,8 +1406,9 @@ xfs_reflink_remap_range(
struct inode *inode_out = file_inode(file_out);
struct xfs_inode *dest = XFS_I(inode_out);
struct xfs_mount *mp = src->i_mount;
+ loff_t remapped = 0;
xfs_extlen_t cowextsize;
- ssize_t ret;
+ int ret;
if (!xfs_sb_version_hasreflink(&mp->m_sb))
return -EOPNOTSUPP;
@@ -1418,7 +1424,8 @@ xfs_reflink_remap_range(
trace_xfs_reflink_remap_range(src, pos_in, len, dest, pos_out);
- ret = xfs_reflink_remap_blocks(src, pos_in, dest, pos_out, len);
+ ret = xfs_reflink_remap_blocks(src, pos_in, dest, pos_out, len,
+ &remapped);
if (ret)
goto out_unlock;
@@ -1441,7 +1448,7 @@ out_unlock:
xfs_reflink_remap_unlock(file_in, file_out);
if (ret)
trace_xfs_reflink_remap_range_error(dest, ret, _RET_IP_);
- return ret;
+ return remapped > 0 ? remapped : ret;
}
/*