|
|
357786 |
From c957ec8a9629189e188747c48ed830599457e7c0 Mon Sep 17 00:00:00 2001
|
|
|
357786 |
From: "plai@redhat.com" <plai@redhat.com>
|
|
|
357786 |
Date: Thu, 21 Jun 2018 18:54:43 +0200
|
|
|
357786 |
Subject: [PATCH 34/57] vhost-user: introduce shared vhost-user state
|
|
|
357786 |
|
|
|
357786 |
RH-Author: plai@redhat.com
|
|
|
357786 |
Message-id: <1529607285-9942-9-git-send-email-plai@redhat.com>
|
|
|
357786 |
Patchwork-id: 80942
|
|
|
357786 |
O-Subject: [RHEL7.6 PATCH BZ 1526645 08/10] vhost-user: introduce shared vhost-user state
|
|
|
357786 |
Bugzilla: 1526645
|
|
|
357786 |
RH-Acked-by: Michael S. Tsirkin <mst@redhat.com>
|
|
|
357786 |
RH-Acked-by: Maxime Coquelin <maxime.coquelin@redhat.com>
|
|
|
357786 |
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
|
|
|
357786 |
|
|
|
357786 |
From: Tiwei Bie <tiwei.bie@intel.com>
|
|
|
357786 |
|
|
|
357786 |
When multi queue is enabled e.g. for a virtio-net device,
|
|
|
357786 |
each queue pair will have a vhost_dev, and the only thing
|
|
|
357786 |
shared between vhost devs currently is the chardev. This
|
|
|
357786 |
patch introduces a vhost-user state structure which will
|
|
|
357786 |
be shared by all vhost devs of the same virtio device.
|
|
|
357786 |
|
|
|
357786 |
Signed-off-by: Tiwei Bie <tiwei.bie@intel.com>
|
|
|
357786 |
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
|
|
|
357786 |
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
|
|
|
357786 |
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
|
|
|
357786 |
(cherry picked from commit 4d0cf552d3a9585f380e8abdc313e4d416a56aa0)
|
|
|
357786 |
Signed-off-by: Paul Lai <plai@redhat.com>
|
|
|
357786 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
357786 |
---
|
|
|
357786 |
backends/cryptodev-vhost-user.c | 20 ++++++++++++++++-
|
|
|
357786 |
hw/block/vhost-user-blk.c | 22 ++++++++++++++++++-
|
|
|
357786 |
hw/scsi/vhost-user-scsi.c | 20 ++++++++++++++++-
|
|
|
357786 |
hw/virtio/Makefile.objs | 2 +-
|
|
|
357786 |
hw/virtio/vhost-stub.c | 10 +++++++++
|
|
|
357786 |
hw/virtio/vhost-user.c | 31 ++++++++++++++++++--------
|
|
|
357786 |
include/hw/virtio/vhost-user-blk.h | 2 ++
|
|
|
357786 |
include/hw/virtio/vhost-user-scsi.h | 2 ++
|
|
|
357786 |
include/hw/virtio/vhost-user.h | 20 +++++++++++++++++
|
|
|
357786 |
net/vhost-user.c | 44 ++++++++++++++++++++++++++++++-------
|
|
|
357786 |
10 files changed, 152 insertions(+), 21 deletions(-)
|
|
|
357786 |
create mode 100644 include/hw/virtio/vhost-user.h
|
|
|
357786 |
|
|
|
357786 |
diff --git a/backends/cryptodev-vhost-user.c b/backends/cryptodev-vhost-user.c
|
|
|
357786 |
index 862d4f2..d52dacc 100644
|
|
|
357786 |
--- a/backends/cryptodev-vhost-user.c
|
|
|
357786 |
+++ b/backends/cryptodev-vhost-user.c
|
|
|
357786 |
@@ -26,6 +26,7 @@
|
|
|
357786 |
#include "qapi/error.h"
|
|
|
357786 |
#include "qapi/qmp/qerror.h"
|
|
|
357786 |
#include "qemu/error-report.h"
|
|
|
357786 |
+#include "hw/virtio/vhost-user.h"
|
|
|
357786 |
#include "standard-headers/linux/virtio_crypto.h"
|
|
|
357786 |
#include "sysemu/cryptodev-vhost.h"
|
|
|
357786 |
#include "chardev/char-fe.h"
|
|
|
357786 |
@@ -46,6 +47,7 @@
|
|
|
357786 |
typedef struct CryptoDevBackendVhostUser {
|
|
|
357786 |
CryptoDevBackend parent_obj;
|
|
|
357786 |
|
|
|
357786 |
+ VhostUserState *vhost_user;
|
|
|
357786 |
CharBackend chr;
|
|
|
357786 |
char *chr_name;
|
|
|
357786 |
bool opened;
|
|
|
357786 |
@@ -102,7 +104,7 @@ cryptodev_vhost_user_start(int queues,
|
|
|
357786 |
continue;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
- options.opaque = &s->chr;
|
|
|
357786 |
+ options.opaque = s->vhost_user;
|
|
|
357786 |
options.backend_type = VHOST_BACKEND_TYPE_USER;
|
|
|
357786 |
options.cc = b->conf.peers.ccs[i];
|
|
|
357786 |
s->vhost_crypto[i] = cryptodev_vhost_init(&options);
|
|
|
357786 |
@@ -185,6 +187,7 @@ static void cryptodev_vhost_user_init(
|
|
|
357786 |
size_t i;
|
|
|
357786 |
Error *local_err = NULL;
|
|
|
357786 |
Chardev *chr;
|
|
|
357786 |
+ VhostUserState *user;
|
|
|
357786 |
CryptoDevBackendClient *cc;
|
|
|
357786 |
CryptoDevBackendVhostUser *s =
|
|
|
357786 |
CRYPTODEV_BACKEND_VHOST_USER(backend);
|
|
|
357786 |
@@ -215,6 +218,15 @@ static void cryptodev_vhost_user_init(
|
|
|
357786 |
}
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
+ user = vhost_user_init();
|
|
|
357786 |
+ if (!user) {
|
|
|
357786 |
+ error_setg(errp, "Failed to init vhost_user");
|
|
|
357786 |
+ return;
|
|
|
357786 |
+ }
|
|
|
357786 |
+
|
|
|
357786 |
+ user->chr = &s->chr;
|
|
|
357786 |
+ s->vhost_user = user;
|
|
|
357786 |
+
|
|
|
357786 |
qemu_chr_fe_set_handlers(&s->chr, NULL, NULL,
|
|
|
357786 |
cryptodev_vhost_user_event, NULL, s, NULL, true);
|
|
|
357786 |
|
|
|
357786 |
@@ -299,6 +311,12 @@ static void cryptodev_vhost_user_cleanup(
|
|
|
357786 |
backend->conf.peers.ccs[i] = NULL;
|
|
|
357786 |
}
|
|
|
357786 |
}
|
|
|
357786 |
+
|
|
|
357786 |
+ if (s->vhost_user) {
|
|
|
357786 |
+ vhost_user_cleanup(s->vhost_user);
|
|
|
357786 |
+ g_free(s->vhost_user);
|
|
|
357786 |
+ s->vhost_user = NULL;
|
|
|
357786 |
+ }
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
static void cryptodev_vhost_user_set_chardev(Object *obj,
|
|
|
357786 |
diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c
|
|
|
357786 |
index 262baca..4021d71 100644
|
|
|
357786 |
--- a/hw/block/vhost-user-blk.c
|
|
|
357786 |
+++ b/hw/block/vhost-user-blk.c
|
|
|
357786 |
@@ -229,6 +229,7 @@ static void vhost_user_blk_device_realize(DeviceState *dev, Error **errp)
|
|
|
357786 |
{
|
|
|
357786 |
VirtIODevice *vdev = VIRTIO_DEVICE(dev);
|
|
|
357786 |
VHostUserBlk *s = VHOST_USER_BLK(vdev);
|
|
|
357786 |
+ VhostUserState *user;
|
|
|
357786 |
int i, ret;
|
|
|
357786 |
|
|
|
357786 |
if (!s->chardev.chr) {
|
|
|
357786 |
@@ -246,6 +247,15 @@ static void vhost_user_blk_device_realize(DeviceState *dev, Error **errp)
|
|
|
357786 |
return;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
+ user = vhost_user_init();
|
|
|
357786 |
+ if (!user) {
|
|
|
357786 |
+ error_setg(errp, "vhost-user-blk: failed to init vhost_user");
|
|
|
357786 |
+ return;
|
|
|
357786 |
+ }
|
|
|
357786 |
+
|
|
|
357786 |
+ user->chr = &s->chardev;
|
|
|
357786 |
+ s->vhost_user = user;
|
|
|
357786 |
+
|
|
|
357786 |
virtio_init(vdev, "virtio-blk", VIRTIO_ID_BLOCK,
|
|
|
357786 |
sizeof(struct virtio_blk_config));
|
|
|
357786 |
|
|
|
357786 |
@@ -261,7 +271,7 @@ static void vhost_user_blk_device_realize(DeviceState *dev, Error **errp)
|
|
|
357786 |
|
|
|
357786 |
vhost_dev_set_config_notifier(&s->dev, &blk_ops);
|
|
|
357786 |
|
|
|
357786 |
- ret = vhost_dev_init(&s->dev, &s->chardev, VHOST_BACKEND_TYPE_USER, 0);
|
|
|
357786 |
+ ret = vhost_dev_init(&s->dev, s->vhost_user, VHOST_BACKEND_TYPE_USER, 0);
|
|
|
357786 |
if (ret < 0) {
|
|
|
357786 |
error_setg(errp, "vhost-user-blk: vhost initialization failed: %s",
|
|
|
357786 |
strerror(-ret));
|
|
|
357786 |
@@ -286,6 +296,10 @@ vhost_err:
|
|
|
357786 |
virtio_err:
|
|
|
357786 |
g_free(s->dev.vqs);
|
|
|
357786 |
virtio_cleanup(vdev);
|
|
|
357786 |
+
|
|
|
357786 |
+ vhost_user_cleanup(user);
|
|
|
357786 |
+ g_free(user);
|
|
|
357786 |
+ s->vhost_user = NULL;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
static void vhost_user_blk_device_unrealize(DeviceState *dev, Error **errp)
|
|
|
357786 |
@@ -297,6 +311,12 @@ static void vhost_user_blk_device_unrealize(DeviceState *dev, Error **errp)
|
|
|
357786 |
vhost_dev_cleanup(&s->dev);
|
|
|
357786 |
g_free(s->dev.vqs);
|
|
|
357786 |
virtio_cleanup(vdev);
|
|
|
357786 |
+
|
|
|
357786 |
+ if (s->vhost_user) {
|
|
|
357786 |
+ vhost_user_cleanup(s->vhost_user);
|
|
|
357786 |
+ g_free(s->vhost_user);
|
|
|
357786 |
+ s->vhost_user = NULL;
|
|
|
357786 |
+ }
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
static void vhost_user_blk_instance_init(Object *obj)
|
|
|
357786 |
diff --git a/hw/scsi/vhost-user-scsi.c b/hw/scsi/vhost-user-scsi.c
|
|
|
357786 |
index 9389ed4..9355cfd 100644
|
|
|
357786 |
--- a/hw/scsi/vhost-user-scsi.c
|
|
|
357786 |
+++ b/hw/scsi/vhost-user-scsi.c
|
|
|
357786 |
@@ -69,6 +69,7 @@ static void vhost_user_scsi_realize(DeviceState *dev, Error **errp)
|
|
|
357786 |
VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(dev);
|
|
|
357786 |
VHostUserSCSI *s = VHOST_USER_SCSI(dev);
|
|
|
357786 |
VHostSCSICommon *vsc = VHOST_SCSI_COMMON(s);
|
|
|
357786 |
+ VhostUserState *user;
|
|
|
357786 |
Error *err = NULL;
|
|
|
357786 |
int ret;
|
|
|
357786 |
|
|
|
357786 |
@@ -85,19 +86,30 @@ static void vhost_user_scsi_realize(DeviceState *dev, Error **errp)
|
|
|
357786 |
return;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
+ user = vhost_user_init();
|
|
|
357786 |
+ if (!user) {
|
|
|
357786 |
+ error_setg(errp, "vhost-user-scsi: failed to init vhost_user");
|
|
|
357786 |
+ return;
|
|
|
357786 |
+ }
|
|
|
357786 |
+ user->chr = &vs->conf.chardev;
|
|
|
357786 |
+
|
|
|
357786 |
vsc->dev.nvqs = 2 + vs->conf.num_queues;
|
|
|
357786 |
vsc->dev.vqs = g_new(struct vhost_virtqueue, vsc->dev.nvqs);
|
|
|
357786 |
vsc->dev.vq_index = 0;
|
|
|
357786 |
vsc->dev.backend_features = 0;
|
|
|
357786 |
|
|
|
357786 |
- ret = vhost_dev_init(&vsc->dev, (void *)&vs->conf.chardev,
|
|
|
357786 |
+ ret = vhost_dev_init(&vsc->dev, user,
|
|
|
357786 |
VHOST_BACKEND_TYPE_USER, 0);
|
|
|
357786 |
if (ret < 0) {
|
|
|
357786 |
error_setg(errp, "vhost-user-scsi: vhost initialization failed: %s",
|
|
|
357786 |
strerror(-ret));
|
|
|
357786 |
+ vhost_user_cleanup(user);
|
|
|
357786 |
+ g_free(user);
|
|
|
357786 |
return;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
+ s->vhost_user = user;
|
|
|
357786 |
+
|
|
|
357786 |
/* Channel and lun both are 0 for bootable vhost-user-scsi disk */
|
|
|
357786 |
vsc->channel = 0;
|
|
|
357786 |
vsc->lun = 0;
|
|
|
357786 |
@@ -117,6 +129,12 @@ static void vhost_user_scsi_unrealize(DeviceState *dev, Error **errp)
|
|
|
357786 |
g_free(vsc->dev.vqs);
|
|
|
357786 |
|
|
|
357786 |
virtio_scsi_common_unrealize(dev, errp);
|
|
|
357786 |
+
|
|
|
357786 |
+ if (s->vhost_user) {
|
|
|
357786 |
+ vhost_user_cleanup(s->vhost_user);
|
|
|
357786 |
+ g_free(s->vhost_user);
|
|
|
357786 |
+ s->vhost_user = NULL;
|
|
|
357786 |
+ }
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
static uint64_t vhost_user_scsi_get_features(VirtIODevice *vdev,
|
|
|
357786 |
diff --git a/hw/virtio/Makefile.objs b/hw/virtio/Makefile.objs
|
|
|
357786 |
index a5a0936..00c6696 100644
|
|
|
357786 |
--- a/hw/virtio/Makefile.objs
|
|
|
357786 |
+++ b/hw/virtio/Makefile.objs
|
|
|
357786 |
@@ -12,5 +12,5 @@ obj-$(CONFIG_VHOST_VSOCK) += vhost-vsock.o
|
|
|
357786 |
#obj-$(CONFIG_VIRTIO_PCI) += virtio-crypto-pci.o
|
|
|
357786 |
endif
|
|
|
357786 |
|
|
|
357786 |
-common-obj-$(call lnot,$(CONFIG_LINUX)) += vhost-stub.o
|
|
|
357786 |
+common-obj-$(call lnot,$(call land,$(CONFIG_VIRTIO),$(CONFIG_LINUX))) += vhost-stub.o
|
|
|
357786 |
common-obj-$(CONFIG_ALL) += vhost-stub.o
|
|
|
357786 |
diff --git a/hw/virtio/vhost-stub.c b/hw/virtio/vhost-stub.c
|
|
|
357786 |
index 2d76cde..049089b 100644
|
|
|
357786 |
--- a/hw/virtio/vhost-stub.c
|
|
|
357786 |
+++ b/hw/virtio/vhost-stub.c
|
|
|
357786 |
@@ -1,7 +1,17 @@
|
|
|
357786 |
#include "qemu/osdep.h"
|
|
|
357786 |
#include "hw/virtio/vhost.h"
|
|
|
357786 |
+#include "hw/virtio/vhost-user.h"
|
|
|
357786 |
|
|
|
357786 |
bool vhost_has_free_slot(void)
|
|
|
357786 |
{
|
|
|
357786 |
return true;
|
|
|
357786 |
}
|
|
|
357786 |
+
|
|
|
357786 |
+VhostUserState *vhost_user_init(void)
|
|
|
357786 |
+{
|
|
|
357786 |
+ return NULL;
|
|
|
357786 |
+}
|
|
|
357786 |
+
|
|
|
357786 |
+void vhost_user_cleanup(VhostUserState *user)
|
|
|
357786 |
+{
|
|
|
357786 |
+}
|
|
|
357786 |
diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
|
|
|
357786 |
index e8027ad..a715c5c 100644
|
|
|
357786 |
--- a/hw/virtio/vhost-user.c
|
|
|
357786 |
+++ b/hw/virtio/vhost-user.c
|
|
|
357786 |
@@ -11,6 +11,7 @@
|
|
|
357786 |
#include "qemu/osdep.h"
|
|
|
357786 |
#include "qapi/error.h"
|
|
|
357786 |
#include "hw/virtio/vhost.h"
|
|
|
357786 |
+#include "hw/virtio/vhost-user.h"
|
|
|
357786 |
#include "hw/virtio/vhost-backend.h"
|
|
|
357786 |
#include "hw/virtio/virtio-net.h"
|
|
|
357786 |
#include "chardev/char-fe.h"
|
|
|
357786 |
@@ -175,7 +176,8 @@ static VhostUserMsg m __attribute__ ((unused));
|
|
|
357786 |
|
|
|
357786 |
struct vhost_user {
|
|
|
357786 |
struct vhost_dev *dev;
|
|
|
357786 |
- CharBackend *chr;
|
|
|
357786 |
+ /* Shared between vhost devs of the same virtio device */
|
|
|
357786 |
+ VhostUserState *user;
|
|
|
357786 |
int slave_fd;
|
|
|
357786 |
NotifierWithReturn postcopy_notifier;
|
|
|
357786 |
struct PostCopyFD postcopy_fd;
|
|
|
357786 |
@@ -201,7 +203,7 @@ static bool ioeventfd_enabled(void)
|
|
|
357786 |
static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg)
|
|
|
357786 |
{
|
|
|
357786 |
struct vhost_user *u = dev->opaque;
|
|
|
357786 |
- CharBackend *chr = u->chr;
|
|
|
357786 |
+ CharBackend *chr = u->user->chr;
|
|
|
357786 |
uint8_t *p = (uint8_t *) msg;
|
|
|
357786 |
int r, size = VHOST_USER_HDR_SIZE;
|
|
|
357786 |
|
|
|
357786 |
@@ -287,7 +289,7 @@ static int vhost_user_write(struct vhost_dev *dev, VhostUserMsg *msg,
|
|
|
357786 |
int *fds, int fd_num)
|
|
|
357786 |
{
|
|
|
357786 |
struct vhost_user *u = dev->opaque;
|
|
|
357786 |
- CharBackend *chr = u->chr;
|
|
|
357786 |
+ CharBackend *chr = u->user->chr;
|
|
|
357786 |
int ret, size = VHOST_USER_HDR_SIZE + msg->hdr.size;
|
|
|
357786 |
|
|
|
357786 |
/*
|
|
|
357786 |
@@ -1090,7 +1092,7 @@ static int vhost_user_postcopy_waker(struct PostCopyFD *pcfd, RAMBlock *rb,
|
|
|
357786 |
static int vhost_user_postcopy_advise(struct vhost_dev *dev, Error **errp)
|
|
|
357786 |
{
|
|
|
357786 |
struct vhost_user *u = dev->opaque;
|
|
|
357786 |
- CharBackend *chr = u->chr;
|
|
|
357786 |
+ CharBackend *chr = u->user->chr;
|
|
|
357786 |
int ufd;
|
|
|
357786 |
VhostUserMsg msg = {
|
|
|
357786 |
.hdr.request = VHOST_USER_POSTCOPY_ADVISE,
|
|
|
357786 |
@@ -1228,7 +1230,7 @@ static int vhost_user_postcopy_notifier(NotifierWithReturn *notifier,
|
|
|
357786 |
return 0;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
-static int vhost_user_init(struct vhost_dev *dev, void *opaque)
|
|
|
357786 |
+static int vhost_user_backend_init(struct vhost_dev *dev, void *opaque)
|
|
|
357786 |
{
|
|
|
357786 |
uint64_t features, protocol_features;
|
|
|
357786 |
struct vhost_user *u;
|
|
|
357786 |
@@ -1237,7 +1239,7 @@ static int vhost_user_init(struct vhost_dev *dev, void *opaque)
|
|
|
357786 |
assert(dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_USER);
|
|
|
357786 |
|
|
|
357786 |
u = g_new0(struct vhost_user, 1);
|
|
|
357786 |
- u->chr = opaque;
|
|
|
357786 |
+ u->user = opaque;
|
|
|
357786 |
u->slave_fd = -1;
|
|
|
357786 |
u->dev = dev;
|
|
|
357786 |
dev->opaque = u;
|
|
|
357786 |
@@ -1313,7 +1315,7 @@ static int vhost_user_init(struct vhost_dev *dev, void *opaque)
|
|
|
357786 |
return 0;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
-static int vhost_user_cleanup(struct vhost_dev *dev)
|
|
|
357786 |
+static int vhost_user_backend_cleanup(struct vhost_dev *dev)
|
|
|
357786 |
{
|
|
|
357786 |
struct vhost_user *u;
|
|
|
357786 |
|
|
|
357786 |
@@ -1637,10 +1639,21 @@ static bool vhost_user_mem_section_filter(struct vhost_dev *dev,
|
|
|
357786 |
return result;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
+VhostUserState *vhost_user_init(void)
|
|
|
357786 |
+{
|
|
|
357786 |
+ VhostUserState *user = g_new0(struct VhostUserState, 1);
|
|
|
357786 |
+
|
|
|
357786 |
+ return user;
|
|
|
357786 |
+}
|
|
|
357786 |
+
|
|
|
357786 |
+void vhost_user_cleanup(VhostUserState *user)
|
|
|
357786 |
+{
|
|
|
357786 |
+}
|
|
|
357786 |
+
|
|
|
357786 |
const VhostOps user_ops = {
|
|
|
357786 |
.backend_type = VHOST_BACKEND_TYPE_USER,
|
|
|
357786 |
- .vhost_backend_init = vhost_user_init,
|
|
|
357786 |
- .vhost_backend_cleanup = vhost_user_cleanup,
|
|
|
357786 |
+ .vhost_backend_init = vhost_user_backend_init,
|
|
|
357786 |
+ .vhost_backend_cleanup = vhost_user_backend_cleanup,
|
|
|
357786 |
.vhost_backend_memslots_limit = vhost_user_memslots_limit,
|
|
|
357786 |
.vhost_set_log_base = vhost_user_set_log_base,
|
|
|
357786 |
.vhost_set_mem_table = vhost_user_set_mem_table,
|
|
|
357786 |
diff --git a/include/hw/virtio/vhost-user-blk.h b/include/hw/virtio/vhost-user-blk.h
|
|
|
357786 |
index 5804cc9..f1258ae 100644
|
|
|
357786 |
--- a/include/hw/virtio/vhost-user-blk.h
|
|
|
357786 |
+++ b/include/hw/virtio/vhost-user-blk.h
|
|
|
357786 |
@@ -21,6 +21,7 @@
|
|
|
357786 |
#include "hw/block/block.h"
|
|
|
357786 |
#include "chardev/char-fe.h"
|
|
|
357786 |
#include "hw/virtio/vhost.h"
|
|
|
357786 |
+#include "hw/virtio/vhost-user.h"
|
|
|
357786 |
|
|
|
357786 |
#define TYPE_VHOST_USER_BLK "vhost-user-blk"
|
|
|
357786 |
#define VHOST_USER_BLK(obj) \
|
|
|
357786 |
@@ -36,6 +37,7 @@ typedef struct VHostUserBlk {
|
|
|
357786 |
uint32_t config_wce;
|
|
|
357786 |
uint32_t config_ro;
|
|
|
357786 |
struct vhost_dev dev;
|
|
|
357786 |
+ VhostUserState *vhost_user;
|
|
|
357786 |
} VHostUserBlk;
|
|
|
357786 |
|
|
|
357786 |
#endif
|
|
|
357786 |
diff --git a/include/hw/virtio/vhost-user-scsi.h b/include/hw/virtio/vhost-user-scsi.h
|
|
|
357786 |
index 01861f7..3ec34ae 100644
|
|
|
357786 |
--- a/include/hw/virtio/vhost-user-scsi.h
|
|
|
357786 |
+++ b/include/hw/virtio/vhost-user-scsi.h
|
|
|
357786 |
@@ -21,6 +21,7 @@
|
|
|
357786 |
#include "hw/qdev.h"
|
|
|
357786 |
#include "hw/virtio/virtio-scsi.h"
|
|
|
357786 |
#include "hw/virtio/vhost.h"
|
|
|
357786 |
+#include "hw/virtio/vhost-user.h"
|
|
|
357786 |
#include "hw/virtio/vhost-scsi-common.h"
|
|
|
357786 |
|
|
|
357786 |
#define TYPE_VHOST_USER_SCSI "vhost-user-scsi"
|
|
|
357786 |
@@ -30,6 +31,7 @@
|
|
|
357786 |
typedef struct VHostUserSCSI {
|
|
|
357786 |
VHostSCSICommon parent_obj;
|
|
|
357786 |
uint64_t host_features;
|
|
|
357786 |
+ VhostUserState *vhost_user;
|
|
|
357786 |
} VHostUserSCSI;
|
|
|
357786 |
|
|
|
357786 |
#endif /* VHOST_USER_SCSI_H */
|
|
|
357786 |
diff --git a/include/hw/virtio/vhost-user.h b/include/hw/virtio/vhost-user.h
|
|
|
357786 |
new file mode 100644
|
|
|
357786 |
index 0000000..eb8bc0d
|
|
|
357786 |
--- /dev/null
|
|
|
357786 |
+++ b/include/hw/virtio/vhost-user.h
|
|
|
357786 |
@@ -0,0 +1,20 @@
|
|
|
357786 |
+/*
|
|
|
357786 |
+ * Copyright (c) 2017-2018 Intel Corporation
|
|
|
357786 |
+ *
|
|
|
357786 |
+ * This work is licensed under the terms of the GNU GPL, version 2.
|
|
|
357786 |
+ * See the COPYING file in the top-level directory.
|
|
|
357786 |
+ */
|
|
|
357786 |
+
|
|
|
357786 |
+#ifndef HW_VIRTIO_VHOST_USER_H
|
|
|
357786 |
+#define HW_VIRTIO_VHOST_USER_H
|
|
|
357786 |
+
|
|
|
357786 |
+#include "chardev/char-fe.h"
|
|
|
357786 |
+
|
|
|
357786 |
+typedef struct VhostUserState {
|
|
|
357786 |
+ CharBackend *chr;
|
|
|
357786 |
+} VhostUserState;
|
|
|
357786 |
+
|
|
|
357786 |
+VhostUserState *vhost_user_init(void);
|
|
|
357786 |
+void vhost_user_cleanup(VhostUserState *user);
|
|
|
357786 |
+
|
|
|
357786 |
+#endif
|
|
|
357786 |
diff --git a/net/vhost-user.c b/net/vhost-user.c
|
|
|
357786 |
index fa28aad..608b837 100644
|
|
|
357786 |
--- a/net/vhost-user.c
|
|
|
357786 |
+++ b/net/vhost-user.c
|
|
|
357786 |
@@ -12,6 +12,7 @@
|
|
|
357786 |
#include "clients.h"
|
|
|
357786 |
#include "net/vhost_net.h"
|
|
|
357786 |
#include "net/vhost-user.h"
|
|
|
357786 |
+#include "hw/virtio/vhost-user.h"
|
|
|
357786 |
#include "chardev/char-fe.h"
|
|
|
357786 |
#include "qapi/error.h"
|
|
|
357786 |
#include "qapi/qapi-commands-net.h"
|
|
|
357786 |
@@ -23,6 +24,7 @@
|
|
|
357786 |
typedef struct NetVhostUserState {
|
|
|
357786 |
NetClientState nc;
|
|
|
357786 |
CharBackend chr; /* only queue index 0 */
|
|
|
357786 |
+ VhostUserState *vhost_user;
|
|
|
357786 |
VHostNetState *vhost_net;
|
|
|
357786 |
guint watch;
|
|
|
357786 |
uint64_t acked_features;
|
|
|
357786 |
@@ -64,7 +66,8 @@ static void vhost_user_stop(int queues, NetClientState *ncs[])
|
|
|
357786 |
}
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
-static int vhost_user_start(int queues, NetClientState *ncs[], CharBackend *be)
|
|
|
357786 |
+static int vhost_user_start(int queues, NetClientState *ncs[],
|
|
|
357786 |
+ VhostUserState *be)
|
|
|
357786 |
{
|
|
|
357786 |
VhostNetOptions options;
|
|
|
357786 |
struct vhost_net *net = NULL;
|
|
|
357786 |
@@ -144,7 +147,7 @@ static ssize_t vhost_user_receive(NetClientState *nc, const uint8_t *buf,
|
|
|
357786 |
return size;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
-static void vhost_user_cleanup(NetClientState *nc)
|
|
|
357786 |
+static void net_vhost_user_cleanup(NetClientState *nc)
|
|
|
357786 |
{
|
|
|
357786 |
NetVhostUserState *s = DO_UPCAST(NetVhostUserState, nc, nc);
|
|
|
357786 |
|
|
|
357786 |
@@ -159,6 +162,11 @@ static void vhost_user_cleanup(NetClientState *nc)
|
|
|
357786 |
s->watch = 0;
|
|
|
357786 |
}
|
|
|
357786 |
qemu_chr_fe_deinit(&s->chr, true);
|
|
|
357786 |
+ if (s->vhost_user) {
|
|
|
357786 |
+ vhost_user_cleanup(s->vhost_user);
|
|
|
357786 |
+ g_free(s->vhost_user);
|
|
|
357786 |
+ s->vhost_user = NULL;
|
|
|
357786 |
+ }
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
qemu_purge_queued_packets(nc);
|
|
|
357786 |
@@ -182,7 +190,7 @@ static NetClientInfo net_vhost_user_info = {
|
|
|
357786 |
.type = NET_CLIENT_DRIVER_VHOST_USER,
|
|
|
357786 |
.size = sizeof(NetVhostUserState),
|
|
|
357786 |
.receive = vhost_user_receive,
|
|
|
357786 |
- .cleanup = vhost_user_cleanup,
|
|
|
357786 |
+ .cleanup = net_vhost_user_cleanup,
|
|
|
357786 |
.has_vnet_hdr = vhost_user_has_vnet_hdr,
|
|
|
357786 |
.has_ufo = vhost_user_has_ufo,
|
|
|
357786 |
};
|
|
|
357786 |
@@ -244,7 +252,7 @@ static void net_vhost_user_event(void *opaque, int event)
|
|
|
357786 |
trace_vhost_user_event(chr->label, event);
|
|
|
357786 |
switch (event) {
|
|
|
357786 |
case CHR_EVENT_OPENED:
|
|
|
357786 |
- if (vhost_user_start(queues, ncs, &s->chr) < 0) {
|
|
|
357786 |
+ if (vhost_user_start(queues, ncs, s->vhost_user) < 0) {
|
|
|
357786 |
qemu_chr_fe_disconnect(&s->chr);
|
|
|
357786 |
return;
|
|
|
357786 |
}
|
|
|
357786 |
@@ -283,12 +291,19 @@ static int net_vhost_user_init(NetClientState *peer, const char *device,
|
|
|
357786 |
{
|
|
|
357786 |
Error *err = NULL;
|
|
|
357786 |
NetClientState *nc, *nc0 = NULL;
|
|
|
357786 |
- NetVhostUserState *s;
|
|
|
357786 |
+ VhostUserState *user = NULL;
|
|
|
357786 |
+ NetVhostUserState *s = NULL;
|
|
|
357786 |
int i;
|
|
|
357786 |
|
|
|
357786 |
assert(name);
|
|
|
357786 |
assert(queues > 0);
|
|
|
357786 |
|
|
|
357786 |
+ user = vhost_user_init();
|
|
|
357786 |
+ if (!user) {
|
|
|
357786 |
+ error_report("failed to init vhost_user");
|
|
|
357786 |
+ goto err;
|
|
|
357786 |
+ }
|
|
|
357786 |
+
|
|
|
357786 |
for (i = 0; i < queues; i++) {
|
|
|
357786 |
nc = qemu_new_net_client(&net_vhost_user_info, peer, device, name);
|
|
|
357786 |
snprintf(nc->info_str, sizeof(nc->info_str), "vhost-user%d to %s",
|
|
|
357786 |
@@ -299,17 +314,19 @@ static int net_vhost_user_init(NetClientState *peer, const char *device,
|
|
|
357786 |
s = DO_UPCAST(NetVhostUserState, nc, nc);
|
|
|
357786 |
if (!qemu_chr_fe_init(&s->chr, chr, &err)) {
|
|
|
357786 |
error_report_err(err);
|
|
|
357786 |
- return -1;
|
|
|
357786 |
+ goto err;
|
|
|
357786 |
}
|
|
|
357786 |
+ user->chr = &s->chr;
|
|
|
357786 |
}
|
|
|
357786 |
-
|
|
|
357786 |
+ s = DO_UPCAST(NetVhostUserState, nc, nc);
|
|
|
357786 |
+ s->vhost_user = user;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
s = DO_UPCAST(NetVhostUserState, nc, nc0);
|
|
|
357786 |
do {
|
|
|
357786 |
if (qemu_chr_fe_wait_connected(&s->chr, &err) < 0) {
|
|
|
357786 |
error_report_err(err);
|
|
|
357786 |
- return -1;
|
|
|
357786 |
+ goto err;
|
|
|
357786 |
}
|
|
|
357786 |
qemu_chr_fe_set_handlers(&s->chr, NULL, NULL,
|
|
|
357786 |
net_vhost_user_event, NULL, nc0->name, NULL,
|
|
|
357786 |
@@ -319,6 +336,17 @@ static int net_vhost_user_init(NetClientState *peer, const char *device,
|
|
|
357786 |
assert(s->vhost_net);
|
|
|
357786 |
|
|
|
357786 |
return 0;
|
|
|
357786 |
+
|
|
|
357786 |
+err:
|
|
|
357786 |
+ if (user) {
|
|
|
357786 |
+ vhost_user_cleanup(user);
|
|
|
357786 |
+ g_free(user);
|
|
|
357786 |
+ if (s) {
|
|
|
357786 |
+ s->vhost_user = NULL;
|
|
|
357786 |
+ }
|
|
|
357786 |
+ }
|
|
|
357786 |
+
|
|
|
357786 |
+ return -1;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
static Chardev *net_vhost_claim_chardev(
|
|
|
357786 |
--
|
|
|
357786 |
1.8.3.1
|
|
|
357786 |
|