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 queue handler\n", ops->name);
42 * sync engines only need a ->queue()
44 if (ops->flags & FIO_SYNCIO)
48 log_err("%s: no event handler\n", ops->name);
51 if (!ops->getevents) {
52 log_err("%s: no getevents handler\n", ops->name);
56 log_err("%s: no queue handler\n", ops->name);
63 void unregister_ioengine(struct ioengine_ops *ops)
66 INIT_LIST_HEAD(&ops->list);
69 void register_ioengine(struct ioengine_ops *ops)
71 INIT_LIST_HEAD(&ops->list);
72 list_add_tail(&ops->list, &engine_list);
75 static struct ioengine_ops *find_ioengine(const char *name)
77 struct ioengine_ops *ops;
78 struct list_head *entry;
81 strncpy(engine, name, sizeof(engine) - 1);
83 if (!strncmp(engine, "linuxaio", 8) || !strncmp(engine, "aio", 3))
84 strcpy(engine, "libaio");
86 list_for_each(entry, &engine_list) {
87 ops = list_entry(entry, struct ioengine_ops, list);
88 if (!strcmp(engine, ops->name))
95 static struct ioengine_ops *dlopen_ioengine(struct thread_data *td,
96 const char *engine_lib)
98 struct ioengine_ops *ops;
102 dlhandle = dlopen(engine_lib, RTLD_LAZY);
104 td_vmsg(td, -1, dlerror());
109 * Unlike the included modules, external engines should have a
110 * non-static ioengine structure that we can reference.
112 ops = dlsym(dlhandle, "ioengine");
114 td_vmsg(td, -1, dlerror());
119 ops->dlhandle = dlhandle;
123 struct ioengine_ops *load_ioengine(struct thread_data *td, const char *name)
125 struct ioengine_ops *ops, *ret;
128 strncpy(engine, name, sizeof(engine) - 1);
131 * linux libaio has alias names, so convert to what we want
133 if (!strncmp(engine, "linuxaio", 8) || !strncmp(engine, "aio", 3))
134 strcpy(engine, "libaio");
136 ops = find_ioengine(engine);
138 ops = dlopen_ioengine(td, name);
141 log_err("fio: engine %s not loadable\n", name);
146 * Check that the required methods are there.
148 if (check_engine_ops(ops))
151 ret = malloc(sizeof(*ret));
152 memcpy(ret, ops, sizeof(*ret));
158 void close_ioengine(struct thread_data *td)
160 if (td->io_ops->cleanup)
161 td->io_ops->cleanup(td);
163 if (td->io_ops->dlhandle)
164 dlclose(td->io_ops->dlhandle);
170 int td_io_prep(struct thread_data *td, struct io_u *io_u)
172 if (td->io_ops->prep)
173 return td->io_ops->prep(td, io_u);
178 int td_io_getevents(struct thread_data *td, int min, int max,
181 if (td->io_ops->getevents)
182 return td->io_ops->getevents(td, min, max, t);
187 int td_io_queue(struct thread_data *td, struct io_u *io_u)
191 if (td->io_ops->flags & FIO_SYNCIO)
192 fio_gettime(&io_u->issue_time, NULL);
194 if (io_u->ddir != DDIR_SYNC)
195 td->io_issues[io_u->ddir]++;
197 ret = td->io_ops->queue(td, io_u);
199 if ((td->io_ops->flags & FIO_SYNCIO) == 0)
200 fio_gettime(&io_u->issue_time, NULL);
205 int td_io_init(struct thread_data *td)
207 if (td->io_ops->init)
208 return td->io_ops->init(td);
213 int td_io_commit(struct thread_data *td)
215 if (td->io_ops->commit)
216 return td->io_ops->commit(td);