14 struct spliceio_data {
15 struct io_u *last_io_u;
19 static int fio_spliceio_getevents(struct thread_data *td, int fio_unused min,
20 int max, struct timespec fio_unused *t)
25 * we can only have one finished io_u for sync io, since the depth
28 if (list_empty(&td->io_u_busylist))
34 static struct io_u *fio_spliceio_event(struct thread_data *td, int event)
36 struct spliceio_data *sd = td->io_ops->data;
44 * For splice reading, we unfortunately cannot (yet) vmsplice the other way.
45 * So just splice the data from the file into the pipe, and use regular
46 * read to fill the buffer. Doesn't make a lot of sense, but...
48 static int fio_splice_read(struct thread_data *td, struct io_u *io_u)
50 struct spliceio_data *sd = td->io_ops->data;
51 struct fio_file *f = io_u->file;
52 int ret, ret2, buflen;
56 offset = io_u->offset;
57 buflen = io_u->buflen;
60 int this_len = buflen;
62 if (this_len > SPLICE_DEF_SIZE)
63 this_len = SPLICE_DEF_SIZE;
65 ret = splice(f->fd, &offset, sd->pipe[1], NULL, this_len, SPLICE_F_MORE);
67 if (errno == ENODATA || errno == EAGAIN)
76 ret2 = read(sd->pipe[0], p, ret);
89 * For splice writing, we can vmsplice our data buffer directly into a
90 * pipe and then splice that to a file.
92 static int fio_splice_write(struct thread_data *td, struct io_u *io_u)
94 struct spliceio_data *sd = td->io_ops->data;
95 struct iovec iov[1] = {
97 .iov_base = io_u->buf,
98 .iov_len = io_u->buflen,
101 struct pollfd pfd = { .fd = sd->pipe[1], .events = POLLOUT, };
102 struct fio_file *f = io_u->file;
103 off_t off = io_u->offset;
106 while (iov[0].iov_len) {
107 if (poll(&pfd, 1, -1) < 0)
110 ret = vmsplice(sd->pipe[1], iov, 1, SPLICE_F_NONBLOCK);
114 iov[0].iov_len -= ret;
115 iov[0].iov_base += ret;
118 ret2 = splice(sd->pipe[0], NULL, f->fd, &off, ret, 0);
129 static int fio_spliceio_queue(struct thread_data *td, struct io_u *io_u)
131 struct spliceio_data *sd = td->io_ops->data;
134 if (io_u->ddir == DDIR_READ)
135 ret = fio_splice_read(td, io_u);
136 else if (io_u->ddir == DDIR_WRITE)
137 ret = fio_splice_write(td, io_u);
139 ret = fsync(io_u->file->fd);
141 if ((unsigned int) ret != io_u->buflen) {
143 io_u->resid = io_u->buflen - ret;
144 io_u->error = ENODATA;
150 sd->last_io_u = io_u;
155 static void fio_spliceio_cleanup(struct thread_data *td)
157 struct spliceio_data *sd = td->io_ops->data;
163 td->io_ops->data = NULL;
167 static int fio_spliceio_init(struct thread_data *td)
169 struct spliceio_data *sd = malloc(sizeof(*sd));
171 sd->last_io_u = NULL;
172 if (pipe(sd->pipe) < 0) {
173 td_verror(td, errno);
178 td->io_ops->data = sd;
182 struct ioengine_ops ioengine = {
184 .version = FIO_IOOPS_VERSION,
185 .init = fio_spliceio_init,
186 .queue = fio_spliceio_queue,
187 .getevents = fio_spliceio_getevents,
188 .event = fio_spliceio_event,
189 .cleanup = fio_spliceio_cleanup,