From: Eric Blake <eblake@redhat.com>
To: Nikolay Nikolaev <n.nikolaev@virtualopensystems.com>,
snabb-devel@googlegroups.com, qemu-devel@nongnu.org
Cc: a.motakis@virtualopensystems.com, luke@snabb.co,
tech@virtualopensystems.com, mst@redhat.com
Subject: Re: [Qemu-devel] [PATCH v10 15/18] Add the vhost-user netdev backend to the command line
Date: Thu, 05 Jun 2014 10:08:16 -0600 [thread overview]
Message-ID: <539095F0.5020504@redhat.com> (raw)
In-Reply-To: <20140527120638.15172.80806.stgit@3820>
[-- Attachment #1: Type: text/plain, Size: 6006 bytes --]
On 05/27/2014 06:06 AM, Nikolay Nikolaev wrote:
> 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 `-numa node,memdev=..`
> - 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 | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++-
> qapi-schema.json | 19 ++++++++-
> qemu-options.hx | 18 ++++++++
> 7 files changed, 169 insertions(+), 16 deletions(-)
>
>
> +static int net_vhost_chardev_opts(const char *name, const char *value,
> + void *opaque)
Indentation is off (second line should be aligned to the ( of the first).
> +{
> + VhostUserChardevProps *props = opaque;
> +
> + if (strcmp(name, "backend") == 0 && strcmp(value, "socket") == 0) {
> + props->is_socket = 1;
s/1/true/ - when a field is a boolean, assign it boolean constants.
> + } 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;
and 3 more times.
> + return -1;
> + }
> + return 0;
> +}
> +
> +static CharDriverState *net_vhost_parse_chardev(
> + const NetdevVhostUserOptions *opts)
Unusual indentation, but I see your dilemma of fitting 80 columns.
> +{
> + CharDriverState *chr = qemu_chr_find(opts->chardev);
> + VhostUserChardevProps props;
> +
> + if (chr == NULL) {
> + error_report("chardev \"%s\" not found\n", opts->chardev);
> + return 0;
s/0/NULL/ - much nicer to use the named constant when referring to a
null pointer.
> + }
> +
> + /* 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;
2 more instances
> + }
> +
> + 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)) {
Unusual indentation and spurious ():
if (strcmp(netdev, name) == 0 &&
strncmp(driver, virtio_name, strlen(virtio_name)) != 0) {
> + error_report("vhost-user requires frontend driver virtio-net-*");
How many of these error_report() should be using Error **errp logistics
instead?
> + return -1;
> + }
> +
> + return 0;
> +}
> +
> int net_init_vhost_user(const NetClientOptions *opts, const char *name,
> NetClientState *peer)
Pre-existing indentation problem, but you could fix it here (or if you
introduced it earlier in the series, fix it there)
> {
> - return net_vhost_user_init(peer, "vhost_user", 0, 0, 0);
> + const NetdevVhostUserOptions *vhost_user_opts;
> + CharDriverState *chr;
> + bool vhostforce;
> +
> + 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");
No \n in error_report() messages.
> + return -1;
> + }
> +
> + /* verify net frontend */
> + if (qemu_opts_foreach(qemu_find_opts("device"), net_vhost_check_net,
> + (void *)name, true) == -1) {
This is C; why do you need a cast to (void*)?
> + 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 1f28177..f458dd8 100644
> --- a/qapi-schema.json
> +++ b/qapi-schema.json
> @@ -3264,6 +3264,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.1
> +##
> +{ 'type': 'NetdevVhostUserOptions',
> + 'data': {
> + 'chardev': 'str',
> + '*vhostforce': 'bool' } }
Bikeshedding - is 'vhost-force' any more legible?
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]
next prev parent reply other threads:[~2014-06-05 16:08 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20140527120050.15172.94908.stgit@3820>
2014-06-04 19:30 ` [Qemu-devel] [PATCH v10 00/18] Vhost and vhost-net support for userspace based backends Michael S. Tsirkin
2014-06-04 20:03 ` [Qemu-devel] [snabb-devel] " Nikolay Nikolaev
[not found] ` <20140527120330.15172.91211.stgit@3820>
2014-06-05 14:00 ` [Qemu-devel] [PATCH v10 01/18] Add kvm_eventfds_enabled function Paolo Bonzini
[not found] ` <20140527120638.15172.80806.stgit@3820>
2014-06-05 14:37 ` [Qemu-devel] [PATCH v10 15/18] Add the vhost-user netdev backend to the command line Luiz Capitulino
2014-06-09 13:28 ` [Qemu-devel] [snabb-devel] " Nikolay Nikolaev
2014-06-09 13:31 ` Michael S. Tsirkin
2014-06-09 13:43 ` Nikolay Nikolaev
2014-06-05 16:08 ` Eric Blake [this message]
2014-06-09 21:19 ` Nikolay Nikolaev
2014-06-09 22:22 ` Eric Blake
[not found] ` <20140527120651.15172.72895.stgit@3820>
2014-06-05 16:17 ` [Qemu-devel] [PATCH v10 16/18] Add vhost-user protocol documentation Eric Blake
2014-06-08 15:05 ` Michael S. Tsirkin
2014-06-08 15:12 ` [Qemu-devel] [PATCH v10 00/18] Vhost and vhost-net support for userspace based backends Michael S. Tsirkin
2014-06-09 10:14 ` [Qemu-devel] [snabb-devel] " Nikolay Nikolaev
[not found] ` <20140527120718.15172.9772.stgit@3820>
2014-07-09 14:24 ` [Qemu-devel] [PATCH v10 18/18] Add qtest for vhost-user Kevin Wolf
2014-07-09 15:09 ` [Qemu-devel] [snabb-devel] " Nikolay Nikolaev
2014-07-11 18:35 ` [Qemu-devel] " Michael S. Tsirkin
2014-07-11 18:35 ` [Qemu-devel] [snabb-devel] " Nikolay Nikolaev
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=539095F0.5020504@redhat.com \
--to=eblake@redhat.com \
--cc=a.motakis@virtualopensystems.com \
--cc=luke@snabb.co \
--cc=mst@redhat.com \
--cc=n.nikolaev@virtualopensystems.com \
--cc=qemu-devel@nongnu.org \
--cc=snabb-devel@googlegroups.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).