14 struct spliceio_data {
15 struct io_u *last_io_u;
19 static int fio_spliceio_sync(struct thread_data *td)
24 static int fio_spliceio_getevents(struct thread_data *td, int fio_unused min,
25 int max, struct timespec fio_unused *t)
30 * we can only have one finished io_u for sync io, since the depth
33 if (list_empty(&td->io_u_busylist))
39 static struct io_u *fio_spliceio_event(struct thread_data *td, int event)
41 struct spliceio_data *sd = td->io_ops->data;
49 * For splice reading, we unfortunately cannot (yet) vmsplice the other way.
50 * So just splice the data from the file into the pipe, and use regular
51 * read to fill the buffer. Doesn't make a lot of sense, but...
53 static int fio_splice_read(struct thread_data *td, struct io_u *io_u)
55 struct spliceio_data *sd = td->io_ops->data;
56 int ret, ret2, buflen;
60 offset = io_u->offset;
61 buflen = io_u->buflen;
64 int this_len = buflen;
66 if (this_len > SPLICE_DEF_SIZE)
67 this_len = SPLICE_DEF_SIZE;
69 ret = splice(td->fd, &offset, sd->pipe[1], NULL, this_len, SPLICE_F_MORE);
71 if (errno == ENODATA || errno == EAGAIN)
80 ret2 = read(sd->pipe[0], p, ret);
93 * For splice writing, we can vmsplice our data buffer directly into a
94 * pipe and then splice that to a file.
96 static int fio_splice_write(struct thread_data *td, struct io_u *io_u)
98 struct spliceio_data *sd = td->io_ops->data;
99 struct iovec iov[1] = {
101 .iov_base = io_u->buf,
102 .iov_len = io_u->buflen,
105 struct pollfd pfd = { .fd = sd->pipe[1], .events = POLLOUT, };
106 off_t off = io_u->offset;
109 while (iov[0].iov_len) {
110 if (poll(&pfd, 1, -1) < 0)
113 ret = vmsplice(sd->pipe[1], iov, 1, SPLICE_F_NONBLOCK);
117 iov[0].iov_len -= ret;
118 iov[0].iov_base += ret;
121 ret2 = splice(sd->pipe[0], NULL, td->fd, &off, ret, 0);
132 static int fio_spliceio_queue(struct thread_data *td, struct io_u *io_u)
134 struct spliceio_data *sd = td->io_ops->data;
137 if (io_u->ddir == DDIR_READ)
138 ret = fio_splice_read(td, io_u);
140 ret = fio_splice_write(td, io_u);
142 if ((unsigned int) ret != io_u->buflen) {
144 io_u->resid = io_u->buflen - ret;
145 io_u->error = ENODATA;
151 sd->last_io_u = io_u;
156 static void fio_spliceio_cleanup(struct thread_data *td)
158 struct spliceio_data *sd = td->io_ops->data;
164 td->io_ops->data = NULL;
168 static int fio_spliceio_init(struct thread_data *td)
170 struct spliceio_data *sd = malloc(sizeof(*sd));
172 sd->last_io_u = NULL;
173 if (pipe(sd->pipe) < 0) {
174 td_verror(td, errno);
179 td->io_ops->data = sd;
183 struct ioengine_ops ioengine = {
185 .version = FIO_IOOPS_VERSION,
186 .init = fio_spliceio_init,
187 .queue = fio_spliceio_queue,
188 .getevents = fio_spliceio_getevents,
189 .event = fio_spliceio_event,
190 .cleanup = fio_spliceio_cleanup,
191 .sync = fio_spliceio_sync,