+ int ret = 0;
+
+ if (td->io_ops->init) {
+ ret = td->io_ops->init(td);
+ if (ret)
+ log_err("fio: io engine %s init failed.%s\n",
+ td->io_ops->name,
+ td->o.iodepth > 1 ?
+ " Perhaps try reducing io depth?" : "");
+ else
+ td->io_ops_init = 1;
+ if (!td->error)
+ td->error = ret;
+ }
+
+ return ret;
+}
+
+int td_io_commit(struct thread_data *td)
+{
+ int ret;
+
+ dprint(FD_IO, "calling ->commit(), depth %d\n", td->cur_depth);
+
+ if (!td->cur_depth || !td->io_u_queued)
+ return 0;
+
+ 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.
+ */
+ td->io_u_in_flight += td->io_u_queued;
+ td->io_u_queued = 0;
+
+ return 0;
+}
+
+int td_io_open_file(struct thread_data *td, struct fio_file *f)
+{
+ assert(!fio_file_open(f));
+ assert(f->fd == -1);
+
+ if (td->io_ops->open_file(td, f)) {
+ if (td->error == EINVAL && td->o.odirect)
+ log_err("fio: destination does not support O_DIRECT\n");
+ if (td->error == EMFILE) {
+ log_err("fio: try reducing/setting openfiles (failed"
+ " at %u of %u)\n", td->nr_open_files,
+ td->o.nr_files);
+ }
+
+ assert(f->fd == -1);
+ assert(!fio_file_open(f));
+ return 1;
+ }
+
+ fio_file_reset(td, f);
+ fio_file_set_open(f);
+ fio_file_clear_closing(f);
+ disk_util_inc(f->du);
+
+ td->nr_open_files++;
+ get_file(f);
+
+ if (f->filetype == FIO_TYPE_PIPE) {
+ if (td_random(td)) {
+ log_err("fio: can't seek on pipes (no random io)\n");
+ goto err;
+ }
+ }
+
+ if (td_ioengine_flagged(td, FIO_DISKLESSIO))
+ goto done;
+
+ if (td->o.invalidate_cache && file_invalidate_cache(td, f))
+ goto err;
+
+ if (td->o.fadvise_hint != F_ADV_NONE &&
+ (f->filetype == FIO_TYPE_BLOCK || f->filetype == FIO_TYPE_FILE)) {
+ int flags;
+
+ if (td->o.fadvise_hint == F_ADV_TYPE) {
+ if (td_random(td))
+ flags = POSIX_FADV_RANDOM;
+ else
+ flags = POSIX_FADV_SEQUENTIAL;
+ } else if (td->o.fadvise_hint == F_ADV_RANDOM)
+ flags = POSIX_FADV_RANDOM;
+ else if (td->o.fadvise_hint == F_ADV_SEQUENTIAL)
+ flags = POSIX_FADV_SEQUENTIAL;
+ else {
+ log_err("fio: unknown fadvise type %d\n",
+ td->o.fadvise_hint);
+ flags = POSIX_FADV_NORMAL;
+ }
+
+ if (posix_fadvise(f->fd, f->file_offset, f->io_size, flags) < 0) {
+ td_verror(td, errno, "fadvise");
+ goto err;
+ }
+ }
+#ifdef FIO_HAVE_WRITE_HINT
+ if (fio_option_is_set(&td->o, write_hint) &&
+ (f->filetype == FIO_TYPE_BLOCK || f->filetype == FIO_TYPE_FILE)) {
+ uint64_t hint = td->o.write_hint;
+ int cmd;
+
+ /*
+ * For direct IO, we just need/want to set the hint on
+ * the file descriptor. For buffered IO, we need to set
+ * it on the inode.
+ */
+ if (td->o.odirect)
+ cmd = F_SET_FILE_RW_HINT;
+ else
+ cmd = F_SET_RW_HINT;