blob: 43bc8a2edccf5aa347142fb05029a49241d2b97c [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,
19};
20
21struct io_uring_cmd {
22 struct file *file;
23 const void *cmd;
Kanchan Joshi5756a3a2022-08-23 21:44:41 +053024 union {
25 /* callback to defer completions to task context */
26 void (*task_work_cb)(struct io_uring_cmd *cmd);
27 /* used for polled completion */
28 void *cookie;
29 };
Jens Axboeee692a22022-05-11 11:17:45 +053030 u32 cmd_op;
Anuj Gupta9cda70f62022-09-30 11:57:39 +053031 u32 flags;
Jens Axboeee692a22022-05-11 11:17:45 +053032 u8 pdu[32]; /* available inline for free use */
33};
34
Jens Axboe0f212202020-09-13 13:09:39 -060035#if defined(CONFIG_IO_URING)
Anuj Guptaa9216fa2022-09-30 11:57:38 +053036int io_uring_cmd_import_fixed(u64 ubuf, unsigned long len, int rw,
37 struct iov_iter *iter, void *ioucmd);
Jens Axboeee692a22022-05-11 11:17:45 +053038void io_uring_cmd_done(struct io_uring_cmd *cmd, ssize_t ret, ssize_t res2);
39void io_uring_cmd_complete_in_task(struct io_uring_cmd *ioucmd,
40 void (*task_work_cb)(struct io_uring_cmd *));
Jens Axboea3ec6002020-09-18 20:41:00 -060041struct sock *io_uring_get_socket(struct file *file);
Hao Xuf552a272021-08-12 12:14:35 +080042void __io_uring_cancel(bool cancel_all);
Jens Axboe0f212202020-09-13 13:09:39 -060043void __io_uring_free(struct task_struct *tsk);
Jens Axboee7a6c002022-03-04 08:22:22 -070044void io_uring_unreg_ringfd(void);
Dylan Yudaken33337d02022-04-26 01:29:05 -070045const char *io_uring_get_opcode(u8 opcode);
Jens Axboe0f212202020-09-13 13:09:39 -060046
Hao Xuf552a272021-08-12 12:14:35 +080047static inline void io_uring_files_cancel(void)
Jens Axboe0f212202020-09-13 13:09:39 -060048{
Jens Axboee7a6c002022-03-04 08:22:22 -070049 if (current->io_uring) {
50 io_uring_unreg_ringfd();
Hao Xuf552a272021-08-12 12:14:35 +080051 __io_uring_cancel(false);
Jens Axboee7a6c002022-03-04 08:22:22 -070052 }
Pavel Begunkov3f48cf12021-04-11 01:46:27 +010053}
54static inline void io_uring_task_cancel(void)
55{
Hao Xua4aadd12021-08-12 12:14:34 +080056 if (current->io_uring)
Hao Xuf552a272021-08-12 12:14:35 +080057 __io_uring_cancel(true);
Jens Axboe0f212202020-09-13 13:09:39 -060058}
59static inline void io_uring_free(struct task_struct *tsk)
60{
61 if (tsk->io_uring)
62 __io_uring_free(tsk);
63}
64#else
Geert Uytterhoeven0e0abad2022-10-04 14:39:10 +020065static inline int io_uring_cmd_import_fixed(u64 ubuf, unsigned long len, int rw,
Anuj Guptaa9216fa2022-09-30 11:57:38 +053066 struct iov_iter *iter, void *ioucmd)
67{
68 return -EOPNOTSUPP;
69}
Jens Axboeee692a22022-05-11 11:17:45 +053070static inline void io_uring_cmd_done(struct io_uring_cmd *cmd, ssize_t ret,
71 ssize_t ret2)
72{
73}
74static inline void io_uring_cmd_complete_in_task(struct io_uring_cmd *ioucmd,
75 void (*task_work_cb)(struct io_uring_cmd *))
76{
77}
Jens Axboea3ec6002020-09-18 20:41:00 -060078static inline struct sock *io_uring_get_socket(struct file *file)
79{
80 return NULL;
81}
Jens Axboe0f212202020-09-13 13:09:39 -060082static inline void io_uring_task_cancel(void)
83{
84}
Hao Xuf552a272021-08-12 12:14:35 +080085static inline void io_uring_files_cancel(void)
Jens Axboe0f212202020-09-13 13:09:39 -060086{
87}
88static inline void io_uring_free(struct task_struct *tsk)
89{
90}
Dylan Yudaken33337d02022-04-26 01:29:05 -070091static inline const char *io_uring_get_opcode(u8 opcode)
92{
93 return "";
94}
Jens Axboe0f212202020-09-13 13:09:39 -060095#endif
96
97#endif