splice helpers + tests
v2 cover splice helpers + tests
Add splice prep helpers and some basic tests.
v2: minor: fix comment, add inline, remove newline
Pavel Begunkov (2):
splice: add splice(2) helpers
test/splice: add basic splice tests
src/include/liburing.h | 11 +++ src/include/liburing/io_uring.h | 14 +++- test/Makefile | 4 +- test/splice.c | 138 ++++++++++++++++++++++++++++++++ 4 files changed, 164 insertions(+), 3 deletions(-) create mode 100644 test/splice.c
Signature · 1 line
2.24.0
PATCH v2 1/2 splice: add splice(2) helpers
Add splice helpers and update io_uring.h
--- src/include/liburing.h | 11 +++++++++++ src/include/liburing/io_uring.h | 14 +++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-)
src/include/liburing.h +11 -0
@@ -191,6 +191,17 @@ static inline void io_uring_prep_rw(int op, struct io_uring_sqe *sqe, int fd, sqe->__pad2[0 ] = sqe->__pad2[1 ] = sqe->__pad2[2 ] =0 ; } +static inline void io_uring_prep_splice (struct io_uring_sqe *sqe, +int fd_in,loff_t off_in, +int fd_out,loff_t off_out, +unsigned int nbytes,int splice_flags) +{ +io_uring_prep_rw (IORING_OP_SPLICE , sqe, fd_out, (void *)off_in, + nbytes, off_out); + sqe->splice_fd_in = fd_in; + sqe->splice_flags = splice_flags; +} +static inline void io_uring_prep_readv (struct io_uring_sqe *sqe,int fd,const struct iovec *iovecs,unsigned nr_vecs,off_t offset)
src/include/liburing/io_uring.h +13 -1
@@ -23,7 +23,10 @@ struct io_uring_sqe {__u64 off;/* offset into file */ __u64 addr2; }; -__u64 addr;/* pointer to buffer or iovecs */ +union { +__u64 addr;/* pointer to buffer or iovecs */ +__u64 off_in; + };__u32 len;/* buffer size or number of iovecs */ union {__kernel_rwf_t rw_flags;
@@ -37,6 +40,7 @@ struct io_uring_sqe {__u32 open_flags;__u32 statx_flags;__u32 fadvise_advice; +__u32 splice_flags; };__u64 user_data;/* data to be passed back at completion time */ union {
@@ -45,6 +49,7 @@ struct io_uring_sqe {__u16 buf_index;/* personality to use, if used */ __u16 personality; +__u32 splice_fd_in; };__u64 __pad2[3 ]; };
@@ -113,6 +118,7 @@ enum {IORING_OP_RECV ,IORING_OP_OPENAT2 ,IORING_OP_EPOLL_CTL , +IORING_OP_SPLICE ,/* this goes last, obviously */ IORING_OP_LAST,
@@ -128,6 +134,12 @@ enum {*/ #define IORING_TIMEOUT_ABS (1U << 0) +/* +* sqe->splice_flags +* extends splice(2) flags +*/ +#define SPLICE_F_FD_IN_FIXED (1U << 31)/* the last bit of __u32 */ +/* * IO completion data structure (Completion Queue Entry) */
Signature · 1 line
2.24.0
PATCH v2 2/2 test/splice: add basic splice tests
In reply to Pavel Begunkov--- test/Makefile | 4 +- test/splice.c | 138 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 140 insertions(+), 2 deletions(-) create mode 100644 test/splice.c
test/Makefile +2 -2
@@ -20,7 +20,7 @@ all_targets += poll poll-cancel ring-leak fsync io_uring_setup io_uring_register connect 7ad0e4b2f83c-test submit-reuse fallocate open-close \ file-update statx accept-reuse poll-v-poll fadvise madvise \ short-read openat2 probe shared-wq personality eventfd \ - send_recv eventfd-ring across-fork + send_recv eventfd-ring across-fork splice include ../Makefile.quiet
@@ -47,7 +47,7 @@ test_srcs := poll.c poll-cancel.c ring-leak.c fsync.c io_uring_setup.c \ 7ad0e4b2f83c-test.c submit-reuse.c fallocate.c open-close.c \ file-update.c statx.c accept-reuse.c poll-v-poll.c fadvise.c \ madvise.c short-read.c openat2.c probe.c shared-wq.c \ - personality.c eventfd.c eventfd-ring.c across-fork.c + personality.c eventfd.c eventfd-ring.c across-fork.c splice.c test_objs := $(patsubst %.c,%.ol,$(test_srcs))
test/splice.c new file +138 -0
138 lines not on this page · raw message
Signature · 1 line
2.24.0
Re: [PATCH v2 1/2] splice: add splice(2) helpers
In reply to Pavel BegunkovHi Pavel,
src/include/liburing.h static inline void io_uring_prep_rw(int op, struct io_uring_sqe *sqe, int fd, · line 198
Quoted 13 lines
src/include/liburing.h +5
-0@@ -191,6 +191,17 @@ static inline void io_uring_prep_rw(int op, struct io_uring_sqe *sqe, int fd, sqe->__pad2[0 ] = sqe->__pad2[1 ] = sqe->__pad2[2 ] =0 ; } +static inline void io_uring_prep_splice (struct io_uring_sqe *sqe, +int fd_in,loff_t off_in, +int fd_out,loff_t off_out, +unsigned int nbytes,int splice_flags) +{
The splice() syscall takes 'size_t len' and 'unsigned int flags', I think we should at least change this to 'unsigned int splice_flags'.
Quoted 25 lines
src/include/liburing/io_uring.h +5
-1@@ -23,7 +23,10 @@ struct io_uring_sqe {__u64 off;/* offset into file */ __u64 addr2; }; -__u64 addr;/* pointer to buffer or iovecs */ +union { +__u64 addr;/* pointer to buffer or iovecs */ +__u64 off_in; + };__u32 len;/* buffer size or number of iovecs */ union {__kernel_rwf_t rw_flags;@@ -37,6 +40,7 @@ struct io_uring_sqe {__u32 open_flags;__u32 statx_flags;__u32 fadvise_advice; +__u32 splice_flags; };__u64 user_data;/* data to be passed back at completion time */ union {
src/include/liburing/io_uring.h struct io_uring_sqe { · line 52
Quoted 4 lines
src/include/liburing/io_uring.h +1
-0@@ -45,6 +49,7 @@ struct io_uring_sqe {__u16 buf_index;/* personality to use, if used */ __u16 personality; +__u32 splice_fd_in;
Shouldn't this be __s32 in order to match "__s32 fd"?
src/include/liburing/io_uring.h struct io_uring_sqe { · line 53
Quoted 1 line
src/include/liburing/io_uring.h +0
-0};
Can you please add BUILD_BUG_SQE_ELEM() checks for the new elements in io_uring_init()?
Thanks!
metze
Re: [PATCH v2 1/2] splice: add splice(2) helpers
Quoted 10 lines · Stefan Metzmacher
Hi Pavel,
Quoted 8 lines
src/include/liburing.h +0
-0@@ -191,6 +191,17 @@ static inline void io_uring_prep_rw(int op, struct io_uring_sqe *sqe, int fd, sqe->__pad2[0 ] = sqe->__pad2[1 ] = sqe->__pad2[2 ] =0 ; }
Quoted 7 lines
src/include/liburing.h static inline void io_uring_prep_rw(int op, struct io_uring_sqe *sqe, int fd, · line 198
Quoted 5 lines
src/include/liburing.h +5
-0+static inline void io_uring_prep_splice (struct io_uring_sqe *sqe, +int fd_in,loff_t off_in, +int fd_out,loff_t off_out, +unsigned int nbytes,int splice_flags) +{The
splice()syscall takes 'size_tlen' and 'unsigned int flags',
sqe->len is u32, so can't fit size_t there, it was discussed before.
Quoted 2 lines
I think we should at least change this to 'unsigned int
splice_flags'.
Good point, for the comments below as well. I'll resend.
Quoted 40 lines
Quoted 25 lines
src/include/liburing/io_uring.h +5
-1@@ -23,7 +23,10 @@ struct io_uring_sqe {__u64 off;/* offset into file */ __u64 addr2; }; -__u64 addr;/* pointer to buffer or iovecs */ +union { +__u64 addr;/* pointer to buffer or iovecs */ +__u64 off_in; + };__u32 len;/* buffer size or number of iovecs */ union {__kernel_rwf_t rw_flags;@@ -37,6 +40,7 @@ struct io_uring_sqe {__u32 open_flags;__u32 statx_flags;__u32 fadvise_advice; +__u32 splice_flags; };__u64 user_data;/* data to be passed back at completion time */ union {src/include/liburing/io_uring.h struct io_uring_sqe { · line 52
Quoted 4 lines
src/include/liburing/io_uring.h +1
-0@@ -45,6 +49,7 @@ struct io_uring_sqe {__u16 buf_index;/* personality to use, if used */ __u16 personality; +__u32 splice_fd_in;Shouldn't this be
__s32in order to match "__s32fd"?src/include/liburing/io_uring.h struct io_uring_sqe { · line 53
Quoted 1 line
src/include/liburing/io_uring.h +0
-0};Can you please add
BUILD_BUG_SQE_ELEM()checks for the new elements inio_uring_init()?Thanks!
metze
Signature · 1 line
Pavel Begunkov