14 struct spliceio_data {
15 struct io_u *last_io_u;
19 static int fio_spliceio_sync(struct thread_data fio_unused *td,
25 static int fio_spliceio_getevents(struct thread_data *td, int fio_unused min,
26 int max, struct timespec fio_unused *t)
31 * we can only have one finished io_u for sync io, since the depth
34 if (list_empty(&td->io_u_busylist))
40 static struct io_u *fio_spliceio_event(struct thread_data *td, int event)
42 struct spliceio_data *sd = td->io_ops->data;
50 * For splice reading, we unfortunately cannot (yet) vmsplice the other way.
51 * So just splice the data from the file into the pipe, and use regular
52 * read to fill the buffer. Doesn't make a lot of sense, but...
54 static int fio_splice_read(struct thread_data *td, struct io_u *io_u)
56 struct spliceio_data *sd = td->io_ops->data;
57 struct fio_file *f = io_u->file;
58 int ret, ret2, buflen;
62 offset = io_u->offset;
63 buflen = io_u->buflen;
66 int this_len = buflen;
68 if (this_len > SPLICE_DEF_SIZE)
69 this_len = SPLICE_DEF_SIZE;
71 ret = splice(f->fd, &offset, sd->pipe[1], NULL, this_len, SPLICE_F_MORE);
73 if (errno == ENODATA || errno == EAGAIN)
82 ret2 = read(sd->pipe[0], p, ret);
95 * For splice writing, we can vmsplice our data buffer directly into a
96 * pipe and then splice that to a file.
98 static int fio_splice_write(struct thread_data *td, struct io_u *io_u)
100 struct spliceio_data *sd = td->io_ops->data;
101 struct iovec iov[1] = {
103 .iov_base = io_u->buf,
104 .iov_len = io_u->buflen,
107 struct pollfd pfd = { .fd = sd->pipe[1], .events = POLLOUT, };
108 struct fio_file *f = io_u->file;
109 off_t off = io_u->offset;
112 while (iov[0].iov_len) {
113 if (poll(&pfd, 1, -1) < 0)
116 ret = vmsplice(sd->pipe[1], iov, 1, SPLICE_F_NONBLOCK);
120 iov[0].iov_len -= ret;
121 iov[0].iov_base += ret;
124 ret2 = splice(sd->pipe[0], NULL, f->fd, &off, ret, 0);
135 static int fio_spliceio_queue(struct thread_data *td, struct io_u *io_u)
137 struct spliceio_data *sd = td->io_ops->data;
140 if (io_u->ddir == DDIR_READ)
141 ret = fio_splice_read(td, io_u);
143 ret = fio_splice_write(td, io_u);
145 if ((unsigned int) ret != io_u->buflen) {
147 io_u->resid = io_u->buflen - ret;
148 io_u->error = ENODATA;
154 sd->last_io_u = io_u;
159 static void fio_spliceio_cleanup(struct thread_data *td)
161 struct spliceio_data *sd = td->io_ops->data;
167 td->io_ops->data = NULL;
171 static int fio_spliceio_init(struct thread_data *td)
173 struct spliceio_data *sd = malloc(sizeof(*sd));
175 sd->last_io_u = NULL;
176 if (pipe(sd->pipe) < 0) {
177 td_verror(td, errno);
182 td->io_ops->data = sd;
186 struct ioengine_ops ioengine = {
188 .version = FIO_IOOPS_VERSION,
189 .init = fio_spliceio_init,
190 .queue = fio_spliceio_queue,
191 .getevents = fio_spliceio_getevents,
192 .event = fio_spliceio_event,
193 .cleanup = fio_spliceio_cleanup,
194 .sync = fio_spliceio_sync,