add __load_ioengine() to separate ioengine loading from td context
[fio.git] / ioengines.c
index 6e135af42c4e8ecccba555b18b7e1fbb13074ac2..e78b4f79acadc87a30808e54a7e78b55155318f6 100644 (file)
@@ -123,13 +123,10 @@ static struct ioengine_ops *dlopen_ioengine(struct thread_data *td,
        return ops;
 }
 
-struct ioengine_ops *load_ioengine(struct thread_data *td, const char *name)
+static struct ioengine_ops *__load_ioengine(const char *name)
 {
-       struct ioengine_ops *ops;
        char engine[64];
 
-       dprint(FD_IO, "load ioengine %s\n", name);
-
        engine[sizeof(engine) - 1] = '\0';
        strncpy(engine, name, sizeof(engine) - 1);
 
@@ -139,9 +136,23 @@ struct ioengine_ops *load_ioengine(struct thread_data *td, const char *name)
        if (!strncmp(engine, "linuxaio", 8) || !strncmp(engine, "aio", 3))
                strcpy(engine, "libaio");
 
-       ops = find_ioengine(engine);
-       if (!ops)
+       dprint(FD_IO, "load ioengine %s\n", engine);
+       return find_ioengine(engine);
+}
+
+struct ioengine_ops *load_ioengine(struct thread_data *td)
+{
+       struct ioengine_ops *ops = NULL;
+       const char *name = NULL;
+
+       if (strcmp(td->o.ioengine, "external")) {
+               name = td->o.ioengine;
+               ops = __load_ioengine(name);
+       } else if (td->o.ioengine_so_path) {
+               name = td->o.ioengine_so_path;
                ops = dlopen_ioengine(td, name);
+       } else
+               log_err("fio: missing external ioengine path\n");
 
        if (!ops) {
                log_err("fio: engine %s not loadable\n", name);
@@ -495,29 +506,8 @@ int td_io_open_file(struct thread_data *td, struct fio_file *f)
        }
 #endif
 
-#ifdef FIO_OS_DIRECTIO
-       /*
-        * Some OS's have a distinct call to mark the file non-buffered,
-        * instead of using O_DIRECT (Solaris)
-        */
-       if (td->o.odirect) {
-               int ret = fio_set_odirect(f->fd);
-
-               if (ret) {
-                       td_verror(td, ret, "fio_set_odirect");
-#if defined(__sun__)
-                       if (ret == ENOTTY) { /* ENOTTY suggests RAW device or ZFS */
-                               log_err("fio: doing directIO to RAW devices or ZFS not supported\n");
-                       } else {
-                               log_err("fio: the file system does not seem to support direct IO\n");
-                       }
-#else
-                       log_err("fio: the file system does not seem to support direct IO\n");
-#endif
-                       goto err;
-               }
-       }
-#endif
+       if (td->o.odirect && !OS_O_DIRECT && fio_set_directio(td, f))
+               goto err;
 
 done:
        log_file(td, f, FIO_LOG_OPEN_FILE);
@@ -573,7 +563,6 @@ int td_io_get_file_size(struct thread_data *td, struct fio_file *f)
 int fio_show_ioengine_help(const char *engine)
 {
        struct flist_head *entry;
-       struct thread_data td;
        struct ioengine_ops *io_ops;
        char *sep;
        int ret = 1;
@@ -592,9 +581,7 @@ int fio_show_ioengine_help(const char *engine)
                sep++;
        }
 
-       memset(&td, 0, sizeof(td));
-
-       io_ops = load_ioengine(&td, engine);
+       io_ops = __load_ioengine(engine);
        if (!io_ops) {
                log_info("IO engine %s not found\n", engine);
                return 1;
@@ -605,7 +592,5 @@ int fio_show_ioengine_help(const char *engine)
        else
                log_info("IO engine %s has no options\n", io_ops->name);
 
-       free_ioengine(&td);
-
        return ret;
 }