Don't malloc/memcpy ioengine_ops on td initialization
[fio.git] / ioengines.c
index decc9cbb459ec953712f78fb1ac2aa6a4e3b7fac..918b50ad2bf27dafc0d69f9750d106aad29e2fa4 100644 (file)
 
 static FLIST_HEAD(engine_list);
 
-static int check_engine_ops(struct ioengine_ops *ops)
+static bool check_engine_ops(struct ioengine_ops *ops)
 {
        if (ops->version != FIO_IOOPS_VERSION) {
                log_err("bad ioops version %d (want %d)\n", ops->version,
                                                        FIO_IOOPS_VERSION);
-               return 1;
+               return true;
        }
 
        if (!ops->queue) {
                log_err("%s: no queue handler\n", ops->name);
-               return 1;
+               return true;
        }
 
        /*
         * sync engines only need a ->queue()
         */
        if (ops->flags & FIO_SYNCIO)
-               return 0;
+               return false;
 
-       if (!ops->event) {
-               log_err("%s: no event handler\n", ops->name);
-               return 1;
-       }
-       if (!ops->getevents) {
-               log_err("%s: no getevents handler\n", ops->name);
-               return 1;
+       if (!ops->event || !ops->getevents) {
+               log_err("%s: no event/getevents handler\n", ops->name);
+               return true;
        }
 
-       return 0;
+       return false;
 }
 
 void unregister_ioengine(struct ioengine_ops *ops)
@@ -123,13 +119,13 @@ static struct ioengine_ops *dlopen_ioengine(struct thread_data *td,
                return NULL;
        }
 
-       ops->dlhandle = dlhandle;
+       td->io_ops_dlhandle = dlhandle;
        return ops;
 }
 
 struct ioengine_ops *load_ioengine(struct thread_data *td, const char *name)
 {
-       struct ioengine_ops *ops, *ret;
+       struct ioengine_ops *ops;
        char engine[16];
 
        dprint(FD_IO, "load ioengine %s\n", name);
@@ -157,11 +153,7 @@ struct ioengine_ops *load_ioengine(struct thread_data *td, const char *name)
        if (check_engine_ops(ops))
                return NULL;
 
-       ret = malloc(sizeof(*ret));
-       memcpy(ret, ops, sizeof(*ret));
-       ret->data = NULL;
-
-       return ret;
+       return ops;
 }
 
 /*
@@ -177,10 +169,9 @@ void free_ioengine(struct thread_data *td)
                td->eo = NULL;
        }
 
-       if (td->io_ops->dlhandle)
-               dlclose(td->io_ops->dlhandle);
+       if (td->io_ops_dlhandle)
+               dlclose(td->io_ops_dlhandle);
 
-       free(td->io_ops);
        td->io_ops = NULL;
 }
 
@@ -190,7 +181,7 @@ void close_ioengine(struct thread_data *td)
 
        if (td->io_ops->cleanup) {
                td->io_ops->cleanup(td);
-               td->io_ops->data = NULL;
+               td->io_ops_data = NULL;
        }
 
        free_ioengine(td);
@@ -342,10 +333,10 @@ int td_io_queue(struct thread_data *td, struct io_u *io_u)
        } else if (ret == FIO_Q_QUEUED) {
                int r;
 
-               if (ddir_rw(io_u->ddir)) {
-                       td->io_u_queued++;
+               td->io_u_queued++;
+
+               if (ddir_rw(io_u->ddir))
                        td->ts.total_io_u[io_u->ddir]++;
-               }
 
                if (td->io_u_queued >= td->o.iodepth_batch) {
                        r = td_io_commit(td);