Skip to content

Commit

Permalink
[SPLICE]: Don't assume regular pages in splice_to_pipe()
Browse files Browse the repository at this point in the history
Allow caller to pass in a release function, there might be
other resources that need releasing as well. Needed for
network receive.

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Jens Axboe authored and David S. Miller committed Jan 28, 2008
1 parent d10f215 commit bbdfc2f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
9 changes: 8 additions & 1 deletion fs/splice.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,16 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
}

while (page_nr < spd_pages)
page_cache_release(spd->pages[page_nr++]);
spd->spd_release(spd, page_nr++);

return ret;
}

static void spd_release_page(struct splice_pipe_desc *spd, unsigned int i)
{
page_cache_release(spd->pages[i]);
}

static int
__generic_file_splice_read(struct file *in, loff_t *ppos,
struct pipe_inode_info *pipe, size_t len,
Expand All @@ -277,6 +282,7 @@ __generic_file_splice_read(struct file *in, loff_t *ppos,
.partial = partial,
.flags = flags,
.ops = &page_cache_pipe_buf_ops,
.spd_release = spd_release_page,
};

index = *ppos >> PAGE_CACHE_SHIFT;
Expand Down Expand Up @@ -1432,6 +1438,7 @@ static long vmsplice_to_pipe(struct file *file, const struct iovec __user *iov,
.partial = partial,
.flags = flags,
.ops = &user_page_pipe_buf_ops,
.spd_release = spd_release_page,
};

pipe = pipe_info(file->f_path.dentry->d_inode);
Expand Down
1 change: 1 addition & 0 deletions include/linux/splice.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ struct splice_pipe_desc {
int nr_pages; /* number of pages in map */
unsigned int flags; /* splice flags */
const struct pipe_buf_operations *ops;/* ops associated with output pipe */
void (*spd_release)(struct splice_pipe_desc *, unsigned int);
};

typedef int (splice_actor)(struct pipe_inode_info *, struct pipe_buffer *,
Expand Down

0 comments on commit bbdfc2f

Please sign in to comment.