ioengines: improve "is this the same IO engine" check
authorJens Axboe <axboe@kernel.dk>
Fri, 15 Dec 2017 16:08:26 +0000 (09:08 -0700)
committerJens Axboe <axboe@kernel.dk>
Fri, 15 Dec 2017 16:08:26 +0000 (09:08 -0700)
We can't just compare the name, that assumes that name and filename
match for an IO engine. While that's generally the case for the
engines that fio ships with, it's not a requirement, and it's
definitely not true for external engines.

Fixup the check by re-loading the engine and checking the OPS
instead. That should be bullet proof.

Fixes: 800334d ("Correctly detect whether ioengine_load can exit early")
Signed-off-by: Jens Axboe <axboe@kernel.dk>
init.c

diff --git a/init.c b/init.c
index b9da71335a7fc34aece77d4678949c35a276cdd1..03cdf902261f51d6d4dc33360bdcb67bd9fe88c9 100644 (file)
--- a/init.c
+++ b/init.c
@@ -11,6 +11,7 @@
 #include <sys/ipc.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <dlfcn.h>
 
 #include "fio.h"
 #ifndef FIO_NO_HAVE_SHM_H
@@ -1064,6 +1065,9 @@ int ioengine_load(struct thread_data *td)
        }
 
        if (td->io_ops) {
+               struct ioengine_ops *ops;
+               void *dlhandle;
+
                /* An engine is loaded, but the requested ioengine
                 * may have changed.
                 */
@@ -1072,6 +1076,19 @@ int ioengine_load(struct thread_data *td)
                        return 0;
                }
 
+               /*
+                * Name of file and engine may be different, load ops
+                * for this name and see if they match. If they do, then
+                * the engine is unchanged.
+                */
+               dlhandle = td->io_ops_dlhandle;
+               ops = load_ioengine(td);
+               if (ops == td->io_ops && dlhandle == td->io_ops_dlhandle)
+                       return 0;
+
+               if (dlhandle && dlhandle != td->io_ops_dlhandle)
+                       dlclose(dlhandle);
+
                /* Unload the old engine. */
                free_ioengine(td);
        }