blob: 723f310d6e1bcb8d28a2e6f637212dcfa489f5f8 [file] [log] [blame]
Jens Axboeebac4652005-12-08 15:25:21 +01001/*
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 Axboe5c4e1db2006-06-07 14:17:08 +020015#include <string.h>
Jens Axboe2866c822006-10-09 15:57:48 +020016#include <dlfcn.h>
Jens Axboeebac4652005-12-08 15:25:21 +010017#include "fio.h"
18#include "os.h"
19
Jens Axboe2866c822006-10-09 15:57:48 +020020struct ioengine_ops *load_ioengine(struct thread_data *td, char *name)
Jens Axboeebac4652005-12-08 15:25:21 +010021{
Jens Axboe2866c822006-10-09 15:57:48 +020022 char engine[16], engine_lib[256];
23 struct ioengine_ops *ops;
24 void *dlhandle;
Jens Axboeebac4652005-12-08 15:25:21 +010025
Jens Axboe2866c822006-10-09 15:57:48 +020026 strcpy(engine, name);
Jens Axboeebac4652005-12-08 15:25:21 +010027
28 /*
Jens Axboe2866c822006-10-09 15:57:48 +020029 * linux libaio has alias names, so convert to what we want
Jens Axboeebac4652005-12-08 15:25:21 +010030 */
Jens Axboe2866c822006-10-09 15:57:48 +020031 if (!strncmp(engine, "linuxaio", 8) || !strncmp(engine, "aio", 3))
32 strcpy(engine, "libaio");
33
34 sprintf(engine_lib, "/usr/local/lib/fio/fio-engine-%s.o", engine);
35 dlerror();
36 dlhandle = dlopen(engine_lib, RTLD_LAZY);
37 if (!dlhandle)
38 printf("bla: %s\n", dlerror());
39
40 ops = dlsym(dlhandle, "ioengine");
41 if (!ops)
42 printf("get ops failed\n");
43
44 ops->dlhandle = dlhandle;
45 return ops;
Jens Axboeebac4652005-12-08 15:25:21 +010046}
47
Jens Axboe2866c822006-10-09 15:57:48 +020048void close_ioengine(struct thread_data *td)
Jens Axboeebac4652005-12-08 15:25:21 +010049{
Jens Axboe2866c822006-10-09 15:57:48 +020050 if (td->io_ops->cleanup)
51 td->io_ops->cleanup(td);
Jens Axboeebac4652005-12-08 15:25:21 +010052
Jens Axboe2866c822006-10-09 15:57:48 +020053 dlclose(td->io_ops->dlhandle);
Jens Axboeb990b5c2006-09-14 09:48:22 +020054}