Stefan Hajnoczi | 1f050a4 | 2020-03-05 17:08:02 +0000 | [diff] [blame] | 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 | |
| 17 | #ifndef AIO_POSIX_H |
| 18 | #define AIO_POSIX_H |
| 19 | |
| 20 | #include "block/aio.h" |
| 21 | |
| 22 | struct AioHandler { |
| 23 | GPollFD pfd; |
| 24 | IOHandler *io_read; |
| 25 | IOHandler *io_write; |
| 26 | AioPollFn *io_poll; |
Stefan Hajnoczi | 826cc32 | 2021-12-07 13:23:31 +0000 | [diff] [blame] | 27 | IOHandler *io_poll_ready; |
Stefan Hajnoczi | 1f050a4 | 2020-03-05 17:08:02 +0000 | [diff] [blame] | 28 | IOHandler *io_poll_begin; |
| 29 | IOHandler *io_poll_end; |
| 30 | void *opaque; |
Stefan Hajnoczi | 1f050a4 | 2020-03-05 17:08:02 +0000 | [diff] [blame] | 31 | QLIST_ENTRY(AioHandler) node; |
| 32 | QLIST_ENTRY(AioHandler) node_ready; /* only used during aio_poll() */ |
| 33 | QLIST_ENTRY(AioHandler) node_deleted; |
Stefan Hajnoczi | d37d0e3 | 2020-03-05 17:08:06 +0000 | [diff] [blame] | 34 | QLIST_ENTRY(AioHandler) node_poll; |
Stefan Hajnoczi | 73fd282 | 2020-03-05 17:08:04 +0000 | [diff] [blame] | 35 | #ifdef CONFIG_LINUX_IO_URING |
| 36 | QSLIST_ENTRY(AioHandler) node_submitted; |
| 37 | unsigned flags; /* see fdmon-io_uring.c */ |
| 38 | #endif |
Stefan Hajnoczi | d37d0e3 | 2020-03-05 17:08:06 +0000 | [diff] [blame] | 39 | int64_t poll_idle_timeout; /* when to stop userspace polling */ |
Stefan Hajnoczi | fc87964 | 2022-02-23 15:57:03 +0000 | [diff] [blame] | 40 | bool poll_ready; /* has polling detected an event? */ |
Stefan Hajnoczi | 1f050a4 | 2020-03-05 17:08:02 +0000 | [diff] [blame] | 41 | }; |
| 42 | |
| 43 | /* Add a handler to a ready list */ |
| 44 | void aio_add_ready_handler(AioHandlerList *ready_list, AioHandler *node, |
| 45 | int revents); |
| 46 | |
| 47 | extern const FDMonOps fdmon_poll_ops; |
| 48 | |
| 49 | #ifdef CONFIG_EPOLL_CREATE1 |
| 50 | bool fdmon_epoll_try_upgrade(AioContext *ctx, unsigned npfd); |
| 51 | void fdmon_epoll_setup(AioContext *ctx); |
| 52 | void fdmon_epoll_disable(AioContext *ctx); |
| 53 | #else |
| 54 | static inline bool fdmon_epoll_try_upgrade(AioContext *ctx, unsigned npfd) |
| 55 | { |
| 56 | return false; |
| 57 | } |
| 58 | |
| 59 | static inline void fdmon_epoll_setup(AioContext *ctx) |
| 60 | { |
| 61 | } |
| 62 | |
| 63 | static inline void fdmon_epoll_disable(AioContext *ctx) |
| 64 | { |
| 65 | } |
| 66 | #endif /* !CONFIG_EPOLL_CREATE1 */ |
| 67 | |
Stefan Hajnoczi | 73fd282 | 2020-03-05 17:08:04 +0000 | [diff] [blame] | 68 | #ifdef CONFIG_LINUX_IO_URING |
| 69 | bool fdmon_io_uring_setup(AioContext *ctx); |
| 70 | void fdmon_io_uring_destroy(AioContext *ctx); |
| 71 | #else |
| 72 | static inline bool fdmon_io_uring_setup(AioContext *ctx) |
| 73 | { |
| 74 | return false; |
| 75 | } |
| 76 | |
| 77 | static inline void fdmon_io_uring_destroy(AioContext *ctx) |
| 78 | { |
| 79 | } |
| 80 | #endif /* !CONFIG_LINUX_IO_URING */ |
| 81 | |
Stefan Hajnoczi | 1f050a4 | 2020-03-05 17:08:02 +0000 | [diff] [blame] | 82 | #endif /* AIO_POSIX_H */ |