Skip to content

Commit 5274f05

Browse files
Jens AxboeLinus Torvalds
authored andcommitted
[PATCH] Introduce sys_splice() system call
This adds support for the sys_splice system call. Using a pipe as a transport, it can connect to files or sockets (latter as output only). From the splice.c comments: "splice": joining two ropes together by interweaving their strands. This is the "extended pipe" functionality, where a pipe is used as an arbitrary in-memory buffer. Think of a pipe as a small kernel buffer that you can use to transfer data from one end to the other. The traditional unix read/write is extended with a "splice()" operation that transfers data buffers to or from a pipe buffer. Named by Larry McVoy, original implementation from Linus, extended by Jens to support splicing to files and fixing the initial implementation bugs. Signed-off-by: Jens Axboe <axboe@suse.de> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent 5d4fe2c commit 5274f05

15 files changed

Lines changed: 669 additions & 11 deletions

File tree

‎arch/i386/kernel/syscall_table.S‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,3 +312,4 @@ ENTRY(sys_call_table)
312312
.long sys_unshare /* 310 */
313313
.long sys_set_robust_list
314314
.long sys_get_robust_list
315+
.long sys_splice

‎arch/ia64/kernel/entry.S‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,5 +1605,6 @@ sys_call_table:
16051605
data8 sys_ni_syscall // reserved for pselect
16061606
data8 sys_ni_syscall // 1295 reserved for ppoll
16071607
data8 sys_unshare
1608+
data8 sys_splice
16081609

16091610
.org sys_call_table + 8*NR_syscalls // guard against failures to increase NR_syscalls

‎fs/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ obj-y := open.o read_write.o file_table.o buffer.o bio.o super.o \
1010
ioctl.o readdir.o select.o fifo.o locks.o dcache.o inode.o \
1111
attr.o bad_inode.o file.o filesystems.o namespace.o aio.o \
1212
seq_file.o xattr.o libfs.o fs-writeback.o mpage.o direct-io.o \
13-
ioprio.o pnode.o drop_caches.o
13+
ioprio.o pnode.o drop_caches.o splice.o
1414

1515
obj-$(CONFIG_INOTIFY) += inotify.o
1616
obj-$(CONFIG_EPOLL) += eventpoll.o

‎fs/ext2/file.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ const struct file_operations ext2_file_operations = {
5353
.readv = generic_file_readv,
5454
.writev = generic_file_writev,
5555
.sendfile = generic_file_sendfile,
56+
.splice_read = generic_file_splice_read,
57+
.splice_write = generic_file_splice_write,
5658
};
5759

5860
#ifdef CONFIG_EXT2_FS_XIP

‎fs/ext3/file.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ const struct file_operations ext3_file_operations = {
119119
.release = ext3_release_file,
120120
.fsync = ext3_sync_file,
121121
.sendfile = generic_file_sendfile,
122+
.splice_read = generic_file_splice_read,
123+
.splice_write = generic_file_splice_write,
122124
};
123125

124126
struct inode_operations ext3_file_inode_operations = {

‎fs/pipe.c‎

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <linux/pipe_fs_i.h>
1616
#include <linux/uio.h>
1717
#include <linux/highmem.h>
18+
#include <linux/pagemap.h>
1819

1920
#include <asm/uaccess.h>
2021
#include <asm/ioctls.h>
@@ -94,11 +95,20 @@ static void anon_pipe_buf_release(struct pipe_inode_info *info, struct pipe_buff
9495
{
9596
struct page *page = buf->page;
9697

97-
if (info->tmp_page) {
98-
__free_page(page);
98+
/*
99+
* If nobody else uses this page, and we don't already have a
100+
* temporary page, let's keep track of it as a one-deep
101+
* allocation cache
102+
*/
103+
if (page_count(page) == 1 && !info->tmp_page) {
104+
info->tmp_page = page;
99105
return;
100106
}
101-
info->tmp_page = page;
107+
108+
/*
109+
* Otherwise just release our reference to it
110+
*/
111+
page_cache_release(page);
102112
}
103113

104114
static void *anon_pipe_buf_map(struct file *file, struct pipe_inode_info *info, struct pipe_buffer *buf)
@@ -152,6 +162,11 @@ pipe_readv(struct file *filp, const struct iovec *_iov,
152162
chars = total_len;
153163

154164
addr = ops->map(filp, info, buf);
165+
if (IS_ERR(addr)) {
166+
if (!ret)
167+
ret = PTR_ERR(addr);
168+
break;
169+
}
155170
error = pipe_iov_copy_to_user(iov, addr + buf->offset, chars);
156171
ops->unmap(info, buf);
157172
if (unlikely(error)) {
@@ -254,8 +269,16 @@ pipe_writev(struct file *filp, const struct iovec *_iov,
254269
struct pipe_buf_operations *ops = buf->ops;
255270
int offset = buf->offset + buf->len;
256271
if (ops->can_merge && offset + chars <= PAGE_SIZE) {
257-
void *addr = ops->map(filp, info, buf);
258-
int error = pipe_iov_copy_from_user(offset + addr, iov, chars);
272+
void *addr;
273+
int error;
274+
275+
addr = ops->map(filp, info, buf);
276+
if (IS_ERR(addr)) {
277+
error = PTR_ERR(addr);
278+
goto out;
279+
}
280+
error = pipe_iov_copy_from_user(offset + addr, iov,
281+
chars);
259282
ops->unmap(info, buf);
260283
ret = error;
261284
do_wakeup = 1;

‎fs/reiserfs/file.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,6 +1576,8 @@ const struct file_operations reiserfs_file_operations = {
15761576
.sendfile = generic_file_sendfile,
15771577
.aio_read = generic_file_aio_read,
15781578
.aio_write = reiserfs_aio_write,
1579+
.splice_read = generic_file_splice_read,
1580+
.splice_write = generic_file_splice_write,
15791581
};
15801582

15811583
struct inode_operations reiserfs_file_inode_operations = {

0 commit comments

Comments
 (0)