engines: pvsync2 libaio io_uring: add support for RWF_NOWAIT
[fio.git] / engines / libaio.c
index 299798ae8a5a16de1e0b112d2bbf74323eae22b8..daa576dad3e64b97f4af427633921f0ab9c61e6c 100644 (file)
 #define IOCB_FLAG_IOPRIO    (1 << 1)
 #endif
 
+/* Hack for libaio < 0.3.111 */
+#ifndef CONFIG_LIBAIO_RW_FLAGS
+#define aio_rw_flags __pad2
+#endif
+
 static int fio_libaio_commit(struct thread_data *td);
 static int fio_libaio_init(struct thread_data *td);
 
@@ -51,6 +56,7 @@ struct libaio_options {
        void *pad;
        unsigned int userspace_reap;
        unsigned int cmdprio_percentage;
+       unsigned int nowait;
 };
 
 static struct fio_option options[] = {
@@ -83,6 +89,15 @@ static struct fio_option options[] = {
                .help   = "Your platform does not support I/O priority classes",
        },
 #endif
+       {
+               .name   = "nowait",
+               .lname  = "RWF_NOWAIT",
+               .type   = FIO_OPT_BOOL,
+               .off1   = offsetof(struct libaio_options, nowait),
+               .help   = "Set RWF_NOWAIT for reads/writes",
+               .category = FIO_OPT_C_ENGINE,
+               .group  = FIO_OPT_G_LIBAIO,
+       },
        {
                .name   = NULL,
        },
@@ -97,15 +112,20 @@ static inline void ring_inc(struct libaio_data *ld, unsigned int *val,
                *val = (*val + add) % ld->entries;
 }
 
-static int fio_libaio_prep(struct thread_data fio_unused *td, struct io_u *io_u)
+static int fio_libaio_prep(struct thread_data *td, struct io_u *io_u)
 {
+       struct libaio_options *o = td->eo;
        struct fio_file *f = io_u->file;
        struct iocb *iocb = &io_u->iocb;
 
        if (io_u->ddir == DDIR_READ) {
                io_prep_pread(iocb, f->fd, io_u->xfer_buf, io_u->xfer_buflen, io_u->offset);
+               if (o->nowait)
+                       iocb->aio_rw_flags |= RWF_NOWAIT;
        } else if (io_u->ddir == DDIR_WRITE) {
                io_prep_pwrite(iocb, f->fd, io_u->xfer_buf, io_u->xfer_buflen, io_u->offset);
+               if (o->nowait)
+                       iocb->aio_rw_flags |= RWF_NOWAIT;
        } else if (ddir_sync(io_u->ddir))
                io_prep_fsync(iocb, f->fd);