aio.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 *private;
  30. union {
  31. void __user *user;
  32. struct task_struct *tsk;
  33. } ki_obj;
  34. __u64 ki_user_data; /* user's data for completion */
  35. loff_t ki_pos;
  36. size_t ki_nbytes; /* copy of iocb->aio_nbytes */
  37. struct list_head ki_list; /* the aio core uses this
  38. * for cancellation */
  39. /*
  40. * If the aio_resfd field of the userspace iocb is not zero,
  41. * this is the underlying eventfd context to deliver events to.
  42. */
  43. struct eventfd_ctx *ki_eventfd;
  44. };
  45. static inline bool is_sync_kiocb(struct kiocb *kiocb)
  46. {
  47. return kiocb->ki_ctx == NULL;
  48. }
  49. static inline void init_sync_kiocb(struct kiocb *kiocb, struct file *filp)
  50. {
  51. *kiocb = (struct kiocb) {
  52. .ki_ctx = NULL,
  53. .ki_filp = filp,
  54. .ki_obj.tsk = current,
  55. };
  56. }
  57. /* prototypes */
  58. #ifdef CONFIG_AIO
  59. extern ssize_t wait_on_sync_kiocb(struct kiocb *iocb);
  60. extern void aio_complete(struct kiocb *iocb, long res, long res2);
  61. struct mm_struct;
  62. extern void exit_aio(struct mm_struct *mm);
  63. extern long do_io_submit(aio_context_t ctx_id, long nr,
  64. struct iocb __user *__user *iocbpp, bool compat);
  65. void kiocb_set_cancel_fn(struct kiocb *req, kiocb_cancel_fn *cancel);
  66. #else
  67. static inline ssize_t wait_on_sync_kiocb(struct kiocb *iocb) { return 0; }
  68. static inline void aio_complete(struct kiocb *iocb, long res, long res2) { }
  69. struct mm_struct;
  70. static inline void exit_aio(struct mm_struct *mm) { }
  71. static inline long do_io_submit(aio_context_t ctx_id, long nr,
  72. struct iocb __user * __user *iocbpp,
  73. bool compat) { return 0; }
  74. static inline void kiocb_set_cancel_fn(struct kiocb *req,
  75. kiocb_cancel_fn *cancel) { }
  76. #endif /* CONFIG_AIO */
  77. static inline struct kiocb *list_kiocb(struct list_head *h)
  78. {
  79. return list_entry(h, struct kiocb, ki_list);
  80. }
  81. /* for sysctl: */
  82. extern unsigned long aio_nr;
  83. extern unsigned long aio_max_nr;
  84. #endif /* __LINUX__AIO_H */