@@ -875,6 +875,11 @@ static ssize_t splice_socket_generic(struct pipe_inode_info *pipe,
if (out->f_flags & O_NONBLOCK)
msg.msg_flags |= MSG_DONTWAIT;
+ if (unlikely(flags & SPLICE_F_ZC) && ubuf_info) {
+ msg.msg_flags = MSG_ZEROCOPY;
+ msg.msg_ubuf = ubuf_info;
+ }
+
iov_iter_bvec(&msg.msg_iter, ITER_SOURCE, bvec, bc,
len - remain);
ret = sock_sendmsg(sock, &msg);
@@ -1223,12 +1228,27 @@ static ssize_t do_splice_direct_actor(struct file *in, loff_t *ppos,
if (unlikely(out->f_flags & O_APPEND))
return -EINVAL;
+ if (unlikely(flags & SPLICE_F_ZC)) {
+ struct socket *sock = sock_from_file(out);
+ struct sock *sk = sock->sk;
+ struct ubuf_info *ubuf_info;
+
+ ubuf_info = msg_zerocopy_realloc(sk, len, NULL);
+ if (!ubuf_info)
+ return -ENOMEM;
+ sd.ubuf_info = ubuf_info;
+ }
+
ret = splice_direct_to_actor(in, &sd, actor);
if (ret > 0)
*ppos = sd.pos;
+ if (unlikely(flags & SPLICE_F_ZC))
+ refcount_dec(&sd.ubuf_info->refcnt);
+
return ret;
}
+
/**
* do_splice_direct - splices data directly between two files
* @in: file to splice from
@@ -21,8 +21,9 @@
/* from/to, of course */
#define SPLICE_F_MORE (0x04) /* expect more data */
#define SPLICE_F_GIFT (0x08) /* pages passed in are a gift */
+#define SPLICE_F_ZC (0x10) /* generate zero copy notifications */
-#define SPLICE_F_ALL (SPLICE_F_MOVE|SPLICE_F_NONBLOCK|SPLICE_F_MORE|SPLICE_F_GIFT)
+#define SPLICE_F_ALL (SPLICE_F_MOVE|SPLICE_F_NONBLOCK|SPLICE_F_MORE|SPLICE_F_GIFT|SPLICE_F_ZC)
/*
* Passed to the actors
Add the SPLICE_F_ZC flag and when it is set, allocate a ubuf and attach it to generate zerocopy notifications. Signed-off-by: Joe Damato <jdamato@fastly.com> --- fs/splice.c | 20 ++++++++++++++++++++ include/linux/splice.h | 3 ++- 2 files changed, 22 insertions(+), 1 deletion(-)