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;
56 if (p == (aio_result_t *) -1) {
61 td_verror(td, err, "aiowait");
63 } else if (p != NULL) {
64 io_u = container_of(p, struct io_u, resultp);
66 sd->aio_events[r++] = io_u;
69 if (io_u->resultp.aio_return >= 0) {
70 io_u->resid = io_u->xfer_buflen
71 - io_u->resultp.aio_return;
74 io_u->error = io_u->resultp.aio_return;
81 static struct io_u *fio_solarisaio_event(struct thread_data *td, int event)
83 struct solarisaio_data *sd = td->io_ops->data;
85 return sd->aio_events[event];
88 static int fio_solarisaio_queue(struct thread_data fio_unused *td,
91 struct solarisaio_data *sd = td->io_ops->data;
92 struct fio_file *f = io_u->file;
96 fio_ro_check(td, io_u);
98 if (io_u->ddir == DDIR_SYNC) {
101 if (fsync(f->fd) < 0)
104 return FIO_Q_COMPLETED;
107 if (sd->nr == sd->max_depth)
111 if (io_u->ddir == DDIR_READ)
112 ret = aioread(f->fd, io_u->xfer_buf, io_u->xfer_buflen, off,
113 SEEK_SET, &io_u->resultp);
115 ret = aiowrite(f->fd, io_u->xfer_buf, io_u->xfer_buflen, off,
116 SEEK_SET, &io_u->resultp);
119 td_verror(td, io_u->error, "xfer");
120 return FIO_Q_COMPLETED;
127 static void fio_solarisaio_cleanup(struct thread_data *td)
129 struct solarisaio_data *sd = td->io_ops->data;
132 free(sd->aio_events);
137 static int fio_solarisaio_init(struct thread_data *td)
139 struct solarisaio_data *sd = malloc(sizeof(*sd));
140 unsigned int max_depth;
142 max_depth = td->o.iodepth;
143 if (max_depth > MAXASYNCHIO) {
144 max_depth = MAXASYNCHIO;
145 log_info("fio: lower depth to %d due to OS constraints\n",
149 memset(sd, 0, sizeof(*sd));
150 sd->aio_events = malloc(max_depth * sizeof(struct io_u *));
151 memset(sd->aio_events, 0, max_depth * sizeof(struct io_u *));
152 sd->max_depth = max_depth;
154 td->io_ops->data = sd;
158 static struct ioengine_ops ioengine = {
159 .name = "solarisaio",
160 .version = FIO_IOOPS_VERSION,
161 .init = fio_solarisaio_init,
162 .prep = fio_solarisaio_prep,
163 .queue = fio_solarisaio_queue,
164 .cancel = fio_solarisaio_cancel,
165 .getevents = fio_solarisaio_getevents,
166 .event = fio_solarisaio_event,
167 .cleanup = fio_solarisaio_cleanup,
168 .open_file = generic_open_file,
169 .close_file = generic_close_file,
172 #else /* FIO_HAVE_SOLARISAIO */
175 * When we have a proper configure system in place, we simply wont build
176 * and install this io engine. For now install a crippled version that
177 * just complains and fails to load.
179 static int fio_solarisaio_init(struct thread_data fio_unused *td)
181 fprintf(stderr, "fio: solarisaio not available\n");
185 static struct ioengine_ops ioengine = {
186 .name = "solarisaio",
187 .version = FIO_IOOPS_VERSION,
188 .init = fio_solarisaio_init,
193 static void fio_init fio_solarisaio_register(void)
195 register_ioengine(&ioengine);
198 static void fio_exit fio_solarisaio_unregister(void)
200 unregister_ioengine(&ioengine);