Merge branch 'master' of https://github.com/donny372/fio into master
[fio.git] / os / linux / io_uring.h
1 /* SPDX-License-Identifier: (GPL-2.0 WITH Linux-syscall-note) OR MIT */
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 #ifdef __cplusplus
15 extern "C" {
16 #endif
17
18 /*
19  * IO submission data structure (Submission Queue Entry)
20  */
21 struct io_uring_sqe {
22         __u8    opcode;         /* type of operation for this sqe */
23         __u8    flags;          /* IOSQE_ flags */
24         __u16   ioprio;         /* ioprio for the request */
25         __s32   fd;             /* file descriptor to do IO on */
26         union {
27                 __u64   off;    /* offset into file */
28                 __u64   addr2;
29         };
30         union {
31                 __u64   addr;   /* pointer to buffer or iovecs */
32                 __u64   splice_off_in;
33         };
34         __u32   len;            /* buffer size or number of iovecs */
35         union {
36                 __kernel_rwf_t  rw_flags;
37                 __u32           fsync_flags;
38                 __u16           poll_events;    /* compatibility */
39                 __u32           poll32_events;  /* word-reversed for BE */
40                 __u32           sync_range_flags;
41                 __u32           msg_flags;
42                 __u32           timeout_flags;
43                 __u32           accept_flags;
44                 __u32           cancel_flags;
45                 __u32           open_flags;
46                 __u32           statx_flags;
47                 __u32           fadvise_advice;
48                 __u32           splice_flags;
49         };
50         __u64   user_data;      /* data to be passed back at completion time */
51         union {
52                 struct {
53                         /* pack this to avoid bogus arm OABI complaints */
54                         union {
55                                 /* index into fixed buffers, if used */
56                                 __u16   buf_index;
57                                 /* for grouped buffer selection */
58                                 __u16   buf_group;
59                         } __attribute__((packed));
60                         /* personality to use, if used */
61                         __u16   personality;
62                         __s32   splice_fd_in;
63                 };
64                 __u64   __pad2[3];
65         };
66 };
67
68 enum {
69         IOSQE_FIXED_FILE_BIT,
70         IOSQE_IO_DRAIN_BIT,
71         IOSQE_IO_LINK_BIT,
72         IOSQE_IO_HARDLINK_BIT,
73         IOSQE_ASYNC_BIT,
74         IOSQE_BUFFER_SELECT_BIT,
75 };
76
77 /*
78  * sqe->flags
79  */
80 /* use fixed fileset */
81 #define IOSQE_FIXED_FILE        (1U << IOSQE_FIXED_FILE_BIT)
82 /* issue after inflight IO */
83 #define IOSQE_IO_DRAIN          (1U << IOSQE_IO_DRAIN_BIT)
84 /* links next sqe */
85 #define IOSQE_IO_LINK           (1U << IOSQE_IO_LINK_BIT)
86 /* like LINK, but stronger */
87 #define IOSQE_IO_HARDLINK       (1U << IOSQE_IO_HARDLINK_BIT)
88 /* always go async */
89 #define IOSQE_ASYNC             (1U << IOSQE_ASYNC_BIT)
90 /* select buffer from sqe->buf_group */
91 #define IOSQE_BUFFER_SELECT     (1U << IOSQE_BUFFER_SELECT_BIT)
92
93 /*
94  * io_uring_setup() flags
95  */
96 #define IORING_SETUP_IOPOLL     (1U << 0)       /* io_context is polled */
97 #define IORING_SETUP_SQPOLL     (1U << 1)       /* SQ poll thread */
98 #define IORING_SETUP_SQ_AFF     (1U << 2)       /* sq_thread_cpu is valid */
99 #define IORING_SETUP_CQSIZE     (1U << 3)       /* app defines CQ size */
100 #define IORING_SETUP_CLAMP      (1U << 4)       /* clamp SQ/CQ ring sizes */
101 #define IORING_SETUP_ATTACH_WQ  (1U << 5)       /* attach to existing wq */
102
103 enum {
104         IORING_OP_NOP,
105         IORING_OP_READV,
106         IORING_OP_WRITEV,
107         IORING_OP_FSYNC,
108         IORING_OP_READ_FIXED,
109         IORING_OP_WRITE_FIXED,
110         IORING_OP_POLL_ADD,
111         IORING_OP_POLL_REMOVE,
112         IORING_OP_SYNC_FILE_RANGE,
113         IORING_OP_SENDMSG,
114         IORING_OP_RECVMSG,
115         IORING_OP_TIMEOUT,
116         IORING_OP_TIMEOUT_REMOVE,
117         IORING_OP_ACCEPT,
118         IORING_OP_ASYNC_CANCEL,
119         IORING_OP_LINK_TIMEOUT,
120         IORING_OP_CONNECT,
121         IORING_OP_FALLOCATE,
122         IORING_OP_OPENAT,
123         IORING_OP_CLOSE,
124         IORING_OP_FILES_UPDATE,
125         IORING_OP_STATX,
126         IORING_OP_READ,
127         IORING_OP_WRITE,
128         IORING_OP_FADVISE,
129         IORING_OP_MADVISE,
130         IORING_OP_SEND,
131         IORING_OP_RECV,
132         IORING_OP_OPENAT2,
133         IORING_OP_EPOLL_CTL,
134         IORING_OP_SPLICE,
135         IORING_OP_PROVIDE_BUFFERS,
136         IORING_OP_REMOVE_BUFFERS,
137         IORING_OP_TEE,
138
139         /* this goes last, obviously */
140         IORING_OP_LAST,
141 };
142
143 /*
144  * sqe->fsync_flags
145  */
146 #define IORING_FSYNC_DATASYNC   (1U << 0)
147
148 /*
149  * sqe->timeout_flags
150  */
151 #define IORING_TIMEOUT_ABS      (1U << 0)
152
153 /*
154  * sqe->splice_flags
155  * extends splice(2) flags
156  */
157 #define SPLICE_F_FD_IN_FIXED    (1U << 31) /* the last bit of __u32 */
158
159 /*
160  * IO completion data structure (Completion Queue Entry)
161  */
162 struct io_uring_cqe {
163         __u64   user_data;      /* sqe->data submission passed back */
164         __s32   res;            /* result code for this event */
165         __u32   flags;
166 };
167
168 /*
169  * cqe->flags
170  *
171  * IORING_CQE_F_BUFFER  If set, the upper 16 bits are the buffer ID
172  */
173 #define IORING_CQE_F_BUFFER             (1U << 0)
174
175 enum {
176         IORING_CQE_BUFFER_SHIFT         = 16,
177 };
178
179 /*
180  * Magic offsets for the application to mmap the data it needs
181  */
182 #define IORING_OFF_SQ_RING              0ULL
183 #define IORING_OFF_CQ_RING              0x8000000ULL
184 #define IORING_OFF_SQES                 0x10000000ULL
185
186 /*
187  * Filled with the offset for mmap(2)
188  */
189 struct io_sqring_offsets {
190         __u32 head;
191         __u32 tail;
192         __u32 ring_mask;
193         __u32 ring_entries;
194         __u32 flags;
195         __u32 dropped;
196         __u32 array;
197         __u32 resv1;
198         __u64 resv2;
199 };
200
201 /*
202  * sq_ring->flags
203  */
204 #define IORING_SQ_NEED_WAKEUP   (1U << 0) /* needs io_uring_enter wakeup */
205 #define IORING_SQ_CQ_OVERFLOW   (1U << 1) /* CQ ring is overflown */
206
207 struct io_cqring_offsets {
208         __u32 head;
209         __u32 tail;
210         __u32 ring_mask;
211         __u32 ring_entries;
212         __u32 overflow;
213         __u32 cqes;
214         __u32 flags;
215         __u32 resv1;
216         __u64 resv2;
217 };
218
219 /*
220  * cq_ring->flags
221  */
222
223 /* disable eventfd notifications */
224 #define IORING_CQ_EVENTFD_DISABLED      (1U << 0)
225
226 /*
227  * io_uring_enter(2) flags
228  */
229 #define IORING_ENTER_GETEVENTS  (1U << 0)
230 #define IORING_ENTER_SQ_WAKEUP  (1U << 1)
231
232 /*
233  * Passed in for io_uring_setup(2). Copied back with updated info on success
234  */
235 struct io_uring_params {
236         __u32 sq_entries;
237         __u32 cq_entries;
238         __u32 flags;
239         __u32 sq_thread_cpu;
240         __u32 sq_thread_idle;
241         __u32 features;
242         __u32 wq_fd;
243         __u32 resv[3];
244         struct io_sqring_offsets sq_off;
245         struct io_cqring_offsets cq_off;
246 };
247
248 /*
249  * io_uring_params->features flags
250  */
251 #define IORING_FEAT_SINGLE_MMAP         (1U << 0)
252 #define IORING_FEAT_NODROP              (1U << 1)
253 #define IORING_FEAT_SUBMIT_STABLE       (1U << 2)
254 #define IORING_FEAT_RW_CUR_POS          (1U << 3)
255 #define IORING_FEAT_CUR_PERSONALITY     (1U << 4)
256 #define IORING_FEAT_FAST_POLL           (1U << 5)
257 #define IORING_FEAT_POLL_32BITS         (1U << 6)
258
259 /*
260  * io_uring_register(2) opcodes and arguments
261  */
262 #define IORING_REGISTER_BUFFERS         0
263 #define IORING_UNREGISTER_BUFFERS       1
264 #define IORING_REGISTER_FILES           2
265 #define IORING_UNREGISTER_FILES         3
266 #define IORING_REGISTER_EVENTFD         4
267 #define IORING_UNREGISTER_EVENTFD       5
268 #define IORING_REGISTER_FILES_UPDATE    6
269 #define IORING_REGISTER_EVENTFD_ASYNC   7
270 #define IORING_REGISTER_PROBE           8
271 #define IORING_REGISTER_PERSONALITY     9
272 #define IORING_UNREGISTER_PERSONALITY   10
273
274 struct io_uring_files_update {
275         __u32 offset;
276         __u32 resv;
277         __aligned_u64 /* __s32 * */ fds;
278 };
279
280 #define IO_URING_OP_SUPPORTED   (1U << 0)
281
282 struct io_uring_probe_op {
283         __u8 op;
284         __u8 resv;
285         __u16 flags;    /* IO_URING_OP_* flags */
286         __u32 resv2;
287 };
288
289 struct io_uring_probe {
290         __u8 last_op;   /* last opcode supported */
291         __u8 ops_len;   /* length of ops[] array below */
292         __u16 resv;
293         __u32 resv2[3];
294         struct io_uring_probe_op ops[0];
295 };
296
297 #ifdef __cplusplus
298 }
299 #endif
300
301 #endif