[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20161209095823.22370-1-jthumshirn@suse.de>
Date: Fri, 9 Dec 2016 10:58:23 +0100
From: Johannes Thumshirn <jthumshirn@...e.de>
To: Al Viro <viro@...iv.linux.org.uk>
Cc: Jeff Layton <jlayton@...chiereds.net>,
"J . Bruce Fields" <bfields@...ldses.org>,
linux-fsdevel@...r.kernel.org, linux-kernel@...r.kernel.org,
Linus Torvalds <torvalds@...ux-foundation.org>,
Johannes Thumshirn <jthumshirn@...e.de>
Subject: [PATCH] splice: introduce FMODE_SPLICE_READ and FMODE_SPLICE_WRITE
Introduce FMODE_SPLICE_READ and FMODE_SPLICE_WRITE. These modes check
whether it is legal to read or write a file using splice. Both get
automatically set on regular files and are not checked when a 'struct
fileoperations' includes the splice_{read,write} methods.
Suggested-by: Linus Torvalds <torvalds@...ux-foundation.org>
Cc: Al Viro <viro@...iv.linux.org.uk>
Signed-off-by: Johannes Thumshirn <jthumshirn@...e.de>
---
fs/open.c | 4 ++++
fs/splice.c | 6 ++++++
include/linux/fs.h | 5 +++++
3 files changed, 15 insertions(+)
diff --git a/fs/open.c b/fs/open.c
index d3ed817..f97acfc 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -733,6 +733,10 @@ static int do_dentry_open(struct file *f,
if (S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode))
f->f_mode |= FMODE_ATOMIC_POS;
+ if (S_ISREG(inode->i_mode))
+ f->f_mode |= FMODE_SPLICE_WRITE | FMODE_SPLICE_READ;
+
+
f->f_op = fops_get(inode->i_fop);
if (unlikely(WARN_ON(!f->f_op))) {
error = -ENODEV;
diff --git a/fs/splice.c b/fs/splice.c
index 5a7750b..5e8daff 100644
--- a/fs/splice.c
+++ b/fs/splice.c
@@ -396,6 +396,9 @@ static ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
if (pipe->nrbufs == pipe->buffers)
return -EAGAIN;
+ if (unlikely(!(in->f_mode & FMODE_SPLICE_READ)))
+ return -EINVAL;
+
/*
* Try to keep page boundaries matching to source pagecache ones -
* it probably won't be much help, but...
@@ -824,6 +827,9 @@ static ssize_t default_file_splice_write(struct pipe_inode_info *pipe,
{
ssize_t ret;
+ if (unlikely(!(out->f_mode & FMODE_SPLICE_WRITE)))
+ return -EINVAL;
+
ret = splice_from_pipe(pipe, out, ppos, len, flags, write_pipe_buf);
if (ret > 0)
*ppos += ret;
diff --git a/include/linux/fs.h b/include/linux/fs.h
index dc0478c..019dbb0 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -143,6 +143,11 @@ typedef int (dio_iodone_t)(struct kiocb *iocb, loff_t offset,
/* File was opened by fanotify and shouldn't generate fanotify events */
#define FMODE_NONOTIFY ((__force fmode_t)0x4000000)
+/* File can be read using splice */
+#define FMODE_SPLICE_READ ((__force fmode_t)0x8000000)
+/* File can be written using splice */
+#define FMODE_SPLICE_WRITE ((__force fmode_t)0x10000000)
+
/*
* Flag for rw_copy_check_uvector and compat_rw_copy_check_uvector
* that indicates that they should check the contents of the iovec are
--
1.8.5.6
Powered by blists - more mailing lists