2 * native linux aio io engine
13 #define ev_to_iou(ev) (struct io_u *) ((unsigned long) (ev)->obj)
17 struct io_event *aio_events;
20 static int fio_libaio_sync(struct thread_data *td)
25 static int fio_libaio_prep(struct thread_data *td, struct io_u *io_u)
27 if (io_u->ddir == DDIR_READ)
28 io_prep_pread(&io_u->iocb, td->fd, io_u->buf, io_u->buflen, io_u->offset);
30 io_prep_pwrite(&io_u->iocb, td->fd, io_u->buf, io_u->buflen, io_u->offset);
35 static struct io_u *fio_libaio_event(struct thread_data *td, int event)
37 struct libaio_data *ld = td->io_ops->data;
39 return ev_to_iou(ld->aio_events + event);
42 static int fio_libaio_getevents(struct thread_data *td, int min, int max,
45 struct libaio_data *ld = td->io_ops->data;
49 r = io_getevents(ld->aio_ctx, min, max, ld->aio_events, t);
53 } else if (r == -EINTR)
62 static int fio_libaio_queue(struct thread_data *td, struct io_u *io_u)
64 struct libaio_data *ld = td->io_ops->data;
65 struct iocb *iocb = &io_u->iocb;
69 ret = io_submit(ld->aio_ctx, 1, &iocb);
72 else if (ret == -EAGAIN)
74 else if (ret == -EINTR)
84 static int fio_libaio_cancel(struct thread_data *td, struct io_u *io_u)
86 struct libaio_data *ld = td->io_ops->data;
88 return io_cancel(ld->aio_ctx, &io_u->iocb, ld->aio_events);
91 static void fio_libaio_cleanup(struct thread_data *td)
93 struct libaio_data *ld = td->io_ops->data;
96 io_destroy(ld->aio_ctx);
101 td->io_ops->data = NULL;
105 static int fio_libaio_init(struct thread_data *td)
107 struct libaio_data *ld = malloc(sizeof(*ld));
109 memset(ld, 0, sizeof(*ld));
110 if (io_queue_init(td->iodepth, &ld->aio_ctx)) {
111 td_verror(td, errno);
115 ld->aio_events = malloc(td->iodepth * sizeof(struct io_event));
116 td->io_ops->data = ld;
120 struct ioengine_ops ioengine = {
122 .version = FIO_IOOPS_VERSION,
123 .init = fio_libaio_init,
124 .prep = fio_libaio_prep,
125 .queue = fio_libaio_queue,
126 .cancel = fio_libaio_cancel,
127 .getevents = fio_libaio_getevents,
128 .event = fio_libaio_event,
129 .cleanup = fio_libaio_cleanup,
130 .sync = fio_libaio_sync,