From patchwork Thu Feb 13 12:03:19 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonios Motakis X-Patchwork-Id: 319992 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id CF3EF2C008F for ; Thu, 13 Feb 2014 23:09:07 +1100 (EST) Received: from localhost ([::1]:45757 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WDv6H-0006dI-H1 for incoming@patchwork.ozlabs.org; Thu, 13 Feb 2014 07:09:05 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39723) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WDv1c-0007li-Nk for qemu-devel@nongnu.org; Thu, 13 Feb 2014 07:04:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WDv1W-00016m-90 for qemu-devel@nongnu.org; Thu, 13 Feb 2014 07:04:16 -0500 Received: from mail-wi0-f173.google.com ([209.85.212.173]:61995) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WDv1W-00016W-0x for qemu-devel@nongnu.org; Thu, 13 Feb 2014 07:04:10 -0500 Received: by mail-wi0-f173.google.com with SMTP id hn9so8476346wib.0 for ; Thu, 13 Feb 2014 04:04:09 -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=OItmOh0a62P4pLGeBTqQXIDJPhP84u14yG1pNAisqOU=; b=S5Nub9hHqcXME2YbVDm+tIWup/ONZRbSmkCWQCJE82JzvEc7ewJtsKzav4HbfMn3df cN1qMbX/4xeSuaSR0bxeAu/VrLt54WQU7eTk/5H2jjBtq6xEvszWO3c9+3YMYvEFULi2 9utYZN0c0TOa/e8iMCh95ITTnwtluXLUrhltFAVMSTXRRNaG2KSXYcBI6pijC6uxq5eX PmvqKglBDFyPVIjMvR5KMKdXpqO0HjSWgtLjwLwHFYlSWjSDBkpcT0BlGyu0HirN/c+R g6+ruutQ+OUNf3rZIhIGq+x786z7f1pL1Za3v276JQCGWm+te1QopRHWCDvoF6IM3xi7 CTUw== X-Gm-Message-State: ALoCoQmqQp9HTlHpAek9KRmV74z8qTowXlYbaxfUgShWXjKci9ipLvxtG1I7JD8oqxU4yUuI+XfC X-Received: by 10.180.149.143 with SMTP id ua15mr2247198wib.36.1392293049252; Thu, 13 Feb 2014 04:04:09 -0800 (PST) Received: from localhost.localdomain (home.tvelocity.eu. [82.67.68.96]) by mx.google.com with ESMTPSA id bj3sm4039419wjb.14.2014.02.13.04.04.06 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 13 Feb 2014 04:04:08 -0800 (PST) From: Antonios Motakis To: qemu-devel@nongnu.org, snabb-devel@googlegroups.com Date: Thu, 13 Feb 2014 13:03:19 +0100 Message-Id: <1392293009-13812-9-git-send-email-a.motakis@virtualopensystems.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1392293009-13812-1-git-send-email-a.motakis@virtualopensystems.com> References: <1392293009-13812-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: 209.85.212.173 Cc: Stefan Hajnoczi , mst@redhat.com, n.nikolaev@virtualopensystems.com, Nicholas Bellinger , Anthony Liguori , Paolo Bonzini , lukego@gmail.com, Antonios Motakis , tech@virtualopensystems.com Subject: [Qemu-devel] [PATCH v8 08/17] vhost_net_init will use VhostNetOptions to get all its arguments 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 vhost_dev_init will replace devfd and devpath with a single opaque argument. This is initialised with a file descriptor. When TAP is used (through vhost_net), open /dev/vhost-net and pass the fd as an opaque parameter in VhostNetOptions. The same applies to vhost-scsi - open /dev/vhost-scsi and pass the fd. Signed-off-by: Antonios Motakis Signed-off-by: Nikolay Nikolaev --- hw/net/vhost_net.c | 24 +++++++++++++----------- hw/scsi/vhost-scsi.c | 10 +++++++++- hw/virtio/vhost.c | 12 +++--------- include/hw/virtio/vhost.h | 2 +- include/net/vhost_net.h | 8 +++++++- net/tap.c | 17 +++++++++++++---- 6 files changed, 46 insertions(+), 27 deletions(-) diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index 618e78e..493c643 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -92,32 +92,35 @@ 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; 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); + + r = vhost_net_get_fd(options->net_backend); if (r < 0) { goto fail; } - net->nc = backend; - net->dev.backend_features = tap_has_vnet_hdr(backend) ? 0 : + + net->nc = options->net_backend; + net->dev.backend_features = tap_has_vnet_hdr(options->net_backend) ? 0 : (1 << VHOST_NET_F_VIRTIO_NET_HDR); net->backend = r; net->dev.nvqs = 2; net->dev.vqs = net->vqs; - r = vhost_dev_init(&net->dev, devfd, "/dev/vhost-net", force); + r = vhost_dev_init(&net->dev, options->opaque, + options->force); if (r < 0) { goto fail; } - if (!tap_has_vnet_hdr_len(backend, + 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); } @@ -309,8 +312,7 @@ VHostNetState *get_vhost_net(NetClientState *nc) return vhost_net; } #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/scsi/vhost-scsi.c b/hw/scsi/vhost-scsi.c index 3983a5b..9b03fb6 100644 --- a/hw/scsi/vhost-scsi.c +++ b/hw/scsi/vhost-scsi.c @@ -215,6 +215,13 @@ static void vhost_scsi_realize(DeviceState *dev, Error **errp) error_setg(errp, "vhost-scsi: unable to parse vhostfd"); return; } + } else { + vhostfd = open("/dev/vhost-scsi", O_RDWR); + if (vhostfd < 0) { + error_setg(errp, "vhost-scsi: open vhost char device failed: %s", + strerror(errno)); + return; + } } virtio_scsi_common_realize(dev, &err); @@ -227,7 +234,8 @@ static void vhost_scsi_realize(DeviceState *dev, Error **errp) s->dev.vqs = g_new(struct vhost_virtqueue, s->dev.nvqs); s->dev.vq_index = 0; - ret = vhost_dev_init(&s->dev, vhostfd, "/dev/vhost-scsi", true); + ret = vhost_dev_init(&s->dev, (void *)(uintptr_t)vhostfd, + true); if (ret < 0) { error_setg(errp, "vhost-scsi: vhost initialization failed: %s", strerror(-ret)); diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 9e336ad..7636836 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -814,19 +814,13 @@ static void vhost_virtqueue_cleanup(struct vhost_virtqueue *vq) event_notifier_cleanup(&vq->masked_notifier); } -int vhost_dev_init(struct vhost_dev *hdev, int devfd, const char *devpath, +int vhost_dev_init(struct vhost_dev *hdev, void *opaque, bool force) { uint64_t features; int i, r; - if (devfd >= 0) { - hdev->control = devfd; - } else { - hdev->control = open(devpath, O_RDWR); - if (hdev->control < 0) { - return -errno; - } - } + hdev->control = (uintptr_t) opaque;; + r = ioctl(hdev->control, VHOST_SET_OWNER, NULL); if (r < 0) { goto fail; diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index de24746..eb25ffa 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -50,7 +50,7 @@ struct vhost_dev { hwaddr mem_changed_end_addr; }; -int vhost_dev_init(struct vhost_dev *hdev, int devfd, const char *devpath, +int vhost_dev_init(struct vhost_dev *hdev, void *opaque, bool force); void vhost_dev_cleanup(struct vhost_dev *hdev); bool vhost_dev_query(struct vhost_dev *hdev, VirtIODevice *vdev); diff --git a/include/net/vhost_net.h b/include/net/vhost_net.h index e2bd61c..2067ee2 100644 --- a/include/net/vhost_net.h +++ b/include/net/vhost_net.h @@ -6,7 +6,13 @@ struct vhost_net; typedef struct vhost_net VHostNetState; -VHostNetState *vhost_net_init(NetClientState *backend, int devfd, bool force); +typedef struct VhostNetOptions { + NetClientState *net_backend; + void *opaque; + 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..0840093 100644 --- a/net/tap.c +++ b/net/tap.c @@ -591,6 +591,7 @@ static int net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer, int vnet_hdr, int fd) { TAPState *s; + int vhostfd; s = net_tap_fd_init(peer, model, name, fd, vnet_hdr); if (!s) { @@ -621,7 +622,10 @@ 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.net_backend = &s->nc; + options.force = tap->has_vhostforce && tap->vhostforce; if (tap->has_vhostfd || tap->has_vhostfds) { vhostfd = monitor_handle_fd_param(cur_mon, vhostfdname); @@ -629,11 +633,16 @@ static int net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer, return -1; } } else { - vhostfd = -1; + vhostfd = open("/dev/vhost-net", O_RDWR); + if (vhostfd < 0) { + error_report("tap: open vhost char device failed: %s", + strerror(errno)); + return -1; + } } + options.opaque = (void *)(uintptr_t)vhostfd; - 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;