From: Antonios Motakis <a.motakis@virtualopensystems.com>
To: qemu-devel@nongnu.org, snabb-devel@googlegroups.com
Cc: Stefan Hajnoczi <stefanha@redhat.com>,
mst@redhat.com, Corey Bryant <coreyb@linux.vnet.ibm.com>,
Michael Tokarev <mjt@tls.msk.ru>,
Markus Armbruster <armbru@redhat.com>,
n.nikolaev@virtualopensystems.com,
Luiz Capitulino <lcapitulino@redhat.com>,
Anthony Liguori <aliguori@amazon.com>,
Paolo Bonzini <pbonzini@redhat.com>,
lukego@gmail.com,
Antonios Motakis <a.motakis@virtualopensystems.com>,
tech@virtualopensystems.com
Subject: [Qemu-devel] [PATCH v9 17/20] Add the vhost-user netdev backend to the command line
Date: Tue, 4 Mar 2014 19:23:00 +0100 [thread overview]
Message-ID: <1393957383-16685-18-git-send-email-a.motakis@virtualopensystems.com> (raw)
In-Reply-To: <1393957383-16685-1-git-send-email-a.motakis@virtualopensystems.com>
The supplied chardev id will be inspected for supported options. Only
a socket backend, with a set path (i.e. a Unix socket) and optionally
the server parameter set, will be allowed. Other options (nowait, telnet)
will make the chardev unusable and the netdev will not be initialised.
Additional checks for validity:
- requires `-mempath ...,share=on`
- requires `-device virtio-net-*`
The `vhostforce` option is used to force vhost-net when we deal with
non-MSIX guests.
Signed-off-by: Antonios Motakis <a.motakis@virtualopensystems.com>
Signed-off-by: Nikolay Nikolaev <n.nikolaev@virtualopensystems.com>
---
hmp-commands.hx | 4 +-
hw/net/vhost_net.c | 4 ++
net/hub.c | 1 +
net/net.c | 25 ++++++-----
net/vhost-user.c | 127 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
qapi-schema.json | 19 +++++++-
qemu-options.hx | 17 +++++++
7 files changed, 181 insertions(+), 16 deletions(-)
diff --git a/hmp-commands.hx b/hmp-commands.hx
index f3fc514..68128c1 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -1195,7 +1195,7 @@ ETEXI
{
.name = "host_net_add",
.args_type = "device:s,opts:s?",
- .params = "tap|user|socket|vde|netmap|dump [options]",
+ .params = "tap|user|socket|vde|netmap|vhost-user|dump [options]",
.help = "add host VLAN client",
.mhandler.cmd = net_host_device_add,
},
@@ -1223,7 +1223,7 @@ ETEXI
{
.name = "netdev_add",
.args_type = "netdev:O",
- .params = "[user|tap|socket|hubport|netmap],id=str[,prop=value][,...]",
+ .params = "[user|tap|socket|hubport|netmap|vhost-user],id=str[,prop=value][,...]",
.help = "add host network device",
.mhandler.cmd = hmp_netdev_add,
},
diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
index 48cfda7..1c0ffd5 100644
--- a/hw/net/vhost_net.c
+++ b/hw/net/vhost_net.c
@@ -15,6 +15,7 @@
#include "net/net.h"
#include "net/tap.h"
+#include "net/vhost-user.h"
#include "hw/virtio/virtio-net.h"
#include "net/vhost_net.h"
@@ -325,6 +326,9 @@ VHostNetState *get_vhost_net(NetClientState *nc)
case NET_CLIENT_OPTIONS_KIND_TAP:
vhost_net = tap_get_vhost_net(nc);
break;
+ case NET_CLIENT_OPTIONS_KIND_VHOST_USER:
+ vhost_net = vhost_user_get_vhost_net(nc);
+ break;
default:
break;
}
diff --git a/net/hub.c b/net/hub.c
index 33a99c9..7e0f2d6 100644
--- a/net/hub.c
+++ b/net/hub.c
@@ -322,6 +322,7 @@ void net_hub_check_clients(void)
case NET_CLIENT_OPTIONS_KIND_TAP:
case NET_CLIENT_OPTIONS_KIND_SOCKET:
case NET_CLIENT_OPTIONS_KIND_VDE:
+ case NET_CLIENT_OPTIONS_KIND_VHOST_USER:
has_host_dev = 1;
break;
default:
diff --git a/net/net.c b/net/net.c
index e3ef1e4..872ede4 100644
--- a/net/net.c
+++ b/net/net.c
@@ -769,23 +769,24 @@ static int (* const net_client_init_fun[NET_CLIENT_OPTIONS_KIND_MAX])(
const NetClientOptions *opts,
const char *name,
NetClientState *peer) = {
- [NET_CLIENT_OPTIONS_KIND_NIC] = net_init_nic,
+ [NET_CLIENT_OPTIONS_KIND_NIC] = net_init_nic,
#ifdef CONFIG_SLIRP
- [NET_CLIENT_OPTIONS_KIND_USER] = net_init_slirp,
+ [NET_CLIENT_OPTIONS_KIND_USER] = net_init_slirp,
#endif
- [NET_CLIENT_OPTIONS_KIND_TAP] = net_init_tap,
- [NET_CLIENT_OPTIONS_KIND_SOCKET] = net_init_socket,
+ [NET_CLIENT_OPTIONS_KIND_TAP] = net_init_tap,
+ [NET_CLIENT_OPTIONS_KIND_SOCKET] = net_init_socket,
#ifdef CONFIG_VDE
- [NET_CLIENT_OPTIONS_KIND_VDE] = net_init_vde,
+ [NET_CLIENT_OPTIONS_KIND_VDE] = net_init_vde,
#endif
#ifdef CONFIG_NETMAP
- [NET_CLIENT_OPTIONS_KIND_NETMAP] = net_init_netmap,
+ [NET_CLIENT_OPTIONS_KIND_NETMAP] = net_init_netmap,
#endif
- [NET_CLIENT_OPTIONS_KIND_DUMP] = net_init_dump,
+ [NET_CLIENT_OPTIONS_KIND_DUMP] = net_init_dump,
#ifdef CONFIG_NET_BRIDGE
- [NET_CLIENT_OPTIONS_KIND_BRIDGE] = net_init_bridge,
+ [NET_CLIENT_OPTIONS_KIND_BRIDGE] = net_init_bridge,
#endif
- [NET_CLIENT_OPTIONS_KIND_HUBPORT] = net_init_hubport,
+ [NET_CLIENT_OPTIONS_KIND_HUBPORT] = net_init_hubport,
+ [NET_CLIENT_OPTIONS_KIND_VHOST_USER] = net_init_vhost_user,
};
@@ -819,6 +820,7 @@ static int net_client_init1(const void *object, int is_netdev, Error **errp)
case NET_CLIENT_OPTIONS_KIND_BRIDGE:
#endif
case NET_CLIENT_OPTIONS_KIND_HUBPORT:
+ case NET_CLIENT_OPTIONS_KIND_VHOST_USER:
break;
default:
@@ -902,11 +904,12 @@ static int net_host_check_device(const char *device)
, "bridge"
#endif
#ifdef CONFIG_SLIRP
- ,"user"
+ , "user"
#endif
#ifdef CONFIG_VDE
- ,"vde"
+ , "vde"
#endif
+ , "vhost-user"
};
for (i = 0; i < ARRAY_SIZE(valid_param_list); i++) {
if (!strncmp(valid_param_list[i], device,
diff --git a/net/vhost-user.c b/net/vhost-user.c
index 292be41..600f31f 100644
--- a/net/vhost-user.c
+++ b/net/vhost-user.c
@@ -12,6 +12,7 @@
#include "net/vhost_net.h"
#include "net/vhost-user.h"
#include "sysemu/char.h"
+#include "qemu/config-file.h"
#include "qemu/error-report.h"
typedef struct VhostUserState {
@@ -22,9 +23,17 @@ typedef struct VhostUserState {
unsigned long long features;
} VhostUserState;
+typedef struct VhostUserChardevProps {
+ bool is_socket;
+ bool is_unix;
+ bool is_server;
+ bool has_unsupported;
+} VhostUserChardevProps;
+
VHostNetState *vhost_user_get_vhost_net(NetClientState *nc)
{
VhostUserState *s = DO_UPCAST(VhostUserState, nc, nc);
+ assert(nc->info->type == NET_CLIENT_OPTIONS_KIND_VHOST_USER);
return s->vhost_net;
}
@@ -79,7 +88,7 @@ static void vhost_user_cleanup(NetClientState *nc)
}
static NetClientInfo net_vhost_user_info = {
- .type = 0,
+ .type = NET_CLIENT_OPTIONS_KIND_VHOST_USER,
.size = sizeof(VhostUserState),
.cleanup = vhost_user_cleanup,
};
@@ -143,8 +152,122 @@ static int net_vhost_user_init(NetClientState *peer, const char *device,
return 0;
}
+static int net_vhost_chardev_opts(const char *name, const char *value,
+ void *opaque)
+{
+ VhostUserChardevProps *props = opaque;
+
+ if (strcmp(name, "backend") == 0 && strcmp(value, "socket") == 0) {
+ props->is_socket = 1;
+ } else if (strcmp(name, "path") == 0) {
+ props->is_unix = 1;
+ } else if (strcmp(name, "server") == 0) {
+ props->is_server = 1;
+ } else {
+ error_report("vhost-user does not support a chardev"
+ " with the following option:\n %s = %s",
+ name, value);
+ props->has_unsupported = 1;
+ return -1;
+ }
+ return 0;
+}
+
+static CharDriverState *net_vhost_parse_chardev(
+ const NetdevVhostUserOptions *opts)
+{
+ CharDriverState *chr = qemu_chr_find(opts->chardev);
+ VhostUserChardevProps props;
+
+ if (chr == NULL) {
+ error_report("chardev \"%s\" not found\n", opts->chardev);
+ return 0;
+ }
+
+ /* inspect chardev opts */
+ memset(&props, 0, sizeof(props));
+ qemu_opt_foreach(chr->opts, net_vhost_chardev_opts, &props, false);
+
+ if (!props.is_socket || !props.is_unix) {
+ error_report("chardev \"%s\" is not a unix socket\n",
+ opts->chardev);
+ return 0;
+ }
+
+ if (props.has_unsupported) {
+ error_report("chardev \"%s\" has an unsupported option\n",
+ opts->chardev);
+ return 0;
+ }
+
+ qemu_chr_fe_claim_no_fail(chr);
+
+ return chr;
+}
+
+static int net_vhost_check_net(QemuOpts *opts, void *opaque)
+{
+ const char *name = opaque;
+ const char *driver, *netdev;
+ const char virtio_name[] = "virtio-net-";
+
+ driver = qemu_opt_get(opts, "driver");
+ netdev = qemu_opt_get(opts, "netdev");
+
+ if (!driver || !netdev) {
+ return 0;
+ }
+
+ if ((strcmp(netdev, name) == 0)
+ && (strncmp(driver, virtio_name, strlen(virtio_name)) != 0)) {
+ error_report("vhost-user requires frontend driver virtio-net-*");
+ return -1;
+ }
+
+ return 0;
+}
+
int net_init_vhost_user(const NetClientOptions *opts, const char *name,
NetClientState *peer)
{
- return net_vhost_user_init(peer, "vhost_user", 0, 0, 0);
+ const NetdevVhostUserOptions *vhost_user_opts;
+ CharDriverState *chr;
+ bool vhostforce;
+ QemuOpts *mem_opts;
+ unsigned int mem_share = 0;
+
+ assert(opts->kind == NET_CLIENT_OPTIONS_KIND_VHOST_USER);
+ vhost_user_opts = opts->vhost_user;
+
+ chr = net_vhost_parse_chardev(vhost_user_opts);
+ if (!chr) {
+ error_report("No suitable chardev found\n");
+ return -1;
+ }
+
+ /* verify mem-path is set and shared */
+ mem_opts = qemu_opts_find(qemu_find_opts("mem-path"), NULL);
+ if (mem_opts) {
+ mem_share = qemu_opt_get_bool(mem_opts, "share", 0);
+ }
+
+ if (!mem_share) {
+ error_report("vhost-user requires -mem-path /path,share=on");
+ return -1;
+ }
+
+ /* verify net frontend */
+ if (qemu_opts_foreach(qemu_find_opts("device"), net_vhost_check_net,
+ (void *)name, true) == -1) {
+ return -1;
+ }
+
+ /* vhostforce for non-MSIX */
+ if (vhost_user_opts->has_vhostforce) {
+ vhostforce = vhost_user_opts->vhostforce;
+ } else {
+ vhostforce = false;
+ }
+
+ return net_vhost_user_init(peer, "vhost_user", name, chr, vhostforce);
}
diff --git a/qapi-schema.json b/qapi-schema.json
index ac8ad24..960a853 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -3183,6 +3183,22 @@
'*devname': 'str' } }
##
+# @NetdevVhostUserOptions
+#
+# Vhost-user network backend
+#
+# @path: control socket path
+#
+# @vhostforce: #optional vhost on for non-MSIX virtio guests (default: false).
+#
+# Since 2.0
+##
+{ 'type': 'NetdevVhostUserOptions',
+ 'data': {
+ 'chardev': 'str',
+ '*vhostforce': 'bool' } }
+
+##
# @NetClientOptions
#
# A discriminated record of network device traits.
@@ -3200,7 +3216,8 @@
'dump': 'NetdevDumpOptions',
'bridge': 'NetdevBridgeOptions',
'hubport': 'NetdevHubPortOptions',
- 'netmap': 'NetdevNetmapOptions' } }
+ 'netmap': 'NetdevNetmapOptions',
+ 'vhost-user': 'NetdevVhostUserOptions' } }
##
# @NetLegacy
diff --git a/qemu-options.hx b/qemu-options.hx
index f9f42a0..42a51ae 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -1434,6 +1434,7 @@ DEF("netdev", HAS_ARG, QEMU_OPTION_netdev,
#ifdef CONFIG_NETMAP
"netmap|"
#endif
+ "vhost-user|"
"socket|"
"hubport],id=str[,option][,option][,...]\n", QEMU_ARCH_ALL)
STEXI
@@ -1765,6 +1766,22 @@ The hubport netdev lets you connect a NIC to a QEMU "vlan" instead of a single
netdev. @code{-net} and @code{-device} with parameter @option{vlan} create the
required hub automatically.
+@item -netdev vhost-user,chardev=@var{id}[,vhostforce=on|off]
+
+Establish a vhost-user netdev, backed by a chardev @var{id}. The chardev should
+be a unix domain socket backed one. The vhost-user uses a specifically defined
+protocol to pass vhost ioctl replacement messages to an application on the other
+end of the socket. On non-MSIX guests, the feature can be forced with
+@var{vhostforce}.
+
+Example:
+@example
+qemu -m 1024 -mem-path /hugetlbfs,prealloc=on,share=on \
+ -chardev socket,path=/path/to/socket \
+ -netdev type=vhost-user,id=net0,chardev=chr0 \
+ -device virtio-net-pci,netdev=net0
+@end example
+
@item -net dump[,vlan=@var{n}][,file=@var{file}][,len=@var{len}]
Dump network traffic on VLAN @var{n} to file @var{file} (@file{qemu-vlan0.pcap} by default).
At most @var{len} bytes (64k by default) per packet are stored. The file format is
--
1.8.3.2
next prev parent reply other threads:[~2014-03-04 18:31 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-04 18:22 [Qemu-devel] [PATCH v9 00/20] Vhost and vhost-net support for userspace based backends Antonios Motakis
2014-03-04 18:22 ` [Qemu-devel] [PATCH v9 01/20] Convert -mem-path to QemuOpts and add share property Antonios Motakis
2014-03-04 18:22 ` [Qemu-devel] [PATCH v9 02/20] Add kvm_eventfds_enabled function Antonios Motakis
2014-03-04 18:22 ` [Qemu-devel] [PATCH v9 03/20] Add chardev API qemu_chr_fe_read_all Antonios Motakis
2014-03-04 18:22 ` [Qemu-devel] [PATCH v9 04/20] Add chardev API qemu_chr_fe_set_msgfds Antonios Motakis
2014-03-04 18:22 ` [Qemu-devel] [PATCH v9 05/20] Add chardev API qemu_chr_fe_get_msgfds Antonios Motakis
2014-03-04 18:22 ` [Qemu-devel] [PATCH v9 06/20] Add G_IO_HUP handler for socket chardev Antonios Motakis
2014-03-04 18:22 ` [Qemu-devel] [PATCH v9 07/20] vhost_net should call the poll callback only when it is set Antonios Motakis
2014-03-04 18:22 ` [Qemu-devel] [PATCH v9 08/20] Refactor virtio-net to use generic get_vhost_net Antonios Motakis
2014-03-04 18:22 ` [Qemu-devel] [PATCH v9 09/20] Add new virtio API virtio_queue_get_avail_idx Antonios Motakis
2014-03-04 18:22 ` [Qemu-devel] [PATCH v9 10/20] Gracefully handle ioctl failure in vhost_virtqueue_stop Antonios Motakis
2014-03-04 18:45 ` Michael S. Tsirkin
2014-03-05 13:38 ` Antonios Motakis
2014-03-05 13:47 ` Michael S. Tsirkin
2014-03-04 18:22 ` [Qemu-devel] [PATCH v9 11/20] vhost_net_init will use VhostNetOptions to get all its arguments Antonios Motakis
2014-03-04 18:22 ` [Qemu-devel] [PATCH v9 12/20] Add vhost_ops to vhost_dev struct and replace all relevant ioctls Antonios Motakis
2014-03-04 18:22 ` [Qemu-devel] [PATCH v9 13/20] Add mandatory_features to vhost_dev Antonios Motakis
2014-03-04 18:38 ` Michael S. Tsirkin
2014-03-05 13:40 ` Antonios Motakis
2014-03-04 18:22 ` [Qemu-devel] [PATCH v9 14/20] Add vhost-backend and VhostBackendType Antonios Motakis
2014-03-04 18:22 ` [Qemu-devel] [PATCH v9 15/20] Add vhost-user as a vhost backend Antonios Motakis
2014-03-04 18:22 ` [Qemu-devel] [PATCH v9 16/20] Add new vhost-user netdev backend Antonios Motakis
2014-03-04 18:23 ` Antonios Motakis [this message]
2014-03-04 18:23 ` [Qemu-devel] [PATCH v9 18/20] Add vhost-user protocol documentation Antonios Motakis
2014-03-04 18:23 ` [Qemu-devel] [PATCH v9 19/20] libqemustub: add stubs to be able to use qemu-char.c Antonios Motakis
2014-03-04 18:23 ` [Qemu-devel] [PATCH v9 20/20] Add qtest for vhost-user Antonios Motakis
2014-03-04 18:39 ` Andreas Färber
2014-03-05 13:39 ` Antonios Motakis
2014-03-04 18:29 ` [Qemu-devel] [PATCH v9 00/20] Vhost and vhost-net support for userspace based backends Paolo Bonzini
2014-03-04 18:33 ` Antonios Motakis
2014-03-04 18:38 ` Paolo Bonzini
2014-05-20 11:22 ` Nikolay Nikolaev
2014-05-20 12:51 ` Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1393957383-16685-18-git-send-email-a.motakis@virtualopensystems.com \
--to=a.motakis@virtualopensystems.com \
--cc=aliguori@amazon.com \
--cc=armbru@redhat.com \
--cc=coreyb@linux.vnet.ibm.com \
--cc=lcapitulino@redhat.com \
--cc=lukego@gmail.com \
--cc=mjt@tls.msk.ru \
--cc=mst@redhat.com \
--cc=n.nikolaev@virtualopensystems.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=snabb-devel@googlegroups.com \
--cc=stefanha@redhat.com \
--cc=tech@virtualopensystems.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).