From: Antonios Motakis <a.motakis@virtualopensystems.com>
To: qemu-devel@nongnu.org
Cc: "Michael S. Tsirkin" <mst@redhat.com>,
n.nikolaev@virtualopensystems.com,
Anthony Liguori <anthony@codemonkey.ws>,
Paolo Bonzini <pbonzini@redhat.com>,
lukego@gmail.com,
Antonios Motakis <a.motakis@virtualopensystems.com>,
tech@virtualopensystems.com
Subject: [Qemu-devel] [PATCH 2/5] Add vhost-kernel and the vhost-user skeleton
Date: Fri, 29 Nov 2013 20:52:23 +0100 [thread overview]
Message-ID: <1385754746-21172-3-git-send-email-a.motakis@virtualopensystems.com> (raw)
In-Reply-To: <1385754746-21172-1-git-send-email-a.motakis@virtualopensystems.com>
Introduce the backend type - vhost-kernel and vhost-user.
Add basic ioctl, open, close multiplexing depending on selected backend.
Signed-off-by: Antonios Motakis <a.motakis@virtualopensystems.com>
Signed-off-by: Nikolay Nikolaev <n.nikolaev@virtualopensystems.com>
---
hw/net/vhost_net.c | 3 +--
hw/scsi/vhost-scsi.c | 4 ++--
hw/virtio/vhost-backend.c | 25 ++++++++++++++++++++++---
hw/virtio/vhost.c | 6 ++++--
include/hw/virtio/vhost-backend.h | 7 +++++++
include/hw/virtio/vhost.h | 4 +++-
6 files changed, 39 insertions(+), 10 deletions(-)
diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
index 0d1943f..58a1880 100644
--- a/hw/net/vhost_net.c
+++ b/hw/net/vhost_net.c
@@ -36,7 +36,6 @@
#include <stdio.h>
#include "hw/virtio/vhost.h"
-#include "hw/virtio/vhost-backend.h"
#include "hw/virtio/virtio-bus.h"
struct vhost_net {
@@ -113,7 +112,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", force);
+ r = vhost_dev_init(&net->dev, devfd, "/dev/vhost-net", VHOST_BACKEND_TYPE_KERNEL, force);
if (r < 0) {
goto fail;
}
diff --git a/hw/scsi/vhost-scsi.c b/hw/scsi/vhost-scsi.c
index 14d5030..fdc5d44 100644
--- a/hw/scsi/vhost-scsi.c
+++ b/hw/scsi/vhost-scsi.c
@@ -21,7 +21,6 @@
#include "migration/migration.h"
#include "hw/virtio/vhost-scsi.h"
#include "hw/virtio/vhost.h"
-#include "hw/virtio/vhost-backend.h"
#include "hw/virtio/virtio-scsi.h"
#include "hw/virtio/virtio-bus.h"
@@ -226,7 +225,8 @@ static int vhost_scsi_init(VirtIODevice *vdev)
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, vhostfd, "/dev/vhost-scsi",
+ VHOST_BACKEND_TYPE_KERNEL, true);
if (ret < 0) {
error_report("vhost-scsi: vhost initialization failed: %s\n",
strerror(-ret));
diff --git a/hw/virtio/vhost-backend.c b/hw/virtio/vhost-backend.c
index 05de174..80defe4 100644
--- a/hw/virtio/vhost-backend.c
+++ b/hw/virtio/vhost-backend.c
@@ -25,9 +25,18 @@ static int vhost_kernel_call(struct vhost_dev *dev, unsigned long int request,
int vhost_call(struct vhost_dev *dev, unsigned long int request, void *arg)
{
- int result;
+ int result = -1;
- result = vhost_kernel_call(dev, request, arg);
+ switch (dev->backend_type) {
+ case VHOST_BACKEND_TYPE_KERNEL:
+ result = vhost_kernel_call(dev, request, arg);
+ break;
+ case VHOST_BACKEND_TYPE_USER:
+ fprintf(stderr, "vhost-user not implemented\n");
+ break;
+ default:
+ fprintf(stderr, "Unknown vhost backend type\n");
+ }
return result;
}
@@ -36,7 +45,17 @@ int vhost_backend_init(struct vhost_dev *dev, const char *devpath)
{
int fd = -1;
- fd = open(devpath, O_RDWR);
+ switch (dev->backend_type) {
+ case VHOST_BACKEND_TYPE_KERNEL:
+ fd = open(devpath, O_RDWR);
+ break;
+ case VHOST_BACKEND_TYPE_USER:
+ fprintf(stderr, "vhost-user not implemented\n");
+ break;
+ default:
+ fprintf(stderr, "Unknown vhost backend type\n");
+ }
+
dev->control = fd;
return fd;
diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
index 42f4d5f..35eeb5f 100644
--- a/hw/virtio/vhost.c
+++ b/hw/virtio/vhost.c
@@ -14,7 +14,6 @@
*/
#include "hw/virtio/vhost.h"
-#include "hw/virtio/vhost-backend.h"
#include "hw/hw.h"
#include "qemu/atomic.h"
#include "qemu/range.h"
@@ -815,10 +814,13 @@ static void vhost_virtqueue_cleanup(struct vhost_virtqueue *vq)
}
int vhost_dev_init(struct vhost_dev *hdev, int devfd, const char *devpath,
- bool force)
+ VhostBackendType backend_type, bool force)
{
uint64_t features;
int i, r;
+
+ hdev->backend_type = backend_type;
+
if (devfd >= 0) {
hdev->control = devfd;
} else {
diff --git a/include/hw/virtio/vhost-backend.h b/include/hw/virtio/vhost-backend.h
index fc51b72..970f033 100644
--- a/include/hw/virtio/vhost-backend.h
+++ b/include/hw/virtio/vhost-backend.h
@@ -12,6 +12,13 @@
#ifndef VHOST_BACKEND_H_
#define VHOST_BACKEND_H_
+typedef enum VhostBackendType {
+ VHOST_BACKEND_TYPE_NONE = 0,
+ VHOST_BACKEND_TYPE_KERNEL = 1,
+ VHOST_BACKEND_TYPE_USER = 2,
+ VHOST_BACKEND_TYPE_MAX = 3,
+} VhostBackendType;
+
struct vhost_dev;
int vhost_call(struct vhost_dev *dev, unsigned long int request, void *arg);
diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h
index de24746..c08ae46 100644
--- a/include/hw/virtio/vhost.h
+++ b/include/hw/virtio/vhost.h
@@ -2,6 +2,7 @@
#define VHOST_H
#include "hw/hw.h"
+#include "hw/virtio/vhost-backend.h"
#include "hw/virtio/virtio.h"
#include "exec/memory.h"
@@ -48,10 +49,11 @@ struct vhost_dev {
bool memory_changed;
hwaddr mem_changed_start_addr;
hwaddr mem_changed_end_addr;
+ VhostBackendType backend_type;
};
int vhost_dev_init(struct vhost_dev *hdev, int devfd, const char *devpath,
- bool force);
+ VhostBackendType backend_type, bool force);
void vhost_dev_cleanup(struct vhost_dev *hdev);
bool vhost_dev_query(struct vhost_dev *hdev, VirtIODevice *vdev);
int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev);
--
1.8.3.2
next prev parent reply other threads:[~2013-11-29 19:53 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-29 19:52 [Qemu-devel] [RFC 0/5] Vhost and vhost-net support for userspace based backends Antonios Motakis
2013-11-29 19:52 ` [Qemu-devel] [PATCH 1/5] Decouple vhost from kernel interface Antonios Motakis
2013-11-29 19:52 ` Antonios Motakis [this message]
2013-12-04 13:47 ` [Qemu-devel] [PATCH 2/5] Add vhost-kernel and the vhost-user skeleton Stefan Hajnoczi
2013-12-04 15:23 ` Antonios Motakis
2013-11-29 19:52 ` [Qemu-devel] [PATCH 3/5] Add vhostsock option Antonios Motakis
2013-12-04 13:42 ` Stefan Hajnoczi
2013-12-04 15:21 ` Antonios Motakis
2013-12-04 14:28 ` Eric Blake
2013-11-29 19:52 ` [Qemu-devel] [PATCH 4/5] Add domain socket communication for vhost-user backend Antonios Motakis
2013-11-29 19:52 ` [Qemu-devel] [PATCH 5/5] Add vhost-user calls implementation Antonios Motakis
2013-12-04 20:00 ` Michael S. Tsirkin
2013-12-10 12:05 ` Antonios Motakis
2013-12-04 13:56 ` [Qemu-devel] [RFC 0/5] Vhost and vhost-net support for userspace based backends Stefan Hajnoczi
2013-12-04 15:23 ` Antonios Motakis
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=1385754746-21172-3-git-send-email-a.motakis@virtualopensystems.com \
--to=a.motakis@virtualopensystems.com \
--cc=anthony@codemonkey.ws \
--cc=lukego@gmail.com \
--cc=mst@redhat.com \
--cc=n.nikolaev@virtualopensystems.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--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).