Unify architecture io_uring syscall numbers
[fio.git] / engines / io_uring.c
1 /*
2  * io_uring engine
3  *
4  * IO engine using the new native Linux aio io_uring interface. See:
5  *
6  * http://git.kernel.dk/cgit/linux-block/log/?h=io_uring
7  *
8  */
9 #include <stdlib.h>
10 #include <unistd.h>
11 #include <errno.h>
12 #include <sys/time.h>
13 #include <sys/resource.h>
14
15 #include "../fio.h"
16 #include "../lib/pow2.h"
17 #include "../optgroup.h"
18 #include "../lib/memalign.h"
19 #include "../lib/fls.h"
20
21 #ifdef ARCH_HAVE_IOURING
22
23 #include "../lib/types.h"
24 #include "../os/linux/io_uring.h"
25
26 struct io_sq_ring {
27         unsigned *head;
28         unsigned *tail;
29         unsigned *ring_mask;
30         unsigned *ring_entries;
31         unsigned *flags;
32         unsigned *array;
33 };
34
35 struct io_cq_ring {
36         unsigned *head;
37         unsigned *tail;
38         unsigned *ring_mask;
39         unsigned *ring_entries;
40         struct io_uring_cqe *cqes;
41 };
42
43 struct ioring_mmap {
44         void *ptr;
45         size_t len;
46 };
47
48 struct ioring_data {
49         int ring_fd;
50
51         struct io_u **io_u_index;
52
53         int *fds;
54
55         struct io_sq_ring sq_ring;
56         struct io_uring_sqe *sqes;
57         struct iovec *iovecs;
58         unsigned sq_ring_mask;
59
60         struct io_cq_ring cq_ring;
61         unsigned cq_ring_mask;
62
63         int queued;
64         int cq_ring_off;
65         unsigned iodepth;
66
67         struct ioring_mmap mmap[3];
68 };
69
70 struct ioring_options {
71         void *pad;
72         unsigned int hipri;
73         unsigned int cmdprio_percentage;
74         unsigned int fixedbufs;
75         unsigned int registerfiles;
76         unsigned int sqpoll_thread;
77         unsigned int sqpoll_set;
78         unsigned int sqpoll_cpu;
79         unsigned int nonvectored;
80         unsigned int uncached;
81 };
82
83 static const int ddir_to_op[2][2] = {
84         { IORING_OP_READV, IORING_OP_READ },
85         { IORING_OP_WRITEV, IORING_OP_WRITE }
86 };
87
88 static const int fixed_ddir_to_op[2] = {
89         IORING_OP_READ_FIXED,
90         IORING_OP_WRITE_FIXED
91 };
92
93 static int fio_ioring_sqpoll_cb(void *data, unsigned long long *val)
94 {
95         struct ioring_options *o = data;
96
97         o->sqpoll_cpu = *val;
98         o->sqpoll_set = 1;
99         return 0;
100 }
101
102 static struct fio_option options[] = {
103         {
104                 .name   = "hipri",
105                 .lname  = "High Priority",
106                 .type   = FIO_OPT_STR_SET,
107                 .off1   = offsetof(struct ioring_options, hipri),
108                 .help   = "Use polled IO completions",
109                 .category = FIO_OPT_C_ENGINE,
110                 .group  = FIO_OPT_G_IOURING,
111         },
112 #ifdef FIO_HAVE_IOPRIO_CLASS
113         {
114                 .name   = "cmdprio_percentage",
115                 .lname  = "high priority percentage",
116                 .type   = FIO_OPT_INT,
117                 .off1   = offsetof(struct ioring_options, cmdprio_percentage),
118                 .minval = 1,
119                 .maxval = 100,
120                 .help   = "Send high priority I/O this percentage of the time",
121                 .category = FIO_OPT_C_ENGINE,
122                 .group  = FIO_OPT_G_IOURING,
123         },
124 #else
125         {
126                 .name   = "cmdprio_percentage",
127                 .lname  = "high priority percentage",
128                 .type   = FIO_OPT_UNSUPPORTED,
129                 .help   = "Your platform does not support I/O priority classes",
130         },
131 #endif
132         {
133                 .name   = "fixedbufs",
134                 .lname  = "Fixed (pre-mapped) IO buffers",
135                 .type   = FIO_OPT_STR_SET,
136                 .off1   = offsetof(struct ioring_options, fixedbufs),
137                 .help   = "Pre map IO buffers",
138                 .category = FIO_OPT_C_ENGINE,
139                 .group  = FIO_OPT_G_IOURING,
140         },
141         {
142                 .name   = "registerfiles",
143                 .lname  = "Register file set",
144                 .type   = FIO_OPT_STR_SET,
145                 .off1   = offsetof(struct ioring_options, registerfiles),
146                 .help   = "Pre-open/register files",
147                 .category = FIO_OPT_C_ENGINE,
148                 .group  = FIO_OPT_G_IOURING,
149         },
150         {
151                 .name   = "sqthread_poll",
152                 .lname  = "Kernel SQ thread polling",
153                 .type   = FIO_OPT_INT,
154                 .off1   = offsetof(struct ioring_options, sqpoll_thread),
155                 .help   = "Offload submission/completion to kernel thread",
156                 .category = FIO_OPT_C_ENGINE,
157                 .group  = FIO_OPT_G_IOURING,
158         },
159         {
160                 .name   = "sqthread_poll_cpu",
161                 .lname  = "SQ Thread Poll CPU",
162                 .type   = FIO_OPT_INT,
163                 .cb     = fio_ioring_sqpoll_cb,
164                 .help   = "What CPU to run SQ thread polling on",
165                 .category = FIO_OPT_C_ENGINE,
166                 .group  = FIO_OPT_G_IOURING,
167         },
168         {
169                 .name   = "nonvectored",
170                 .lname  = "Non-vectored",
171                 .type   = FIO_OPT_INT,
172                 .off1   = offsetof(struct ioring_options, nonvectored),
173                 .help   = "Use non-vectored read/write commands",
174                 .category = FIO_OPT_C_ENGINE,
175                 .group  = FIO_OPT_G_IOURING,
176         },
177         {
178                 .name   = "uncached",
179                 .lname  = "Uncached",
180                 .type   = FIO_OPT_INT,
181                 .off1   = offsetof(struct ioring_options, uncached),
182                 .help   = "Use RWF_UNCACHED for buffered read/writes",
183                 .category = FIO_OPT_C_ENGINE,
184                 .group  = FIO_OPT_G_IOURING,
185         },
186         {
187                 .name   = NULL,
188         },
189 };
190
191 static int io_uring_enter(struct ioring_data *ld, unsigned int to_submit,
192                          unsigned int min_complete, unsigned int flags)
193 {
194         return syscall(__NR_io_uring_enter, ld->ring_fd, to_submit,
195                         min_complete, flags, NULL, 0);
196 }
197
198 static int fio_ioring_prep(struct thread_data *td, struct io_u *io_u)
199 {
200         struct ioring_data *ld = td->io_ops_data;
201         struct ioring_options *o = td->eo;
202         struct fio_file *f = io_u->file;
203         struct io_uring_sqe *sqe;
204
205         sqe = &ld->sqes[io_u->index];
206
207         /* zero out fields not used in this submission */
208         memset(sqe, 0, sizeof(*sqe));
209
210         if (o->registerfiles) {
211                 sqe->fd = f->engine_pos;
212                 sqe->flags = IOSQE_FIXED_FILE;
213         } else {
214                 sqe->fd = f->fd;
215         }
216
217         if (io_u->ddir == DDIR_READ || io_u->ddir == DDIR_WRITE) {
218                 if (o->fixedbufs) {
219                         sqe->opcode = fixed_ddir_to_op[io_u->ddir];
220                         sqe->addr = (unsigned long) io_u->xfer_buf;
221                         sqe->len = io_u->xfer_buflen;
222                         sqe->buf_index = io_u->index;
223                 } else {
224                         sqe->opcode = ddir_to_op[io_u->ddir][!!o->nonvectored];
225                         if (o->nonvectored) {
226                                 sqe->addr = (unsigned long)
227                                                 ld->iovecs[io_u->index].iov_base;
228                                 sqe->len = ld->iovecs[io_u->index].iov_len;
229                         } else {
230                                 sqe->addr = (unsigned long) &ld->iovecs[io_u->index];
231                                 sqe->len = 1;
232                         }
233                 }
234                 if (!td->o.odirect && o->uncached)
235                         sqe->rw_flags = RWF_UNCACHED;
236                 if (fio_option_is_set(&td->o, ioprio_class))
237                         sqe->ioprio = td->o.ioprio_class << 13;
238                 if (fio_option_is_set(&td->o, ioprio))
239                         sqe->ioprio |= td->o.ioprio;
240                 sqe->off = io_u->offset;
241         } else if (ddir_sync(io_u->ddir)) {
242                 if (io_u->ddir == DDIR_SYNC_FILE_RANGE) {
243                         sqe->off = f->first_write;
244                         sqe->len = f->last_write - f->first_write;
245                         sqe->sync_range_flags = td->o.sync_file_range;
246                         sqe->opcode = IORING_OP_SYNC_FILE_RANGE;
247                 } else {
248                         if (io_u->ddir == DDIR_DATASYNC)
249                                 sqe->fsync_flags |= IORING_FSYNC_DATASYNC;
250                         sqe->opcode = IORING_OP_FSYNC;
251                 }
252         }
253
254         sqe->user_data = (unsigned long) io_u;
255         return 0;
256 }
257
258 static struct io_u *fio_ioring_event(struct thread_data *td, int event)
259 {
260         struct ioring_data *ld = td->io_ops_data;
261         struct io_uring_cqe *cqe;
262         struct io_u *io_u;
263         unsigned index;
264
265         index = (event + ld->cq_ring_off) & ld->cq_ring_mask;
266
267         cqe = &ld->cq_ring.cqes[index];
268         io_u = (struct io_u *) (uintptr_t) cqe->user_data;
269
270         if (cqe->res != io_u->xfer_buflen) {
271                 if (cqe->res > io_u->xfer_buflen)
272                         io_u->error = -cqe->res;
273                 else
274                         io_u->resid = io_u->xfer_buflen - cqe->res;
275         } else
276                 io_u->error = 0;
277
278         return io_u;
279 }
280
281 static int fio_ioring_cqring_reap(struct thread_data *td, unsigned int events,
282                                    unsigned int max)
283 {
284         struct ioring_data *ld = td->io_ops_data;
285         struct io_cq_ring *ring = &ld->cq_ring;
286         unsigned head, reaped = 0;
287
288         head = *ring->head;
289         do {
290                 read_barrier();
291                 if (head == *ring->tail)
292                         break;
293                 reaped++;
294                 head++;
295         } while (reaped + events < max);
296
297         *ring->head = head;
298         write_barrier();
299         return reaped;
300 }
301
302 static int fio_ioring_getevents(struct thread_data *td, unsigned int min,
303                                 unsigned int max, const struct timespec *t)
304 {
305         struct ioring_data *ld = td->io_ops_data;
306         unsigned actual_min = td->o.iodepth_batch_complete_min == 0 ? 0 : min;
307         struct ioring_options *o = td->eo;
308         struct io_cq_ring *ring = &ld->cq_ring;
309         unsigned events = 0;
310         int r;
311
312         ld->cq_ring_off = *ring->head;
313         do {
314                 r = fio_ioring_cqring_reap(td, events, max);
315                 if (r) {
316                         events += r;
317                         if (actual_min != 0)
318                                 actual_min -= r;
319                         continue;
320                 }
321
322                 if (!o->sqpoll_thread) {
323                         r = io_uring_enter(ld, 0, actual_min,
324                                                 IORING_ENTER_GETEVENTS);
325                         if (r < 0) {
326                                 if (errno == EAGAIN || errno == EINTR)
327                                         continue;
328                                 td_verror(td, errno, "io_uring_enter");
329                                 break;
330                         }
331                 }
332         } while (events < min);
333
334         return r < 0 ? r : events;
335 }
336
337 static void fio_ioring_prio_prep(struct thread_data *td, struct io_u *io_u)
338 {
339         struct ioring_options *o = td->eo;
340         struct ioring_data *ld = td->io_ops_data;
341         if (rand_between(&td->prio_state, 0, 99) < o->cmdprio_percentage) {
342                 ld->sqes[io_u->index].ioprio = IOPRIO_CLASS_RT << IOPRIO_CLASS_SHIFT;
343                 io_u->flags |= IO_U_F_PRIORITY;
344         }
345         return;
346 }
347
348 static enum fio_q_status fio_ioring_queue(struct thread_data *td,
349                                           struct io_u *io_u)
350 {
351         struct ioring_data *ld = td->io_ops_data;
352         struct io_sq_ring *ring = &ld->sq_ring;
353         struct ioring_options *o = td->eo;
354         unsigned tail, next_tail;
355
356         fio_ro_check(td, io_u);
357
358         if (ld->queued == ld->iodepth)
359                 return FIO_Q_BUSY;
360
361         if (io_u->ddir == DDIR_TRIM) {
362                 if (ld->queued)
363                         return FIO_Q_BUSY;
364
365                 do_io_u_trim(td, io_u);
366                 io_u_mark_submit(td, 1);
367                 io_u_mark_complete(td, 1);
368                 return FIO_Q_COMPLETED;
369         }
370
371         tail = *ring->tail;
372         next_tail = tail + 1;
373         read_barrier();
374         if (next_tail == *ring->head)
375                 return FIO_Q_BUSY;
376
377         /* ensure sqe stores are ordered with tail update */
378         write_barrier();
379         if (o->cmdprio_percentage)
380                 fio_ioring_prio_prep(td, io_u);
381         ring->array[tail & ld->sq_ring_mask] = io_u->index;
382         *ring->tail = next_tail;
383         write_barrier();
384
385         ld->queued++;
386         return FIO_Q_QUEUED;
387 }
388
389 static void fio_ioring_queued(struct thread_data *td, int start, int nr)
390 {
391         struct ioring_data *ld = td->io_ops_data;
392         struct timespec now;
393
394         if (!fio_fill_issue_time(td))
395                 return;
396
397         fio_gettime(&now, NULL);
398
399         while (nr--) {
400                 struct io_sq_ring *ring = &ld->sq_ring;
401                 int index = ring->array[start & ld->sq_ring_mask];
402                 struct io_u *io_u = ld->io_u_index[index];
403
404                 memcpy(&io_u->issue_time, &now, sizeof(now));
405                 io_u_queued(td, io_u);
406
407                 start++;
408         }
409 }
410
411 static int fio_ioring_commit(struct thread_data *td)
412 {
413         struct ioring_data *ld = td->io_ops_data;
414         struct ioring_options *o = td->eo;
415         int ret;
416
417         if (!ld->queued)
418                 return 0;
419
420         /*
421          * Kernel side does submission. just need to check if the ring is
422          * flagged as needing a kick, if so, call io_uring_enter(). This
423          * only happens if we've been idle too long.
424          */
425         if (o->sqpoll_thread) {
426                 struct io_sq_ring *ring = &ld->sq_ring;
427
428                 read_barrier();
429                 if (*ring->flags & IORING_SQ_NEED_WAKEUP)
430                         io_uring_enter(ld, ld->queued, 0,
431                                         IORING_ENTER_SQ_WAKEUP);
432                 ld->queued = 0;
433                 return 0;
434         }
435
436         do {
437                 unsigned start = *ld->sq_ring.head;
438                 long nr = ld->queued;
439
440                 ret = io_uring_enter(ld, nr, 0, IORING_ENTER_GETEVENTS);
441                 if (ret > 0) {
442                         fio_ioring_queued(td, start, ret);
443                         io_u_mark_submit(td, ret);
444
445                         ld->queued -= ret;
446                         ret = 0;
447                 } else if (!ret) {
448                         io_u_mark_submit(td, ret);
449                         continue;
450                 } else {
451                         if (errno == EAGAIN || errno == EINTR) {
452                                 ret = fio_ioring_cqring_reap(td, 0, ld->queued);
453                                 if (ret)
454                                         continue;
455                                 /* Shouldn't happen */
456                                 usleep(1);
457                                 continue;
458                         }
459                         td_verror(td, errno, "io_uring_enter submit");
460                         break;
461                 }
462         } while (ld->queued);
463
464         return ret;
465 }
466
467 static void fio_ioring_unmap(struct ioring_data *ld)
468 {
469         int i;
470
471         for (i = 0; i < ARRAY_SIZE(ld->mmap); i++)
472                 munmap(ld->mmap[i].ptr, ld->mmap[i].len);
473         close(ld->ring_fd);
474 }
475
476 static void fio_ioring_cleanup(struct thread_data *td)
477 {
478         struct ioring_data *ld = td->io_ops_data;
479
480         if (ld) {
481                 if (!(td->flags & TD_F_CHILD))
482                         fio_ioring_unmap(ld);
483
484                 free(ld->io_u_index);
485                 free(ld->iovecs);
486                 free(ld->fds);
487                 free(ld);
488         }
489 }
490
491 static int fio_ioring_mmap(struct ioring_data *ld, struct io_uring_params *p)
492 {
493         struct io_sq_ring *sring = &ld->sq_ring;
494         struct io_cq_ring *cring = &ld->cq_ring;
495         void *ptr;
496
497         ld->mmap[0].len = p->sq_off.array + p->sq_entries * sizeof(__u32);
498         ptr = mmap(0, ld->mmap[0].len, PROT_READ | PROT_WRITE,
499                         MAP_SHARED | MAP_POPULATE, ld->ring_fd,
500                         IORING_OFF_SQ_RING);
501         ld->mmap[0].ptr = ptr;
502         sring->head = ptr + p->sq_off.head;
503         sring->tail = ptr + p->sq_off.tail;
504         sring->ring_mask = ptr + p->sq_off.ring_mask;
505         sring->ring_entries = ptr + p->sq_off.ring_entries;
506         sring->flags = ptr + p->sq_off.flags;
507         sring->array = ptr + p->sq_off.array;
508         ld->sq_ring_mask = *sring->ring_mask;
509
510         ld->mmap[1].len = p->sq_entries * sizeof(struct io_uring_sqe);
511         ld->sqes = mmap(0, ld->mmap[1].len, PROT_READ | PROT_WRITE,
512                                 MAP_SHARED | MAP_POPULATE, ld->ring_fd,
513                                 IORING_OFF_SQES);
514         ld->mmap[1].ptr = ld->sqes;
515
516         ld->mmap[2].len = p->cq_off.cqes +
517                                 p->cq_entries * sizeof(struct io_uring_cqe);
518         ptr = mmap(0, ld->mmap[2].len, PROT_READ | PROT_WRITE,
519                         MAP_SHARED | MAP_POPULATE, ld->ring_fd,
520                         IORING_OFF_CQ_RING);
521         ld->mmap[2].ptr = ptr;
522         cring->head = ptr + p->cq_off.head;
523         cring->tail = ptr + p->cq_off.tail;
524         cring->ring_mask = ptr + p->cq_off.ring_mask;
525         cring->ring_entries = ptr + p->cq_off.ring_entries;
526         cring->cqes = ptr + p->cq_off.cqes;
527         ld->cq_ring_mask = *cring->ring_mask;
528         return 0;
529 }
530
531 static int fio_ioring_queue_init(struct thread_data *td)
532 {
533         struct ioring_data *ld = td->io_ops_data;
534         struct ioring_options *o = td->eo;
535         int depth = td->o.iodepth;
536         struct io_uring_params p;
537         int ret;
538
539         memset(&p, 0, sizeof(p));
540
541         if (o->hipri)
542                 p.flags |= IORING_SETUP_IOPOLL;
543         if (o->sqpoll_thread) {
544                 p.flags |= IORING_SETUP_SQPOLL;
545                 if (o->sqpoll_set) {
546                         p.flags |= IORING_SETUP_SQ_AFF;
547                         p.sq_thread_cpu = o->sqpoll_cpu;
548                 }
549         }
550
551         ret = syscall(__NR_io_uring_setup, depth, &p);
552         if (ret < 0)
553                 return ret;
554
555         ld->ring_fd = ret;
556
557         if (o->fixedbufs) {
558                 struct rlimit rlim = {
559                         .rlim_cur = RLIM_INFINITY,
560                         .rlim_max = RLIM_INFINITY,
561                 };
562
563                 if (setrlimit(RLIMIT_MEMLOCK, &rlim) < 0)
564                         return -1;
565
566                 ret = syscall(__NR_io_uring_register, ld->ring_fd,
567                                 IORING_REGISTER_BUFFERS, ld->iovecs, depth);
568                 if (ret < 0)
569                         return ret;
570         }
571
572         return fio_ioring_mmap(ld, &p);
573 }
574
575 static int fio_ioring_register_files(struct thread_data *td)
576 {
577         struct ioring_data *ld = td->io_ops_data;
578         struct fio_file *f;
579         unsigned int i;
580         int ret;
581
582         ld->fds = calloc(td->o.nr_files, sizeof(int));
583
584         for_each_file(td, f, i) {
585                 ret = generic_open_file(td, f);
586                 if (ret)
587                         goto err;
588                 ld->fds[i] = f->fd;
589                 f->engine_pos = i;
590         }
591
592         ret = syscall(__NR_io_uring_register, ld->ring_fd,
593                         IORING_REGISTER_FILES, ld->fds, td->o.nr_files);
594         if (ret) {
595 err:
596                 free(ld->fds);
597                 ld->fds = NULL;
598         }
599
600         /*
601          * Pretend the file is closed again, and really close it if we hit
602          * an error.
603          */
604         for_each_file(td, f, i) {
605                 if (ret) {
606                         int fio_unused ret2;
607                         ret2 = generic_close_file(td, f);
608                 } else
609                         f->fd = -1;
610         }
611
612         return ret;
613 }
614
615 static int fio_ioring_post_init(struct thread_data *td)
616 {
617         struct ioring_data *ld = td->io_ops_data;
618         struct ioring_options *o = td->eo;
619         struct io_u *io_u;
620         int err, i;
621
622         for (i = 0; i < td->o.iodepth; i++) {
623                 struct iovec *iov = &ld->iovecs[i];
624
625                 io_u = ld->io_u_index[i];
626                 iov->iov_base = io_u->buf;
627                 iov->iov_len = td_max_bs(td);
628         }
629
630         err = fio_ioring_queue_init(td);
631         if (err) {
632                 td_verror(td, errno, "io_queue_init");
633                 return 1;
634         }
635
636         if (o->registerfiles) {
637                 err = fio_ioring_register_files(td);
638                 if (err) {
639                         td_verror(td, errno, "ioring_register_files");
640                         return 1;
641                 }
642         }
643
644         return 0;
645 }
646
647 static unsigned roundup_pow2(unsigned depth)
648 {
649         return 1UL << __fls(depth - 1);
650 }
651
652 static int fio_ioring_init(struct thread_data *td)
653 {
654         struct ioring_options *o = td->eo;
655         struct ioring_data *ld;
656         struct thread_options *to = &td->o;
657
658         /* sqthread submission requires registered files */
659         if (o->sqpoll_thread)
660                 o->registerfiles = 1;
661
662         if (o->registerfiles && td->o.nr_files != td->o.open_files) {
663                 log_err("fio: io_uring registered files require nr_files to "
664                         "be identical to open_files\n");
665                 return 1;
666         }
667
668         ld = calloc(1, sizeof(*ld));
669
670         /* ring depth must be a power-of-2 */
671         ld->iodepth = td->o.iodepth;
672         td->o.iodepth = roundup_pow2(td->o.iodepth);
673
674         /* io_u index */
675         ld->io_u_index = calloc(td->o.iodepth, sizeof(struct io_u *));
676         ld->iovecs = calloc(td->o.iodepth, sizeof(struct iovec));
677
678         td->io_ops_data = ld;
679
680         /*
681          * Check for option conflicts
682          */
683         if ((fio_option_is_set(to, ioprio) || fio_option_is_set(to, ioprio_class)) &&
684                         o->cmdprio_percentage != 0) {
685                 log_err("%s: cmdprio_percentage option and mutually exclusive "
686                                 "prio or prioclass option is set, exiting\n", to->name);
687                 td_verror(td, EINVAL, "fio_io_uring_init");
688                 return 1;
689         }
690         return 0;
691 }
692
693 static int fio_ioring_io_u_init(struct thread_data *td, struct io_u *io_u)
694 {
695         struct ioring_data *ld = td->io_ops_data;
696
697         ld->io_u_index[io_u->index] = io_u;
698         return 0;
699 }
700
701 static int fio_ioring_open_file(struct thread_data *td, struct fio_file *f)
702 {
703         struct ioring_data *ld = td->io_ops_data;
704         struct ioring_options *o = td->eo;
705
706         if (!ld || !o->registerfiles)
707                 return generic_open_file(td, f);
708
709         f->fd = ld->fds[f->engine_pos];
710         return 0;
711 }
712
713 static int fio_ioring_close_file(struct thread_data *td, struct fio_file *f)
714 {
715         struct ioring_data *ld = td->io_ops_data;
716         struct ioring_options *o = td->eo;
717
718         if (!ld || !o->registerfiles)
719                 return generic_close_file(td, f);
720
721         f->fd = -1;
722         return 0;
723 }
724
725 static struct ioengine_ops ioengine = {
726         .name                   = "io_uring",
727         .version                = FIO_IOOPS_VERSION,
728         .flags                  = FIO_ASYNCIO_SYNC_TRIM,
729         .init                   = fio_ioring_init,
730         .post_init              = fio_ioring_post_init,
731         .io_u_init              = fio_ioring_io_u_init,
732         .prep                   = fio_ioring_prep,
733         .queue                  = fio_ioring_queue,
734         .commit                 = fio_ioring_commit,
735         .getevents              = fio_ioring_getevents,
736         .event                  = fio_ioring_event,
737         .cleanup                = fio_ioring_cleanup,
738         .open_file              = fio_ioring_open_file,
739         .close_file             = fio_ioring_close_file,
740         .get_file_size          = generic_get_file_size,
741         .options                = options,
742         .option_struct_size     = sizeof(struct ioring_options),
743 };
744
745 static void fio_init fio_ioring_register(void)
746 {
747         register_ioengine(&ioengine);
748 }
749
750 static void fio_exit fio_ioring_unregister(void)
751 {
752         unregister_ioengine(&ioengine);
753 }
754 #endif