Jens Axboe | 2b188cc | 2019-01-07 10:46:33 -0700 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ |
| 2 | /* |
| 3 | * Header file for the io_uring interface. |
| 4 | * |
| 5 | * Copyright (C) 2019 Jens Axboe |
| 6 | * Copyright (C) 2019 Christoph Hellwig |
| 7 | */ |
| 8 | #ifndef LINUX_IO_URING_H |
| 9 | #define LINUX_IO_URING_H |
| 10 | |
| 11 | #include <linux/fs.h> |
| 12 | #include <linux/types.h> |
| 13 | |
| 14 | /* |
| 15 | * IO submission data structure (Submission Queue Entry) |
| 16 | */ |
| 17 | struct io_uring_sqe { |
| 18 | __u8 opcode; /* type of operation for this sqe */ |
Jens Axboe | 6b06314 | 2019-01-10 22:13:58 -0700 | [diff] [blame] | 19 | __u8 flags; /* IOSQE_ flags */ |
Jens Axboe | 2b188cc | 2019-01-07 10:46:33 -0700 | [diff] [blame] | 20 | __u16 ioprio; /* ioprio for the request */ |
| 21 | __s32 fd; /* file descriptor to do IO on */ |
Jens Axboe | 17f2fe3 | 2019-10-17 14:42:58 -0600 | [diff] [blame] | 22 | union { |
| 23 | __u64 off; /* offset into file */ |
| 24 | __u64 addr2; |
| 25 | }; |
Jens Axboe | 2b188cc | 2019-01-07 10:46:33 -0700 | [diff] [blame] | 26 | __u64 addr; /* pointer to buffer or iovecs */ |
| 27 | __u32 len; /* buffer size or number of iovecs */ |
| 28 | union { |
| 29 | __kernel_rwf_t rw_flags; |
Christoph Hellwig | c992fe2 | 2019-01-11 09:43:02 -0700 | [diff] [blame] | 30 | __u32 fsync_flags; |
Jens Axboe | 221c5eb | 2019-01-17 09:41:58 -0700 | [diff] [blame] | 31 | __u16 poll_events; |
Jens Axboe | 5d17b4a | 2019-04-09 14:56:44 -0600 | [diff] [blame] | 32 | __u32 sync_range_flags; |
Jens Axboe | 0fa03c6 | 2019-04-19 13:34:07 -0600 | [diff] [blame] | 33 | __u32 msg_flags; |
Jens Axboe | 5262f56 | 2019-09-17 12:26:57 -0600 | [diff] [blame] | 34 | __u32 timeout_flags; |
Jens Axboe | 17f2fe3 | 2019-10-17 14:42:58 -0600 | [diff] [blame] | 35 | __u32 accept_flags; |
Jens Axboe | 62755e3 | 2019-10-28 21:49:21 -0600 | [diff] [blame] | 36 | __u32 cancel_flags; |
Jens Axboe | 2b188cc | 2019-01-07 10:46:33 -0700 | [diff] [blame] | 37 | }; |
| 38 | __u64 user_data; /* data to be passed back at completion time */ |
Jens Axboe | edafcce | 2019-01-09 09:16:05 -0700 | [diff] [blame] | 39 | union { |
| 40 | __u16 buf_index; /* index into fixed buffers, if used */ |
| 41 | __u64 __pad2[3]; |
| 42 | }; |
Jens Axboe | 2b188cc | 2019-01-07 10:46:33 -0700 | [diff] [blame] | 43 | }; |
| 44 | |
Jens Axboe | def596e | 2019-01-09 08:59:42 -0700 | [diff] [blame] | 45 | /* |
Jens Axboe | 6b06314 | 2019-01-10 22:13:58 -0700 | [diff] [blame] | 46 | * sqe->flags |
| 47 | */ |
| 48 | #define IOSQE_FIXED_FILE (1U << 0) /* use fixed fileset */ |
Jens Axboe | de0617e | 2019-04-06 21:51:27 -0600 | [diff] [blame] | 49 | #define IOSQE_IO_DRAIN (1U << 1) /* issue after inflight IO */ |
Jens Axboe | 9e645e11 | 2019-05-10 16:07:28 -0600 | [diff] [blame] | 50 | #define IOSQE_IO_LINK (1U << 2) /* links next sqe */ |
Jens Axboe | 4e88d6e | 2019-12-07 20:59:47 -0700 | [diff] [blame] | 51 | #define IOSQE_IO_HARDLINK (1U << 3) /* like LINK, but stronger */ |
Jens Axboe | 6b06314 | 2019-01-10 22:13:58 -0700 | [diff] [blame] | 52 | |
| 53 | /* |
Jens Axboe | def596e | 2019-01-09 08:59:42 -0700 | [diff] [blame] | 54 | * io_uring_setup() flags |
| 55 | */ |
| 56 | #define IORING_SETUP_IOPOLL (1U << 0) /* io_context is polled */ |
Jens Axboe | 6c271ce | 2019-01-10 11:22:30 -0700 | [diff] [blame] | 57 | #define IORING_SETUP_SQPOLL (1U << 1) /* SQ poll thread */ |
| 58 | #define IORING_SETUP_SQ_AFF (1U << 2) /* sq_thread_cpu is valid */ |
Jens Axboe | 33a107f | 2019-10-04 12:10:03 -0600 | [diff] [blame] | 59 | #define IORING_SETUP_CQSIZE (1U << 3) /* app defines CQ size */ |
Jens Axboe | def596e | 2019-01-09 08:59:42 -0700 | [diff] [blame] | 60 | |
Jens Axboe | 9e3aa61 | 2019-12-11 15:55:43 -0700 | [diff] [blame] | 61 | enum { |
| 62 | IORING_OP_NOP, |
| 63 | IORING_OP_READV, |
| 64 | IORING_OP_WRITEV, |
| 65 | IORING_OP_FSYNC, |
| 66 | IORING_OP_READ_FIXED, |
| 67 | IORING_OP_WRITE_FIXED, |
| 68 | IORING_OP_POLL_ADD, |
| 69 | IORING_OP_POLL_REMOVE, |
| 70 | IORING_OP_SYNC_FILE_RANGE, |
| 71 | IORING_OP_SENDMSG, |
| 72 | IORING_OP_RECVMSG, |
| 73 | IORING_OP_TIMEOUT, |
| 74 | IORING_OP_TIMEOUT_REMOVE, |
| 75 | IORING_OP_ACCEPT, |
| 76 | IORING_OP_ASYNC_CANCEL, |
| 77 | IORING_OP_LINK_TIMEOUT, |
| 78 | IORING_OP_CONNECT, |
Jens Axboe | d63d1b5 | 2019-12-10 10:38:56 -0700 | [diff] [blame^] | 79 | IORING_OP_FALLOCATE, |
Jens Axboe | 9e3aa61 | 2019-12-11 15:55:43 -0700 | [diff] [blame] | 80 | |
| 81 | /* this goes last, obviously */ |
| 82 | IORING_OP_LAST, |
| 83 | }; |
Christoph Hellwig | c992fe2 | 2019-01-11 09:43:02 -0700 | [diff] [blame] | 84 | |
| 85 | /* |
| 86 | * sqe->fsync_flags |
| 87 | */ |
| 88 | #define IORING_FSYNC_DATASYNC (1U << 0) |
Jens Axboe | 2b188cc | 2019-01-07 10:46:33 -0700 | [diff] [blame] | 89 | |
| 90 | /* |
Jens Axboe | a41525a | 2019-10-15 16:48:15 -0600 | [diff] [blame] | 91 | * sqe->timeout_flags |
| 92 | */ |
| 93 | #define IORING_TIMEOUT_ABS (1U << 0) |
| 94 | |
| 95 | /* |
Jens Axboe | 2b188cc | 2019-01-07 10:46:33 -0700 | [diff] [blame] | 96 | * IO completion data structure (Completion Queue Entry) |
| 97 | */ |
| 98 | struct io_uring_cqe { |
| 99 | __u64 user_data; /* sqe->data submission passed back */ |
| 100 | __s32 res; /* result code for this event */ |
| 101 | __u32 flags; |
| 102 | }; |
| 103 | |
| 104 | /* |
| 105 | * Magic offsets for the application to mmap the data it needs |
| 106 | */ |
| 107 | #define IORING_OFF_SQ_RING 0ULL |
| 108 | #define IORING_OFF_CQ_RING 0x8000000ULL |
| 109 | #define IORING_OFF_SQES 0x10000000ULL |
| 110 | |
| 111 | /* |
| 112 | * Filled with the offset for mmap(2) |
| 113 | */ |
| 114 | struct io_sqring_offsets { |
| 115 | __u32 head; |
| 116 | __u32 tail; |
| 117 | __u32 ring_mask; |
| 118 | __u32 ring_entries; |
| 119 | __u32 flags; |
| 120 | __u32 dropped; |
| 121 | __u32 array; |
| 122 | __u32 resv1; |
| 123 | __u64 resv2; |
| 124 | }; |
| 125 | |
Jens Axboe | 6c271ce | 2019-01-10 11:22:30 -0700 | [diff] [blame] | 126 | /* |
| 127 | * sq_ring->flags |
| 128 | */ |
| 129 | #define IORING_SQ_NEED_WAKEUP (1U << 0) /* needs io_uring_enter wakeup */ |
| 130 | |
Jens Axboe | 2b188cc | 2019-01-07 10:46:33 -0700 | [diff] [blame] | 131 | struct io_cqring_offsets { |
| 132 | __u32 head; |
| 133 | __u32 tail; |
| 134 | __u32 ring_mask; |
| 135 | __u32 ring_entries; |
| 136 | __u32 overflow; |
| 137 | __u32 cqes; |
| 138 | __u64 resv[2]; |
| 139 | }; |
| 140 | |
| 141 | /* |
| 142 | * io_uring_enter(2) flags |
| 143 | */ |
| 144 | #define IORING_ENTER_GETEVENTS (1U << 0) |
Jens Axboe | 6c271ce | 2019-01-10 11:22:30 -0700 | [diff] [blame] | 145 | #define IORING_ENTER_SQ_WAKEUP (1U << 1) |
Jens Axboe | 2b188cc | 2019-01-07 10:46:33 -0700 | [diff] [blame] | 146 | |
| 147 | /* |
| 148 | * Passed in for io_uring_setup(2). Copied back with updated info on success |
| 149 | */ |
| 150 | struct io_uring_params { |
| 151 | __u32 sq_entries; |
| 152 | __u32 cq_entries; |
| 153 | __u32 flags; |
Jens Axboe | 6c271ce | 2019-01-10 11:22:30 -0700 | [diff] [blame] | 154 | __u32 sq_thread_cpu; |
| 155 | __u32 sq_thread_idle; |
Jens Axboe | ac90f24 | 2019-09-06 10:26:21 -0600 | [diff] [blame] | 156 | __u32 features; |
| 157 | __u32 resv[4]; |
Jens Axboe | 2b188cc | 2019-01-07 10:46:33 -0700 | [diff] [blame] | 158 | struct io_sqring_offsets sq_off; |
| 159 | struct io_cqring_offsets cq_off; |
| 160 | }; |
| 161 | |
Jens Axboe | edafcce | 2019-01-09 09:16:05 -0700 | [diff] [blame] | 162 | /* |
Jens Axboe | ac90f24 | 2019-09-06 10:26:21 -0600 | [diff] [blame] | 163 | * io_uring_params->features flags |
| 164 | */ |
| 165 | #define IORING_FEAT_SINGLE_MMAP (1U << 0) |
Jens Axboe | 1d7bb1d | 2019-11-06 11:31:17 -0700 | [diff] [blame] | 166 | #define IORING_FEAT_NODROP (1U << 1) |
Jens Axboe | da8c969 | 2019-12-02 18:51:26 -0700 | [diff] [blame] | 167 | #define IORING_FEAT_SUBMIT_STABLE (1U << 2) |
Jens Axboe | ac90f24 | 2019-09-06 10:26:21 -0600 | [diff] [blame] | 168 | |
| 169 | /* |
Jens Axboe | edafcce | 2019-01-09 09:16:05 -0700 | [diff] [blame] | 170 | * io_uring_register(2) opcodes and arguments |
| 171 | */ |
| 172 | #define IORING_REGISTER_BUFFERS 0 |
| 173 | #define IORING_UNREGISTER_BUFFERS 1 |
Jens Axboe | 6b06314 | 2019-01-10 22:13:58 -0700 | [diff] [blame] | 174 | #define IORING_REGISTER_FILES 2 |
| 175 | #define IORING_UNREGISTER_FILES 3 |
Jens Axboe | 9b40284 | 2019-04-11 11:45:41 -0600 | [diff] [blame] | 176 | #define IORING_REGISTER_EVENTFD 4 |
| 177 | #define IORING_UNREGISTER_EVENTFD 5 |
Jens Axboe | c3a31e6 | 2019-10-03 13:59:56 -0600 | [diff] [blame] | 178 | #define IORING_REGISTER_FILES_UPDATE 6 |
| 179 | |
| 180 | struct io_uring_files_update { |
| 181 | __u32 offset; |
Eugene Syromiatnikov | 1292e97 | 2020-01-15 17:35:38 +0100 | [diff] [blame] | 182 | __u32 resv; |
| 183 | __aligned_u64 /* __s32 * */ fds; |
Jens Axboe | c3a31e6 | 2019-10-03 13:59:56 -0600 | [diff] [blame] | 184 | }; |
Jens Axboe | edafcce | 2019-01-09 09:16:05 -0700 | [diff] [blame] | 185 | |
Jens Axboe | 2b188cc | 2019-01-07 10:46:33 -0700 | [diff] [blame] | 186 | #endif |