io_uring.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. #ifndef _LINUX_IO_URING_H
  3. #define _LINUX_IO_URING_H
  4. #include <linux/sched.h>
  5. #include <linux/xarray.h>
  6. #include <uapi/linux/io_uring.h>
  7. enum io_uring_cmd_flags {
  8. IO_URING_F_COMPLETE_DEFER = 1,
  9. IO_URING_F_UNLOCKED = 2,
  10. /* int's last bit, sign checks are usually faster than a bit test */
  11. IO_URING_F_NONBLOCK = INT_MIN,
  12. /* ctx state flags, for URING_CMD */
  13. IO_URING_F_SQE128 = 4,
  14. IO_URING_F_CQE32 = 8,
  15. IO_URING_F_IOPOLL = 16,
  16. /* the request is executed from poll, it should not be freed */
  17. IO_URING_F_MULTISHOT = 32,
  18. };
  19. struct io_uring_cmd {
  20. struct file *file;
  21. const void *cmd;
  22. union {
  23. /* callback to defer completions to task context */
  24. void (*task_work_cb)(struct io_uring_cmd *cmd, unsigned);
  25. /* used for polled completion */
  26. void *cookie;
  27. };
  28. u32 cmd_op;
  29. u32 flags;
  30. u8 pdu[32]; /* available inline for free use */
  31. };
  32. #if defined(CONFIG_IO_URING)
  33. int io_uring_cmd_import_fixed(u64 ubuf, unsigned long len, int rw,
  34. struct iov_iter *iter, void *ioucmd);
  35. void io_uring_cmd_done(struct io_uring_cmd *cmd, ssize_t ret, ssize_t res2,
  36. unsigned issue_flags);
  37. void io_uring_cmd_complete_in_task(struct io_uring_cmd *ioucmd,
  38. void (*task_work_cb)(struct io_uring_cmd *, unsigned));
  39. struct sock *io_uring_get_socket(struct file *file);
  40. void __io_uring_cancel(bool cancel_all);
  41. void __io_uring_free(struct task_struct *tsk);
  42. void io_uring_unreg_ringfd(void);
  43. const char *io_uring_get_opcode(u8 opcode);
  44. static inline void io_uring_files_cancel(void)
  45. {
  46. if (current->io_uring) {
  47. io_uring_unreg_ringfd();
  48. __io_uring_cancel(false);
  49. }
  50. }
  51. static inline void io_uring_task_cancel(void)
  52. {
  53. if (current->io_uring)
  54. __io_uring_cancel(true);
  55. }
  56. static inline void io_uring_free(struct task_struct *tsk)
  57. {
  58. if (tsk->io_uring)
  59. __io_uring_free(tsk);
  60. }
  61. #else
  62. static inline int io_uring_cmd_import_fixed(u64 ubuf, unsigned long len, int rw,
  63. struct iov_iter *iter, void *ioucmd)
  64. {
  65. return -EOPNOTSUPP;
  66. }
  67. static inline void io_uring_cmd_done(struct io_uring_cmd *cmd, ssize_t ret,
  68. ssize_t ret2, unsigned issue_flags)
  69. {
  70. }
  71. static inline void io_uring_cmd_complete_in_task(struct io_uring_cmd *ioucmd,
  72. void (*task_work_cb)(struct io_uring_cmd *, unsigned))
  73. {
  74. }
  75. static inline struct sock *io_uring_get_socket(struct file *file)
  76. {
  77. return NULL;
  78. }
  79. static inline void io_uring_task_cancel(void)
  80. {
  81. }
  82. static inline void io_uring_files_cancel(void)
  83. {
  84. }
  85. static inline void io_uring_free(struct task_struct *tsk)
  86. {
  87. }
  88. static inline const char *io_uring_get_opcode(u8 opcode)
  89. {
  90. return "";
  91. }
  92. #endif
  93. #endif