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_FILES_UPDATE] = {
252 .name = "FILES_UPDATE",
253 .prep = io_files_update_prep,
254 .issue = io_files_update,
256 [IORING_OP_STATX] = {
259 .prep = io_statx_prep,
261 .cleanup = io_statx_cleanup,
265 .unbound_nonreg_file = 1,
272 .async_size = sizeof(struct io_async_rw),
277 [IORING_OP_WRITE] = {
280 .unbound_nonreg_file = 1,
286 .async_size = sizeof(struct io_async_rw),
291 [IORING_OP_FADVISE] = {
295 .prep = io_fadvise_prep,
298 [IORING_OP_MADVISE] = {
300 .prep = io_madvise_prep,
305 .unbound_nonreg_file = 1,
310 #if defined(CONFIG_NET)
311 .prep = io_sendmsg_prep,
314 .prep = io_eopnotsupp_prep,
319 .unbound_nonreg_file = 1,
325 #if defined(CONFIG_NET)
326 .prep = io_recvmsg_prep,
329 .prep = io_eopnotsupp_prep,
332 [IORING_OP_OPENAT2] = {
334 .prep = io_openat2_prep,
336 .cleanup = io_open_cleanup,
338 [IORING_OP_EPOLL_CTL] = {
339 .unbound_nonreg_file = 1,
342 #if defined(CONFIG_EPOLL)
343 .prep = io_epoll_ctl_prep,
344 .issue = io_epoll_ctl,
346 .prep = io_eopnotsupp_prep,
349 [IORING_OP_SPLICE] = {
352 .unbound_nonreg_file = 1,
355 .prep = io_splice_prep,
358 [IORING_OP_PROVIDE_BUFFERS] = {
361 .name = "PROVIDE_BUFFERS",
362 .prep = io_provide_buffers_prep,
363 .issue = io_provide_buffers,
365 [IORING_OP_REMOVE_BUFFERS] = {
368 .name = "REMOVE_BUFFERS",
369 .prep = io_remove_buffers_prep,
370 .issue = io_remove_buffers,
375 .unbound_nonreg_file = 1,
381 [IORING_OP_SHUTDOWN] = {
384 #if defined(CONFIG_NET)
385 .prep = io_shutdown_prep,
386 .issue = io_shutdown,
388 .prep = io_eopnotsupp_prep,
391 [IORING_OP_RENAMEAT] = {
393 .prep = io_renameat_prep,
394 .issue = io_renameat,
395 .cleanup = io_renameat_cleanup,
397 [IORING_OP_UNLINKAT] = {
399 .prep = io_unlinkat_prep,
400 .issue = io_unlinkat,
401 .cleanup = io_unlinkat_cleanup,
403 [IORING_OP_MKDIRAT] = {
405 .prep = io_mkdirat_prep,
407 .cleanup = io_mkdirat_cleanup,
409 [IORING_OP_SYMLINKAT] = {
411 .prep = io_symlinkat_prep,
412 .issue = io_symlinkat,
413 .cleanup = io_link_cleanup,
415 [IORING_OP_LINKAT] = {
417 .prep = io_linkat_prep,
419 .cleanup = io_link_cleanup,
421 [IORING_OP_MSG_RING] = {
425 .prep = io_msg_ring_prep,
426 .issue = io_msg_ring,
428 [IORING_OP_FSETXATTR] = {
431 .prep = io_fsetxattr_prep,
432 .issue = io_fsetxattr,
433 .cleanup = io_xattr_cleanup,
435 [IORING_OP_SETXATTR] = {
437 .prep = io_setxattr_prep,
438 .issue = io_setxattr,
439 .cleanup = io_xattr_cleanup,
441 [IORING_OP_FGETXATTR] = {
444 .prep = io_fgetxattr_prep,
445 .issue = io_fgetxattr,
446 .cleanup = io_xattr_cleanup,
448 [IORING_OP_GETXATTR] = {
450 .prep = io_getxattr_prep,
451 .issue = io_getxattr,
452 .cleanup = io_xattr_cleanup,
454 [IORING_OP_SOCKET] = {
457 #if defined(CONFIG_NET)
458 .prep = io_socket_prep,
461 .prep = io_eopnotsupp_prep,
464 [IORING_OP_URING_CMD] = {
468 .async_size = uring_cmd_pdu_size(1),
469 .prep = io_uring_cmd_prep,
470 .issue = io_uring_cmd,
471 .prep_async = io_uring_cmd_prep_async,
473 [IORING_OP_SEND_ZC] = {
476 .unbound_nonreg_file = 1,
481 #if defined(CONFIG_NET)
482 .async_size = sizeof(struct io_async_msghdr),
483 .prep = io_sendzc_prep,
485 .prep_async = io_sendzc_prep_async,
486 .cleanup = io_sendzc_cleanup,
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);