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 <dhowells@redhat.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Christian Brauner <brauner@kernel.org> cc: Miklos Szeredi <miklos@szeredi.hu> cc: Jens Axboe <axboe@kernel.dk> cc: Al Viro <viro@zeniv.linux.org.uk> cc: John Hubbard <jhubbard@nvidia.com> cc: David Hildenbrand <david@redhat.com> cc: Matthew Wilcox <willy@infradead.org> cc: linux-unionfs@vger.kernel.org cc: linux-block@vger.kernel.org cc: linux-fsdevel@vger.kernel.org cc: linux-mm@kvack.org Link: https://lore.kernel.org/r/CAJfpeguGksS3sCigmRi9hJdUec8qtM9f+_9jC1rJhsXT+dV01w@mail.gmail.com/ [1] Link: https://lore.kernel.org/r/20230522135018.2742245-6-dhowells@redhat.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
Родитель
e69f37bce1
Коммит
6a3f30b8bd
27
fs/splice.c
27
fs/splice.c
|
@ -867,12 +867,24 @@ static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
|
|||
return out->f_op->splice_write(pipe, out, ppos, len, flags);
|
||||
}
|
||||
|
||||
/*
|
||||
* Attempt to initiate a splice from a file to a pipe.
|
||||
/**
|
||||
* vfs_splice_read - Read data from a file and splice it into a pipe
|
||||
* @in: File to splice from
|
||||
* @ppos: Input file offset
|
||||
* @pipe: Pipe to splice to
|
||||
* @len: Number of bytes to splice
|
||||
* @flags: Splice modifier flags (SPLICE_F_*)
|
||||
*
|
||||
* Splice the requested amount of data from the input file to the pipe. This
|
||||
* is synchronous as the caller must hold the pipe lock across the entire
|
||||
* operation.
|
||||
*
|
||||
* If successful, it returns the amount of data spliced, 0 if it hit the EOF or
|
||||
* a hole and a negative error code otherwise.
|
||||
*/
|
||||
static long do_splice_to(struct file *in, loff_t *ppos,
|
||||
struct pipe_inode_info *pipe, size_t len,
|
||||
unsigned int flags)
|
||||
long vfs_splice_read(struct file *in, loff_t *ppos,
|
||||
struct pipe_inode_info *pipe, size_t len,
|
||||
unsigned int flags)
|
||||
{
|
||||
unsigned int p_space;
|
||||
int ret;
|
||||
|
@ -895,6 +907,7 @@ static long do_splice_to(struct file *in, loff_t *ppos,
|
|||
return warn_unsupported(in, "read");
|
||||
return in->f_op->splice_read(in, ppos, pipe, len, flags);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(vfs_splice_read);
|
||||
|
||||
/**
|
||||
* 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,
|
|||
size_t read_len;
|
||||
loff_t pos = sd->pos, prev_pos = pos;
|
||||
|
||||
ret = do_splice_to(in, &pos, pipe, len, flags);
|
||||
ret = vfs_splice_read(in, &pos, pipe, len, flags);
|
||||
if (unlikely(ret <= 0))
|
||||
goto out_release;
|
||||
|
||||
|
@ -1112,7 +1125,7 @@ long splice_file_to_pipe(struct file *in,
|
|||
pipe_lock(opipe);
|
||||
ret = wait_for_space(opipe, flags);
|
||||
if (!ret)
|
||||
ret = do_splice_to(in, offset, opipe, len, flags);
|
||||
ret = vfs_splice_read(in, offset, opipe, len, flags);
|
||||
pipe_unlock(opipe);
|
||||
if (ret > 0)
|
||||
wakeup_pipe_readers(opipe);
|
||||
|
|
|
@ -76,6 +76,9 @@ extern ssize_t splice_to_pipe(struct pipe_inode_info *,
|
|||
struct splice_pipe_desc *);
|
||||
extern ssize_t add_to_pipe(struct pipe_inode_info *,
|
||||
struct pipe_buffer *);
|
||||
long vfs_splice_read(struct file *in, loff_t *ppos,
|
||||
struct pipe_inode_info *pipe, size_t len,
|
||||
unsigned int flags);
|
||||
extern ssize_t splice_direct_to_actor(struct file *, struct splice_desc *,
|
||||
splice_direct_actor *);
|
||||
extern long do_splice(struct file *in, loff_t *off_in,
|
||||
|
|
Загрузка…
Ссылка в новой задаче