Make sure each job loads a private io engine
authorJens Axboe <jens.axboe@oracle.com>
Fri, 9 Mar 2007 08:00:06 +0000 (09:00 +0100)
committerJens Axboe <jens.axboe@oracle.com>
Fri, 9 Mar 2007 08:00:06 +0000 (09:00 +0100)
Threads got it shared, breaks for obvious reasons. Also gets rid
of the free hack in ioengine unload.

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
fio.h
init.c
ioengines.c

diff --git a/fio.h b/fio.h
index 12cf3c9a686b4a389cacd4da13736d0a0d0d8bf8..c20f21ba2fbca6625c8f222b69e6d38d901c51d5 100644 (file)
--- a/fio.h
+++ b/fio.h
@@ -307,6 +307,7 @@ struct thread_data {
        char *name;
        char *directory;
        char *filename;
        char *name;
        char *directory;
        char *filename;
+       char *ioengine;
        char verror[128];
        pthread_t thread;
        int thread_number;
        char verror[128];
        pthread_t thread;
        int thread_number;
diff --git a/init.c b/init.c
index c75bed21d670b29fae359c917af5aaed12331334..56df3c7582e91ce2f419709672d550d1b3d5173c 100644 (file)
--- a/init.c
+++ b/init.c
@@ -22,7 +22,6 @@
 
 #define td_var_offset(var)     ((size_t) &((struct thread_data *)0)->var)
 
 
 #define td_var_offset(var)     ((size_t) &((struct thread_data *)0)->var)
 
-static int str_ioengine_cb(void *, const char *);
 static int str_mem_cb(void *, const char *);
 static int str_lockmem_cb(void *, unsigned long *);
 #ifdef FIO_HAVE_IOPRIO
 static int str_mem_cb(void *, const char *);
 static int str_lockmem_cb(void *, unsigned long *);
 #ifdef FIO_HAVE_IOPRIO
@@ -80,8 +79,8 @@ static struct fio_option options[] = {
        },
        {
                .name   = "ioengine",
        },
        {
                .name   = "ioengine",
-               .type   = FIO_OPT_STR,
-               .cb     = str_ioengine_cb,
+               .type   = FIO_OPT_STR_STORE,
+               .off1   = td_var_offset(ioengine),
                .help   = "IO engine to use",
                .def    = "sync",
                .posval = {
                .help   = "IO engine to use",
                .def    = "sync",
                .posval = {
@@ -774,6 +773,20 @@ static char *to_kmg(unsigned int val)
        return buf;
 }
 
        return buf;
 }
 
+/* External engines are specified by "external:name.o") */
+static const char *get_engine_name(const char *str)
+{
+       char *p = strstr(str, ":");
+
+       if (!p)
+               return str;
+
+       p++;
+       strip_blank_front(&p);
+       strip_blank_end(p);
+       return p;
+}
+
 /*
  * Adds a job to the list of things todo. Sanitizes the various options
  * to make sure we don't have conflicts, and initializes various
 /*
  * Adds a job to the list of things todo. Sanitizes the various options
  * to make sure we don't have conflicts, and initializes various
@@ -786,6 +799,7 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num)
        struct stat sb;
        int numjobs, i;
        struct fio_file *f;
        struct stat sb;
        int numjobs, i;
        struct fio_file *f;
+       const char *engine;
 
        /*
         * the def_thread is just for options, it's not a real job
 
        /*
         * the def_thread is just for options, it's not a real job
@@ -793,7 +807,12 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num)
        if (td == &def_thread)
                return 0;
 
        if (td == &def_thread)
                return 0;
 
-       assert(td->io_ops);
+       engine = get_engine_name(td->ioengine);
+       td->io_ops = load_ioengine(td, engine);
+       if (!td->io_ops) {
+               log_err("fio: failed to load engine %s\n", engine);
+               return 1;
+       }
 
        if (td->odirect)
                td->io_ops->flags |= FIO_RAWIO;
 
        if (td->odirect)
                td->io_ops->flags |= FIO_RAWIO;
@@ -1043,32 +1062,6 @@ static int str_mem_cb(void *data, const char *mem)
        return 0;
 }
 
        return 0;
 }
 
-/* External engines are specified by "external:name.o") */
-static const char *get_engine_name(const char *str)
-{
-       char *p = strstr(str, ":");
-
-       if (!p)
-               return str;
-
-       p++;
-       strip_blank_front(&p);
-       strip_blank_end(p);
-       return p;
-}
-
-static int str_ioengine_cb(void *data, const char *str)
-{
-       struct thread_data *td = data;
-       const char *name = get_engine_name(str);
-
-       td->io_ops = load_ioengine(td, name);
-       if (td->io_ops)
-               return 0;
-
-       return 1;
-}
-
 static int str_lockmem_cb(void fio_unused *data, unsigned long *val)
 {
        mlock_size = *val;
 static int str_lockmem_cb(void fio_unused *data, unsigned long *val)
 {
        mlock_size = *val;
index 1a89ea7691ce7c7f82d71302e966c4377b27f0e9..66991c7cce1f3bb93b6b73981f43e5d3b82039ad 100644 (file)
@@ -158,10 +158,7 @@ void close_ioengine(struct thread_data *td)
        if (td->io_ops->dlhandle)
                dlclose(td->io_ops->dlhandle);
 
        if (td->io_ops->dlhandle)
                dlclose(td->io_ops->dlhandle);
 
-#if 0
-       /* we can't do this for threads, so just leak it, it's exiting */
        free(td->io_ops);
        free(td->io_ops);
-#endif
        td->io_ops = NULL;
 }
 
        td->io_ops = NULL;
 }