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>
This commit is contained in:
parent
9f04aaffdd
commit
3f68c1f562
|
@ -928,14 +928,11 @@ xfs_file_remap_range(
|
|||
loff_t len,
|
||||
unsigned int remap_flags)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (remap_flags & ~(REMAP_FILE_DEDUP | REMAP_FILE_ADVISORY))
|
||||
return -EINVAL;
|
||||
|
||||
ret = xfs_reflink_remap_range(file_in, pos_in, file_out, pos_out,
|
||||
return xfs_reflink_remap_range(file_in, pos_in, file_out, pos_out,
|
||||
len, remap_flags);
|
||||
return ret < 0 ? ret : len;
|
||||
}
|
||||
|
||||
STATIC int
|
||||
|
|
|
@ -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 @@ xfs_reflink_remap_prep(
|
|||
/*
|
||||
* 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 @@ xfs_reflink_remap_range(
|
|||
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;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -27,7 +27,7 @@ extern int xfs_reflink_cancel_cow_range(struct xfs_inode *ip, xfs_off_t offset,
|
|||
extern int xfs_reflink_end_cow(struct xfs_inode *ip, xfs_off_t offset,
|
||||
xfs_off_t count);
|
||||
extern int xfs_reflink_recover_cow(struct xfs_mount *mp);
|
||||
extern int xfs_reflink_remap_range(struct file *file_in, loff_t pos_in,
|
||||
extern loff_t xfs_reflink_remap_range(struct file *file_in, loff_t pos_in,
|
||||
struct file *file_out, loff_t pos_out, loff_t len,
|
||||
unsigned int remap_flags);
|
||||
extern int xfs_reflink_inode_has_shared_extents(struct xfs_trans *tp,
|
||||
|
|
Loading…
Reference in New Issue