4 * IO engine using Glusterfs's gfapi async interface
13 static ulong cb_count = 0, issued = 0;
15 static struct io_u *fio_gf_event(struct thread_data *td, int event)
17 struct gf_data *gf_data = td->io_ops->data;
18 dprint(FD_IO, "%s\n", __FUNCTION__);
19 return gf_data->aio_events[event];
22 static int fio_gf_getevents(struct thread_data *td, unsigned int min,
23 unsigned int max, const struct timespec *t)
25 struct gf_data *g = td->io_ops->data;
26 unsigned int events = 0;
29 struct fio_gf_iou *io = NULL;
31 dprint(FD_IO, "%s\n", __FUNCTION__);
33 io_u_qiter(&td->io_u_all, io_u, i) {
34 if (!(io_u->flags & IO_U_F_FLIGHT))
37 io = (struct fio_gf_iou *)io_u->engine_data;
39 if (io && io->io_complete) {
41 g->aio_events[events] = io_u;
59 static void fio_gf_io_u_free(struct thread_data *td, struct io_u *io_u)
61 struct fio_gf_iou *io = io_u->engine_data;
64 if (io->io_complete) {
65 log_err("incomplete IO found.\n");
67 io_u->engine_data = NULL;
70 log_err("issued %lu finished %lu\n", issued, cb_count);
73 static int fio_gf_io_u_init(struct thread_data *td, struct io_u *io_u)
75 struct fio_gf_iou *io = NULL;
77 dprint(FD_FILE, "%s\n", __FUNCTION__);
79 if (!io_u->engine_data) {
80 io = malloc(sizeof(struct fio_gf_iou));
82 td_verror(td, errno, "malloc");
87 io_u->engine_data = io;
92 static void gf_async_cb(glfs_fd_t * fd, ssize_t ret, void *data)
94 struct io_u *io_u = (struct io_u *)data;
95 struct fio_gf_iou *iou = (struct fio_gf_iou *)io_u->engine_data;
97 dprint(FD_IO, "%s ret %lu\n", __FUNCTION__, ret);
102 static int fio_gf_async_queue(struct thread_data fio_unused * td,
105 struct gf_data *g = td->io_ops->data;
108 dprint(FD_IO, "%s op %s\n", __FUNCTION__,
109 io_u->ddir == DDIR_READ ? "read" : io_u->ddir ==
110 DDIR_WRITE ? "write" : io_u->ddir ==
111 DDIR_SYNC ? "sync" : "unknown");
113 fio_ro_check(td, io_u);
115 if (io_u->ddir == DDIR_READ)
116 r = glfs_pread_async(g->fd, io_u->xfer_buf, io_u->xfer_buflen,
117 io_u->offset, 0, gf_async_cb,
119 else if (io_u->ddir == DDIR_WRITE)
120 r = glfs_pwrite_async(g->fd, io_u->xfer_buf, io_u->xfer_buflen,
121 io_u->offset, 0, gf_async_cb,
123 #if defined(CONFIG_GF_TRIM)
124 else if (io_u->ddir == DDIR_TRIM)
125 r = glfs_discard_async(g->fd, io_u->offset, io_u->xfer_buflen,
128 else if (io_u->ddir == DDIR_SYNC) {
129 r = glfs_fsync_async(g->fd, gf_async_cb, (void *)io_u);
131 log_err("unsupported operation.\n");
132 io_u->error = -EINVAL;
136 log_err("glfs failed.\n");
145 td_verror(td, io_u->error, "xfer");
146 return FIO_Q_COMPLETED;
149 int fio_gf_async_setup(struct thread_data *td)
152 struct gf_data *g = NULL;
155 log_err("the async interface is still very experimental...\n");
157 r = fio_gf_setup(td);
161 td->o.use_thread = 1;
162 g = td->io_ops->data;
163 g->aio_events = malloc(td->o.iodepth * sizeof(struct io_u *));
164 if (!g->aio_events) {
170 memset(g->aio_events, 0, td->o.iodepth * sizeof(struct io_u *));
176 static int fio_gf_async_prep(struct thread_data *td, struct io_u *io_u)
178 dprint(FD_FILE, "%s\n", __FUNCTION__);
180 if (!ddir_rw(io_u->ddir))
186 static struct ioengine_ops ioengine = {
187 .name = "gfapi_async",
188 .version = FIO_IOOPS_VERSION,
189 .init = fio_gf_async_setup,
190 .cleanup = fio_gf_cleanup,
191 .prep = fio_gf_async_prep,
192 .queue = fio_gf_async_queue,
193 .open_file = fio_gf_open_file,
194 .close_file = fio_gf_close_file,
195 .unlink_file = fio_gf_unlink_file,
196 .get_file_size = fio_gf_get_file_size,
197 .getevents = fio_gf_getevents,
198 .event = fio_gf_event,
199 .io_u_init = fio_gf_io_u_init,
200 .io_u_free = fio_gf_io_u_free,
201 .options = gfapi_options,
202 .option_struct_size = sizeof(struct gf_options),
203 .flags = FIO_DISKLESSIO,
206 static void fio_init fio_gf_register(void)
208 register_ioengine(&ioengine);
211 static void fio_exit fio_gf_unregister(void)
213 unregister_ioengine(&ioengine);