@@ -91,15 +91,27 @@ static int vhost_net_get_fd(NetClientState *backend)
}
}
-struct vhost_net *vhost_net_init(NetClientState *backend, int devfd,
- bool force)
+struct vhost_net *vhost_net_init(NetClientState *backend, char *vhostsock,
+ int devfd, bool force)
{
int r;
struct vhost_net *net = g_malloc(sizeof *net);
+ const char *backend_sock = 0;
+ VhostBackendType backend_type = VHOST_BACKEND_TYPE_NONE;
+
if (!backend) {
fprintf(stderr, "vhost-net requires backend to be setup\n");
goto fail;
}
+
+ if (vhostsock && strcmp(vhostsock, VHOST_NET_DEFAULT_SOCK) != 0) {
+ backend_type = VHOST_BACKEND_TYPE_USER;
+ backend_sock = vhostsock;
+ } else {
+ backend_type = VHOST_BACKEND_TYPE_KERNEL;
+ backend_sock = VHOST_NET_DEFAULT_SOCK;
+ }
+
r = vhost_net_get_fd(backend);
if (r < 0) {
goto fail;
@@ -112,7 +124,7 @@ struct vhost_net *vhost_net_init(NetClientState *backend, int devfd,
net->dev.nvqs = 2;
net->dev.vqs = net->vqs;
- r = vhost_dev_init(&net->dev, devfd, "/dev/vhost-net", VHOST_BACKEND_TYPE_KERNEL, force);
+ r = vhost_dev_init(&net->dev, devfd, backend_sock, backend_type, force);
if (r < 0) {
goto fail;
}
@@ -282,8 +294,8 @@ void vhost_net_virtqueue_mask(VHostNetState *net, VirtIODevice *dev,
vhost_virtqueue_mask(&net->dev, dev, idx, mask);
}
#else
-struct vhost_net *vhost_net_init(NetClientState *backend, int devfd,
- bool force)
+struct vhost_net *vhost_net_init(NetClientState *backend, char *vhostsock,
+ int devfd, bool force)
{
error_report("vhost-net support is not compiled in");
return NULL;
@@ -3,10 +3,13 @@
#include "net/net.h"
+#define VHOST_NET_DEFAULT_SOCK "/dev/vhost-net"
+
struct vhost_net;
typedef struct vhost_net VHostNetState;
-VHostNetState *vhost_net_init(NetClientState *backend, int devfd, bool force);
+VHostNetState *vhost_net_init(NetClientState *backend, char *vhostsock,
+ int devfd, bool force);
bool vhost_net_query(VHostNetState *net, VirtIODevice *dev);
int vhost_net_start(VirtIODevice *dev, NetClientState *ncs, int total_queues);
@@ -632,7 +632,9 @@ static int net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
vhostfd = -1;
}
- s->vhost_net = vhost_net_init(&s->nc, vhostfd,
+ s->vhost_net = vhost_net_init(&s->nc,
+ tap->has_vhostsock ? tap->vhostsock : 0,
+ vhostfd,
tap->has_vhostforce && tap->vhostforce);
if (!s->vhost_net) {
error_report("vhost-net requested but could not be initialized");
@@ -2891,6 +2891,8 @@
#
# @vhostforce: #optional vhost on for non-MSIX virtio guests
#
+# @vhostsock: #optional vhost backend socket
+#
# @queues: #optional number of queues to be created for multiqueue capable tap
#
# Since 1.2
@@ -2909,6 +2911,7 @@
'*vhostfd': 'str',
'*vhostfds': 'str',
'*vhostforce': 'bool',
+ '*vhostsock': 'str',
'*queues': 'uint32'} }
##
@@ -1370,7 +1370,7 @@ DEF("net", HAS_ARG, QEMU_OPTION_net,
"-net tap[,vlan=n][,name=str],ifname=name\n"
" connect the host TAP network interface to VLAN 'n'\n"
#else
- "-net tap[,vlan=n][,name=str][,fd=h][,fds=x:y:...:z][,ifname=name][,script=file][,downscript=dfile][,helper=helper][,sndbuf=nbytes][,vnet_hdr=on|off][,vhost=on|off][,vhostfd=h][,vhostfds=x:y:...:z][,vhostforce=on|off][,queues=n]\n"
+ "-net tap[,vlan=n][,name=str][,fd=h][,fds=x:y:...:z][,ifname=name][,script=file][,downscript=dfile][,helper=helper][,sndbuf=nbytes][,vnet_hdr=on|off][,vhost=on|off][,vhostfd=h][,vhostfds=x:y:...:z][,vhostforce=on|off][,queues=n][,vhostsock=file]\n"
" connect the host TAP network interface to VLAN 'n'\n"
" use network scripts 'file' (default=" DEFAULT_NETWORK_SCRIPT ")\n"
" to configure it and 'dfile' (default=" DEFAULT_NETWORK_DOWN_SCRIPT ")\n"
@@ -1390,6 +1390,7 @@ DEF("net", HAS_ARG, QEMU_OPTION_net,
" use 'vhostfd=h' to connect to an already opened vhost net device\n"
" use 'vhostfds=x:y:...:z to connect to multiple already opened vhost net devices\n"
" use 'queues=n' to specify the number of queues to be created for multiqueue TAP\n"
+ " use 'vhostsock=file' vhost-user backend socket\n"
"-net bridge[,vlan=n][,name=str][,br=bridge][,helper=helper]\n"
" connects a host TAP network interface to a host bridge device 'br'\n"
" (default=" DEFAULT_BRIDGE_INTERFACE ") using the program 'helper'\n"