All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Marc-André Lureau" <marcandre.lureau@redhat.com>
To: qemu-devel@nongnu.org
Cc: kraxel@redhat.com, mst@redhat.com
Subject: [Qemu-devel] [PATCH v6 07/12] vhost-user: split vhost_user_read()
Date: Fri,  8 Mar 2019 15:04:49 +0100	[thread overview]
Message-ID: <20190308140454.32437-8-marcandre.lureau@redhat.com> (raw)
In-Reply-To: <20190308140454.32437-1-marcandre.lureau@redhat.com>

Split vhost_user_read(), so only header can be read with
vhost_user_read_header().

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
---
 hw/virtio/vhost-user.c | 27 +++++++++++++++++++--------
 1 file changed, 19 insertions(+), 8 deletions(-)

diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
index 3b09c40578..5df73405bc 100644
--- a/hw/virtio/vhost-user.c
+++ b/hw/virtio/vhost-user.c
@@ -214,7 +214,7 @@ static bool ioeventfd_enabled(void)
     return !kvm_enabled() || kvm_eventfds_enabled();
 }
 
-static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg)
+static int vhost_user_read_header(struct vhost_dev *dev, VhostUserMsg *msg)
 {
     struct vhost_user *u = dev->opaque;
     CharBackend *chr = u->user->chr;
@@ -225,7 +225,7 @@ static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg)
     if (r != size) {
         error_report("Failed to read msg header. Read %d instead of %d."
                      " Original request %d.", r, size, msg->hdr.request);
-        goto fail;
+        return -1;
     }
 
     /* validate received flags */
@@ -233,7 +233,21 @@ static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg)
         error_report("Failed to read msg header."
                 " Flags 0x%x instead of 0x%x.", msg->hdr.flags,
                 VHOST_USER_REPLY_MASK | VHOST_USER_VERSION);
-        goto fail;
+        return -1;
+    }
+
+    return 0;
+}
+
+static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg)
+{
+    struct vhost_user *u = dev->opaque;
+    CharBackend *chr = u->user->chr;
+    uint8_t *p = (uint8_t *) msg;
+    int r, size;
+
+    if (vhost_user_read_header(dev, msg) < 0) {
+        return -1;
     }
 
     /* validate message size is sane */
@@ -241,7 +255,7 @@ static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg)
         error_report("Failed to read msg header."
                 " Size %d exceeds the maximum %zu.", msg->hdr.size,
                 VHOST_USER_PAYLOAD_SIZE);
-        goto fail;
+        return -1;
     }
 
     if (msg->hdr.size) {
@@ -251,14 +265,11 @@ static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg)
         if (r != size) {
             error_report("Failed to read msg payload."
                          " Read %d instead of %d.", r, msg->hdr.size);
-            goto fail;
+            return -1;
         }
     }
 
     return 0;
-
-fail:
-    return -1;
 }
 
 static int process_message_reply(struct vhost_dev *dev,
-- 
2.21.0.4.g36eb1cb9cf

  parent reply	other threads:[~2019-03-08 14:05 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-08 14:04 [Qemu-devel] [PATCH v6 00/12] vhost-user-backend & vhost-user-input Marc-André Lureau
2019-03-08 14:04 ` [Qemu-devel] [PATCH v6 01/12] libvhost-user: fix clang enum-conversion warning Marc-André Lureau
2019-03-08 14:04 ` [Qemu-devel] [PATCH v6 02/12] vhost-user: define conventions for vhost-user backends Marc-André Lureau
2019-03-08 14:04 ` [Qemu-devel] [PATCH v6 03/12] vhost-user: simplify vhost_user_init/vhost_user_cleanup Marc-André Lureau
2019-03-08 14:04 ` [Qemu-devel] [PATCH v6 04/12] libvhost-user: exit by default on VHOST_USER_NONE Marc-André Lureau
2019-03-08 14:04 ` [Qemu-devel] [PATCH v6 05/12] vhost-user: wrap some read/write with retry handling Marc-André Lureau
2019-03-08 14:04 ` [Qemu-devel] [PATCH v6 06/12] Add vhost-user-backend Marc-André Lureau
2019-03-08 14:04 ` Marc-André Lureau [this message]
2019-03-08 14:04 ` [Qemu-devel] [PATCH v6 08/12] vhost-user: add vhost_user_input_get_config() Marc-André Lureau
2019-03-08 14:04 ` [Qemu-devel] [PATCH v6 09/12] libvhost-user-glib: export vug_source_new() Marc-André Lureau
2019-03-08 14:04 ` [Qemu-devel] [PATCH v6 10/12] libvhost-user: add vu_queue_unpop() Marc-André Lureau
2019-03-08 14:04 ` [Qemu-devel] [PATCH v6 11/12] Add vhost-user-input-pci Marc-André Lureau
2019-03-08 14:04 ` [Qemu-devel] [PATCH v6 12/12] contrib: add vhost-user-input Marc-André Lureau

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=20190308140454.32437-8-marcandre.lureau@redhat.com \
    --to=marcandre.lureau@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.