Use the libvhost-user library.
This ended up being a rather large patch that cannot be easily splitted,
due to massive code move and API changes.
Signed-off-by: Marc-André Lureau
---
tests/vhost-user-bridge.c | 1177 +
tests/Makefile.include|2 +-
2 files changed, 229 insertions(+), 950 deletions(-)
diff --git a/tests/vhost-user-bridge.c b/tests/vhost-user-bridge.c
index 5b618f6..8618c20 100644
--- a/tests/vhost-user-bridge.c
+++ b/tests/vhost-user-bridge.c
@@ -30,17 +30,9 @@
#define _FILE_OFFSET_BITS 64
#include "qemu/osdep.h"
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include "qemu/atomic.h"
+#include "qemu/iov.h"
#include "standard-headers/linux/virtio_net.h"
-#include "standard-headers/linux/virtio_ring.h"
+#include "contrib/libvhost-user/libvhost-user.h"
#define VHOST_USER_BRIDGE_DEBUG 1
@@ -64,6 +56,17 @@ typedef struct Dispatcher {
Event events[FD_SETSIZE];
} Dispatcher;
+typedef struct VubrDev {
+VuDev vudev;
+Dispatcher dispatcher;
+int backend_udp_sock;
+struct sockaddr_in backend_udp_dest;
+int hdrlen;
+int sock;
+int ready;
+int quit;
+} VubrDev;
+
static void
vubr_die(const char *s)
{
@@ -155,1036 +158,313 @@ dispatcher_wait(Dispatcher *dispr, uint32_t timeout)
return 0;
}
-typedef struct VubrVirtq {
-int call_fd;
-int kick_fd;
-uint32_t size;
-uint16_t last_avail_index;
-uint16_t last_used_index;
-struct vring_desc *desc;
-struct vring_avail *avail;
-struct vring_used *used;
-uint64_t log_guest_addr;
-int enable;
-} VubrVirtq;
-
-/* Based on qemu/hw/virtio/vhost-user.c */
-
-#define VHOST_MEMORY_MAX_NREGIONS8
-#define VHOST_USER_F_PROTOCOL_FEATURES 30
-/* v1.0 compliant. */
-#define VIRTIO_F_VERSION_1 32
-
-#define VHOST_LOG_PAGE 4096
-
-enum VhostUserProtocolFeature {
-VHOST_USER_PROTOCOL_F_MQ = 0,
-VHOST_USER_PROTOCOL_F_LOG_SHMFD = 1,
-VHOST_USER_PROTOCOL_F_RARP = 2,
-
-VHOST_USER_PROTOCOL_F_MAX
-};
-
-#define VHOST_USER_PROTOCOL_FEATURE_MASK ((1 << VHOST_USER_PROTOCOL_F_MAX) - 1)
-
-typedef enum VhostUserRequest {
-VHOST_USER_NONE = 0,
-VHOST_USER_GET_FEATURES = 1,
-VHOST_USER_SET_FEATURES = 2,
-VHOST_USER_SET_OWNER = 3,
-VHOST_USER_RESET_OWNER = 4,
-VHOST_USER_SET_MEM_TABLE = 5,
-VHOST_USER_SET_LOG_BASE = 6,
-VHOST_USER_SET_LOG_FD = 7,
-VHOST_USER_SET_VRING_NUM = 8,
-VHOST_USER_SET_VRING_ADDR = 9,
-VHOST_USER_SET_VRING_BASE = 10,
-VHOST_USER_GET_VRING_BASE = 11,
-VHOST_USER_SET_VRING_KICK = 12,
-VHOST_USER_SET_VRING_CALL = 13,
-VHOST_USER_SET_VRING_ERR = 14,
-VHOST_USER_GET_PROTOCOL_FEATURES = 15,
-VHOST_USER_SET_PROTOCOL_FEATURES = 16,
-VHOST_USER_GET_QUEUE_NUM = 17,
-VHOST_USER_SET_VRING_ENABLE = 18,
-VHOST_USER_SEND_RARP = 19,
-VHOST_USER_MAX
-} VhostUserRequest;
-
-typedef struct VhostUserMemoryRegion {
-uint64_t guest_phys_addr;
-uint64_t memory_size;
-uint64_t userspace_addr;
-uint64_t mmap_offset;
-} VhostUserMemoryRegion;
-
-typedef struct VhostUserMemory {
-uint32_t nregions;
-uint32_t padding;
-VhostUserMemoryRegion regions[VHOST_MEMORY_MAX_NREGIONS];
-} VhostUserMemory;
-
-typedef struct VhostUserLog {
-uint64_t mmap_size;
-uint64_t mmap_offset;
-} VhostUserLog;
-
-typedef struct VhostUserMsg {
-VhostUserRequest request;
-
-#define VHOST_USER_VERSION_MASK (0x3)
-#define VHOST_USER_REPLY_MASK (0x1<<2)
-uint32_t flags;
-uint32_t size; /* the following payload size */
-union {
-#define VHOST_USER_VRING_IDX_MASK (0xff)
-#define VHOST_USER_VRING_NOFD_MASK (0x1<<8)
-uint64_t u64;
-struct vhost_vring_state state;
-struct vhost_vring_addr addr;
-VhostUserMemory memory;
-VhostUserLog log;
-} payload;
-int fds[VHOST_MEMORY_MAX_NREGIONS];
-int fd_num;
-} QEMU_PACKED VhostUserMsg;
-
-#define VHOST_USER_HDR_SIZE offsetof(VhostUserMsg, payload.u64)
-
-/* The version of the protocol we support */
-#define VHOST_USER_VERSION(0x1)
-
-#define MAX_NR_VIRTQUEUE (8)
-
-typedef struct VubrDevRegion {
-/* Guest Physical address. */
-uint64_t gpa;
-/* Memory region size. */
-uint64_t size;
-/* QEMU virtual address (userspace). */
-uint64_t qva;
-/* Starting offset in our mmaped space. */
-uint64_t mmap_offset;
-/* Start address of mmaped space. */
-uint64_t mmap_addr;
-} VubrDevRegion;
-
-typedef struct VubrDev {
-int sock;
-Dispatcher dispatcher;
-uint32_t nregions;
-VubrDevRegion regions[VHOST_MEMORY_MAX_NREGIONS];
-VubrVirtq vq[MAX_NR_VIRTQUEUE];
-int log_call_fd;
-uint64_t log_size;
-uint8_t *log_table;
-int backend_udp_sock;
-struct sockaddr_in backend_udp_dest;
-int ready;
-uint64_t features;
-int hdrlen;
-} VubrDev;
-
-static const char *vubr_request_str[] = {
-[VHOST_USER_NO