Convert sendfile to splice
Subsystems (31)
cover Convert sendfile to splice
Hi,
This series of splice patches removes file_operations ->sendfile() from the kernel and converts do_sendfile() to use ->splice_read() to achieve the same function.
Signature · 1 line
Jens Axboe
PATCH 1/18 splice: abstract out actor data
For direct splicing (or private splicing), the output may not be a file. So abstract out the handling into a specified actor function and put the data in the splice_desc structure earlier, so we can build on top of that.
This is the first step in better splice handling for drivers, and also for implementing vmsplice _to_ user memory.
--- fs/ocfs2/file.c | 11 ++++- fs/splice.c | 100 ++++++++++++++++++++++++++++++++------------- include/linux/pipe_fs_i.h | 10 +++-- 3 files changed, 85 insertions(+), 36 deletions(-)
fs/ocfs2/file.c +8 -3
@@ -1636,9 +1636,14 @@ static ssize_t __ocfs2_file_splice_write(struct pipe_inode_info *pipe,int ret, err;struct address_space *mapping = out->f_mapping;struct inode *inode = mapping->host; - - ret =__splice_from_pipe (pipe, out, ppos, len, flags, - ocfs2_splice_write_actor); +struct splice_desc sd = { + .total_len = len, + .flags = flags, + .pos = *ppos, + }; + + sd.file = out; + ret =__splice_from_pipe (pipe, &sd, ocfs2_splice_write_actor);if (ret >0 ) { *ppos += ret;
fs/splice.c +71 -29
198 lines not on this page · raw message
include/linux/pipe_fs_i.h +6 -4
@@ -94,13 +94,15 @@ struct splice_desc {typedef int (splice_actor )(struct pipe_inode_info *,struct pipe_buffer *,struct splice_desc *); +typedef int (splice_direct_actor )(struct pipe_inode_info *, +struct splice_desc *);extern ssize_t splice_from_pipe (struct pipe_inode_info *,struct file *,loff_t *,size_t ,unsigned int ,splice_actor *); - -extern ssize_t __splice_from_pipe (struct pipe_inode_info *,struct file *, -loff_t *,size_t ,unsigned int , -splice_actor *); +extern ssize_t __splice_from_pipe (struct pipe_inode_info *, +struct splice_desc *,splice_actor *); +extern ssize_t splice_direct_to_actor (struct file *,struct splice_desc *, +splice_direct_actor *);#endif
Signature · 1 line
1.5.2.1.174.gcd03
Re: [PATCH 1/18] splice: abstract out actor data
fs/ocfs2/file.c static ssize_t __ocfs2_file_splice_write(struct pipe_inode_info *pipe, · line 1645
Quoted 7 lines · On Tue, 12 Jun 2007 08:57:57 +0200 Jens Axboe <[email protected]> wrote:
fs/ocfs2/file.c +7
-0+struct splice_desc sd = { + .total_len = len, + .flags = flags, + .pos = *ppos, + }; + + sd.file = out;
minor remark, why sd.file is setup differently than other fields ?
(this several times on this patch)
Re: [PATCH 1/18] splice: abstract out actor data
Quoted 14 lines · Eric Dumazet
fs/ocfs2/file.c static ssize_t __ocfs2_file_splice_write(struct pipe_inode_info *pipe, · line 1645
Quoted 7 lines · On Tue, 12 Jun 2007 08:57:57 +0200 Jens Axboe <[email protected]> wrote:
fs/ocfs2/file.c +7
-0+struct splice_desc sd = { + .total_len = len, + .flags = flags, + .pos = *ppos, + }; + + sd.file = out;minor remark, why sd.file is setup differently than other fields ?
Quoted 1 line
(this several times on this patch)
yeah, it's inside an anonymous union, and apparently gcc doesn't like it being initialized that way.
Signature · 1 line
Jens Axboe
Re: [PATCH 1/18] splice: abstract out actor data
Quoted 15 lines · Jens Axboe
Quoted 14 lines · Eric Dumazet
fs/ocfs2/file.c static ssize_t __ocfs2_file_splice_write(struct pipe_inode_info *pipe, · line 1645
Quoted 7 lines · On Tue, 12 Jun 2007 08:57:57 +0200 Jens Axboe <[email protected]> wrote:
fs/ocfs2/file.c +7
-0+struct splice_desc sd = { + .total_len = len, + .flags = flags, + .pos = *ppos, + }; + + sd.file = out;minor remark, why sd.file is setup differently than other fields ?
Quoted 4 lines
Quoted 1 line
(this several times on this patch)
yeah, it's inside an anonymous union, and apparently gcc doesn't like it being initialized that way.
The one time I had such a situation something along the lines of:
struct splice_desc sd = {
.total_len = len,
.flags = flags,
.pos = *ppos,
{ .file = out },
};worked.
Re: [PATCH 1/18] splice: abstract out actor data
Quoted 23 lines · Peter Zijlstra
Quoted 15 lines · Jens Axboe
Quoted 14 lines · Eric Dumazet
fs/ocfs2/file.c static ssize_t __ocfs2_file_splice_write(struct pipe_inode_info *pipe, · line 1645
Quoted 7 lines · On Tue, 12 Jun 2007 08:57:57 +0200 Jens Axboe <[email protected]> wrote:
fs/ocfs2/file.c +7
-0+struct splice_desc sd = { + .total_len = len, + .flags = flags, + .pos = *ppos, + }; + + sd.file = out;minor remark, why sd.file is setup differently than other fields ?
Quoted 4 lines
Quoted 1 line
(this several times on this patch)
yeah, it's inside an anonymous union, and apparently gcc doesn't like it being initialized that way.
The one time I had such a situation something along the lines of:
Quoted 8 lines
struct splice_desc sd = { .total_len = len, .flags = flags, .pos = *ppos, { .file = out }, };worked.
OK, that looks pretty handy. But I just threw the towel into the ring and named the union instead yesterday. The outside initialization of file/userptr/data was an eyesore to me.
Signature · 1 line
Jens Axboe
PATCH 2/18 vmsplice: add vmsplice-to-user support
In reply to Jens AxboeA bit of a cheat, it actually just copies the data to userspace. But this makes the interface nice and symmetric and enables people to build on splice, with room for future improvement in performance.
--- fs/splice.c | 142 ++++++++++++++++++++++++++++++++++++++------- include/linux/pipe_fs_i.h | 8 ++- 2 files changed, 127 insertions(+), 23 deletions(-)
fs/splice.c +120 -22
@@ -1282,28 +1282,107 @@ static int get_iovec_page_array(const struct iovec __user *iov,return error; } +static int pipe_to_user (struct pipe_inode_info *pipe,struct pipe_buffer *buf, +struct splice_desc *sd) +{ +int ret; + + ret = buf->ops->pin (pipe, buf); +if (!ret) { +/* +* use non-atomic map, can be optimized to map atomically if we +* prefault the user memory. +*/ +char *src = buf->ops->map (pipe, buf,0 ); + +if (copy_to_user (sd->userptr, src, sd->len)) + ret = -EFAULT ; + + buf->ops->unmap (pipe, buf, src); + +if (!ret) +return sd->len; + } + +return ret; +} + +/* +* For lack of a better implementation, implement vmsplice() to userspace +* as a simple copy of the pipes pages to the user iov. +*/ +static long vmsplice_to_user (struct file *file,const struct iovec __user *iov, +unsigned long nr_segs,unsigned int flags) +{ +struct pipe_inode_info *pipe; +struct splice_desc sd; +ssize_t size; +int error; +long ret; + + pipe =pipe_info (file->f_path.dentry->d_inode); +if (!pipe) +return -EBADF ; + +if (pipe->inode) +mutex_lock (&pipe->inode->i_mutex); + + ret =0 ; +while (nr_segs) { +void __user *base; +size_t len; + +/* +* Get user address base and length for this iovec. +*/ + error =get_user (base, &iov->iov_base); +if (unlikely (error)) +break ; + error =get_user (len, &iov->iov_len); +if (unlikely (error)) +break ; + +/* +* Sanity check this iovec. 0 read succeeds. +*/ +if (unlikely (!len)) +break ; + error = -EFAULT ; +if (unlikely (!base)) +break ; + + sd.len =0 ; + sd.total_len = len; + sd.flags = flags; + sd.userptr = base; + sd.pos =0 ; + + size =__splice_from_pipe (pipe, &sd, pipe_to_user); +if (size <0 ) { +if (!ret) + ret = size; + +break ; + } + + nr_segs--; + iov++; + ret += size; + } + +if (pipe->inode) +mutex_unlock (&pipe->inode->i_mutex); + +return ret; +} +/* * vmsplice splices a user address range into a pipe. It can be thought of * as splice-from-memory, where the regular splice is splice-from-file (or * to file). In both cases the output is a pipe, naturally. -* -* Note that vmsplice only supports splicing _from_ user memory to a pipe, -* not the other way around. Splicing from user memory is a simple operation -* that can be supported without any funky alignment restrictions or nasty -* vm tricks. We simply map in the user memory and fill them into a pipe. -* The reverse isn't quite as easy, though. There are two possible solutions -* for that: -* -* - memcpy() the data internally, at which point we might as well just -* do a regular read() on the buffer anyway. -* - Lots of nasty vm tricks, that are neither fast nor flexible (it -* has restriction limitations on both ends of the pipe). -* -* Alas, it isn't here. -* */ -static long do_vmsplice (struct file *file,const struct iovec __user *iov, -unsigned long nr_segs,unsigned int flags) +static long vmsplice_to_pipe (struct file *file,const struct iovec __user *iov, +unsigned long nr_segs,unsigned int flags) {struct pipe_inode_info *pipe;struct page *pages[PIPE_BUFFERS ];
@@ -1318,10 +1397,6 @@ static long do_vmsplice(struct file *file, const struct iovec __user *iov, pipe =pipe_info (file->f_path.dentry->d_inode);if (!pipe)return -EBADF ; -if (unlikely (nr_segs >UIO_MAXIOV )) -return -EINVAL ; -else if (unlikely (!nr_segs)) -return 0 ; spd.nr_pages =get_iovec_page_array (iov, nr_segs, pages, partial, flags &SPLICE_F_GIFT );
@@ -1331,6 +1406,22 @@ static long do_vmsplice(struct file *file, const struct iovec __user *iov,return splice_to_pipe (pipe, &spd); } +/* +* Note that vmsplice only really supports true splicing _from_ user memory +* to a pipe, not the other way around. Splicing from user memory is a simple +* operation that can be supported without any funky alignment restrictions +* or nasty vm tricks. We simply map in the user memory and fill them into +* a pipe. The reverse isn't quite as easy, though. There are two possible +* solutions for that: +* +* - memcpy() the data internally, at which point we might as well just +* do a regular read() on the buffer anyway. +* - Lots of nasty vm tricks, that are neither fast nor flexible (it +* has restriction limitations on both ends of the pipe). +* +* Currently we punt and implement it as a normal copy, see pipe_to_user(). +* +*/ asmlinkage long sys_vmsplice (int fd,const struct iovec __user *iov,unsigned long nr_segs,unsigned int flags) {
@@ -1338,11 +1429,18 @@ asmlinkage long sys_vmsplice(int fd, const struct iovec __user *iov,long error;int fput; +if (unlikely (nr_segs >UIO_MAXIOV )) +return -EINVAL ; +else if (unlikely (!nr_segs)) +return 0 ; + error = -EBADF ; file =fget_light (fd, &fput);if (file) {if (file->f_mode &FMODE_WRITE ) - error =do_vmsplice (file, iov, nr_segs, flags); + error =vmsplice_to_pipe (file, iov, nr_segs, flags); +else if (file->f_mode &FMODE_READ ) + error =vmsplice_to_user (file, iov, nr_segs, flags);fput_light (file, fput); }
include/linux/pipe_fs_i.h +7 -1
@@ -88,7 +88,13 @@ int generic_pipe_buf_steal(struct pipe_inode_info *, struct pipe_buffer *);struct splice_desc {unsigned int len, total_len;/* current and remaining length */ unsigned int flags;/* splice flags */ -struct file *file;/* file to read/write */ +/* +* actor() private data +*/ +union { +void __user *userptr;/* memory to write to */ +struct file *file;/* file to read/write */ + };loff_t pos;/* file position */ };
Signature · 1 line
1.5.2.1.174.gcd03
PATCH 3/18 sys_sendfile: switch to using ->splice_read, if available
In reply to Jens AxboeThis patch makes sendfile prefer to use ->splice_read(), if it's available in the file_operations structure.
--- fs/read_write.c | 24 ++++++++++++++++++++---- 1 files changed, 20 insertions(+), 4 deletions(-)
fs/read_write.c +20 -4
@@ -15,6 +15,7 @@#include <linux/module.h> #include <linux/syscalls.h> #include <linux/pagemap.h> +#include <linux/pipe_fs_i.h> #include "read_write.h" #include <asm/uaccess.h>
@@ -25,7 +26,7 @@ const struct file_operations generic_ro_fops = { .read = do_sync_read, .aio_read = generic_file_aio_read, .mmap = generic_file_readonly_mmap, - .sendfile = generic_file_sendfile, + .splice_read = generic_file_splice_read, };EXPORT_SYMBOL (generic_ro_fops);
@@ -708,7 +709,7 @@ static ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos,struct inode * in_inode, * out_inode;loff_t pos;ssize_t retval; -int fput_needed_in, fput_needed_out; +int fput_needed_in, fput_needed_out, fl;/* * Get input file, and verify that it is ok..
@@ -723,7 +724,8 @@ static ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos, in_inode = in_file->f_path.dentry->d_inode;if (!in_inode) goto fput_in; -if (!in_file->f_op || !in_file->f_op->sendfile) +if (!in_file->f_op || (!in_file->f_op->sendfile && + !in_file->f_op->splice_read)) goto fput_in; retval = -ESPIPE ;if (!ppos)
@@ -776,7 +778,21 @@ static ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos, count = max - pos; } - retval = in_file->f_op->sendfile (in_file, ppos, count, file_send_actor, out_file); +if (in_file->f_op->splice_read) { + fl =0 ; +#if 0 +/* +* We need to debate whether we can enable this or not. The +* man page documents EAGAIN return for the output at least, +* and the application is arguably buggy if it doesn't expect +* EAGAIN on a non-blocking file descriptor. +*/ +if (in_file->f_flags &O_NONBLOCK ) + fl =SPLICE_F_NONBLOCK ; +#endif + retval =do_splice_direct (in_file, ppos, out_file, count, fl); + }else + retval = in_file->f_op->sendfile (in_file, ppos, count, file_send_actor, out_file);if (retval >0 ) {add_rchar (current, retval);
Signature · 1 line
1.5.2.1.174.gcd03
PATCH 4/18 sendfile: remove .sendfile from filesystems that use generic_file_sendfile()
In reply to Jens AxboeThey can use generic_file_splice_read() instead. Since sys_sendfile() now prefers that, there should be no change in behaviour.
--- fs/adfs/file.c | 2 +- fs/affs/file.c | 2 +- fs/afs/file.c | 2 +- fs/bfs/file.c | 2 +- fs/block_dev.c | 1 - fs/cifs/cifsfs.c | 8 +++--- fs/coda/file.c | 11 +++++---- fs/ecryptfs/file.c | 15 +++++++------ fs/ext2/file.c | 1 - fs/ext3/file.c | 1 - fs/ext4/file.c | 1 - fs/fat/file.c | 2 +- fs/fuse/file.c | 4 +- fs/gfs2/ops_file.c | 1 - fs/hfs/inode.c | 2 +- fs/hfsplus/inode.c | 2 +- fs/hostfs/hostfs_kern.c | 2 +- fs/hpfs/file.c | 2 +- fs/jffs2/file.c | 2 +- fs/jfs/file.c | 1 - fs/minix/file.c | 2 +- fs/ntfs/file.c | 2 +- fs/ocfs2/file.c | 1 - fs/qnx4/file.c | 2 +- fs/ramfs/file-mmu.c | 2 +- fs/ramfs/file-nommu.c | 2 +- fs/reiserfs/file.c | 1 - fs/smbfs/file.c | 9 ++++--- fs/sysv/file.c | 2 +- fs/udf/file.c | 2 +- fs/ufs/file.c | 2 +- fs/xfs/linux-2.6/xfs_file.c | 26 ------------------------ fs/xfs/linux-2.6/xfs_linux.h | 1 - fs/xfs/linux-2.6/xfs_lrw.c | 44 ------------------------------------------ fs/xfs/linux-2.6/xfs_lrw.h | 3 -- fs/xfs/linux-2.6/xfs_vnode.h | 6 ----- fs/xfs/xfs_vnodeops.c | 3 -- 37 files changed, 43 insertions(+), 131 deletions(-)
fs/adfs/file.c +1 -1
@@ -33,7 +33,7 @@ const struct file_operations adfs_file_operations = { .fsync = file_fsync, .write = do_sync_write, .aio_write = generic_file_aio_write, - .sendfile = generic_file_sendfile, + .splice_read = generic_file_splice_read, };const struct inode_operations adfs_file_inode_operations = {
fs/affs/file.c +1 -1
@@ -35,7 +35,7 @@ const struct file_operations affs_file_operations = { .open = affs_file_open, .release = affs_file_release, .fsync = file_fsync, - .sendfile = generic_file_sendfile, + .splice_read = generic_file_splice_read, };const struct inode_operations affs_file_inode_operations = {
fs/afs/file.c +1 -1
@@ -32,7 +32,7 @@ const struct file_operations afs_file_operations = { .aio_read = generic_file_aio_read, .aio_write = afs_file_write, .mmap = generic_file_readonly_mmap, - .sendfile = generic_file_sendfile, + .splice_read = generic_file_splice_read, .fsync = afs_fsync, };
fs/bfs/file.c +1 -1
@@ -24,7 +24,7 @@ const struct file_operations bfs_file_operations = { .write = do_sync_write, .aio_write = generic_file_aio_write, .mmap = generic_file_mmap, - .sendfile = generic_file_sendfile, + .splice_read = generic_file_splice_read, };static int bfs_move_block (unsigned long from,unsigned long to,struct super_block *sb)
fs/block_dev.c +0 -1
@@ -1346,7 +1346,6 @@ const struct file_operations def_blk_fops = {#ifdef CONFIG_COMPAT .compat_ioctl = compat_blkdev_ioctl, #endif - .sendfile = generic_file_sendfile, .splice_read = generic_file_splice_read, .splice_write = generic_file_splice_write, };
fs/cifs/cifsfs.c +4 -4
@@ -616,7 +616,7 @@ const struct file_operations cifs_file_ops = { .fsync = cifs_fsync, .flush = cifs_flush, .mmap = cifs_file_mmap, - .sendfile = generic_file_sendfile, + .splice_read = generic_file_splice_read, .llseek = cifs_llseek, #ifdef CONFIG_CIFS_POSIX .ioctl = cifs_ioctl,
@@ -637,7 +637,7 @@ const struct file_operations cifs_file_direct_ops = { .lock = cifs_lock, .fsync = cifs_fsync, .flush = cifs_flush, - .sendfile = generic_file_sendfile, /* BB removeme BB */ + .splice_read = generic_file_splice_read,#ifdef CONFIG_CIFS_POSIX .ioctl = cifs_ioctl,#endif /* CONFIG_CIFS_POSIX */
@@ -656,7 +656,7 @@ const struct file_operations cifs_file_nobrl_ops = { .fsync = cifs_fsync, .flush = cifs_flush, .mmap = cifs_file_mmap, - .sendfile = generic_file_sendfile, + .splice_read = generic_file_splice_read, .llseek = cifs_llseek, #ifdef CONFIG_CIFS_POSIX .ioctl = cifs_ioctl,
@@ -676,7 +676,7 @@ const struct file_operations cifs_file_direct_nobrl_ops = { .release = cifs_close, .fsync = cifs_fsync, .flush = cifs_flush, - .sendfile = generic_file_sendfile, /* BB removeme BB */ + .splice_read = generic_file_splice_read,#ifdef CONFIG_CIFS_POSIX .ioctl = cifs_ioctl,#endif /* CONFIG_CIFS_POSIX */
fs/coda/file.c +6 -5
@@ -47,8 +47,9 @@ coda_file_read(struct file *coda_file, char __user *buf, size_t count, loff_t *p }static ssize_t -coda_file_sendfile (struct file *coda_file,loff_t *ppos,size_t count, -read_actor_t actor,void *target) +coda_file_splice_read (struct file *coda_file,loff_t *ppos, +struct pipe_inode_info *pipe,size_t count, +unsigned int flags) {struct coda_file_info *cfi;struct file *host_file;
@@ -57,10 +58,10 @@ coda_file_sendfile(struct file *coda_file, loff_t *ppos, size_t count,BUG_ON (!cfi || cfi->cfi_magic !=CODA_MAGIC ); host_file = cfi->cfi_container; -if (!host_file->f_op || !host_file->f_op->sendfile) +if (!host_file->f_op || !host_file->f_op->splice_read)return -EINVAL ; -return host_file->f_op->sendfile (host_file, ppos, count, actor, target); +return host_file->f_op->splice_read (host_file, ppos, pipe, count,flags); } static ssize_t
@@ -295,6 +296,6 @@ const struct file_operations coda_file_operations = { .flush = coda_flush, .release = coda_release, .fsync = coda_fsync, - .sendfile = coda_file_sendfile, + .splice_read = coda_file_splice_read, };
fs/ecryptfs/file.c +8 -7
@@ -338,16 +338,17 @@ static int ecryptfs_fasync(int fd, struct file *file, int flag)return rc; } -static ssize_t ecryptfs_sendfile (struct file *file,loff_t * ppos, -size_t count,read_actor_t actor,void *target) +static ssize_t ecryptfs_splice_read (struct file *file,loff_t * ppos, +struct pipe_inode_info *pipe,size_t count, +unsigned int flags) {struct file *lower_file =NULL ;int rc = -EINVAL ; lower_file =ecryptfs_file_to_lower (file); -if (lower_file->f_op && lower_file->f_op->sendfile) - rc = lower_file->f_op->sendfile (lower_file, ppos, count, - actor, target); +if (lower_file->f_op && lower_file->f_op->splice_read) + rc = lower_file->f_op->splice_read (lower_file, ppos, pipe, + count, flags);return rc; }
@@ -364,7 +365,7 @@ const struct file_operations ecryptfs_dir_fops = { .release = ecryptfs_release, .fsync = ecryptfs_fsync, .fasync = ecryptfs_fasync, - .sendfile = ecryptfs_sendfile, + .splice_read = ecryptfs_splice_read, };const struct file_operations ecryptfs_main_fops = {
@@ -381,7 +382,7 @@ const struct file_operations ecryptfs_main_fops = { .release = ecryptfs_release, .fsync = ecryptfs_fsync, .fasync = ecryptfs_fasync, - .sendfile = ecryptfs_sendfile, + .splice_read = ecryptfs_splice_read, }; static int
fs/ext2/file.c +0 -1
@@ -53,7 +53,6 @@ const struct file_operations ext2_file_operations = { .open = generic_file_open, .release = ext2_release_file, .fsync = ext2_sync_file, - .sendfile = generic_file_sendfile, .splice_read = generic_file_splice_read, .splice_write = generic_file_splice_write, };
fs/ext3/file.c +0 -1
@@ -120,7 +120,6 @@ const struct file_operations ext3_file_operations = { .open = generic_file_open, .release = ext3_release_file, .fsync = ext3_sync_file, - .sendfile = generic_file_sendfile, .splice_read = generic_file_splice_read, .splice_write = generic_file_splice_write, };
fs/ext4/file.c +0 -1
@@ -120,7 +120,6 @@ const struct file_operations ext4_file_operations = { .open = generic_file_open, .release = ext4_release_file, .fsync = ext4_sync_file, - .sendfile = generic_file_sendfile, .splice_read = generic_file_splice_read, .splice_write = generic_file_splice_write, };
fs/fat/file.c +1 -1
@@ -134,7 +134,7 @@ const struct file_operations fat_file_operations = { .release = fat_file_release, .ioctl = fat_generic_ioctl, .fsync = file_fsync, - .sendfile = generic_file_sendfile, + .splice_read = generic_file_splice_read, };static int fat_cont_expand (struct inode *inode,loff_t size)
fs/fuse/file.c +2 -2
@@ -802,7 +802,7 @@ static const struct file_operations fuse_file_operations = { .release = fuse_release, .fsync = fuse_fsync, .lock = fuse_file_lock, - .sendfile = generic_file_sendfile, + .splice_read = generic_file_splice_read, };static const struct file_operations fuse_direct_io_file_operations = {
@@ -814,7 +814,7 @@ static const struct file_operations fuse_direct_io_file_operations = { .release = fuse_release, .fsync = fuse_fsync, .lock = fuse_file_lock, -/* no mmap and sendfile */ +/* no mmap and splice_read */ };static const struct address_space_operations fuse_file_aops = {
fs/gfs2/ops_file.c +0 -1
@@ -635,7 +635,6 @@ const struct file_operations gfs2_file_fops = { .release = gfs2_close, .fsync = gfs2_fsync, .lock = gfs2_lock, - .sendfile = generic_file_sendfile, .flock = gfs2_flock, .splice_read = generic_file_splice_read, .splice_write = generic_file_splice_write,
fs/hfs/inode.c +1 -1
@@ -607,7 +607,7 @@ static const struct file_operations hfs_file_operations = { .write = do_sync_write, .aio_write = generic_file_aio_write, .mmap = generic_file_mmap, - .sendfile = generic_file_sendfile, + .splice_read = generic_file_splice_read, .fsync = file_fsync, .open = hfs_file_open, .release = hfs_file_release,
fs/hfsplus/inode.c +1 -1
@@ -288,7 +288,7 @@ static const struct file_operations hfsplus_file_operations = { .write = do_sync_write, .aio_write = generic_file_aio_write, .mmap = generic_file_mmap, - .sendfile = generic_file_sendfile, + .splice_read = generic_file_splice_read, .fsync = file_fsync, .open = hfsplus_file_open, .release = hfsplus_file_release,
fs/hostfs/hostfs_kern.c +1 -1
@@ -390,7 +390,7 @@ int hostfs_fsync(struct file *file, struct dentry *dentry, int datasync)static const struct file_operations hostfs_file_fops = { .llseek = generic_file_llseek, .read = do_sync_read, - .sendfile = generic_file_sendfile, + .splice_read = generic_file_splice_read, .aio_read = generic_file_aio_read, .aio_write = generic_file_aio_write, .write = do_sync_write,
fs/hpfs/file.c +1 -1
@@ -129,7 +129,7 @@ const struct file_operations hpfs_file_ops = .mmap = generic_file_mmap, .release = hpfs_file_release, .fsync = hpfs_file_fsync, - .sendfile = generic_file_sendfile, + .splice_read = generic_file_splice_read, }; const struct inode_operations hpfs_file_iops =
fs/jffs2/file.c +1 -1
@@ -47,7 +47,7 @@ const struct file_operations jffs2_file_operations = .ioctl = jffs2_ioctl, .mmap = generic_file_readonly_mmap, .fsync = jffs2_fsync, - .sendfile = generic_file_sendfile + .splice_read = generic_file_splice_read, };/* jffs2_file_inode_operations */
fs/jfs/file.c +0 -1
@@ -108,7 +108,6 @@ const struct file_operations jfs_file_operations = { .aio_read = generic_file_aio_read, .aio_write = generic_file_aio_write, .mmap = generic_file_mmap, - .sendfile = generic_file_sendfile, .splice_read = generic_file_splice_read, .splice_write = generic_file_splice_write, .fsync = jfs_fsync,
fs/minix/file.c +1 -1
@@ -23,7 +23,7 @@ const struct file_operations minix_file_operations = { .aio_write = generic_file_aio_write, .mmap = generic_file_mmap, .fsync = minix_sync_file, - .sendfile = generic_file_sendfile, + .splice_read = generic_file_splice_read, };const struct inode_operations minix_file_inode_operations = {
fs/ntfs/file.c +1 -1
@@ -2276,7 +2276,7 @@ const struct file_operations ntfs_file_ops = {mounted filesystem. */ .mmap = generic_file_mmap, /* Mmap file. */ .open = ntfs_file_open,/* Open file. */ - .sendfile = generic_file_sendfile, /* Zero-copy data send with + .splice_read = generic_file_splice_read /* Zero-copy data send withthe data source being on the ntfs partition. We do not need to care about the
fs/ocfs2/file.c +0 -1
@@ -1822,7 +1822,6 @@ const struct inode_operations ocfs2_special_file_iops = {const struct file_operations ocfs2_fops = { .read = do_sync_read, .write = do_sync_write, - .sendfile = generic_file_sendfile, .mmap = ocfs2_mmap, .fsync = ocfs2_sync_file, .release = ocfs2_file_release,
fs/qnx4/file.c +1 -1
@@ -25,7 +25,7 @@ const struct file_operations qnx4_file_operations = .read = do_sync_read, .aio_read = generic_file_aio_read, .mmap = generic_file_mmap, - .sendfile = generic_file_sendfile, + .splice_read = generic_file_splice_read, #ifdef CONFIG_QNX4FS_RW .write = do_sync_write, .aio_write = generic_file_aio_write,
fs/ramfs/file-mmu.c +1 -1
@@ -41,7 +41,7 @@ const struct file_operations ramfs_file_operations = { .aio_write = generic_file_aio_write, .mmap = generic_file_mmap, .fsync = simple_sync_file, - .sendfile = generic_file_sendfile, + .splice_read = generic_file_splice_read, .llseek = generic_file_llseek, };
fs/ramfs/file-nommu.c +1 -1
@@ -42,7 +42,7 @@ const struct file_operations ramfs_file_operations = { .write = do_sync_write, .aio_write = generic_file_aio_write, .fsync = simple_sync_file, - .sendfile = generic_file_sendfile, + .splice_read = generic_file_splice_read, .llseek = generic_file_llseek, };
fs/reiserfs/file.c +0 -1
@@ -1531,7 +1531,6 @@ const struct file_operations reiserfs_file_operations = { .open = generic_file_open, .release = reiserfs_file_release, .fsync = reiserfs_sync_file, - .sendfile = generic_file_sendfile, .aio_read = generic_file_aio_read, .aio_write = generic_file_aio_write, .splice_read = generic_file_splice_read,
fs/smbfs/file.c +5 -4
@@ -262,8 +262,9 @@ out: }static ssize_t -smb_file_sendfile (struct file *file,loff_t *ppos, -size_t count,read_actor_t actor,void *target) +smb_file_splice_read (struct file *file,loff_t *ppos, +struct pipe_inode_info *pipe,size_t count, +unsigned int flags) {struct dentry *dentry = file->f_path.dentry;ssize_t status;
@@ -277,7 +278,7 @@ smb_file_sendfile(struct file *file, loff_t *ppos, DENTRY_PATH(dentry), status); goto out; } - status =generic_file_sendfile (file, ppos, count, actor, target); + status =generic_file_splice_read (file, ppos, pipe, count, flags); out:return status; }
@@ -416,7 +417,7 @@ const struct file_operations smb_file_operations = .open = smb_file_open, .release = smb_file_release, .fsync = smb_fsync, - .sendfile = smb_file_sendfile, + .splice_read = smb_file_splice_read, }; const struct inode_operations smb_file_inode_operations =
fs/sysv/file.c +1 -1
@@ -27,7 +27,7 @@ const struct file_operations sysv_file_operations = { .aio_write = generic_file_aio_write, .mmap = generic_file_mmap, .fsync = sysv_sync_file, - .sendfile = generic_file_sendfile, + .splice_read = generic_file_splice_read, };const struct inode_operations sysv_file_inode_operations = {
fs/udf/file.c +1 -1
@@ -261,7 +261,7 @@ const struct file_operations udf_file_operations = { .aio_write = udf_file_aio_write, .release = udf_release_file, .fsync = udf_fsync_file, - .sendfile = generic_file_sendfile, + .splice_read = generic_file_splice_read, };const struct inode_operations udf_file_inode_operations = {
fs/ufs/file.c +1 -1
@@ -60,5 +60,5 @@ const struct file_operations ufs_file_operations = { .mmap = generic_file_mmap, .open = generic_file_open, .fsync = ufs_sync_file, - .sendfile = generic_file_sendfile, + .splice_read = generic_file_splice_read, };
fs/xfs/linux-2.6/xfs_file.c +0 -26
@@ -124,30 +124,6 @@ xfs_file_aio_write_invis( } STATIC ssize_t -xfs_file_sendfile ( -struct file *filp, -loff_t *pos, -size_t count, -read_actor_t actor, -void *target) -{ -return bhv_vop_sendfile (vn_from_inode (filp->f_path.dentry->d_inode), - filp, pos,0 , count, actor, target,NULL ); -} - -STATIC ssize_t -xfs_file_sendfile_invis ( -struct file *filp, -loff_t *pos, -size_t count, -read_actor_t actor, -void *target) -{ -return bhv_vop_sendfile (vn_from_inode (filp->f_path.dentry->d_inode), - filp, pos,IO_INVIS , count, actor, target,NULL ); -} - -STATIC ssize_t xfs_file_splice_read( struct file *infilp, loff_t *ppos,
@@ -452,7 +428,6 @@ const struct file_operations xfs_file_operations = { .write = do_sync_write, .aio_read = xfs_file_aio_read, .aio_write = xfs_file_aio_write, - .sendfile = xfs_file_sendfile, .splice_read = xfs_file_splice_read, .splice_write = xfs_file_splice_write, .unlocked_ioctl = xfs_file_ioctl,
@@ -475,7 +450,6 @@ const struct file_operations xfs_invis_file_operations = { .write = do_sync_write, .aio_read = xfs_file_aio_read_invis, .aio_write = xfs_file_aio_write_invis, - .sendfile = xfs_file_sendfile_invis, .splice_read = xfs_file_splice_read_invis, .splice_write = xfs_file_splice_write_invis, .unlocked_ioctl = xfs_file_ioctl_invis,
fs/xfs/linux-2.6/xfs_linux.h +0 -1
@@ -101,7 +101,6 @@* Feature macros (disable/enable) */ #undef HAVE_REFCACHE/* reference cache not needed for NFS in 2.6 */ -#define HAVE_SENDFILE /* sendfile(2) exists in 2.6, but not in 2.4 */ #define HAVE_SPLICE /* a splice(2) exists in 2.6, but not in 2.4 */ #ifdef CONFIG_SMP #define HAVE_PERCPU_SB /* per cpu superblock counters are a 2.6 feature */
fs/xfs/linux-2.6/xfs_lrw.c +0 -44
50 lines not on this page · raw message
fs/xfs/linux-2.6/xfs_lrw.h +0 -3
@@ -90,9 +90,6 @@ extern ssize_t xfs_read(struct bhv_desc *, struct kiocb *,extern ssize_t xfs_write (struct bhv_desc *,struct kiocb *,const struct iovec *,unsigned int ,loff_t *,int ,struct cred *); -extern ssize_t xfs_sendfile (struct bhv_desc *,struct file *, -loff_t *,int ,size_t ,read_actor_t , -void *,struct cred *);extern ssize_t xfs_splice_read (struct bhv_desc *,struct file *,loff_t *,struct pipe_inode_info *,size_t ,int ,int ,struct cred *);
fs/xfs/linux-2.6/xfs_vnode.h +0 -6
@@ -139,9 +139,6 @@ typedef ssize_t (*vop_read_t)(bhv_desc_t *, struct kiocb *,typedef ssize_t (*vop_write_t )(bhv_desc_t *,struct kiocb *,const struct iovec *,unsigned int ,loff_t *,int ,struct cred *); -typedef ssize_t (*vop_sendfile_t )(bhv_desc_t *,struct file *, -loff_t *,int ,size_t ,read_actor_t , -void *,struct cred *);typedef ssize_t (*vop_splice_read_t )(bhv_desc_t *,struct file *,loff_t *,struct pipe_inode_info *,size_t ,int ,int ,struct cred *);
@@ -206,7 +203,6 @@ typedef struct bhv_vnodeops {vop_close_t vop_close;vop_read_t vop_read;vop_write_t vop_write; -vop_sendfile_t vop_sendfile;vop_splice_read_t vop_splice_read;vop_splice_write_t vop_splice_write;vop_ioctl_t vop_ioctl;
@@ -254,8 +250,6 @@ typedef struct bhv_vnodeops { VOP(vop_read, vp)(VNHEAD(vp),file,iov,segs,offset,ioflags,cr)#define bhv_vop_write (vp,file,iov,segs,offset,ioflags,cr) \ VOP(vop_write, vp)(VNHEAD(vp),file,iov,segs,offset,ioflags,cr) -#define bhv_vop_sendfile (vp,f,off,ioflags,cnt,act,targ,cr) \ - VOP(vop_sendfile, vp)(VNHEAD(vp),f,off,ioflags,cnt,act,targ,cr)#define bhv_vop_splice_read (vp,f,o,pipe,cnt,fl,iofl,cr) \ VOP(vop_splice_read, vp)(VNHEAD(vp),f,o,pipe,cnt,fl,iofl,cr)#define bhv_vop_splice_write (vp,f,o,pipe,cnt,fl,iofl,cr) \
fs/xfs/xfs_vnodeops.c +0 -3
@@ -4680,9 +4680,6 @@ bhv_vnodeops_t xfs_vnodeops = { .vop_open = xfs_open, .vop_close = xfs_close, .vop_read = xfs_read, -#ifdef HAVE_SENDFILE - .vop_sendfile = xfs_sendfile, -#endif #ifdef HAVE_SPLICE .vop_splice_read = xfs_splice_read, .vop_splice_write = xfs_splice_write,
Signature · 1 line
1.5.2.1.174.gcd03
PATCH 5/18 sendfile: kill generic_file_sendfile()
In reply to Jens AxboeIt's no longer used.
--- include/linux/fs.h | 1 - mm/filemap.c | 20 -------------------- 2 files changed, 0 insertions(+), 21 deletions(-)
include/linux/fs.h +0 -1
@@ -1735,7 +1735,6 @@ extern ssize_t generic_file_buffered_write(struct kiocb *, const struct iovec *, unsigned long, loff_t, loff_t *, size_t, ssize_t);extern ssize_t do_sync_read (struct file *filp,char __user *buf,size_t len,loff_t *ppos);extern ssize_t do_sync_write (struct file *filp,const char __user *buf,size_t len,loff_t *ppos); -extern ssize_t generic_file_sendfile (struct file *,loff_t *,size_t ,read_actor_t ,void *);extern void do_generic_mapping_read (struct address_space *mapping,struct file_ra_state *,struct file *,loff_t *,read_descriptor_t *,read_actor_t );
mm/filemap.c +0 -20
@@ -1245,26 +1245,6 @@ int file_send_actor(read_descriptor_t * desc, struct page *page, unsigned long oreturn written; } -ssize_t generic_file_sendfile (struct file *in_file,loff_t *ppos, -size_t count,read_actor_t actor,void *target) -{ -read_descriptor_t desc; - -if (!count) -return 0 ; - - desc.written =0 ; - desc.count = count; - desc.arg.data = target; - desc.error =0 ; - -do_generic_file_read (in_file, ppos, &desc, actor); -if (desc.written) -return desc.written; -return desc.error; -} -EXPORT_SYMBOL (generic_file_sendfile); -static ssize_t do_readahead (struct address_space *mapping,struct file *filp,unsigned long index,unsigned long nr)
Signature · 1 line
1.5.2.1.174.gcd03
PATCH 6/18 splice: add void cookie to the actor data
In reply to Jens AxboeWe need that for passing driver private info.
--- include/linux/pipe_fs_i.h | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
include/linux/pipe_fs_i.h +1 -0
@@ -94,6 +94,7 @@ struct splice_desc {union {void __user *userptr;/* memory to write to */ struct file *file;/* file to read/write */ +void *data;/* cookie */ };loff_t pos;/* file position */ };
Signature · 1 line
1.5.2.1.174.gcd03
PATCH 7/18 loop: convert to using splice_direct_to_actor() instead of sendfile()
In reply to Jens AxboeThis gets rid of the dependency on ->sendfile() for receiving data and converts loop to ->splice_read() instead.
Also includes an IV offset fix from Hugh Dickins.
--- drivers/block/loop.c | 64 ++++++++++++++++++++++++++++++++++--------------- 1 files changed, 44 insertions(+), 20 deletions(-)
drivers/block/loop.c +44 -20
@@ -74,6 +74,7 @@#include <linux/highmem.h> #include <linux/gfp.h> #include <linux/kthread.h> +#include <linux/pipe_fs_i.h> #include <asm/uaccess.h>
@@ -401,50 +402,73 @@ struct lo_read_data { };static int -lo_read_actor (read_descriptor_t *desc,struct page *page, -unsigned long offset,unsigned long size) +lo_splice_actor (struct pipe_inode_info *pipe,struct pipe_buffer *buf, +struct splice_desc *sd) { -unsigned long count = desc->count; -struct lo_read_data *p = desc->arg.data; +struct lo_read_data *p = sd->data;struct loop_device *lo = p->lo; +struct page *page = buf->page;sector_t IV ; +size_t size; +int ret; -IV = ((sector_t ) page->index << (PAGE_CACHE_SHIFT -9 ))+(offset >>9 ); + ret = buf->ops->pin (pipe, buf); +if (unlikely (ret)) +return ret; -if (size > count) - size = count; +IV = ((sector_t ) page->index << (PAGE_CACHE_SHIFT -9 )) + + (buf->offset >>9 ); + size = sd->len; +if (size > p->bsize) + size = p->bsize; -if (lo_do_transfer (lo,READ , page, offset, p->page, p->offset, size,IV )) { - size =0 ; +if (lo_do_transfer (lo,READ , page, buf->offset, p->page, p->offset, size,IV )) {printk (KERN_ERR "loop: transfer error block %ld\n" , page->index); - desc->error = -EINVAL ; + size = -EINVAL ; }flush_dcache_page (p->page); - desc->count = count - size; - desc->written += size; - p->offset += size; +if (size >0 ) + p->offset += size; +return size; }static int +lo_direct_splice_actor (struct pipe_inode_info *pipe,struct splice_desc *sd) +{ +return __splice_from_pipe (pipe, sd, lo_splice_actor); +} + +static int do_lo_receive (struct loop_device *lo,struct bio_vec *bvec,int bsize,loff_t pos) {struct lo_read_data cookie; +struct splice_desc sd;struct file *file; -int retval; +long retval; cookie.lo = lo; cookie.page = bvec->bv_page; cookie.offset = bvec->bv_offset; cookie.bsize = bsize; + + sd.len =0 ; + sd.total_len = bvec->bv_len; + sd.flags =0 ; + sd.pos = pos; + sd.data = &cookie; + file = lo->lo_backing_file; - retval = file->f_op->sendfile (file, &pos, bvec->bv_len, - lo_read_actor, &cookie); -return (retval <0 )? retval:0 ; + retval =splice_direct_to_actor (file, &sd, lo_direct_splice_actor); + +if (retval <0 ) +return retval; + +return 0 ; } static int
@@ -679,8 +703,8 @@ static int loop_change_fd(struct loop_device *lo, struct file *lo_file,if (!S_ISREG (inode->i_mode) && !S_ISBLK (inode->i_mode)) goto out_putf; -/* new backing store needs to support loop (eg sendfile) */ -if (!inode->i_fop->sendfile) +/* new backing store needs to support loop (eg splice_read) */ +if (!inode->i_fop->splice_read) goto out_putf;/* size of the new backing store needs to be the same */
@@ -760,7 +784,7 @@ static int loop_set_fd(struct loop_device *lo, struct file *lo_file,* If we can't read - sorry. If we only can't write - well, * it's going to be read-only. */ -if (!file->f_op->sendfile) +if (!file->f_op->splice_read) goto out_putf;if (aops->prepare_write && aops->commit_write) lo_flags |=LO_FLAGS_USE_AOPS ;
Signature · 1 line
1.5.2.1.174.gcd03
PATCH 8/18 sendfile: convert nfs to using splice_read()
In reply to Jens Axboe--- fs/nfs/file.c | 15 +++++++++------ 1 files changed, 9 insertions(+), 6 deletions(-)
fs/nfs/file.c +9 -6
@@ -41,7 +41,9 @@ static int nfs_file_open(struct inode *, struct file *);static int nfs_file_release (struct inode *,struct file *);static loff_t nfs_file_llseek (struct file *file,loff_t offset,int origin);static int nfs_file_mmap (struct file *,struct vm_area_struct *); -static ssize_t nfs_file_sendfile (struct file *,loff_t *,size_t ,read_actor_t ,void *); +static ssize_t nfs_file_splice_read (struct file *filp,loff_t *ppos, +struct pipe_inode_info *pipe, +size_t count,unsigned int flags);static ssize_t nfs_file_read (struct kiocb *,const struct iovec *iov,unsigned long nr_segs,loff_t pos); static ssize_t nfs_file_write(struct kiocb *, const struct iovec *iov,
@@ -65,7 +67,7 @@ const struct file_operations nfs_file_operations = { .fsync = nfs_fsync, .lock = nfs_lock, .flock = nfs_flock, - .sendfile = nfs_file_sendfile, + .splice_read = nfs_file_splice_read, .check_flags = nfs_check_flags, };
@@ -224,20 +226,21 @@ nfs_file_read(struct kiocb *iocb, const struct iovec *iov, }static ssize_t -nfs_file_sendfile (struct file *filp,loff_t *ppos,size_t count, -read_actor_t actor,void *target) +nfs_file_splice_read (struct file *filp,loff_t *ppos, +struct pipe_inode_info *pipe,size_t count, +unsigned int flags) {struct dentry *dentry = filp->f_path.dentry;struct inode *inode = dentry->d_inode;ssize_t res; -dfprintk (VFS ,"nfs: sendfile(%s/%s, %lu@%Lu)\n" , +dfprintk (VFS ,"nfs: splice_read(%s/%s, %lu@%Lu)\n" , dentry->d_parent->d_name.name, dentry->d_name.name, (unsigned long ) count, (unsigned long long ) *ppos); res =nfs_revalidate_mapping (inode, filp->f_mapping);if (!res) - res =generic_file_sendfile (filp, ppos, count, actor, target); + res =generic_file_splice_read (filp, ppos, pipe, count, flags);return res; }
Signature · 1 line
1.5.2.1.174.gcd03
PATCH 9/18 sendfile: convert nfsd to splice_direct_to_actor()
In reply to Jens Axboe--- fs/nfsd/vfs.c | 47 ++++++++++++++++++++++++------------ include/linux/sunrpc/svc.h | 2 +- net/sunrpc/auth_gss/svcauth_gss.c | 2 +- net/sunrpc/svc.c | 2 +- 4 files changed, 34 insertions(+), 19 deletions(-)
fs/nfsd/vfs.c +31 -16
@@ -23,7 +23,7 @@#include <linux/file.h> #include <linux/mount.h> #include <linux/major.h> -#include <linux/ext2_fs.h> +#include <linux/pipe_fs_i.h> #include <linux/proc_fs.h> #include <linux/stat.h> #include <linux/fcntl.h>
@@ -801,26 +801,32 @@ found: }/* -* Grab and keep cached pages assosiated with a file in the svc_rqst -* so that they can be passed to the netowork sendmsg/sendpage routines -* directrly. They will be released after the sending has completed. +* Grab and keep cached pages associated with a file in the svc_rqst +* so that they can be passed to the network sendmsg/sendpage routines +* directly. They will be released after the sending has completed. */ static int -nfsd_read_actor (read_descriptor_t *desc,struct page *page,unsigned long offset ,unsigned long size) +nfsd_splice_actor (struct pipe_inode_info *pipe,struct pipe_buffer *buf, +struct splice_desc *sd) { -unsigned long count = desc->count; -struct svc_rqst *rqstp = desc->arg.data; +struct svc_rqst *rqstp = sd->data;struct page **pp = rqstp->rq_respages + rqstp->rq_resused; +struct page *page = buf->page; +size_t size; +int ret; + + ret = buf->ops->pin (pipe, buf); +if (unlikely (ret)) +return ret; -if (size > count) - size = count; + size = sd->len;if (rqstp->rq_res.page_len ==0 ) {get_page (page);put_page (*pp); *pp = page; rqstp->rq_resused++; - rqstp->rq_res.page_base = offset; + rqstp->rq_res.page_base = buf->offset; rqstp->rq_res.page_len = size; }else if (page != pp[-1 ]) {get_page (page);
@@ -832,11 +838,15 @@ nfsd_read_actor(read_descriptor_t *desc, struct page *page, unsigned long offset }else rqstp->rq_res.page_len += size; - desc->count = count - size; - desc->written += size;return size; } +static int nfsd_direct_splice_actor (struct pipe_inode_info *pipe, +struct splice_desc *sd) +{ +return __splice_from_pipe (pipe, sd, nfsd_splice_actor); +} +static __be32 nfsd_vfs_read (struct svc_rqst *rqstp,struct svc_fh *fhp,struct file *file,loff_t offset,struct kvec *vec,int vlen,unsigned long *count)
@@ -861,10 +871,15 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,if (ra && ra->p_set) file->f_ra = ra->p_ra; -if (file->f_op->sendfile && rqstp->rq_sendfile_ok) { - rqstp->rq_resused =1 ; - host_err = file->f_op->sendfile (file, &offset, *count, - nfsd_read_actor, rqstp); +if (file->f_op->splice_read && rqstp->rq_splice_ok) { +struct splice_desc sd = { + .len =0 , + .total_len = *count, + .pos = offset, + }; + + sd.data = rqstp; + host_err =splice_direct_to_actor (file, &sd, nfsd_direct_splice_actor); }else { oldfs =get_fs ();set_fs (KERNEL_DS );
include/linux/sunrpc/svc.h +1 -1
@@ -253,7 +253,7 @@ struct svc_rqst {* determine what device number * to report (real or virtual) */ -int rq_sendfile_ok;/* turned off in gss privacy +int rq_splice_ok;/* turned off in gss privacy * to prevent encrypting page * cache pages */ wait_queue_head_t rq_wait;/* synchronization */
net/sunrpc/auth_gss/svcauth_gss.c +1 -1
@@ -853,7 +853,7 @@ unwrap_priv_data(struct svc_rqst *rqstp, struct xdr_buf *buf, u32 seq, struct gsu32 priv_len, maj_stat;int pad, saved_len, remaining_len, offset; - rqstp->rq_sendfile_ok =0 ; + rqstp->rq_splice_ok =0 ; priv_len =svc_getnl (&buf->head[0 ]);if (rqstp->rq_deferred) {
net/sunrpc/svc.c +1 -1
@@ -814,7 +814,7 @@ svc_process(struct svc_rqst *rqstp) rqstp->rq_res.tail[0 ].iov_base =NULL ; rqstp->rq_res.tail[0 ].iov_len =0 ;/* Will be turned off only in gss privacy case: */ - rqstp->rq_sendfile_ok =1 ; + rqstp->rq_splice_ok =1 ;/* tcp needs a space for the record length... */ if (rqstp->rq_prot ==IPPROTO_TCP )svc_putnl (resv,0 );
Signature · 1 line
1.5.2.1.174.gcd03
PATCH 10/18 splice: relay support
In reply to Jens AxboeFrom: Tom Zanussi <[email protected]>
--- kernel/relay.c | 241 ++++++++++++++++++++++++++++++++++++++++++++------------ 1 files changed, 191 insertions(+), 50 deletions(-)
kernel/relay.c +191 -50
@@ -21,6 +21,7 @@#include <linux/vmalloc.h> #include <linux/mm.h> #include <linux/cpu.h> +#include <linux/pipe_fs_i.h> /* list of open channels, for cpu hotplug */ static DEFINE_MUTEX (relay_channels_mutex);
@@ -121,6 +122,7 @@ static void *relay_alloc_buf(struct rchan_buf *buf, size_t *size) buf->page_array[i] =alloc_page (GFP_KERNEL );if (unlikely (!buf->page_array[i])) goto depopulate; +set_page_private (buf->page_array[i], (unsigned long )buf); } mem =vmap (buf->page_array, n_pages,VM_MAP ,PAGE_KERNEL );if (!mem)
@@ -963,43 +965,6 @@ static int subbuf_read_actor(size_t read_start,return ret; } -/* -* subbuf_send_actor - send up to one subbuf's worth of data -*/ -static int subbuf_send_actor (size_t read_start, -struct rchan_buf *buf, -size_t avail, -read_descriptor_t *desc, -read_actor_t actor) -{ -unsigned long pidx, poff; -unsigned int subbuf_pages; -int ret =0 ; - - subbuf_pages = buf->chan->alloc_size >>PAGE_SHIFT ; - pidx = (read_start /PAGE_SIZE ) % subbuf_pages; - poff = read_start & ~PAGE_MASK ; -while (avail) { -struct page *p = buf->page_array[pidx]; -unsigned int len; - - len =PAGE_SIZE - poff; -if (len > avail) - len = avail; - - len =actor (desc, p, poff, len); -if (desc->error) -break ; - - avail -= len; - ret += len; - poff =0 ; - pidx = (pidx +1 ) % subbuf_pages; - } - -return ret; -} - typedef int (*subbuf_actor_t) (size_t read_start, struct rchan_buf *buf, size_t avail,
@@ -1060,19 +1025,195 @@ static ssize_t relay_file_read(struct file *filp, NULL, &desc); } -static ssize_t relay_file_sendfile (struct file *filp, -loff_t *ppos, -size_t count, -read_actor_t actor, -void *target) +static void relay_pipe_buf_release (struct pipe_inode_info *pipe, +struct pipe_buffer *buf) { -read_descriptor_t desc; - desc.written =0 ; - desc.count = count; - desc.arg.data = target; - desc.error =0 ; -return relay_file_read_subbufs (filp, ppos, subbuf_send_actor, - actor, &desc); +struct rchan_buf *rbuf; + + rbuf = (struct rchan_buf *)page_private (buf->page); + + rbuf->bytes_consumed +=PAGE_SIZE ; + +if (rbuf->bytes_consumed == rbuf->chan->subbuf_size) { +relay_subbufs_consumed (rbuf->chan, rbuf->cpu,1 ); + rbuf->bytes_consumed =0 ; + } +} + +static struct pipe_buf_operations relay_pipe_buf_ops = { + .can_merge =0 , + .map = generic_pipe_buf_map, + .unmap = generic_pipe_buf_unmap, + .pin = generic_pipe_buf_pin, + .release = relay_pipe_buf_release, + .steal = generic_pipe_buf_steal, + .get = generic_pipe_buf_get, +}; + +/** +* subbuf_splice_actor - splice up to one subbuf's worth of data +*/ +static int subbuf_splice_actor (struct file *in, +loff_t *ppos, +struct pipe_inode_info *pipe, +size_t len, +unsigned int flags, +int *nonpad_ret) +{ +unsigned int pidx, poff; +unsigned int subbuf_pages; +int ret =0 ; +int do_wakeup =0 ; +struct rchan_buf *rbuf = in->private_data; +unsigned int subbuf_size = rbuf->chan->subbuf_size; +size_t read_start = ((size_t )*ppos) % rbuf->chan->alloc_size; +size_t avail = subbuf_size - read_start % subbuf_size; +size_t read_subbuf = read_start / subbuf_size; +size_t padding = rbuf->padding[read_subbuf]; +size_t nonpad_end = read_subbuf * subbuf_size + subbuf_size - padding; + +if (rbuf->subbufs_produced == rbuf->subbufs_consumed) +return 0 ; + +if (len > avail) + len = avail; + +if (pipe->inode) +mutex_lock (&pipe->inode->i_mutex); + + subbuf_pages = rbuf->chan->alloc_size >>PAGE_SHIFT ; + pidx = (read_start /PAGE_SIZE ) % subbuf_pages; + poff = read_start & ~PAGE_MASK ; + +for (;;) { +unsigned int this_len; +unsigned int this_end; +int newbuf = (pipe->curbuf + pipe->nrbufs) & (PIPE_BUFFERS -1 ); +struct pipe_buffer *buf = pipe->bufs + newbuf; + +if (!pipe->readers) { +send_sig (SIGPIPE , current,0 ); +if (!ret) + ret = -EPIPE ; +break ; + } + +if (pipe->nrbufs <PIPE_BUFFERS ) { + this_len =PAGE_SIZE - poff; +if (this_len > avail) + this_len = avail; + + buf->page = rbuf->page_array[pidx]; + buf->offset = poff; + this_end = read_start + ret + this_len; +if (this_end > nonpad_end) { +if (read_start + ret >= nonpad_end) + buf->len =0 ; +else + buf->len = nonpad_end - (read_start + ret); + }else + buf->len = this_len; + + *nonpad_ret += buf->len; + + buf->ops = &relay_pipe_buf_ops; + pipe->nrbufs++; + + avail -= this_len; + ret += this_len; + poff =0 ; + pidx = (pidx +1 ) % subbuf_pages; + +if (pipe->inode) + do_wakeup =1 ; + +if (!avail) +break ; + +if (pipe->nrbufs <PIPE_BUFFERS ) +continue ; + +break ; + } + +if (flags &SPLICE_F_NONBLOCK ) { +if (!ret) + ret = -EAGAIN ; +break ; + } + +if (signal_pending (current)) { +if (!ret) + ret = -ERESTARTSYS ; +break ; + } + +if (do_wakeup) { +smp_mb (); +if (waitqueue_active (&pipe->wait)) +wake_up_interruptible_sync (&pipe->wait); +kill_fasync (&pipe->fasync_readers,SIGIO ,POLL_IN ); + do_wakeup =0 ; + } + + pipe->waiting_writers++; +pipe_wait (pipe); + pipe->waiting_writers--; + } + +if (pipe->inode) +mutex_unlock (&pipe->inode->i_mutex); + +if (do_wakeup) { +smp_mb (); +if (waitqueue_active (&pipe->wait)) +wake_up_interruptible (&pipe->wait); +kill_fasync (&pipe->fasync_readers,SIGIO ,POLL_IN ); + } + +return ret; +} + +static ssize_t relay_file_splice_read (struct file *in, +loff_t *ppos, +struct pipe_inode_info *pipe, +size_t len, +unsigned int flags) +{ +ssize_t spliced; +int ret; +int nonpad_ret =0 ; + + ret =0 ; + spliced =0 ; + +while (len) { + ret =subbuf_splice_actor (in, ppos, pipe, len, flags, &nonpad_ret); +if (ret <0 ) +break ; +else if (!ret) { +break ; +if (spliced) +break ; +if (flags &SPLICE_F_NONBLOCK ) { + ret = -EAGAIN ; +break ; + } + } + + *ppos += ret; +if (ret > len) + len =0 ; +else + len -= ret; + spliced += nonpad_ret; + nonpad_ret =0 ; + } + +if (spliced) +return spliced; + +return ret; }const struct file_operations relay_file_operations = {
@@ -1082,7 +1223,7 @@ const struct file_operations relay_file_operations = { .read = relay_file_read, .llseek = no_llseek, .release = relay_file_release, - .sendfile = relay_file_sendfile, + .splice_read = relay_file_splice_read, };EXPORT_SYMBOL_GPL (relay_file_operations);
Signature · 1 line
1.5.2.1.174.gcd03
PATCH 11/18 splice: divorce the splice structure/function definitions from the pipe header
In reply to Jens AxboeWe need to move even more stuff into the header so that folks can use the splice_to_pipe() implementation instead of open-coding a lot of pipe knowledge (see relay implementation), so move to our own header file finally.
--- drivers/block/loop.c | 2 +- drivers/char/mem.c | 2 +- fs/nfsd/vfs.c | 2 +- fs/ocfs2/file.c | 2 +- fs/read_write.c | 2 +- fs/splice.c | 26 +++------------- include/linux/pipe_fs_i.h | 41 ------------------------- include/linux/splice.h | 72 +++++++++++++++++++++++++++++++++++++++++++++ kernel/relay.c | 2 +- 9 files changed, 83 insertions(+), 68 deletions(-) create mode 100644 include/linux/splice.h
drivers/block/loop.c +1 -1
@@ -74,7 +74,7 @@#include <linux/highmem.h> #include <linux/gfp.h> #include <linux/kthread.h> -#include <linux/pipe_fs_i.h> +#include <linux/splice.h> #include <asm/uaccess.h>
drivers/char/mem.c +1 -1
@@ -24,7 +24,7 @@#include <linux/crash_dump.h> #include <linux/backing-dev.h> #include <linux/bootmem.h> -#include <linux/pipe_fs_i.h> +#include <linux/splice.h> #include <linux/pfn.h> #include <asm/uaccess.h>
fs/nfsd/vfs.c +1 -1
@@ -23,7 +23,7 @@#include <linux/file.h> #include <linux/mount.h> #include <linux/major.h> -#include <linux/pipe_fs_i.h> +#include <linux/splice.h> #include <linux/proc_fs.h> #include <linux/stat.h> #include <linux/fcntl.h>
fs/ocfs2/file.c +1 -1
@@ -31,7 +31,7 @@#include <linux/pagemap.h> #include <linux/uio.h> #include <linux/sched.h> -#include <linux/pipe_fs_i.h> +#include <linux/splice.h> #include <linux/mount.h> #include <linux/writeback.h>
fs/read_write.c +1 -1
@@ -15,7 +15,7 @@#include <linux/module.h> #include <linux/syscalls.h> #include <linux/pagemap.h> -#include <linux/pipe_fs_i.h> +#include <linux/splice.h> #include "read_write.h" #include <asm/uaccess.h>
fs/splice.c +5 -21
@@ -20,7 +20,7 @@#include <linux/fs.h> #include <linux/file.h> #include <linux/pagemap.h> -#include <linux/pipe_fs_i.h> +#include <linux/splice.h> #include <linux/mm_inline.h> #include <linux/swap.h> #include <linux/writeback.h>
@@ -29,22 +29,6 @@#include <linux/syscalls.h> #include <linux/uio.h> -struct partial_page { -unsigned int offset; -unsigned int len; -}; - -/* -* Passed to splice_to_pipe -*/ -struct splice_pipe_desc { -struct page **pages;/* page map */ -struct partial_page *partial;/* pages[] may not be contig */ -int nr_pages;/* number of pages in map */ -unsigned int flags;/* splice flags */ -const struct pipe_buf_operations *ops;/* ops associated with output pipe */ -}; -/* * Attempt to steal a page from a pipe buffer. This should perhaps go into * a vm helper function, it's already simplified quite a bit by the
@@ -170,11 +154,11 @@ static const struct pipe_buf_operations user_page_pipe_buf_ops = { };/* -* Pipe output worker. This sets up our pipe format with the page cache -* pipe buffer operations. Otherwise very similar to the regular pipe_writev(). +* Pipe output worker. This fills a pipe with the information contained +* from splice_pipe_desc(). */ -static ssize_t splice_to_pipe (struct pipe_inode_info *pipe, -struct splice_pipe_desc *spd) +ssize_t splice_to_pipe (struct pipe_inode_info *pipe, +struct splice_pipe_desc *spd) {int ret, do_wakeup, page_nr;
include/linux/pipe_fs_i.h +0 -41
45 lines not on this page · raw message
include/linux/splice.h new file +72 -0
72 lines not on this page · raw message
kernel/relay.c +1 -1
@@ -21,7 +21,7 @@#include <linux/vmalloc.h> #include <linux/mm.h> #include <linux/cpu.h> -#include <linux/pipe_fs_i.h> +#include <linux/splice.h> /* list of open channels, for cpu hotplug */ static DEFINE_MUTEX (relay_channels_mutex);
Signature · 1 line
1.5.2.1.174.gcd03
PATCH 12/18 pipe: allow passing around of ops private pointer
In reply to Jens Axboerelay needs this for proper consumption handling, and the network receive support needs it as well to lookup the sk_buff on pipe release.
--- fs/splice.c | 1 + include/linux/pipe_fs_i.h | 1 + include/linux/splice.h | 1 + 3 files changed, 3 insertions(+), 0 deletions(-)
fs/splice.c +1 -0
@@ -184,6 +184,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe, buf->page = spd->pages[page_nr]; buf->offset = spd->partial[page_nr].offset; buf->len = spd->partial[page_nr].len; + buf->private = spd->partial[page_nr].private; buf->ops = spd->ops;if (spd->flags &SPLICE_F_GIFT ) buf->flags |=PIPE_BUF_FLAG_GIFT ;
include/linux/pipe_fs_i.h +1 -0
@@ -14,6 +14,7 @@ struct pipe_buffer {unsigned int offset, len;const struct pipe_buf_operations *ops;unsigned int flags; +unsigned long private; };struct pipe_inode_info {
include/linux/splice.h +1 -0
@@ -41,6 +41,7 @@ struct splice_desc {struct partial_page {unsigned int offset;unsigned int len; +unsigned long private; };/*
Signature · 1 line
1.5.2.1.174.gcd03
PATCH 13/18 relay: use splice_to_pipe() instead of open-coding the pipe loop
In reply to Jens AxboeIt cleans up the relay splice implementation a lot, and gets rid of a lot of internal pipe knowledge that should not be in there.
Plus fixes for padding and partial first page (and lots more) from Tom Zanussi.
--- kernel/relay.c | 146 +++++++++++++++++++++----------------------------------- 1 files changed, 55 insertions(+), 91 deletions(-)
kernel/relay.c +55 -91
@@ -1025,19 +1025,23 @@ static ssize_t relay_file_read(struct file *filp, NULL, &desc); } +static void relay_consume_bytes (struct rchan_buf *rbuf,int bytes_consumed) +{ + rbuf->bytes_consumed += bytes_consumed; + +if (rbuf->bytes_consumed >= rbuf->chan->subbuf_size) { +relay_subbufs_consumed (rbuf->chan, rbuf->cpu,1 ); + rbuf->bytes_consumed %= rbuf->chan->subbuf_size; + } +} +static void relay_pipe_buf_release (struct pipe_inode_info *pipe,struct pipe_buffer *buf) {struct rchan_buf *rbuf; rbuf = (struct rchan_buf *)page_private (buf->page); - - rbuf->bytes_consumed +=PAGE_SIZE ; - -if (rbuf->bytes_consumed == rbuf->chan->subbuf_size) { -relay_subbufs_consumed (rbuf->chan, rbuf->cpu,1 ); - rbuf->bytes_consumed =0 ; - } +relay_consume_bytes (rbuf, buf->private); }static struct pipe_buf_operations relay_pipe_buf_ops = {
@@ -1060,118 +1064,79 @@ static int subbuf_splice_actor(struct file *in,unsigned int flags, int *nonpad_ret) { - unsigned int pidx, poff; -unsigned int subbuf_pages; -int ret =0 ; -int do_wakeup =0 ; + unsigned int pidx, poff, total_len, subbuf_pages, ret;struct rchan_buf *rbuf = in->private_data;unsigned int subbuf_size = rbuf->chan->subbuf_size;size_t read_start = ((size_t )*ppos) % rbuf->chan->alloc_size; -size_t avail = subbuf_size - read_start % subbuf_size;size_t read_subbuf = read_start / subbuf_size;size_t padding = rbuf->padding[read_subbuf];size_t nonpad_end = read_subbuf * subbuf_size + subbuf_size - padding; +struct page *pages[PIPE_BUFFERS ]; +struct partial_page partial[PIPE_BUFFERS ]; +struct splice_pipe_desc spd = { + .pages = pages, + .nr_pages =0 , + .partial = partial, + .flags = flags, + .ops = &relay_pipe_buf_ops, + };if (rbuf->subbufs_produced == rbuf->subbufs_consumed)return 0 ; -if (len > avail) - len = avail; - -if (pipe->inode) -mutex_lock (&pipe->inode->i_mutex); +/* +* Adjust read len, if longer than what is available +*/ +if (len > (subbuf_size - read_start % subbuf_size)) + len = subbuf_size - read_start % subbuf_size; subbuf_pages = rbuf->chan->alloc_size >>PAGE_SHIFT ; pidx = (read_start /PAGE_SIZE ) % subbuf_pages; poff = read_start & ~PAGE_MASK ; -for (;;) { -unsigned int this_len; -unsigned int this_end; -int newbuf = (pipe->curbuf + pipe->nrbufs) & (PIPE_BUFFERS -1 ); -struct pipe_buffer *buf = pipe->bufs + newbuf; +for (total_len =0 ; spd.nr_pages < subbuf_pages; spd.nr_pages++) { +unsigned int this_len, this_end, private; +unsigned int cur_pos = read_start + total_len; -if (!pipe->readers) { -send_sig (SIGPIPE , current,0 ); -if (!ret) - ret = -EPIPE ; +if (!len)break ; - } - -if (pipe->nrbufs <PIPE_BUFFERS ) { - this_len =PAGE_SIZE - poff; -if (this_len > avail) - this_len = avail; - - buf->page = rbuf->page_array[pidx]; - buf->offset = poff; - this_end = read_start + ret + this_len; -if (this_end > nonpad_end) { -if (read_start + ret >= nonpad_end) - buf->len =0 ; -else - buf->len = nonpad_end - (read_start + ret); - }else - buf->len = this_len; - - *nonpad_ret += buf->len; - - buf->ops = &relay_pipe_buf_ops; - pipe->nrbufs++; - avail -= this_len; - ret += this_len; - poff =0 ; - pidx = (pidx +1 ) % subbuf_pages; + this_len = min_t(unsigned long, len, PAGE_SIZE - poff); + private = this_len; -if (pipe->inode) - do_wakeup =1 ; + spd.pages[spd.nr_pages] = rbuf->page_array[pidx]; + spd.partial[spd.nr_pages].offset = poff; -if (!avail) -break ; - -if (pipe->nrbufs <PIPE_BUFFERS ) -continue ; - -break ; + this_end = cur_pos + this_len; +if (this_end >= nonpad_end) { + this_len = nonpad_end - cur_pos; + private = this_len + padding; } + spd.partial[spd.nr_pages].len = this_len; + spd.partial[spd.nr_pages].private = private; -if (flags &SPLICE_F_NONBLOCK ) { -if (!ret) - ret = -EAGAIN ; -break ; - } + len -= this_len; + total_len += this_len; + poff =0 ; + pidx = (pidx +1 ) % subbuf_pages; -if (signal_pending (current)) { -if (!ret) - ret = -ERESTARTSYS ; +if (this_end >= nonpad_end) { + spd.nr_pages++;break ; } - -if (do_wakeup) { -smp_mb (); -if (waitqueue_active (&pipe->wait)) -wake_up_interruptible_sync (&pipe->wait); -kill_fasync (&pipe->fasync_readers,SIGIO ,POLL_IN ); - do_wakeup =0 ; - } - - pipe->waiting_writers++; -pipe_wait (pipe); - pipe->waiting_writers--; } -if (pipe->inode) -mutex_unlock (&pipe->inode->i_mutex); +if (!spd.nr_pages) +return 0 ; -if (do_wakeup) { -smp_mb (); -if (waitqueue_active (&pipe->wait)) -wake_up_interruptible (&pipe->wait); -kill_fasync (&pipe->fasync_readers,SIGIO ,POLL_IN ); - } + ret = *nonpad_ret =splice_to_pipe (pipe, &spd); +if (ret <0 || ret < total_len) +return ret; -return ret; +if (read_start + ret == nonpad_end) + ret += padding; + +return ret; } static ssize_t relay_file_splice_read(struct file *in,
@@ -1192,7 +1157,6 @@ static ssize_t relay_file_splice_read(struct file *in,if (ret <0 )break ;else if (!ret) { -break ;if (spliced)break ;if (flags &SPLICE_F_NONBLOCK ) {
Signature · 1 line
1.5.2.1.174.gcd03
PATCH 14/18 shmem: convert to using splice instead of sendfile()
In reply to Jens AxboeFrom: Hugh Dickins <[email protected]>
Remove shmem_file_sendfile and resurrect shmem_readpage, as used by tmpfs to support loop and sendfile in 2.4 and 2.5. Now tmpfs can support splice, loop and sendfile in the simplest way, using generic_file_splice_read and generic_file_splice_write (with the aid of shmem_prepare_write).
We could make some efficiency tweaks later, if there's a real need; but this is stable and works well as is.
--- mm/shmem.c | 42 +++++++++++++++++------------------------- 1 files changed, 17 insertions(+), 25 deletions(-)
mm/shmem.c +17 -25
@@ -1100,9 +1100,9 @@ static int shmem_getpage(struct inode *inode, unsigned long idx,* Normally, filepage is NULL on entry, and either found * uptodate immediately, or allocated and zeroed, or read * in under swappage, which is then assigned to filepage. -* But shmem_prepare_write passes in a locked filepage, -* which may be found not uptodate by other callers too, -* and may need to be copied from the swappage read in. +* But shmem_readpage and shmem_prepare_write pass in a locked +* filepage, which may be found not uptodate by other callers +* too, and may need to be copied from the swappage read in. */ repeat:if (!filepage)
@@ -1485,9 +1485,18 @@ static const struct inode_operations shmem_symlink_inode_operations;static const struct inode_operations shmem_symlink_inline_operations;/* -* Normally tmpfs makes no use of shmem_prepare_write, but it -* lets a tmpfs file be used read-write below the loop driver. +* Normally tmpfs avoids the use of shmem_readpage and shmem_prepare_write; +* but providing them allows a tmpfs file to be used for splice, sendfile, and +* below the loop driver, in the generic fashion that many filesystems support. */ +static int shmem_readpage (struct file *file,struct page *page) +{ +struct inode *inode = page->mapping->host; +int error =shmem_getpage (inode, page->index, &page,SGP_CACHE ,NULL ); +unlock_page (page); +return error; +} +static int shmem_prepare_write (struct file *file,struct page *page,unsigned offset,unsigned to) {
@@ -1711,25 +1720,6 @@ static ssize_t shmem_file_read(struct file *filp, char __user *buf, size_t countreturn desc.error; } -static ssize_t shmem_file_sendfile (struct file *in_file,loff_t *ppos, -size_t count,read_actor_t actor,void *target) -{ -read_descriptor_t desc; - -if (!count) -return 0 ; - - desc.written =0 ; - desc.count = count; - desc.arg.data = target; - desc.error =0 ; - -do_shmem_file_read (in_file, ppos, &desc, actor); -if (desc.written) -return desc.written; -return desc.error; -} -static int shmem_statfs (struct dentry *dentry,struct kstatfs *buf) {struct shmem_sb_info *sbinfo =SHMEM_SB (dentry->d_sb);
@@ -2386,6 +2376,7 @@ static const struct address_space_operations shmem_aops = { .writepage = shmem_writepage, .set_page_dirty = __set_page_dirty_no_writeback, #ifdef CONFIG_TMPFS + .readpage = shmem_readpage, .prepare_write = shmem_prepare_write, .commit_write = simple_commit_write, #endif
@@ -2399,7 +2390,8 @@ static const struct file_operations shmem_file_operations = { .read = shmem_file_read, .write = shmem_file_write, .fsync = simple_sync_file, - .sendfile = shmem_file_sendfile, + .splice_read = generic_file_splice_read, + .splice_write = generic_file_splice_write,#endif };
Signature · 1 line
1.5.2.1.174.gcd03
PATCH 15/18 sendfile: remove bad_sendfile() from bad_file_ops
In reply to Jens Axboedo_sendfile() prefers splice over sendfile, so it should not trigger (directly, at least).
--- fs/bad_inode.c | 7 ------- 1 files changed, 0 insertions(+), 7 deletions(-)
fs/bad_inode.c +0 -7
@@ -114,12 +114,6 @@ static int bad_file_lock(struct file *file, int cmd, struct file_lock *fl)return -EIO ; } -static ssize_t bad_file_sendfile (struct file *in_file,loff_t *ppos, -size_t count,read_actor_t actor,void *target) -{ -return -EIO ; -} -static ssize_t bad_file_sendpage (struct file *file,struct page *page,int off,size_t len,loff_t *pos,int more) {
@@ -182,7 +176,6 @@ static const struct file_operations bad_file_ops = .aio_fsync = bad_file_aio_fsync, .fasync = bad_file_fasync, .lock = bad_file_lock, - .sendfile = bad_file_sendfile, .sendpage = bad_file_sendpage, .get_unmapped_area = bad_file_get_unmapped_area, .check_flags = bad_file_check_flags,
Signature · 1 line
1.5.2.1.174.gcd03
PATCH 16/18 splice: completely document external interface with kerneldoc
In reply to Jens AxboeAlso add fs/splice.c as a kerneldoc target with a smaller blurb that should be expanded to better explain the overview of splice.
--- Documentation/DocBook/kernel-api.tmpl | 11 ++++ fs/splice.c | 101 +++++++++++++++++++++++++++------ 2 files changed, 94 insertions(+), 18 deletions(-)
Documentation/DocBook/kernel-api.tmpl +11 -0
@@ -643,4 +643,15 @@ X!Idrivers/video/console/fonts.c !Edrivers/spi/spi.c </chapter> + <chapter id="splice"> + <title>splice API</title> + <para>) + splice is a method for moving blocks of data around inside the + kernel, without continually transferring it between the kernel + and user space. + </para> +!Iinclude/linux/splice.h +!Ffs/splice.c + </chapter> + </book>
fs/splice.c +83 -18
169 lines not on this page · raw message
Signature · 1 line
1.5.2.1.174.gcd03
PATCH 17/18 ext2 xip: replace sendfile with splice
In reply to Jens AxboeFrom: Carsten Otte <[email protected]>
This patch removes xip_file_sendfile, and replaces it with xip_file_splice_read. It passes the ltp testcase on a ext2 filesystem that is mounted -o xip,rw.
I am not exactly happy with this patch, because it introduces waaaay too much code duplication from fs/splice.c. I want to dig into making generic_file_splice_read able to deal with xip files aswell. That would allow to do the same for splice write.
If I cannot find a nicer solution, I'd vote for removing sendfile from filemap_xip without replacement: a xip filesystem is intended to be used for executables and libraries. This content is very rarely subject to splice.
--- fs/ext2/file.c | 2 +- include/linux/fs.h | 4 +- mm/filemap_xip.c | 206 ++++++++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 192 insertions(+), 20 deletions(-)
fs/ext2/file.c +1 -1
@@ -70,7 +70,7 @@ const struct file_operations ext2_xip_file_operations = { .open = generic_file_open, .release = ext2_release_file, .fsync = ext2_sync_file, - .sendfile = xip_file_sendfile, + .splice_read = xip_file_splice_read, };#endif
include/linux/fs.h +1 -3
@@ -1764,13 +1764,11 @@ extern int nonseekable_open(struct inode * inode, struct file * filp);#ifdef CONFIG_FS_XIP extern ssize_t xip_file_read (struct file *filp,char __user *buf,size_t len,loff_t *ppos); -extern ssize_t xip_file_sendfile (struct file *in_file,loff_t *ppos, -size_t count,read_actor_t actor, -void *target);extern int xip_file_mmap (struct file * file,struct vm_area_struct * vma);extern ssize_t xip_file_write (struct file *filp,const char __user *buf,size_t len,loff_t *ppos);extern int xip_truncate_page (struct address_space *mapping,loff_t from); +extern ssize_t xip_file_splice_read (struct file *,loff_t *,struct pipe_inode_info *,size_t ,unsigned int );#else static inline int xip_truncate_page (struct address_space *mapping,loff_t from) {
mm/filemap_xip.c +190 -16
230 lines not on this page · raw message
Signature · 1 line
1.5.2.1.174.gcd03
PATCH 18/18 Remove remnants of sendfile()
In reply to Jens AxboeThere are now zero users of .sendfile() in the kernel, so kill it from the file_operations structure and in do_sendfile().
--- fs/read_write.c | 26 +++++++++++--------------- include/linux/fs.h | 3 +-- 2 files changed, 12 insertions(+), 17 deletions(-)
fs/read_write.c +11 -15
@@ -724,8 +724,7 @@ static ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos, in_inode = in_file->f_path.dentry->d_inode;if (!in_inode) goto fput_in; -if (!in_file->f_op || (!in_file->f_op->sendfile && - !in_file->f_op->splice_read)) +if (!in_file->f_op || !in_file->f_op->splice_read) goto fput_in; retval = -ESPIPE ;if (!ppos)
@@ -778,21 +777,18 @@ static ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos, count = max - pos; } -if (in_file->f_op->splice_read) { - fl =0 ; + fl =0 ;#if 0 -/* -* We need to debate whether we can enable this or not. The -* man page documents EAGAIN return for the output at least, -* and the application is arguably buggy if it doesn't expect -* EAGAIN on a non-blocking file descriptor. -*/ -if (in_file->f_flags &O_NONBLOCK ) - fl =SPLICE_F_NONBLOCK ; +/* +* We need to debate whether we can enable this or not. The +* man page documents EAGAIN return for the output at least, +* and the application is arguably buggy if it doesn't expect +* EAGAIN on a non-blocking file descriptor. +*/ +if (in_file->f_flags &O_NONBLOCK ) + fl =SPLICE_F_NONBLOCK ;#endif - retval =do_splice_direct (in_file, ppos, out_file, count, fl); - }else - retval = in_file->f_op->sendfile (in_file, ppos, count, file_send_actor, out_file); + retval =do_splice_direct (in_file, ppos, out_file, count, fl);if (retval >0 ) {add_rchar (current, retval);
include/linux/fs.h +1 -2
@@ -1054,7 +1054,7 @@ struct block_device_operations { };/* -* "descriptor" for what we're up to with a read for sendfile(). +* "descriptor" for what we're up to with a read. * This allows us to use the same read code yet * have multiple different users of the data that * we read from a file.
@@ -1105,7 +1105,6 @@ struct file_operations {int (*aio_fsync) (struct kiocb *,int datasync);int (*fasync) (int ,struct file *,int );int (*lock) (struct file *,int ,struct file_lock *); -ssize_t (*sendfile) (struct file *,loff_t *,size_t ,read_actor_t ,void *);ssize_t (*sendpage) (struct file *,struct page *,int ,size_t ,loff_t *,int );unsigned long (*get_unmapped_area)(struct file *,unsigned long ,unsigned long ,unsigned long ,unsigned long );int (*check_flags)(int );
Signature · 1 line
1.5.2.1.174.gcd03