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 LIST_HEAD(engine_list);
23 static int check_engine_ops(struct ioengine_ops *ops)
25 if (ops->version != FIO_IOOPS_VERSION) {
26 log_err("bad ioops version %d (want %d)\n", ops->version, FIO_IOOPS_VERSION);
31 * cpu thread doesn't need to provide anything
33 if (ops->flags & FIO_CPUIO)
37 log_err("%s: no event handler)\n", ops->name);
40 if (!ops->getevents) {
41 log_err("%s: no getevents handler)\n", ops->name);
45 log_err("%s: no queue handler)\n", ops->name);
52 void unregister_ioengine(struct ioengine_ops *ops)
55 INIT_LIST_HEAD(&ops->list);
58 int register_ioengine(struct ioengine_ops *ops)
60 if (check_engine_ops(ops))
63 INIT_LIST_HEAD(&ops->list);
64 list_add_tail(&ops->list, &engine_list);
68 static struct ioengine_ops *find_ioengine(const char *name)
70 struct ioengine_ops *ops;
71 struct list_head *entry;
74 strncpy(engine, name, sizeof(engine) - 1);
76 if (!strncmp(engine, "linuxaio", 8) || !strncmp(engine, "aio", 3))
77 strcpy(engine, "libaio");
79 list_for_each(entry, &engine_list) {
80 ops = list_entry(entry, struct ioengine_ops, list);
81 if (!strcmp(engine, ops->name))
88 static struct ioengine_ops *dlopen_ioengine(struct thread_data *td,
89 const char *engine_lib)
91 struct ioengine_ops *ops;
95 dlhandle = dlopen(engine_lib, RTLD_LAZY);
97 td_vmsg(td, -1, dlerror());
102 * Unlike the included modules, external engines should have a
103 * non-static ioengine structure that we can reference.
105 ops = dlsym(dlhandle, "ioengine");
107 td_vmsg(td, -1, dlerror());
112 ops->dlhandle = dlhandle;
116 struct ioengine_ops *load_ioengine(struct thread_data *td, const char *name)
118 struct ioengine_ops *ops, *ret;
121 strncpy(engine, name, sizeof(engine) - 1);
124 * linux libaio has alias names, so convert to what we want
126 if (!strncmp(engine, "linuxaio", 8) || !strncmp(engine, "aio", 3))
127 strcpy(engine, "libaio");
129 ops = find_ioengine(engine);
131 ops = dlopen_ioengine(td, name);
134 log_err("fio: engine %s not loadable\n", name);
139 * Check that the required methods are there.
141 if (check_engine_ops(ops))
144 ret = malloc(sizeof(*ret));
145 memcpy(ret, ops, sizeof(*ret));
151 void close_ioengine(struct thread_data *td)
153 if (td->io_ops->cleanup)
154 td->io_ops->cleanup(td);
156 if (td->io_ops->dlhandle)
157 dlclose(td->io_ops->dlhandle);
163 int td_io_prep(struct thread_data *td, struct io_u *io_u)
165 if (td->io_ops->prep && td->io_ops->prep(td, io_u))
171 int td_io_getevents(struct thread_data *td, int min, int max,
174 return td->io_ops->getevents(td, min, max, t);
177 int td_io_queue(struct thread_data *td, struct io_u *io_u)
179 fio_gettime(&io_u->issue_time, NULL);
181 return td->io_ops->queue(td, io_u);
184 int td_io_init(struct thread_data *td)
186 if (td->io_ops->init)
187 return td->io_ops->init(td);