+ int ret;
+
+ dprint_io_u(io_u, "queue");
+ fio_ro_check(td, io_u);
+
+ assert((io_u->flags & IO_U_F_FLIGHT) == 0);
+ io_u->flags |= IO_U_F_FLIGHT;
+
+ assert(io_u->file->flags & FIO_FILE_OPEN);
+
+ io_u->error = 0;
+ io_u->resid = 0;
+
+ if (td->io_ops->flags & FIO_SYNCIO) {
+ fio_gettime(&io_u->issue_time, NULL);
+ memcpy(&td->last_issue, &io_u->issue_time,
+ sizeof(struct timeval));
+
+ /*
+ * for a sync engine, set the timeout upfront
+ */
+ if (mtime_since(&td->timeout_end, &io_u->issue_time)
+ < IO_U_TIMEOUT)
+ io_u_set_timeout(td);
+ }
+
+ if (io_u->ddir != DDIR_SYNC)
+ td->io_issues[io_u->ddir]++;
+
+ ret = td->io_ops->queue(td, io_u);
+
+ unlock_file(td, io_u->file);
+
+ if (!td->io_ops->commit) {
+ io_u_mark_submit(td, 1);
+ io_u_mark_complete(td, 1);
+ }
+
+ if (ret == FIO_Q_COMPLETED) {
+ if (io_u->ddir != DDIR_SYNC) {
+ io_u_mark_depth(td, 1);
+ td->ts.total_io_u[io_u->ddir]++;
+ }
+ } else if (ret == FIO_Q_QUEUED) {
+ int r;
+
+ if (io_u->ddir != DDIR_SYNC) {
+ td->io_u_queued++;
+ td->ts.total_io_u[io_u->ddir]++;
+ }
+
+ if (td->io_u_queued >= td->o.iodepth_batch) {
+ r = td_io_commit(td);
+ if (r < 0)
+ return r;
+ }
+ }
+
+ if ((td->io_ops->flags & FIO_SYNCIO) == 0) {
+ fio_gettime(&io_u->issue_time, NULL);
+ memcpy(&td->last_issue, &io_u->issue_time,
+ sizeof(struct timeval));
+
+ /*
+ * async engine, set the timeout here
+ */
+ if (ret == FIO_Q_QUEUED &&
+ (mtime_since(&td->timeout_end, &io_u->issue_time)
+ < IO_U_TIMEOUT)) {
+ io_u_set_timeout(td);
+ }
+ }