From patchwork Tue Dec 10 00:25:07 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonios Motakis X-Patchwork-Id: 299243 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 2D26B2C00AC for ; Tue, 10 Dec 2013 11:28:49 +1100 (EST) Received: from localhost ([::1]:46602 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VqBBu-0006C6-La for incoming@patchwork.ozlabs.org; Mon, 09 Dec 2013 19:28:46 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57825) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VqB9L-0002ny-7K for qemu-devel@nongnu.org; Mon, 09 Dec 2013 19:26:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VqB9F-0002Xx-2U for qemu-devel@nongnu.org; Mon, 09 Dec 2013 19:26:07 -0500 Received: from mail-wg0-f52.google.com ([74.125.82.52]:52319) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VqB9E-0002XM-GR for qemu-devel@nongnu.org; Mon, 09 Dec 2013 19:26:00 -0500 Received: by mail-wg0-f52.google.com with SMTP id x13so4267327wgg.7 for ; Mon, 09 Dec 2013 16:25:59 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=bbUVtXcLET5xY/NzhjadmWfNxe+iIvjoEZnCCcUMPmc=; b=COZoh8j/Jw4yipYn5NsKB1IkRRnOSoSpGVaLv7ugFj2mlBgUVMAoz+F/8ErBLHqcxI QC8NN9jvocjbK3bLrrjbag7n1OqTPwkOR6K9kpuPedGB/+z6TV4szg7ryXgZktnPYZmv oE5FxsTvlblWdZShT/AhVu4o0gYBOVaePR6BHGbPCTGLtNS/5i74QVGmkgbKRVfaat6V QubN8/wv8h84X+YYhZ32w66Lx0mb3Oi0Yr4pSgbSlNaeyqaAG1naJAo0yjqI+jz7QGrs 3qRgPYQUSuTkGzTnXcvJLCt61FjXqnLjhHrNoZEic4yOi+dNP+RqRfyCNetckPTV+mWr IXeQ== X-Gm-Message-State: ALoCoQnsZs1N0KFdrfWoVf5XAkdxBi6+/RCM/TOQYf/ygrckNz71tCVOxGAejAe/yiZA06deLX9p X-Received: by 10.180.189.49 with SMTP id gf17mr16607792wic.23.1386635159838; Mon, 09 Dec 2013 16:25:59 -0800 (PST) Received: from localhost.localdomain (home.tvelocity.eu. [82.67.68.96]) by mx.google.com with ESMTPSA id mt2sm214519wic.7.2013.12.09.16.25.58 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 09 Dec 2013 16:25:59 -0800 (PST) From: Antonios Motakis To: qemu-devel@nongnu.org, snabb-devel@googlegroups.com Date: Tue, 10 Dec 2013 01:25:07 +0100 Message-Id: <1386635110-31990-4-git-send-email-a.motakis@virtualopensystems.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1386635110-31990-1-git-send-email-a.motakis@virtualopensystems.com> References: <1386635110-31990-1-git-send-email-a.motakis@virtualopensystems.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 74.125.82.52 Cc: lukego@gmail.com, Antonios Motakis , tech@virtualopensystems.com, n.nikolaev@virtualopensystems.com Subject: [Qemu-devel] [PATCH 3/6] Add vhost-user skeleton X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Add empty vhost_call, init and cleanup for the vhost-user backend. Signed-off-by: Antonios Motakis Signed-off-by: Nikolay Nikolaev --- hw/net/vhost_net.c | 55 ++++++++++++++++++++++----------------- hw/virtio/vhost-backend.c | 37 +++++++++++++++++++++++++- include/hw/virtio/vhost-backend.h | 3 ++- include/net/vhost_net.h | 13 ++++++++- net/tap.c | 16 +++++++----- 5 files changed, 91 insertions(+), 33 deletions(-) diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index b248c58..5fc2900 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -91,42 +91,50 @@ 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(VhostNetOptions *options) { - int r; + int r = -1; struct vhost_net *net = g_malloc(sizeof *net); - if (!backend) { - fprintf(stderr, "vhost-net requires backend to be setup\n"); + + if (!options->net_backend) { + fprintf(stderr, "vhost-net requires net backend to be setup\n"); goto fail; } - r = vhost_net_get_fd(backend); - if (r < 0) { - goto fail; + + if (options->backend_type == VHOST_BACKEND_TYPE_KERNEL) { + r = vhost_net_get_fd(options->net_backend); + if (r < 0) { + goto fail; + } + + net->dev.backend_features = + tap_has_vnet_hdr(options->net_backend) ? 0 : + (1 << VHOST_NET_F_VIRTIO_NET_HDR); } - net->nc = backend; - net->dev.backend_features = tap_has_vnet_hdr(backend) ? 0 : - (1 << VHOST_NET_F_VIRTIO_NET_HDR); + + net->nc = options->net_backend; net->backend = r; 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, options->devfd, options->devpath, + options->backend_type, options->force); if (r < 0) { goto fail; } - if (!tap_has_vnet_hdr_len(backend, - sizeof(struct virtio_net_hdr_mrg_rxbuf))) { - net->dev.features &= ~(1 << VIRTIO_NET_F_MRG_RXBUF); - } - if (~net->dev.features & net->dev.backend_features) { - fprintf(stderr, "vhost lacks feature mask %" PRIu64 " for backend\n", - (uint64_t)(~net->dev.features & net->dev.backend_features)); - vhost_dev_cleanup(&net->dev); - goto fail; + if ( options->backend_type == VHOST_BACKEND_TYPE_KERNEL) { + if (!tap_has_vnet_hdr_len(options->net_backend, + sizeof(struct virtio_net_hdr_mrg_rxbuf))) { + net->dev.features &= ~(1 << VIRTIO_NET_F_MRG_RXBUF); + } + if (~net->dev.features & net->dev.backend_features) { + fprintf(stderr, "vhost lacks feature mask %" PRIu64 " for backend\n", + (uint64_t)(~net->dev.features & net->dev.backend_features)); + vhost_dev_cleanup(&net->dev); + goto fail; + } } - /* Set sane init value. Override when guest acks. */ vhost_net_ack_features(net, 0); return net; @@ -285,8 +293,7 @@ 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(VhostNetOptions *options) { error_report("vhost-net support is not compiled in"); return NULL; diff --git a/hw/virtio/vhost-backend.c b/hw/virtio/vhost-backend.c index 410e77a..5519047 100644 --- a/hw/virtio/vhost-backend.c +++ b/hw/virtio/vhost-backend.c @@ -15,6 +15,38 @@ #include #include +static int vhost_user_call(struct vhost_dev *dev, unsigned long int request, + void *arg) +{ + assert(dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_USER); + fprintf(stderr, "vhost_user_call not implemented\n"); + + return -1; +} + +static int vhost_user_init(struct vhost_dev *dev, const char *devpath) +{ + assert(dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_USER); + fprintf(stderr, "vhost_user_init not implemented\n"); + + return -1; +} + +static int vhost_user_cleanup(struct vhost_dev *dev) +{ + assert(dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_USER); + fprintf(stderr, "vhost_user_cleanup not implemented\n"); + + return -1; +} + +static const VhostOps user_ops = { + .backend_type = VHOST_BACKEND_TYPE_USER, + .vhost_call = vhost_user_call, + .vhost_backend_init = vhost_user_init, + .vhost_backend_cleanup = vhost_user_cleanup +}; + static int vhost_kernel_call(struct vhost_dev *dev, unsigned long int request, void *arg) { @@ -55,10 +87,13 @@ int vhost_set_backend_type(struct vhost_dev *dev, VhostBackendType backend_type) case VHOST_BACKEND_TYPE_KERNEL: dev->vhost_ops = &kernel_ops; break; + case VHOST_BACKEND_TYPE_USER: + dev->vhost_ops = &user_ops; + break; default: fprintf(stderr, "Unknown vhost backend type\n"); r = -1; } return r; -} \ No newline at end of file +} diff --git a/include/hw/virtio/vhost-backend.h b/include/hw/virtio/vhost-backend.h index 8cc8235..bbb8709 100644 --- a/include/hw/virtio/vhost-backend.h +++ b/include/hw/virtio/vhost-backend.h @@ -14,7 +14,8 @@ typedef enum VhostBackendType { VHOST_BACKEND_TYPE_NONE = 0, VHOST_BACKEND_TYPE_KERNEL = 1, - VHOST_BACKEND_TYPE_MAX = 2, + VHOST_BACKEND_TYPE_USER = 2, + VHOST_BACKEND_TYPE_MAX = 3, } VhostBackendType; struct vhost_dev; diff --git a/include/net/vhost_net.h b/include/net/vhost_net.h index 2d936bb..1169562 100644 --- a/include/net/vhost_net.h +++ b/include/net/vhost_net.h @@ -2,11 +2,22 @@ #define VHOST_NET_H #include "net/net.h" +#include "hw/virtio/vhost-backend.h" + +#define VHOST_NET_DEFAULT_PATH "/dev/vhost-net" struct vhost_net; typedef struct vhost_net VHostNetState; -VHostNetState *vhost_net_init(NetClientState *backend, int devfd, bool force); +typedef struct VhostNetOptions { + VhostBackendType backend_type; + NetClientState *net_backend; + const char *devpath; + int devfd; + bool force; +} VhostNetOptions; + +struct vhost_net *vhost_net_init(VhostNetOptions *options); bool vhost_net_query(VHostNetState *net, VirtIODevice *dev); int vhost_net_start(VirtIODevice *dev, NetClientState *ncs, int total_queues); diff --git a/net/tap.c b/net/tap.c index 39c1cda..776dbc4 100644 --- a/net/tap.c +++ b/net/tap.c @@ -621,19 +621,23 @@ static int net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer, if (tap->has_vhost ? tap->vhost : vhostfdname || (tap->has_vhostforce && tap->vhostforce)) { - int vhostfd; + VhostNetOptions options; + + options.backend_type = VHOST_BACKEND_TYPE_KERNEL; + options.net_backend = &s->nc; + options.devpath = VHOST_NET_DEFAULT_PATH; + options.force = tap->has_vhostforce && tap->vhostforce; if (tap->has_vhostfd || tap->has_vhostfds) { - vhostfd = monitor_handle_fd_param(cur_mon, vhostfdname); - if (vhostfd == -1) { + options.devfd = monitor_handle_fd_param(cur_mon, vhostfdname); + if (options.devfd == -1) { return -1; } } else { - vhostfd = -1; + options.devfd = -1; } - s->vhost_net = vhost_net_init(&s->nc, vhostfd, - tap->has_vhostforce && tap->vhostforce); + s->vhost_net = vhost_net_init(&options); if (!s->vhost_net) { error_report("vhost-net requested but could not be initialized"); return -1;