Constify 'td' in a few functions
[fio.git] / ioengines.c
index 4d1491cf079b5a504a22aad46965ade8c95bc6c8..56149381894abfb56e9bd7a47368cc2773278fde 100644 (file)
@@ -107,6 +107,20 @@ static struct ioengine_ops *dlopen_ioengine(struct thread_data *td,
        ops = dlsym(dlhandle, engine_lib);
        if (!ops)
                ops = dlsym(dlhandle, "ioengine");
+
+       /*
+        * For some external engines (like C++ ones) it is not that trivial
+        * to provide a non-static ionengine structure that we can reference.
+        * Instead we call a method which allocates the required ioengine
+        * structure.
+        */
+       if (!ops) {
+               get_ioengine_t get_ioengine = dlsym(dlhandle, "get_ioengine");
+
+               if (get_ioengine)
+                       get_ioengine(&ops);
+       }
+
        if (!ops) {
                td_vmsg(td, -1, dlerror(), "dlsym");
                dlclose(dlhandle);
@@ -236,7 +250,7 @@ int td_io_getevents(struct thread_data *td, unsigned int min, unsigned int max,
 out:
        if (r >= 0) {
                /*
-                * Reflect that our submitted requests were retrieved with
+                * Reflect that our submitted requests were retrieved with
                 * whatever OS async calls are in the underlying engine.
                 */
                td->io_u_in_flight -= r;
@@ -287,6 +301,13 @@ int td_io_queue(struct thread_data *td, struct io_u *io_u)
 
        unlock_file(td, io_u->file);
 
+       /*
+        * If an error was seen and the io engine didn't propagate it
+        * back to 'td', do so.
+        */
+       if (io_u->error && !td->error)
+               td_verror(td, io_u->error, "td_io_queue");
+
        /*
         * Add warning for O_DIRECT so that users have an easier time
         * spotting potentially bad alignment. If this triggers for the first
@@ -354,6 +375,9 @@ int td_io_init(struct thread_data *td)
                        td->error = ret;
        }
 
+       if (!ret && (td->io_ops->flags & FIO_NOIO))
+               td->flags |= TD_F_NOIO;
+
        return ret;
 }
 
@@ -366,14 +390,14 @@ int td_io_commit(struct thread_data *td)
        if (!td->cur_depth || !td->io_u_queued)
                return 0;
 
-       io_u_mark_depth(td, td->io_u_queued);   
+       io_u_mark_depth(td, td->io_u_queued);
 
        if (td->io_ops->commit) {
                ret = td->io_ops->commit(td);
                if (ret)
                        td_verror(td, -ret, "io commit");
        }
-       
+
        /*
         * Reflect that events were submitted as async IO requests.
         */
@@ -482,6 +506,14 @@ int td_io_close_file(struct thread_data *td, struct fio_file *f)
        return put_file(td, f);
 }
 
+int td_io_unlink_file(struct thread_data *td, struct fio_file *f)
+{
+       if (td->io_ops->unlink_file)
+               return td->io_ops->unlink_file(td, f);
+       else
+               return unlink(f->file_name);
+}
+
 int td_io_get_file_size(struct thread_data *td, struct fio_file *f)
 {
        if (!td->io_ops->get_file_size)
@@ -490,7 +522,8 @@ int td_io_get_file_size(struct thread_data *td, struct fio_file *f)
        return td->io_ops->get_file_size(td, f);
 }
 
-static int do_sync_file_range(struct thread_data *td, struct fio_file *f)
+static int do_sync_file_range(const struct thread_data *td,
+                             struct fio_file *f)
 {
        off64_t offset, nbytes;
 
@@ -503,7 +536,7 @@ static int do_sync_file_range(struct thread_data *td, struct fio_file *f)
        return sync_file_range(f->fd, offset, nbytes, td->o.sync_file_range);
 }
 
-int do_io_u_sync(struct thread_data *td, struct io_u *io_u)
+int do_io_u_sync(const struct thread_data *td, struct io_u *io_u)
 {
        int ret;
 
@@ -529,7 +562,7 @@ int do_io_u_sync(struct thread_data *td, struct io_u *io_u)
        return ret;
 }
 
-int do_io_u_trim(struct thread_data *td, struct io_u *io_u)
+int do_io_u_trim(const struct thread_data *td, struct io_u *io_u)
 {
 #ifndef FIO_HAVE_TRIM
        io_u->error = EINVAL;
@@ -540,7 +573,7 @@ int do_io_u_trim(struct thread_data *td, struct io_u *io_u)
 
        ret = os_trim(f->fd, io_u->offset, io_u->xfer_buflen);
        if (!ret)
-               return io_u->xfer_buflen;;
+               return io_u->xfer_buflen;
 
        io_u->error = ret;
        return 0;