aio-posix.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * AioContext POSIX event loop implementation internal APIs
  3. *
  4. * Copyright IBM, Corp. 2008
  5. * Copyright Red Hat, Inc. 2020
  6. *
  7. * Authors:
  8. * Anthony Liguori <aliguori@us.ibm.com>
  9. *
  10. * This work is licensed under the terms of the GNU GPL, version 2. See
  11. * the COPYING file in the top-level directory.
  12. *
  13. * Contributions after 2012-01-13 are licensed under the terms of the
  14. * GNU GPL, version 2 or (at your option) any later version.
  15. */
  16. #ifndef AIO_POSIX_H
  17. #define AIO_POSIX_H
  18. #include "block/aio.h"
  19. struct AioHandler {
  20. GPollFD pfd;
  21. IOHandler *io_read;
  22. IOHandler *io_write;
  23. AioPollFn *io_poll;
  24. IOHandler *io_poll_ready;
  25. IOHandler *io_poll_begin;
  26. IOHandler *io_poll_end;
  27. void *opaque;
  28. QLIST_ENTRY(AioHandler) node;
  29. QLIST_ENTRY(AioHandler) node_ready; /* only used during aio_poll() */
  30. QLIST_ENTRY(AioHandler) node_deleted;
  31. QLIST_ENTRY(AioHandler) node_poll;
  32. #ifdef CONFIG_LINUX_IO_URING
  33. QSLIST_ENTRY(AioHandler) node_submitted;
  34. unsigned flags; /* see fdmon-io_uring.c */
  35. #endif
  36. int64_t poll_idle_timeout; /* when to stop userspace polling */
  37. bool poll_ready; /* has polling detected an event? */
  38. bool is_external;
  39. };
  40. /* Add a handler to a ready list */
  41. void aio_add_ready_handler(AioHandlerList *ready_list, AioHandler *node,
  42. int revents);
  43. extern const FDMonOps fdmon_poll_ops;
  44. #ifdef CONFIG_EPOLL_CREATE1
  45. bool fdmon_epoll_try_upgrade(AioContext *ctx, unsigned npfd);
  46. void fdmon_epoll_setup(AioContext *ctx);
  47. void fdmon_epoll_disable(AioContext *ctx);
  48. #else
  49. static inline bool fdmon_epoll_try_upgrade(AioContext *ctx, unsigned npfd)
  50. {
  51. return false;
  52. }
  53. static inline void fdmon_epoll_setup(AioContext *ctx)
  54. {
  55. }
  56. static inline void fdmon_epoll_disable(AioContext *ctx)
  57. {
  58. }
  59. #endif /* !CONFIG_EPOLL_CREATE1 */
  60. #ifdef CONFIG_LINUX_IO_URING
  61. bool fdmon_io_uring_setup(AioContext *ctx);
  62. void fdmon_io_uring_destroy(AioContext *ctx);
  63. #else
  64. static inline bool fdmon_io_uring_setup(AioContext *ctx)
  65. {
  66. return false;
  67. }
  68. static inline void fdmon_io_uring_destroy(AioContext *ctx)
  69. {
  70. }
  71. #endif /* !CONFIG_LINUX_IO_URING */
  72. #endif /* AIO_POSIX_H */