[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC 04/14] vhost-user: add vhost_user_input_get_config()
From: |
marcandre . lureau |
Subject: |
[Qemu-devel] [RFC 04/14] vhost-user: add vhost_user_input_get_config() |
Date: |
Sat, 4 Jun 2016 23:33:13 +0200 |
From: Marc-André Lureau <address@hidden>
Signed-off-by: Marc-André Lureau <address@hidden>
---
docs/specs/vhost-user.txt | 9 ++++++
hw/virtio/vhost-user.c | 58 +++++++++++++++++++++++++++++++++++++++
include/hw/virtio/vhost-backend.h | 4 +++
3 files changed, 71 insertions(+)
diff --git a/docs/specs/vhost-user.txt b/docs/specs/vhost-user.txt
index 777c49c..fab67a5 100644
--- a/docs/specs/vhost-user.txt
+++ b/docs/specs/vhost-user.txt
@@ -464,3 +464,12 @@ Message types
is present in VHOST_USER_GET_PROTOCOL_FEATURES.
The first 6 bytes of the payload contain the mac address of the guest to
allow the vhost user backend to construct and broadcast the fake RARP.
+
+ * VHOST_USER_INPUT_GET_CONFIG
+
+ Id: 20
+ Equivalent ioctl: N/A
+ Master payload: N/A
+ Slave payload: (struct virtio_input_config)*
+
+ Ask vhost user input backend the list of virtio_input_config.
diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
index 63ffe48..8072c16 100644
--- a/hw/virtio/vhost-user.c
+++ b/hw/virtio/vhost-user.c
@@ -58,6 +58,7 @@ typedef enum VhostUserRequest {
VHOST_USER_GET_QUEUE_NUM = 17,
VHOST_USER_SET_VRING_ENABLE = 18,
VHOST_USER_SEND_RARP = 19,
+ VHOST_USER_INPUT_GET_CONFIG = 20,
VHOST_USER_MAX
} VhostUserRequest;
@@ -205,6 +206,63 @@ static int vhost_user_write(struct vhost_dev *dev,
VhostUserMsg *msg,
0 : -1;
}
+static void *vhost_user_read_size(struct vhost_dev *dev, uint32_t size)
+{
+ CharDriverState *chr = dev->opaque;
+ int r;
+ uint8_t *p = g_malloc(size);
+
+ r = qemu_chr_fe_read_all(chr, p, size);
+ if (r != size) {
+ error_report("Failed to read msg payload."
+ " Read %d instead of %d.", r, size);
+ return NULL;
+ }
+
+ return p;
+}
+
+int vhost_user_input_get_config(struct vhost_dev *dev,
+ struct virtio_input_config **config)
+{
+ void *p = NULL;
+ VhostUserMsg msg = {
+ .request = VHOST_USER_INPUT_GET_CONFIG,
+ .flags = VHOST_USER_VERSION,
+ };
+
+ if (vhost_user_write(dev, &msg, NULL, 0) < 0) {
+ goto err;
+ }
+
+ if (vhost_user_read_header(dev, &msg) < 0) {
+ goto err;
+ }
+
+ p = vhost_user_read_size(dev, msg.size);
+ if (!p) {
+ goto err;
+ }
+
+ if (msg.request != VHOST_USER_INPUT_GET_CONFIG) {
+ error_report("Received unexpected msg type. Expected %d received %d",
+ VHOST_USER_INPUT_GET_CONFIG, msg.request);
+ goto err;
+ }
+
+ if (msg.size % sizeof(struct virtio_input_config)) {
+ error_report("Invalid msg size");
+ goto err;
+ }
+
+ *config = p;
+ return msg.size / sizeof(struct virtio_input_config);
+
+err:
+ g_free(p);
+ return -1;
+}
+
static int vhost_user_set_log_base(struct vhost_dev *dev, uint64_t base,
struct vhost_log *log)
{
diff --git a/include/hw/virtio/vhost-backend.h
b/include/hw/virtio/vhost-backend.h
index 95fcc96..08d34db 100644
--- a/include/hw/virtio/vhost-backend.h
+++ b/include/hw/virtio/vhost-backend.h
@@ -11,6 +11,7 @@
#ifndef VHOST_BACKEND_H_
#define VHOST_BACKEND_H_
+#include "standard-headers/linux/virtio_input.h"
typedef enum VhostBackendType {
VHOST_BACKEND_TYPE_NONE = 0,
@@ -107,4 +108,7 @@ extern const VhostOps user_ops;
int vhost_set_backend_type(struct vhost_dev *dev,
VhostBackendType backend_type);
+int vhost_user_input_get_config(struct vhost_dev *dev,
+ struct virtio_input_config **config);
+
#endif /* VHOST_BACKEND_H_ */
--
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, 2016/06/04
- [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 <=
- [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
- [Qemu-devel] [RFC 08/14] vhost: make sure call fd has been received, marcandre . lureau, 2016/06/04
- [Qemu-devel] [RFC 06/14] contrib: add vhost-user-input, marcandre . lureau, 2016/06/04
- [Qemu-devel] [RFC 10/14] qemu-char: block during sync read, marcandre . lureau, 2016/06/04