master
h 81 lines 2.18 KB
Raw
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 "qemu/aio.h"
21 #include "qapi/error.h"
22
23 struct AioHandler {
24 GPollFD pfd;
25 IOHandler *io_read;
26 IOHandler *io_write;
27 AioPollFn *io_poll;
28 IOHandler *io_poll_ready;
29 IOHandler *io_poll_begin;
30 IOHandler *io_poll_end;
31 void *opaque;
32 QLIST_ENTRY(AioHandler) node;
33 QLIST_ENTRY(AioHandler) node_ready; /* only used during aio_poll() */
34 QLIST_ENTRY(AioHandler) node_deleted;
35 QLIST_ENTRY(AioHandler) node_poll;
36 #ifdef CONFIG_LINUX_IO_URING
37 QSLIST_ENTRY(AioHandler) node_submitted;
38 unsigned flags; /* see fdmon-io_uring.c */
39 CqeHandler internal_cqe_handler; /* used for POLL_ADD/POLL_REMOVE */
40 #endif
41 int64_t last_dispatch_timestamp; /* when last handler was dispatched */
42 bool poll_ready; /* has polling detected an event? */
43 AioPolledEvent poll;
44 };
45
46 /* Add a handler to a ready list */
47 void aio_add_ready_handler(AioHandlerList *ready_list, AioHandler *node,
48 int revents);
49
50 extern const FDMonOps fdmon_poll_ops;
51
52 /* Switch back to poll(2). list_lock must be held. */
53 void fdmon_poll_downgrade(AioContext *ctx);
54
55 #ifdef CONFIG_EPOLL
56 bool fdmon_epoll_try_upgrade(AioContext *ctx, unsigned npfd);
57 void fdmon_epoll_setup(AioContext *ctx);
58
59 /* list_lock must be held */
60 void fdmon_epoll_disable(AioContext *ctx);
61 #else
62 static inline bool fdmon_epoll_try_upgrade(AioContext *ctx, unsigned npfd)
63 {
64 return false;
65 }
66
67 static inline void fdmon_epoll_setup(AioContext *ctx)
68 {
69 }
70
71 static inline void fdmon_epoll_disable(AioContext *ctx)
72 {
73 }
74 #endif /* !CONFIG_EPOLL */
75
76 #ifdef CONFIG_LINUX_IO_URING
77 bool fdmon_io_uring_setup(AioContext *ctx, Error **errp);
78 void fdmon_io_uring_destroy(AioContext *ctx);
79 #endif /* !CONFIG_LINUX_IO_URING */
80
81 #endif /* AIO_POSIX_H */