@@ -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.
@@ -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)
{
@@ -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_ */