Extend the <rte_vhost.h> API to support the virtio-vhost-user transport
as an alternative to the AF_UNIX transport. The caller provides a PCI
DomBDF address:
rte_vhost_driver_register("0000:00:04.0",
RTE_VHOST_USER_VIRTIO_TRANSPORT);
Signed-off-by: Nikos Dragazis <ndragazis@arrikto.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
drivers/virtio_vhost_user/trans_virtio_vhost_user.c | 4 ++++
lib/librte_vhost/rte_vhost.h | 1 +
lib/librte_vhost/socket.c | 19 ++++++++++++++++++-
lib/librte_vhost/vhost.h | 6 +++++-
4 files changed, 28 insertions(+), 2 deletions(-)
@@ -979,6 +979,10 @@ vvu_pci_init(void)
}
rte_pci_register(&vvu_pci_driver);
+ if (rte_vhost_register_transport(VHOST_TRANSPORT_VVU, &virtio_vhost_user_trans_ops) < 0) {
+ RTE_LOG(ERR, VHOST_CONFIG,
+ "Registration of vhost-user transport (%d) failed\n", VHOST_TRANSPORT_VVU);
+ }
}
static int
@@ -29,6 +29,7 @@ extern "C" {
#define RTE_VHOST_USER_DEQUEUE_ZERO_COPY (1ULL << 2)
#define RTE_VHOST_USER_IOMMU_SUPPORT (1ULL << 3)
#define RTE_VHOST_USER_POSTCOPY_SUPPORT (1ULL << 4)
+#define RTE_VHOST_USER_VIRTIO_TRANSPORT (1ULL << 5)
/** Protocol features. */
#ifndef VHOST_USER_PROTOCOL_F_MQ
@@ -327,7 +327,16 @@ rte_vhost_driver_register(const char *path, uint64_t flags)
goto out;
}
- trans_ops = g_transport_map[VHOST_TRANSPORT_UNIX];
+ if (flags & RTE_VHOST_USER_VIRTIO_TRANSPORT) {
+ trans_ops = g_transport_map[VHOST_TRANSPORT_VVU];
+ if (trans_ops == NULL) {
+ RTE_LOG(ERR, VHOST_CONFIG,
+ "virtio-vhost-user transport is not supported\n");
+ goto out;
+ }
+ } else {
+ trans_ops = g_transport_map[VHOST_TRANSPORT_UNIX];
+ }
if (!path)
return -1;
@@ -400,6 +409,14 @@ rte_vhost_driver_register(const char *path, uint64_t flags)
"Postcopy requested but not compiled\n");
ret = -1;
goto out_free;
+#else
+ if (flags & RTE_VHOST_USER_VIRTIO_TRANSPORT) {
+ RTE_LOG(ERR, VHOST_CONFIG,
+ "Postcopy requested but not supported "
+ "by the virtio-vhost-user transport\n");
+ ret = -1;
+ goto out_free;
+ }
#endif
}
@@ -494,9 +494,13 @@ struct vhost_transport_ops {
/** The traditional AF_UNIX vhost-user protocol transport. */
extern const struct vhost_transport_ops af_unix_trans_ops;
+/** The virtio-vhost-user PCI vhost-user protocol transport. */
+extern const struct vhost_transport_ops virtio_vhost_user_trans_ops;
+
typedef enum VhostUserTransport {
VHOST_TRANSPORT_UNIX = 0,
- VHOST_TRANSPORT_MAX = 1
+ VHOST_TRANSPORT_VVU = 1,
+ VHOST_TRANSPORT_MAX = 2
} VhostUserTransport;
/* A list with all the available vhost-user transports. */