1 // SPDX-License-Identifier: GPL-2.0
3 * io_uring opcode handling table
5 #include <linux/kernel.h>
6 #include <linux/errno.h>
8 #include <linux/file.h>
9 #include <linux/io_uring.h>
26 #include "openclose.h"
27 #include "uring_cmd.h"
37 static int io_no_issue(struct io_kiocb
*req
, unsigned int issue_flags
)
43 static __maybe_unused
int io_eopnotsupp_prep(struct io_kiocb
*kiocb
,
44 const struct io_uring_sqe
*sqe
)
49 const struct io_issue_def io_issue_defs
[] = {
58 .unbound_nonreg_file
= 1,
69 [IORING_OP_WRITEV
] = {
72 .unbound_nonreg_file
= 1,
85 .prep
= io_fsync_prep
,
88 [IORING_OP_READ_FIXED
] = {
90 .unbound_nonreg_file
= 1,
100 [IORING_OP_WRITE_FIXED
] = {
103 .unbound_nonreg_file
= 1,
113 [IORING_OP_POLL_ADD
] = {
115 .unbound_nonreg_file
= 1,
117 .prep
= io_poll_add_prep
,
118 .issue
= io_poll_add
,
120 [IORING_OP_POLL_REMOVE
] = {
122 .prep
= io_poll_remove_prep
,
123 .issue
= io_poll_remove
,
125 [IORING_OP_SYNC_FILE_RANGE
] = {
129 .issue
= io_sync_file_range
,
131 [IORING_OP_SENDMSG
] = {
133 .unbound_nonreg_file
= 1,
137 #if defined(CONFIG_NET)
138 .prep
= io_sendmsg_prep
,
141 .prep
= io_eopnotsupp_prep
,
144 [IORING_OP_RECVMSG
] = {
146 .unbound_nonreg_file
= 1,
151 #if defined(CONFIG_NET)
152 .prep
= io_recvmsg_prep
,
155 .prep
= io_eopnotsupp_prep
,
158 [IORING_OP_TIMEOUT
] = {
160 .prep
= io_timeout_prep
,
163 [IORING_OP_TIMEOUT_REMOVE
] = {
164 /* used by timeout updates' prep() */
166 .prep
= io_timeout_remove_prep
,
167 .issue
= io_timeout_remove
,
169 [IORING_OP_ACCEPT
] = {
171 .unbound_nonreg_file
= 1,
174 .ioprio
= 1, /* used for flags */
175 #if defined(CONFIG_NET)
176 .prep
= io_accept_prep
,
179 .prep
= io_eopnotsupp_prep
,
182 [IORING_OP_ASYNC_CANCEL
] = {
184 .prep
= io_async_cancel_prep
,
185 .issue
= io_async_cancel
,
187 [IORING_OP_LINK_TIMEOUT
] = {
189 .prep
= io_link_timeout_prep
,
190 .issue
= io_no_issue
,
192 [IORING_OP_CONNECT
] = {
194 .unbound_nonreg_file
= 1,
196 #if defined(CONFIG_NET)
197 .prep
= io_connect_prep
,
200 .prep
= io_eopnotsupp_prep
,
203 [IORING_OP_FALLOCATE
] = {
205 .prep
= io_fallocate_prep
,
206 .issue
= io_fallocate
,
208 [IORING_OP_OPENAT
] = {
209 .prep
= io_openat_prep
,
212 [IORING_OP_CLOSE
] = {
213 .prep
= io_close_prep
,
216 [IORING_OP_FILES_UPDATE
] = {
219 .prep
= io_files_update_prep
,
220 .issue
= io_files_update
,
222 [IORING_OP_STATX
] = {
224 .prep
= io_statx_prep
,
229 .unbound_nonreg_file
= 1,
240 [IORING_OP_WRITE
] = {
243 .unbound_nonreg_file
= 1,
253 [IORING_OP_FADVISE
] = {
256 .prep
= io_fadvise_prep
,
259 [IORING_OP_MADVISE
] = {
261 .prep
= io_madvise_prep
,
266 .unbound_nonreg_file
= 1,
271 #if defined(CONFIG_NET)
272 .prep
= io_sendmsg_prep
,
275 .prep
= io_eopnotsupp_prep
,
280 .unbound_nonreg_file
= 1,
285 #if defined(CONFIG_NET)
286 .prep
= io_recvmsg_prep
,
289 .prep
= io_eopnotsupp_prep
,
292 [IORING_OP_OPENAT2
] = {
293 .prep
= io_openat2_prep
,
296 [IORING_OP_EPOLL_CTL
] = {
297 .unbound_nonreg_file
= 1,
299 #if defined(CONFIG_EPOLL)
300 .prep
= io_epoll_ctl_prep
,
301 .issue
= io_epoll_ctl
,
303 .prep
= io_eopnotsupp_prep
,
306 [IORING_OP_SPLICE
] = {
309 .unbound_nonreg_file
= 1,
311 .prep
= io_splice_prep
,
314 [IORING_OP_PROVIDE_BUFFERS
] = {
317 .prep
= io_provide_buffers_prep
,
318 .issue
= io_provide_buffers
,
320 [IORING_OP_REMOVE_BUFFERS
] = {
323 .prep
= io_remove_buffers_prep
,
324 .issue
= io_remove_buffers
,
329 .unbound_nonreg_file
= 1,
334 [IORING_OP_SHUTDOWN
] = {
336 #if defined(CONFIG_NET)
337 .prep
= io_shutdown_prep
,
338 .issue
= io_shutdown
,
340 .prep
= io_eopnotsupp_prep
,
343 [IORING_OP_RENAMEAT
] = {
344 .prep
= io_renameat_prep
,
345 .issue
= io_renameat
,
347 [IORING_OP_UNLINKAT
] = {
348 .prep
= io_unlinkat_prep
,
349 .issue
= io_unlinkat
,
351 [IORING_OP_MKDIRAT
] = {
352 .prep
= io_mkdirat_prep
,
355 [IORING_OP_SYMLINKAT
] = {
356 .prep
= io_symlinkat_prep
,
357 .issue
= io_symlinkat
,
359 [IORING_OP_LINKAT
] = {
360 .prep
= io_linkat_prep
,
363 [IORING_OP_MSG_RING
] = {
366 .prep
= io_msg_ring_prep
,
367 .issue
= io_msg_ring
,
369 [IORING_OP_FSETXATTR
] = {
371 .prep
= io_fsetxattr_prep
,
372 .issue
= io_fsetxattr
,
374 [IORING_OP_SETXATTR
] = {
375 .prep
= io_setxattr_prep
,
376 .issue
= io_setxattr
,
378 [IORING_OP_FGETXATTR
] = {
380 .prep
= io_fgetxattr_prep
,
381 .issue
= io_fgetxattr
,
383 [IORING_OP_GETXATTR
] = {
384 .prep
= io_getxattr_prep
,
385 .issue
= io_getxattr
,
387 [IORING_OP_SOCKET
] = {
389 #if defined(CONFIG_NET)
390 .prep
= io_socket_prep
,
393 .prep
= io_eopnotsupp_prep
,
396 [IORING_OP_URING_CMD
] = {
401 .prep
= io_uring_cmd_prep
,
402 .issue
= io_uring_cmd
,
404 [IORING_OP_SEND_ZC
] = {
406 .unbound_nonreg_file
= 1,
411 #if defined(CONFIG_NET)
412 .prep
= io_send_zc_prep
,
415 .prep
= io_eopnotsupp_prep
,
418 [IORING_OP_SENDMSG_ZC
] = {
420 .unbound_nonreg_file
= 1,
424 #if defined(CONFIG_NET)
425 .prep
= io_send_zc_prep
,
426 .issue
= io_sendmsg_zc
,
428 .prep
= io_eopnotsupp_prep
,
434 const struct io_cold_def io_cold_defs
[] = {
438 [IORING_OP_READV
] = {
439 .async_size
= sizeof(struct io_async_rw
),
441 .prep_async
= io_readv_prep_async
,
442 .cleanup
= io_readv_writev_cleanup
,
445 [IORING_OP_WRITEV
] = {
446 .async_size
= sizeof(struct io_async_rw
),
448 .prep_async
= io_writev_prep_async
,
449 .cleanup
= io_readv_writev_cleanup
,
452 [IORING_OP_FSYNC
] = {
455 [IORING_OP_READ_FIXED
] = {
456 .async_size
= sizeof(struct io_async_rw
),
457 .name
= "READ_FIXED",
460 [IORING_OP_WRITE_FIXED
] = {
461 .async_size
= sizeof(struct io_async_rw
),
462 .name
= "WRITE_FIXED",
465 [IORING_OP_POLL_ADD
] = {
468 [IORING_OP_POLL_REMOVE
] = {
469 .name
= "POLL_REMOVE",
471 [IORING_OP_SYNC_FILE_RANGE
] = {
472 .name
= "SYNC_FILE_RANGE",
474 [IORING_OP_SENDMSG
] = {
476 #if defined(CONFIG_NET)
477 .async_size
= sizeof(struct io_async_msghdr
),
478 .prep_async
= io_sendmsg_prep_async
,
479 .cleanup
= io_sendmsg_recvmsg_cleanup
,
480 .fail
= io_sendrecv_fail
,
483 [IORING_OP_RECVMSG
] = {
485 #if defined(CONFIG_NET)
486 .async_size
= sizeof(struct io_async_msghdr
),
487 .prep_async
= io_recvmsg_prep_async
,
488 .cleanup
= io_sendmsg_recvmsg_cleanup
,
489 .fail
= io_sendrecv_fail
,
492 [IORING_OP_TIMEOUT
] = {
493 .async_size
= sizeof(struct io_timeout_data
),
496 [IORING_OP_TIMEOUT_REMOVE
] = {
497 .name
= "TIMEOUT_REMOVE",
499 [IORING_OP_ACCEPT
] = {
502 [IORING_OP_ASYNC_CANCEL
] = {
503 .name
= "ASYNC_CANCEL",
505 [IORING_OP_LINK_TIMEOUT
] = {
506 .async_size
= sizeof(struct io_timeout_data
),
507 .name
= "LINK_TIMEOUT",
509 [IORING_OP_CONNECT
] = {
511 #if defined(CONFIG_NET)
512 .async_size
= sizeof(struct io_async_connect
),
513 .prep_async
= io_connect_prep_async
,
516 [IORING_OP_FALLOCATE
] = {
519 [IORING_OP_OPENAT
] = {
521 .cleanup
= io_open_cleanup
,
523 [IORING_OP_CLOSE
] = {
526 [IORING_OP_FILES_UPDATE
] = {
527 .name
= "FILES_UPDATE",
529 [IORING_OP_STATX
] = {
531 .cleanup
= io_statx_cleanup
,
534 .async_size
= sizeof(struct io_async_rw
),
538 [IORING_OP_WRITE
] = {
539 .async_size
= sizeof(struct io_async_rw
),
543 [IORING_OP_FADVISE
] = {
546 [IORING_OP_MADVISE
] = {
551 #if defined(CONFIG_NET)
552 .async_size
= sizeof(struct io_async_msghdr
),
553 .fail
= io_sendrecv_fail
,
554 .prep_async
= io_send_prep_async
,
559 #if defined(CONFIG_NET)
560 .fail
= io_sendrecv_fail
,
563 [IORING_OP_OPENAT2
] = {
565 .cleanup
= io_open_cleanup
,
567 [IORING_OP_EPOLL_CTL
] = {
570 [IORING_OP_SPLICE
] = {
573 [IORING_OP_PROVIDE_BUFFERS
] = {
574 .name
= "PROVIDE_BUFFERS",
576 [IORING_OP_REMOVE_BUFFERS
] = {
577 .name
= "REMOVE_BUFFERS",
582 [IORING_OP_SHUTDOWN
] = {
585 [IORING_OP_RENAMEAT
] = {
587 .cleanup
= io_renameat_cleanup
,
589 [IORING_OP_UNLINKAT
] = {
591 .cleanup
= io_unlinkat_cleanup
,
593 [IORING_OP_MKDIRAT
] = {
595 .cleanup
= io_mkdirat_cleanup
,
597 [IORING_OP_SYMLINKAT
] = {
599 .cleanup
= io_link_cleanup
,
601 [IORING_OP_LINKAT
] = {
603 .cleanup
= io_link_cleanup
,
605 [IORING_OP_MSG_RING
] = {
607 .cleanup
= io_msg_ring_cleanup
,
609 [IORING_OP_FSETXATTR
] = {
611 .cleanup
= io_xattr_cleanup
,
613 [IORING_OP_SETXATTR
] = {
615 .cleanup
= io_xattr_cleanup
,
617 [IORING_OP_FGETXATTR
] = {
619 .cleanup
= io_xattr_cleanup
,
621 [IORING_OP_GETXATTR
] = {
623 .cleanup
= io_xattr_cleanup
,
625 [IORING_OP_SOCKET
] = {
628 [IORING_OP_URING_CMD
] = {
630 .async_size
= 2 * sizeof(struct io_uring_sqe
),
631 .prep_async
= io_uring_cmd_prep_async
,
633 [IORING_OP_SEND_ZC
] = {
635 #if defined(CONFIG_NET)
636 .async_size
= sizeof(struct io_async_msghdr
),
637 .prep_async
= io_send_prep_async
,
638 .cleanup
= io_send_zc_cleanup
,
639 .fail
= io_sendrecv_fail
,
642 [IORING_OP_SENDMSG_ZC
] = {
643 .name
= "SENDMSG_ZC",
644 #if defined(CONFIG_NET)
645 .async_size
= sizeof(struct io_async_msghdr
),
646 .prep_async
= io_sendmsg_prep_async
,
647 .cleanup
= io_send_zc_cleanup
,
648 .fail
= io_sendrecv_fail
,
653 const char *io_uring_get_opcode(u8 opcode
)
655 if (opcode
< IORING_OP_LAST
)
656 return io_cold_defs
[opcode
].name
;
660 void __init
io_uring_optable_init(void)
664 BUILD_BUG_ON(ARRAY_SIZE(io_cold_defs
) != IORING_OP_LAST
);
665 BUILD_BUG_ON(ARRAY_SIZE(io_issue_defs
) != IORING_OP_LAST
);
667 for (i
= 0; i
< ARRAY_SIZE(io_issue_defs
); i
++) {
668 BUG_ON(!io_issue_defs
[i
].prep
);
669 if (io_issue_defs
[i
].prep
!= io_eopnotsupp_prep
)
670 BUG_ON(!io_issue_defs
[i
].issue
);
671 WARN_ON_ONCE(!io_cold_defs
[i
].name
);