14 #ifdef FIO_HAVE_SPLICE
16 struct spliceio_data {
17 struct io_u *last_io_u;
21 static int fio_spliceio_getevents(struct thread_data *td, int fio_unused min,
22 int max, struct timespec fio_unused *t)
27 * we can only have one finished io_u for sync io, since the depth
30 if (list_empty(&td->io_u_busylist))
36 static struct io_u *fio_spliceio_event(struct thread_data *td, int event)
38 struct spliceio_data *sd = td->io_ops->data;
46 * For splice reading, we unfortunately cannot (yet) vmsplice the other way.
47 * So just splice the data from the file into the pipe, and use regular
48 * read to fill the buffer. Doesn't make a lot of sense, but...
50 static int fio_splice_read(struct thread_data *td, struct io_u *io_u)
52 struct spliceio_data *sd = td->io_ops->data;
53 struct fio_file *f = io_u->file;
54 int ret, ret2, buflen;
58 offset = io_u->offset;
59 buflen = io_u->buflen;
62 int this_len = buflen;
64 if (this_len > SPLICE_DEF_SIZE)
65 this_len = SPLICE_DEF_SIZE;
67 ret = splice(f->fd, &offset, sd->pipe[1], NULL, this_len, SPLICE_F_MORE);
69 if (errno == ENODATA || errno == EAGAIN)
78 ret2 = read(sd->pipe[0], p, ret);
91 * For splice writing, we can vmsplice our data buffer directly into a
92 * pipe and then splice that to a file.
94 static int fio_splice_write(struct thread_data *td, struct io_u *io_u)
96 struct spliceio_data *sd = td->io_ops->data;
97 struct iovec iov[1] = {
99 .iov_base = io_u->buf,
100 .iov_len = io_u->buflen,
103 struct pollfd pfd = { .fd = sd->pipe[1], .events = POLLOUT, };
104 struct fio_file *f = io_u->file;
105 off_t off = io_u->offset;
108 while (iov[0].iov_len) {
109 if (poll(&pfd, 1, -1) < 0)
112 ret = vmsplice(sd->pipe[1], iov, 1, SPLICE_F_NONBLOCK);
116 iov[0].iov_len -= ret;
117 iov[0].iov_base += ret;
120 ret2 = splice(sd->pipe[0], NULL, f->fd, &off, ret, 0);
131 static int fio_spliceio_queue(struct thread_data *td, struct io_u *io_u)
133 struct spliceio_data *sd = td->io_ops->data;
136 if (io_u->ddir == DDIR_READ)
137 ret = fio_splice_read(td, io_u);
138 else if (io_u->ddir == DDIR_WRITE)
139 ret = fio_splice_write(td, io_u);
141 ret = fsync(io_u->file->fd);
143 if (ret != io_u->buflen) {
145 io_u->resid = io_u->buflen - ret;
146 io_u->error = ENODATA;
152 sd->last_io_u = io_u;
157 static void fio_spliceio_cleanup(struct thread_data *td)
159 struct spliceio_data *sd = td->io_ops->data;
165 td->io_ops->data = NULL;
169 static int fio_spliceio_init(struct thread_data *td)
171 struct spliceio_data *sd = malloc(sizeof(*sd));
173 sd->last_io_u = NULL;
174 if (pipe(sd->pipe) < 0) {
175 td_verror(td, errno);
180 td->io_ops->data = sd;
184 struct ioengine_ops ioengine = {
186 .version = FIO_IOOPS_VERSION,
187 .init = fio_spliceio_init,
188 .queue = fio_spliceio_queue,
189 .getevents = fio_spliceio_getevents,
190 .event = fio_spliceio_event,
191 .cleanup = fio_spliceio_cleanup,
195 #else /* FIO_HAVE_SPLICE */
198 * When we have a proper configure system in place, we simply wont build
199 * and install this io engine. For now install a crippled version that
200 * just complains and fails to load.
202 static int fio_spliceio_init(struct thread_data fio_unused *td)
204 fprintf(stderr, "fio: splice not available\n");
208 struct ioengine_ops ioengine = {
210 .version = FIO_IOOPS_VERSION,
211 .init = fio_spliceio_init,