76daa3
From a9adfd803bc1a101c3229b5ad20da533fa2d51f1 Mon Sep 17 00:00:00 2001
76daa3
From: Maxime Coquelin <maxime.coquelin@redhat.com>
76daa3
Date: Tue, 6 Jun 2017 12:05:22 +0200
76daa3
Subject: [PATCH 11/17] vhost-user: add vhost_user to hold the chr
76daa3
MIME-Version: 1.0
76daa3
Content-Type: text/plain; charset=UTF-8
76daa3
Content-Transfer-Encoding: 8bit
76daa3
76daa3
RH-Author: Maxime Coquelin <maxime.coquelin@redhat.com>
76daa3
Message-id: <20170606120524.3050-4-maxime.coquelin@redhat.com>
76daa3
Patchwork-id: 75499
76daa3
O-Subject: [RHV-7.4 qemu-kvm-rhev PATCH 3/5] vhost-user: add vhost_user to hold the chr
76daa3
Bugzilla: 1451862
76daa3
RH-Acked-by: Peter Xu <peterx@redhat.com>
76daa3
RH-Acked-by: Xiao Wang <jasowang@redhat.com>
76daa3
RH-Acked-by: Jens Freimann <jfreiman@redhat.com>
76daa3
76daa3
From: Marc-André Lureau <marcandre.lureau@redhat.com>
76daa3
76daa3
Next patches will add more fields to the structure
76daa3
76daa3
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
76daa3
Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
76daa3
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
76daa3
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
76daa3
(cherry picked from commit 2152f3fead5ddaf7bdbe370f9b87713eae683b75)
76daa3
Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
76daa3
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
76daa3
---
76daa3
 hw/virtio/vhost-user.c | 19 ++++++++++++++++---
76daa3
 1 file changed, 16 insertions(+), 3 deletions(-)
76daa3
76daa3
diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
76daa3
index 24ca863..325319f 100644
76daa3
--- a/hw/virtio/vhost-user.c
76daa3
+++ b/hw/virtio/vhost-user.c
76daa3
@@ -111,6 +111,10 @@ static VhostUserMsg m __attribute__ ((unused));
76daa3
 /* The version of the protocol we support */
76daa3
 #define VHOST_USER_VERSION    (0x1)
76daa3
 
76daa3
+struct vhost_user {
76daa3
+    CharBackend *chr;
76daa3
+};
76daa3
+
76daa3
 static bool ioeventfd_enabled(void)
76daa3
 {
76daa3
     return kvm_enabled() && kvm_eventfds_enabled();
76daa3
@@ -118,7 +122,8 @@ static bool ioeventfd_enabled(void)
76daa3
 
76daa3
 static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg)
76daa3
 {
76daa3
-    CharBackend *chr = dev->opaque;
76daa3
+    struct vhost_user *u = dev->opaque;
76daa3
+    CharBackend *chr = u->chr;
76daa3
     uint8_t *p = (uint8_t *) msg;
76daa3
     int r, size = VHOST_USER_HDR_SIZE;
76daa3
 
76daa3
@@ -203,7 +208,8 @@ static bool vhost_user_one_time_request(VhostUserRequest request)
76daa3
 static int vhost_user_write(struct vhost_dev *dev, VhostUserMsg *msg,
76daa3
                             int *fds, int fd_num)
76daa3
 {
76daa3
-    CharBackend *chr = dev->opaque;
76daa3
+    struct vhost_user *u = dev->opaque;
76daa3
+    CharBackend *chr = u->chr;
76daa3
     int ret, size = VHOST_USER_HDR_SIZE + msg->size;
76daa3
 
76daa3
     /*
76daa3
@@ -576,11 +582,14 @@ static int vhost_user_reset_device(struct vhost_dev *dev)
76daa3
 static int vhost_user_init(struct vhost_dev *dev, void *opaque)
76daa3
 {
76daa3
     uint64_t features;
76daa3
+    struct vhost_user *u;
76daa3
     int err;
76daa3
 
76daa3
     assert(dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_USER);
76daa3
 
76daa3
-    dev->opaque = opaque;
76daa3
+    u = g_new0(struct vhost_user, 1);
76daa3
+    u->chr = opaque;
76daa3
+    dev->opaque = u;
76daa3
 
76daa3
     err = vhost_user_get_features(dev, &features);
76daa3
     if (err < 0) {
76daa3
@@ -625,8 +634,12 @@ static int vhost_user_init(struct vhost_dev *dev, void *opaque)
76daa3
 
76daa3
 static int vhost_user_cleanup(struct vhost_dev *dev)
76daa3
 {
76daa3
+    struct vhost_user *u;
76daa3
+
76daa3
     assert(dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_USER);
76daa3
 
76daa3
+    u = dev->opaque;
76daa3
+    g_free(u);
76daa3
     dev->opaque = 0;
76daa3
 
76daa3
     return 0;
76daa3
-- 
76daa3
1.8.3.1
76daa3