fio: move dynamic library handle to io_ops structure
authorEric Sandeen <sandeen@redhat.com>
Mon, 25 Jan 2021 19:18:31 +0000 (13:18 -0600)
committerJens Axboe <axboe@kernel.dk>
Mon, 25 Jan 2021 21:03:56 +0000 (14:03 -0700)
Keeping a dynamic engine's dlopen'd dlhandle on a thread structure doesn't
make sense; that thread may exit while others are still using the engine.

Move the dlhandle onto the ops structure itself.

We still only call dlopen for the first thead, which leaves a refcounting
issue which will be fixed in the next patch.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
fio.h
init.c
ioengines.c
ioengines.h

diff --git a/fio.h b/fio.h
index ee582a7241f1710bcd3b82681932c764f8cd14df..062abfa74c54ba7b122fac300348fc390243ac4e 100644 (file)
--- a/fio.h
+++ b/fio.h
@@ -281,7 +281,6 @@ struct thread_data {
         * IO engine private data and dlhandle.
         */
        void *io_ops_data;
-       void *io_ops_dlhandle;
 
        /*
         * Queue depth of io_u's that fio MIGHT do
diff --git a/init.c b/init.c
index 1d14df169d0919e1a868320272ea68b646999e2d..ab38b334a9195b089d686785c9ec0d0d02d17dc4 100644 (file)
--- a/init.c
+++ b/init.c
@@ -1104,18 +1104,18 @@ int ioengine_load(struct thread_data *td)
                 * for this name and see if they match. If they do, then
                 * the engine is unchanged.
                 */
-               dlhandle = td->io_ops_dlhandle;
+               dlhandle = td->io_ops->dlhandle;
                ops = load_ioengine(td);
                if (!ops)
                        goto fail;
 
-               if (ops == td->io_ops && dlhandle == td->io_ops_dlhandle) {
+               if (ops == td->io_ops && dlhandle == td->io_ops->dlhandle) {
                        if (dlhandle)
                                dlclose(dlhandle);
                        return 0;
                }
 
-               if (dlhandle && dlhandle != td->io_ops_dlhandle)
+               if (dlhandle && dlhandle != td->io_ops->dlhandle)
                        dlclose(dlhandle);
 
                /* Unload the old engine. */
index 5ac512ae05c6c07c1a4daacc126b7bc56ddb9280..dcc9496dd4ddab6fe0c79612e13684e7b790441f 100644 (file)
@@ -155,7 +155,7 @@ static struct ioengine_ops *dlopen_ioengine(struct thread_data *td,
                return NULL;
        }
 
-       td->io_ops_dlhandle = dlhandle;
+       ops->dlhandle = dlhandle;
        return ops;
 }
 
@@ -228,9 +228,9 @@ void free_ioengine(struct thread_data *td)
                td->eo = NULL;
        }
 
-       if (td->io_ops_dlhandle) {
-               dlclose(td->io_ops_dlhandle);
-               td->io_ops_dlhandle = NULL;
+       if (td->io_ops->dlhandle) {
+               dlclose(td->io_ops->dlhandle);
+               td->io_ops->dlhandle = NULL;
        }
 
        td->io_ops = NULL;
index a928b211509281eb1e93d5d27c8d9d4225086c60..839b318da60464eb5d78d503ca930559c2548c41 100644 (file)
@@ -8,7 +8,7 @@
 #include "io_u.h"
 #include "zbd_types.h"
 
-#define FIO_IOOPS_VERSION      27
+#define FIO_IOOPS_VERSION      28
 
 #ifndef CONFIG_DYNAMIC_ENGINES
 #define FIO_STATIC     static
@@ -30,6 +30,7 @@ struct ioengine_ops {
        const char *name;
        int version;
        int flags;
+       void *dlhandle;
        int (*setup)(struct thread_data *);
        int (*init)(struct thread_data *);
        int (*post_init)(struct thread_data *);