Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 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> |
Jens Axboe | 5c4e1db | 2006-06-07 14:17:08 +0200 | [diff] [blame] | 15 | #include <string.h> |
Jens Axboe | 2866c82 | 2006-10-09 15:57:48 +0200 | [diff] [blame] | 16 | #include <dlfcn.h> |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 17 | #include "fio.h" |
| 18 | #include "os.h" |
| 19 | |
Jens Axboe | 2866c82 | 2006-10-09 15:57:48 +0200 | [diff] [blame] | 20 | struct ioengine_ops *load_ioengine(struct thread_data *td, char *name) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 21 | { |
Jens Axboe | 2866c82 | 2006-10-09 15:57:48 +0200 | [diff] [blame] | 22 | char engine[16], engine_lib[256]; |
Jens Axboe | 8458500 | 2006-10-19 20:26:22 +0200 | [diff] [blame] | 23 | struct ioengine_ops *ops, *ret; |
Jens Axboe | 2866c82 | 2006-10-09 15:57:48 +0200 | [diff] [blame] | 24 | void *dlhandle; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 25 | |
Jens Axboe | 2866c82 | 2006-10-09 15:57:48 +0200 | [diff] [blame] | 26 | strcpy(engine, name); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 27 | |
| 28 | /* |
Jens Axboe | 2866c82 | 2006-10-09 15:57:48 +0200 | [diff] [blame] | 29 | * linux libaio has alias names, so convert to what we want |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 30 | */ |
Jens Axboe | 2866c82 | 2006-10-09 15:57:48 +0200 | [diff] [blame] | 31 | if (!strncmp(engine, "linuxaio", 8) || !strncmp(engine, "aio", 3)) |
| 32 | strcpy(engine, "libaio"); |
| 33 | |
Jens Axboe | c1d5725 | 2006-10-09 19:56:04 +0200 | [diff] [blame] | 34 | sprintf(engine_lib, "%s/lib/fio/fio-engine-%s.o", fio_inst_prefix, engine); |
Jens Axboe | 2866c82 | 2006-10-09 15:57:48 +0200 | [diff] [blame] | 35 | dlerror(); |
| 36 | dlhandle = dlopen(engine_lib, RTLD_LAZY); |
Jens Axboe | d4dbaaa | 2006-10-09 16:01:27 +0200 | [diff] [blame] | 37 | if (!dlhandle) { |
| 38 | td_vmsg(td, -1, dlerror()); |
| 39 | return NULL; |
| 40 | } |
Jens Axboe | 2866c82 | 2006-10-09 15:57:48 +0200 | [diff] [blame] | 41 | |
| 42 | ops = dlsym(dlhandle, "ioengine"); |
Jens Axboe | d4dbaaa | 2006-10-09 16:01:27 +0200 | [diff] [blame] | 43 | if (!ops) { |
| 44 | td_vmsg(td, -1, dlerror()); |
| 45 | dlclose(dlhandle); |
| 46 | return NULL; |
| 47 | } |
Jens Axboe | 2866c82 | 2006-10-09 15:57:48 +0200 | [diff] [blame] | 48 | |
Jens Axboe | b902ceb | 2006-10-09 16:11:45 +0200 | [diff] [blame] | 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 | |
Jens Axboe | 8458500 | 2006-10-19 20:26:22 +0200 | [diff] [blame] | 55 | ret = malloc(sizeof(*ret)); |
| 56 | memcpy(ret, ops, sizeof(*ret)); |
| 57 | ret->data = NULL; |
| 58 | ret->dlhandle = dlhandle; |
| 59 | |
| 60 | return ret; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 61 | } |
| 62 | |
Jens Axboe | 2866c82 | 2006-10-09 15:57:48 +0200 | [diff] [blame] | 63 | void close_ioengine(struct thread_data *td) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 64 | { |
Jens Axboe | 2866c82 | 2006-10-09 15:57:48 +0200 | [diff] [blame] | 65 | if (td->io_ops->cleanup) |
| 66 | td->io_ops->cleanup(td); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 67 | |
Jens Axboe | 2866c82 | 2006-10-09 15:57:48 +0200 | [diff] [blame] | 68 | dlclose(td->io_ops->dlhandle); |
Jens Axboe | 8458500 | 2006-10-19 20:26:22 +0200 | [diff] [blame] | 69 | free(td->io_ops); |
| 70 | td->io_ops = NULL; |
Jens Axboe | b990b5c | 2006-09-14 09:48:22 +0200 | [diff] [blame] | 71 | } |