[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC 03/14] vhost-user: split vhost_user_read()
From: |
marcandre . lureau |
Subject: |
[Qemu-devel] [RFC 03/14] vhost-user: split vhost_user_read() |
Date: |
Sat, 4 Jun 2016 23:33:12 +0200 |
From: Marc-André Lureau <address@hidden>
Split vhost_user_read(), so only header can be read with
vhost_user_read_header().
Signed-off-by: Marc-André Lureau <address@hidden>
---
hw/virtio/vhost-user.c | 28 +++++++++++++++++++---------
1 file changed, 19 insertions(+), 9 deletions(-)
diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
index 495e09f..63ffe48 100644
--- a/hw/virtio/vhost-user.c
+++ b/hw/virtio/vhost-user.c
@@ -112,7 +112,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)
{
CharDriverState *chr = dev->opaque;
uint8_t *p = (uint8_t *) msg;
@@ -122,7 +122,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->request);
- goto fail;
+ return -1;
}
/* validate received flags */
@@ -130,7 +130,20 @@ 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->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)
+{
+ CharDriverState *chr = dev->opaque;
+ uint8_t *p = (uint8_t *) msg;
+ int r, size;
+
+ if (vhost_user_read_header(dev, msg) < 0) {
+ return -1;
}
/* validate message size is sane */
@@ -138,7 +151,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->size,
VHOST_USER_PAYLOAD_SIZE);
- goto fail;
+ return -1;
}
if (msg->size) {
@@ -148,14 +161,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->size);
- goto fail;
+ return -1;
}
}
return 0;
-
-fail:
- return -1;
}
static bool vhost_user_one_time_request(VhostUserRequest request)
@@ -458,7 +468,7 @@ static int vhost_user_get_u64(struct vhost_dev *dev, int
request, uint64_t *u64)
vhost_user_write(dev, &msg, NULL, 0);
if (vhost_user_read(dev, &msg) < 0) {
- return 0;
+ return -1;
}
if (msg.request != request) {
--
2.7.4
- [Qemu-devel] [RFC 00/14] vhost-user backends for gpu & input virtio devices, marcandre . lureau, 2016/06/04
- [Qemu-devel] [RFC 02/14] Add vhost-user-backend, marcandre . lureau, 2016/06/04
- [Qemu-devel] [RFC 03/14] vhost-user: split vhost_user_read(),
marcandre . lureau <=
- [Qemu-devel] [RFC 01/14] Add qemu_chr_open_socket(), marcandre . lureau, 2016/06/04
- [Qemu-devel] [RFC 07/14] misc: rename virtio-gpu.h header guard, marcandre . lureau, 2016/06/04
- [Qemu-devel] [RFC 04/14] vhost-user: add vhost_user_input_get_config(), marcandre . lureau, 2016/06/04
- [Qemu-devel] [RFC 09/14] qemu-char: use READ_RETRIES, marcandre . lureau, 2016/06/04
- [Qemu-devel] [RFC 11/14] console: add dpy_gl_scanout2(), marcandre . lureau, 2016/06/04
- [Qemu-devel] [RFC 05/14] Add vhost-user backend to virtio-input-host, marcandre . lureau, 2016/06/04