Skip to content


new iov_iter flavour: pipe-backed
Browse files Browse the repository at this point in the history
iov_iter variant for passing data into pipe.  copy_to_iter()
copies data into page(s) it has allocated and stuffs them into
the pipe; copy_page_to_iter() stuffs there a reference to the
page given to it.  Both will try to coalesce if possible.
iov_iter_zero() is similar to copy_to_iter(); iov_iter_get_pages()
and friends will do as copy_to_iter() would have and return the
pages where the data would've been copied.  iov_iter_advance()
will truncate everything past the spot it has advanced to.

New primitive: iov_iter_pipe(), used for initializing those.
pipe should be locked all along.

Running out of space acts as fault would for iovec-backed ones;
in other words, giving it to ->read_iter() may result in short
read if the pipe overflows, or -EFAULT if it happens with nothing
copied there.

In other words, ->read_iter() on those acts pretty much like
->splice_read().  Moreover, all generic_file_splice_read() users,
as well as many other ->splice_read() instances can be switched
to that scheme - that'll happen in the next commit.

Signed-off-by: Al Viro <>
  • Loading branch information
Al Viro committed Oct 5, 2016
1 parent d82718e commit 241699c
Show file tree
Hide file tree
Showing 4 changed files with 408 additions and 6 deletions.
2 changes: 1 addition & 1 deletion fs/splice.c
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ ssize_t generic_file_splice_read(struct file *in, loff_t *ppos,

static const struct pipe_buf_operations default_pipe_buf_ops = {
const struct pipe_buf_operations default_pipe_buf_ops = {
.can_merge = 0,
.confirm = generic_pipe_buf_confirm,
.release = generic_pipe_buf_release,
Expand Down
1 change: 1 addition & 0 deletions include/linux/splice.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,5 @@ extern void splice_shrink_spd(struct splice_pipe_desc *);
extern void spd_release_page(struct splice_pipe_desc *, unsigned int);

extern const struct pipe_buf_operations page_cache_pipe_buf_ops;
extern const struct pipe_buf_operations default_pipe_buf_ops;
14 changes: 11 additions & 3 deletions include/linux/uio.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <uapi/linux/uio.h>

struct page;
struct pipe_inode_info;

struct kvec {
void *iov_base; /* and that should *never* hold a userland pointer */
Expand All @@ -23,6 +24,7 @@ enum {

struct iov_iter {
Expand All @@ -33,8 +35,12 @@ struct iov_iter {
const struct iovec *iov;
const struct kvec *kvec;
const struct bio_vec *bvec;
struct pipe_inode_info *pipe;
union {
unsigned long nr_segs;
int idx;
unsigned long nr_segs;

Expand Down Expand Up @@ -64,7 +70,7 @@ static inline struct iovec iov_iter_iovec(const struct iov_iter *iter)

#define iov_for_each(iov, iter, start) \
if (!((start).type & ITER_BVEC)) \
if (!((start).type & (ITER_BVEC | ITER_PIPE))) \
for (iter = (start); \
(iter).count && \
((iov = iov_iter_iovec(&(iter))), 1); \
Expand Down Expand Up @@ -94,6 +100,8 @@ void iov_iter_kvec(struct iov_iter *i, int direction, const struct kvec *kvec,
unsigned long nr_segs, size_t count);
void iov_iter_bvec(struct iov_iter *i, int direction, const struct bio_vec *bvec,
unsigned long nr_segs, size_t count);
void iov_iter_pipe(struct iov_iter *i, int direction, struct pipe_inode_info *pipe,
size_t count);
ssize_t iov_iter_get_pages(struct iov_iter *i, struct page **pages,
size_t maxsize, unsigned maxpages, size_t *start);
ssize_t iov_iter_get_pages_alloc(struct iov_iter *i, struct page ***pages,
Expand All @@ -109,7 +117,7 @@ static inline size_t iov_iter_count(struct iov_iter *i)

static inline bool iter_is_iovec(struct iov_iter *i)
return !(i->type & (ITER_BVEC | ITER_KVEC));
return !(i->type & (ITER_BVEC | ITER_KVEC | ITER_PIPE));

Expand Down

0 comments on commit 241699c

Please sign in to comment.