2 * The io parts of the fio tool, includes workers for sync and mmap'ed
3 * io, as well as both posix and linux libaio support.
5 * sync io is implemented on top of aio.
7 * This is not really specific to fio, if the get_io_u/put_io_u and
8 * structures was pulled into this as well it would be a perfectly
9 * generic io engine that could be used for other projects.
21 static int check_engine_ops(struct ioengine_ops *ops)
24 * cpu thread doesn't need to provide anything
26 if (ops->flags & FIO_CPUIO)
30 log_err("%s: no event handler)\n", ops->name);
33 if (!ops->getevents) {
34 log_err("%s: no getevents handler)\n", ops->name);
38 log_err("%s: no queue handler)\n", ops->name);
45 struct ioengine_ops *load_ioengine(struct thread_data *td, const char *name)
47 char engine[16], engine_lib[256];
48 struct ioengine_ops *ops, *ret;
51 strncpy(engine, name, sizeof(engine) - 1);
54 * linux libaio has alias names, so convert to what we want
56 if (!strncmp(engine, "linuxaio", 8) || !strncmp(engine, "aio", 3))
57 strcpy(engine, "libaio");
59 sprintf(engine_lib, "%s/lib/fio/fio-engine-%s.o", fio_inst_prefix, engine);
61 dlhandle = dlopen(engine_lib, RTLD_LAZY);
63 td_vmsg(td, -1, dlerror());
67 ops = dlsym(dlhandle, "ioengine");
69 td_vmsg(td, -1, dlerror());
74 if (ops->version != FIO_IOOPS_VERSION) {
75 log_err("bad ioops version %d (want %d)\n", ops->version, FIO_IOOPS_VERSION);
81 * Check that the required methods are there.
83 if (check_engine_ops(ops)) {
88 ret = malloc(sizeof(*ret));
89 memcpy(ret, ops, sizeof(*ret));
91 ret->dlhandle = dlhandle;
96 void close_ioengine(struct thread_data *td)
98 if (td->io_ops->cleanup)
99 td->io_ops->cleanup(td);
101 dlclose(td->io_ops->dlhandle);
106 int td_io_prep(struct thread_data *td, struct io_u *io_u)
108 if (td->io_ops->prep && td->io_ops->prep(td, io_u))
114 int td_io_getevents(struct thread_data *td, int min, int max,
117 return td->io_ops->getevents(td, min, max, t);
120 int td_io_queue(struct thread_data *td, struct io_u *io_u)
122 gettimeofday(&io_u->issue_time, NULL);
124 return td->io_ops->queue(td, io_u);
127 int td_io_init(struct thread_data *td)
129 if (td->io_ops->init)
130 return td->io_ops->init(td);