sg: add support for WRITE STREAM(16) commands
[fio.git] / engines / io_uring.c
index 68c3311386da328abe7e19b435186b6a3fbe7fdd..a2533c88e6a2c0bfa819dd782e37888f6f0bc960 100644 (file)
@@ -69,13 +69,13 @@ struct ioring_data {
 
        struct ioring_mmap mmap[3];
 
-       bool use_cmdprio;
+       struct cmdprio cmdprio;
 };
 
 struct ioring_options {
        struct thread_data *td;
        unsigned int hipri;
-       struct cmdprio cmdprio;
+       struct cmdprio_options cmdprio_options;
        unsigned int fixedbufs;
        unsigned int registerfiles;
        unsigned int sqpoll_thread;
@@ -106,15 +106,6 @@ static int fio_ioring_sqpoll_cb(void *data, unsigned long long *val)
        return 0;
 }
 
-static int str_cmdprio_bssplit_cb(void *data, const char *input)
-{
-       struct ioring_options *o = data;
-       struct thread_data *td = o->td;
-       struct cmdprio *cmdprio = &o->cmdprio;
-
-       return fio_cmdprio_bssplit_parse(td, input, cmdprio);
-}
-
 static struct fio_option options[] = {
        {
                .name   = "hipri",
@@ -131,9 +122,9 @@ static struct fio_option options[] = {
                .lname  = "high priority percentage",
                .type   = FIO_OPT_INT,
                .off1   = offsetof(struct ioring_options,
-                                  cmdprio.percentage[DDIR_READ]),
+                                  cmdprio_options.percentage[DDIR_READ]),
                .off2   = offsetof(struct ioring_options,
-                                  cmdprio.percentage[DDIR_WRITE]),
+                                  cmdprio_options.percentage[DDIR_WRITE]),
                .minval = 0,
                .maxval = 100,
                .help   = "Send high priority I/O this percentage of the time",
@@ -145,9 +136,9 @@ static struct fio_option options[] = {
                .lname  = "Asynchronous I/O priority class",
                .type   = FIO_OPT_INT,
                .off1   = offsetof(struct ioring_options,
-                                  cmdprio.class[DDIR_READ]),
+                                  cmdprio_options.class[DDIR_READ]),
                .off2   = offsetof(struct ioring_options,
-                                  cmdprio.class[DDIR_WRITE]),
+                                  cmdprio_options.class[DDIR_WRITE]),
                .help   = "Set asynchronous IO priority class",
                .minval = IOPRIO_MIN_PRIO_CLASS + 1,
                .maxval = IOPRIO_MAX_PRIO_CLASS,
@@ -160,9 +151,9 @@ static struct fio_option options[] = {
                .lname  = "Asynchronous I/O priority level",
                .type   = FIO_OPT_INT,
                .off1   = offsetof(struct ioring_options,
-                                  cmdprio.level[DDIR_READ]),
+                                  cmdprio_options.level[DDIR_READ]),
                .off2   = offsetof(struct ioring_options,
-                                  cmdprio.level[DDIR_WRITE]),
+                                  cmdprio_options.level[DDIR_WRITE]),
                .help   = "Set asynchronous IO priority level",
                .minval = IOPRIO_MIN_PRIO,
                .maxval = IOPRIO_MAX_PRIO,
@@ -173,9 +164,9 @@ static struct fio_option options[] = {
        {
                .name   = "cmdprio_bssplit",
                .lname  = "Priority percentage block size split",
-               .type   = FIO_OPT_STR_ULL,
-               .cb     = str_cmdprio_bssplit_cb,
-               .off1   = offsetof(struct ioring_options, cmdprio.bssplit),
+               .type   = FIO_OPT_STR_STORE,
+               .off1   = offsetof(struct ioring_options,
+                                  cmdprio_options.bssplit_str),
                .help   = "Set priority percentages for different block sizes",
                .category = FIO_OPT_C_ENGINE,
                .group  = FIO_OPT_G_IOURING,
@@ -460,8 +451,7 @@ static inline void fio_ioring_cmdprio_prep(struct thread_data *td,
                                           struct io_u *io_u)
 {
        struct ioring_data *ld = td->io_ops_data;
-       struct ioring_options *o = td->eo;
-       struct cmdprio *cmdprio = &o->cmdprio;
+       struct cmdprio *cmdprio = &ld->cmdprio;
 
        if (fio_cmdprio_set_ioprio(td, cmdprio, io_u))
                ld->sqes[io_u->index].ioprio = io_u->ioprio;
@@ -494,7 +484,7 @@ static enum fio_q_status fio_ioring_queue(struct thread_data *td,
        if (next_tail == atomic_load_acquire(ring->head))
                return FIO_Q_BUSY;
 
-       if (ld->use_cmdprio)
+       if (ld->cmdprio.mode != CMDPRIO_MODE_NONE)
                fio_ioring_cmdprio_prep(td, io_u);
 
        ring->array[tail & ld->sq_ring_mask] = io_u->index;
@@ -600,6 +590,7 @@ static void fio_ioring_cleanup(struct thread_data *td)
                if (!(td->flags & TD_F_CHILD))
                        fio_ioring_unmap(ld);
 
+               fio_cmdprio_cleanup(&ld->cmdprio);
                free(ld->io_u_index);
                free(ld->iovecs);
                free(ld->fds);
@@ -701,9 +692,22 @@ static int fio_ioring_queue_init(struct thread_data *td)
                }
        }
 
+       /*
+        * Clamp CQ ring size at our SQ ring size, we don't need more entries
+        * than that.
+        */
+       p.flags |= IORING_SETUP_CQSIZE;
+       p.cq_entries = depth;
+
+retry:
        ret = syscall(__NR_io_uring_setup, depth, &p);
-       if (ret < 0)
+       if (ret < 0) {
+               if (errno == EINVAL && p.flags & IORING_SETUP_CQSIZE) {
+                       p.flags &= ~IORING_SETUP_CQSIZE;
+                       goto retry;
+               }
                return ret;
+       }
 
        ld->ring_fd = ret;
 
@@ -806,7 +810,6 @@ static int fio_ioring_init(struct thread_data *td)
 {
        struct ioring_options *o = td->eo;
        struct ioring_data *ld;
-       struct cmdprio *cmdprio = &o->cmdprio;
        int ret;
 
        /* sqthread submission requires registered files */
@@ -831,7 +834,7 @@ static int fio_ioring_init(struct thread_data *td)
 
        td->io_ops_data = ld;
 
-       ret = fio_cmdprio_init(td, cmdprio, &ld->use_cmdprio);
+       ret = fio_cmdprio_init(td, &ld->cmdprio, &o->cmdprio_options);
        if (ret) {
                td_verror(td, EINVAL, "fio_ioring_init");
                return 1;