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 enum fio_q_status 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 unsigned int max_depth;
189 struct solarisaio_data *sd;
190 sd = calloc(1, sizeof(*sd));
192 max_depth = td->o.iodepth;
193 if (max_depth > MAXASYNCHIO) {
194 max_depth = MAXASYNCHIO;
195 log_info("fio: lower depth to %d due to OS constraints\n",
199 sd->aio_events = calloc(max_depth, sizeof(struct io_u *));
200 sd->max_depth = max_depth;
202 #ifdef USE_SIGNAL_COMPLETIONS
203 fio_solarisaio_init_sigio();
206 td->io_ops_data = sd;
210 static struct ioengine_ops ioengine = {
211 .name = "solarisaio",
212 .version = FIO_IOOPS_VERSION,
213 .init = fio_solarisaio_init,
214 .prep = fio_solarisaio_prep,
215 .queue = fio_solarisaio_queue,
216 .cancel = fio_solarisaio_cancel,
217 .getevents = fio_solarisaio_getevents,
218 .event = fio_solarisaio_event,
219 .cleanup = fio_solarisaio_cleanup,
220 .open_file = generic_open_file,
221 .close_file = generic_close_file,
222 .get_file_size = generic_get_file_size,
225 static void fio_init fio_solarisaio_register(void)
227 register_ioengine(&ioengine);
230 static void fio_exit fio_solarisaio_unregister(void)
232 unregister_ioengine(&ioengine);