28 #include <linux/export.h>
30 #include <linux/uio.h>
33 #include <linux/socket.h>
49 mapping = page_mapping(page);
61 wait_on_page_writeback(page);
63 if (page_has_private(page) &&
100 struct page *page = buf->
page;
103 if (!PageUptodate(page)) {
118 if (!PageUptodate(page)) {
139 .confirm = page_cache_pipe_buf_confirm,
140 .release = page_cache_pipe_buf_release,
141 .steal = page_cache_pipe_buf_steal,
160 .release = page_cache_pipe_buf_release,
161 .steal = user_page_pipe_buf_steal,
168 if (waitqueue_active(&pipe->
wait))
187 unsigned int spd_pages = spd->
nr_pages;
188 int ret, do_wakeup, page_nr;
245 if (waitqueue_active(&pipe->
wait))
259 wakeup_pipe_readers(pipe);
261 while (page_nr < spd_pages)
305 __generic_file_splice_read(
struct file *
in, loff_t *ppos,
310 unsigned int loff, nr_pages, req_pages;
359 page = page_cache_alloc_cold(mapping);
389 for (page_nr = 0; page_nr <
nr_pages; page_nr++) {
390 unsigned int this_len;
399 page = spd.
pages[page_nr];
401 if (PageReadahead(page))
403 page, index, req_pages - page_nr);
408 if (!PageUptodate(page)) {
420 mapping_gfp_mask(mapping));
432 if (PageUptodate(page)) {
440 error = mapping->
a_ops->readpage(in, page);
458 isize = i_size_read(mapping->
host);
459 end_index = (isize - 1) >> PAGE_CACHE_SHIFT;
460 if (
unlikely(!isize || index > end_index))
467 if (end_index == index) {
480 this_len =
min(this_len, plen - loff);
484 spd.
partial[page_nr].offset = loff;
485 spd.
partial[page_nr].len = this_len;
496 while (page_nr < nr_pages)
498 in->
f_ra.prev_pos = (loff_t)index << PAGE_CACHE_SHIFT;
528 isize = i_size_read(in->
f_mapping->host);
532 left = isize - *ppos;
536 ret = __generic_file_splice_read(in, ppos, pipe, len, flags);
557 unsigned long vlen, loff_t
offset)
566 res =
vfs_readv(file, (
const struct iovec __user *)vec, vlen, &pos);
572 static ssize_t kernel_write(
struct file *file,
const char *buf,
size_t count,
581 res =
vfs_write(file, (
const char __user *)buf, count, &pos);
591 unsigned int nr_pages;
592 unsigned int nr_freed;
606 .ops = &default_pipe_buf_ops,
624 for (i = 0; i < nr_pages && i < spd.
nr_pages_max && len; i++) {
641 res = kernel_readv(in, vec, spd.
nr_pages, *ppos);
652 for (i = 0; i < spd.
nr_pages; i++) {
653 this_len =
min_t(
size_t, vec[i].iov_len, res);
691 struct file *file = sd->
u.
file;
692 loff_t pos = sd->
pos;
702 sd->
len, &pos, more);
728 struct file *file = sd->
u.
file;
730 unsigned int offset, this_len;
746 if (buf->
page != page) {
747 char *
src = buf->
ops->map(pipe, buf, 1);
753 buf->
ops->unmap(pipe, buf, src);
765 if (waitqueue_active(&pipe->
wait))
803 ret = buf->
ops->confirm(pipe, buf);
810 ret = actor(pipe, buf, sd);
865 wakeup_pipe_writers(pipe);
905 wakeup_pipe_writers(pipe);
954 loff_t *ppos,
size_t len,
unsigned int flags,
987 loff_t *ppos,
size_t len,
unsigned int flags)
999 sb_start_write(inode->
i_sb);
1027 unsigned long nr_pages;
1039 sb_end_write(inode->
i_sb);
1052 data = buf->
ops->map(pipe, buf, 0);
1054 buf->
ops->unmap(pipe, buf, data);
1060 struct file *
out, loff_t *ppos,
1061 size_t len,
unsigned int flags)
1086 loff_t *ppos,
size_t len,
unsigned int flags)
1096 static long do_splice_from(
struct pipe_inode_info *pipe,
struct file *out,
1097 loff_t *ppos,
size_t len,
unsigned int flags)
1113 if (out->
f_op && out->
f_op->splice_write)
1114 splice_write = out->
f_op->splice_write;
1116 splice_write = default_file_splice_write;
1118 return splice_write(pipe, out, ppos, len, flags);
1124 static long do_splice_to(
struct file *in, loff_t *ppos,
1128 ssize_t (*splice_read)(
struct file *, loff_t *,
1139 if (in->
f_op && in->
f_op->splice_read)
1140 splice_read = in->
f_op->splice_read;
1144 return splice_read(in, ppos, pipe, len, flags);
1174 i_mode = in->
f_path.dentry->d_inode->i_mode;
1213 loff_t pos = sd->
pos, prev_pos =
pos;
1215 ret = do_splice_to(in, &pos, pipe, len, flags);
1227 ret = actor(pipe, sd);
1237 if (ret < read_len) {
1238 sd->
pos = prev_pos +
ret;
1253 for (i = 0; i < pipe->
buffers; i++) {
1257 buf->
ops->release(pipe, buf);
1272 struct file *file = sd->
u.
file;
1294 size_t len,
unsigned int flags)
1314 size_t len,
unsigned int flags);
1319 static long do_splice(
struct file *in, loff_t __user *off_in,
1320 struct file *out, loff_t __user *off_out,
1321 size_t len,
unsigned int flags)
1331 if (ipipe && opipe) {
1332 if (off_in || off_out)
1345 return splice_pipe_to_pipe(ipipe, opipe, len, flags);
1360 ret = do_splice_from(ipipe, out, off, len, flags);
1362 if (off_out &&
copy_to_user(off_out, off,
sizeof(loff_t)))
1380 ret = do_splice_to(in, off, opipe, len, flags);
1382 if (off_in &&
copy_to_user(off_in, off,
sizeof(loff_t)))
1398 static int get_iovec_page_array(
const struct iovec __user *iov,
1399 unsigned int nr_vecs,
struct page **pages,
1401 unsigned int pipe_buffers)
1406 unsigned long off, npages;
1416 base =
entry.iov_base;
1417 len =
entry.iov_len;
1440 if (aligned && (off || len & ~
PAGE_MASK))
1444 if (npages > pipe_buffers - buffers)
1445 npages = pipe_buffers - buffers;
1448 0, &pages[buffers]);
1456 for (i = 0; i <
error; i++) {
1459 partial[buffers].
offset = off;
1480 if (error < npages || buffers == pipe_buffers)
1503 if (!fault_in_pages_writeable(sd->
u.
userptr, sd->
len)) {
1504 src = buf->
ops->map(pipe, buf, 1);
1507 buf->
ops->unmap(pipe, buf, src);
1517 src = buf->
ops->map(pipe, buf, 0);
1523 buf->
ops->unmap(pipe, buf, src);
1534 static long vmsplice_to_user(
struct file *file,
const struct iovec __user *iov,
1535 unsigned long nr_segs,
unsigned int flags)
1557 error =
get_user(base, &iov->iov_base);
1560 error =
get_user(len, &iov->iov_len);
1615 static long vmsplice_to_pipe(
struct file *file,
const struct iovec __user *iov,
1616 unsigned long nr_segs,
unsigned int flags)
1626 .ops = &user_page_pipe_buf_ops,
1638 spd.
nr_pages = get_iovec_page_array(iov, nr_segs, spd.
pages,
1667 unsigned long, nr_segs,
unsigned int, flags)
1681 error = vmsplice_to_pipe(f.
file, iov, nr_segs, flags);
1683 error = vmsplice_to_user(f.
file, iov, nr_segs, flags);
1692 int, fd_out, loff_t __user *, off_out,
1693 size_t, len,
unsigned int, flags)
1705 out = fdget(fd_out);
1708 error = do_splice(in.
file, off_in,
1723 static int ipipe_prep(
struct pipe_inode_info *pipe,
unsigned int flags)
1738 if (signal_pending(
current)) {
1761 static int opipe_prep(
struct pipe_inode_info *pipe,
unsigned int flags)
1785 if (signal_pending(
current)) {
1803 size_t len,
unsigned int flags)
1807 bool input_wakeup =
false;
1811 ret = ipipe_prep(ipipe, flags);
1815 ret = opipe_prep(opipe, flags);
1846 if (flags & SPLICE_F_NONBLOCK) {
1863 obuf = opipe->
bufs + nbuf;
1865 if (len >= ibuf->
len) {
1874 input_wakeup =
true;
1880 ibuf->
ops->get(ipipe, ibuf);
1905 wakeup_pipe_readers(opipe);
1908 wakeup_pipe_writers(ipipe);
1918 size_t len,
unsigned int flags)
1921 int ret = 0, i = 0, nbuf;
1952 ibuf->
ops->get(ipipe, ibuf);
1954 obuf = opipe->
bufs + nbuf;
1963 if (obuf->
len > len)
1986 wakeup_pipe_readers(opipe);
1997 static long do_tee(
struct file *in,
struct file *out,
size_t len,
2008 if (ipipe && opipe && ipipe != opipe) {
2013 ret = ipipe_prep(ipipe, flags);
2015 ret = opipe_prep(opipe, flags);
2017 ret = link_pipe(ipipe, opipe, len, flags);
2036 struct fd out = fdget(fdout);