aio.h 3.0 KB

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