aio.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #ifndef __LINUX__AIO_H
  2. #define __LINUX__AIO_H
  3. #include <linux/list.h>
  4. #include <linux/workqueue.h>
  5. #include <linux/aio_abi.h>
  6. #include <linux/uio.h>
  7. #include <linux/rcupdate.h>
  8. #include <linux/atomic.h>
  9. struct kioctx;
  10. struct kiocb;
  11. #define KIOCB_KEY 0
  12. /*
  13. * We use ki_cancel == KIOCB_CANCELLED to indicate that a kiocb has been either
  14. * cancelled or completed (this makes a certain amount of sense because
  15. * successful cancellation - io_cancel() - does deliver the completion to
  16. * userspace).
  17. *
  18. * And since most things don't implement kiocb cancellation and we'd really like
  19. * kiocb completion to be lockless when possible, we use ki_cancel to
  20. * synchronize cancellation and completion - we only set it to KIOCB_CANCELLED
  21. * with xchg() or cmpxchg(), see batch_complete_aio() and kiocb_cancel().
  22. */
  23. #define KIOCB_CANCELLED ((void *) (~0ULL))
  24. typedef int (kiocb_cancel_fn)(struct kiocb *);
  25. struct kiocb {
  26. struct file *ki_filp;
  27. struct kioctx *ki_ctx; /* NULL for sync ops */
  28. kiocb_cancel_fn *ki_cancel;
  29. void (*ki_dtor)(struct kiocb *);
  30. void *private;
  31. union {
  32. void __user *user;
  33. struct task_struct *tsk;
  34. } ki_obj;
  35. __u64 ki_user_data; /* user's data for completion */
  36. loff_t ki_pos;
  37. size_t ki_nbytes; /* copy of iocb->aio_nbytes */
  38. struct list_head ki_list; /* the aio core uses this
  39. * for cancellation */
  40. /*
  41. * If the aio_resfd field of the userspace iocb is not zero,
  42. * this is the underlying eventfd context to deliver events to.
  43. */
  44. struct eventfd_ctx *ki_eventfd;
  45. };
  46. static inline bool is_sync_kiocb(struct kiocb *kiocb)
  47. {
  48. return kiocb->ki_ctx == NULL;
  49. }
  50. static inline void init_sync_kiocb(struct kiocb *kiocb, struct file *filp)
  51. {
  52. *kiocb = (struct kiocb) {
  53. .ki_ctx = NULL,
  54. .ki_filp = filp,
  55. .ki_obj.tsk = current,
  56. };
  57. }
  58. /* prototypes */
  59. #ifdef CONFIG_AIO
  60. extern ssize_t wait_on_sync_kiocb(struct kiocb *iocb);
  61. extern void aio_complete(struct kiocb *iocb, long res, long res2);
  62. struct mm_struct;
  63. extern void exit_aio(struct mm_struct *mm);
  64. extern long do_io_submit(aio_context_t ctx_id, long nr,
  65. struct iocb __user *__user *iocbpp, bool compat);
  66. void kiocb_set_cancel_fn(struct kiocb *req, kiocb_cancel_fn *cancel);
  67. #else
  68. static inline ssize_t wait_on_sync_kiocb(struct kiocb *iocb) { return 0; }
  69. static inline void aio_complete(struct kiocb *iocb, long res, long res2) { }
  70. struct mm_struct;
  71. static inline void exit_aio(struct mm_struct *mm) { }
  72. static inline long do_io_submit(aio_context_t ctx_id, long nr,
  73. struct iocb __user * __user *iocbpp,
  74. bool compat) { return 0; }
  75. static inline void kiocb_set_cancel_fn(struct kiocb *req,
  76. kiocb_cancel_fn *cancel) { }
  77. #endif /* CONFIG_AIO */
  78. static inline struct kiocb *list_kiocb(struct list_head *h)
  79. {
  80. return list_entry(h, struct kiocb, ki_list);
  81. }
  82. /* for sysctl: */
  83. extern unsigned long aio_nr;
  84. extern unsigned long aio_max_nr;
  85. #endif /* __LINUX__AIO_H */