Skip to content

Commit 6a3f30b

Browse files
dhowellsaxboe
authored andcommitted
splice: Make do_splice_to() generic and export it
Rename do_splice_to() to vfs_splice_read() and export it so that it can be used as a helper when calling down to a lower layer filesystem as it performs all the necessary checks[1]. Signed-off-by: David Howells <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: Christian Brauner <[email protected]> cc: Miklos Szeredi <[email protected]> cc: Jens Axboe <[email protected]> cc: Al Viro <[email protected]> cc: John Hubbard <[email protected]> cc: David Hildenbrand <[email protected]> cc: Matthew Wilcox <[email protected]> cc: [email protected] cc: [email protected] cc: [email protected] cc: [email protected] Link: https://lore.kernel.org/r/CAJfpeguGksS3sCigmRi9hJdUec8qtM9f+_9jC1rJhsXT+dV01w@mail.gmail.com/ [1] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent e69f37b commit 6a3f30b

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

fs/splice.c

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -867,12 +867,24 @@ static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
867867
return out->f_op->splice_write(pipe, out, ppos, len, flags);
868868
}
869869

870-
/*
871-
* Attempt to initiate a splice from a file to a pipe.
870+
/**
871+
* vfs_splice_read - Read data from a file and splice it into a pipe
872+
* @in: File to splice from
873+
* @ppos: Input file offset
874+
* @pipe: Pipe to splice to
875+
* @len: Number of bytes to splice
876+
* @flags: Splice modifier flags (SPLICE_F_*)
877+
*
878+
* Splice the requested amount of data from the input file to the pipe. This
879+
* is synchronous as the caller must hold the pipe lock across the entire
880+
* operation.
881+
*
882+
* If successful, it returns the amount of data spliced, 0 if it hit the EOF or
883+
* a hole and a negative error code otherwise.
872884
*/
873-
static long do_splice_to(struct file *in, loff_t *ppos,
874-
struct pipe_inode_info *pipe, size_t len,
875-
unsigned int flags)
885+
long vfs_splice_read(struct file *in, loff_t *ppos,
886+
struct pipe_inode_info *pipe, size_t len,
887+
unsigned int flags)
876888
{
877889
unsigned int p_space;
878890
int ret;
@@ -895,6 +907,7 @@ static long do_splice_to(struct file *in, loff_t *ppos,
895907
return warn_unsupported(in, "read");
896908
return in->f_op->splice_read(in, ppos, pipe, len, flags);
897909
}
910+
EXPORT_SYMBOL_GPL(vfs_splice_read);
898911

899912
/**
900913
* splice_direct_to_actor - splices data directly between two non-pipes
@@ -964,7 +977,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
964977
size_t read_len;
965978
loff_t pos = sd->pos, prev_pos = pos;
966979

967-
ret = do_splice_to(in, &pos, pipe, len, flags);
980+
ret = vfs_splice_read(in, &pos, pipe, len, flags);
968981
if (unlikely(ret <= 0))
969982
goto out_release;
970983

@@ -1112,7 +1125,7 @@ long splice_file_to_pipe(struct file *in,
11121125
pipe_lock(opipe);
11131126
ret = wait_for_space(opipe, flags);
11141127
if (!ret)
1115-
ret = do_splice_to(in, offset, opipe, len, flags);
1128+
ret = vfs_splice_read(in, offset, opipe, len, flags);
11161129
pipe_unlock(opipe);
11171130
if (ret > 0)
11181131
wakeup_pipe_readers(opipe);

include/linux/splice.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ extern ssize_t splice_to_pipe(struct pipe_inode_info *,
7676
struct splice_pipe_desc *);
7777
extern ssize_t add_to_pipe(struct pipe_inode_info *,
7878
struct pipe_buffer *);
79+
long vfs_splice_read(struct file *in, loff_t *ppos,
80+
struct pipe_inode_info *pipe, size_t len,
81+
unsigned int flags);
7982
extern ssize_t splice_direct_to_actor(struct file *, struct splice_desc *,
8083
splice_direct_actor *);
8184
extern long do_splice(struct file *in, loff_t *off_in,

0 commit comments

Comments
 (0)