2020-09-18 10:09:08 +02:00
|
|
|
/*
|
|
|
|
* Sharing QEMU devices via vhost-user protocol
|
|
|
|
*
|
|
|
|
* Copyright (c) Coiby Xu <coiby.xu@gmail.com>.
|
|
|
|
* Copyright (c) 2020 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or
|
|
|
|
* later. See the COPYING file in the top-level directory.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef VHOST_USER_SERVER_H
|
|
|
|
#define VHOST_USER_SERVER_H
|
|
|
|
|
2020-11-25 11:06:37 +01:00
|
|
|
#include "subprojects/libvhost-user/libvhost-user.h" /* only for the type definitions */
|
2020-09-18 10:09:08 +02:00
|
|
|
#include "io/channel-socket.h"
|
|
|
|
#include "io/channel-file.h"
|
|
|
|
#include "io/net-listener.h"
|
|
|
|
#include "qapi/error.h"
|
|
|
|
#include "standard-headers/linux/virtio_blk.h"
|
|
|
|
|
2020-09-24 17:15:45 +02:00
|
|
|
/* A kick fd that we monitor on behalf of libvhost-user */
|
2020-09-18 10:09:08 +02:00
|
|
|
typedef struct VuFdWatch {
|
|
|
|
VuDev *vu_dev;
|
|
|
|
int fd; /*kick fd*/
|
|
|
|
void *pvt;
|
|
|
|
vu_watch_cb cb;
|
|
|
|
QTAILQ_ENTRY(VuFdWatch) next;
|
|
|
|
} VuFdWatch;
|
|
|
|
|
2020-09-24 17:15:45 +02:00
|
|
|
/**
|
|
|
|
* VuServer:
|
|
|
|
* A vhost-user server instance with user-defined VuDevIface callbacks.
|
|
|
|
* Vhost-user device backends can be implemented using VuServer. VuDevIface
|
|
|
|
* callbacks and virtqueue kicks run in the given AioContext.
|
|
|
|
*/
|
|
|
|
typedef struct {
|
2020-09-18 10:09:08 +02:00
|
|
|
QIONetListener *listener;
|
2020-09-24 17:15:45 +02:00
|
|
|
QEMUBH *restart_listener_bh;
|
2020-09-18 10:09:08 +02:00
|
|
|
AioContext *ctx;
|
|
|
|
int max_queues;
|
|
|
|
const VuDevIface *vu_iface;
|
2020-09-24 17:15:45 +02:00
|
|
|
|
2023-05-16 21:02:24 +02:00
|
|
|
unsigned int in_flight; /* atomic */
|
|
|
|
|
2020-09-24 17:15:45 +02:00
|
|
|
/* Protected by ctx lock */
|
2023-08-31 00:48:02 +02:00
|
|
|
bool in_qio_channel_yield;
|
2022-01-25 16:14:35 +01:00
|
|
|
bool wait_idle;
|
2020-09-18 10:09:08 +02:00
|
|
|
VuDev vu_dev;
|
|
|
|
QIOChannel *ioc; /* The I/O channel with the client */
|
|
|
|
QIOChannelSocket *sioc; /* The underlying data channel with the client */
|
|
|
|
QTAILQ_HEAD(, VuFdWatch) vu_fd_watches;
|
2020-09-24 17:15:45 +02:00
|
|
|
|
|
|
|
Coroutine *co_trip; /* coroutine for processing VhostUserMsg */
|
|
|
|
} VuServer;
|
2020-09-18 10:09:08 +02:00
|
|
|
|
|
|
|
bool vhost_user_server_start(VuServer *server,
|
|
|
|
SocketAddress *unix_socket,
|
|
|
|
AioContext *ctx,
|
|
|
|
uint16_t max_queues,
|
|
|
|
const VuDevIface *vu_iface,
|
|
|
|
Error **errp);
|
|
|
|
|
|
|
|
void vhost_user_server_stop(VuServer *server);
|
|
|
|
|
2023-05-16 21:02:23 +02:00
|
|
|
void vhost_user_server_inc_in_flight(VuServer *server);
|
|
|
|
void vhost_user_server_dec_in_flight(VuServer *server);
|
2023-05-16 21:02:24 +02:00
|
|
|
bool vhost_user_server_has_in_flight(VuServer *server);
|
2022-01-25 16:14:35 +01:00
|
|
|
|
2020-09-24 17:15:45 +02:00
|
|
|
void vhost_user_server_attach_aio_context(VuServer *server, AioContext *ctx);
|
|
|
|
void vhost_user_server_detach_aio_context(VuServer *server);
|
2020-09-18 10:09:08 +02:00
|
|
|
|
|
|
|
#endif /* VHOST_USER_SERVER_H */
|