2 * Native Solaris async IO engine
13 #include <sys/asynch.h>
15 struct solarisaio_data {
16 struct io_u **aio_events;
17 unsigned int aio_pending;
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 struct solarisaio_data *sd = td->io_ops_data;
33 io_u->resultp.aio_return = AIO_INPROGRESS;
34 io_u->engine_data = sd;
38 static void wait_for_event(struct timeval *tv)
40 struct solarisaio_data *sd;
45 if (res == (aio_result_t *) -1) {
49 log_err("fio: solarisaio got %d in aiowait\n", err);
56 io_u = container_of(res, struct io_u, resultp);
57 sd = io_u->engine_data;
59 if (io_u->resultp.aio_return >= 0) {
60 io_u->resid = io_u->xfer_buflen - io_u->resultp.aio_return;
63 io_u->error = io_u->resultp.aio_errno;
66 * For SIGIO, we need a write barrier between the two, so that
67 * the ->aio_pending store is seen after the ->aio_events store
69 sd->aio_events[sd->aio_pending] = io_u;
75 static int fio_solarisaio_getevents(struct thread_data *td, unsigned int min,
76 unsigned int max, const struct timespec *t)
78 struct solarisaio_data *sd = td->io_ops_data;
86 tv.tv_sec = t->tv_sec;
87 tv.tv_usec = t->tv_nsec / 1000;
90 while (sd->aio_pending < min)
94 * should be OK without locking, as int operations should be atomic
96 ret = sd->aio_pending;
97 sd->aio_pending -= ret;
101 static struct io_u *fio_solarisaio_event(struct thread_data *td, int event)
103 struct solarisaio_data *sd = td->io_ops_data;
105 return sd->aio_events[event];
108 static int fio_solarisaio_queue(struct thread_data fio_unused *td,
111 struct solarisaio_data *sd = td->io_ops_data;
112 struct fio_file *f = io_u->file;
116 fio_ro_check(td, io_u);
118 if (io_u->ddir == DDIR_SYNC) {
121 if (fsync(f->fd) < 0)
124 return FIO_Q_COMPLETED;
127 if (io_u->ddir == DDIR_DATASYNC) {
130 if (fdatasync(f->fd) < 0)
133 return FIO_Q_COMPLETED;
136 if (sd->nr == sd->max_depth)
140 if (io_u->ddir == DDIR_READ)
141 ret = aioread(f->fd, io_u->xfer_buf, io_u->xfer_buflen, off,
142 SEEK_SET, &io_u->resultp);
144 ret = aiowrite(f->fd, io_u->xfer_buf, io_u->xfer_buflen, off,
145 SEEK_SET, &io_u->resultp);
148 td_verror(td, io_u->error, "xfer");
149 return FIO_Q_COMPLETED;
156 static void fio_solarisaio_cleanup(struct thread_data *td)
158 struct solarisaio_data *sd = td->io_ops_data;
161 free(sd->aio_events);
167 * Set USE_SIGNAL_COMPLETIONS to use SIGIO as completion events.
169 #ifdef USE_SIGNAL_COMPLETIONS
170 static void fio_solarisaio_sigio(int sig)
172 wait_for_event(NULL);
175 static void fio_solarisaio_init_sigio(void)
177 struct sigaction act;
179 memset(&act, 0, sizeof(act));
180 act.sa_handler = fio_solarisaio_sigio;
181 act.sa_flags = SA_RESTART;
182 sigaction(SIGIO, &act, NULL);
186 static int fio_solarisaio_init(struct thread_data *td)
188 struct solarisaio_data *sd = malloc(sizeof(*sd));
189 unsigned int max_depth;
191 max_depth = td->o.iodepth;
192 if (max_depth > MAXASYNCHIO) {
193 max_depth = MAXASYNCHIO;
194 log_info("fio: lower depth to %d due to OS constraints\n",
198 memset(sd, 0, sizeof(*sd));
199 sd->aio_events = malloc(max_depth * sizeof(struct io_u *));
200 memset(sd->aio_events, 0, max_depth * sizeof(struct io_u *));
201 sd->max_depth = max_depth;
203 #ifdef USE_SIGNAL_COMPLETIONS
204 fio_solarisaio_init_sigio();
207 td->io_ops_data = sd;
211 static struct ioengine_ops ioengine = {
212 .name = "solarisaio",
213 .version = FIO_IOOPS_VERSION,
214 .init = fio_solarisaio_init,
215 .prep = fio_solarisaio_prep,
216 .queue = fio_solarisaio_queue,
217 .cancel = fio_solarisaio_cancel,
218 .getevents = fio_solarisaio_getevents,
219 .event = fio_solarisaio_event,
220 .cleanup = fio_solarisaio_cleanup,
221 .open_file = generic_open_file,
222 .close_file = generic_close_file,
223 .get_file_size = generic_get_file_size,
226 static void fio_init fio_solarisaio_register(void)
228 register_ioengine(&ioengine);
231 static void fio_exit fio_solarisaio_unregister(void)
233 unregister_ioengine(&ioengine);