[PATCH] Fix a bunch of bugs
[fio.git] / ioengines.c
index 723f310d6e1bcb8d28a2e6f637212dcfa489f5f8..abc385303d86c466ba34ed261a5624e2546e03de 100644 (file)
@@ -20,7 +20,7 @@
 struct ioengine_ops *load_ioengine(struct thread_data *td, char *name)
 {
        char engine[16], engine_lib[256];
-       struct ioengine_ops *ops;
+       struct ioengine_ops *ops, *ret;
        void *dlhandle;
 
        strcpy(engine, name);
@@ -31,18 +31,33 @@ struct ioengine_ops *load_ioengine(struct thread_data *td, char *name)
        if (!strncmp(engine, "linuxaio", 8) || !strncmp(engine, "aio", 3))
                strcpy(engine, "libaio");
 
-       sprintf(engine_lib, "/usr/local/lib/fio/fio-engine-%s.o", engine);
+       sprintf(engine_lib, "%s/lib/fio/fio-engine-%s.o", fio_inst_prefix, engine);
        dlerror();
        dlhandle = dlopen(engine_lib, RTLD_LAZY);
-       if (!dlhandle)
-               printf("bla: %s\n", dlerror());
+       if (!dlhandle) {
+               td_vmsg(td, -1, dlerror());
+               return NULL;
+       }
 
        ops = dlsym(dlhandle, "ioengine");
-       if (!ops)
-               printf("get ops failed\n");
+       if (!ops) {
+               td_vmsg(td, -1, dlerror());
+               dlclose(dlhandle);
+               return NULL;
+       }
 
-       ops->dlhandle = dlhandle;
-       return ops;
+       if (ops->version != FIO_IOOPS_VERSION) {
+               log_err("bad ioops version %d (want %d)\n", ops->version, FIO_IOOPS_VERSION);
+               dlclose(dlhandle);
+               return NULL;
+       }
+
+       ret = malloc(sizeof(*ret));
+       memcpy(ret, ops, sizeof(*ret));
+       ret->data = NULL;
+       ret->dlhandle = dlhandle;
+
+       return ret;
 }
 
 void close_ioengine(struct thread_data *td)
@@ -51,4 +66,6 @@ void close_ioengine(struct thread_data *td)
                td->io_ops->cleanup(td);
 
        dlclose(td->io_ops->dlhandle);
+       free(td->io_ops);
+       td->io_ops = NULL;
 }