From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx1.redhat.com ([209.132.183.28]:49038 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752666AbcJGSEz (ORCPT ); Fri, 7 Oct 2016 14:04:55 -0400 Date: Fri, 7 Oct 2016 14:04:30 -0400 From: Brian Foster Subject: Re: [PATCH 42/63] xfs: add clone file and clone range vfs functions Message-ID: <20161007180430.GE58659@bfoster.bfoster> References: <147520472904.29434.15518629624221621056.stgit@birch.djwong.org> <147520501393.29434.5617758777691039165.stgit@birch.djwong.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <147520501393.29434.5617758777691039165.stgit@birch.djwong.org> Sender: linux-xfs-owner@vger.kernel.org List-ID: List-Id: xfs To: "Darrick J. Wong" Cc: david@fromorbit.com, linux-xfs@vger.kernel.org On Thu, Sep 29, 2016 at 08:10:14PM -0700, Darrick J. Wong wrote: > Define two VFS functions which allow userspace to reflink a range of > blocks between two files or to reflink one file's contents to another. > These functions fit the new VFS ioctls that standardize the checking > for the btrfs CLONE and CLONE RANGE ioctls. > > Signed-off-by: Darrick J. Wong > --- > v2: Plug into the VFS function pointers instead of handling ioctls > directly. > --- > fs/xfs/xfs_file.c | 142 +++++++++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 142 insertions(+) > > > diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c > index 025d52f..3db3f34 100644 > --- a/fs/xfs/xfs_file.c > +++ b/fs/xfs/xfs_file.c > @@ -974,6 +974,146 @@ xfs_file_fallocate( ... > +/* Hook up to the VFS reflink function */ > +STATIC int > +xfs_file_share_range( > + struct file *file_in, > + loff_t pos_in, > + struct file *file_out, > + loff_t pos_out, > + u64 len) > +{ ... > + /* Wait for the completion of any pending IOs on srcfile */ > + ret = xfs_file_wait_for_io(inode_in, pos_in, len); > + if (ret) > + goto out_unlock; > + ret = xfs_file_wait_for_io(inode_out, pos_out, len); > + if (ret) > + goto out_unlock; > + > + ret = xfs_reflink_remap_range(XFS_I(inode_in), pos_in, XFS_I(inode_out), > + pos_out, len); > + if (ret < 0) > + goto out_unlock; > + > +out_unlock: Nit: 'out:' Brian > + return ret; > +} > + > +STATIC ssize_t > +xfs_file_copy_range( > + struct file *file_in, > + loff_t pos_in, > + struct file *file_out, > + loff_t pos_out, > + size_t len, > + unsigned int flags) > +{ > + int error; > + > + error = xfs_file_share_range(file_in, pos_in, file_out, pos_out, > + len); > + if (error) > + return error; > + return len; > +} > + > +STATIC int > +xfs_file_clone_range( > + struct file *file_in, > + loff_t pos_in, > + struct file *file_out, > + loff_t pos_out, > + u64 len) > +{ > + return xfs_file_share_range(file_in, pos_in, file_out, pos_out, > + len); > +} > > STATIC int > xfs_file_open( > @@ -1634,6 +1774,8 @@ const struct file_operations xfs_file_operations = { > .release = xfs_file_release, > .fsync = xfs_file_fsync, > .fallocate = xfs_file_fallocate, > + .copy_file_range = xfs_file_copy_range, > + .clone_file_range = xfs_file_clone_range, > }; > > const struct file_operations xfs_dir_file_operations = { > > -- > To unsubscribe from this list: send the line "unsubscribe linux-xfs" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html