Commit | Line | Data |
---|---|---|
ebac4655 JA |
1 | /* |
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. | |
4 | * | |
5 | * sync io is implemented on top of aio. | |
6 | * | |
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. | |
10 | * | |
11 | */ | |
12 | #include <stdio.h> | |
13 | #include <stdlib.h> | |
14 | #include <unistd.h> | |
5c4e1dbc | 15 | #include <string.h> |
2866c82d | 16 | #include <dlfcn.h> |
ebac4655 JA |
17 | #include "fio.h" |
18 | #include "os.h" | |
19 | ||
2866c82d | 20 | struct ioengine_ops *load_ioengine(struct thread_data *td, char *name) |
ebac4655 | 21 | { |
2866c82d JA |
22 | char engine[16], engine_lib[256]; |
23 | struct ioengine_ops *ops; | |
24 | void *dlhandle; | |
ebac4655 | 25 | |
2866c82d | 26 | strcpy(engine, name); |
ebac4655 JA |
27 | |
28 | /* | |
2866c82d | 29 | * linux libaio has alias names, so convert to what we want |
ebac4655 | 30 | */ |
2866c82d JA |
31 | if (!strncmp(engine, "linuxaio", 8) || !strncmp(engine, "aio", 3)) |
32 | strcpy(engine, "libaio"); | |
ebac4655 | 33 | |
2866c82d JA |
34 | sprintf(engine_lib, "/usr/local/lib/fio/fio-engine-%s.o", engine); |
35 | dlerror(); | |
36 | dlhandle = dlopen(engine_lib, RTLD_LAZY); | |
d4dbaaa8 JA |
37 | if (!dlhandle) { |
38 | td_vmsg(td, -1, dlerror()); | |
39 | return NULL; | |
40 | } | |
8756e4d4 | 41 | |
2866c82d | 42 | ops = dlsym(dlhandle, "ioengine"); |
d4dbaaa8 JA |
43 | if (!ops) { |
44 | td_vmsg(td, -1, dlerror()); | |
45 | dlclose(dlhandle); | |
46 | return NULL; | |
47 | } | |
8756e4d4 | 48 | |
b902ceb5 JA |
49 | if (ops->version != FIO_IOOPS_VERSION) { |
50 | log_err("bad ioops version %d (want %d)\n", ops->version, FIO_IOOPS_VERSION); | |
51 | dlclose(dlhandle); | |
52 | return NULL; | |
53 | } | |
54 | ||
2866c82d JA |
55 | ops->dlhandle = dlhandle; |
56 | return ops; | |
8756e4d4 JA |
57 | } |
58 | ||
2866c82d | 59 | void close_ioengine(struct thread_data *td) |
8756e4d4 | 60 | { |
2866c82d JA |
61 | if (td->io_ops->cleanup) |
62 | td->io_ops->cleanup(td); | |
b990b5c0 | 63 | |
2866c82d | 64 | dlclose(td->io_ops->dlhandle); |
b990b5c0 | 65 | } |