From: Peng Tao <tao.peng-7I+n7zu2hftEKMMhf/gKZA@public.gmane.org>
To: linux-fsdevel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: Trond Myklebust
<trond.myklebust-7I+n7zu2hftEKMMhf/gKZA@public.gmane.org>,
Anna Schumaker
<anna.schumaker-HgOvQuBEEgTQT0dZR+AlfA@public.gmane.org>,
Christoph Hellwig <hch-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>,
Zach Brown <zab-ugsP4Wv/S6ZeoWH0uzbU5w@public.gmane.org>,
Darren Hart <dvhart-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>,
Jeff Layton <jeff.layton-7I+n7zu2hftEKMMhf/gKZA@public.gmane.org>,
bfields-uC3wQj2KruNg9hUCZPvPmw@public.gmane.org,
"Darrick J. Wong"
<darrick.wong-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>,
viro-RmSDqhL/yNMiFSDQTTA3OLVCufUGDwFn@public.gmane.org,
linux-nfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-btrfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-cifs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Steve French
<steve.french-7I+n7zu2hftEKMMhf/gKZA@public.gmane.org>,
Peng Tao <tao.peng-7I+n7zu2hftEKMMhf/gKZA@public.gmane.org>
Subject: [PATCH 4/9] vfs: pull btrfs clone API to vfs layer
Date: Sun, 25 Oct 2015 07:17:11 +0800 [thread overview]
Message-ID: <1445728636-10109-5-git-send-email-tao.peng@primarydata.com> (raw)
In-Reply-To: <1445728636-10109-1-git-send-email-tao.peng-7I+n7zu2hftEKMMhf/gKZA@public.gmane.org>
Now that a few file systems are adding clone functionality, namingly
btrfs, CIFS, NFS (in another series) and XFS
(ttp://oss.sgi.com/archives/xfs/2015-06/msg00407.html), it makes sense
to pull the ioctl to common code.
Signed-off-by: Peng Tao <tao.peng-7I+n7zu2hftEKMMhf/gKZA@public.gmane.org>
---
fs/ioctl.c | 40 ++++++++++++++++++++++++++++++++++++++++
include/uapi/linux/fs.h | 9 +++++++++
2 files changed, 49 insertions(+)
diff --git a/fs/ioctl.c b/fs/ioctl.c
index 5d01d26..9a78426 100644
--- a/fs/ioctl.c
+++ b/fs/ioctl.c
@@ -215,6 +215,40 @@ static int ioctl_fiemap(struct file *filp, unsigned long arg)
return error;
}
+static long ioctl_file_clone(struct file *dst_file, unsigned long srcfd,
+ u64 off, u64 olen, u64 destoff)
+{
+ struct fd src_file = fdget(srcfd);
+ struct inode *src_inode;
+ int ret;
+
+ if (!src_file.file)
+ return -EBADF;
+ /* olen == 0 means src off to eof */
+ if (olen == 0) {
+ src_inode = file_inode(src_file.file);
+ olen = i_size_read(src_inode) - off;
+ }
+ ret = vfs_copy_file_range(src_file.file, off, dst_file,
+ destoff, olen, COPY_FILE_CLONE_ONLY);
+ /* vfs_copy_file_range returns bytes copied */
+ if (ret > 0)
+ ret = 0;
+
+ fdput(src_file);
+ return ret;
+}
+
+static long ioctl_file_clone_range(struct file *file, void __user *argp)
+{
+ struct file_clone_range args;
+
+ if (copy_from_user(&args, argp, sizeof(args)))
+ return -EFAULT;
+ return ioctl_file_clone(file, args.src_fd, args.src_offset,
+ args.src_length, args.dest_offset);
+}
+
#ifdef CONFIG_BLOCK
static inline sector_t logical_to_blk(struct inode *inode, loff_t offset)
@@ -600,6 +634,12 @@ int do_vfs_ioctl(struct file *filp, unsigned int fd, unsigned int cmd,
case FIGETBSZ:
return put_user(inode->i_sb->s_blocksize, argp);
+ case FICLONE:
+ return ioctl_file_clone(filp, arg, 0, 0, 0);
+
+ case FICLONERANGE:
+ return ioctl_file_clone_range(filp, argp);
+
default:
if (S_ISREG(inode->i_mode))
error = file_ioctl(filp, cmd, arg);
diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h
index 9b964a5..ac7f1c5 100644
--- a/include/uapi/linux/fs.h
+++ b/include/uapi/linux/fs.h
@@ -39,6 +39,13 @@
#define RENAME_EXCHANGE (1 << 1) /* Exchange source and dest */
#define RENAME_WHITEOUT (1 << 2) /* Whiteout source */
+struct file_clone_range {
+ __s64 src_fd;
+ __u64 src_offset;
+ __u64 src_length;
+ __u64 dest_offset;
+};
+
struct fstrim_range {
__u64 start;
__u64 len;
@@ -159,6 +166,8 @@ struct inodes_stat_t {
#define FIFREEZE _IOWR('X', 119, int) /* Freeze */
#define FITHAW _IOWR('X', 120, int) /* Thaw */
#define FITRIM _IOWR('X', 121, struct fstrim_range) /* Trim */
+#define FICLONE _IOW(0x94, 9, int) /* Clone */
+#define FICLONERANGE _IOW(0x94, 13, struct file_clone_range) /* Clone range */
#define FS_IOC_GETFLAGS _IOR('f', 1, long)
#define FS_IOC_SETFLAGS _IOW('f', 2, long)
--
1.8.3.1
next prev parent reply other threads:[~2015-10-24 23:17 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-24 23:17 [PATCH 0/9] vfs: move btrfs clone ioctls to common code Peng Tao
[not found] ` <1445728636-10109-1-git-send-email-tao.peng-7I+n7zu2hftEKMMhf/gKZA@public.gmane.org>
2015-10-24 23:17 ` [PATCH 1/9] vfs: add COPY_FILE_CLONE_ONLY flag Peng Tao
[not found] ` <1445728636-10109-2-git-send-email-tao.peng-7I+n7zu2hftEKMMhf/gKZA@public.gmane.org>
2015-11-13 8:58 ` Christoph Hellwig
2015-10-24 23:17 ` Peng Tao [this message]
2015-10-24 23:17 ` [PATCH 2/9] cifs: add .copy_file_range file operation Peng Tao
2015-10-27 17:13 ` Steve French
2015-10-24 23:17 ` [PATCH 3/9] nfs42: " Peng Tao
2015-10-24 23:17 ` [PATCH 5/9] btrfs: remove btrfs_ioctl_clone(_range) Peng Tao
2015-10-24 23:17 ` [PATCH 6/9] cifs: remove private handler of BTRFS_IOC_CLONE Peng Tao
2015-10-24 23:17 ` [PATCH 7/9] nfs42: remove private clone ioctl handler Peng Tao
2015-10-24 23:17 ` [PATCH 8/9] nfsd: Pass filehandle to nfs4_preprocess_stateid_op() Peng Tao
2015-10-24 23:17 ` [PATCH 9/9] NFSD: Implement the CLONE call Peng Tao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1445728636-10109-5-git-send-email-tao.peng@primarydata.com \
--to=tao.peng-7i+n7zu2hftekmmhf/gkza@public.gmane.org \
--cc=anna.schumaker-HgOvQuBEEgTQT0dZR+AlfA@public.gmane.org \
--cc=bfields-uC3wQj2KruNg9hUCZPvPmw@public.gmane.org \
--cc=darrick.wong-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org \
--cc=dvhart-VuQAYsv1563Yd54FQh9/CA@public.gmane.org \
--cc=hch-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org \
--cc=jeff.layton-7I+n7zu2hftEKMMhf/gKZA@public.gmane.org \
--cc=linux-btrfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-cifs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-fsdevel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-nfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=steve.french-7I+n7zu2hftEKMMhf/gKZA@public.gmane.org \
--cc=trond.myklebust-7I+n7zu2hftEKMMhf/gKZA@public.gmane.org \
--cc=viro-RmSDqhL/yNMiFSDQTTA3OLVCufUGDwFn@public.gmane.org \
--cc=zab-ugsP4Wv/S6ZeoWH0uzbU5w@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).