2 * Native Solaris async IO engine
12 #ifdef FIO_HAVE_SOLARISAIO
14 #include <sys/asynch.h>
16 struct solarisaio_data {
17 struct io_u **aio_events;
19 unsigned int max_depth;
22 static int fio_solarisaio_cancel(struct thread_data fio_unused *td,
25 return aiocancel(&io_u->resultp);
28 static int fio_solarisaio_prep(struct thread_data fio_unused *td,
31 io_u->resultp.aio_return = AIO_INPROGRESS;
35 static int fio_solarisaio_getevents(struct thread_data *td, unsigned int min,
36 unsigned int max, struct timespec *t)
38 struct solarisaio_data *sd = td->io_ops->data;
51 tv.tv_sec = t->tv_sec;
52 tv.tv_usec = t->tv_nsec / 1000;
57 io_u = container_of(p, struct io_u, resultp);
59 sd->aio_events[r++] = io_u;
62 if (io_u->resultp.aio_return >= 0) {
63 io_u->resid = io_u->xfer_buflen
64 - io_u->resultp.aio_return;
67 io_u->error = io_u->resultp.aio_return;
74 static struct io_u *fio_solarisaio_event(struct thread_data *td, int event)
76 struct solarisaio_data *sd = td->io_ops->data;
78 return sd->aio_events[event];
81 static int fio_solarisaio_queue(struct thread_data fio_unused *td,
84 struct solarisaio_data *sd = td->io_ops->data;
85 struct fio_file *f = io_u->file;
89 fio_ro_check(td, io_u);
91 if (io_u->ddir == DDIR_SYNC) {
97 return FIO_Q_COMPLETED;
100 if (sd->nr == sd->max_depth)
104 if (io_u->ddir == DDIR_READ)
105 ret = aioread(f->fd, io_u->xfer_buf, io_u->xfer_buflen, off,
106 SEEK_SET, &io_u->resultp);
108 ret = aiowrite(f->fd, io_u->xfer_buf, io_u->xfer_buflen, off,
109 SEEK_SET, &io_u->resultp);
112 td_verror(td, io_u->error, "xfer");
113 return FIO_Q_COMPLETED;
120 static void fio_solarisaio_cleanup(struct thread_data *td)
122 struct solarisaio_data *sd = td->io_ops->data;
125 free(sd->aio_events);
130 static int fio_solarisaio_init(struct thread_data *td)
132 struct solarisaio_data *sd = malloc(sizeof(*sd));
133 unsigned int max_depth;
135 max_depth = td->o.iodepth;
136 if (max_depth > MAXASYNCHIO) {
137 max_depth = MAXASYNCHIO;
138 log_info("fio: lower depth to %d due to OS constraints\n",
142 memset(sd, 0, sizeof(*sd));
143 sd->aio_events = malloc(max_depth * sizeof(struct io_u *));
144 memset(sd->aio_events, 0, max_depth * sizeof(struct io_u *));
145 sd->max_depth = max_depth;
147 td->io_ops->data = sd;
151 static struct ioengine_ops ioengine = {
152 .name = "solarisaio",
153 .version = FIO_IOOPS_VERSION,
154 .init = fio_solarisaio_init,
155 .prep = fio_solarisaio_prep,
156 .queue = fio_solarisaio_queue,
157 .cancel = fio_solarisaio_cancel,
158 .getevents = fio_solarisaio_getevents,
159 .event = fio_solarisaio_event,
160 .cleanup = fio_solarisaio_cleanup,
161 .open_file = generic_open_file,
162 .close_file = generic_close_file,
165 #else /* FIO_HAVE_SOLARISAIO */
168 * When we have a proper configure system in place, we simply wont build
169 * and install this io engine. For now install a crippled version that
170 * just complains and fails to load.
172 static int fio_solarisaio_init(struct thread_data fio_unused *td)
174 fprintf(stderr, "fio: solarisaio not available\n");
178 static struct ioengine_ops ioengine = {
179 .name = "solarisaio",
180 .version = FIO_IOOPS_VERSION,
181 .init = fio_solarisaio_init,
186 static void fio_init fio_solarisaio_register(void)
188 register_ioengine(&ioengine);
191 static void fio_exit fio_solarisaio_unregister(void)
193 unregister_ioengine(&ioengine);