fs: fixes for serious clone/dedupe problems
Subsystems (13)
v6 cover fs: fixes for serious clone/dedupe problems
Hi all,
Dave, Eric, and I have been chasing a stale data exposure bug in the XFS reflink implementation, and tracked it down to reflink forgetting to do some of the file-extending activities that must happen for regular writes.
We then started auditing the clone, dedupe, and copyfile code and realized that from a file contents perspective, clonerange isn't any different from a regular file write. Unfortunately, we also noticed that *unlike* a regular write, clonerange skips a ton of overflow checks, such as validating the ranges against s_maxbytes, MAX_NON_LFS, and RLIMIT_FSIZE. We also observed that cloning into a file did not strip security privileges (suid, capabilities) like a regular write would. I also noticed that xfs and ocfs2 need to dump the page cache before remapping blocks, not after.
In fixing the range checking problems I also realized that both dedupe and copyfile tell userspace how much of the requested operation was acted upon. Since the range validation can shorten a clone request (or we can ENOSPC midway through), we might as well plumb the short operation reporting back through the VFS indirection code to userspace. I added a few more cleanups to the xfs code per reviewer suggestions.
So, here's the whole giant pile of patches[1] that fix all the problems. This branch is against current upstream (4.19-rc8). The patch "generic: test reflink side effects" recently sent to fstests exercises the fixes in this series. Tests are in [2].
--D
[1] https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux.git/log/?h=djwong-devel
[2] https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfstests-dev.git/log/?h=djwong-devel
PATCH v6 1/29 vfs: vfs_clone_file_prep_inodes should return EINVAL for a clone from beyond EOF
From: Darrick J. Wong <[email protected]>
vfs_clone_file_prep_inodes cannot return 0 if it is asked to remap from a zero byte file because that's what btrfs does.
--- fs/read_write.c | 3 --- 1 file changed, 3 deletions(-)
fs/read_write.c +0 -3
@@ -1740,10 +1740,7 @@ int vfs_clone_file_prep_inodes(struct inode *inode_in, loff_t pos_in,if (!S_ISREG (inode_in->i_mode) || !S_ISREG (inode_out->i_mode))return -EINVAL ; -/* Are we going all the way to the end? */ isize =i_size_read (inode_in); -if (isize ==0 ) -return 0 ;/* Zero length dedupe exits immediately; reflink goes to EOF. */ if (*len ==0 ) {
PATCH v6 2/29 vfs: check file ranges before cloning files
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Move the file range checks from vfs_clone_file_prep into a separate generic_remap_checks function so that all the checks are collected in a central location. This forms the basis for adding more checks from generic_write_checks that will make cloning's input checking more consistent with write input checking.
--- fs/ocfs2/refcounttree.c | 2 + fs/read_write.c | 55 +++++++++---------------------------- fs/xfs/xfs_reflink.c | 2 + include/linux/fs.h | 9 ++++-- mm/filemap.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 90 insertions(+), 47 deletions(-)
fs/ocfs2/refcounttree.c +1 -1
@@ -4850,7 +4850,7 @@ int ocfs2_reflink_remap_range(struct file *file_in, (OCFS2_I(inode_out)->ip_flags & OCFS2_INODE_SYSTEM_FILE)) goto out_unlock; - ret =vfs_clone_file_prep_inodes (inode_in, pos_in, inode_out, pos_out, + ret =vfs_clone_file_prep (file_in, pos_in, file_out, pos_out, &len, is_dedupe);if (ret <=0 ) goto out_unlock;
fs/read_write.c +13 -42
88 lines not on this page · raw message
fs/xfs/xfs_reflink.c +1 -1
@@ -1326,7 +1326,7 @@ xfs_reflink_remap_prep(if (IS_DAX (inode_in) ||IS_DAX (inode_out)) goto out_unlock; - ret =vfs_clone_file_prep_inodes (inode_in, pos_in, inode_out, pos_out, + ret =vfs_clone_file_prep (file_in, pos_in, file_out, pos_out, len, is_dedupe);if (ret <=0 ) goto out_unlock;
include/linux/fs.h +6 -3
@@ -1825,9 +1825,9 @@ extern ssize_t vfs_readv(struct file *, const struct iovec __user *, unsigned long, loff_t *, rwf_t);extern ssize_t vfs_copy_file_range (struct file *,loff_t ,struct file *,loff_t ,size_t ,unsigned int ); -extern int vfs_clone_file_prep_inodes (struct inode *inode_in,loff_t pos_in, -struct inode *inode_out,loff_t pos_out, -u64 *len,bool is_dedupe); +extern int vfs_clone_file_prep (struct file *file_in,loff_t pos_in, +struct file *file_out,loff_t pos_out, +u64 *count,bool is_dedupe);extern int do_clone_file_range (struct file *file_in,loff_t pos_in,struct file *file_out,loff_t pos_out,u64 len); extern int vfs_clone_file_range(struct file *file_in, loff_t pos_in,
@@ -2967,6 +2967,9 @@ extern int sb_min_blocksize(struct super_block *, int);extern int generic_file_mmap (struct file *,struct vm_area_struct *);extern int generic_file_readonly_mmap (struct file *,struct vm_area_struct *);extern ssize_t generic_write_checks (struct kiocb *,struct iov_iter *); +extern int generic_remap_checks (struct file *file_in,loff_t pos_in, +struct file *file_out,loff_t pos_out, +uint64_t *count,bool is_dedupe);extern ssize_t generic_file_read_iter (struct kiocb *,struct iov_iter *);extern ssize_t __generic_file_write_iter (struct kiocb *,struct iov_iter *);extern ssize_t generic_file_write_iter (struct kiocb *,struct iov_iter *);
mm/filemap.c +69 -0
75 lines not on this page · raw message
PATCH v6 3/29 vfs: exit early from zero length remap operations
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
If a remap caller asks us to remap to the source file's EOF and the source file length leaves us with a zero byte request, exit early.
--- fs/read_write.c | 2 ++ 1 file changed, 2 insertions(+)
fs/read_write.c +2 -0
@@ -1748,6 +1748,8 @@ int vfs_clone_file_prep(struct file *file_in, loff_t pos_in,if (pos_in > isize)return -EINVAL ; *len = isize - pos_in; +if (*len ==0 ) +return 0 ; }/* Check that we don't violate system file offset limits. */
PATCH v6 4/29 vfs: strengthen checking of file range inputs to generic_remap_checks
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
File range remapping, if allowed to run past the destination file's EOF, is an optimization on a regular file write. Regular file writes that extend the file length are subject to various constraints which are not checked by range cloning.
This is a correctness problem because we're never allowed to touch ranges that the page cache can't support (s_maxbytes); we're not supposed to deal with large offsets (MAX_NON_LFS) if O_LARGEFILE isn't set; and we must obey resource limits (RLIMIT_FSIZE).
Therefore, add these checks to the new generic_remap_checks function so that we curtail unexpected behavior.
--- mm/filemap.c | 91 ++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 59 insertions(+), 32 deletions(-)
mm/filemap.c +59 -32
@@ -2915,6 +2915,49 @@ struct page *read_cache_page_gfp(struct address_space *mapping, }EXPORT_SYMBOL (read_cache_page_gfp); +static int generic_access_check_limits (struct file *file,loff_t pos, +loff_t *count) +{ +struct inode *inode = file->f_mapping->host; + +/* Don't exceed the LFS limits. */ +if (unlikely (pos + *count >MAX_NON_LFS && + !(file->f_flags &O_LARGEFILE ))) { +if (pos >=MAX_NON_LFS ) +return -EFBIG ; + *count =min (*count, (loff_t )MAX_NON_LFS - pos); + } + +/* +* Don't operate on ranges the page cache doesn't support. +* +* If we have written data it becomes a short write. If we have +* exceeded without writing data we send a signal and return EFBIG. +* Linus frestrict idea will clean these up nicely.. +*/ +if (unlikely (pos >= inode->i_sb->s_maxbytes)) +return -EFBIG ; + + *count =min (*count, inode->i_sb->s_maxbytes - pos); +return 0 ; +} + +static int generic_write_check_limits (struct file *file,loff_t pos, +loff_t *count) +{ +unsigned long limit =rlimit (RLIMIT_FSIZE ); + +if (limit !=RLIM_INFINITY ) { +if (pos >= limit) { +send_sig (SIGXFSZ , current,0 ); +return -EFBIG ; + } + *count =min (*count, (loff_t )limit - pos); + } + +return generic_access_check_limits (file, pos, count); +} +/* * Performs necessary checks before doing a write *
@@ -2926,8 +2969,8 @@ inline ssize_t generic_write_checks(struct kiocb *iocb, struct iov_iter *from) {struct file *file = iocb->ki_filp;struct inode *inode = file->f_mapping->host; -unsigned long limit =rlimit (RLIMIT_FSIZE ); -loff_t pos; +loff_t count; +int ret;if (!iov_iter_count (from))return 0 ;
@@ -2936,40 +2979,15 @@ inline ssize_t generic_write_checks(struct kiocb *iocb, struct iov_iter *from)if (iocb->ki_flags &IOCB_APPEND ) iocb->ki_pos =i_size_read (inode); - pos = iocb->ki_pos; -if ((iocb->ki_flags &IOCB_NOWAIT ) && !(iocb->ki_flags &IOCB_DIRECT ))return -EINVAL ; -if (limit !=RLIM_INFINITY ) { -if (iocb->ki_pos >= limit) { -send_sig (SIGXFSZ , current,0 ); -return -EFBIG ; - } -iov_iter_truncate (from, limit - (unsigned long )pos); - } + count =iov_iter_count (from); + ret =generic_write_check_limits (file, iocb->ki_pos, &count); +if (ret) +return ret; -/* -* LFS rule -*/ -if (unlikely (pos +iov_iter_count (from) >MAX_NON_LFS && - !(file->f_flags &O_LARGEFILE ))) { -if (pos >=MAX_NON_LFS ) -return -EFBIG ; -iov_iter_truncate (from,MAX_NON_LFS - (unsigned long )pos); - } - -/* -* Are we about to exceed the fs block limit ? -* -* If we have written data it becomes a short write. If we have -* exceeded without writing data we send a signal and return EFBIG. -* Linus frestrict idea will clean these up nicely.. -*/ -if (unlikely (pos >= inode->i_sb->s_maxbytes)) -return -EFBIG ; - -iov_iter_truncate (from, inode->i_sb->s_maxbytes - pos); +iov_iter_truncate (from, count);return iov_iter_count (from); }EXPORT_SYMBOL (generic_write_checks);
@@ -2991,6 +3009,7 @@ int generic_remap_checks(struct file *file_in, loff_t pos_in,uint64_t bcount;loff_t size_in, size_out;loff_t bs = inode_out->i_sb->s_blocksize; +int ret;/* The start of both ranges must be aligned to an fs block. */ if (!IS_ALIGNED (pos_in, bs) || !IS_ALIGNED (pos_out, bs))
@@ -3014,6 +3033,14 @@ int generic_remap_checks(struct file *file_in, loff_t pos_in,return -EINVAL ; count =min (count, size_in - (uint64_t )pos_in); + ret =generic_access_check_limits (file_in, pos_in, &count); +if (ret) +return ret; + + ret =generic_write_check_limits (file_out, pos_out, &count); +if (ret) +return ret; +/* * If the user wanted us to link to the infile's EOF, round up to the * next block boundary for this check.
Al Viro
maintainerRe: [PATCH 04/29] vfs: strengthen checking of file range inputs to generic_remap_checks
mm/filemap.c struct page *read_cache_page_gfp(struct address_space *mapping, · line 2928
Quoted 11 lines · Darrick J. Wong
mm/filemap.c +11
-0+static int generic_access_check_limits (struct file *file,loff_t pos, +loff_t *count) +{ +struct inode *inode = file->f_mapping->host; + +/* Don't exceed the LFS limits. */ +if (unlikely (pos + *count >MAX_NON_LFS && + !(file->f_flags &O_LARGEFILE ))) { +if (pos >=MAX_NON_LFS ) +return -EFBIG ; + *count =min (*count, (loff_t )MAX_NON_LFS - pos);
Can that can be different from MAX_NON_LFS - pos?
Quoted 5 lines
mm/filemap.c +5
-0+ } + +/* +* Don't operate on ranges the page cache doesn't support. +*
mm/filemap.c struct page *read_cache_page_gfp(struct address_space *mapping, · line 2943
Quoted 10 lines
mm/filemap.c +10
-0+* If we have written data it becomes a short write. If we have +* exceeded without writing data we send a signal and return EFBIG. +* Linus frestrict idea will clean these up nicely.. +*/ +if (unlikely (pos >= inode->i_sb->s_maxbytes)) +return -EFBIG ; + + *count =min (*count, inode->i_sb->s_maxbytes - pos); +return 0 ; +}
Anyway, I would rather do this here:
struct inode *inode = file->f_mapping->host; loff_t max_size = inode->i_sb->s_maxbytes; if (!(file->f_flags & O_LARGEFILE)) max_size = MAX_NON_LFS; if (unlikely(pos >= max_size)) return -EFBIG; *count = min(*count, max_size - pos); return 0;
Re: [PATCH 04/29] vfs: strengthen checking of file range inputs to generic_remap_checks
Quoted 33 lines · Al Viro
mm/filemap.c struct page *read_cache_page_gfp(struct address_space *mapping, · line 2928
Quoted 11 lines · Darrick J. Wong
mm/filemap.c +11
-0+static int generic_access_check_limits (struct file *file,loff_t pos, +loff_t *count) +{ +struct inode *inode = file->f_mapping->host; + +/* Don't exceed the LFS limits. */ +if (unlikely (pos + *count >MAX_NON_LFS && + !(file->f_flags &O_LARGEFILE ))) { +if (pos >=MAX_NON_LFS ) +return -EFBIG ; + *count =min (*count, (loff_t )MAX_NON_LFS - pos);Can that can be different from
MAX_NON_LFS- pos?Quoted 5 lines
mm/filemap.c +5
-0+ } + +/* +* Don't operate on ranges the page cache doesn't support. +* mm/filemap.c struct page *read_cache_page_gfp(struct address_space *mapping, · line 2943
Quoted 10 lines
mm/filemap.c +10
-0+* If we have written data it becomes a short write. If we have +* exceeded without writing data we send a signal and return EFBIG. +* Linus frestrict idea will clean these up nicely.. +*/ +if (unlikely (pos >= inode->i_sb->s_maxbytes)) +return -EFBIG ; + + *count =min (*count, inode->i_sb->s_maxbytes - pos); +return 0 ; +}Anyway, I would rather do this here:
Quoted 10 lines
struct inode *inode = file->f_mapping->host; loff_t max_size = inode->i_sb->s_maxbytes; if (!(file->f_flags & O_LARGEFILE)) max_size = MAX_NON_LFS; if (unlikely(pos >= max_size)) return -EFBIG; *count = min(*count, max_size - pos); return 0;
Sounds much better to me. :)
--D
PATCH v2 4/29 vfs: strengthen checking of file range inputs to generic_remap_checks
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
File range remapping, if allowed to run past the destination file's EOF, is an optimization on a regular file write. Regular file writes that extend the file length are subject to various constraints which are not checked by range cloning.
This is a correctness problem because we're never allowed to touch ranges that the page cache can't support (s_maxbytes); we're not supposed to deal with large offsets (MAX_NON_LFS) if O_LARGEFILE isn't set; and we must obey resource limits (RLIMIT_FSIZE).
Therefore, add these checks to the new generic_remap_checks function so that we curtail unexpected behavior.
---
v2: restructurings as recommended by Al Viro
--- mm/filemap.c | 84 ++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 52 insertions(+), 32 deletions(-)
mm/filemap.c +52 -32
@@ -2915,6 +2915,42 @@ struct page *read_cache_page_gfp(struct address_space *mapping, }EXPORT_SYMBOL (read_cache_page_gfp); +/* +* Don't operate on ranges the page cache doesn't support, and don't exceed the +* LFS limits. If pos is under the limit it becomes a short access. If it +* exceeds the limit we return -EFBIG. +*/ +static int generic_access_check_limits (struct file *file,loff_t pos, +loff_t *count) +{ +struct inode *inode = file->f_mapping->host; +loff_t max_size = inode->i_sb->s_maxbytes; + +if (!(file->f_flags &O_LARGEFILE )) + max_size =MAX_NON_LFS ; + +if (unlikely (pos >= max_size)) +return -EFBIG ; + *count =min (*count, max_size - pos); +return 0 ; +} + +static int generic_write_check_limits (struct file *file,loff_t pos, +loff_t *count) +{ +loff_t limit =rlimit (RLIMIT_FSIZE ); + +if (limit !=RLIM_INFINITY ) { +if (pos >= limit) { +send_sig (SIGXFSZ , current,0 ); +return -EFBIG ; + } + *count =min (*count, limit - pos); + } + +return generic_access_check_limits (file, pos, count); +} +/* * Performs necessary checks before doing a write *
@@ -2926,8 +2962,8 @@ inline ssize_t generic_write_checks(struct kiocb *iocb, struct iov_iter *from) {struct file *file = iocb->ki_filp;struct inode *inode = file->f_mapping->host; -unsigned long limit =rlimit (RLIMIT_FSIZE ); -loff_t pos; +loff_t count; +int ret;if (!iov_iter_count (from))return 0 ;
@@ -2936,40 +2972,15 @@ inline ssize_t generic_write_checks(struct kiocb *iocb, struct iov_iter *from)if (iocb->ki_flags &IOCB_APPEND ) iocb->ki_pos =i_size_read (inode); - pos = iocb->ki_pos; -if ((iocb->ki_flags &IOCB_NOWAIT ) && !(iocb->ki_flags &IOCB_DIRECT ))return -EINVAL ; -if (limit !=RLIM_INFINITY ) { -if (iocb->ki_pos >= limit) { -send_sig (SIGXFSZ , current,0 ); -return -EFBIG ; - } -iov_iter_truncate (from, limit - (unsigned long )pos); - } - -/* -* LFS rule -*/ -if (unlikely (pos +iov_iter_count (from) >MAX_NON_LFS && - !(file->f_flags &O_LARGEFILE ))) { -if (pos >=MAX_NON_LFS ) -return -EFBIG ; -iov_iter_truncate (from,MAX_NON_LFS - (unsigned long )pos); - } - -/* -* Are we about to exceed the fs block limit ? -* -* If we have written data it becomes a short write. If we have -* exceeded without writing data we send a signal and return EFBIG. -* Linus frestrict idea will clean these up nicely.. -*/ -if (unlikely (pos >= inode->i_sb->s_maxbytes)) -return -EFBIG ; + count =iov_iter_count (from); + ret =generic_write_check_limits (file, iocb->ki_pos, &count); +if (ret) +return ret; -iov_iter_truncate (from, inode->i_sb->s_maxbytes - pos); +iov_iter_truncate (from, count);return iov_iter_count (from); }EXPORT_SYMBOL (generic_write_checks);
@@ -2991,6 +3002,7 @@ int generic_remap_checks(struct file *file_in, loff_t pos_in,uint64_t bcount;loff_t size_in, size_out;loff_t bs = inode_out->i_sb->s_blocksize; +int ret;/* The start of both ranges must be aligned to an fs block. */ if (!IS_ALIGNED (pos_in, bs) || !IS_ALIGNED (pos_out, bs))
@@ -3014,6 +3026,14 @@ int generic_remap_checks(struct file *file_in, loff_t pos_in,return -EINVAL ; count =min (count, size_in - (uint64_t )pos_in); + ret =generic_access_check_limits (file_in, pos_in, &count); +if (ret) +return ret; + + ret =generic_write_check_limits (file_out, pos_out, &count); +if (ret) +return ret; +/* * If the user wanted us to link to the infile's EOF, round up to the * next block boundary for this check.
PATCH v6 5/29 vfs: avoid problematic remapping requests into partial EOF block
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
A deduplication data corruption is exposed in XFS and btrfs. It is caused by extending the block match range to include the partial EOF block, but then allowing unknown data beyond EOF to be considered a "match" to data in the destination file because the comparison is only made to the end of the source file. This corrupts the destination file when the source extent is shared with it.
The VFS remapping prep functions only support whole block dedupe, but we still need to appear to support whole file dedupe correctly. Hence if the dedupe request includes the last block of the souce file, don't include it in the actual dedupe operation. If the rest of the range dedupes successfully, then reject the entire request. A subsequent patch will enable us to shorten dedupe requests correctly.
When reflinking sub-file ranges, a data corruption can occur when the source file range includes a partial EOF block. This shares the unknown data beyond EOF into the second file at a position inside EOF, exposing stale data in the second file.
If the reflink request includes the last block of the souce file, only proceed with the reflink operation if it lands at or past the destination file's current EOF. If it lands within the destination file EOF, reject the entire request with -EINVAL and make the caller go the hard way. A subsequent patch will enable us to shorten reflink requests correctly.
--- fs/read_write.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)
fs/read_write.c +33 -0
@@ -1708,6 +1708,34 @@ static int clone_verify_area(struct file *file, loff_t pos, u64 len, bool write)return security_file_permission (file, write ?MAY_WRITE :MAY_READ ); } +/* +* Ensure that we don't remap a partial EOF block in the middle of something +* else. Assume that the offsets have already been checked for block +* alignment. +* +* For deduplication we always scale down to the previous block because we +* can't meaningfully compare post-EOF contents. +* +* For clone we only link a partial EOF block above the destination file's EOF. +*/ +static int generic_remap_check_len (struct inode *inode_in, +struct inode *inode_out, +loff_t pos_out, +u64 *len, +bool is_dedupe) +{ +u64 blkmask =i_blocksize (inode_in) -1 ; + +if ((*len & blkmask) ==0 ) +return 0 ; + +if (is_dedupe) + *len &= ~blkmask; +else if (pos_out + *len <i_size_read (inode_out)) +return -EINVAL ; + +return 0 ; +}/* * Check that the two inodes are eligible for cloning, the ranges make
@@ -1787,6 +1815,11 @@ int vfs_clone_file_prep(struct file *file_in, loff_t pos_in,return -EBADE ; } + ret =generic_remap_check_len (inode_in, inode_out, pos_out, len, + is_dedupe); +if (ret) +return ret; +return 1 ; }EXPORT_SYMBOL (vfs_clone_file_prep);
PATCH v6 6/29 vfs: skip zero-length dedupe requests
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Don't bother calling the filesystem for a zero-length dedupe request; we can return zero and exit.
--- fs/read_write.c | 5 +++++ 1 file changed, 5 insertions(+)
fs/read_write.c +5 -0
@@ -2009,6 +2009,11 @@ int vfs_dedupe_file_range_one(struct file *src_file, loff_t src_pos,if (!dst_file->f_op->dedupe_file_range) goto out_drop_write; +if (len ==0 ) { + ret =0 ; + goto out_drop_write; + } + ret = dst_file->f_op->dedupe_file_range (src_file, src_pos, dst_file, dst_pos, len); out_drop_write:
PATCH v6 7/29 vfs: rename vfs_clone_file_prep to be more descriptive
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
The vfs_clone_file_prep is a generic function to be called by filesystem implementations only. Rename the prefix to generic_ and make it more clear that it applies to remap operations, not just clones.
--- fs/ocfs2/refcounttree.c | 2 +- fs/read_write.c | 8 ++++---- fs/xfs/xfs_reflink.c | 2 +- include/linux/fs.h | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-)
fs/ocfs2/refcounttree.c +1 -1
@@ -4850,7 +4850,7 @@ int ocfs2_reflink_remap_range(struct file *file_in, (OCFS2_I(inode_out)->ip_flags & OCFS2_INODE_SYSTEM_FILE)) goto out_unlock; - ret =vfs_clone_file_prep (file_in, pos_in, file_out, pos_out, + ret =generic_remap_file_range_prep (file_in, pos_in, file_out, pos_out, &len, is_dedupe);if (ret <=0 ) goto out_unlock;
fs/read_write.c +4 -4
@@ -1745,9 +1745,9 @@ static int generic_remap_check_len(struct inode *inode_in,* Returns: 0 for "nothing to clone", 1 for "something to clone", or * the usual negative error code. */ -int vfs_clone_file_prep (struct file *file_in,loff_t pos_in, -struct file *file_out,loff_t pos_out, -u64 *len,bool is_dedupe) +int generic_remap_file_range_prep (struct file *file_in,loff_t pos_in, +struct file *file_out,loff_t pos_out, +u64 *len,bool is_dedupe) {struct inode *inode_in =file_inode (file_in);struct inode *inode_out =file_inode (file_out);
@@ -1822,7 +1822,7 @@ int vfs_clone_file_prep(struct file *file_in, loff_t pos_in,return 1 ; } -EXPORT_SYMBOL (vfs_clone_file_prep); +EXPORT_SYMBOL (generic_remap_file_range_prep);int do_clone_file_range (struct file *file_in,loff_t pos_in,struct file *file_out,loff_t pos_out,u64 len)
fs/xfs/xfs_reflink.c +1 -1
@@ -1326,7 +1326,7 @@ xfs_reflink_remap_prep(if (IS_DAX (inode_in) ||IS_DAX (inode_out)) goto out_unlock; - ret =vfs_clone_file_prep (file_in, pos_in, file_out, pos_out, + ret =generic_remap_file_range_prep (file_in, pos_in, file_out, pos_out, len, is_dedupe);if (ret <=0 ) goto out_unlock;
include/linux/fs.h +3 -3
@@ -1825,9 +1825,9 @@ extern ssize_t vfs_readv(struct file *, const struct iovec __user *, unsigned long, loff_t *, rwf_t);extern ssize_t vfs_copy_file_range (struct file *,loff_t ,struct file *,loff_t ,size_t ,unsigned int ); -extern int vfs_clone_file_prep (struct file *file_in,loff_t pos_in, -struct file *file_out,loff_t pos_out, -u64 *count,bool is_dedupe); +extern int generic_remap_file_range_prep (struct file *file_in,loff_t pos_in, +struct file *file_out,loff_t pos_out, +u64 *count,bool is_dedupe);extern int do_clone_file_range (struct file *file_in,loff_t pos_in,struct file *file_out,loff_t pos_out,u64 len); extern int vfs_clone_file_range(struct file *file_in, loff_t pos_in,
PATCH v6 8/29 vfs: rename clone_verify_area to remap_verify_area
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Since we use clone_verify_area for both clone and dedupe range checks, rename the function to make it clear that it's for both.
--- fs/read_write.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
fs/read_write.c +5 -5
@@ -1686,7 +1686,7 @@ SYSCALL_DEFINE6(copy_file_range, int, fd_in, loff_t __user *, off_in,return ret; } -static int clone_verify_area (struct file *file,loff_t pos,u64 len,bool write) +static int remap_verify_area (struct file *file,loff_t pos,u64 len,bool write) {struct inode *inode =file_inode (file);
@@ -1852,11 +1852,11 @@ int do_clone_file_range(struct file *file_in, loff_t pos_in,if (!file_in->f_op->clone_file_range)return -EOPNOTSUPP ; - ret =clone_verify_area (file_in, pos_in, len, false); + ret =remap_verify_area (file_in, pos_in, len, false);if (ret)return ret; - ret =clone_verify_area (file_out, pos_out, len, true); + ret =remap_verify_area (file_out, pos_out, len, true);if (ret)return ret;
@@ -1989,7 +1989,7 @@ int vfs_dedupe_file_range_one(struct file *src_file, loff_t src_pos,if (ret)return ret; - ret =clone_verify_area (dst_file, dst_pos, len, true); + ret =remap_verify_area (dst_file, dst_pos, len, true);if (ret <0 ) goto out_drop_write;
@@ -2051,7 +2051,7 @@ int vfs_dedupe_file_range(struct file *file, struct file_dedupe_range *same)if (!S_ISREG (src->i_mode)) goto out; - ret =clone_verify_area (file, off, len, false); + ret =remap_verify_area (file, off, len, false);if (ret <0 ) goto out; ret =0 ;
PATCH v6 9/29 vfs: combine the clone and dedupe into a single remap_file_range
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Combine the clone_file_range and dedupe_file_range operations into a single remap_file_range file operation dispatch since they're fundamentally the same operation. The differences between the two can be made in the prep functions.
--- Documentation/filesystems/vfs.txt | 13 +++++------ fs/btrfs/ctree.h | 8 ++----- fs/btrfs/file.c | 3 +- fs/btrfs/ioctl.c | 45 +++++++++++++++++++------------------ fs/cifs/cifsfs.c | 22 +++++++++++------- fs/nfs/nfs4file.c | 10 ++++++-- fs/ocfs2/file.c | 24 +++++++------------- fs/overlayfs/file.c | 30 ++++++++++++++----------- fs/read_write.c | 18 +++++++-------- fs/xfs/xfs_file.c | 23 ++++++------------- include/linux/fs.h | 20 +++++++++++++--- 11 files changed, 110 insertions(+), 106 deletions(-)
Documentation/filesystems/vfs.txt +6 -7
@@ -883,8 +883,9 @@ struct file_operations { unsigned (*mmap_capabilities)(struct file *); #endif ssize_t (*copy_file_range)(struct file *, loff_t, struct file *, loff_t, size_t, unsigned int); - int (*clone_file_range)(struct file *, loff_t, struct file *, loff_t, u64); - int (*dedupe_file_range)(struct file *, loff_t, struct file *, loff_t, u64); + int (*remap_file_range)(struct file *file_in, loff_t pos_in, + struct file *file_out, loff_t pos_out, + u64 len, unsigned int remap_flags); int (*fadvise)(struct file *, loff_t, loff_t, int); };
@@ -960,11 +961,9 @@ otherwise noted. copy_file_range: called by the copy_file_range(2) system call. - clone_file_range: called by the ioctl(2) system call for FICLONERANGE and - FICLONE commands. - - dedupe_file_range: called by the ioctl(2) system call for FIDEDUPERANGE - command. + remap_file_range: called by the ioctl(2) system call for FICLONERANGE and + FICLONE and FIDEDUPERANGE commands to remap file ranges. Note that + a zero length implies "remap to end of source file". fadvise: possibly called by the fadvise64() system call.
fs/btrfs/ctree.h +3 -5
@@ -3218,9 +3218,6 @@ void btrfs_get_block_group_info(struct list_head *groups_list, struct btrfs_ioctl_space_info *space);void btrfs_update_ioctl_balance_args (struct btrfs_fs_info *fs_info,struct btrfs_ioctl_balance_args *bargs); -int btrfs_dedupe_file_range (struct file *src_file,loff_t src_loff, -struct file *dst_file,loff_t dst_loff, -u64 olen);/* file.c */ int __init btrfs_auto_defrag_init (void );
@@ -3250,8 +3247,9 @@ int btrfs_dirty_pages(struct inode *inode, struct page **pages, size_t num_pages, loff_t pos, size_t write_bytes, struct extent_state **cached);int btrfs_fdatawrite_range (struct inode *inode,loff_t start,loff_t end); -int btrfs_clone_file_range (struct file *file_in,loff_t pos_in, -struct file *file_out,loff_t pos_out,u64 len); +int btrfs_remap_file_range (struct file *file_in,loff_t pos_in, +struct file *file_out,loff_t pos_out,u64 len, +unsigned int remap_flags);/* tree-defrag.c */ int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,
fs/btrfs/file.c +1 -2
@@ -3269,8 +3269,7 @@ const struct file_operations btrfs_file_operations = {#ifdef CONFIG_COMPAT .compat_ioctl = btrfs_compat_ioctl, #endif - .clone_file_range = btrfs_clone_file_range, - .dedupe_file_range = btrfs_dedupe_file_range, + .remap_file_range = btrfs_remap_file_range, };void __cold btrfs_auto_defrag_exit (void )
fs/btrfs/ioctl.c +23 -22
58 lines not on this page · raw message
fs/cifs/cifsfs.c +13 -9
@@ -975,8 +975,9 @@ const struct inode_operations cifs_symlink_inode_ops = { .listxattr = cifs_listxattr, }; -static int cifs_clone_file_range (struct file *src_file,loff_t off, -struct file *dst_file,loff_t destoff,u64 len) +static int cifs_remap_file_range (struct file *src_file,loff_t off, +struct file *dst_file,loff_t destoff,u64 len, +unsigned int remap_flags) {struct inode *src_inode =file_inode (src_file);struct inode *target_inode =file_inode (dst_file);
@@ -986,6 +987,9 @@ static int cifs_clone_file_range(struct file *src_file, loff_t off,unsigned int xid;int rc; +if (remap_flags & ~REMAP_FILE_ADVISORY ) +return -EINVAL ; +cifs_dbg (FYI ,"clone range\n" ); xid =get_xid ();
@@ -1134,7 +1138,7 @@ const struct file_operations cifs_file_ops = { .llseek = cifs_llseek, .unlocked_ioctl = cifs_ioctl, .copy_file_range = cifs_copy_file_range, - .clone_file_range = cifs_clone_file_range, + .remap_file_range = cifs_remap_file_range, .setlease = cifs_setlease, .fallocate = cifs_fallocate, };
@@ -1153,7 +1157,7 @@ const struct file_operations cifs_file_strict_ops = { .llseek = cifs_llseek, .unlocked_ioctl = cifs_ioctl, .copy_file_range = cifs_copy_file_range, - .clone_file_range = cifs_clone_file_range, + .remap_file_range = cifs_remap_file_range, .setlease = cifs_setlease, .fallocate = cifs_fallocate, };
@@ -1172,7 +1176,7 @@ const struct file_operations cifs_file_direct_ops = { .splice_write = iter_file_splice_write, .unlocked_ioctl = cifs_ioctl, .copy_file_range = cifs_copy_file_range, - .clone_file_range = cifs_clone_file_range, + .remap_file_range = cifs_remap_file_range, .llseek = cifs_llseek, .setlease = cifs_setlease, .fallocate = cifs_fallocate,
@@ -1191,7 +1195,7 @@ const struct file_operations cifs_file_nobrl_ops = { .llseek = cifs_llseek, .unlocked_ioctl = cifs_ioctl, .copy_file_range = cifs_copy_file_range, - .clone_file_range = cifs_clone_file_range, + .remap_file_range = cifs_remap_file_range, .setlease = cifs_setlease, .fallocate = cifs_fallocate, };
@@ -1209,7 +1213,7 @@ const struct file_operations cifs_file_strict_nobrl_ops = { .llseek = cifs_llseek, .unlocked_ioctl = cifs_ioctl, .copy_file_range = cifs_copy_file_range, - .clone_file_range = cifs_clone_file_range, + .remap_file_range = cifs_remap_file_range, .setlease = cifs_setlease, .fallocate = cifs_fallocate, };
@@ -1227,7 +1231,7 @@ const struct file_operations cifs_file_direct_nobrl_ops = { .splice_write = iter_file_splice_write, .unlocked_ioctl = cifs_ioctl, .copy_file_range = cifs_copy_file_range, - .clone_file_range = cifs_clone_file_range, + .remap_file_range = cifs_remap_file_range, .llseek = cifs_llseek, .setlease = cifs_setlease, .fallocate = cifs_fallocate,
@@ -1239,7 +1243,7 @@ const struct file_operations cifs_dir_ops = { .read = generic_read_dir, .unlocked_ioctl = cifs_ioctl, .copy_file_range = cifs_copy_file_range, - .clone_file_range = cifs_clone_file_range, + .remap_file_range = cifs_remap_file_range, .llseek = generic_file_llseek, .fsync = cifs_dir_fsync, };
fs/nfs/nfs4file.c +7 -3
@@ -180,8 +180,9 @@ static long nfs42_fallocate(struct file *filep, int mode, loff_t offset, loff_treturn nfs42_proc_allocate (filep, offset, len); } -static int nfs42_clone_file_range (struct file *src_file,loff_t src_off, -struct file *dst_file,loff_t dst_off,u64 count) +static int nfs42_remap_file_range (struct file *src_file,loff_t src_off, +struct file *dst_file,loff_t dst_off,u64 count, +unsigned int remap_flags) {struct inode *dst_inode =file_inode (dst_file);struct nfs_server *server =NFS_SERVER (dst_inode);
@@ -190,6 +191,9 @@ static int nfs42_clone_file_range(struct file *src_file, loff_t src_off,bool same_inode = false;int ret; +if (remap_flags & ~REMAP_FILE_ADVISORY ) +return -EINVAL ; +/* check alignment w.r.t. clone_blksize */ ret = -EINVAL ;if (bs) {
@@ -262,7 +266,7 @@ const struct file_operations nfs4_file_operations = { .copy_file_range = nfs4_copy_file_range, .llseek = nfs4_file_llseek, .fallocate = nfs42_fallocate, - .clone_file_range = nfs42_clone_file_range, + .remap_file_range = nfs42_remap_file_range, #else .llseek = nfs_file_llseek,#endif
fs/ocfs2/file.c +8 -16
@@ -2527,24 +2527,18 @@ static loff_t ocfs2_file_llseek(struct file *file, loff_t offset, int whence)return offset; } -static int ocfs2_file_clone_range (struct file *file_in, +static int ocfs2_remap_file_range (struct file *file_in,loff_t pos_in,struct file *file_out,loff_t pos_out, -u64 len) +u64 len, +unsigned int remap_flags) { -return ocfs2_reflink_remap_range (file_in, pos_in, file_out, pos_out, - len, false); -} +if (remap_flags & ~(REMAP_FILE_DEDUP |REMAP_FILE_ADVISORY )) +return -EINVAL ; -static int ocfs2_file_dedupe_range (struct file *file_in, -loff_t pos_in, -struct file *file_out, -loff_t pos_out, -u64 len) -{return ocfs2_reflink_remap_range (file_in, pos_in, file_out, pos_out, - len, true); + len, remap_flags &REMAP_FILE_DEDUP ); }const struct inode_operations ocfs2_file_iops = {
@@ -2586,8 +2580,7 @@ const struct file_operations ocfs2_fops = { .splice_read = generic_file_splice_read, .splice_write = iter_file_splice_write, .fallocate = ocfs2_fallocate, - .clone_file_range = ocfs2_file_clone_range, - .dedupe_file_range = ocfs2_file_dedupe_range, + .remap_file_range = ocfs2_remap_file_range, };const struct file_operations ocfs2_dops = {
@@ -2633,8 +2626,7 @@ const struct file_operations ocfs2_fops_no_plocks = { .splice_read = generic_file_splice_read, .splice_write = iter_file_splice_write, .fallocate = ocfs2_fallocate, - .clone_file_range = ocfs2_file_clone_range, - .dedupe_file_range = ocfs2_file_dedupe_range, + .remap_file_range = ocfs2_remap_file_range, };const struct file_operations ocfs2_dops_no_plocks = {
fs/overlayfs/file.c +17 -13
@@ -489,26 +489,31 @@ static ssize_t ovl_copy_file_range(struct file *file_in, loff_t pos_in, OVL_COPY); } -static int ovl_clone_file_range (struct file *file_in,loff_t pos_in, -struct file *file_out,loff_t pos_out,u64 len) +static int ovl_remap_file_range (struct file *file_in,loff_t pos_in, +struct file *file_out,loff_t pos_out, +u64 len,unsigned int remap_flags) { -return ovl_copyfile (file_in, pos_in, file_out, pos_out, len,0 , -OVL_CLONE ); -} +enum ovl_copyop op; + +if (remap_flags & ~(REMAP_FILE_DEDUP |REMAP_FILE_ADVISORY )) +return -EINVAL ; + +if (remap_flags &REMAP_FILE_DEDUP ) + op =OVL_DEDUPE ; +else + op =OVL_CLONE ; -static int ovl_dedupe_file_range (struct file *file_in,loff_t pos_in, -struct file *file_out,loff_t pos_out,u64 len) -{/* * Don't copy up because of a dedupe request, this wouldn't make sense * most of the time (data would be duplicated instead of deduplicated). */ -if (!ovl_inode_upper (file_inode (file_in)) || - !ovl_inode_upper (file_inode (file_out))) +if (op ==OVL_DEDUPE && + (!ovl_inode_upper (file_inode (file_in)) || + !ovl_inode_upper (file_inode (file_out))))return -EPERM ;return ovl_copyfile (file_in, pos_in, file_out, pos_out, len,0 , -OVL_DEDUPE ); + op); }const struct file_operations ovl_file_operations = {
@@ -525,6 +530,5 @@ const struct file_operations ovl_file_operations = { .compat_ioctl = ovl_compat_ioctl, .copy_file_range = ovl_copy_file_range, - .clone_file_range = ovl_clone_file_range, - .dedupe_file_range = ovl_dedupe_file_range, + .remap_file_range = ovl_remap_file_range, };
fs/read_write.c +9 -9
@@ -1588,9 +1588,9 @@ ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in,* Try cloning first, this is supported by more file systems, and * more efficient if both clone and copy are supported (e.g. NFS). */ -if (file_in->f_op->clone_file_range) { - ret = file_in->f_op->clone_file_range (file_in, pos_in, - file_out, pos_out, len); +if (file_in->f_op->remap_file_range) { + ret = file_in->f_op->remap_file_range (file_in, pos_in, + file_out, pos_out, len,0 );if (ret ==0 ) { ret = len; goto done;
@@ -1849,7 +1849,7 @@ int do_clone_file_range(struct file *file_in, loff_t pos_in, (file_out->f_flags & O_APPEND))return -EBADF ; -if (!file_in->f_op->clone_file_range) +if (!file_in->f_op->remap_file_range)return -EOPNOTSUPP ; ret =remap_verify_area (file_in, pos_in, len, false);
@@ -1860,8 +1860,8 @@ int do_clone_file_range(struct file *file_in, loff_t pos_in,if (ret)return ret; - ret = file_in->f_op->clone_file_range (file_in, pos_in, - file_out, pos_out, len); + ret = file_in->f_op->remap_file_range (file_in, pos_in, + file_out, pos_out, len,0 );if (!ret) {fsnotify_access (file_in);fsnotify_modify (file_out);
@@ -2006,7 +2006,7 @@ int vfs_dedupe_file_range_one(struct file *src_file, loff_t src_pos, goto out_drop_write; ret = -EINVAL ; -if (!dst_file->f_op->dedupe_file_range) +if (!dst_file->f_op->remap_file_range) goto out_drop_write;if (len ==0 ) {
@@ -2014,8 +2014,8 @@ int vfs_dedupe_file_range_one(struct file *src_file, loff_t src_pos, goto out_drop_write; } - ret = dst_file->f_op->dedupe_file_range (src_file, src_pos, - dst_file, dst_pos, len); + ret = dst_file->f_op->remap_file_range (src_file, src_pos, dst_file, + dst_pos, len,REMAP_FILE_DEDUP ); out_drop_write:mnt_drop_write_file (dst_file);
fs/xfs/xfs_file.c +7 -16
@@ -920,27 +920,19 @@ xfs_file_fallocate( } STATIC int -xfs_file_clone_range ( +xfs_file_remap_range (struct file *file_in,loff_t pos_in,struct file *file_out,loff_t pos_out, -u64 len) +u64 len, +unsigned int remap_flags) { -return xfs_reflink_remap_range (file_in, pos_in, file_out, pos_out, - len, false); -} +if (remap_flags & ~(REMAP_FILE_DEDUP |REMAP_FILE_ADVISORY )) +return -EINVAL ; -STATIC int -xfs_file_dedupe_range ( -struct file *file_in, -loff_t pos_in, -struct file *file_out, -loff_t pos_out, -u64 len) -{return xfs_reflink_remap_range (file_in, pos_in, file_out, pos_out, - len, true); + len, remap_flags &REMAP_FILE_DEDUP ); }STATIC int
@@ -1175,8 +1167,7 @@ const struct file_operations xfs_file_operations = { .fsync = xfs_file_fsync, .get_unmapped_area = thp_get_unmapped_area, .fallocate = xfs_file_fallocate, - .clone_file_range = xfs_file_clone_range, - .dedupe_file_range = xfs_file_dedupe_range, + .remap_file_range = xfs_file_remap_range, };const struct file_operations xfs_dir_file_operations = {
include/linux/fs.h +16 -4
@@ -1721,6 +1721,19 @@ struct block_device_operations;#define NOMMU_VMFLAGS \ (NOMMU_MAP_READ | NOMMU_MAP_WRITE | NOMMU_MAP_EXEC) +/* +* These flags control the behavior of the remap_file_range function pointer. +* If it is called with len == 0 that means "remap to end of source file". +* +* REMAP_FILE_DEDUP: only remap if contents identical (i.e. deduplicate) +*/ +#define REMAP_FILE_DEDUP (1 << 0) + +/* +* These flags should be taken care of by the implementation (possibly using +* vfs helpers) but can be ignored by the implementation. +*/ +#define REMAP_FILE_ADVISORY (0)struct iov_iter ;
@@ -1759,10 +1772,9 @@ struct file_operations {#endif ssize_t (*copy_file_range)(struct file *,loff_t ,struct file *,loff_t ,size_t ,unsigned int ); -int (*clone_file_range)(struct file *,loff_t ,struct file *,loff_t , -u64 ); -int (*dedupe_file_range)(struct file *,loff_t ,struct file *,loff_t , -u64 ); +int (*remap_file_range)(struct file *file_in,loff_t pos_in, +struct file *file_out,loff_t pos_out, +u64 len,unsigned int remap_flags);int (*fadvise)(struct file *,loff_t ,loff_t ,int ); } __randomize_layout;
Al Viro
maintainerRe: [PATCH 09/29] vfs: combine the clone and dedupe into a single remap_file_range
Quoted 30 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Combine the
clone_file_rangeanddedupe_file_rangeoperations into a singleremap_file_rangefile operation dispatch since they're fundamentally the same operation. The differences between the two can be made in the prep functions.Signed-off-by Darrick J. Wong <[email protected]>Reviewed-by Amir Goldstein <[email protected]>Reviewed-by Christoph Hellwig <[email protected]>--- Documentation/filesystems/vfs.txt | 13 +++++------ fs/btrfs/ctree.h | 8 ++----- fs/btrfs/file.c | 3 +- fs/btrfs/ioctl.c | 45 +++++++++++++++++++------------------ fs/cifs/cifsfs.c | 22 +++++++++++------- fs/nfs/nfs4file.c | 10 ++++++-- fs/ocfs2/file.c | 24 +++++++------------- fs/overlayfs/file.c | 30 ++++++++++++++----------- fs/read_write.c | 18 +++++++-------- fs/xfs/xfs_file.c | 23 ++++++------------- include/linux/fs.h | 20 +++++++++++++--- 11 files changed, 110 insertions(+), 106 deletions(-)Documentation/filesystems/vfs.txt +0
-0
Documentation/filesystems/vfs.txt struct file_operations { · line 890
Quoted 10 lines
Documentation/filesystems/vfs.txt +3
-2@@ -883,8 +883,9 @@ struct file_operations { unsigned (*mmap_capabilities)(struct file *); #endif ssize_t (*copy_file_range)(struct file *, loff_t, struct file *, loff_t, size_t, unsigned int); - int (*clone_file_range)(struct file *, loff_t, struct file *, loff_t, u64); - int (*dedupe_file_range)(struct file *, loff_t, struct file *, loff_t, u64); + int (*remap_file_range)(struct file *file_in, loff_t pos_in, + struct file *file_out, loff_t pos_out, + u64 len, unsigned int remap_flags); int (*fadvise)(struct file *, loff_t, loff_t, int); };
Documentation/filesystems/porting part, please. And document remap_flags.
Documentation/filesystems/vfs.txt struct file_operations {
Quoted 7 lines
Documentation/filesystems/vfs.txt +7
-0+#define REMAP_FILE_DEDUP (1 << 0) + +/* + * These flags should be taken care of by the implementation (possibly using + * vfs helpers) but can be ignored by the implementation. + */ +#define REMAP_FILE_ADVISORY (0)
???
Re: [PATCH 09/29] vfs: combine the clone and dedupe into a single remap_file_range
Quoted 35 lines · Al Viro
Quoted 34 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Combine the
clone_file_rangeanddedupe_file_rangeoperations into a singleremap_file_rangefile operation dispatch since they're fundamentally the same operation. The differences between the two can be made in the prep functions.Signed-off-by Darrick J. Wong <[email protected]>Reviewed-by Amir Goldstein <[email protected]>Reviewed-by Christoph Hellwig <[email protected]>--- Documentation/filesystems/vfs.txt | 13 +++++------ fs/btrfs/ctree.h | 8 ++----- fs/btrfs/file.c | 3 +- fs/btrfs/ioctl.c | 45 +++++++++++++++++++------------------ fs/cifs/cifsfs.c | 22 +++++++++++------- fs/nfs/nfs4file.c | 10 ++++++-- fs/ocfs2/file.c | 24 +++++++------------- fs/overlayfs/file.c | 30 ++++++++++++++----------- fs/read_write.c | 18 +++++++-------- fs/xfs/xfs_file.c | 23 ++++++------------- include/linux/fs.h | 20 +++++++++++++--- 11 files changed, 110 insertions(+), 106 deletions(-)Documentation/filesystems/vfs.txt +0
-1@@ -883,8 +883,9 @@ struct file_operations { unsigned (*mmap_capabilities)(struct file *); #endif ssize_t (*copy_file_range)(struct file *, loff_t, struct file *, loff_t, size_t, unsigned int); - int (*clone_file_range)(struct file *, loff_t, struct file *, loff_t, u64);
Quoted 8 lines
Documentation/filesystems/vfs.txt struct file_operations { · line 890
Quoted 6 lines
Documentation/filesystems/vfs.txt +3
-1- int (*dedupe_file_range)(struct file *, loff_t, struct file *, loff_t, u64); + int (*remap_file_range)(struct file *file_in, loff_t pos_in, + struct file *file_out, loff_t pos_out, + u64 len, unsigned int remap_flags); int (*fadvise)(struct file *, loff_t, loff_t, int); };
Documentation/filesystems/portingpart, please. And documentremap_flags.
Ok, will do.
Quoted 9 lines
Documentation/filesystems/vfs.txt struct file_operations {
Quoted 7 lines
Documentation/filesystems/vfs.txt +7
-0+#define REMAP_FILE_DEDUP (1 << 0) + +/* + * These flags should be taken care of by the implementation (possibly using + * vfs helpers) but can be ignored by the implementation. + */ +#define REMAP_FILE_ADVISORY (0)???
Sorry if this wasn't clear. How about this?
/*
* These flags signal that the caller is ok with altering various aspects of
* the behavior of the remap operation. The changes must be made by the
* implementation; the vfs remap helper functions can take advantage of them.
* Flags in this category exist to preserve the quirky behavior of the hoisted
* btrfs clone/dedupe ioctls.
*/
--D
Al Viro
maintainerRe: [PATCH 09/29] vfs: combine the clone and dedupe into a single remap_file_range
Quoted 12 lines · Darrick J. Wong
Quoted 9 lines
include/linux/fs.h struct block_device_operations; · line 1736
Quoted 7 lines
include/linux/fs.h +7
-0+#define REMAP_FILE_DEDUP (1 << 0) + +/* +* These flags should be taken care of by the implementation (possibly using +* vfs helpers) but can be ignored by the implementation. +*/ +#define REMAP_FILE_ADVISORY (0)???
Sorry if this wasn't clear. How about this?
Quoted 7 lines
/*
* These flags signal that the caller is ok with altering various aspects of
* the behavior of the remap operation. The changes must be made by the
* implementation; the vfs remap helper functions can take advantage of them.
* Flags in this category exist to preserve the quirky behavior of the hoisted
* btrfs clone/dedupe ioctls.
*/
Something like "currently we have no such flags, but some will appear in subsequent commits", removed once such flags do appear, perhaps?
Re: [PATCH 09/29] vfs: combine the clone and dedupe into a single remap_file_range
Quoted 22 lines · Al Viro
Quoted 12 lines · Darrick J. Wong
Quoted 9 lines
include/linux/fs.h struct block_device_operations; · line 1736
Quoted 7 lines
include/linux/fs.h +7
-0+#define REMAP_FILE_DEDUP (1 << 0) + +/* +* These flags should be taken care of by the implementation (possibly using +* vfs helpers) but can be ignored by the implementation. +*/ +#define REMAP_FILE_ADVISORY (0)???
Sorry if this wasn't clear. How about this?
Quoted 7 lines
/*
* These flags signal that the caller is ok with altering various aspects of
* the behavior of the remap operation. The changes must be made by the
* implementation; the vfs remap helper functions can take advantage of them.
* Flags in this category exist to preserve the quirky behavior of the hoisted
* btrfs clone/dedupe ioctls.
*/
Quoted 2 lines
Something like "currently we have no such flags, but some will appear in subsequent commits", removed once such flags do appear, perhaps?
Done.
--D
PATCH v2 9/29 vfs: combine the clone and dedupe into a single remap_file_range
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Combine the clone_file_range and dedupe_file_range operations into a single remap_file_range file operation dispatch since they're fundamentally the same operation. The differences between the two can be made in the prep functions.
---
v2: documentation updates requested by Al Viro
--- Documentation/filesystems/porting | 5 ++++ Documentation/filesystems/vfs.txt | 20 +++++++++++----- fs/btrfs/ctree.h | 8 ++----- fs/btrfs/file.c | 3 +- fs/btrfs/ioctl.c | 45 +++++++++++++++++++------------------ fs/cifs/cifsfs.c | 22 +++++++++++------- fs/nfs/nfs4file.c | 10 ++++++-- fs/ocfs2/file.c | 24 +++++++------------- fs/overlayfs/file.c | 30 ++++++++++++++----------- fs/read_write.c | 18 +++++++-------- fs/xfs/xfs_file.c | 23 ++++++------------- include/linux/fs.h | 25 +++++++++++++++++---- 12 files changed, 127 insertions(+), 106 deletions(-)
Documentation/filesystems/porting +5 -0
@@ -622,3 +622,8 @@ in your dentry operations instead. alloc_file_clone(file, flags, ops) does not affect any caller's references. On success you get a new struct file sharing the mount/dentry with the original, on failure - ERR_PTR(). +-- +[mandatory] + ->clone_file_range() and ->dedupe_file_range have been replaced with + ->remap_file_range(). See Documentation/filesystems/vfs.txt for more + information.
Documentation/filesystems/vfs.txt +13 -7
@@ -883,8 +883,9 @@ struct file_operations { unsigned (*mmap_capabilities)(struct file *); #endif ssize_t (*copy_file_range)(struct file *, loff_t, struct file *, loff_t, size_t, unsigned int); - int (*clone_file_range)(struct file *, loff_t, struct file *, loff_t, u64); - int (*dedupe_file_range)(struct file *, loff_t, struct file *, loff_t, u64); + int (*remap_file_range)(struct file *file_in, loff_t pos_in, + struct file *file_out, loff_t pos_out, + u64 len, unsigned int remap_flags); int (*fadvise)(struct file *, loff_t, loff_t, int); };
@@ -960,11 +961,16 @@ otherwise noted. copy_file_range: called by the copy_file_range(2) system call. - clone_file_range: called by the ioctl(2) system call for FICLONERANGE and - FICLONE commands. - - dedupe_file_range: called by the ioctl(2) system call for FIDEDUPERANGE - command. + remap_file_range: called by the ioctl(2) system call for FICLONERANGE and + FICLONE and FIDEDUPERANGE commands to remap file ranges. An + implementation should remap len bytes at pos_in of the source file into + the dest file at pos_out. Implementations must handle callers passing + in len == 0; this means "remap to the end of the source file". The + return value should be zero if all bytes were remapped, or the usual + negative error code if the remapping did not succeed completely. + The remap_flags parameter accepts REMAP_FILE_* flags. If + REMAP_FILE_DEDUP is set then the implementation must only remap if the + requested file ranges have identical contents. fadvise: possibly called by the fadvise64() system call.
fs/btrfs/ctree.h +3 -5
@@ -3218,9 +3218,6 @@ void btrfs_get_block_group_info(struct list_head *groups_list, struct btrfs_ioctl_space_info *space);void btrfs_update_ioctl_balance_args (struct btrfs_fs_info *fs_info,struct btrfs_ioctl_balance_args *bargs); -int btrfs_dedupe_file_range (struct file *src_file,loff_t src_loff, -struct file *dst_file,loff_t dst_loff, -u64 olen);/* file.c */ int __init btrfs_auto_defrag_init (void );
@@ -3250,8 +3247,9 @@ int btrfs_dirty_pages(struct inode *inode, struct page **pages, size_t num_pages, loff_t pos, size_t write_bytes, struct extent_state **cached);int btrfs_fdatawrite_range (struct inode *inode,loff_t start,loff_t end); -int btrfs_clone_file_range (struct file *file_in,loff_t pos_in, -struct file *file_out,loff_t pos_out,u64 len); +int btrfs_remap_file_range (struct file *file_in,loff_t pos_in, +struct file *file_out,loff_t pos_out,u64 len, +unsigned int remap_flags);/* tree-defrag.c */ int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,
fs/btrfs/file.c +1 -2
@@ -3269,8 +3269,7 @@ const struct file_operations btrfs_file_operations = {#ifdef CONFIG_COMPAT .compat_ioctl = btrfs_compat_ioctl, #endif - .clone_file_range = btrfs_clone_file_range, - .dedupe_file_range = btrfs_dedupe_file_range, + .remap_file_range = btrfs_remap_file_range, };void __cold btrfs_auto_defrag_exit (void )
fs/btrfs/ioctl.c +23 -22
58 lines not on this page · raw message
fs/cifs/cifsfs.c +13 -9
@@ -975,8 +975,9 @@ const struct inode_operations cifs_symlink_inode_ops = { .listxattr = cifs_listxattr, }; -static int cifs_clone_file_range (struct file *src_file,loff_t off, -struct file *dst_file,loff_t destoff,u64 len) +static int cifs_remap_file_range (struct file *src_file,loff_t off, +struct file *dst_file,loff_t destoff,u64 len, +unsigned int remap_flags) {struct inode *src_inode =file_inode (src_file);struct inode *target_inode =file_inode (dst_file);
@@ -986,6 +987,9 @@ static int cifs_clone_file_range(struct file *src_file, loff_t off,unsigned int xid;int rc; +if (remap_flags & ~REMAP_FILE_ADVISORY ) +return -EINVAL ; +cifs_dbg (FYI ,"clone range\n" ); xid =get_xid ();
@@ -1134,7 +1138,7 @@ const struct file_operations cifs_file_ops = { .llseek = cifs_llseek, .unlocked_ioctl = cifs_ioctl, .copy_file_range = cifs_copy_file_range, - .clone_file_range = cifs_clone_file_range, + .remap_file_range = cifs_remap_file_range, .setlease = cifs_setlease, .fallocate = cifs_fallocate, };
@@ -1153,7 +1157,7 @@ const struct file_operations cifs_file_strict_ops = { .llseek = cifs_llseek, .unlocked_ioctl = cifs_ioctl, .copy_file_range = cifs_copy_file_range, - .clone_file_range = cifs_clone_file_range, + .remap_file_range = cifs_remap_file_range, .setlease = cifs_setlease, .fallocate = cifs_fallocate, };
@@ -1172,7 +1176,7 @@ const struct file_operations cifs_file_direct_ops = { .splice_write = iter_file_splice_write, .unlocked_ioctl = cifs_ioctl, .copy_file_range = cifs_copy_file_range, - .clone_file_range = cifs_clone_file_range, + .remap_file_range = cifs_remap_file_range, .llseek = cifs_llseek, .setlease = cifs_setlease, .fallocate = cifs_fallocate,
@@ -1191,7 +1195,7 @@ const struct file_operations cifs_file_nobrl_ops = { .llseek = cifs_llseek, .unlocked_ioctl = cifs_ioctl, .copy_file_range = cifs_copy_file_range, - .clone_file_range = cifs_clone_file_range, + .remap_file_range = cifs_remap_file_range, .setlease = cifs_setlease, .fallocate = cifs_fallocate, };
@@ -1209,7 +1213,7 @@ const struct file_operations cifs_file_strict_nobrl_ops = { .llseek = cifs_llseek, .unlocked_ioctl = cifs_ioctl, .copy_file_range = cifs_copy_file_range, - .clone_file_range = cifs_clone_file_range, + .remap_file_range = cifs_remap_file_range, .setlease = cifs_setlease, .fallocate = cifs_fallocate, };
@@ -1227,7 +1231,7 @@ const struct file_operations cifs_file_direct_nobrl_ops = { .splice_write = iter_file_splice_write, .unlocked_ioctl = cifs_ioctl, .copy_file_range = cifs_copy_file_range, - .clone_file_range = cifs_clone_file_range, + .remap_file_range = cifs_remap_file_range, .llseek = cifs_llseek, .setlease = cifs_setlease, .fallocate = cifs_fallocate,
@@ -1239,7 +1243,7 @@ const struct file_operations cifs_dir_ops = { .read = generic_read_dir, .unlocked_ioctl = cifs_ioctl, .copy_file_range = cifs_copy_file_range, - .clone_file_range = cifs_clone_file_range, + .remap_file_range = cifs_remap_file_range, .llseek = generic_file_llseek, .fsync = cifs_dir_fsync, };
fs/nfs/nfs4file.c +7 -3
@@ -180,8 +180,9 @@ static long nfs42_fallocate(struct file *filep, int mode, loff_t offset, loff_treturn nfs42_proc_allocate (filep, offset, len); } -static int nfs42_clone_file_range (struct file *src_file,loff_t src_off, -struct file *dst_file,loff_t dst_off,u64 count) +static int nfs42_remap_file_range (struct file *src_file,loff_t src_off, +struct file *dst_file,loff_t dst_off,u64 count, +unsigned int remap_flags) {struct inode *dst_inode =file_inode (dst_file);struct nfs_server *server =NFS_SERVER (dst_inode);
@@ -190,6 +191,9 @@ static int nfs42_clone_file_range(struct file *src_file, loff_t src_off,bool same_inode = false;int ret; +if (remap_flags & ~REMAP_FILE_ADVISORY ) +return -EINVAL ; +/* check alignment w.r.t. clone_blksize */ ret = -EINVAL ;if (bs) {
@@ -262,7 +266,7 @@ const struct file_operations nfs4_file_operations = { .copy_file_range = nfs4_copy_file_range, .llseek = nfs4_file_llseek, .fallocate = nfs42_fallocate, - .clone_file_range = nfs42_clone_file_range, + .remap_file_range = nfs42_remap_file_range, #else .llseek = nfs_file_llseek,#endif
fs/ocfs2/file.c +8 -16
@@ -2527,24 +2527,18 @@ static loff_t ocfs2_file_llseek(struct file *file, loff_t offset, int whence)return offset; } -static int ocfs2_file_clone_range (struct file *file_in, +static int ocfs2_remap_file_range (struct file *file_in,loff_t pos_in,struct file *file_out,loff_t pos_out, -u64 len) +u64 len, +unsigned int remap_flags) { -return ocfs2_reflink_remap_range (file_in, pos_in, file_out, pos_out, - len, false); -} +if (remap_flags & ~(REMAP_FILE_DEDUP |REMAP_FILE_ADVISORY )) +return -EINVAL ; -static int ocfs2_file_dedupe_range (struct file *file_in, -loff_t pos_in, -struct file *file_out, -loff_t pos_out, -u64 len) -{return ocfs2_reflink_remap_range (file_in, pos_in, file_out, pos_out, - len, true); + len, remap_flags &REMAP_FILE_DEDUP ); }const struct inode_operations ocfs2_file_iops = {
@@ -2586,8 +2580,7 @@ const struct file_operations ocfs2_fops = { .splice_read = generic_file_splice_read, .splice_write = iter_file_splice_write, .fallocate = ocfs2_fallocate, - .clone_file_range = ocfs2_file_clone_range, - .dedupe_file_range = ocfs2_file_dedupe_range, + .remap_file_range = ocfs2_remap_file_range, };const struct file_operations ocfs2_dops = {
@@ -2633,8 +2626,7 @@ const struct file_operations ocfs2_fops_no_plocks = { .splice_read = generic_file_splice_read, .splice_write = iter_file_splice_write, .fallocate = ocfs2_fallocate, - .clone_file_range = ocfs2_file_clone_range, - .dedupe_file_range = ocfs2_file_dedupe_range, + .remap_file_range = ocfs2_remap_file_range, };const struct file_operations ocfs2_dops_no_plocks = {
fs/overlayfs/file.c +17 -13
@@ -489,26 +489,31 @@ static ssize_t ovl_copy_file_range(struct file *file_in, loff_t pos_in, OVL_COPY); } -static int ovl_clone_file_range (struct file *file_in,loff_t pos_in, -struct file *file_out,loff_t pos_out,u64 len) +static int ovl_remap_file_range (struct file *file_in,loff_t pos_in, +struct file *file_out,loff_t pos_out, +u64 len,unsigned int remap_flags) { -return ovl_copyfile (file_in, pos_in, file_out, pos_out, len,0 , -OVL_CLONE ); -} +enum ovl_copyop op; + +if (remap_flags & ~(REMAP_FILE_DEDUP |REMAP_FILE_ADVISORY )) +return -EINVAL ; + +if (remap_flags &REMAP_FILE_DEDUP ) + op =OVL_DEDUPE ; +else + op =OVL_CLONE ; -static int ovl_dedupe_file_range (struct file *file_in,loff_t pos_in, -struct file *file_out,loff_t pos_out,u64 len) -{/* * Don't copy up because of a dedupe request, this wouldn't make sense * most of the time (data would be duplicated instead of deduplicated). */ -if (!ovl_inode_upper (file_inode (file_in)) || - !ovl_inode_upper (file_inode (file_out))) +if (op ==OVL_DEDUPE && + (!ovl_inode_upper (file_inode (file_in)) || + !ovl_inode_upper (file_inode (file_out))))return -EPERM ;return ovl_copyfile (file_in, pos_in, file_out, pos_out, len,0 , -OVL_DEDUPE ); + op); }const struct file_operations ovl_file_operations = {
@@ -525,6 +530,5 @@ const struct file_operations ovl_file_operations = { .compat_ioctl = ovl_compat_ioctl, .copy_file_range = ovl_copy_file_range, - .clone_file_range = ovl_clone_file_range, - .dedupe_file_range = ovl_dedupe_file_range, + .remap_file_range = ovl_remap_file_range, };
fs/read_write.c +9 -9
@@ -1588,9 +1588,9 @@ ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in,* Try cloning first, this is supported by more file systems, and * more efficient if both clone and copy are supported (e.g. NFS). */ -if (file_in->f_op->clone_file_range) { - ret = file_in->f_op->clone_file_range (file_in, pos_in, - file_out, pos_out, len); +if (file_in->f_op->remap_file_range) { + ret = file_in->f_op->remap_file_range (file_in, pos_in, + file_out, pos_out, len,0 );if (ret ==0 ) { ret = len; goto done;
@@ -1849,7 +1849,7 @@ int do_clone_file_range(struct file *file_in, loff_t pos_in, (file_out->f_flags & O_APPEND))return -EBADF ; -if (!file_in->f_op->clone_file_range) +if (!file_in->f_op->remap_file_range)return -EOPNOTSUPP ; ret =remap_verify_area (file_in, pos_in, len, false);
@@ -1860,8 +1860,8 @@ int do_clone_file_range(struct file *file_in, loff_t pos_in,if (ret)return ret; - ret = file_in->f_op->clone_file_range (file_in, pos_in, - file_out, pos_out, len); + ret = file_in->f_op->remap_file_range (file_in, pos_in, + file_out, pos_out, len,0 );if (!ret) {fsnotify_access (file_in);fsnotify_modify (file_out);
@@ -2006,7 +2006,7 @@ int vfs_dedupe_file_range_one(struct file *src_file, loff_t src_pos, goto out_drop_write; ret = -EINVAL ; -if (!dst_file->f_op->dedupe_file_range) +if (!dst_file->f_op->remap_file_range) goto out_drop_write;if (len ==0 ) {
@@ -2014,8 +2014,8 @@ int vfs_dedupe_file_range_one(struct file *src_file, loff_t src_pos, goto out_drop_write; } - ret = dst_file->f_op->dedupe_file_range (src_file, src_pos, - dst_file, dst_pos, len); + ret = dst_file->f_op->remap_file_range (src_file, src_pos, dst_file, + dst_pos, len,REMAP_FILE_DEDUP ); out_drop_write:mnt_drop_write_file (dst_file);
fs/xfs/xfs_file.c +7 -16
@@ -920,27 +920,19 @@ xfs_file_fallocate( } STATIC int -xfs_file_clone_range ( +xfs_file_remap_range (struct file *file_in,loff_t pos_in,struct file *file_out,loff_t pos_out, -u64 len) +u64 len, +unsigned int remap_flags) { -return xfs_reflink_remap_range (file_in, pos_in, file_out, pos_out, - len, false); -} +if (remap_flags & ~(REMAP_FILE_DEDUP |REMAP_FILE_ADVISORY )) +return -EINVAL ; -STATIC int -xfs_file_dedupe_range ( -struct file *file_in, -loff_t pos_in, -struct file *file_out, -loff_t pos_out, -u64 len) -{return xfs_reflink_remap_range (file_in, pos_in, file_out, pos_out, - len, true); + len, remap_flags &REMAP_FILE_DEDUP ); }STATIC int
@@ -1175,8 +1167,7 @@ const struct file_operations xfs_file_operations = { .fsync = xfs_file_fsync, .get_unmapped_area = thp_get_unmapped_area, .fallocate = xfs_file_fallocate, - .clone_file_range = xfs_file_clone_range, - .dedupe_file_range = xfs_file_dedupe_range, + .remap_file_range = xfs_file_remap_range, };const struct file_operations xfs_dir_file_operations = {
include/linux/fs.h +21 -4
@@ -1721,6 +1721,24 @@ struct block_device_operations;#define NOMMU_VMFLAGS \ (NOMMU_MAP_READ | NOMMU_MAP_WRITE | NOMMU_MAP_EXEC) +/* +* These flags control the behavior of the remap_file_range function pointer. +* If it is called with len == 0 that means "remap to end of source file". +* See Documentation/filesystems/vfs.txt for more details about this call. +* +* REMAP_FILE_DEDUP: only remap if contents identical (i.e. deduplicate) +*/ +#define REMAP_FILE_DEDUP (1 << 0) + +/* +* These flags signal that the caller is ok with altering various aspects of +* the behavior of the remap operation. The changes must be made by the +* implementation; the vfs remap helper functions can take advantage of them. +* Flags in this category exist to preserve the quirky behavior of the hoisted +* btrfs clone/dedupe ioctls. +* There are no flags yet, but subsequent commits will add some. +*/ +#define REMAP_FILE_ADVISORY (0)struct iov_iter ;
@@ -1759,10 +1777,9 @@ struct file_operations {#endif ssize_t (*copy_file_range)(struct file *,loff_t ,struct file *,loff_t ,size_t ,unsigned int ); -int (*clone_file_range)(struct file *,loff_t ,struct file *,loff_t , -u64 ); -int (*dedupe_file_range)(struct file *,loff_t ,struct file *,loff_t , -u64 ); +int (*remap_file_range)(struct file *file_in,loff_t pos_in, +struct file *file_out,loff_t pos_out, +u64 len,unsigned int remap_flags);int (*fadvise)(struct file *,loff_t ,loff_t ,int ); } __randomize_layout;
PATCH v6 10/29 vfs: pass remap flags to generic_remap_file_range_prep
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Plumb the remap flags through the filesystem from the vfs function dispatcher all the way to the prep function to prepare for behavior changes in subsequent patches.
--- fs/ocfs2/file.c | 2 +- fs/ocfs2/refcounttree.c | 4 ++-- fs/ocfs2/refcounttree.h | 2 +- fs/read_write.c | 14 +++++++------- fs/xfs/xfs_file.c | 2 +- fs/xfs/xfs_reflink.c | 21 +++++++++++---------- fs/xfs/xfs_reflink.h | 3 ++- include/linux/fs.h | 2 +- 8 files changed, 26 insertions(+), 24 deletions(-)
fs/ocfs2/file.c +1 -1
@@ -2538,7 +2538,7 @@ static int ocfs2_remap_file_range(struct file *file_in,return -EINVAL ;return ocfs2_reflink_remap_range (file_in, pos_in, file_out, pos_out, - len, remap_flags &REMAP_FILE_DEDUP ); + len, remap_flags); }const struct inode_operations ocfs2_file_iops = {
fs/ocfs2/refcounttree.c +2 -2
@@ -4825,7 +4825,7 @@ int ocfs2_reflink_remap_range(struct file *file_in,struct file *file_out, loff_t pos_out, u64 len, - bool is_dedupe) + unsigned int remap_flags) { struct inode *inode_in = file_inode(file_in);struct inode *inode_out =file_inode (file_out);
@@ -4851,7 +4851,7 @@ int ocfs2_reflink_remap_range(struct file *file_in, goto out_unlock; ret =generic_remap_file_range_prep (file_in, pos_in, file_out, pos_out, - &len, is_dedupe); + &len, remap_flags);if (ret <=0 ) goto out_unlock;
fs/ocfs2/refcounttree.h +1 -1
@@ -120,6 +120,6 @@ int ocfs2_reflink_remap_range(struct file *file_in,struct file *file_out, loff_t pos_out, u64 len, - bool is_dedupe); + unsigned int remap_flags);#endif /* OCFS2_REFCOUNTTREE_H */
fs/read_write.c +7 -7
@@ -1722,14 +1722,14 @@ static int generic_remap_check_len(struct inode *inode_in,struct inode *inode_out, loff_t pos_out, u64 *len, - bool is_dedupe) + unsigned int remap_flags) { u64 blkmask = i_blocksize(inode_in) - 1;if ((*len & blkmask) ==0 )return 0 ; -if (is_dedupe) +if (remap_flags &REMAP_FILE_DEDUP ) *len &= ~blkmask;else if (pos_out + *len <i_size_read (inode_out))return -EINVAL ;
@@ -1747,7 +1747,7 @@ static int generic_remap_check_len(struct inode *inode_in,*/ int generic_remap_file_range_prep (struct file *file_in,loff_t pos_in,struct file *file_out,loff_t pos_out, -u64 *len,bool is_dedupe) +u64 *len,unsigned int remap_flags) {struct inode *inode_in =file_inode (file_in);struct inode *inode_out =file_inode (file_out);
@@ -1771,7 +1771,7 @@ int generic_remap_file_range_prep(struct file *file_in, loff_t pos_in,if (*len ==0 ) {loff_t isize =i_size_read (inode_in); -if (is_dedupe || pos_in == isize) +if ((remap_flags &REMAP_FILE_DEDUP ) || pos_in == isize)return 0 ;if (pos_in > isize)return -EINVAL ;
@@ -1782,7 +1782,7 @@ int generic_remap_file_range_prep(struct file *file_in, loff_t pos_in,/* Check that we don't violate system file offset limits. */ ret =generic_remap_checks (file_in, pos_in, file_out, pos_out, len, - is_dedupe); + (remap_flags &REMAP_FILE_DEDUP ));if (ret)return ret;
@@ -1804,7 +1804,7 @@ int generic_remap_file_range_prep(struct file *file_in, loff_t pos_in,/* * Check that the extents are the same. */ -if (is_dedupe) { +if (remap_flags &REMAP_FILE_DEDUP ) {bool is_same = false; ret = vfs_dedupe_file_range_compare(inode_in, pos_in,
@@ -1816,7 +1816,7 @@ int generic_remap_file_range_prep(struct file *file_in, loff_t pos_in, } ret =generic_remap_check_len (inode_in, inode_out, pos_out, len, - is_dedupe); + remap_flags);if (ret)return ret;
fs/xfs/xfs_file.c +1 -1
@@ -932,7 +932,7 @@ xfs_file_remap_range(return -EINVAL ;return xfs_reflink_remap_range (file_in, pos_in, file_out, pos_out, - len, remap_flags &REMAP_FILE_DEDUP ); + len, remap_flags); }STATIC int
fs/xfs/xfs_reflink.c +11 -10
@@ -921,13 +921,14 @@ xfs_reflink_update_dest(struct xfs_inode *dest, xfs_off_t newlen, xfs_extlen_t cowextsize, - bool is_dedupe) + unsigned int remap_flags) { struct xfs_mount *mp = dest->i_mount;struct xfs_trans *tp;int error; -if (is_dedupe && newlen <=i_size_read (VFS_I (dest)) && cowextsize ==0 ) +if ((remap_flags &REMAP_FILE_DEDUP ) && + newlen <=i_size_read (VFS_I (dest)) && cowextsize ==0 )return 0 ; error =xfs_trans_alloc (mp, &M_RES (mp)->tr_ichange,0 ,0 ,0 , &tp);
@@ -948,7 +949,7 @@ xfs_reflink_update_dest( dest->i_d.di_flags2 |=XFS_DIFLAG2_COWEXTSIZE ; } -if (!is_dedupe) { +if (!(remap_flags &REMAP_FILE_DEDUP )) {xfs_trans_ichgtime (tp, dest,XFS_ICHGTIME_MOD |XFS_ICHGTIME_CHG ); }
@@ -1296,7 +1297,7 @@ xfs_reflink_remap_prep(struct file *file_out, loff_t pos_out, u64 *len, - bool is_dedupe) + unsigned int remap_flags) { struct inode *inode_in = file_inode(file_in);struct xfs_inode *src =XFS_I (inode_in);
@@ -1327,7 +1328,7 @@ xfs_reflink_remap_prep( goto out_unlock; ret =generic_remap_file_range_prep (file_in, pos_in, file_out, pos_out, - len, is_dedupe); + len, remap_flags);if (ret <=0 ) goto out_unlock;
@@ -1336,7 +1337,7 @@ xfs_reflink_remap_prep(* from the source file so we don't try to dedupe the partial * EOF block. */ -if (is_dedupe) { +if (remap_flags &REMAP_FILE_DEDUP ) { *len &= ~blkmask; }else if (*len & blkmask) {/*
@@ -1372,7 +1373,7 @@ xfs_reflink_remap_prep( PAGE_ALIGN(pos_out + *len) - 1);/* If we're altering the file contents... */ -if (!is_dedupe) { +if (!(remap_flags &REMAP_FILE_DEDUP )) {/* * ...update the timestamps (which will grab the ilock again * from xfs_fs_dirty_inode, so we have to call it before we
@@ -1410,7 +1411,7 @@ xfs_reflink_remap_range(struct file *file_out, loff_t pos_out, u64 len, - bool is_dedupe) + unsigned int remap_flags) { struct inode *inode_in = file_inode(file_in);struct xfs_inode *src =XFS_I (inode_in);
@@ -1430,7 +1431,7 @@ xfs_reflink_remap_range(/* Prepare and then clone file data. */ ret =xfs_reflink_remap_prep (file_in, pos_in, file_out, pos_out, - &len, is_dedupe); + &len, remap_flags);if (ret <=0 )return ret;
@@ -1457,7 +1458,7 @@ xfs_reflink_remap_range( cowextsize = src->i_d.di_cowextsize; ret =xfs_reflink_update_dest (dest, pos_out + len, cowextsize, - is_dedupe); + remap_flags); out_unlock:xfs_reflink_remap_unlock (file_in, file_out);
fs/xfs/xfs_reflink.h +2 -1
@@ -28,7 +28,8 @@ 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, -struct file *file_out,loff_t pos_out,u64 len,bool is_dedupe); +struct file *file_out,loff_t pos_out,u64 len, +unsigned int remap_flags);extern int xfs_reflink_inode_has_shared_extents (struct xfs_trans *tp,struct xfs_inode *ip,bool *has_shared); extern int xfs_reflink_clear_inode_flag(struct xfs_inode *ip,
include/linux/fs.h +1 -1
@@ -1839,7 +1839,7 @@ extern ssize_t vfs_copy_file_range(struct file *, loff_t , struct file *, loff_t, size_t, unsigned int);extern int generic_remap_file_range_prep (struct file *file_in,loff_t pos_in,struct file *file_out,loff_t pos_out, -u64 *count,bool is_dedupe); +u64 *count,unsigned int remap_flags);extern int do_clone_file_range (struct file *file_in,loff_t pos_in,struct file *file_out,loff_t pos_out,u64 len); extern int vfs_clone_file_range(struct file *file_in, loff_t pos_in,
PATCH v6 11/29 vfs: pass remap flags to generic_remap_checks
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Pass the same remap flags to generic_remap_checks for consistency.
--- fs/read_write.c | 2 +- include/linux/fs.h | 2 +- mm/filemap.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-)
fs/read_write.c +1 -1
@@ -1782,7 +1782,7 @@ int generic_remap_file_range_prep(struct file *file_in, loff_t pos_in,/* Check that we don't violate system file offset limits. */ ret =generic_remap_checks (file_in, pos_in, file_out, pos_out, len, - (remap_flags &REMAP_FILE_DEDUP )); + remap_flags);if (ret)return ret;
include/linux/fs.h +1 -1
@@ -2981,7 +2981,7 @@ extern int generic_file_readonly_mmap(struct file *, struct vm_area_struct *);extern ssize_t generic_write_checks (struct kiocb *,struct iov_iter *);extern int generic_remap_checks (struct file *file_in,loff_t pos_in,struct file *file_out,loff_t pos_out, -uint64_t *count,bool is_dedupe); +uint64_t *count,unsigned int remap_flags);extern ssize_t generic_file_read_iter (struct kiocb *,struct iov_iter *);extern ssize_t __generic_file_write_iter (struct kiocb *,struct iov_iter *);extern ssize_t generic_file_write_iter (struct kiocb *,struct iov_iter *);
mm/filemap.c +2 -2
@@ -3001,7 +3001,7 @@ EXPORT_SYMBOL(generic_write_checks);*/ int generic_remap_checks (struct file *file_in,loff_t pos_in,struct file *file_out,loff_t pos_out, -uint64_t *req_count,bool is_dedupe) +uint64_t *req_count,unsigned int remap_flags) {struct inode *inode_in = file_in->f_mapping->host;struct inode *inode_out = file_out->f_mapping->host;
@@ -3023,7 +3023,7 @@ int generic_remap_checks(struct file *file_in, loff_t pos_in, size_out =i_size_read (inode_out);/* Dedupe requires both ranges to be within EOF. */ -if (is_dedupe && +if ((remap_flags &REMAP_FILE_DEDUP ) && (pos_in >= size_in || pos_in + count > size_in || pos_out >= size_out || pos_out + count > size_out))return -EINVAL ;
PATCH v6 12/29 vfs: remap helper should update destination inode metadata
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Extend generic_remap_file_range_prep to handle inode metadata updates when remapping into a file. If the operation can possibly alter the file contents, we must update the ctime and mtime and remove security privileges, just like we do for regular file writes.
--- fs/read_write.c | 19 +++++++++++++++++++ fs/xfs/xfs_reflink.c | 23 ----------------------- 2 files changed, 19 insertions(+), 23 deletions(-)
fs/read_write.c +19 -0
@@ -1820,6 +1820,25 @@ int generic_remap_file_range_prep(struct file *file_in, loff_t pos_in,if (ret)return ret; +/* If can't alter the file contents, we're done. */ +if (!(remap_flags &REMAP_FILE_DEDUP )) { +/* Update the timestamps, since we can alter file contents. */ +if (!(file_out->f_mode &FMODE_NOCMTIME )) { + ret =file_update_time (file_out); +if (ret) +return ret; + } + +/* +* Clear the security bits if the process is not being run by +* root. This keeps people from modifying setuid and setgid +* binaries. +*/ + ret =file_remove_privs (file_out); +if (ret) +return ret; + } +return 1 ; }EXPORT_SYMBOL (generic_remap_file_range_prep);
fs/xfs/xfs_reflink.c +0 -23
@@ -1372,29 +1372,6 @@ xfs_reflink_remap_prep(truncate_inode_pages_range (&inode_out->i_data, pos_out,PAGE_ALIGN (pos_out + *len) -1 ); -/* If we're altering the file contents... */ -if (!(remap_flags &REMAP_FILE_DEDUP )) { -/* -* ...update the timestamps (which will grab the ilock again -* from xfs_fs_dirty_inode, so we have to call it before we -* take the ilock). -*/ -if (!(file_out->f_mode &FMODE_NOCMTIME )) { - ret =file_update_time (file_out); -if (ret) - goto out_unlock; - } - -/* -* ...clear the security bits if the process is not being run -* by root. This keeps people from modifying setuid and setgid -* binaries. -*/ - ret =file_remove_privs (file_out); -if (ret) - goto out_unlock; - } -return 1 ; out_unlock:xfs_reflink_remap_unlock (file_in, file_out);
PATCH v6 13/29 vfs: make remap_file_range functions take and return bytes completed
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Change the remap_file_range functions to take a number of bytes to operate upon and return the number of bytes they operated on. This is a requirement for allowing fs implementations to return short clone/dedupe results to the user, which will enable us to obey resource limits in a graceful manner.
A subsequent patch will enable copy_file_range to signal to the ->clone_file_range implementation that it can handle a short length, which will be returned in the function's return value. For now the short return is not implemented anywhere so the behavior won't change -- either copy_file_range manages to clone the entire range or it tries an alternative.
Neither clone ioctl can take advantage of this, alas.
--- Documentation/filesystems/vfs.txt | 6 ++--- fs/btrfs/ctree.h | 6 ++--- fs/btrfs/ioctl.c | 13 ++++++---- fs/cifs/cifsfs.c | 6 ++--- fs/ioctl.c | 10 +++++++- fs/nfs/nfs4file.c | 6 ++--- fs/nfsd/vfs.c | 8 +++++- fs/ocfs2/file.c | 16 ++++++------ fs/ocfs2/refcounttree.c | 2 +- fs/ocfs2/refcounttree.h | 2 +- fs/overlayfs/copy_up.c | 6 ++--- fs/overlayfs/file.c | 12 +++++---- fs/read_write.c | 49 ++++++++++++++++++++----------------- fs/xfs/xfs_file.c | 9 +++++-- fs/xfs/xfs_reflink.c | 4 ++- fs/xfs/xfs_reflink.h | 2 +- include/linux/fs.h | 27 +++++++++++--------- mm/filemap.c | 2 +- 18 files changed, 106 insertions(+), 80 deletions(-)
Documentation/filesystems/vfs.txt +3 -3
@@ -883,9 +883,9 @@ struct file_operations { unsigned (*mmap_capabilities)(struct file *); #endif ssize_t (*copy_file_range)(struct file *, loff_t, struct file *, loff_t, size_t, unsigned int); - int (*remap_file_range)(struct file *file_in, loff_t pos_in, - struct file *file_out, loff_t pos_out, - u64 len, unsigned int remap_flags); + loff_t (*remap_file_range)(struct file *file_in, loff_t pos_in, + struct file *file_out, loff_t pos_out, + loff_t len, unsigned int remap_flags); int (*fadvise)(struct file *, loff_t, loff_t, int); };
fs/btrfs/ctree.h +3 -3
@@ -3247,9 +3247,9 @@ int btrfs_dirty_pages(struct inode *inode, struct page **pages, size_t num_pages, loff_t pos, size_t write_bytes, struct extent_state **cached);int btrfs_fdatawrite_range (struct inode *inode,loff_t start,loff_t end); -int btrfs_remap_file_range (struct file *file_in,loff_t pos_in, -struct file *file_out,loff_t pos_out,u64 len, -unsigned int remap_flags); +loff_t btrfs_remap_file_range (struct file *file_in,loff_t pos_in, +struct file *file_out,loff_t pos_out, +loff_t len,unsigned int remap_flags);/* tree-defrag.c */ int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,
fs/btrfs/ioctl.c +8 -5
@@ -4328,10 +4328,12 @@ static noinline int btrfs_clone_files(struct file *file, struct file *file_src,return ret; } -int btrfs_remap_file_range (struct file *src_file,loff_t off, -struct file *dst_file,loff_t destoff,u64 len, +loff_t btrfs_remap_file_range (struct file *src_file,loff_t off, +struct file *dst_file,loff_t destoff,loff_t len,unsigned int remap_flags) { +int ret; +if (remap_flags & ~(REMAP_FILE_DEDUP |REMAP_FILE_ADVISORY ))return -EINVAL ;
@@ -4349,10 +4351,11 @@ int btrfs_remap_file_range(struct file *src_file, loff_t off,return -EINVAL ; } -return btrfs_extent_same (src, off, len, dst, destoff); + ret =btrfs_extent_same (src, off, len, dst, destoff); + }else { + ret =btrfs_clone_files (dst_file, src_file, off, len, destoff); } - -return btrfs_clone_files (dst_file, src_file, off, len, destoff); +return ret <0 ? ret : len; }static long btrfs_ioctl_default_subvol (struct file *file,void __user *argp)
fs/cifs/cifsfs.c +3 -3
@@ -975,8 +975,8 @@ const struct inode_operations cifs_symlink_inode_ops = { .listxattr = cifs_listxattr, }; -static int cifs_remap_file_range (struct file *src_file,loff_t off, -struct file *dst_file,loff_t destoff,u64 len, +static loff_t cifs_remap_file_range (struct file *src_file,loff_t off, +struct file *dst_file,loff_t destoff,loff_t len,unsigned int remap_flags) {struct inode *src_inode =file_inode (src_file);
@@ -1029,7 +1029,7 @@ static int cifs_remap_file_range(struct file *src_file, loff_t off,unlock_two_nondirectories (src_inode, target_inode); out:free_xid (xid); -return rc; +return rc <0 ? rc : len; } ssize_t cifs_file_copychunk_range(unsigned int xid,
fs/ioctl.c +9 -1
@@ -223,6 +223,7 @@ static long ioctl_file_clone(struct file *dst_file, unsigned long srcfd, u64 off, u64 olen, u64 destoff) { struct fd src_file = fdget(srcfd); +loff_t cloned;int ret;if (!src_file.file)
@@ -230,7 +231,14 @@ static long ioctl_file_clone(struct file *dst_file, unsigned long srcfd, ret = -EXDEV ;if (src_file.file->f_path.mnt != dst_file->f_path.mnt) goto fdput; - ret =vfs_clone_file_range (src_file.file, off, dst_file, destoff, olen); + cloned =vfs_clone_file_range (src_file.file, off, dst_file, destoff, + olen); +if (cloned <0 ) + ret = cloned; +else if (olen && cloned != olen) + ret = -EINVAL ; +else + ret =0 ; fdput:fdput (src_file);return ret;
fs/nfs/nfs4file.c +3 -3
@@ -180,8 +180,8 @@ static long nfs42_fallocate(struct file *filep, int mode, loff_t offset, loff_treturn nfs42_proc_allocate (filep, offset, len); } -static int nfs42_remap_file_range (struct file *src_file,loff_t src_off, -struct file *dst_file,loff_t dst_off,u64 count, +static loff_t nfs42_remap_file_range (struct file *src_file,loff_t src_off, +struct file *dst_file,loff_t dst_off,loff_t count,unsigned int remap_flags) {struct inode *dst_inode =file_inode (dst_file);
@@ -244,7 +244,7 @@ static int nfs42_remap_file_range(struct file *src_file, loff_t src_off, inode_unlock(src_inode); } out: -return ret; +return ret <0 ? ret : count; }#endif /* CONFIG_NFS_V4_2 */
fs/nfsd/vfs.c +6 -2
@@ -541,8 +541,12 @@ __be32 nfsd4_set_nfs4_label(struct svc_rqst *rqstp, struct svc_fh *fhp,__be32 nfsd4_clone_file_range (struct file *src,u64 src_pos,struct file *dst,u64 dst_pos,u64 count) { -return nfserrno (vfs_clone_file_range (src, src_pos, dst, dst_pos, - count)); +loff_t cloned; + + cloned =vfs_clone_file_range (src, src_pos, dst, dst_pos, count); +if (count && cloned != count) + cloned = -EINVAL ; +return nfserrno (cloned <0 ? cloned :0 ); } ssize_t nfsd_copy_file_range(struct file *src, u64 src_pos, struct file *dst,
fs/ocfs2/file.c +8 -8
@@ -2527,18 +2527,18 @@ static loff_t ocfs2_file_llseek(struct file *file, loff_t offset, int whence)return offset; } -static int ocfs2_remap_file_range (struct file *file_in, -loff_t pos_in, -struct file *file_out, -loff_t pos_out, -u64 len, -unsigned int remap_flags) +static loff_t ocfs2_remap_file_range (struct file *file_in,loff_t pos_in, +struct file *file_out,loff_t pos_out, +loff_t len,unsigned int remap_flags) { +int ret; +if (remap_flags & ~(REMAP_FILE_DEDUP |REMAP_FILE_ADVISORY ))return -EINVAL ; -return ocfs2_reflink_remap_range (file_in, pos_in, file_out, pos_out, - len, remap_flags); + ret =ocfs2_reflink_remap_range (file_in, pos_in, file_out, pos_out, + len, remap_flags); +return ret <0 ? ret : len; }const struct inode_operations ocfs2_file_iops = {
fs/ocfs2/refcounttree.c +1 -1
@@ -4824,7 +4824,7 @@ int ocfs2_reflink_remap_range(struct file *file_in,loff_t pos_in, struct file *file_out, loff_t pos_out, - u64 len, + loff_t len, unsigned int remap_flags) { struct inode *inode_in = file_inode(file_in);
fs/ocfs2/refcounttree.h +1 -1
@@ -119,7 +119,7 @@ int ocfs2_reflink_remap_range(struct file *file_in,loff_t pos_in, struct file *file_out, loff_t pos_out, - u64 len, + loff_t len, unsigned int remap_flags);#endif /* OCFS2_REFCOUNTTREE_H */
fs/overlayfs/copy_up.c +3 -3
@@ -125,6 +125,7 @@ static int ovl_copy_up_data(struct path *old, struct path *new, loff_t len)struct file *new_file;loff_t old_pos =0 ;loff_t new_pos =0 ; +loff_t cloned;int error =0 ;if (len ==0 )
@@ -141,11 +142,10 @@ static int ovl_copy_up_data(struct path *old, struct path *new, loff_t len) }/* Try to use clone_file_range to clone up within the same fs */ - error =do_clone_file_range (old_file,0 , new_file,0 , len); -if (!error) + cloned =do_clone_file_range (old_file,0 , new_file,0 , len); +if (cloned == len) goto out;/* Couldn't clone, so now we try to copy the data */ - error =0 ;/* FIXME: copy up sparse files efficiently */ while (len) {
fs/overlayfs/file.c +6 -6
@@ -434,14 +434,14 @@ enum ovl_copyop { OVL_DEDUPE, }; -static ssize_t ovl_copyfile (struct file *file_in,loff_t pos_in, +static loff_t ovl_copyfile (struct file *file_in,loff_t pos_in,struct file *file_out,loff_t pos_out, -u64 len,unsigned int flags,enum ovl_copyop op) +loff_t len,unsigned int flags,enum ovl_copyop op) {struct inode *inode_out =file_inode (file_out);struct fd real_in, real_out;const struct cred *old_cred; -ssize_t ret; +loff_t ret; ret =ovl_real_fdget (file_out, &real_out);if (ret)
@@ -489,9 +489,9 @@ static ssize_t ovl_copy_file_range(struct file *file_in, loff_t pos_in, OVL_COPY); } -static int ovl_remap_file_range (struct file *file_in,loff_t pos_in, -struct file *file_out,loff_t pos_out, -u64 len,unsigned int remap_flags) +static loff_t ovl_remap_file_range (struct file *file_in,loff_t pos_in, +struct file *file_out,loff_t pos_out, +loff_t len,unsigned int remap_flags) {enum ovl_copyop op;
fs/read_write.c +27 -22
110 lines not on this page · raw message
fs/xfs/xfs_file.c +6 -3
@@ -919,20 +919,23 @@ xfs_file_fallocate(return error; } -STATIC int +STATIC loff_txfs_file_remap_range (struct file *file_in,loff_t pos_in,struct file *file_out,loff_t pos_out, -u64 len, +loff_t len,unsigned int remap_flags) { +int ret; +if (remap_flags & ~(REMAP_FILE_DEDUP |REMAP_FILE_ADVISORY ))return -EINVAL ; -return xfs_reflink_remap_range (file_in, pos_in, file_out, pos_out, + ret =xfs_reflink_remap_range (file_in, pos_in, file_out, pos_out, len, remap_flags); +return ret <0 ? ret : len; }STATIC int
fs/xfs/xfs_reflink.c +2 -2
@@ -1296,7 +1296,7 @@ xfs_reflink_remap_prep(loff_t pos_in, struct file *file_out, loff_t pos_out, - u64 *len, + loff_t *len, unsigned int remap_flags) { struct inode *inode_in = file_inode(file_in);
@@ -1387,7 +1387,7 @@ xfs_reflink_remap_range(loff_t pos_in, struct file *file_out, loff_t pos_out, - u64 len, + loff_t len, unsigned int remap_flags) { struct inode *inode_in = file_inode(file_in);
fs/xfs/xfs_reflink.h +1 -1
@@ -28,7 +28,7 @@ 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, -struct file *file_out,loff_t pos_out,u64 len, +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,struct xfs_inode *ip,bool *has_shared);
include/linux/fs.h +15 -12
@@ -1772,9 +1772,9 @@ struct file_operations {#endif ssize_t (*copy_file_range)(struct file *,loff_t ,struct file *,loff_t ,size_t ,unsigned int ); -int (*remap_file_range)(struct file *file_in,loff_t pos_in, -struct file *file_out,loff_t pos_out, -u64 len,unsigned int remap_flags); +loff_t (*remap_file_range)(struct file *file_in,loff_t pos_in, +struct file *file_out,loff_t pos_out, +loff_t len,unsigned int remap_flags);int (*fadvise)(struct file *,loff_t ,loff_t ,int ); } __randomize_layout;
@@ -1839,19 +1839,22 @@ extern ssize_t vfs_copy_file_range(struct file *, loff_t , struct file *, loff_t, size_t, unsigned int);extern int generic_remap_file_range_prep (struct file *file_in,loff_t pos_in,struct file *file_out,loff_t pos_out, -u64 *count,unsigned int remap_flags); -extern int do_clone_file_range (struct file *file_in,loff_t pos_in, -struct file *file_out,loff_t pos_out,u64 len); -extern int vfs_clone_file_range (struct file *file_in,loff_t pos_in, -struct file *file_out,loff_t pos_out,u64 len); +loff_t *count, +unsigned int remap_flags); +extern loff_t do_clone_file_range (struct file *file_in,loff_t pos_in, +struct file *file_out,loff_t pos_out, +loff_t len); +extern loff_t vfs_clone_file_range (struct file *file_in,loff_t pos_in, +struct file *file_out,loff_t pos_out, +loff_t len);extern int vfs_dedupe_file_range_compare (struct inode *src,loff_t srcoff,struct inode *dest,loff_t destoff,loff_t len,bool *is_same);extern int vfs_dedupe_file_range (struct file *file,struct file_dedupe_range *same); -extern int vfs_dedupe_file_range_one (struct file *src_file,loff_t src_pos, -struct file *dst_file,loff_t dst_pos, -u64 len); +extern loff_t vfs_dedupe_file_range_one (struct file *src_file,loff_t src_pos, +struct file *dst_file,loff_t dst_pos, +loff_t len);struct super_operations {
@@ -2981,7 +2984,7 @@ extern int generic_file_readonly_mmap(struct file *, struct vm_area_struct *);extern ssize_t generic_write_checks (struct kiocb *,struct iov_iter *);extern int generic_remap_checks (struct file *file_in,loff_t pos_in,struct file *file_out,loff_t pos_out, -uint64_t *count,unsigned int remap_flags); +loff_t *count,unsigned int remap_flags);extern ssize_t generic_file_read_iter (struct kiocb *,struct iov_iter *);extern ssize_t __generic_file_write_iter (struct kiocb *,struct iov_iter *);extern ssize_t generic_file_write_iter (struct kiocb *,struct iov_iter *);
mm/filemap.c +1 -1
@@ -3001,7 +3001,7 @@ EXPORT_SYMBOL(generic_write_checks);*/ int generic_remap_checks (struct file *file_in,loff_t pos_in,struct file *file_out,loff_t pos_out, -uint64_t *req_count,unsigned int remap_flags) +loff_t *req_count,unsigned int remap_flags) {struct inode *inode_in = file_in->f_mapping->host;struct inode *inode_out = file_out->f_mapping->host;
PATCH v2 13/29 vfs: make remap_file_range functions take and return bytes completed
From: Darrick J. Wong <[email protected]>
Change the remap_file_range functions to take a number of bytes to operate upon and return the number of bytes they operated on. This is a requirement for allowing fs implementations to return short clone/dedupe results to the user, which will enable us to obey resource limits in a graceful manner.
A subsequent patch will enable copy_file_range to signal to the ->clone_file_range implementation that it can handle a short length, which will be returned in the function's return value. For now the short return is not implemented anywhere so the behavior won't change -- either copy_file_range manages to clone the entire range or it tries an alternative.
Neither clone ioctl can take advantage of this, alas.
--- Documentation/filesystems/vfs.txt | 10 ++++---- fs/btrfs/ctree.h | 6 ++--- fs/btrfs/ioctl.c | 13 ++++++---- fs/cifs/cifsfs.c | 6 ++--- fs/ioctl.c | 10 +++++++- fs/nfs/nfs4file.c | 6 ++--- fs/nfsd/vfs.c | 8 +++++- fs/ocfs2/file.c | 16 ++++++------ fs/ocfs2/refcounttree.c | 2 +- fs/ocfs2/refcounttree.h | 2 +- fs/overlayfs/copy_up.c | 6 ++--- fs/overlayfs/file.c | 12 +++++---- fs/read_write.c | 49 ++++++++++++++++++++----------------- fs/xfs/xfs_file.c | 9 +++++-- fs/xfs/xfs_reflink.c | 4 ++- fs/xfs/xfs_reflink.h | 2 +- include/linux/fs.h | 27 +++++++++++--------- mm/filemap.c | 2 +- 18 files changed, 108 insertions(+), 82 deletions(-)
Documentation/filesystems/vfs.txt +5 -5
@@ -883,9 +883,9 @@ struct file_operations { unsigned (*mmap_capabilities)(struct file *); #endif ssize_t (*copy_file_range)(struct file *, loff_t, struct file *, loff_t, size_t, unsigned int); - int (*remap_file_range)(struct file *file_in, loff_t pos_in, - struct file *file_out, loff_t pos_out, - u64 len, unsigned int remap_flags); + loff_t (*remap_file_range)(struct file *file_in, loff_t pos_in, + struct file *file_out, loff_t pos_out, + loff_t len, unsigned int remap_flags); int (*fadvise)(struct file *, loff_t, loff_t, int); };
@@ -966,8 +966,8 @@ otherwise noted. implementation should remap len bytes at pos_in of the source file into the dest file at pos_out. Implementations must handle callers passing in len == 0; this means "remap to the end of the source file". The - return value should be zero if all bytes were remapped, or the usual - negative error code if the remapping did not succeed completely. + return value should the number of bytes remapped, or the usual + negative error code if errors occurred before any bytes were remapped. The remap_flags parameter accepts REMAP_FILE_* flags. If REMAP_FILE_DEDUP is set then the implementation must only remap if the requested file ranges have identical contents.
fs/btrfs/ctree.h +3 -3
@@ -3247,9 +3247,9 @@ int btrfs_dirty_pages(struct inode *inode, struct page **pages, size_t num_pages, loff_t pos, size_t write_bytes, struct extent_state **cached);int btrfs_fdatawrite_range (struct inode *inode,loff_t start,loff_t end); -int btrfs_remap_file_range (struct file *file_in,loff_t pos_in, -struct file *file_out,loff_t pos_out,u64 len, -unsigned int remap_flags); +loff_t btrfs_remap_file_range (struct file *file_in,loff_t pos_in, +struct file *file_out,loff_t pos_out, +loff_t len,unsigned int remap_flags);/* tree-defrag.c */ int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,
fs/btrfs/ioctl.c +8 -5
@@ -4328,10 +4328,12 @@ static noinline int btrfs_clone_files(struct file *file, struct file *file_src,return ret; } -int btrfs_remap_file_range (struct file *src_file,loff_t off, -struct file *dst_file,loff_t destoff,u64 len, +loff_t btrfs_remap_file_range (struct file *src_file,loff_t off, +struct file *dst_file,loff_t destoff,loff_t len,unsigned int remap_flags) { +int ret; +if (remap_flags & ~(REMAP_FILE_DEDUP |REMAP_FILE_ADVISORY ))return -EINVAL ;
@@ -4349,10 +4351,11 @@ int btrfs_remap_file_range(struct file *src_file, loff_t off,return -EINVAL ; } -return btrfs_extent_same (src, off, len, dst, destoff); + ret =btrfs_extent_same (src, off, len, dst, destoff); + }else { + ret =btrfs_clone_files (dst_file, src_file, off, len, destoff); } - -return btrfs_clone_files (dst_file, src_file, off, len, destoff); +return ret <0 ? ret : len; }static long btrfs_ioctl_default_subvol (struct file *file,void __user *argp)
fs/cifs/cifsfs.c +3 -3
@@ -975,8 +975,8 @@ const struct inode_operations cifs_symlink_inode_ops = { .listxattr = cifs_listxattr, }; -static int cifs_remap_file_range (struct file *src_file,loff_t off, -struct file *dst_file,loff_t destoff,u64 len, +static loff_t cifs_remap_file_range (struct file *src_file,loff_t off, +struct file *dst_file,loff_t destoff,loff_t len,unsigned int remap_flags) {struct inode *src_inode =file_inode (src_file);
@@ -1029,7 +1029,7 @@ static int cifs_remap_file_range(struct file *src_file, loff_t off,unlock_two_nondirectories (src_inode, target_inode); out:free_xid (xid); -return rc; +return rc <0 ? rc : len; } ssize_t cifs_file_copychunk_range(unsigned int xid,
fs/ioctl.c +9 -1
@@ -223,6 +223,7 @@ static long ioctl_file_clone(struct file *dst_file, unsigned long srcfd, u64 off, u64 olen, u64 destoff) { struct fd src_file = fdget(srcfd); +loff_t cloned;int ret;if (!src_file.file)
@@ -230,7 +231,14 @@ static long ioctl_file_clone(struct file *dst_file, unsigned long srcfd, ret = -EXDEV ;if (src_file.file->f_path.mnt != dst_file->f_path.mnt) goto fdput; - ret =vfs_clone_file_range (src_file.file, off, dst_file, destoff, olen); + cloned =vfs_clone_file_range (src_file.file, off, dst_file, destoff, + olen); +if (cloned <0 ) + ret = cloned; +else if (olen && cloned != olen) + ret = -EINVAL ; +else + ret =0 ; fdput:fdput (src_file);return ret;
fs/nfs/nfs4file.c +3 -3
@@ -180,8 +180,8 @@ static long nfs42_fallocate(struct file *filep, int mode, loff_t offset, loff_treturn nfs42_proc_allocate (filep, offset, len); } -static int nfs42_remap_file_range (struct file *src_file,loff_t src_off, -struct file *dst_file,loff_t dst_off,u64 count, +static loff_t nfs42_remap_file_range (struct file *src_file,loff_t src_off, +struct file *dst_file,loff_t dst_off,loff_t count,unsigned int remap_flags) {struct inode *dst_inode =file_inode (dst_file);
@@ -244,7 +244,7 @@ static int nfs42_remap_file_range(struct file *src_file, loff_t src_off, inode_unlock(src_inode); } out: -return ret; +return ret <0 ? ret : count; }#endif /* CONFIG_NFS_V4_2 */
fs/nfsd/vfs.c +6 -2
@@ -541,8 +541,12 @@ __be32 nfsd4_set_nfs4_label(struct svc_rqst *rqstp, struct svc_fh *fhp,__be32 nfsd4_clone_file_range (struct file *src,u64 src_pos,struct file *dst,u64 dst_pos,u64 count) { -return nfserrno (vfs_clone_file_range (src, src_pos, dst, dst_pos, - count)); +loff_t cloned; + + cloned =vfs_clone_file_range (src, src_pos, dst, dst_pos, count); +if (count && cloned != count) + cloned = -EINVAL ; +return nfserrno (cloned <0 ? cloned :0 ); } ssize_t nfsd_copy_file_range(struct file *src, u64 src_pos, struct file *dst,
fs/ocfs2/file.c +8 -8
@@ -2527,18 +2527,18 @@ static loff_t ocfs2_file_llseek(struct file *file, loff_t offset, int whence)return offset; } -static int ocfs2_remap_file_range (struct file *file_in, -loff_t pos_in, -struct file *file_out, -loff_t pos_out, -u64 len, -unsigned int remap_flags) +static loff_t ocfs2_remap_file_range (struct file *file_in,loff_t pos_in, +struct file *file_out,loff_t pos_out, +loff_t len,unsigned int remap_flags) { +int ret; +if (remap_flags & ~(REMAP_FILE_DEDUP |REMAP_FILE_ADVISORY ))return -EINVAL ; -return ocfs2_reflink_remap_range (file_in, pos_in, file_out, pos_out, - len, remap_flags); + ret =ocfs2_reflink_remap_range (file_in, pos_in, file_out, pos_out, + len, remap_flags); +return ret <0 ? ret : len; }const struct inode_operations ocfs2_file_iops = {
fs/ocfs2/refcounttree.c +1 -1
@@ -4824,7 +4824,7 @@ int ocfs2_reflink_remap_range(struct file *file_in,loff_t pos_in, struct file *file_out, loff_t pos_out, - u64 len, + loff_t len, unsigned int remap_flags) { struct inode *inode_in = file_inode(file_in);
fs/ocfs2/refcounttree.h +1 -1
@@ -119,7 +119,7 @@ int ocfs2_reflink_remap_range(struct file *file_in,loff_t pos_in, struct file *file_out, loff_t pos_out, - u64 len, + loff_t len, unsigned int remap_flags);#endif /* OCFS2_REFCOUNTTREE_H */
fs/overlayfs/copy_up.c +3 -3
@@ -125,6 +125,7 @@ static int ovl_copy_up_data(struct path *old, struct path *new, loff_t len)struct file *new_file;loff_t old_pos =0 ;loff_t new_pos =0 ; +loff_t cloned;int error =0 ;if (len ==0 )
@@ -141,11 +142,10 @@ static int ovl_copy_up_data(struct path *old, struct path *new, loff_t len) }/* Try to use clone_file_range to clone up within the same fs */ - error =do_clone_file_range (old_file,0 , new_file,0 , len); -if (!error) + cloned =do_clone_file_range (old_file,0 , new_file,0 , len); +if (cloned == len) goto out;/* Couldn't clone, so now we try to copy the data */ - error =0 ;/* FIXME: copy up sparse files efficiently */ while (len) {
fs/overlayfs/file.c +6 -6
@@ -434,14 +434,14 @@ enum ovl_copyop { OVL_DEDUPE, }; -static ssize_t ovl_copyfile (struct file *file_in,loff_t pos_in, +static loff_t ovl_copyfile (struct file *file_in,loff_t pos_in,struct file *file_out,loff_t pos_out, -u64 len,unsigned int flags,enum ovl_copyop op) +loff_t len,unsigned int flags,enum ovl_copyop op) {struct inode *inode_out =file_inode (file_out);struct fd real_in, real_out;const struct cred *old_cred; -ssize_t ret; +loff_t ret; ret =ovl_real_fdget (file_out, &real_out);if (ret)
@@ -489,9 +489,9 @@ static ssize_t ovl_copy_file_range(struct file *file_in, loff_t pos_in, OVL_COPY); } -static int ovl_remap_file_range (struct file *file_in,loff_t pos_in, -struct file *file_out,loff_t pos_out, -u64 len,unsigned int remap_flags) +static loff_t ovl_remap_file_range (struct file *file_in,loff_t pos_in, +struct file *file_out,loff_t pos_out, +loff_t len,unsigned int remap_flags) {enum ovl_copyop op;
fs/read_write.c +27 -22
110 lines not on this page · raw message
fs/xfs/xfs_file.c +6 -3
@@ -919,20 +919,23 @@ xfs_file_fallocate(return error; } -STATIC int +STATIC loff_txfs_file_remap_range (struct file *file_in,loff_t pos_in,struct file *file_out,loff_t pos_out, -u64 len, +loff_t len,unsigned int remap_flags) { +int ret; +if (remap_flags & ~(REMAP_FILE_DEDUP |REMAP_FILE_ADVISORY ))return -EINVAL ; -return xfs_reflink_remap_range (file_in, pos_in, file_out, pos_out, + ret =xfs_reflink_remap_range (file_in, pos_in, file_out, pos_out, len, remap_flags); +return ret <0 ? ret : len; }STATIC int
fs/xfs/xfs_reflink.c +2 -2
@@ -1296,7 +1296,7 @@ xfs_reflink_remap_prep(loff_t pos_in, struct file *file_out, loff_t pos_out, - u64 *len, + loff_t *len, unsigned int remap_flags) { struct inode *inode_in = file_inode(file_in);
@@ -1387,7 +1387,7 @@ xfs_reflink_remap_range(loff_t pos_in, struct file *file_out, loff_t pos_out, - u64 len, + loff_t len, unsigned int remap_flags) { struct inode *inode_in = file_inode(file_in);
fs/xfs/xfs_reflink.h +1 -1
@@ -28,7 +28,7 @@ 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, -struct file *file_out,loff_t pos_out,u64 len, +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,struct xfs_inode *ip,bool *has_shared);
include/linux/fs.h +15 -12
@@ -1777,9 +1777,9 @@ struct file_operations {#endif ssize_t (*copy_file_range)(struct file *,loff_t ,struct file *,loff_t ,size_t ,unsigned int ); -int (*remap_file_range)(struct file *file_in,loff_t pos_in, -struct file *file_out,loff_t pos_out, -u64 len,unsigned int remap_flags); +loff_t (*remap_file_range)(struct file *file_in,loff_t pos_in, +struct file *file_out,loff_t pos_out, +loff_t len,unsigned int remap_flags);int (*fadvise)(struct file *,loff_t ,loff_t ,int ); } __randomize_layout;
@@ -1844,19 +1844,22 @@ extern ssize_t vfs_copy_file_range(struct file *, loff_t , struct file *, loff_t, size_t, unsigned int);extern int generic_remap_file_range_prep (struct file *file_in,loff_t pos_in,struct file *file_out,loff_t pos_out, -u64 *count,unsigned int remap_flags); -extern int do_clone_file_range (struct file *file_in,loff_t pos_in, -struct file *file_out,loff_t pos_out,u64 len); -extern int vfs_clone_file_range (struct file *file_in,loff_t pos_in, -struct file *file_out,loff_t pos_out,u64 len); +loff_t *count, +unsigned int remap_flags); +extern loff_t do_clone_file_range (struct file *file_in,loff_t pos_in, +struct file *file_out,loff_t pos_out, +loff_t len); +extern loff_t vfs_clone_file_range (struct file *file_in,loff_t pos_in, +struct file *file_out,loff_t pos_out, +loff_t len);extern int vfs_dedupe_file_range_compare (struct inode *src,loff_t srcoff,struct inode *dest,loff_t destoff,loff_t len,bool *is_same);extern int vfs_dedupe_file_range (struct file *file,struct file_dedupe_range *same); -extern int vfs_dedupe_file_range_one (struct file *src_file,loff_t src_pos, -struct file *dst_file,loff_t dst_pos, -u64 len); +extern loff_t vfs_dedupe_file_range_one (struct file *src_file,loff_t src_pos, +struct file *dst_file,loff_t dst_pos, +loff_t len);struct super_operations {
@@ -2986,7 +2989,7 @@ extern int generic_file_readonly_mmap(struct file *, struct vm_area_struct *);extern ssize_t generic_write_checks (struct kiocb *,struct iov_iter *);extern int generic_remap_checks (struct file *file_in,loff_t pos_in,struct file *file_out,loff_t pos_out, -uint64_t *count,unsigned int remap_flags); +loff_t *count,unsigned int remap_flags);extern ssize_t generic_file_read_iter (struct kiocb *,struct iov_iter *);extern ssize_t __generic_file_write_iter (struct kiocb *,struct iov_iter *);extern ssize_t generic_file_write_iter (struct kiocb *,struct iov_iter *);
mm/filemap.c +1 -1
@@ -2994,7 +2994,7 @@ EXPORT_SYMBOL(generic_write_checks);*/ int generic_remap_checks (struct file *file_in,loff_t pos_in,struct file *file_out,loff_t pos_out, -uint64_t *req_count,unsigned int remap_flags) +loff_t *req_count,unsigned int remap_flags) {struct inode *inode_in = file_in->f_mapping->host;struct inode *inode_out = file_out->f_mapping->host;
PATCH v6 14/29 vfs: plumb remap flags through the vfs clone functions
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Plumb a remap_flags argument through the {do,vfs}_clone_file_range functions so that clone can take advantage of it.
--- fs/ioctl.c | 2 +- fs/nfsd/vfs.c | 2 +- fs/overlayfs/copy_up.c | 2 +- fs/overlayfs/file.c | 6 +++--- fs/read_write.c | 13 +++++++++---- include/linux/fs.h | 4 ++-- 6 files changed, 17 insertions(+), 12 deletions(-)
fs/ioctl.c +1 -1
@@ -232,7 +232,7 @@ static long ioctl_file_clone(struct file *dst_file, unsigned long srcfd,if (src_file.file->f_path.mnt != dst_file->f_path.mnt) goto fdput; cloned =vfs_clone_file_range (src_file.file, off, dst_file, destoff, - olen); + olen,0 );if (cloned <0 ) ret = cloned;else if (olen && cloned != olen)
fs/nfsd/vfs.c +1 -1
@@ -543,7 +543,7 @@ __be32 nfsd4_clone_file_range(struct file *src, u64 src_pos, struct file *dst, {loff_t cloned; - cloned =vfs_clone_file_range (src, src_pos, dst, dst_pos, count); + cloned =vfs_clone_file_range (src, src_pos, dst, dst_pos, count,0 );if (count && cloned != count) cloned = -EINVAL ;return nfserrno (cloned <0 ? cloned :0 );
fs/overlayfs/copy_up.c +1 -1
@@ -142,7 +142,7 @@ static int ovl_copy_up_data(struct path *old, struct path *new, loff_t len) }/* Try to use clone_file_range to clone up within the same fs */ - cloned =do_clone_file_range (old_file,0 , new_file,0 , len); + cloned =do_clone_file_range (old_file,0 , new_file,0 , len,0 );if (cloned == len) goto out;/* Couldn't clone, so now we try to copy the data */
fs/overlayfs/file.c +3 -3
@@ -462,7 +462,7 @@ static loff_t ovl_copyfile(struct file *file_in, loff_t pos_in,case OVL_CLONE : ret =vfs_clone_file_range (real_in.file, pos_in, - real_out.file, pos_out, len); + real_out.file, pos_out, len, flags);break ;case OVL_DEDUPE :
@@ -512,8 +512,8 @@ static loff_t ovl_remap_file_range(struct file *file_in, loff_t pos_in, !ovl_inode_upper(file_inode(file_out))))return -EPERM ; -return ovl_copyfile (file_in, pos_in, file_out, pos_out, len,0 , - op); +return ovl_copyfile (file_in, pos_in, file_out, pos_out, len, + remap_flags, op); }const struct file_operations ovl_file_operations = {
fs/read_write.c +9 -4
@@ -1848,12 +1848,15 @@ int generic_remap_file_range_prep(struct file *file_in, loff_t pos_in,EXPORT_SYMBOL (generic_remap_file_range_prep);loff_t do_clone_file_range (struct file *file_in,loff_t pos_in, -struct file *file_out,loff_t pos_out,loff_t len) +struct file *file_out,loff_t pos_out, +loff_t len,unsigned int remap_flags) {struct inode *inode_in =file_inode (file_in);struct inode *inode_out =file_inode (file_out);loff_t ret; +WARN_ON_ONCE (remap_flags); +if (S_ISDIR (inode_in->i_mode) ||S_ISDIR (inode_out->i_mode))return -EISDIR ;if (!S_ISREG (inode_in->i_mode) || !S_ISREG (inode_out->i_mode))
@@ -1884,7 +1887,7 @@ loff_t do_clone_file_range(struct file *file_in, loff_t pos_in,return ret; ret = file_in->f_op->remap_file_range (file_in, pos_in, - file_out, pos_out, len,0 ); + file_out, pos_out, len, remap_flags);if (ret <0 )return ret;
@@ -1895,12 +1898,14 @@ loff_t do_clone_file_range(struct file *file_in, loff_t pos_in,EXPORT_SYMBOL (do_clone_file_range);loff_t vfs_clone_file_range (struct file *file_in,loff_t pos_in, -struct file *file_out,loff_t pos_out,loff_t len) +struct file *file_out,loff_t pos_out, +loff_t len,unsigned int remap_flags) {loff_t ret;file_start_write (file_out); - ret =do_clone_file_range (file_in, pos_in, file_out, pos_out, len); + ret =do_clone_file_range (file_in, pos_in, file_out, pos_out, len, + remap_flags);file_end_write (file_out);return ret;
include/linux/fs.h +2 -2
@@ -1843,10 +1843,10 @@ extern int generic_remap_file_range_prep(struct file *file_in, loff_t pos_in, unsigned int remap_flags);extern loff_t do_clone_file_range (struct file *file_in,loff_t pos_in,struct file *file_out,loff_t pos_out, -loff_t len); +loff_t len,unsigned int remap_flags);extern loff_t vfs_clone_file_range (struct file *file_in,loff_t pos_in,struct file *file_out,loff_t pos_out, -loff_t len); +loff_t len,unsigned int remap_flags);extern int vfs_dedupe_file_range_compare (struct inode *src,loff_t srcoff,struct inode *dest,loff_t destoff,loff_t len,bool *is_same);
PATCH v6 15/29 vfs: plumb remap flags through the vfs dedupe functions
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Plumb a remap_flags argument through the vfs_dedupe_file_range_one functions so that dedupe can take advantage of it.
--- fs/overlayfs/file.c | 3 ++- fs/read_write.c | 9 ++++++--- include/linux/fs.h | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-)
fs/overlayfs/file.c +2 -1
@@ -467,7 +467,8 @@ static loff_t ovl_copyfile(struct file *file_in, loff_t pos_in,case OVL_DEDUPE : ret =vfs_dedupe_file_range_one (real_in.file, pos_in, - real_out.file, pos_out, len); + real_out.file, pos_out, len, + flags);break ; }revert_creds (old_cred);
fs/read_write.c +6 -3
@@ -2010,10 +2010,12 @@ EXPORT_SYMBOL(vfs_dedupe_file_range_compare);loff_t vfs_dedupe_file_range_one (struct file *src_file,loff_t src_pos,struct file *dst_file,loff_t dst_pos, -loff_t len) +loff_t len,unsigned int remap_flags) {loff_t ret; +WARN_ON_ONCE (remap_flags & ~(REMAP_FILE_DEDUP )); + ret =mnt_want_write_file (dst_file);if (ret)return ret;
@@ -2044,7 +2046,7 @@ loff_t vfs_dedupe_file_range_one(struct file *src_file, loff_t src_pos, } ret = dst_file->f_op->remap_file_range (src_file, src_pos, dst_file, - dst_pos, len,REMAP_FILE_DEDUP ); + dst_pos, len, remap_flags |REMAP_FILE_DEDUP ); out_drop_write:mnt_drop_write_file (dst_file);
@@ -2112,7 +2114,8 @@ int vfs_dedupe_file_range(struct file *file, struct file_dedupe_range *same) } deduped =vfs_dedupe_file_range_one (file, off, dst_file, - info->dest_offset, len); + info->dest_offset, len, +0 );if (deduped == -EBADE ) info->status =FILE_DEDUPE_RANGE_DIFFERS ;else if (deduped <0 )
include/linux/fs.h +1 -1
@@ -1854,7 +1854,7 @@ extern int vfs_dedupe_file_range(struct file *file, struct file_dedupe_range *same);extern loff_t vfs_dedupe_file_range_one (struct file *src_file,loff_t src_pos,struct file *dst_file,loff_t dst_pos, -loff_t len); +loff_t len,unsigned int remap_flags);struct super_operations {
PATCH v6 16/29 vfs: enable remap callers that can handle short operations
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Plumb in a remap flag that enables the filesystem remap handler to shorten remapping requests for callers that can handle it. Now copy_file_range can report partial success (in case we run up against alignment problems, resource limits, etc.).
We also enable CAN_SHORTEN for fideduperange to maintain existing userspace-visible behavior where xfs/btrfs shorten the dedupe range to avoid stale post-eof data exposure.
--- fs/read_write.c | 28 ++++++++++++++++++++-------- include/linux/fs.h | 4 +++- mm/filemap.c | 11 +++++++---- 3 files changed, 30 insertions(+), 13 deletions(-)
fs/read_write.c +20 -8
@@ -1593,7 +1593,8 @@ ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in, cloned = file_in->f_op->remap_file_range (file_in, pos_in, file_out, pos_out, -min_t (loff_t,MAX_RW_COUNT , len),0 ); +min_t (loff_t,MAX_RW_COUNT , len), +REMAP_FILE_CAN_SHORTEN );if (cloned >0 ) { ret = cloned; goto done;
@@ -1721,6 +1722,8 @@ static int remap_verify_area(struct file *file, loff_t pos, loff_t len,* can't meaningfully compare post-EOF contents. * * For clone we only link a partial EOF block above the destination file's EOF. +* +* Shorten the request if possible. */ static int generic_remap_check_len(struct inode *inode_in, struct inode *inode_out,
@@ -1729,16 +1732,24 @@ static int generic_remap_check_len(struct inode *inode_in, unsigned int remap_flags) {u64 blkmask =i_blocksize (inode_in) -1 ; +loff_t new_len = *len;if ((*len & blkmask) ==0 )return 0 ; -if (remap_flags &REMAP_FILE_DEDUP ) - *len &= ~blkmask; -else if (pos_out + *len <i_size_read (inode_out)) -return -EINVAL ; +if ((remap_flags &REMAP_FILE_DEDUP ) || + pos_out + *len <i_size_read (inode_out)) + new_len &= ~blkmask; -return 0 ; +if (new_len == *len) +return 0 ; + +if (remap_flags &REMAP_FILE_CAN_SHORTEN ) { + *len = new_len; +return 0 ; + } + +return (remap_flags &REMAP_FILE_DEDUP ) ? -EBADE : -EINVAL ; }/*
@@ -2014,7 +2025,8 @@ loff_t vfs_dedupe_file_range_one(struct file *src_file, loff_t src_pos, {loff_t ret; -WARN_ON_ONCE (remap_flags & ~(REMAP_FILE_DEDUP )); +WARN_ON_ONCE (remap_flags & ~(REMAP_FILE_DEDUP | +REMAP_FILE_CAN_SHORTEN )); ret =mnt_want_write_file (dst_file);if (ret)
@@ -2115,7 +2127,7 @@ int vfs_dedupe_file_range(struct file *file, struct file_dedupe_range *same) deduped =vfs_dedupe_file_range_one (file, off, dst_file, info->dest_offset, len, -0 ); +REMAP_FILE_CAN_SHORTEN );if (deduped == -EBADE ) info->status =FILE_DEDUPE_RANGE_DIFFERS ;else if (deduped <0 )
include/linux/fs.h +3 -1
@@ -1726,14 +1726,16 @@ struct block_device_operations;* If it is called with len == 0 that means "remap to end of source file". * * REMAP_FILE_DEDUP: only remap if contents identical (i.e. deduplicate) +* REMAP_FILE_CAN_SHORTEN: caller can handle a shortened request */ #define REMAP_FILE_DEDUP (1 << 0) +#define REMAP_FILE_CAN_SHORTEN (1 << 1)/* * These flags should be taken care of by the implementation (possibly using * vfs helpers) but can be ignored by the implementation. */ -#define REMAP_FILE_ADVISORY (0) +#define REMAP_FILE_ADVISORY (REMAP_FILE_CAN_SHORTEN)struct iov_iter ;
mm/filemap.c +7 -4
@@ -3052,8 +3052,7 @@ int generic_remap_checks(struct file *file_in, loff_t pos_in, bcount =ALIGN (size_in, bs) - pos_in; }else {if (!IS_ALIGNED (count, bs)) -return -EINVAL ; - + count =ALIGN_DOWN (count, bs); bcount = count; }
@@ -3063,10 +3062,14 @@ int generic_remap_checks(struct file *file_in, loff_t pos_in, pos_out < pos_in + bcount)return -EINVAL ; -/* For now we don't support changing the length. */ -if (*req_count != count) +/* +* We shortened the request but the caller can't deal with that, so +* bounce the request back to userspace. +*/ +if (*req_count != count && !(remap_flags &REMAP_FILE_CAN_SHORTEN ))return -EINVAL ; + *req_count = count;return 0 ; }
PATCH v2 16/29 vfs: enable remap callers that can handle short operations
From: Darrick J. Wong <[email protected]>
Plumb in a remap flag that enables the filesystem remap handler to shorten remapping requests for callers that can handle it. Now copy_file_range can report partial success (in case we run up against alignment problems, resource limits, etc.).
We also enable CAN_SHORTEN for fideduperange to maintain existing userspace-visible behavior where xfs/btrfs shorten the dedupe range to avoid stale post-eof data exposure.
--- Documentation/filesystems/vfs.txt | 4 +++- fs/read_write.c | 28 ++++++++++++++++++++-------- include/linux/fs.h | 5 +++-- mm/filemap.c | 11 +++++++---- 4 files changed, 33 insertions(+), 15 deletions(-)
Documentation/filesystems/vfs.txt +3 -1
@@ -970,7 +970,9 @@ otherwise noted. negative error code if errors occurred before any bytes were remapped. The remap_flags parameter accepts REMAP_FILE_* flags. If REMAP_FILE_DEDUP is set then the implementation must only remap if the - requested file ranges have identical contents. + requested file ranges have identical contents. If REMAP_CAN_SHORTEN is + set, the caller is ok with the implementation shortening the request + length to satisfy alignment or EOF requirements (or any other reason). fadvise: possibly called by the fadvise64() system call.
fs/read_write.c +20 -8
@@ -1593,7 +1593,8 @@ ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in, cloned = file_in->f_op->remap_file_range (file_in, pos_in, file_out, pos_out, -min_t (loff_t,MAX_RW_COUNT , len),0 ); +min_t (loff_t,MAX_RW_COUNT , len), +REMAP_FILE_CAN_SHORTEN );if (cloned >0 ) { ret = cloned; goto done;
@@ -1721,6 +1722,8 @@ static int remap_verify_area(struct file *file, loff_t pos, loff_t len,* can't meaningfully compare post-EOF contents. * * For clone we only link a partial EOF block above the destination file's EOF. +* +* Shorten the request if possible. */ static int generic_remap_check_len(struct inode *inode_in, struct inode *inode_out,
@@ -1729,16 +1732,24 @@ static int generic_remap_check_len(struct inode *inode_in, unsigned int remap_flags) {u64 blkmask =i_blocksize (inode_in) -1 ; +loff_t new_len = *len;if ((*len & blkmask) ==0 )return 0 ; -if (remap_flags &REMAP_FILE_DEDUP ) - *len &= ~blkmask; -else if (pos_out + *len <i_size_read (inode_out)) -return -EINVAL ; +if ((remap_flags &REMAP_FILE_DEDUP ) || + pos_out + *len <i_size_read (inode_out)) + new_len &= ~blkmask; -return 0 ; +if (new_len == *len) +return 0 ; + +if (remap_flags &REMAP_FILE_CAN_SHORTEN ) { + *len = new_len; +return 0 ; + } + +return (remap_flags &REMAP_FILE_DEDUP ) ? -EBADE : -EINVAL ; }/*
@@ -2014,7 +2025,8 @@ loff_t vfs_dedupe_file_range_one(struct file *src_file, loff_t src_pos, {loff_t ret; -WARN_ON_ONCE (remap_flags & ~(REMAP_FILE_DEDUP )); +WARN_ON_ONCE (remap_flags & ~(REMAP_FILE_DEDUP | +REMAP_FILE_CAN_SHORTEN )); ret =mnt_want_write_file (dst_file);if (ret)
@@ -2115,7 +2127,7 @@ int vfs_dedupe_file_range(struct file *file, struct file_dedupe_range *same) deduped =vfs_dedupe_file_range_one (file, off, dst_file, info->dest_offset, len, -0 ); +REMAP_FILE_CAN_SHORTEN );if (deduped == -EBADE ) info->status =FILE_DEDUPE_RANGE_DIFFERS ;else if (deduped <0 )
include/linux/fs.h +3 -2
@@ -1727,8 +1727,10 @@ struct block_device_operations;* See Documentation/filesystems/vfs.txt for more details about this call. * * REMAP_FILE_DEDUP: only remap if contents identical (i.e. deduplicate) +* REMAP_FILE_CAN_SHORTEN: caller can handle a shortened request */ #define REMAP_FILE_DEDUP (1 << 0) +#define REMAP_FILE_CAN_SHORTEN (1 << 1)/* * These flags signal that the caller is ok with altering various aspects of
@@ -1736,9 +1738,8 @@ struct block_device_operations;* implementation; the vfs remap helper functions can take advantage of them. * Flags in this category exist to preserve the quirky behavior of the hoisted * btrfs clone/dedupe ioctls. -* There are no flags yet, but subsequent commits will add some. */ -#define REMAP_FILE_ADVISORY (0) +#define REMAP_FILE_ADVISORY (REMAP_FILE_CAN_SHORTEN)struct iov_iter ;
mm/filemap.c +7 -4
@@ -3045,8 +3045,7 @@ int generic_remap_checks(struct file *file_in, loff_t pos_in, bcount =ALIGN (size_in, bs) - pos_in; }else {if (!IS_ALIGNED (count, bs)) -return -EINVAL ; - + count =ALIGN_DOWN (count, bs); bcount = count; }
@@ -3056,10 +3055,14 @@ int generic_remap_checks(struct file *file_in, loff_t pos_in, pos_out < pos_in + bcount)return -EINVAL ; -/* For now we don't support changing the length. */ -if (*req_count != count) +/* +* We shortened the request but the caller can't deal with that, so +* bounce the request back to userspace. +*/ +if (*req_count != count && !(remap_flags &REMAP_FILE_CAN_SHORTEN ))return -EINVAL ; + *req_count = count;return 0 ; }
PATCH v6 17/29 vfs: hide file range comparison function
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
There are no callers of vfs_dedupe_file_range_compare, so we might as well make it a static helper and remove the export.
--- fs/read_write.c | 187 +++++++++++++++++++++++++--------------------------- include/linux/fs.h | 3 - 2 files changed, 91 insertions(+), 99 deletions(-)
fs/read_write.c +91 -96
@@ -1752,6 +1752,97 @@ static int generic_remap_check_len(struct inode *inode_in,return (remap_flags &REMAP_FILE_DEDUP ) ? -EBADE : -EINVAL ; } +/* +* Read a page's worth of file data into the page cache. Return the page +* locked. +*/ +static struct page *vfs_dedupe_get_page (struct inode *inode,loff_t offset) +{ +struct page *page; + + page =read_mapping_page (inode->i_mapping, offset >>PAGE_SHIFT ,NULL ); +if (IS_ERR (page)) +return page; +if (!PageUptodate (page)) { +put_page (page); +return ERR_PTR (-EIO ); + } +lock_page (page); +return page; +} + +/* +* Compare extents of two files to see if they are the same. +* Caller must have locked both inodes to prevent write races. +*/ +static int vfs_dedupe_file_range_compare (struct inode *src,loff_t srcoff, +struct inode *dest,loff_t destoff, +loff_t len,bool *is_same) +{ +loff_t src_poff; +loff_t dest_poff; +void *src_addr; +void *dest_addr; +struct page *src_page; +struct page *dest_page; +loff_t cmp_len; +bool same; +int error; + + error = -EINVAL ; + same = true; +while (len) { + src_poff = srcoff & (PAGE_SIZE -1 ); + dest_poff = destoff & (PAGE_SIZE -1 ); + cmp_len =min (PAGE_SIZE - src_poff, +PAGE_SIZE - dest_poff); + cmp_len =min (cmp_len, len); +if (cmp_len <=0 ) + goto out_error; + + src_page =vfs_dedupe_get_page (src, srcoff); +if (IS_ERR (src_page)) { + error =PTR_ERR (src_page); + goto out_error; + } + dest_page =vfs_dedupe_get_page (dest, destoff); +if (IS_ERR (dest_page)) { + error =PTR_ERR (dest_page); +unlock_page (src_page); +put_page (src_page); + goto out_error; + } + src_addr =kmap_atomic (src_page); + dest_addr =kmap_atomic (dest_page); + +flush_dcache_page (src_page); +flush_dcache_page (dest_page); + +if (memcmp (src_addr + src_poff, dest_addr + dest_poff, cmp_len)) + same = false; + +kunmap_atomic (dest_addr); +kunmap_atomic (src_addr); +unlock_page (dest_page); +unlock_page (src_page); +put_page (dest_page); +put_page (src_page); + +if (!same) +break ; + + srcoff += cmp_len; + destoff += cmp_len; + len -= cmp_len; + } + + *is_same = same; +return 0 ; + +out_error: +return error; +} +/* * Check that the two inodes are eligible for cloning, the ranges make * sense, and then flush all dirty data. Caller must ensure that the
@@ -1923,102 +2014,6 @@ loff_t vfs_clone_file_range(struct file *file_in, loff_t pos_in, }EXPORT_SYMBOL (vfs_clone_file_range); -/* -* Read a page's worth of file data into the page cache. Return the page -* locked. -*/ -static struct page *vfs_dedupe_get_page (struct inode *inode,loff_t offset) -{ -struct address_space *mapping; -struct page *page; -pgoff_t n; - - n = offset >>PAGE_SHIFT ; - mapping = inode->i_mapping; - page =read_mapping_page (mapping, n,NULL ); -if (IS_ERR (page)) -return page; -if (!PageUptodate (page)) { -put_page (page); -return ERR_PTR (-EIO ); - } -lock_page (page); -return page; -} - -/* -* Compare extents of two files to see if they are the same. -* Caller must have locked both inodes to prevent write races. -*/ -int vfs_dedupe_file_range_compare (struct inode *src,loff_t srcoff, -struct inode *dest,loff_t destoff, -loff_t len,bool *is_same) -{ -loff_t src_poff; -loff_t dest_poff; -void *src_addr; -void *dest_addr; -struct page *src_page; -struct page *dest_page; -loff_t cmp_len; -bool same; -int error; - - error = -EINVAL ; - same = true; -while (len) { - src_poff = srcoff & (PAGE_SIZE -1 ); - dest_poff = destoff & (PAGE_SIZE -1 ); - cmp_len =min (PAGE_SIZE - src_poff, -PAGE_SIZE - dest_poff); - cmp_len =min (cmp_len, len); -if (cmp_len <=0 ) - goto out_error; - - src_page =vfs_dedupe_get_page (src, srcoff); -if (IS_ERR (src_page)) { - error =PTR_ERR (src_page); - goto out_error; - } - dest_page =vfs_dedupe_get_page (dest, destoff); -if (IS_ERR (dest_page)) { - error =PTR_ERR (dest_page); -unlock_page (src_page); -put_page (src_page); - goto out_error; - } - src_addr =kmap_atomic (src_page); - dest_addr =kmap_atomic (dest_page); - -flush_dcache_page (src_page); -flush_dcache_page (dest_page); - -if (memcmp (src_addr + src_poff, dest_addr + dest_poff, cmp_len)) - same = false; - -kunmap_atomic (dest_addr); -kunmap_atomic (src_addr); -unlock_page (dest_page); -unlock_page (src_page); -put_page (dest_page); -put_page (src_page); - -if (!same) -break ; - - srcoff += cmp_len; - destoff += cmp_len; - len -= cmp_len; - } - - *is_same = same; -return 0 ; - -out_error: -return error; -} -EXPORT_SYMBOL (vfs_dedupe_file_range_compare); -loff_t vfs_dedupe_file_range_one (struct file *src_file,loff_t src_pos,struct file *dst_file,loff_t dst_pos,loff_t len,unsigned int remap_flags)
include/linux/fs.h +0 -3
@@ -1849,9 +1849,6 @@ extern loff_t do_clone_file_range(struct file *file_in, loff_t pos_in,extern loff_t vfs_clone_file_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 vfs_dedupe_file_range_compare (struct inode *src,loff_t srcoff, -struct inode *dest,loff_t destoff, -loff_t len,bool *is_same);extern int vfs_dedupe_file_range (struct file *file,struct file_dedupe_range *same); extern loff_t vfs_dedupe_file_range_one(struct file *src_file, loff_t src_pos,
PATCH v6 18/29 vfs: clean up generic_remap_file_range_prep return value
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Since the remap prep function can update the length of the remap request, we can change this function to return the usual return status instead of the odd behavior it has now.
--- fs/ocfs2/refcounttree.c | 2 +- fs/read_write.c | 6 +++--- fs/xfs/xfs_reflink.c | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-)
fs/ocfs2/refcounttree.c +1 -1
@@ -4852,7 +4852,7 @@ int ocfs2_reflink_remap_range(struct file *file_in, ret =generic_remap_file_range_prep (file_in, pos_in, file_out, pos_out, &len, remap_flags); -if (ret <=0 ) +if (ret <0 || len ==0 ) goto out_unlock;/* Lock out changes to the allocation maps and remap. */
fs/read_write.c +3 -3
@@ -1848,8 +1848,8 @@ static int vfs_dedupe_file_range_compare(struct inode *src, loff_t srcoff,* sense, and then flush all dirty data. Caller must ensure that the * inodes have been locked against any other modifications. * -* Returns: 0 for "nothing to clone", 1 for "something to clone", or -* the usual negative error code. +* If there's an error, then the usual negative error code is returned. +* Otherwise returns 0 with *len set to the request length. */ int generic_remap_file_range_prep(struct file *file_in, loff_t pos_in, struct file *file_out, loff_t pos_out,
@@ -1945,7 +1945,7 @@ int generic_remap_file_range_prep(struct file *file_in, loff_t pos_in,return ret; } -return 1 ; +return 0 ; }EXPORT_SYMBOL (generic_remap_file_range_prep);
fs/xfs/xfs_reflink.c +2 -2
@@ -1329,7 +1329,7 @@ xfs_reflink_remap_prep( ret =generic_remap_file_range_prep (file_in, pos_in, file_out, pos_out, len, remap_flags); -if (ret <=0 ) +if (ret <0 || *len ==0 ) goto out_unlock;/*
@@ -1409,7 +1409,7 @@ xfs_reflink_remap_range(/* Prepare and then clone file data. */ ret =xfs_reflink_remap_prep (file_in, pos_in, file_out, pos_out, &len, remap_flags); -if (ret <=0 ) +if (ret <0 || len ==0 )return ret;trace_xfs_reflink_remap_range (src, pos_in, len, dest, pos_out);
PATCH v6 19/29 ocfs2: truncate page cache for clone destination file before remapping
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
When cloning blocks into another file, truncate the page cache before we start remapping blocks so that concurrent reads wait for us to finish.
--- fs/ocfs2/refcounttree.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
fs/ocfs2/refcounttree.c +4 -6
@@ -4861,14 +4861,12 @@ int ocfs2_reflink_remap_range(struct file *file_in,down_write_nested (&OCFS2_I (inode_out)->ip_alloc_sem,SINGLE_DEPTH_NESTING ); - ret =ocfs2_reflink_remap_blocks (inode_in, in_bh, pos_in, inode_out, - out_bh, pos_out, len); -/* Zap any page cache for the destination file's range. */ -if (!ret) -truncate_inode_pages_range (&inode_out->i_data, pos_out, -PAGE_ALIGN (pos_out + len) -1 ); +truncate_inode_pages_range (&inode_out->i_data, pos_out, +PAGE_ALIGN (pos_out + len) -1 ); + ret =ocfs2_reflink_remap_blocks (inode_in, in_bh, pos_in, inode_out, + out_bh, pos_out, len);up_write (&OCFS2_I (inode_in)->ip_alloc_sem);if (!same_inode)up_write (&OCFS2_I (inode_out)->ip_alloc_sem);
PATCH v6 20/29 ocfs2: fix pagecache truncation prior to reflink
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Prior to remapping blocks, it is necessary to remove pages from the destination file's page cache. Unfortunately, the truncation is not aggressive enough -- if page size > block size, we'll end up zeroing subpage blocks instead of removing them. So, round the start offset down and the end offset up to page boundaries. We already wrote all the dirty data so the larger range should be fine.
--- fs/ocfs2/refcounttree.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
fs/ocfs2/refcounttree.c +3 -2
@@ -4862,8 +4862,9 @@ int ocfs2_reflink_remap_range(struct file *file_in, SINGLE_DEPTH_NESTING);/* Zap any page cache for the destination file's range. */ -truncate_inode_pages_range (&inode_out->i_data, pos_out, -PAGE_ALIGN (pos_out + len) -1 ); +truncate_inode_pages_range (&inode_out->i_data, +round_down (pos_out,PAGE_SIZE ), +round_up (pos_out + len,PAGE_SIZE ) -1 ); ret =ocfs2_reflink_remap_blocks (inode_in, in_bh, pos_in, inode_out, out_bh, pos_out, len);
PATCH v6 21/29 ocfs2: support partial clone range and dedupe range
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Change the ocfs2 remap code to allow for returning partial results.
--- fs/ocfs2/file.c | 7 +---- fs/ocfs2/refcounttree.c | 72 +++++++++++++++++++++++++---------------------- fs/ocfs2/refcounttree.h | 12 ++++---- 3 files changed, 46 insertions(+), 45 deletions(-)
fs/ocfs2/file.c +2 -5
@@ -2531,14 +2531,11 @@ static loff_t ocfs2_remap_file_range(struct file *file_in, loff_t pos_in, struct file *file_out, loff_t pos_out, loff_t len, unsigned int remap_flags) { - int ret; - if (remap_flags & ~(REMAP_FILE_DEDUP | REMAP_FILE_ADVISORY)) return -EINVAL; - ret =ocfs2_reflink_remap_range (file_in, pos_in, file_out, pos_out, - len, remap_flags); -return ret <0 ? ret : len; +return ocfs2_reflink_remap_range (file_in, pos_in, file_out, pos_out, + len, remap_flags); } const struct inode_operations ocfs2_file_iops = {
fs/ocfs2/refcounttree.c +38 -34
137 lines not on this page · raw message
fs/ocfs2/refcounttree.h +6 -6
@@ -115,11 +115,11 @@ int ocfs2_reflink_ioctl(struct inode *inode,const char __user *oldname, const char __user *newname, bool preserve); -int ocfs2_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); +loff_t ocfs2_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);#endif /* OCFS2_REFCOUNTTREE_H */
PATCH v6 22/29 ocfs2: remove ocfs2_reflink_remap_range
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Since ocfs2_remap_file_range is a thin shell around ocfs2_remap_remap_range, move everything from the latter into the former.
--- fs/ocfs2/file.c | 68 +++++++++++++++++++++++++++- fs/ocfs2/refcounttree.c | 113 +++++++---------------------------------------- fs/ocfs2/refcounttree.h | 24 +++++++--- 3 files changed, 102 insertions(+), 103 deletions(-)
fs/ocfs2/file.c +66 -2
@@ -2531,11 +2531,75 @@ static loff_t ocfs2_remap_file_range(struct file *file_in, loff_t pos_in, struct file *file_out, loff_t pos_out, loff_t len, unsigned int remap_flags) { + struct inode *inode_in = file_inode(file_in); +struct inode *inode_out =file_inode (file_out); +struct ocfs2_super *osb =OCFS2_SB (inode_in->i_sb); +struct buffer_head *in_bh =NULL , *out_bh =NULL ; +bool same_inode = (inode_in == inode_out); +loff_t remapped =0 ; +ssize_t ret; +if (remap_flags & ~(REMAP_FILE_DEDUP |REMAP_FILE_ADVISORY ))return -EINVAL ; +if (!ocfs2_refcount_tree (osb)) +return -EOPNOTSUPP ; +if (ocfs2_is_hard_readonly (osb) ||ocfs2_is_soft_readonly (osb)) +return -EROFS ; -return ocfs2_reflink_remap_range (file_in, pos_in, file_out, pos_out, - len, remap_flags); +/* Lock both files against IO */ + ret =ocfs2_reflink_inodes_lock (inode_in, &in_bh, inode_out, &out_bh); +if (ret) +return ret; + +/* Check file eligibility and prepare for block sharing. */ + ret = -EINVAL ; +if ((OCFS2_I (inode_in)->ip_flags &OCFS2_INODE_SYSTEM_FILE ) || + (OCFS2_I (inode_out)->ip_flags &OCFS2_INODE_SYSTEM_FILE )) + goto out_unlock; + + ret =generic_remap_file_range_prep (file_in, pos_in, file_out, pos_out, + &len, remap_flags); +if (ret <0 || len ==0 ) + goto out_unlock; + +/* Lock out changes to the allocation maps and remap. */ +down_write (&OCFS2_I (inode_in)->ip_alloc_sem); +if (!same_inode) +down_write_nested (&OCFS2_I (inode_out)->ip_alloc_sem, +SINGLE_DEPTH_NESTING ); + +/* Zap any page cache for the destination file's range. */ +truncate_inode_pages_range (&inode_out->i_data, +round_down (pos_out,PAGE_SIZE ), +round_up (pos_out + len,PAGE_SIZE ) -1 ); + + remapped =ocfs2_reflink_remap_blocks (inode_in, in_bh, pos_in, + inode_out, out_bh, pos_out, len); +up_write (&OCFS2_I (inode_in)->ip_alloc_sem); +if (!same_inode) +up_write (&OCFS2_I (inode_out)->ip_alloc_sem); +if (remapped <0 ) { + ret = remapped; +mlog_errno (ret); + goto out_unlock; + } + +/* +* Empty the extent map so that we may get the right extent +* record from the disk. +*/ +ocfs2_extent_map_trunc (inode_in,0 ); +ocfs2_extent_map_trunc (inode_out,0 ); + + ret =ocfs2_reflink_update_dest (inode_out, out_bh, pos_out + len); +if (ret) { +mlog_errno (ret); + goto out_unlock; + } + +out_unlock: +ocfs2_reflink_inodes_unlock (inode_in, in_bh, inode_out, out_bh); +return remapped >0 ? remapped : ret; } const struct inode_operations ocfs2_file_iops = {
fs/ocfs2/refcounttree.c +18 -95
140 lines not on this page · raw message
fs/ocfs2/refcounttree.h +18 -6
@@ -115,11 +115,23 @@ int ocfs2_reflink_ioctl(struct inode *inode,const char __user *oldname, const char __user *newname, bool preserve); -loff_t ocfs2_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); +loff_t ocfs2_reflink_remap_blocks (struct inode *s_inode, +struct buffer_head *s_bh, +loff_t pos_in, +struct inode *t_inode, +struct buffer_head *t_bh, +loff_t pos_out, +loff_t len); +int ocfs2_reflink_inodes_lock (struct inode *s_inode, +struct buffer_head **bh1, +struct inode *t_inode, +struct buffer_head **bh2); +void ocfs2_reflink_inodes_unlock (struct inode *s_inode, +struct buffer_head *s_bh, +struct inode *t_inode, +struct buffer_head *t_bh); +int ocfs2_reflink_update_dest (struct inode *dest, +struct buffer_head *d_bh, +loff_t newlen);#endif /* OCFS2_REFCOUNTTREE_H */
PATCH v6 23/29 xfs: add a per-xfs trace_printk macro
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Add a "xfs_tprintk" macro so that developers can use trace_printk to print out arbitrary debugging information with the XFS device name attached to the trace output.
--- fs/xfs/xfs_error.h | 6 ++++++ 1 file changed, 6 insertions(+)
fs/xfs/xfs_error.h +6 -0
@@ -76,6 +76,11 @@ extern int xfs_errortag_set(struct xfs_mount *mp, unsigned int error_tag, unsigned int tag_value);extern int xfs_errortag_add (struct xfs_mount *mp,unsigned int error_tag);extern int xfs_errortag_clearall (struct xfs_mount *mp); + +/* trace printk version of xfs_err and friends */ +#define xfs_tprintk(mp, fmt, args...) \ + trace_printk("dev %d:%d " fmt, MAJOR((mp)->m_super->s_dev), \ + MINOR((mp)->m_super->s_dev), ##args)#else #define xfs_errortag_init (mp) (0)#define xfs_errortag_del (mp)
@@ -83,6 +88,7 @@ extern int xfs_errortag_clearall(struct xfs_mount *mp);#define xfs_errortag_set (mp, tag, val) (ENOSYS)#define xfs_errortag_add (mp, tag) (ENOSYS)#define xfs_errortag_clearall (mp) (ENOSYS) +#define xfs_tprintk(mp, fmt, args...) do { } while (0)#endif /* DEBUG */ /*
PATCH v6 24/29 xfs: fix pagecache truncation prior to reflink
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Prior to remapping blocks, it is necessary to remove pages from the destination file's page cache. Unfortunately, the truncation is not aggressive enough -- if page size > block size, we'll end up zeroing subpage blocks instead of removing them. So, round the start offset down and the end offset up to page boundaries. We already wrote all the dirty data so the larger range shouldn't be a problem.
--- fs/xfs/xfs_reflink.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
fs/xfs/xfs_reflink.c +3 -2
@@ -1369,8 +1369,9 @@ xfs_reflink_remap_prep( goto out_unlock;/* Zap any page cache for the destination file's range. */ -truncate_inode_pages_range (&inode_out->i_data, pos_out, -PAGE_ALIGN (pos_out + *len) -1 ); +truncate_inode_pages_range (&inode_out->i_data, +round_down (pos_out,PAGE_SIZE ), +round_up (pos_out + *len,PAGE_SIZE ) -1 );return 1 ; out_unlock:
PATCH v6 25/29 xfs: clean up xfs_reflink_remap_blocks call site
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Move the offset <-> blocks unit conversions into xfs_reflink_remap_blocks to make the call site less ugly.
--- fs/xfs/xfs_reflink.c | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-)
fs/xfs/xfs_reflink.c +18 -19
@@ -1119,16 +1119,23 @@ xfs_reflink_remap_extent( STATIC intxfs_reflink_remap_blocks (struct xfs_inode *src, -xfs_fileoff_t srcoff, +loff_t pos_in,struct xfs_inode *dest, -xfs_fileoff_t destoff, -xfs_filblks_t len, -xfs_off_t new_isize) +loff_t pos_out, +loff_t remap_len) {struct xfs_bmbt_irec imap; +xfs_fileoff_t srcoff; +xfs_fileoff_t destoff; +xfs_filblks_t len; +xfs_filblks_t range_len; +xfs_off_t new_isize = pos_out + remap_len;int nimaps;int error =0 ; -xfs_filblks_t range_len; + + destoff =XFS_B_TO_FSBT (src->i_mount, pos_out); + srcoff =XFS_B_TO_FSBT (src->i_mount, pos_in); + len =XFS_B_TO_FSB (src->i_mount, remap_len);/* drange = (destoff, destoff + len); srange = (srcoff, srcoff + len) */ while (len) {
@@ -1143,7 +1150,7 @@ xfs_reflink_remap_blocks( error =xfs_bmapi_read (src, srcoff, len, &imap, &nimaps,0 );xfs_iunlock (src, lock_mode);if (error) - goto err; +break ;ASSERT (nimaps ==1 ); trace_xfs_reflink_remap_imap(src, srcoff, len, XFS_IO_OVERWRITE,
@@ -1157,11 +1164,11 @@ xfs_reflink_remap_blocks( error =xfs_reflink_remap_extent (dest, &imap, destoff, new_isize);if (error) - goto err; +break ;if (fatal_signal_pending (current)) { error = -EINTR ; - goto err; +break ; }/* Advance drange/srange */
@@ -1170,10 +1177,8 @@ xfs_reflink_remap_blocks( len -= range_len; } -return 0 ; - -err: -trace_xfs_reflink_remap_blocks_error (dest, error, _RET_IP_); +if (error) +trace_xfs_reflink_remap_blocks_error (dest, error, _RET_IP_);return error; }
@@ -1396,8 +1401,6 @@ 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; -xfs_fileoff_t sfsbno, dfsbno; -xfs_filblks_t fsblen;xfs_extlen_t cowextsize;ssize_t ret;
@@ -1415,11 +1418,7 @@ xfs_reflink_remap_range(trace_xfs_reflink_remap_range (src, pos_in, len, dest, pos_out); - dfsbno =XFS_B_TO_FSBT (mp, pos_out); - sfsbno =XFS_B_TO_FSBT (mp, pos_in); - fsblen =XFS_B_TO_FSB (mp, len); - ret =xfs_reflink_remap_blocks (src, sfsbno, dest, dfsbno, fsblen, - pos_out + len); + ret =xfs_reflink_remap_blocks (src, pos_in, dest, pos_out, len);if (ret) goto out_unlock;
PATCH v6 26/29 xfs: support returning partial reflink results
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
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.
--- fs/xfs/xfs_file.c | 5 +---- fs/xfs/xfs_reflink.c | 17 ++++++++++++----- fs/xfs/xfs_reflink.h | 2 +- 3 files changed, 14 insertions(+), 10 deletions(-)
fs/xfs/xfs_file.c +1 -4
@@ -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
fs/xfs/xfs_reflink.c +12 -5
@@ -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; }/*
fs/xfs/xfs_reflink.h +1 -1
@@ -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,
PATCH v6 27/29 xfs: remove redundant remap partial EOF block checks
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Now that we've moved the partial EOF block checks to the VFS helpers, we can remove the redundant functionality from XFS.
--- fs/xfs/xfs_reflink.c | 19 ------------------- 1 file changed, 19 deletions(-)
fs/xfs/xfs_reflink.c +0 -19
@@ -1314,7 +1314,6 @@ xfs_reflink_remap_prep(struct inode *inode_out =file_inode (file_out);struct xfs_inode *dest =XFS_I (inode_out);bool same_inode = (inode_in == inode_out); -u64 blkmask =i_blocksize (inode_in) -1 ;ssize_t ret;/* Lock both files against IO */
@@ -1342,24 +1341,6 @@ xfs_reflink_remap_prep(if (ret <0 || *len ==0 ) goto out_unlock; -/* -* If the dedupe data matches, chop off the partial EOF block -* from the source file so we don't try to dedupe the partial -* EOF block. -*/ -if (remap_flags &REMAP_FILE_DEDUP ) { - *len &= ~blkmask; - }else if (*len & blkmask) { -/* -* The user is attempting to share a partial EOF block, -* if it's inside the destination EOF then reject it. -*/ -if (pos_out + *len <i_size_read (inode_out)) { - ret = -EINVAL ; - goto out_unlock; - } - } -/* Attach dquots to dest inode before changing block map */ ret =xfs_qm_dqattach (dest);if (ret)
PATCH v6 28/29 xfs: remove xfs_reflink_remap_range
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Since xfs_file_remap_range is a thin wrapper, move the contents of xfs_reflink_remap_range into the shell. This cuts down on the vfs calls being made from internal xfs code.
--- fs/xfs/xfs_file.c | 65 ++++++++++++++++++++++++++++++++++++++++------ fs/xfs/xfs_reflink.c | 70 +++----------------------------------------------- fs/xfs/xfs_reflink.h | 10 +++++++ 3 files changed, 70 insertions(+), 75 deletions(-)
fs/xfs/xfs_file.c +56 -9
@@ -919,20 +919,67 @@ xfs_file_fallocate(return error; } -STATIC loff_t + +loff_t xfs_file_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) +struct file *file_in, +loff_t pos_in, +struct file *file_out, +loff_t pos_out, +loff_t len, +unsigned int remap_flags) { +struct inode *inode_in =file_inode (file_in); +struct xfs_inode *src =XFS_I (inode_in); +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; +int ret; +if (remap_flags & ~(REMAP_FILE_DEDUP |REMAP_FILE_ADVISORY ))return -EINVAL ; -return xfs_reflink_remap_range (file_in, pos_in, file_out, pos_out, - len, remap_flags); +if (!xfs_sb_version_hasreflink (&mp->m_sb)) +return -EOPNOTSUPP ; + +if (XFS_FORCED_SHUTDOWN (mp)) +return -EIO ; + +/* Prepare and then clone file data. */ + ret =xfs_reflink_remap_prep (file_in, pos_in, file_out, pos_out, + &len, remap_flags); +if (ret <0 || len ==0 ) +return ret; + +trace_xfs_reflink_remap_range (src, pos_in, len, dest, pos_out); + + ret =xfs_reflink_remap_blocks (src, pos_in, dest, pos_out, len, + &remapped); +if (ret) + goto out_unlock; + +/* +* Carry the cowextsize hint from src to dest if we're sharing the +* entire source file to the entire destination file, the source file +* has a cowextsize hint, and the destination file does not. +*/ + cowextsize =0 ; +if (pos_in ==0 && len ==i_size_read (inode_in) && + (src->i_d.di_flags2 &XFS_DIFLAG2_COWEXTSIZE ) && + pos_out ==0 && len >=i_size_read (inode_out) && + !(dest->i_d.di_flags2 &XFS_DIFLAG2_COWEXTSIZE )) + cowextsize = src->i_d.di_cowextsize; + + ret =xfs_reflink_update_dest (dest, pos_out + len, cowextsize, + remap_flags); + +out_unlock: +xfs_reflink_remap_unlock (file_in, file_out); +if (ret) +trace_xfs_reflink_remap_range_error (dest, ret, _RET_IP_); +return remapped >0 ? remapped : ret; }STATIC int
fs/xfs/xfs_reflink.c +4 -66
100 lines not on this page · raw message
fs/xfs/xfs_reflink.h +10 -0
@@ -36,5 +36,15 @@ extern int xfs_reflink_clear_inode_flag(struct xfs_inode *ip, struct xfs_trans **tpp);extern int xfs_reflink_unshare (struct xfs_inode *ip,xfs_off_t offset,xfs_off_t len); +extern int xfs_reflink_remap_prep (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_remap_blocks (struct xfs_inode *src,loff_t pos_in, +struct xfs_inode *dest,loff_t pos_out,loff_t remap_len, +loff_t *remapped); +extern int xfs_reflink_update_dest (struct xfs_inode *dest,xfs_off_t newlen, +xfs_extlen_t cowextsize,unsigned int remap_flags); +extern void xfs_reflink_remap_unlock (struct file *file_in, +struct file *file_out);#endif /* __XFS_REFLINK_H */
PATCH v6 29/29 xfs: remove [cm]time update from reflink calls
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Now that the vfs remap helper dirties the inode [cm]time for us, xfs no longer needs to do that on its own.
--- fs/xfs/xfs_reflink.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
fs/xfs/xfs_reflink.c +1 -6
@@ -927,8 +927,7 @@ xfs_reflink_update_dest(struct xfs_trans *tp;int error; -if ((remap_flags &REMAP_FILE_DEDUP ) && - newlen <=i_size_read (VFS_I (dest)) && cowextsize ==0 ) +if (newlen <=i_size_read (VFS_I (dest)) && cowextsize ==0 )return 0 ; error =xfs_trans_alloc (mp, &M_RES (mp)->tr_ichange,0 ,0 ,0 , &tp);
@@ -949,10 +948,6 @@ xfs_reflink_update_dest( dest->i_d.di_flags2 |=XFS_DIFLAG2_COWEXTSIZE ; } -if (!(remap_flags &REMAP_FILE_DEDUP )) { -xfs_trans_ichgtime (tp, dest, -XFS_ICHGTIME_MOD |XFS_ICHGTIME_CHG ); - }xfs_trans_log_inode (tp, dest,XFS_ILOG_CORE ); error =xfs_trans_commit (tp);