blob: a8f3058448eaa1253fc0354baa834c360be0bcd6 [file] [log] [blame]
Jens Axboe0f212202020-09-13 13:09:39 -06001/* SPDX-License-Identifier: GPL-2.0-or-later */
2#ifndef _LINUX_IO_URING_H
3#define _LINUX_IO_URING_H
4
5#include <linux/sched.h>
6#include <linux/xarray.h>
Anuj Guptaa9216fa2022-09-30 11:57:38 +05307#include <uapi/linux/io_uring.h>
Jens Axboe98447d62020-10-14 10:48:51 -06008
Jens Axboeee692a22022-05-11 11:17:45 +05309enum io_uring_cmd_flags {
10 IO_URING_F_COMPLETE_DEFER = 1,
11 IO_URING_F_UNLOCKED = 2,
12 /* int's last bit, sign checks are usually faster than a bit test */
13 IO_URING_F_NONBLOCK = INT_MIN,
14
15 /* ctx state flags, for URING_CMD */
16 IO_URING_F_SQE128 = 4,
17 IO_URING_F_CQE32 = 8,
18 IO_URING_F_IOPOLL = 16,
Pavel Begunkov91482862022-11-17 18:40:16 +000019
20 /* the request is executed from poll, it should not be freed */
21 IO_URING_F_MULTISHOT = 32,
Jens Axboeee692a22022-05-11 11:17:45 +053022};
23
24struct io_uring_cmd {
25 struct file *file;
26 const void *cmd;
Kanchan Joshi5756a3a2022-08-23 21:44:41 +053027 union {
28 /* callback to defer completions to task context */
Jens Axboee5da1182023-03-20 20:01:25 -060029 void (*task_work_cb)(struct io_uring_cmd *cmd, unsigned);
Kanchan Joshi5756a3a2022-08-23 21:44:41 +053030 /* used for polled completion */
31 void *cookie;
32 };
Jens Axboeee692a22022-05-11 11:17:45 +053033 u32 cmd_op;
Anuj Gupta9cda70f62022-09-30 11:57:39 +053034 u32 flags;
Jens Axboeee692a22022-05-11 11:17:45 +053035 u8 pdu[32]; /* available inline for free use */
36};
37
Jens Axboe0f212202020-09-13 13:09:39 -060038#if defined(CONFIG_IO_URING)
Anuj Guptaa9216fa2022-09-30 11:57:38 +053039int io_uring_cmd_import_fixed(u64 ubuf, unsigned long len, int rw,
40 struct iov_iter *iter, void *ioucmd);
Jens Axboee5da1182023-03-20 20:01:25 -060041void io_uring_cmd_done(struct io_uring_cmd *cmd, ssize_t ret, ssize_t res2,
42 unsigned issue_flags);
Jens Axboeee692a22022-05-11 11:17:45 +053043void io_uring_cmd_complete_in_task(struct io_uring_cmd *ioucmd,
Jens Axboee5da1182023-03-20 20:01:25 -060044 void (*task_work_cb)(struct io_uring_cmd *, unsigned));
Hao Xuf552a272021-08-12 12:14:35 +080045void __io_uring_cancel(bool cancel_all);
Jens Axboe0f212202020-09-13 13:09:39 -060046void __io_uring_free(struct task_struct *tsk);
Jens Axboee7a6c002022-03-04 08:22:22 -070047void io_uring_unreg_ringfd(void);
Dylan Yudaken33337d02022-04-26 01:29:05 -070048const char *io_uring_get_opcode(u8 opcode);
Jens Axboe28fe81b2024-03-13 18:10:12 -060049bool io_is_uring_fops(struct file *file);
Jens Axboe0f212202020-09-13 13:09:39 -060050
Hao Xuf552a272021-08-12 12:14:35 +080051static inline void io_uring_files_cancel(void)
Jens Axboe0f212202020-09-13 13:09:39 -060052{
Jens Axboee7a6c002022-03-04 08:22:22 -070053 if (current->io_uring) {
54 io_uring_unreg_ringfd();
Hao Xuf552a272021-08-12 12:14:35 +080055 __io_uring_cancel(false);
Jens Axboee7a6c002022-03-04 08:22:22 -070056 }
Pavel Begunkov3f48cf12021-04-11 01:46:27 +010057}
58static inline void io_uring_task_cancel(void)
59{
Hao Xua4aadd12021-08-12 12:14:34 +080060 if (current->io_uring)
Hao Xuf552a272021-08-12 12:14:35 +080061 __io_uring_cancel(true);
Jens Axboe0f212202020-09-13 13:09:39 -060062}
63static inline void io_uring_free(struct task_struct *tsk)
64{
65 if (tsk->io_uring)
66 __io_uring_free(tsk);
67}
68#else
Geert Uytterhoeven0e0abad2022-10-04 14:39:10 +020069static inline int io_uring_cmd_import_fixed(u64 ubuf, unsigned long len, int rw,
Anuj Guptaa9216fa2022-09-30 11:57:38 +053070 struct iov_iter *iter, void *ioucmd)
71{
72 return -EOPNOTSUPP;
73}
Jens Axboe28fe81b2024-03-13 18:10:12 -060074static inline bool io_is_uring_fops(struct file *file)
75{
76 return false;
77}
Jens Axboeee692a22022-05-11 11:17:45 +053078static inline void io_uring_cmd_done(struct io_uring_cmd *cmd, ssize_t ret,
Jens Axboee5da1182023-03-20 20:01:25 -060079 ssize_t ret2, unsigned issue_flags)
Jens Axboeee692a22022-05-11 11:17:45 +053080{
81}
82static inline void io_uring_cmd_complete_in_task(struct io_uring_cmd *ioucmd,
Jens Axboee5da1182023-03-20 20:01:25 -060083 void (*task_work_cb)(struct io_uring_cmd *, unsigned))
Jens Axboeee692a22022-05-11 11:17:45 +053084{
85}
Jens Axboe0f212202020-09-13 13:09:39 -060086static inline void io_uring_task_cancel(void)
87{
88}
Hao Xuf552a272021-08-12 12:14:35 +080089static inline void io_uring_files_cancel(void)
Jens Axboe0f212202020-09-13 13:09:39 -060090{
91}
92static inline void io_uring_free(struct task_struct *tsk)
93{
94}
Dylan Yudaken33337d02022-04-26 01:29:05 -070095static inline const char *io_uring_get_opcode(u8 opcode)
96{
97 return "";
98}
Jens Axboe0f212202020-09-13 13:09:39 -060099#endif
100
101#endif