]>
Commit | Line | Data |
---|---|---|
70eb2c07 CX |
1 | /* |
2 | * Sharing QEMU devices via vhost-user protocol | |
3 | * | |
4 | * Copyright (c) Coiby Xu <coiby.xu@gmail.com>. | |
5 | * Copyright (c) 2020 Red Hat, Inc. | |
6 | * | |
7 | * This work is licensed under the terms of the GNU GPL, version 2 or | |
8 | * later. See the COPYING file in the top-level directory. | |
9 | */ | |
10 | ||
11 | #ifndef VHOST_USER_SERVER_H | |
12 | #define VHOST_USER_SERVER_H | |
13 | ||
0df750e9 | 14 | #include "subprojects/libvhost-user/libvhost-user.h" /* only for the type definitions */ |
70eb2c07 CX |
15 | #include "io/channel-socket.h" |
16 | #include "io/channel-file.h" | |
17 | #include "io/net-listener.h" | |
70eb2c07 CX |
18 | #include "qapi/error.h" |
19 | #include "standard-headers/linux/virtio_blk.h" | |
20 | ||
7185c857 | 21 | /* A kick fd that we monitor on behalf of libvhost-user */ |
70eb2c07 CX |
22 | typedef struct VuFdWatch { |
23 | VuDev *vu_dev; | |
24 | int fd; /*kick fd*/ | |
25 | void *pvt; | |
26 | vu_watch_cb cb; | |
70eb2c07 CX |
27 | QTAILQ_ENTRY(VuFdWatch) next; |
28 | } VuFdWatch; | |
29 | ||
7185c857 SH |
30 | /** |
31 | * VuServer: | |
32 | * A vhost-user server instance with user-defined VuDevIface callbacks. | |
33 | * Vhost-user device backends can be implemented using VuServer. VuDevIface | |
34 | * callbacks and virtqueue kicks run in the given AioContext. | |
35 | */ | |
36 | typedef struct { | |
70eb2c07 | 37 | QIONetListener *listener; |
7185c857 | 38 | QEMUBH *restart_listener_bh; |
70eb2c07 | 39 | AioContext *ctx; |
70eb2c07 CX |
40 | int max_queues; |
41 | const VuDevIface *vu_iface; | |
7185c857 | 42 | |
8f5e9a8e SH |
43 | unsigned int in_flight; /* atomic */ |
44 | ||
7185c857 | 45 | /* Protected by ctx lock */ |
06e0f098 | 46 | bool in_qio_channel_yield; |
520d8b40 | 47 | bool wait_idle; |
70eb2c07 CX |
48 | VuDev vu_dev; |
49 | QIOChannel *ioc; /* The I/O channel with the client */ | |
50 | QIOChannelSocket *sioc; /* The underlying data channel with the client */ | |
70eb2c07 | 51 | QTAILQ_HEAD(, VuFdWatch) vu_fd_watches; |
7185c857 SH |
52 | |
53 | Coroutine *co_trip; /* coroutine for processing VhostUserMsg */ | |
54 | } VuServer; | |
70eb2c07 CX |
55 | |
56 | bool vhost_user_server_start(VuServer *server, | |
57 | SocketAddress *unix_socket, | |
58 | AioContext *ctx, | |
59 | uint16_t max_queues, | |
70eb2c07 CX |
60 | const VuDevIface *vu_iface, |
61 | Error **errp); | |
62 | ||
63 | void vhost_user_server_stop(VuServer *server); | |
64 | ||
75d33e85 SH |
65 | void vhost_user_server_inc_in_flight(VuServer *server); |
66 | void vhost_user_server_dec_in_flight(VuServer *server); | |
8f5e9a8e | 67 | bool vhost_user_server_has_in_flight(VuServer *server); |
520d8b40 | 68 | |
7185c857 SH |
69 | void vhost_user_server_attach_aio_context(VuServer *server, AioContext *ctx); |
70 | void vhost_user_server_detach_aio_context(VuServer *server); | |
70eb2c07 CX |
71 | |
72 | #endif /* VHOST_USER_SERVER_H */ |