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_op_def io_op_defs[] = {
59 .unbound_nonreg_file = 1,
66 .async_size = sizeof(struct io_async_rw),
70 .prep_async = io_readv_prep_async,
71 .cleanup = io_readv_writev_cleanup,
73 [IORING_OP_WRITEV] = {
76 .unbound_nonreg_file = 1,
82 .async_size = sizeof(struct io_async_rw),
86 .prep_async = io_writev_prep_async,
87 .cleanup = io_readv_writev_cleanup,
93 .prep = io_fsync_prep,
96 [IORING_OP_READ_FIXED] = {
98 .unbound_nonreg_file = 1,
104 .async_size = sizeof(struct io_async_rw),
105 .name = "READ_FIXED",
109 [IORING_OP_WRITE_FIXED] = {
112 .unbound_nonreg_file = 1,
118 .async_size = sizeof(struct io_async_rw),
119 .name = "WRITE_FIXED",
123 [IORING_OP_POLL_ADD] = {
125 .unbound_nonreg_file = 1,
128 .prep = io_poll_add_prep,
129 .issue = io_poll_add,
131 [IORING_OP_POLL_REMOVE] = {
133 .name = "POLL_REMOVE",
134 .prep = io_poll_remove_prep,
135 .issue = io_poll_remove,
137 [IORING_OP_SYNC_FILE_RANGE] = {
140 .name = "SYNC_FILE_RANGE",
142 .issue = io_sync_file_range,
144 [IORING_OP_SENDMSG] = {
146 .unbound_nonreg_file = 1,
150 #if defined(CONFIG_NET)
151 .async_size = sizeof(struct io_async_msghdr),
152 .prep = io_sendmsg_prep,
154 .prep_async = io_sendmsg_prep_async,
155 .cleanup = io_sendmsg_recvmsg_cleanup,
157 .prep = io_eopnotsupp_prep,
160 [IORING_OP_RECVMSG] = {
162 .unbound_nonreg_file = 1,
167 #if defined(CONFIG_NET)
168 .async_size = sizeof(struct io_async_msghdr),
169 .prep = io_recvmsg_prep,
171 .prep_async = io_recvmsg_prep_async,
172 .cleanup = io_sendmsg_recvmsg_cleanup,
174 .prep = io_eopnotsupp_prep,
177 [IORING_OP_TIMEOUT] = {
179 .async_size = sizeof(struct io_timeout_data),
181 .prep = io_timeout_prep,
184 [IORING_OP_TIMEOUT_REMOVE] = {
185 /* used by timeout updates' prep() */
187 .name = "TIMEOUT_REMOVE",
188 .prep = io_timeout_remove_prep,
189 .issue = io_timeout_remove,
191 [IORING_OP_ACCEPT] = {
193 .unbound_nonreg_file = 1,
196 .ioprio = 1, /* used for flags */
198 #if defined(CONFIG_NET)
199 .prep = io_accept_prep,
202 .prep = io_eopnotsupp_prep,
205 [IORING_OP_ASYNC_CANCEL] = {
207 .name = "ASYNC_CANCEL",
208 .prep = io_async_cancel_prep,
209 .issue = io_async_cancel,
211 [IORING_OP_LINK_TIMEOUT] = {
213 .async_size = sizeof(struct io_timeout_data),
214 .name = "LINK_TIMEOUT",
215 .prep = io_link_timeout_prep,
216 .issue = io_no_issue,
218 [IORING_OP_CONNECT] = {
220 .unbound_nonreg_file = 1,
223 #if defined(CONFIG_NET)
224 .async_size = sizeof(struct io_async_connect),
225 .prep = io_connect_prep,
227 .prep_async = io_connect_prep_async,
229 .prep = io_eopnotsupp_prep,
232 [IORING_OP_FALLOCATE] = {
235 .prep = io_fallocate_prep,
236 .issue = io_fallocate,
238 [IORING_OP_OPENAT] = {
240 .prep = io_openat_prep,
242 .cleanup = io_open_cleanup,
244 [IORING_OP_CLOSE] = {
246 .prep = io_close_prep,
249 [IORING_OP_RSRC_UPDATE] = {
252 .name = "RSRC_UPDATE",
253 .prep = io_rsrc_update_prep,
254 .issue = io_rsrc_update,
257 [IORING_OP_STATX] = {
260 .prep = io_statx_prep,
262 .cleanup = io_statx_cleanup,
266 .unbound_nonreg_file = 1,
273 .async_size = sizeof(struct io_async_rw),
278 [IORING_OP_WRITE] = {
281 .unbound_nonreg_file = 1,
287 .async_size = sizeof(struct io_async_rw),
292 [IORING_OP_FADVISE] = {
296 .prep = io_fadvise_prep,
299 [IORING_OP_MADVISE] = {
301 .prep = io_madvise_prep,
306 .unbound_nonreg_file = 1,
311 #if defined(CONFIG_NET)
312 .prep = io_sendmsg_prep,
315 .prep = io_eopnotsupp_prep,
320 .unbound_nonreg_file = 1,
326 #if defined(CONFIG_NET)
327 .prep = io_recvmsg_prep,
330 .prep = io_eopnotsupp_prep,
333 [IORING_OP_OPENAT2] = {
335 .prep = io_openat2_prep,
337 .cleanup = io_open_cleanup,
339 [IORING_OP_EPOLL_CTL] = {
340 .unbound_nonreg_file = 1,
343 #if defined(CONFIG_EPOLL)
344 .prep = io_epoll_ctl_prep,
345 .issue = io_epoll_ctl,
347 .prep = io_eopnotsupp_prep,
350 [IORING_OP_SPLICE] = {
353 .unbound_nonreg_file = 1,
356 .prep = io_splice_prep,
359 [IORING_OP_PROVIDE_BUFFERS] = {
362 .name = "PROVIDE_BUFFERS",
363 .prep = io_provide_buffers_prep,
364 .issue = io_provide_buffers,
366 [IORING_OP_REMOVE_BUFFERS] = {
369 .name = "REMOVE_BUFFERS",
370 .prep = io_remove_buffers_prep,
371 .issue = io_remove_buffers,
376 .unbound_nonreg_file = 1,
382 [IORING_OP_SHUTDOWN] = {
385 #if defined(CONFIG_NET)
386 .prep = io_shutdown_prep,
387 .issue = io_shutdown,
389 .prep = io_eopnotsupp_prep,
392 [IORING_OP_RENAMEAT] = {
394 .prep = io_renameat_prep,
395 .issue = io_renameat,
396 .cleanup = io_renameat_cleanup,
398 [IORING_OP_UNLINKAT] = {
400 .prep = io_unlinkat_prep,
401 .issue = io_unlinkat,
402 .cleanup = io_unlinkat_cleanup,
404 [IORING_OP_MKDIRAT] = {
406 .prep = io_mkdirat_prep,
408 .cleanup = io_mkdirat_cleanup,
410 [IORING_OP_SYMLINKAT] = {
412 .prep = io_symlinkat_prep,
413 .issue = io_symlinkat,
414 .cleanup = io_link_cleanup,
416 [IORING_OP_LINKAT] = {
418 .prep = io_linkat_prep,
420 .cleanup = io_link_cleanup,
422 [IORING_OP_MSG_RING] = {
426 .prep = io_msg_ring_prep,
427 .issue = io_msg_ring,
429 [IORING_OP_FSETXATTR] = {
432 .prep = io_fsetxattr_prep,
433 .issue = io_fsetxattr,
434 .cleanup = io_xattr_cleanup,
436 [IORING_OP_SETXATTR] = {
438 .prep = io_setxattr_prep,
439 .issue = io_setxattr,
440 .cleanup = io_xattr_cleanup,
442 [IORING_OP_FGETXATTR] = {
445 .prep = io_fgetxattr_prep,
446 .issue = io_fgetxattr,
447 .cleanup = io_xattr_cleanup,
449 [IORING_OP_GETXATTR] = {
451 .prep = io_getxattr_prep,
452 .issue = io_getxattr,
453 .cleanup = io_xattr_cleanup,
455 [IORING_OP_SOCKET] = {
458 #if defined(CONFIG_NET)
459 .prep = io_socket_prep,
462 .prep = io_eopnotsupp_prep,
465 [IORING_OP_URING_CMD] = {
469 .async_size = uring_cmd_pdu_size(1),
470 .prep = io_uring_cmd_prep,
471 .issue = io_uring_cmd,
472 .prep_async = io_uring_cmd_prep_async,
474 [IORING_OP_SENDZC_NOTIF] = {
475 .name = "SENDZC_NOTIF",
477 .unbound_nonreg_file = 1,
482 #if defined(CONFIG_NET)
483 .async_size = sizeof(struct io_async_msghdr),
484 .prep = io_sendzc_prep,
486 .prep_async = io_sendzc_prep_async,
488 .prep = io_eopnotsupp_prep,
493 const char *io_uring_get_opcode(u8 opcode)
495 if (opcode < IORING_OP_LAST)
496 return io_op_defs[opcode].name;
500 void __init io_uring_optable_init(void)
504 BUILD_BUG_ON(ARRAY_SIZE(io_op_defs) != IORING_OP_LAST);
506 for (i = 0; i < ARRAY_SIZE(io_op_defs); i++) {
507 BUG_ON(!io_op_defs[i].prep);
508 if (io_op_defs[i].prep != io_eopnotsupp_prep)
509 BUG_ON(!io_op_defs[i].issue);
510 WARN_ON_ONCE(!io_op_defs[i].name);