Commit | Line | Data |
---|---|---|
e27f928e JA |
1 | #ifndef IO_URING_TYPES_H |
2 | #define IO_URING_TYPES_H | |
3 | ||
4 | #include <linux/blkdev.h> | |
5 | #include <linux/task_work.h> | |
d9b57aa3 | 6 | #include <linux/bitmap.h> |
e70cb608 | 7 | #include <linux/llist.h> |
d9b57aa3 | 8 | #include <uapi/linux/io_uring.h> |
e27f928e | 9 | |
ab1c84d8 PB |
10 | struct io_wq_work_node { |
11 | struct io_wq_work_node *next; | |
12 | }; | |
13 | ||
14 | struct io_wq_work_list { | |
15 | struct io_wq_work_node *first; | |
16 | struct io_wq_work_node *last; | |
17 | }; | |
18 | ||
19 | struct io_wq_work { | |
20 | struct io_wq_work_node list; | |
21 | unsigned flags; | |
22 | /* place it here instead of io_kiocb as it fills padding and saves 4B */ | |
23 | int cancel_seq; | |
24 | }; | |
25 | ||
26 | struct io_fixed_file { | |
27 | /* file * with additional FFS_* flags */ | |
28 | unsigned long file_ptr; | |
29 | }; | |
30 | ||
31 | struct io_file_table { | |
32 | struct io_fixed_file *files; | |
33 | unsigned long *bitmap; | |
34 | unsigned int alloc_hint; | |
35 | }; | |
e27f928e | 36 | |
e6f89be6 PB |
37 | struct io_hash_bucket { |
38 | spinlock_t lock; | |
39 | struct hlist_head list; | |
40 | } ____cacheline_aligned_in_smp; | |
41 | ||
42 | struct io_hash_table { | |
43 | struct io_hash_bucket *hbs; | |
44 | unsigned hash_bits; | |
45 | }; | |
46 | ||
e70cb608 PB |
47 | /* |
48 | * Arbitrary limit, can be raised if need be | |
49 | */ | |
50 | #define IO_RINGFD_REG_MAX 16 | |
51 | ||
52 | struct io_uring_task { | |
53 | /* submission side */ | |
54 | int cached_refs; | |
55 | const struct io_ring_ctx *last; | |
56 | struct io_wq *io_wq; | |
57 | struct file *registered_rings[IO_RINGFD_REG_MAX]; | |
58 | ||
59 | struct xarray xa; | |
60 | struct wait_queue_head wait; | |
8d664282 | 61 | atomic_t in_cancel; |
e70cb608 PB |
62 | atomic_t inflight_tracked; |
63 | struct percpu_counter inflight; | |
64 | ||
65 | struct { /* task_work */ | |
66 | struct llist_head task_list; | |
67 | struct callback_head task_work; | |
68 | } ____cacheline_aligned_in_smp; | |
69 | }; | |
70 | ||
e27f928e JA |
71 | struct io_uring { |
72 | u32 head ____cacheline_aligned_in_smp; | |
73 | u32 tail ____cacheline_aligned_in_smp; | |
74 | }; | |
75 | ||
76 | /* | |
77 | * This data is shared with the application through the mmap at offsets | |
78 | * IORING_OFF_SQ_RING and IORING_OFF_CQ_RING. | |
79 | * | |
80 | * The offsets to the member fields are published through struct | |
81 | * io_sqring_offsets when calling io_uring_setup. | |
82 | */ | |
83 | struct io_rings { | |
84 | /* | |
85 | * Head and tail offsets into the ring; the offsets need to be | |
86 | * masked to get valid indices. | |
87 | * | |
88 | * The kernel controls head of the sq ring and the tail of the cq ring, | |
89 | * and the application controls tail of the sq ring and the head of the | |
90 | * cq ring. | |
91 | */ | |
92 | struct io_uring sq, cq; | |
93 | /* | |
94 | * Bitmasks to apply to head and tail offsets (constant, equals | |
95 | * ring_entries - 1) | |
96 | */ | |
97 | u32 sq_ring_mask, cq_ring_mask; | |
98 | /* Ring sizes (constant, power of 2) */ | |
99 | u32 sq_ring_entries, cq_ring_entries; | |
100 | /* | |
101 | * Number of invalid entries dropped by the kernel due to | |
102 | * invalid index stored in array | |
103 | * | |
104 | * Written by the kernel, shouldn't be modified by the | |
105 | * application (i.e. get number of "new events" by comparing to | |
106 | * cached value). | |
107 | * | |
108 | * After a new SQ head value was read by the application this | |
109 | * counter includes all submissions that were dropped reaching | |
110 | * the new SQ head (and possibly more). | |
111 | */ | |
112 | u32 sq_dropped; | |
113 | /* | |
114 | * Runtime SQ flags | |
115 | * | |
116 | * Written by the kernel, shouldn't be modified by the | |
117 | * application. | |
118 | * | |
119 | * The application needs a full memory barrier before checking | |
120 | * for IORING_SQ_NEED_WAKEUP after updating the sq tail. | |
121 | */ | |
122 | atomic_t sq_flags; | |
123 | /* | |
124 | * Runtime CQ flags | |
125 | * | |
126 | * Written by the application, shouldn't be modified by the | |
127 | * kernel. | |
128 | */ | |
129 | u32 cq_flags; | |
130 | /* | |
131 | * Number of completion events lost because the queue was full; | |
132 | * this should be avoided by the application by making sure | |
133 | * there are not more requests pending than there is space in | |
134 | * the completion queue. | |
135 | * | |
136 | * Written by the kernel, shouldn't be modified by the | |
137 | * application (i.e. get number of "new events" by comparing to | |
138 | * cached value). | |
139 | * | |
140 | * As completion events come in out of order this counter is not | |
141 | * ordered with any other data. | |
142 | */ | |
143 | u32 cq_overflow; | |
144 | /* | |
145 | * Ring buffer of completion events. | |
146 | * | |
147 | * The kernel writes completion events fresh every time they are | |
148 | * produced, so the application is allowed to modify pending | |
149 | * entries. | |
150 | */ | |
151 | struct io_uring_cqe cqes[] ____cacheline_aligned_in_smp; | |
152 | }; | |
153 | ||
154 | struct io_restriction { | |
155 | DECLARE_BITMAP(register_op, IORING_REGISTER_LAST); | |
156 | DECLARE_BITMAP(sqe_op, IORING_OP_LAST); | |
157 | u8 sqe_flags_allowed; | |
158 | u8 sqe_flags_required; | |
159 | bool registered; | |
160 | }; | |
161 | ||
162 | struct io_submit_link { | |
163 | struct io_kiocb *head; | |
164 | struct io_kiocb *last; | |
165 | }; | |
166 | ||
167 | struct io_submit_state { | |
168 | /* inline/task_work completion list, under ->uring_lock */ | |
169 | struct io_wq_work_node free_list; | |
170 | /* batch completion logic */ | |
171 | struct io_wq_work_list compl_reqs; | |
172 | struct io_submit_link link; | |
173 | ||
174 | bool plug_started; | |
175 | bool need_plug; | |
e27f928e | 176 | unsigned short submit_nr; |
931147dd | 177 | unsigned int cqes_count; |
e27f928e | 178 | struct blk_plug plug; |
931147dd | 179 | struct io_uring_cqe cqes[16]; |
e27f928e JA |
180 | }; |
181 | ||
182 | struct io_ev_fd { | |
183 | struct eventfd_ctx *cq_ev_fd; | |
184 | unsigned int eventfd_async: 1; | |
185 | struct rcu_head rcu; | |
21a091b9 DY |
186 | atomic_t refs; |
187 | atomic_t ops; | |
e27f928e JA |
188 | }; |
189 | ||
9b797a37 | 190 | struct io_alloc_cache { |
efba1a9e | 191 | struct io_wq_work_node list; |
9731bc98 | 192 | unsigned int nr_cached; |
69bbc6ad | 193 | unsigned int max_cached; |
e1fe7ee8 | 194 | size_t elem_size; |
9b797a37 JA |
195 | }; |
196 | ||
e27f928e JA |
197 | struct io_ring_ctx { |
198 | /* const or read-mostly hot data */ | |
199 | struct { | |
e27f928e | 200 | unsigned int flags; |
e27f928e JA |
201 | unsigned int drain_next: 1; |
202 | unsigned int restricted: 1; | |
203 | unsigned int off_timeout_used: 1; | |
204 | unsigned int drain_active: 1; | |
e27f928e | 205 | unsigned int has_evfd: 1; |
e6aeb272 PB |
206 | /* all CQEs should be posted only by the submitter task */ |
207 | unsigned int task_complete: 1; | |
632ffe09 | 208 | unsigned int syscall_iopoll: 1; |
bca39f39 | 209 | unsigned int poll_activated: 1; |
632ffe09 PB |
210 | unsigned int drain_disabled: 1; |
211 | unsigned int compat: 1; | |
dde40322 PB |
212 | |
213 | enum task_work_notify_mode notify_method; | |
214 | struct io_rings *rings; | |
215 | struct task_struct *submitter_task; | |
216 | struct percpu_ref refs; | |
e27f928e JA |
217 | } ____cacheline_aligned_in_smp; |
218 | ||
219 | /* submission data */ | |
220 | struct { | |
221 | struct mutex uring_lock; | |
222 | ||
223 | /* | |
224 | * Ring buffer of indices into array of io_uring_sqe, which is | |
225 | * mmapped by the application using the IORING_OFF_SQES offset. | |
226 | * | |
227 | * This indirection could e.g. be used to assign fixed | |
228 | * io_uring_sqe entries to operations and only submit them to | |
229 | * the queue when needed. | |
230 | * | |
231 | * The kernel modifies neither the indices array nor the entries | |
232 | * array. | |
233 | */ | |
234 | u32 *sq_array; | |
235 | struct io_uring_sqe *sq_sqes; | |
236 | unsigned cached_sq_head; | |
237 | unsigned sq_entries; | |
e27f928e JA |
238 | |
239 | /* | |
240 | * Fixed resources fast path, should be accessed only under | |
241 | * uring_lock, and updated through io_uring_register(2) | |
242 | */ | |
243 | struct io_rsrc_node *rsrc_node; | |
e27f928e JA |
244 | atomic_t cancel_seq; |
245 | struct io_file_table file_table; | |
246 | unsigned nr_user_files; | |
247 | unsigned nr_user_bufs; | |
248 | struct io_mapped_ubuf **user_bufs; | |
249 | ||
250 | struct io_submit_state submit_state; | |
251 | ||
252 | struct io_buffer_list *io_bl; | |
253 | struct xarray io_bl_xa; | |
254 | struct list_head io_buffers_cache; | |
255 | ||
9ca9fb24 | 256 | struct io_hash_table cancel_table_locked; |
e27f928e | 257 | struct list_head cq_overflow_list; |
9b797a37 | 258 | struct io_alloc_cache apoll_cache; |
43e0bbbd | 259 | struct io_alloc_cache netmsg_cache; |
e27f928e JA |
260 | } ____cacheline_aligned_in_smp; |
261 | ||
262 | /* IRQ completion list, under ->completion_lock */ | |
263 | struct io_wq_work_list locked_free_list; | |
264 | unsigned int locked_free_nr; | |
265 | ||
266 | const struct cred *sq_creds; /* cred used for __io_sq_thread() */ | |
267 | struct io_sq_data *sq_data; /* if using sq thread polling */ | |
268 | ||
269 | struct wait_queue_head sqo_sq_wait; | |
270 | struct list_head sqd_list; | |
271 | ||
272 | unsigned long check_cq; | |
273 | ||
6e73dffb PB |
274 | unsigned int file_alloc_start; |
275 | unsigned int file_alloc_end; | |
276 | ||
43e0bbbd JA |
277 | struct xarray personalities; |
278 | u32 pers_next; | |
279 | ||
e27f928e JA |
280 | struct { |
281 | /* | |
282 | * We cache a range of free CQEs we can use, once exhausted it | |
283 | * should go through a slower range setup, see __io_get_cqe() | |
284 | */ | |
285 | struct io_uring_cqe *cqe_cached; | |
286 | struct io_uring_cqe *cqe_sentinel; | |
287 | ||
288 | unsigned cached_cq_tail; | |
289 | unsigned cq_entries; | |
290 | struct io_ev_fd __rcu *io_ev_fd; | |
291 | struct wait_queue_head cq_wait; | |
292 | unsigned cq_extra; | |
e27f928e JA |
293 | } ____cacheline_aligned_in_smp; |
294 | ||
295 | struct { | |
296 | spinlock_t completion_lock; | |
297 | ||
59b745bb | 298 | bool poll_multi_queue; |
8751d154 | 299 | atomic_t cq_wait_nr; |
59b745bb | 300 | |
e27f928e JA |
301 | /* |
302 | * ->iopoll_list is protected by the ctx->uring_lock for | |
303 | * io_uring instances that don't use IORING_SETUP_SQPOLL. | |
304 | * For SQPOLL, only the single threaded io_sq_thread() will | |
305 | * manipulate the list, hence no extra locking is needed there. | |
306 | */ | |
307 | struct io_wq_work_list iopoll_list; | |
e6f89be6 | 308 | struct io_hash_table cancel_table; |
e27f928e | 309 | |
c0e0d6ba DY |
310 | struct llist_head work_llist; |
311 | ||
e27f928e JA |
312 | struct list_head io_buffers_comp; |
313 | } ____cacheline_aligned_in_smp; | |
314 | ||
aff5b2df PB |
315 | /* timeouts */ |
316 | struct { | |
317 | spinlock_t timeout_lock; | |
318 | atomic_t cq_timeouts; | |
319 | struct list_head timeout_list; | |
320 | struct list_head ltimeout_list; | |
321 | unsigned cq_last_tm_flush; | |
322 | } ____cacheline_aligned_in_smp; | |
323 | ||
e27f928e | 324 | /* Keep this last, we don't need it for the fast path */ |
7b235dd8 | 325 | struct wait_queue_head poll_wq; |
22eb2a3f PB |
326 | struct io_restriction restrictions; |
327 | ||
328 | /* slow path rsrc auxilary data, used by update/register */ | |
22eb2a3f PB |
329 | struct io_mapped_ubuf *dummy_ubuf; |
330 | struct io_rsrc_data *file_data; | |
331 | struct io_rsrc_data *buf_data; | |
332 | ||
0a4813b1 | 333 | /* protected by ->uring_lock */ |
22eb2a3f | 334 | struct list_head rsrc_ref_list; |
9eae8655 | 335 | struct io_alloc_cache rsrc_node_cache; |
4ea15b56 | 336 | struct wait_queue_head rsrc_quiesce_wq; |
0b222eeb | 337 | unsigned rsrc_quiesce; |
22eb2a3f PB |
338 | |
339 | struct list_head io_buffers_pages; | |
340 | ||
341 | #if defined(CONFIG_UNIX) | |
342 | struct socket *ring_sock; | |
343 | #endif | |
344 | /* hashed buffered write serialization */ | |
345 | struct io_wq_hash *hash_map; | |
346 | ||
347 | /* Only used for accounting purposes */ | |
348 | struct user_struct *user; | |
349 | struct mm_struct *mm_account; | |
350 | ||
351 | /* ctx exit and cancelation */ | |
352 | struct llist_head fallback_llist; | |
353 | struct delayed_work fallback_work; | |
354 | struct work_struct exit_work; | |
355 | struct list_head tctx_list; | |
356 | struct completion ref_comp; | |
357 | ||
358 | /* io-wq management, e.g. thread count */ | |
359 | u32 iowq_limits[2]; | |
360 | bool iowq_limits_set; | |
361 | ||
bca39f39 | 362 | struct callback_head poll_wq_task_work; |
22eb2a3f PB |
363 | struct list_head defer_list; |
364 | unsigned sq_thread_idle; | |
305bef98 PB |
365 | /* protected by ->completion_lock */ |
366 | unsigned evfd_last_cq_tail; | |
e27f928e JA |
367 | }; |
368 | ||
a282967c PB |
369 | struct io_tw_state { |
370 | /* ->uring_lock is taken, callbacks can use io_tw_lock to lock it */ | |
371 | bool locked; | |
372 | }; | |
373 | ||
e27f928e JA |
374 | enum { |
375 | REQ_F_FIXED_FILE_BIT = IOSQE_FIXED_FILE_BIT, | |
376 | REQ_F_IO_DRAIN_BIT = IOSQE_IO_DRAIN_BIT, | |
377 | REQ_F_LINK_BIT = IOSQE_IO_LINK_BIT, | |
378 | REQ_F_HARDLINK_BIT = IOSQE_IO_HARDLINK_BIT, | |
379 | REQ_F_FORCE_ASYNC_BIT = IOSQE_ASYNC_BIT, | |
380 | REQ_F_BUFFER_SELECT_BIT = IOSQE_BUFFER_SELECT_BIT, | |
381 | REQ_F_CQE_SKIP_BIT = IOSQE_CQE_SKIP_SUCCESS_BIT, | |
382 | ||
383 | /* first byte is taken by user flags, shift it to not overlap */ | |
384 | REQ_F_FAIL_BIT = 8, | |
385 | REQ_F_INFLIGHT_BIT, | |
386 | REQ_F_CUR_POS_BIT, | |
387 | REQ_F_NOWAIT_BIT, | |
388 | REQ_F_LINK_TIMEOUT_BIT, | |
389 | REQ_F_NEED_CLEANUP_BIT, | |
390 | REQ_F_POLLED_BIT, | |
391 | REQ_F_BUFFER_SELECTED_BIT, | |
392 | REQ_F_BUFFER_RING_BIT, | |
e27f928e JA |
393 | REQ_F_REISSUE_BIT, |
394 | REQ_F_CREDS_BIT, | |
395 | REQ_F_REFCOUNT_BIT, | |
396 | REQ_F_ARM_LTIMEOUT_BIT, | |
397 | REQ_F_ASYNC_DATA_BIT, | |
398 | REQ_F_SKIP_LINK_CQES_BIT, | |
399 | REQ_F_SINGLE_POLL_BIT, | |
400 | REQ_F_DOUBLE_POLL_BIT, | |
401 | REQ_F_PARTIAL_IO_BIT, | |
402 | REQ_F_CQE32_INIT_BIT, | |
403 | REQ_F_APOLL_MULTISHOT_BIT, | |
404 | REQ_F_CLEAR_POLLIN_BIT, | |
9ca9fb24 | 405 | REQ_F_HASH_LOCKED_BIT, |
e27f928e JA |
406 | /* keep async read/write and isreg together and in order */ |
407 | REQ_F_SUPPORT_NOWAIT_BIT, | |
408 | REQ_F_ISREG_BIT, | |
409 | ||
410 | /* not a real bit, just to check we're not overflowing the space */ | |
411 | __REQ_F_LAST_BIT, | |
412 | }; | |
413 | ||
414 | enum { | |
415 | /* ctx owns file */ | |
416 | REQ_F_FIXED_FILE = BIT(REQ_F_FIXED_FILE_BIT), | |
417 | /* drain existing IO first */ | |
418 | REQ_F_IO_DRAIN = BIT(REQ_F_IO_DRAIN_BIT), | |
419 | /* linked sqes */ | |
420 | REQ_F_LINK = BIT(REQ_F_LINK_BIT), | |
421 | /* doesn't sever on completion < 0 */ | |
422 | REQ_F_HARDLINK = BIT(REQ_F_HARDLINK_BIT), | |
423 | /* IOSQE_ASYNC */ | |
424 | REQ_F_FORCE_ASYNC = BIT(REQ_F_FORCE_ASYNC_BIT), | |
425 | /* IOSQE_BUFFER_SELECT */ | |
426 | REQ_F_BUFFER_SELECT = BIT(REQ_F_BUFFER_SELECT_BIT), | |
427 | /* IOSQE_CQE_SKIP_SUCCESS */ | |
428 | REQ_F_CQE_SKIP = BIT(REQ_F_CQE_SKIP_BIT), | |
429 | ||
430 | /* fail rest of links */ | |
431 | REQ_F_FAIL = BIT(REQ_F_FAIL_BIT), | |
432 | /* on inflight list, should be cancelled and waited on exit reliably */ | |
433 | REQ_F_INFLIGHT = BIT(REQ_F_INFLIGHT_BIT), | |
434 | /* read/write uses file position */ | |
435 | REQ_F_CUR_POS = BIT(REQ_F_CUR_POS_BIT), | |
436 | /* must not punt to workers */ | |
437 | REQ_F_NOWAIT = BIT(REQ_F_NOWAIT_BIT), | |
438 | /* has or had linked timeout */ | |
439 | REQ_F_LINK_TIMEOUT = BIT(REQ_F_LINK_TIMEOUT_BIT), | |
440 | /* needs cleanup */ | |
441 | REQ_F_NEED_CLEANUP = BIT(REQ_F_NEED_CLEANUP_BIT), | |
442 | /* already went through poll handler */ | |
443 | REQ_F_POLLED = BIT(REQ_F_POLLED_BIT), | |
444 | /* buffer already selected */ | |
445 | REQ_F_BUFFER_SELECTED = BIT(REQ_F_BUFFER_SELECTED_BIT), | |
446 | /* buffer selected from ring, needs commit */ | |
447 | REQ_F_BUFFER_RING = BIT(REQ_F_BUFFER_RING_BIT), | |
e27f928e JA |
448 | /* caller should reissue async */ |
449 | REQ_F_REISSUE = BIT(REQ_F_REISSUE_BIT), | |
450 | /* supports async reads/writes */ | |
451 | REQ_F_SUPPORT_NOWAIT = BIT(REQ_F_SUPPORT_NOWAIT_BIT), | |
452 | /* regular file */ | |
453 | REQ_F_ISREG = BIT(REQ_F_ISREG_BIT), | |
454 | /* has creds assigned */ | |
455 | REQ_F_CREDS = BIT(REQ_F_CREDS_BIT), | |
456 | /* skip refcounting if not set */ | |
457 | REQ_F_REFCOUNT = BIT(REQ_F_REFCOUNT_BIT), | |
458 | /* there is a linked timeout that has to be armed */ | |
459 | REQ_F_ARM_LTIMEOUT = BIT(REQ_F_ARM_LTIMEOUT_BIT), | |
460 | /* ->async_data allocated */ | |
461 | REQ_F_ASYNC_DATA = BIT(REQ_F_ASYNC_DATA_BIT), | |
462 | /* don't post CQEs while failing linked requests */ | |
463 | REQ_F_SKIP_LINK_CQES = BIT(REQ_F_SKIP_LINK_CQES_BIT), | |
464 | /* single poll may be active */ | |
465 | REQ_F_SINGLE_POLL = BIT(REQ_F_SINGLE_POLL_BIT), | |
466 | /* double poll may active */ | |
467 | REQ_F_DOUBLE_POLL = BIT(REQ_F_DOUBLE_POLL_BIT), | |
468 | /* request has already done partial IO */ | |
469 | REQ_F_PARTIAL_IO = BIT(REQ_F_PARTIAL_IO_BIT), | |
470 | /* fast poll multishot mode */ | |
471 | REQ_F_APOLL_MULTISHOT = BIT(REQ_F_APOLL_MULTISHOT_BIT), | |
472 | /* ->extra1 and ->extra2 are initialised */ | |
473 | REQ_F_CQE32_INIT = BIT(REQ_F_CQE32_INIT_BIT), | |
474 | /* recvmsg special flag, clear EPOLLIN */ | |
475 | REQ_F_CLEAR_POLLIN = BIT(REQ_F_CLEAR_POLLIN_BIT), | |
9ca9fb24 PB |
476 | /* hashed into ->cancel_hash_locked, protected by ->uring_lock */ |
477 | REQ_F_HASH_LOCKED = BIT(REQ_F_HASH_LOCKED_BIT), | |
e27f928e JA |
478 | }; |
479 | ||
a282967c | 480 | typedef void (*io_req_tw_func_t)(struct io_kiocb *req, struct io_tw_state *ts); |
e27f928e JA |
481 | |
482 | struct io_task_work { | |
3218e5d3 | 483 | struct llist_node node; |
e27f928e JA |
484 | io_req_tw_func_t func; |
485 | }; | |
486 | ||
487 | struct io_cqe { | |
488 | __u64 user_data; | |
489 | __s32 res; | |
490 | /* fd initially, then cflags for completion */ | |
491 | union { | |
492 | __u32 flags; | |
493 | int fd; | |
494 | }; | |
495 | }; | |
496 | ||
497 | /* | |
498 | * Each request type overlays its private data structure on top of this one. | |
499 | * They must not exceed this one in size. | |
500 | */ | |
501 | struct io_cmd_data { | |
502 | struct file *file; | |
503 | /* each command gets 56 bytes of data */ | |
504 | __u8 data[56]; | |
505 | }; | |
506 | ||
f2ccb5ae SM |
507 | static inline void io_kiocb_cmd_sz_check(size_t cmd_sz) |
508 | { | |
509 | BUILD_BUG_ON(cmd_sz > sizeof(struct io_cmd_data)); | |
510 | } | |
511 | #define io_kiocb_to_cmd(req, cmd_type) ( \ | |
512 | io_kiocb_cmd_sz_check(sizeof(cmd_type)) , \ | |
513 | ((cmd_type *)&(req)->cmd) \ | |
514 | ) | |
e27f928e JA |
515 | #define cmd_to_io_kiocb(ptr) ((struct io_kiocb *) ptr) |
516 | ||
517 | struct io_kiocb { | |
518 | union { | |
519 | /* | |
520 | * NOTE! Each of the io_kiocb union members has the file pointer | |
521 | * as the first entry in their struct definition. So you can | |
522 | * access the file pointer through any of the sub-structs, | |
523 | * or directly as just 'file' in this struct. | |
524 | */ | |
525 | struct file *file; | |
526 | struct io_cmd_data cmd; | |
527 | }; | |
528 | ||
529 | u8 opcode; | |
530 | /* polled IO has completed */ | |
531 | u8 iopoll_completed; | |
532 | /* | |
533 | * Can be either a fixed buffer index, or used with provided buffers. | |
534 | * For the latter, before issue it points to the buffer group ID, | |
535 | * and after selection it points to the buffer ID itself. | |
536 | */ | |
537 | u16 buf_index; | |
538 | unsigned int flags; | |
539 | ||
540 | struct io_cqe cqe; | |
541 | ||
542 | struct io_ring_ctx *ctx; | |
543 | struct task_struct *task; | |
544 | ||
545 | struct io_rsrc_node *rsrc_node; | |
546 | ||
547 | union { | |
548 | /* store used ubuf, so we can prevent reloading */ | |
549 | struct io_mapped_ubuf *imu; | |
550 | ||
551 | /* stores selected buf, valid IFF REQ_F_BUFFER_SELECTED is set */ | |
552 | struct io_buffer *kbuf; | |
553 | ||
554 | /* | |
555 | * stores buffer ID for ring provided buffers, valid IFF | |
556 | * REQ_F_BUFFER_RING is set. | |
557 | */ | |
558 | struct io_buffer_list *buf_list; | |
559 | }; | |
560 | ||
561 | union { | |
562 | /* used by request caches, completion batching and iopoll */ | |
563 | struct io_wq_work_node comp_list; | |
564 | /* cache ->apoll->events */ | |
565 | __poll_t apoll_events; | |
566 | }; | |
567 | atomic_t refs; | |
568 | atomic_t poll_refs; | |
569 | struct io_task_work io_task_work; | |
8751d154 | 570 | unsigned nr_tw; |
e27f928e JA |
571 | /* for polled requests, i.e. IORING_OP_POLL_ADD and async armed poll */ |
572 | union { | |
573 | struct hlist_node hash_node; | |
574 | struct { | |
575 | u64 extra1; | |
576 | u64 extra2; | |
577 | }; | |
578 | }; | |
579 | /* internal polling, see IORING_FEAT_FAST_POLL */ | |
580 | struct async_poll *apoll; | |
581 | /* opcode allocated if it needs to store data for async defer */ | |
582 | void *async_data; | |
583 | /* linked requests, IFF REQ_F_HARDLINK or REQ_F_LINK are set */ | |
584 | struct io_kiocb *link; | |
585 | /* custom credentials, valid IFF REQ_F_CREDS is set */ | |
586 | const struct cred *creds; | |
587 | struct io_wq_work work; | |
588 | }; | |
589 | ||
a4ad4f74 JA |
590 | struct io_overflow_cqe { |
591 | struct list_head list; | |
592 | struct io_uring_cqe cqe; | |
593 | }; | |
594 | ||
e27f928e | 595 | #endif |