xref: /linux/include/linux/io_uring/cmd.h (revision be239684b18e1cdcafcf8c7face4a2f562c745ad)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 #ifndef _LINUX_IO_URING_CMD_H
3 #define _LINUX_IO_URING_CMD_H
4 
5 #include <uapi/linux/io_uring.h>
6 #include <linux/io_uring_types.h>
7 
8 /* only top 8 bits of sqe->uring_cmd_flags for kernel internal use */
9 #define IORING_URING_CMD_CANCELABLE	(1U << 30)
10 
11 struct io_uring_cmd {
12 	struct file	*file;
13 	const struct io_uring_sqe *sqe;
14 	/* callback to defer completions to task context */
15 	void (*task_work_cb)(struct io_uring_cmd *cmd, unsigned);
16 	u32		cmd_op;
17 	u32		flags;
18 	u8		pdu[32]; /* available inline for free use */
19 };
20 
21 static inline const void *io_uring_sqe_cmd(const struct io_uring_sqe *sqe)
22 {
23 	return sqe->cmd;
24 }
25 
26 #if defined(CONFIG_IO_URING)
27 int io_uring_cmd_import_fixed(u64 ubuf, unsigned long len, int rw,
28 			      struct iov_iter *iter, void *ioucmd);
29 void io_uring_cmd_done(struct io_uring_cmd *cmd, ssize_t ret, ssize_t res2,
30 			unsigned issue_flags);
31 void __io_uring_cmd_do_in_task(struct io_uring_cmd *ioucmd,
32 			    void (*task_work_cb)(struct io_uring_cmd *, unsigned),
33 			    unsigned flags);
34 
35 void io_uring_cmd_mark_cancelable(struct io_uring_cmd *cmd,
36 		unsigned int issue_flags);
37 
38 #else
39 static inline int io_uring_cmd_import_fixed(u64 ubuf, unsigned long len, int rw,
40 			      struct iov_iter *iter, void *ioucmd)
41 {
42 	return -EOPNOTSUPP;
43 }
44 static inline void io_uring_cmd_done(struct io_uring_cmd *cmd, ssize_t ret,
45 		ssize_t ret2, unsigned issue_flags)
46 {
47 }
48 static inline void __io_uring_cmd_do_in_task(struct io_uring_cmd *ioucmd,
49 			    void (*task_work_cb)(struct io_uring_cmd *, unsigned),
50 			    unsigned flags)
51 {
52 }
53 static inline void io_uring_cmd_mark_cancelable(struct io_uring_cmd *cmd,
54 		unsigned int issue_flags)
55 {
56 }
57 #endif
58 
59 /* users must follow the IOU_F_TWQ_LAZY_WAKE semantics */
60 static inline void io_uring_cmd_do_in_task_lazy(struct io_uring_cmd *ioucmd,
61 			void (*task_work_cb)(struct io_uring_cmd *, unsigned))
62 {
63 	__io_uring_cmd_do_in_task(ioucmd, task_work_cb, IOU_F_TWQ_LAZY_WAKE);
64 }
65 
66 static inline void io_uring_cmd_complete_in_task(struct io_uring_cmd *ioucmd,
67 			void (*task_work_cb)(struct io_uring_cmd *, unsigned))
68 {
69 	__io_uring_cmd_do_in_task(ioucmd, task_work_cb, 0);
70 }
71 
72 static inline struct task_struct *io_uring_cmd_get_task(struct io_uring_cmd *cmd)
73 {
74 	return cmd_to_io_kiocb(cmd)->task;
75 }
76 
77 #endif /* _LINUX_IO_URING_CMD_H */
78