- engine = get_engine_name(td->o.ioengine);
- td->io_ops = load_ioengine(td, engine);
+ if (td->io_ops) {
+ struct ioengine_ops *ops;
+ void *dlhandle;
+
+ /* An engine is loaded, but the requested ioengine
+ * may have changed.
+ */
+ if (!strcmp(td->io_ops->name, td->o.ioengine)) {
+ /* The right engine is already loaded */
+ 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) {
+ if (dlhandle)
+ dlclose(dlhandle);
+ return 0;
+ }
+
+ if (dlhandle && dlhandle != td->io_ops_dlhandle)
+ dlclose(dlhandle);
+
+ /* Unload the old engine. */
+ free_ioengine(td);
+ }
+
+ td->io_ops = load_ioengine(td);